summaryrefslogtreecommitdiffstats
path: root/dom/quota/test/xpcshell/caching
diff options
context:
space:
mode:
Diffstat (limited to 'dom/quota/test/xpcshell/caching')
-rw-r--r--dom/quota/test/xpcshell/caching/groupMismatch_profile.zipbin0 -> 2576 bytes
-rw-r--r--dom/quota/test/xpcshell/caching/head.js14
-rw-r--r--dom/quota/test/xpcshell/caching/make_unsetLastAccessTime.js25
-rw-r--r--dom/quota/test/xpcshell/caching/removedOrigin_profile.zipbin0 -> 1551 bytes
-rw-r--r--dom/quota/test/xpcshell/caching/test_groupMismatch.js45
-rw-r--r--dom/quota/test/xpcshell/caching/test_removedOrigin.js61
-rw-r--r--dom/quota/test/xpcshell/caching/test_unsetLastAccessTime.js46
-rw-r--r--dom/quota/test/xpcshell/caching/unsetLastAccessTime_profile.zipbin0 -> 1574 bytes
-rw-r--r--dom/quota/test/xpcshell/caching/xpcshell.ini17
9 files changed, 208 insertions, 0 deletions
diff --git a/dom/quota/test/xpcshell/caching/groupMismatch_profile.zip b/dom/quota/test/xpcshell/caching/groupMismatch_profile.zip
new file mode 100644
index 0000000000..8124e589de
--- /dev/null
+++ b/dom/quota/test/xpcshell/caching/groupMismatch_profile.zip
Binary files differ
diff --git a/dom/quota/test/xpcshell/caching/head.js b/dom/quota/test/xpcshell/caching/head.js
new file mode 100644
index 0000000000..5c36d82ca6
--- /dev/null
+++ b/dom/quota/test/xpcshell/caching/head.js
@@ -0,0 +1,14 @@
+/**
+ * Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+// The path to the top level directory.
+const depth = "../../../../../";
+
+loadScript("dom/quota/test/xpcshell/common/head.js");
+
+function loadScript(path) {
+ let uri = Services.io.newFileURI(do_get_file(depth + path));
+ Services.scriptloader.loadSubScript(uri.spec);
+}
diff --git a/dom/quota/test/xpcshell/caching/make_unsetLastAccessTime.js b/dom/quota/test/xpcshell/caching/make_unsetLastAccessTime.js
new file mode 100644
index 0000000000..9be377e4f3
--- /dev/null
+++ b/dom/quota/test/xpcshell/caching/make_unsetLastAccessTime.js
@@ -0,0 +1,25 @@
+/*
+ Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/
+*/
+
+async function testSteps() {
+ const originDirPath = "storage/default/https+++foo.example.com";
+
+ info("Initializing");
+
+ let request = init();
+ await requestFinished(request);
+
+ info("Creating an empty origin directory");
+
+ let originDir = getRelativeFile(originDirPath);
+ originDir.create(Ci.nsIFile.DIRECTORY_TYPE, parseInt("0755", 8));
+
+ info("Initializing temporary storage");
+
+ request = initTemporaryStorage();
+ await requestFinished(request);
+
+ // The metadata file should be now restored.
+}
diff --git a/dom/quota/test/xpcshell/caching/removedOrigin_profile.zip b/dom/quota/test/xpcshell/caching/removedOrigin_profile.zip
new file mode 100644
index 0000000000..a5ccc05aa9
--- /dev/null
+++ b/dom/quota/test/xpcshell/caching/removedOrigin_profile.zip
Binary files differ
diff --git a/dom/quota/test/xpcshell/caching/test_groupMismatch.js b/dom/quota/test/xpcshell/caching/test_groupMismatch.js
new file mode 100644
index 0000000000..3f8e843798
--- /dev/null
+++ b/dom/quota/test/xpcshell/caching/test_groupMismatch.js
@@ -0,0 +1,45 @@
+/**
+ * Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+/**
+ * This test is mainly to verify that the group loaded from the origin table
+ * gets updated (if necessary) before quota initialization for the given origin.
+ */
+
+async function testSteps() {
+ const principal = getPrincipal("https://foo.bar.mozilla-iot.org");
+ const originUsage = 100;
+
+ info("Clearing");
+
+ let request = clear();
+ await requestFinished(request);
+
+ info("Installing package");
+
+ // The profile contains one initialized origin directory with simple database
+ // data, a script for origin initialization and the storage database:
+ // - storage/default/https+++foo.bar.mozilla-iot.org
+ // - create_db.js
+ // - storage.sqlite
+ // The file create_db.js in the package was run locally, specifically it was
+ // temporarily added to xpcshell.ini and then executed:
+ // mach xpcshell-test --interactive dom/quota/test/xpcshell/create_db.js
+ // Note: to make it become the profile in the test, additional manual steps
+ // are needed.
+ // 1. Manually change the group and accessed values in the origin table in
+ // storage.sqlite by running this SQL statement:
+ // UPDATE origin SET group_ = 'mozilla-iot.org', accessed = 0
+ // 2. Manually change the group in .metadata-v2 from "bar.mozilla-iot.org" to
+ // "mozilla-iot.org".
+ // 3. Remove the folder "storage/temporary".
+ // 4. Remove the file "storage/ls-archive.sqlite".
+ installPackage("groupMismatch_profile");
+
+ request = getOriginUsage(principal, /* fromMemory */ true);
+ await requestFinished(request);
+
+ is(request.result.usage, originUsage, "Correct origin usage");
+}
diff --git a/dom/quota/test/xpcshell/caching/test_removedOrigin.js b/dom/quota/test/xpcshell/caching/test_removedOrigin.js
new file mode 100644
index 0000000000..8b5702ad9c
--- /dev/null
+++ b/dom/quota/test/xpcshell/caching/test_removedOrigin.js
@@ -0,0 +1,61 @@
+/**
+ * Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+/**
+ * Verify that temporary storage initialization will notice a removed origin
+ * that the cache has data for and which indicates the origin was accessed
+ * during the last run. Currently, we expect LoadQuotaFromCache to fail because
+ * of this inconsistency and to fall back to full initialization.
+ */
+
+async function testSteps() {
+ const principal = getPrincipal("http://example.com");
+ const originUsage = 0;
+
+ info("Setting pref");
+
+ // The packaged profile will have a different build ID and we would treat the
+ // cache as invalid if we didn't bypass this check.
+ Services.prefs.setBoolPref("dom.quotaManager.caching.checkBuildId", false);
+
+ info("Clearing");
+
+ let request = clear();
+ await requestFinished(request);
+
+ info("Installing package");
+
+ // The profile contains empty default storage, a script for origin
+ // initialization and the storage database:
+ // - storage/default
+ // - create_db.js
+ // - storage.sqlite
+ // The file create_db.js in the package was run locally, specifically it was
+ // temporarily added to xpcshell.ini and then executed:
+ // mach xpcshell-test --interactive dom/quota/test/xpcshell/create_db.js
+ // Note: to make it become the profile in the test, additional manual steps
+ // are needed.
+ // 1. Remove the folder "storage/default/http+++example.com".
+ // 2. Remove the folder "storage/temporary".
+ // 3. Remove the file "storage/ls-archive.sqlite".
+ installPackage("removedOrigin_profile");
+
+ info("Initializing");
+
+ request = init();
+ await requestFinished(request);
+
+ info("Initializing temporary storage");
+
+ request = initTemporaryStorage();
+ await requestFinished(request);
+
+ info("Getting origin usage");
+
+ request = getOriginUsage(principal, /* fromMemory */ true);
+ await requestFinished(request);
+
+ is(request.result.usage, originUsage, "Correct origin usage");
+}
diff --git a/dom/quota/test/xpcshell/caching/test_unsetLastAccessTime.js b/dom/quota/test/xpcshell/caching/test_unsetLastAccessTime.js
new file mode 100644
index 0000000000..5abe76eade
--- /dev/null
+++ b/dom/quota/test/xpcshell/caching/test_unsetLastAccessTime.js
@@ -0,0 +1,46 @@
+/**
+ * Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+async function testSteps() {
+ const principal = getPrincipal("https://foo.example.com/");
+
+ info("Setting pref");
+
+ // The packaged profile will have a different build ID and we would treat the
+ // cache as invalid if we didn't bypass this check.
+ Services.prefs.setBoolPref("dom.quotaManager.caching.checkBuildId", false);
+
+ info("Clearing");
+
+ let request = clear();
+ await requestFinished(request);
+
+ info("Installing package");
+
+ // The profile contains one initialized origin directory and the storage
+ // database:
+ // - storage/default/https+++foo.example.com
+ // - storage.sqlite
+ // The file make_unsetLastAccessTime.js was run locally, specifically it was
+ // temporarily enabled in xpcshell.ini and then executed:
+ // mach test --interactive dom/quota/test/xpcshell/caching/make_unsetLastAccessTime.js
+ // Note: to make it become the profile in the test, additional manual steps
+ // are needed.
+ // 1. Remove the folder "storage/temporary".
+ // 2. Remove the file "storage/ls-archive.sqlite".
+ installPackage("unsetLastAccessTime_profile");
+
+ info("Getting full origin metadata");
+
+ request = getFullOriginMetadata("default", principal);
+ await requestFinished(request);
+
+ info("Verifying last access time");
+
+ ok(
+ BigInt(request.result.lastAccessTime) != INT64_MIN,
+ "Correct last access time"
+ );
+}
diff --git a/dom/quota/test/xpcshell/caching/unsetLastAccessTime_profile.zip b/dom/quota/test/xpcshell/caching/unsetLastAccessTime_profile.zip
new file mode 100644
index 0000000000..2b14ca7276
--- /dev/null
+++ b/dom/quota/test/xpcshell/caching/unsetLastAccessTime_profile.zip
Binary files differ
diff --git a/dom/quota/test/xpcshell/caching/xpcshell.ini b/dom/quota/test/xpcshell/caching/xpcshell.ini
new file mode 100644
index 0000000000..d08f15c0a8
--- /dev/null
+++ b/dom/quota/test/xpcshell/caching/xpcshell.ini
@@ -0,0 +1,17 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+[DEFAULT]
+head = head.js
+support-files =
+ groupMismatch_profile.zip
+ removedOrigin_profile.zip
+
+[make_unsetLastAccessTime.js]
+skip-if = true # Only used for recreating unsetLastAccessTime_profile.zip
+[test_groupMismatch.js]
+[test_removedOrigin.js]
+[test_unsetLastAccessTime.js]
+support-files =
+ unsetLastAccessTime_profile.zip