test_localStorageArchive4upgrade.js (2977B)
1 /** 2 * Any copyright is dedicated to the Public Domain. 3 * http://creativecommons.org/publicdomain/zero/1.0/ 4 */ 5 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. 10 */ 11 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", 17 ]; 18 19 const principalInfos = [ 20 "http://localhost", 21 "http://www.mozilla.org", 22 "http://example.com", 23 ]; 24 25 const data = [ 26 { key: "foo0", value: "bar" }, 27 { key: "foo1", value: "A" }, 28 { key: "foo2", value: "A".repeat(100) }, 29 ]; 30 31 function getLocalStorage(principal) { 32 return Services.domStorageManager.createStorage( 33 null, 34 principal, 35 principal, 36 "" 37 ); 38 } 39 40 info("Setting pref"); 41 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); 46 47 info("Clearing"); 48 49 let request = clear(); 50 await requestFinished(request); 51 52 info("Installing package"); 53 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.toml 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"); 72 73 info("Checking ls dirs"); 74 75 for (let lsDir of lsDirs) { 76 let dir = getRelativeFile(lsDir); 77 78 exists = dir.exists(); 79 ok(exists, "ls directory does exist"); 80 } 81 82 request = init(); 83 request = await requestFinished(request); 84 85 info("Checking ls dirs"); 86 87 for (let lsDir of lsDirs) { 88 let dir = getRelativeFile(lsDir); 89 90 exists = dir.exists(); 91 ok(!exists, "ls directory doesn't exist"); 92 } 93 94 info("Getting storages"); 95 96 let storages = []; 97 for (let i = 0; i < principalInfos.length; i++) { 98 let storage = getLocalStorage(getPrincipal(principalInfos[i])); 99 storages.push(storage); 100 } 101 102 info("Verifying data"); 103 104 for (let i = 0; i < storages.length; i++) { 105 is(storages[i].getItem(data[i].key), data[i].value, "Correct value"); 106 } 107 }