summaryrefslogtreecommitdiffstats
path: root/dom/quota/test/xpcshell/test_persist_eviction.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
commit2aa4a82499d4becd2284cdb482213d541b8804dd (patch)
treeb80bf8bf13c3766139fbacc530efd0dd9d54394c /dom/quota/test/xpcshell/test_persist_eviction.js
parentInitial commit. (diff)
downloadfirefox-upstream.tar.xz
firefox-upstream.zip
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/quota/test/xpcshell/test_persist_eviction.js')
-rw-r--r--dom/quota/test/xpcshell/test_persist_eviction.js85
1 files changed, 85 insertions, 0 deletions
diff --git a/dom/quota/test/xpcshell/test_persist_eviction.js b/dom/quota/test/xpcshell/test_persist_eviction.js
new file mode 100644
index 0000000000..cc725a1330
--- /dev/null
+++ b/dom/quota/test/xpcshell/test_persist_eviction.js
@@ -0,0 +1,85 @@
+/**
+ * Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+/**
+ * This test is mainly to verify that normally the oldest origin will be
+ * evicted if the global limit is reached, but if the oldest origin is
+ * persisted, then it won't be evicted.
+ */
+
+loadScript("dom/quota/test/common/file.js");
+
+async function fillOrigin(principal, size) {
+ let database = getSimpleDatabase(principal);
+
+ let request = database.open("data");
+ await requestFinished(request);
+
+ try {
+ request = database.write(getBuffer(size));
+ await requestFinished(request);
+ ok(true, "Should not have thrown");
+ } catch (ex) {
+ ok(false, "Should not have thrown");
+ }
+
+ request = database.close();
+ await requestFinished(request);
+}
+
+async function testSteps() {
+ // The group limit is calculated as 20% of the global limit and the minimum
+ // value of the group limit is 10 MB.
+
+ const groupLimitKB = 10 * 1024;
+ const globalLimitKB = groupLimitKB * 5;
+
+ setGlobalLimit(globalLimitKB);
+
+ let request = clear();
+ await requestFinished(request);
+
+ for (let persistOldestOrigin of [false, true]) {
+ info(
+ "Testing " +
+ (persistOldestOrigin ? "with" : "without") +
+ " persisting the oldest origin"
+ );
+
+ info(
+ "Step 1: Filling six separate origins to reach the global limit " +
+ "and trigger eviction"
+ );
+
+ for (let index = 1; index <= 6; index++) {
+ let spec = "http://example" + index + ".com";
+ if (index == 1 && persistOldestOrigin) {
+ request = persist(getPrincipal(spec));
+ await requestFinished(request);
+ }
+ await fillOrigin(getPrincipal(spec), groupLimitKB * 1024);
+ }
+
+ info("Step 2: Verifying origin directories");
+
+ for (let index = 1; index <= 6; index++) {
+ let path = "storage/default/http+++example" + index + ".com";
+ let file = getRelativeFile(path);
+ if (index == (persistOldestOrigin ? 2 : 1)) {
+ ok(!file.exists(), "The origin directory " + path + " doesn't exist");
+ } else {
+ ok(file.exists(), "The origin directory " + path + " does exist");
+ }
+ }
+
+ request = clear();
+ await requestFinished(request);
+ }
+
+ resetGlobalLimit();
+
+ request = reset();
+ await requestFinished(request);
+}