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 normally the oldest origin will be
8 * evicted if the global limit is reached, but if the oldest origin is
9 * persisted or is an extension origin, then it won't be evicted.
12 loadScript("dom/quota/test/xpcshell/common/utils.js");
14 async
function testSteps() {
15 // The group limit is calculated as 20% of the global limit and the minimum
16 // value of the group limit is 10 MB.
18 const groupLimitKB
= 10 * 1024;
19 const globalLimitKB
= groupLimitKB
* 5;
21 setGlobalLimit(globalLimitKB
);
23 let request
= clear();
24 await
requestFinished(request
);
26 for (let persistOldestOrigin
of [false, true]) {
29 (persistOldestOrigin
? "with" : "without") +
30 " persisting the oldest origin"
34 "Step 0: Filling a moz-extension origin as the oldest origin with non-persisted data"
37 // Just a fake moz-extension origin to mock an extension origin.
38 let extUUID
= "20445ca5-75f9-420e-a1d4-9cccccb5e891";
39 let spec
= `moz-extension://${extUUID}`;
40 await
fillOrigin(getPrincipal(spec
), groupLimitKB
* 1024);
43 "Step 1: Filling five separate web origins to reach the global limit " +
44 "and trigger eviction"
47 for (let index
= 1; index
<= 5; index
++) {
48 let spec
= "http://example" + index
+ ".com";
49 if (index
== 1 && persistOldestOrigin
) {
50 request
= persist(getPrincipal(spec
));
51 await
requestFinished(request
);
53 await
fillOrigin(getPrincipal(spec
), groupLimitKB
* 1024);
56 info("Step 2: Verifying origin directories");
58 for (let index
= 1; index
<= 5; index
++) {
59 let path
= "storage/default/http+++example" + index
+ ".com";
60 let file
= getRelativeFile(path
);
61 if (index
== (persistOldestOrigin
? 2 : 1)) {
62 ok(!file
.exists(), "The origin directory " + path
+ " doesn't exist");
64 let spec
= "http://example" + index
+ ".com";
65 request
= initTemporaryOrigin("default", getPrincipal(spec
));
66 await
requestFinished(request
);
68 ok(file
.exists(), "The origin directory " + path
+ " does exist");
70 ok(file
.exists(), "The origin directory " + path
+ " does exist");
74 // Verify that the extension storage data has not been evicted (even if it wasn't marked as
75 // persisted and it was the less recently used origin).
76 let path
= `storage/default/moz-extension+++${extUUID}`;
77 let file
= getRelativeFile(path
);
78 ok(file
.exists(), "The origin directory " + path
+ "does exist");
81 await
requestFinished(request
);
87 await
requestFinished(request
);