summaryrefslogtreecommitdiffstats
path: root/dom/localstorage/test/unit/test_archive.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /dom/localstorage/test/unit/test_archive.js
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/localstorage/test/unit/test_archive.js')
-rw-r--r--dom/localstorage/test/unit/test_archive.js78
1 files changed, 78 insertions, 0 deletions
diff --git a/dom/localstorage/test/unit/test_archive.js b/dom/localstorage/test/unit/test_archive.js
new file mode 100644
index 0000000000..86e59d73c8
--- /dev/null
+++ b/dom/localstorage/test/unit/test_archive.js
@@ -0,0 +1,78 @@
+/**
+ * Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+add_task(async function testSteps() {
+ const lsArchiveFile = "storage/ls-archive.sqlite";
+
+ const principalInfo = {
+ url: "http://example.com",
+ attrs: {},
+ };
+
+ function checkStorage() {
+ let principal = getPrincipal(principalInfo.url, principalInfo.attrs);
+ let storage = getLocalStorage(principal);
+ try {
+ storage.open();
+ ok(true, "Did not throw");
+ } catch (ex) {
+ ok(false, "Should not have thrown");
+ }
+ }
+
+ info("Setting pref");
+
+ Services.prefs.setBoolPref("dom.storage.next_gen", true);
+
+ info("Sub test case 1 - Archive file is a directory.");
+
+ info("Clearing");
+
+ let request = clear();
+ await requestFinished(request);
+
+ let archiveFile = getRelativeFile(lsArchiveFile);
+
+ archiveFile.create(Ci.nsIFile.DIRECTORY_TYPE, parseInt("0755", 8));
+
+ checkStorage();
+
+ info("Sub test case 2 - Corrupted archive file.");
+
+ info("Clearing");
+
+ request = clear();
+ await requestFinished(request);
+
+ let ostream = Cc["@mozilla.org/network/file-output-stream;1"].createInstance(
+ Ci.nsIFileOutputStream
+ );
+ ostream.init(archiveFile, -1, parseInt("0644", 8), 0);
+ ostream.write("foobar", 6);
+ ostream.close();
+
+ checkStorage();
+
+ info("Sub test case 3 - Nonupdateable archive file.");
+
+ info("Clearing");
+
+ request = clear();
+ await requestFinished(request);
+
+ info("Installing package");
+
+ // The profile contains storage.sqlite and storage/ls-archive.sqlite
+ // storage/ls-archive.sqlite was taken from FF 54 to force an upgrade.
+ // There's just one record in the webappsstore2 table. The record was
+ // modified by renaming the origin attribute userContextId to userContextKey.
+ // This triggers an error during the upgrade.
+ installPackage("archive_profile");
+
+ let fileSize = archiveFile.fileSize;
+ Assert.greater(fileSize, 0, "archive file size is greater than zero");
+
+ checkStorage();
+});