Bug 1945643 - Update to mozilla-nimbus-schemas 2025.1.1 r=chumphreys
[gecko.git] / dom / quota / test / xpcshell / upgrades / test_localStorageArchive4upgrade.js
blob0b0fcfccd6f57a736eb6c6c0a0edc450023b9bab
1 /**
2 * Any copyright is dedicated to the Public Domain.
3 * http://creativecommons.org/publicdomain/zero/1.0/
4 */
6 /**
7 * This test is mainly to verify that local storage directories are removed
8 * during local storage archive upgrade from version 3 to version 4.
9 * See bug 1549654.
12 async function testSteps() {
13 const lsDirs = [
14 "storage/default/http+++localhost/ls",
15 "storage/default/http+++www.mozilla.org/ls",
16 "storage/default/http+++example.com/ls",
19 const principalInfos = [
20 "http://localhost",
21 "http://www.mozilla.org",
22 "http://example.com",
25 const data = [
26 { key: "foo0", value: "bar" },
27 { key: "foo1", value: "A" },
28 { key: "foo2", value: "A".repeat(100) },
31 function getLocalStorage(principal) {
32 return Services.domStorageManager.createStorage(
33 null,
34 principal,
35 principal,
40 info("Setting pref");
42 // xpcshell globals don't have associated clients in the Clients API sense, so
43 // we need to disable client validation so that this xpcshell test is allowed
44 // to use LocalStorage.
45 Services.prefs.setBoolPref("dom.storage.client_validation", false);
47 info("Clearing");
49 let request = clear();
50 await requestFinished(request);
52 info("Installing package");
54 // The profile contains three initialized origin directories with local
55 // storage data, local storage archive, a script for origin initialization,
56 // the storage database and the web apps store database:
57 // - storage/default/https+++example.com
58 // - storage/default/https+++localhost
59 // - storage/default/https+++www.mozilla.org
60 // - storage/ls-archive.sqlite
61 // - create_db.js
62 // - storage.sqlite
63 // - webappsstore.sqlite
64 // The file create_db.js in the package was run locally (with a build with
65 // local storage archive version 3), specifically it was temporarily added to
66 // xpcshell.ini and then executed:
67 // mach xpcshell-test --interactive dom/localstorage/test/xpcshell/create_db.js
68 // Note: to make it become the profile in the test, additional manual steps
69 // are needed.
70 // 1. Remove the folder "storage/temporary".
71 installPackage("localStorageArchive4upgrade_profile");
73 info("Checking ls dirs");
75 for (let lsDir of lsDirs) {
76 let dir = getRelativeFile(lsDir);
78 exists = dir.exists();
79 ok(exists, "ls directory does exist");
82 request = init();
83 request = await requestFinished(request);
85 info("Checking ls dirs");
87 for (let lsDir of lsDirs) {
88 let dir = getRelativeFile(lsDir);
90 exists = dir.exists();
91 ok(!exists, "ls directory doesn't exist");
94 info("Getting storages");
96 let storages = [];
97 for (let i = 0; i < principalInfos.length; i++) {
98 let storage = getLocalStorage(getPrincipal(principalInfos[i]));
99 storages.push(storage);
102 info("Verifying data");
104 for (let i = 0; i < storages.length; i++) {
105 is(storages[i].getItem(data[i].key), data[i].value, "Correct value");