test_migration.js (3293B)
1 /** 2 * Any copyright is dedicated to the Public Domain. 3 * http://creativecommons.org/publicdomain/zero/1.0/ 4 */ 5 6 add_task(async function testSteps() { 7 const principalInfos = [ 8 { url: "http://localhost", attrs: {} }, 9 { url: "http://www.mozilla.org", attrs: {} }, 10 { url: "http://example.com", attrs: {} }, 11 { url: "http://example.org", attrs: { userContextId: 5 } }, 12 13 { url: "http://origin.test", attrs: {} }, 14 15 { url: "http://prefix.test", attrs: {} }, 16 { url: "http://prefix.test", attrs: { userContextId: 10 } }, 17 18 { url: "http://pattern.test", attrs: { userContextId: 15 } }, 19 { url: "http://pattern.test:8080", attrs: { userContextId: 15 } }, 20 { url: "https://pattern.test", attrs: { userContextId: 15 } }, 21 ]; 22 23 const data = { 24 key: "foo", 25 value: "bar", 26 }; 27 28 function verifyData(clearedOrigins) { 29 info("Getting storages"); 30 31 let storages = []; 32 for (let i = 0; i < principalInfos.length; i++) { 33 let principalInfo = principalInfos[i]; 34 let principal = getPrincipal(principalInfo.url, principalInfo.attrs); 35 let storage = getLocalStorage(principal); 36 storages.push(storage); 37 } 38 39 info("Verifying data"); 40 41 for (let i = 0; i < storages.length; i++) { 42 let value = storages[i].getItem(data.key + i); 43 if (clearedOrigins.includes(i)) { 44 is(value, null, "Correct value"); 45 } else { 46 is(value, data.value + i, "Correct value"); 47 } 48 } 49 } 50 51 info("Setting pref"); 52 53 Services.prefs.setBoolPref( 54 "dom.storage.enable_unsupported_legacy_implementation", 55 false 56 ); 57 58 info("Stage 1 - Testing archived data migration"); 59 60 info("Clearing"); 61 62 let request = clear(); 63 await requestFinished(request); 64 65 info("Installing package"); 66 67 // The profile contains storage.sqlite and webappsstore.sqlite. The file 68 // create_db.js in the package was run locally, specifically it was 69 // temporarily added to xpcshell.toml and then executed: 70 // mach xpcshell-test --interactive dom/localstorage/test/unit/create_db.js 71 installPackage("migration_profile"); 72 73 verifyData([]); 74 75 info("Stage 2 - Testing archived data clearing"); 76 77 for (let type of ["origin", "prefix", "pattern"]) { 78 info("Clearing"); 79 80 request = clear(); 81 await requestFinished(request); 82 83 info("Installing package"); 84 85 // See the comment for the first installPackage() call. 86 installPackage("migration_profile"); 87 88 let clearedOrigins = []; 89 90 switch (type) { 91 case "origin": { 92 let principal = getPrincipal("http://origin.test", {}); 93 request = clearOrigin(principal, "default"); 94 await requestFinished(request); 95 96 clearedOrigins.push(4); 97 98 break; 99 } 100 101 case "prefix": { 102 let principal = getPrincipal("http://prefix.test", {}); 103 request = clearOriginsByPrefix(principal, "default"); 104 await requestFinished(request); 105 106 clearedOrigins.push(5, 6); 107 108 break; 109 } 110 111 case "pattern": { 112 request = clearOriginsByPattern(JSON.stringify({ userContextId: 15 })); 113 await requestFinished(request); 114 115 clearedOrigins.push(7, 8, 9); 116 117 break; 118 } 119 120 default: { 121 throw new Error("Unknown type: " + type); 122 } 123 } 124 125 verifyData(clearedOrigins); 126 } 127 });