2 * Any copyright is dedicated to the Public Domain.
3 * http://creativecommons.org/publicdomain/zero/1.0/
7 * This test is mainly to verify that persisted origins are not constrained by
8 * the group limit. It consits of these steps:
9 * - Set the limits as small as our limits allow. This does result in needing
10 * to perform 10 megs of writes which is a lot for a test but not horrible.
11 * - Create databases for 2 origins under the same group.
12 * - Have the foo2 origin use up the shared group quota.
13 * - Verify neither origin can write additional data (via a single byte write).
14 * - Do navigator.storage.persist() for that foo2 origin.
15 * - Verify that both origins can now write an additional byte. This
17 * - foo2 no longer counts against the group limit at all since foo1 can
19 * - foo2 is no longer constrained by the group limit itself.
21 async
function testSteps() {
22 // The group limit is calculated as 20% of the global limit and the minimum
23 // value of the group limit is 10 MB.
25 const groupLimitKB
= 10 * 1024;
26 const globalLimitKB
= groupLimitKB
* 5;
28 const urls
= ["http://foo1.example.com", "http://foo2.example.com"];
34 info("Setting limits");
36 setGlobalLimit(globalLimitKB
);
38 let request
= clear();
39 await
requestFinished(request
);
41 info("Opening databases");
44 for (index
= 0; index
< urls
.length
; index
++) {
45 let database
= getSimpleDatabase(getPrincipal(urls
[index
]));
47 request
= database
.open("data");
48 await
requestFinished(request
);
50 databases
.push(database
);
53 info("Filling up the whole group");
56 request
= databases
[foo2Index
].write(new ArrayBuffer(groupLimitKB
* 1024));
57 await
requestFinished(request
);
58 ok(true, "Should not have thrown");
60 ok(false, "Should not have thrown");
63 info("Verifying no more data can be written");
65 for (index
= 0; index
< urls
.length
; index
++) {
67 request
= databases
[index
].write(new ArrayBuffer(1));
68 await
requestFinished(request
);
69 ok(false, "Should have thrown");
71 ok(true, "Should have thrown");
74 NS_ERROR_FILE_NO_DEVICE_SPACE
,
75 "Threw right result code"
80 info("Persisting origin");
82 request
= persist(getPrincipal(urls
[foo2Index
]));
83 await
requestFinished(request
);
85 info("Verifying more data data can be written");
87 for (index
= 0; index
< urls
.length
; index
++) {
89 request
= databases
[index
].write(new ArrayBuffer(1));
90 await
requestFinished(request
);
91 ok(true, "Should not have thrown");
93 ok(false, "Should not have thrown");
97 info("Closing databases");
99 for (index
= 0; index
< urls
.length
; index
++) {
100 request
= databases
[index
].close();
101 await
requestFinished(request
);