Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | * http://creativecommons.org/publicdomain/zero/1.0/ |
michael@0 | 3 | */ |
michael@0 | 4 | |
michael@0 | 5 | // Checks that we migrate data from the old extensions.rdf database. This |
michael@0 | 6 | // matches test_migrate1.js however it runs with a lightweight theme selected |
michael@0 | 7 | // so the themes should appear disabled. |
michael@0 | 8 | |
michael@0 | 9 | Components.utils.import("resource://gre/modules/LightweightThemeManager.jsm"); |
michael@0 | 10 | |
michael@0 | 11 | var addon1 = { |
michael@0 | 12 | id: "addon1@tests.mozilla.org", |
michael@0 | 13 | version: "1.0", |
michael@0 | 14 | name: "Test 1", |
michael@0 | 15 | targetApplications: [{ |
michael@0 | 16 | id: "xpcshell@tests.mozilla.org", |
michael@0 | 17 | minVersion: "1", |
michael@0 | 18 | maxVersion: "1" |
michael@0 | 19 | }] |
michael@0 | 20 | }; |
michael@0 | 21 | |
michael@0 | 22 | var addon2 = { |
michael@0 | 23 | id: "addon2@tests.mozilla.org", |
michael@0 | 24 | version: "2.0", |
michael@0 | 25 | name: "Test 2", |
michael@0 | 26 | targetApplications: [{ |
michael@0 | 27 | id: "toolkit@mozilla.org", |
michael@0 | 28 | minVersion: "1", |
michael@0 | 29 | maxVersion: "1" |
michael@0 | 30 | }] |
michael@0 | 31 | }; |
michael@0 | 32 | |
michael@0 | 33 | var addon3 = { |
michael@0 | 34 | id: "addon3@tests.mozilla.org", |
michael@0 | 35 | version: "2.0", |
michael@0 | 36 | name: "Test 3", |
michael@0 | 37 | targetApplications: [{ |
michael@0 | 38 | id: "xpcshell@tests.mozilla.org", |
michael@0 | 39 | minVersion: "1", |
michael@0 | 40 | maxVersion: "1" |
michael@0 | 41 | }] |
michael@0 | 42 | }; |
michael@0 | 43 | |
michael@0 | 44 | var addon4 = { |
michael@0 | 45 | id: "addon4@tests.mozilla.org", |
michael@0 | 46 | version: "2.0", |
michael@0 | 47 | name: "Test 4", |
michael@0 | 48 | targetApplications: [{ |
michael@0 | 49 | id: "toolkit@mozilla.org", |
michael@0 | 50 | minVersion: "1", |
michael@0 | 51 | maxVersion: "1" |
michael@0 | 52 | }] |
michael@0 | 53 | }; |
michael@0 | 54 | |
michael@0 | 55 | var addon5 = { |
michael@0 | 56 | id: "addon5@tests.mozilla.org", |
michael@0 | 57 | version: "2.0", |
michael@0 | 58 | name: "Test 5", |
michael@0 | 59 | targetApplications: [{ |
michael@0 | 60 | id: "toolkit@mozilla.org", |
michael@0 | 61 | minVersion: "1", |
michael@0 | 62 | maxVersion: "1" |
michael@0 | 63 | }] |
michael@0 | 64 | }; |
michael@0 | 65 | |
michael@0 | 66 | var theme1 = { |
michael@0 | 67 | id: "theme1@tests.mozilla.org", |
michael@0 | 68 | version: "1.0", |
michael@0 | 69 | name: "Theme 1", |
michael@0 | 70 | type: 4, |
michael@0 | 71 | internalName: "theme1/1.0", |
michael@0 | 72 | targetApplications: [{ |
michael@0 | 73 | id: "xpcshell@tests.mozilla.org", |
michael@0 | 74 | minVersion: "1", |
michael@0 | 75 | maxVersion: "2" |
michael@0 | 76 | }] |
michael@0 | 77 | }; |
michael@0 | 78 | |
michael@0 | 79 | var theme2 = { |
michael@0 | 80 | id: "theme2@tests.mozilla.org", |
michael@0 | 81 | version: "1.0", |
michael@0 | 82 | name: "Theme 2", |
michael@0 | 83 | type: 4, |
michael@0 | 84 | internalName: "theme2/1.0", |
michael@0 | 85 | targetApplications: [{ |
michael@0 | 86 | id: "xpcshell@tests.mozilla.org", |
michael@0 | 87 | minVersion: "1", |
michael@0 | 88 | maxVersion: "2" |
michael@0 | 89 | }] |
michael@0 | 90 | }; |
michael@0 | 91 | |
michael@0 | 92 | const profileDir = gProfD.clone(); |
michael@0 | 93 | profileDir.append("extensions"); |
michael@0 | 94 | |
michael@0 | 95 | function run_test() { |
michael@0 | 96 | do_test_pending(); |
michael@0 | 97 | createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "2", "2"); |
michael@0 | 98 | |
michael@0 | 99 | writeInstallRDFForExtension(addon1, profileDir); |
michael@0 | 100 | writeInstallRDFForExtension(addon2, profileDir); |
michael@0 | 101 | writeInstallRDFForExtension(addon3, profileDir); |
michael@0 | 102 | writeInstallRDFForExtension(addon4, profileDir); |
michael@0 | 103 | writeInstallRDFForExtension(addon5, profileDir); |
michael@0 | 104 | writeInstallRDFForExtension(theme1, profileDir); |
michael@0 | 105 | writeInstallRDFForExtension(theme2, profileDir); |
michael@0 | 106 | |
michael@0 | 107 | // Cannot use the LightweightThemeManager before AddonManager has been started |
michael@0 | 108 | // so inject the correct prefs |
michael@0 | 109 | Services.prefs.setCharPref("lightweightThemes.usedThemes", JSON.stringify([{ |
michael@0 | 110 | id: "1", |
michael@0 | 111 | version: "1", |
michael@0 | 112 | name: "Test LW Theme", |
michael@0 | 113 | description: "A test theme", |
michael@0 | 114 | author: "Mozilla", |
michael@0 | 115 | homepageURL: "http://localhost/data/index.html", |
michael@0 | 116 | headerURL: "http://localhost/data/header.png", |
michael@0 | 117 | footerURL: "http://localhost/data/footer.png", |
michael@0 | 118 | previewURL: "http://localhost/data/preview.png", |
michael@0 | 119 | iconURL: "http://localhost/data/icon.png" |
michael@0 | 120 | }])); |
michael@0 | 121 | Services.prefs.setBoolPref("lightweightThemes.isThemeSelected", true); |
michael@0 | 122 | |
michael@0 | 123 | let stagedXPIs = profileDir.clone(); |
michael@0 | 124 | stagedXPIs.append("staged-xpis"); |
michael@0 | 125 | stagedXPIs.append("addon6@tests.mozilla.org"); |
michael@0 | 126 | stagedXPIs.create(AM_Ci.nsIFile.DIRECTORY_TYPE, 0755); |
michael@0 | 127 | |
michael@0 | 128 | let addon6 = do_get_addon("test_migrate6"); |
michael@0 | 129 | addon6.copyTo(stagedXPIs, "tmp.xpi"); |
michael@0 | 130 | stagedXPIs = stagedXPIs.parent; |
michael@0 | 131 | |
michael@0 | 132 | stagedXPIs.append("addon7@tests.mozilla.org"); |
michael@0 | 133 | stagedXPIs.create(AM_Ci.nsIFile.DIRECTORY_TYPE, 0755); |
michael@0 | 134 | |
michael@0 | 135 | let addon7 = do_get_addon("test_migrate7"); |
michael@0 | 136 | addon7.copyTo(stagedXPIs, "tmp.xpi"); |
michael@0 | 137 | stagedXPIs = stagedXPIs.parent; |
michael@0 | 138 | |
michael@0 | 139 | let old = do_get_file("data/test_migrate.rdf"); |
michael@0 | 140 | old.copyTo(gProfD, "extensions.rdf"); |
michael@0 | 141 | |
michael@0 | 142 | // Theme state is determined by the selected theme pref |
michael@0 | 143 | Services.prefs.setCharPref("general.skins.selectedSkin", "theme1/1.0"); |
michael@0 | 144 | |
michael@0 | 145 | startupManager(); |
michael@0 | 146 | check_startup_changes("installed", []); |
michael@0 | 147 | check_startup_changes("updated", []); |
michael@0 | 148 | check_startup_changes("uninstalled", []); |
michael@0 | 149 | check_startup_changes("disabled", []); |
michael@0 | 150 | check_startup_changes("enabled", []); |
michael@0 | 151 | |
michael@0 | 152 | AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org", |
michael@0 | 153 | "addon2@tests.mozilla.org", |
michael@0 | 154 | "addon3@tests.mozilla.org", |
michael@0 | 155 | "addon4@tests.mozilla.org", |
michael@0 | 156 | "addon5@tests.mozilla.org", |
michael@0 | 157 | "addon6@tests.mozilla.org", |
michael@0 | 158 | "addon7@tests.mozilla.org", |
michael@0 | 159 | "theme1@tests.mozilla.org", |
michael@0 | 160 | "theme2@tests.mozilla.org"], function([a1, a2, a3, |
michael@0 | 161 | a4, a5, a6, |
michael@0 | 162 | a7, t1, t2]) { |
michael@0 | 163 | // addon1 was user and app enabled in the old extensions.rdf |
michael@0 | 164 | do_check_neq(a1, null); |
michael@0 | 165 | do_check_false(a1.userDisabled); |
michael@0 | 166 | do_check_false(a1.appDisabled); |
michael@0 | 167 | do_check_true(a1.isActive); |
michael@0 | 168 | do_check_true(isExtensionInAddonsList(profileDir, a1.id)); |
michael@0 | 169 | |
michael@0 | 170 | // addon2 was user disabled and app enabled in the old extensions.rdf |
michael@0 | 171 | do_check_neq(a2, null); |
michael@0 | 172 | do_check_true(a2.userDisabled); |
michael@0 | 173 | do_check_false(a2.appDisabled); |
michael@0 | 174 | do_check_false(a2.isActive); |
michael@0 | 175 | do_check_false(isExtensionInAddonsList(profileDir, a2.id)); |
michael@0 | 176 | |
michael@0 | 177 | // addon3 was pending user disable and app disabled in the old extensions.rdf |
michael@0 | 178 | do_check_neq(a3, null); |
michael@0 | 179 | do_check_true(a3.userDisabled); |
michael@0 | 180 | do_check_true(a3.appDisabled); |
michael@0 | 181 | do_check_false(a3.isActive); |
michael@0 | 182 | do_check_false(isExtensionInAddonsList(profileDir, a3.id)); |
michael@0 | 183 | |
michael@0 | 184 | // addon4 was pending user enable and app disabled in the old extensions.rdf |
michael@0 | 185 | do_check_neq(a4, null); |
michael@0 | 186 | do_check_false(a4.userDisabled); |
michael@0 | 187 | do_check_true(a4.appDisabled); |
michael@0 | 188 | do_check_false(a4.isActive); |
michael@0 | 189 | do_check_false(isExtensionInAddonsList(profileDir, a4.id)); |
michael@0 | 190 | |
michael@0 | 191 | // addon5 was disabled and compatible but a new version has been installed |
michael@0 | 192 | // since, it should still be disabled but should be incompatible |
michael@0 | 193 | do_check_neq(a5, null); |
michael@0 | 194 | do_check_true(a5.userDisabled); |
michael@0 | 195 | do_check_true(a5.appDisabled); |
michael@0 | 196 | do_check_false(a5.isActive); |
michael@0 | 197 | do_check_false(isExtensionInAddonsList(profileDir, a5.id)); |
michael@0 | 198 | |
michael@0 | 199 | // addon6 should be installed and compatible and packed unless unpacking is |
michael@0 | 200 | // forced |
michael@0 | 201 | do_check_neq(a6, null); |
michael@0 | 202 | do_check_false(a6.userDisabled); |
michael@0 | 203 | do_check_false(a6.appDisabled); |
michael@0 | 204 | do_check_true(a6.isActive); |
michael@0 | 205 | do_check_true(isExtensionInAddonsList(profileDir, a6.id)); |
michael@0 | 206 | if (Services.prefs.getBoolPref("extensions.alwaysUnpack")) |
michael@0 | 207 | do_check_eq(a6.getResourceURI("install.rdf").scheme, "file"); |
michael@0 | 208 | else |
michael@0 | 209 | do_check_eq(a6.getResourceURI("install.rdf").scheme, "jar"); |
michael@0 | 210 | |
michael@0 | 211 | // addon7 should be installed and compatible and unpacked |
michael@0 | 212 | do_check_neq(a7, null); |
michael@0 | 213 | do_check_false(a7.userDisabled); |
michael@0 | 214 | do_check_false(a7.appDisabled); |
michael@0 | 215 | do_check_true(a7.isActive); |
michael@0 | 216 | do_check_true(isExtensionInAddonsList(profileDir, a7.id)); |
michael@0 | 217 | do_check_eq(a7.getResourceURI("install.rdf").scheme, "file"); |
michael@0 | 218 | |
michael@0 | 219 | // Theme 1 was previously disabled |
michael@0 | 220 | do_check_neq(t1, null); |
michael@0 | 221 | do_check_true(t1.userDisabled); |
michael@0 | 222 | do_check_false(t1.appDisabled); |
michael@0 | 223 | do_check_false(t1.isActive); |
michael@0 | 224 | do_check_true(isThemeInAddonsList(profileDir, t1.id)); |
michael@0 | 225 | do_check_true(hasFlag(t1.permissions, AddonManager.PERM_CAN_ENABLE)); |
michael@0 | 226 | |
michael@0 | 227 | // Theme 2 was previously disabled |
michael@0 | 228 | do_check_neq(t1, null); |
michael@0 | 229 | do_check_true(t2.userDisabled); |
michael@0 | 230 | do_check_false(t2.appDisabled); |
michael@0 | 231 | do_check_false(t2.isActive); |
michael@0 | 232 | do_check_false(isThemeInAddonsList(profileDir, t2.id)); |
michael@0 | 233 | do_check_true(hasFlag(t2.permissions, AddonManager.PERM_CAN_ENABLE)); |
michael@0 | 234 | |
michael@0 | 235 | do_check_false(stagedXPIs.exists()); |
michael@0 | 236 | |
michael@0 | 237 | do_execute_soon(do_test_finished); |
michael@0 | 238 | }); |
michael@0 | 239 | } |