Bug 1943761 - Add class alignment to the mozsearch analysis file. r=asuth
[gecko.git] / dom / quota / test / xpcshell / test_getUsage.js
blob967acadb8e2be5f32dd51de4fc54393d68cfb401
1 /**
2 * Any copyright is dedicated to the Public Domain.
3 * http://creativecommons.org/publicdomain/zero/1.0/
4 */
6 async function testSteps() {
7 const origins = [
9 origin: "http://example.com",
10 persisted: false,
11 usage: 49152,
15 origin: "http://localhost",
16 persisted: false,
17 usage: 147456,
21 origin: "http://www.mozilla.org",
22 persisted: true,
23 usage: 98304,
27 const allOrigins = [
29 origin: "chrome",
30 persisted: false,
31 usage: 147456,
35 origin: "http://example.com",
36 persisted: false,
37 usage: 49152,
41 origin: "http://localhost",
42 persisted: false,
43 usage: 147456,
47 origin: "http://www.mozilla.org",
48 persisted: true,
49 usage: 98304,
53 function verifyResult(result, expectedOrigins) {
54 ok(result instanceof Array, "Got an array object");
55 Assert.equal(
56 result.length,
57 expectedOrigins.length,
58 "Correct number of elements"
61 info("Sorting elements");
63 result.sort(function (a, b) {
64 let originA = a.origin;
65 let originB = b.origin;
67 if (originA < originB) {
68 return -1;
70 if (originA > originB) {
71 return 1;
73 return 0;
74 });
76 info("Verifying elements");
78 for (let i = 0; i < result.length; i++) {
79 let a = result[i];
80 let b = expectedOrigins[i];
81 Assert.equal(a.origin, b.origin, "Origin equals");
82 Assert.equal(a.persisted, b.persisted, "Persisted equals");
83 Assert.equal(a.usage, b.usage, "Usage equals");
87 function dummy() {}
89 info("Clearing");
91 let request = clear();
92 await requestFinished(request);
94 info("Getting usage");
96 request = getUsage(dummy, /* getAll */ true);
97 let result = await requestFinished(request);
99 info("Verifying result");
101 verifyResult(result, []);
103 info("Clearing");
105 request = clear();
106 await requestFinished(request);
108 info("Installing package");
110 // The profile contains IndexedDB databases placed across the repositories.
111 // The file create_db.js in the package was run locally, specifically it was
112 // temporarily added to xpcshell.ini and then executed:
113 // mach xpcshell-test --interactive dom/quota/test/xpcshell/create_db.js
114 installPackage("getUsage_profile");
116 info("Getting usage");
118 request = getUsage(dummy, /* getAll */ false);
119 result = await requestFinished(request);
121 info("Verifying result");
123 verifyResult(result, origins);
125 info("Getting usage");
127 request = getUsage(dummy, /* getAll */ true);
128 result = await requestFinished(request);
130 info("Verifying result");
132 verifyResult(result, allOrigins);
134 info("Getting usage");
136 Services.prefs.setIntPref(
137 "dom.quotaManager.originOperations.pauseOnIOThreadMs",
138 1000
141 request = getUsage(dummy, /* getAll */ true);
143 info("Cancelling request");
145 request.cancel();
147 try {
148 result = await requestFinished(request);
149 ok(false, "Should have thrown");
150 } catch (e) {
151 ok(true, "Should have thrown");
152 Assert.strictEqual(
153 e.resultCode,
154 NS_ERROR_FAILURE,
155 "Threw right result code"
159 Services.prefs.clearUserPref(
160 "dom.quotaManager.originOperations.pauseOnIOThreadMs"