Sat, 03 Jan 2015 20:18:00 +0100
Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.
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 | Components.utils.import("resource://gre/modules/NetUtil.jsm"); |
michael@0 | 6 | |
michael@0 | 7 | // The maximum allowable time since install. If an add-on claims to have been |
michael@0 | 8 | // installed longer ago than this the the test will fail. |
michael@0 | 9 | const MAX_INSTALL_TIME = 10000; |
michael@0 | 10 | |
michael@0 | 11 | // This verifies that themes behave as expected |
michael@0 | 12 | |
michael@0 | 13 | const PREF_GENERAL_SKINS_SELECTEDSKIN = "general.skins.selectedSkin"; |
michael@0 | 14 | |
michael@0 | 15 | Components.utils.import("resource://gre/modules/LightweightThemeManager.jsm"); |
michael@0 | 16 | |
michael@0 | 17 | const profileDir = gProfD.clone(); |
michael@0 | 18 | profileDir.append("extensions"); |
michael@0 | 19 | |
michael@0 | 20 | // Observer to ensure a "lightweight-theme-styling-update" notification is sent |
michael@0 | 21 | // when expected |
michael@0 | 22 | var gLWThemeChanged = false; |
michael@0 | 23 | var LightweightThemeObserver = { |
michael@0 | 24 | observe: function(aSubject, aTopic, aData) { |
michael@0 | 25 | if (aTopic != "lightweight-theme-styling-update") |
michael@0 | 26 | return; |
michael@0 | 27 | |
michael@0 | 28 | gLWThemeChanged = true; |
michael@0 | 29 | } |
michael@0 | 30 | }; |
michael@0 | 31 | |
michael@0 | 32 | AM_Cc["@mozilla.org/observer-service;1"] |
michael@0 | 33 | .getService(Components.interfaces.nsIObserverService) |
michael@0 | 34 | .addObserver(LightweightThemeObserver, "lightweight-theme-styling-update", false); |
michael@0 | 35 | |
michael@0 | 36 | |
michael@0 | 37 | function run_test() { |
michael@0 | 38 | do_test_pending(); |
michael@0 | 39 | createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2"); |
michael@0 | 40 | |
michael@0 | 41 | Services.prefs.setCharPref(PREF_GENERAL_SKINS_SELECTEDSKIN, "theme1/1.0"); |
michael@0 | 42 | writeInstallRDFForExtension({ |
michael@0 | 43 | id: "theme1@tests.mozilla.org", |
michael@0 | 44 | version: "1.0", |
michael@0 | 45 | name: "Test 1", |
michael@0 | 46 | type: 4, |
michael@0 | 47 | skinnable: true, |
michael@0 | 48 | internalName: "theme1/1.0", |
michael@0 | 49 | targetApplications: [{ |
michael@0 | 50 | id: "xpcshell@tests.mozilla.org", |
michael@0 | 51 | minVersion: "1", |
michael@0 | 52 | maxVersion: "2" |
michael@0 | 53 | }] |
michael@0 | 54 | }, profileDir); |
michael@0 | 55 | |
michael@0 | 56 | writeInstallRDFForExtension({ |
michael@0 | 57 | id: "theme2@tests.mozilla.org", |
michael@0 | 58 | version: "1.0", |
michael@0 | 59 | name: "Test 1", |
michael@0 | 60 | skinnable: false, |
michael@0 | 61 | internalName: "theme2/1.0", |
michael@0 | 62 | targetApplications: [{ |
michael@0 | 63 | id: "xpcshell@tests.mozilla.org", |
michael@0 | 64 | minVersion: "1", |
michael@0 | 65 | maxVersion: "2" |
michael@0 | 66 | }] |
michael@0 | 67 | }, profileDir); |
michael@0 | 68 | |
michael@0 | 69 | // We need a default theme for some of these things to work but we have hidden |
michael@0 | 70 | // the one in the application directory. |
michael@0 | 71 | writeInstallRDFForExtension({ |
michael@0 | 72 | id: "default@tests.mozilla.org", |
michael@0 | 73 | version: "1.0", |
michael@0 | 74 | name: "Default", |
michael@0 | 75 | internalName: "classic/1.0", |
michael@0 | 76 | targetApplications: [{ |
michael@0 | 77 | id: "xpcshell@tests.mozilla.org", |
michael@0 | 78 | minVersion: "1", |
michael@0 | 79 | maxVersion: "2" |
michael@0 | 80 | }] |
michael@0 | 81 | }, profileDir); |
michael@0 | 82 | |
michael@0 | 83 | startupManager(); |
michael@0 | 84 | // Make sure we only register once despite multiple calls |
michael@0 | 85 | AddonManager.addInstallListener(InstallListener); |
michael@0 | 86 | AddonManager.addAddonListener(AddonListener); |
michael@0 | 87 | AddonManager.addInstallListener(InstallListener); |
michael@0 | 88 | AddonManager.addAddonListener(AddonListener); |
michael@0 | 89 | AddonManager.addInstallListener(InstallListener); |
michael@0 | 90 | |
michael@0 | 91 | AddonManager.getAddonsByIDs(["default@tests.mozilla.org", |
michael@0 | 92 | "theme1@tests.mozilla.org", |
michael@0 | 93 | "theme2@tests.mozilla.org"], |
michael@0 | 94 | function([d, t1, t2]) { |
michael@0 | 95 | do_check_neq(d, null); |
michael@0 | 96 | do_check_false(d.skinnable); |
michael@0 | 97 | do_check_false(d.foreignInstall); |
michael@0 | 98 | |
michael@0 | 99 | do_check_neq(t1, null); |
michael@0 | 100 | do_check_false(t1.userDisabled); |
michael@0 | 101 | do_check_false(t1.appDisabled); |
michael@0 | 102 | do_check_true(t1.isActive); |
michael@0 | 103 | do_check_true(t1.skinnable); |
michael@0 | 104 | do_check_true(t1.foreignInstall); |
michael@0 | 105 | do_check_eq(t1.screenshots, null); |
michael@0 | 106 | do_check_true(isThemeInAddonsList(profileDir, t1.id)); |
michael@0 | 107 | do_check_false(hasFlag(t1.permissions, AddonManager.PERM_CAN_DISABLE)); |
michael@0 | 108 | do_check_false(hasFlag(t1.permissions, AddonManager.PERM_CAN_ENABLE)); |
michael@0 | 109 | do_check_eq(t1.operationsRequiringRestart, AddonManager.OP_NEEDS_RESTART_UNINSTALL | |
michael@0 | 110 | AddonManager.OP_NEEDS_RESTART_DISABLE); |
michael@0 | 111 | |
michael@0 | 112 | do_check_neq(t2, null); |
michael@0 | 113 | do_check_true(t2.userDisabled); |
michael@0 | 114 | do_check_false(t2.appDisabled); |
michael@0 | 115 | do_check_false(t2.isActive); |
michael@0 | 116 | do_check_false(t2.skinnable); |
michael@0 | 117 | do_check_true(t2.foreignInstall); |
michael@0 | 118 | do_check_eq(t2.screenshots, null); |
michael@0 | 119 | do_check_false(isThemeInAddonsList(profileDir, t2.id)); |
michael@0 | 120 | do_check_false(hasFlag(t2.permissions, AddonManager.PERM_CAN_DISABLE)); |
michael@0 | 121 | do_check_true(hasFlag(t2.permissions, AddonManager.PERM_CAN_ENABLE)); |
michael@0 | 122 | do_check_eq(t2.operationsRequiringRestart, AddonManager.OP_NEEDS_RESTART_ENABLE); |
michael@0 | 123 | |
michael@0 | 124 | do_execute_soon(run_test_1); |
michael@0 | 125 | }); |
michael@0 | 126 | } |
michael@0 | 127 | |
michael@0 | 128 | function end_test() { |
michael@0 | 129 | do_execute_soon(do_test_finished); |
michael@0 | 130 | } |
michael@0 | 131 | |
michael@0 | 132 | // Checks enabling one theme disables the others |
michael@0 | 133 | function run_test_1() { |
michael@0 | 134 | prepare_test({ |
michael@0 | 135 | "theme1@tests.mozilla.org": [ |
michael@0 | 136 | "onDisabling" |
michael@0 | 137 | ], |
michael@0 | 138 | "theme2@tests.mozilla.org": [ |
michael@0 | 139 | "onEnabling" |
michael@0 | 140 | ] |
michael@0 | 141 | }); |
michael@0 | 142 | AddonManager.getAddonsByIDs(["theme1@tests.mozilla.org", |
michael@0 | 143 | "theme2@tests.mozilla.org"], function([t1, t2]) { |
michael@0 | 144 | t2.userDisabled = false; |
michael@0 | 145 | |
michael@0 | 146 | ensure_test_completed(); |
michael@0 | 147 | do_check_false(hasFlag(t2.permissions, AddonManager.PERM_CAN_DISABLE)); |
michael@0 | 148 | do_check_false(hasFlag(t2.permissions, AddonManager.PERM_CAN_ENABLE)); |
michael@0 | 149 | |
michael@0 | 150 | do_check_true(t1.userDisabled); |
michael@0 | 151 | do_check_false(hasFlag(t1.permissions, AddonManager.PERM_CAN_DISABLE)); |
michael@0 | 152 | do_check_true(hasFlag(t1.permissions, AddonManager.PERM_CAN_ENABLE)); |
michael@0 | 153 | |
michael@0 | 154 | do_execute_soon(check_test_1); |
michael@0 | 155 | }); |
michael@0 | 156 | } |
michael@0 | 157 | |
michael@0 | 158 | function check_test_1() { |
michael@0 | 159 | restartManager(); |
michael@0 | 160 | do_check_eq(Services.prefs.getCharPref(PREF_GENERAL_SKINS_SELECTEDSKIN), "theme2/1.0"); |
michael@0 | 161 | |
michael@0 | 162 | AddonManager.getAddonsByIDs(["theme1@tests.mozilla.org", |
michael@0 | 163 | "theme2@tests.mozilla.org"], function([t1, t2]) { |
michael@0 | 164 | do_check_neq(t1, null); |
michael@0 | 165 | do_check_true(t1.userDisabled); |
michael@0 | 166 | do_check_false(t1.appDisabled); |
michael@0 | 167 | do_check_false(t1.isActive); |
michael@0 | 168 | do_check_false(isThemeInAddonsList(profileDir, t1.id)); |
michael@0 | 169 | do_check_false(hasFlag(t1.permissions, AddonManager.PERM_CAN_DISABLE)); |
michael@0 | 170 | do_check_true(hasFlag(t1.permissions, AddonManager.PERM_CAN_ENABLE)); |
michael@0 | 171 | do_check_eq(t1.operationsRequiringRestart, AddonManager.OP_NEEDS_RESTART_ENABLE); |
michael@0 | 172 | |
michael@0 | 173 | do_check_neq(t2, null); |
michael@0 | 174 | do_check_false(t2.userDisabled); |
michael@0 | 175 | do_check_false(t2.appDisabled); |
michael@0 | 176 | do_check_true(t2.isActive); |
michael@0 | 177 | do_check_true(isThemeInAddonsList(profileDir, t2.id)); |
michael@0 | 178 | do_check_false(hasFlag(t2.permissions, AddonManager.PERM_CAN_DISABLE)); |
michael@0 | 179 | do_check_false(hasFlag(t2.permissions, AddonManager.PERM_CAN_ENABLE)); |
michael@0 | 180 | do_check_eq(t2.operationsRequiringRestart, AddonManager.OP_NEEDS_RESTART_UNINSTALL | |
michael@0 | 181 | AddonManager.OP_NEEDS_RESTART_DISABLE); |
michael@0 | 182 | do_check_false(gLWThemeChanged); |
michael@0 | 183 | |
michael@0 | 184 | do_execute_soon(run_test_2); |
michael@0 | 185 | }); |
michael@0 | 186 | } |
michael@0 | 187 | |
michael@0 | 188 | // Removing the active theme should fall back to the default (not ideal in this |
michael@0 | 189 | // case since we don't have the default theme installed) |
michael@0 | 190 | function run_test_2() { |
michael@0 | 191 | var dest = profileDir.clone(); |
michael@0 | 192 | dest.append(do_get_expected_addon_name("theme2@tests.mozilla.org")); |
michael@0 | 193 | dest.remove(true); |
michael@0 | 194 | |
michael@0 | 195 | restartManager(); |
michael@0 | 196 | do_check_eq(Services.prefs.getCharPref(PREF_GENERAL_SKINS_SELECTEDSKIN), "classic/1.0"); |
michael@0 | 197 | |
michael@0 | 198 | AddonManager.getAddonsByIDs(["theme1@tests.mozilla.org", |
michael@0 | 199 | "theme2@tests.mozilla.org"], function([t1, t2]) { |
michael@0 | 200 | do_check_neq(t1, null); |
michael@0 | 201 | do_check_true(t1.userDisabled); |
michael@0 | 202 | do_check_false(t1.appDisabled); |
michael@0 | 203 | do_check_false(t1.isActive); |
michael@0 | 204 | do_check_false(isThemeInAddonsList(profileDir, t1.id)); |
michael@0 | 205 | do_check_false(hasFlag(t1.permissions, AddonManager.PERM_CAN_DISABLE)); |
michael@0 | 206 | do_check_true(hasFlag(t1.permissions, AddonManager.PERM_CAN_ENABLE)); |
michael@0 | 207 | |
michael@0 | 208 | do_check_eq(t2, null); |
michael@0 | 209 | do_check_false(isThemeInAddonsList(profileDir, "theme2@tests.mozilla.org")); |
michael@0 | 210 | do_check_false(gLWThemeChanged); |
michael@0 | 211 | |
michael@0 | 212 | do_execute_soon(run_test_3); |
michael@0 | 213 | }); |
michael@0 | 214 | } |
michael@0 | 215 | |
michael@0 | 216 | // Installing a lightweight theme should happen instantly and disable the default theme |
michael@0 | 217 | function run_test_3() { |
michael@0 | 218 | writeInstallRDFForExtension({ |
michael@0 | 219 | id: "theme2@tests.mozilla.org", |
michael@0 | 220 | version: "1.0", |
michael@0 | 221 | name: "Test 1", |
michael@0 | 222 | internalName: "theme2/1.0", |
michael@0 | 223 | targetApplications: [{ |
michael@0 | 224 | id: "xpcshell@tests.mozilla.org", |
michael@0 | 225 | minVersion: "1", |
michael@0 | 226 | maxVersion: "2" |
michael@0 | 227 | }] |
michael@0 | 228 | }, profileDir); |
michael@0 | 229 | restartManager(); |
michael@0 | 230 | |
michael@0 | 231 | prepare_test({ |
michael@0 | 232 | "1@personas.mozilla.org": [ |
michael@0 | 233 | ["onInstalling", false], |
michael@0 | 234 | "onInstalled", |
michael@0 | 235 | ["onEnabling", false], |
michael@0 | 236 | "onEnabled" |
michael@0 | 237 | ], |
michael@0 | 238 | "default@tests.mozilla.org": [ |
michael@0 | 239 | ["onDisabling", false], |
michael@0 | 240 | "onDisabled", |
michael@0 | 241 | ] |
michael@0 | 242 | }, [ |
michael@0 | 243 | "onExternalInstall" |
michael@0 | 244 | ]); |
michael@0 | 245 | |
michael@0 | 246 | LightweightThemeManager.currentTheme = { |
michael@0 | 247 | id: "1", |
michael@0 | 248 | version: "1", |
michael@0 | 249 | name: "Test LW Theme", |
michael@0 | 250 | description: "A test theme", |
michael@0 | 251 | author: "Mozilla", |
michael@0 | 252 | homepageURL: "http://localhost/data/index.html", |
michael@0 | 253 | headerURL: "http://localhost/data/header.png", |
michael@0 | 254 | footerURL: "http://localhost/data/footer.png", |
michael@0 | 255 | previewURL: "http://localhost/data/preview.png", |
michael@0 | 256 | iconURL: "http://localhost/data/icon.png" |
michael@0 | 257 | }; |
michael@0 | 258 | |
michael@0 | 259 | ensure_test_completed(); |
michael@0 | 260 | |
michael@0 | 261 | AddonManager.getAddonByID("1@personas.mozilla.org", function(p1) { |
michael@0 | 262 | do_check_neq(null, p1); |
michael@0 | 263 | do_check_eq(p1.name, "Test LW Theme"); |
michael@0 | 264 | do_check_eq(p1.version, "1"); |
michael@0 | 265 | do_check_eq(p1.type, "theme"); |
michael@0 | 266 | do_check_eq(p1.description, "A test theme"); |
michael@0 | 267 | do_check_eq(p1.creator, "Mozilla"); |
michael@0 | 268 | do_check_eq(p1.homepageURL, "http://localhost/data/index.html"); |
michael@0 | 269 | do_check_eq(p1.iconURL, "http://localhost/data/icon.png"); |
michael@0 | 270 | do_check_eq(p1.screenshots.length, 1); |
michael@0 | 271 | do_check_eq(p1.screenshots[0], "http://localhost/data/preview.png"); |
michael@0 | 272 | do_check_false(p1.appDisabled); |
michael@0 | 273 | do_check_false(p1.userDisabled); |
michael@0 | 274 | do_check_true(p1.isCompatible); |
michael@0 | 275 | do_check_true(p1.providesUpdatesSecurely); |
michael@0 | 276 | do_check_eq(p1.blocklistState, 0); |
michael@0 | 277 | do_check_true(p1.isActive); |
michael@0 | 278 | do_check_eq(p1.pendingOperations, 0); |
michael@0 | 279 | do_check_eq(p1.permissions, AddonManager.PERM_CAN_UNINSTALL | AddonManager.PERM_CAN_DISABLE); |
michael@0 | 280 | do_check_eq(p1.scope, AddonManager.SCOPE_PROFILE); |
michael@0 | 281 | do_check_true("isCompatibleWith" in p1); |
michael@0 | 282 | do_check_true("findUpdates" in p1); |
michael@0 | 283 | do_check_eq(p1.installDate.getTime(), p1.updateDate.getTime()); |
michael@0 | 284 | |
michael@0 | 285 | // Should have been installed sometime in the last few seconds. |
michael@0 | 286 | let difference = Date.now() - p1.installDate.getTime(); |
michael@0 | 287 | if (difference > MAX_INSTALL_TIME) |
michael@0 | 288 | do_throw("Add-on was installed " + difference + "ms ago"); |
michael@0 | 289 | else if (difference < 0) |
michael@0 | 290 | do_throw("Add-on was installed " + difference + "ms in the future"); |
michael@0 | 291 | |
michael@0 | 292 | AddonManager.getAddonsByTypes(["theme"], function(addons) { |
michael@0 | 293 | let seen = false; |
michael@0 | 294 | addons.forEach(function(a) { |
michael@0 | 295 | if (a.id == "1@personas.mozilla.org") { |
michael@0 | 296 | seen = true; |
michael@0 | 297 | } |
michael@0 | 298 | else { |
michael@0 | 299 | dump("Checking theme " + a.id + "\n"); |
michael@0 | 300 | do_check_false(a.isActive); |
michael@0 | 301 | do_check_true(a.userDisabled); |
michael@0 | 302 | } |
michael@0 | 303 | }); |
michael@0 | 304 | do_check_true(seen); |
michael@0 | 305 | |
michael@0 | 306 | do_check_true(gLWThemeChanged); |
michael@0 | 307 | gLWThemeChanged = false; |
michael@0 | 308 | |
michael@0 | 309 | do_execute_soon(run_test_4); |
michael@0 | 310 | }); |
michael@0 | 311 | }); |
michael@0 | 312 | } |
michael@0 | 313 | |
michael@0 | 314 | // Installing a second lightweight theme should disable the first with no restart |
michael@0 | 315 | function run_test_4() { |
michael@0 | 316 | prepare_test({ |
michael@0 | 317 | "1@personas.mozilla.org": [ |
michael@0 | 318 | ["onDisabling", false], |
michael@0 | 319 | "onDisabled", |
michael@0 | 320 | ], |
michael@0 | 321 | "2@personas.mozilla.org": [ |
michael@0 | 322 | ["onInstalling", false], |
michael@0 | 323 | "onInstalled", |
michael@0 | 324 | ["onEnabling", false], |
michael@0 | 325 | "onEnabled" |
michael@0 | 326 | ] |
michael@0 | 327 | }, [ |
michael@0 | 328 | "onExternalInstall" |
michael@0 | 329 | ]); |
michael@0 | 330 | |
michael@0 | 331 | LightweightThemeManager.currentTheme = { |
michael@0 | 332 | id: "2", |
michael@0 | 333 | version: "1", |
michael@0 | 334 | name: "Test LW Theme", |
michael@0 | 335 | description: "A second test theme", |
michael@0 | 336 | author: "Mozilla", |
michael@0 | 337 | homepageURL: "http://localhost/data/index.html", |
michael@0 | 338 | headerURL: "http://localhost/data/header.png", |
michael@0 | 339 | footerURL: "http://localhost/data/footer.png", |
michael@0 | 340 | previewURL: "http://localhost/data/preview.png", |
michael@0 | 341 | iconURL: "http://localhost/data/icon.png" |
michael@0 | 342 | }; |
michael@0 | 343 | |
michael@0 | 344 | ensure_test_completed(); |
michael@0 | 345 | |
michael@0 | 346 | AddonManager.getAddonsByIDs(["1@personas.mozilla.org", |
michael@0 | 347 | "2@personas.mozilla.org"], function([p1, p2]) { |
michael@0 | 348 | do_check_neq(null, p2); |
michael@0 | 349 | do_check_false(p2.appDisabled); |
michael@0 | 350 | do_check_false(p2.userDisabled); |
michael@0 | 351 | do_check_true(p2.isActive); |
michael@0 | 352 | do_check_eq(p2.pendingOperations, 0); |
michael@0 | 353 | do_check_eq(p2.permissions, AddonManager.PERM_CAN_UNINSTALL | AddonManager.PERM_CAN_DISABLE); |
michael@0 | 354 | do_check_eq(p2.installDate.getTime(), p2.updateDate.getTime()); |
michael@0 | 355 | |
michael@0 | 356 | // Should have been installed sometime in the last few seconds. |
michael@0 | 357 | let difference = Date.now() - p2.installDate.getTime(); |
michael@0 | 358 | if (difference > MAX_INSTALL_TIME) |
michael@0 | 359 | do_throw("Add-on was installed " + difference + "ms ago"); |
michael@0 | 360 | else if (difference < 0) |
michael@0 | 361 | do_throw("Add-on was installed " + difference + "ms in the future"); |
michael@0 | 362 | |
michael@0 | 363 | do_check_neq(null, p1); |
michael@0 | 364 | do_check_false(p1.appDisabled); |
michael@0 | 365 | do_check_true(p1.userDisabled); |
michael@0 | 366 | do_check_false(p1.isActive); |
michael@0 | 367 | do_check_eq(p1.pendingOperations, 0); |
michael@0 | 368 | do_check_eq(p1.permissions, AddonManager.PERM_CAN_UNINSTALL | AddonManager.PERM_CAN_ENABLE); |
michael@0 | 369 | |
michael@0 | 370 | AddonManager.getAddonsByTypes(["theme"], function(addons) { |
michael@0 | 371 | let seen = false; |
michael@0 | 372 | addons.forEach(function(a) { |
michael@0 | 373 | if (a.id == "2@personas.mozilla.org") { |
michael@0 | 374 | seen = true; |
michael@0 | 375 | } |
michael@0 | 376 | else { |
michael@0 | 377 | dump("Checking theme " + a.id + "\n"); |
michael@0 | 378 | do_check_false(a.isActive); |
michael@0 | 379 | do_check_true(a.userDisabled); |
michael@0 | 380 | } |
michael@0 | 381 | }); |
michael@0 | 382 | do_check_true(seen); |
michael@0 | 383 | |
michael@0 | 384 | do_check_true(gLWThemeChanged); |
michael@0 | 385 | gLWThemeChanged = false; |
michael@0 | 386 | |
michael@0 | 387 | do_execute_soon(run_test_5); |
michael@0 | 388 | }); |
michael@0 | 389 | }); |
michael@0 | 390 | } |
michael@0 | 391 | |
michael@0 | 392 | // Switching to a custom theme should disable the lightweight theme and require |
michael@0 | 393 | // a restart. Cancelling that should also be possible. |
michael@0 | 394 | function run_test_5() { |
michael@0 | 395 | prepare_test({ |
michael@0 | 396 | "2@personas.mozilla.org": [ |
michael@0 | 397 | "onDisabling", |
michael@0 | 398 | ], |
michael@0 | 399 | "theme2@tests.mozilla.org": [ |
michael@0 | 400 | "onEnabling" |
michael@0 | 401 | ] |
michael@0 | 402 | }); |
michael@0 | 403 | |
michael@0 | 404 | AddonManager.getAddonsByIDs(["2@personas.mozilla.org", |
michael@0 | 405 | "theme2@tests.mozilla.org"], function([p2, t2]) { |
michael@0 | 406 | t2.userDisabled = false; |
michael@0 | 407 | |
michael@0 | 408 | ensure_test_completed(); |
michael@0 | 409 | |
michael@0 | 410 | prepare_test({ |
michael@0 | 411 | "2@personas.mozilla.org": [ |
michael@0 | 412 | "onOperationCancelled", |
michael@0 | 413 | ], |
michael@0 | 414 | "theme2@tests.mozilla.org": [ |
michael@0 | 415 | "onOperationCancelled" |
michael@0 | 416 | ] |
michael@0 | 417 | }); |
michael@0 | 418 | |
michael@0 | 419 | p2.userDisabled = false; |
michael@0 | 420 | |
michael@0 | 421 | ensure_test_completed(); |
michael@0 | 422 | |
michael@0 | 423 | prepare_test({ |
michael@0 | 424 | "2@personas.mozilla.org": [ |
michael@0 | 425 | "onDisabling", |
michael@0 | 426 | ], |
michael@0 | 427 | "theme2@tests.mozilla.org": [ |
michael@0 | 428 | "onEnabling" |
michael@0 | 429 | ] |
michael@0 | 430 | }); |
michael@0 | 431 | |
michael@0 | 432 | t2.userDisabled = false; |
michael@0 | 433 | |
michael@0 | 434 | ensure_test_completed(); |
michael@0 | 435 | |
michael@0 | 436 | do_check_false(t2.isActive); |
michael@0 | 437 | do_check_false(t2.userDisabled); |
michael@0 | 438 | do_check_true(hasFlag(AddonManager.PENDING_ENABLE, t2.pendingOperations)); |
michael@0 | 439 | do_check_true(p2.isActive); |
michael@0 | 440 | do_check_true(p2.userDisabled); |
michael@0 | 441 | do_check_true(hasFlag(AddonManager.PENDING_DISABLE, p2.pendingOperations)); |
michael@0 | 442 | do_check_true(hasFlag(AddonManager.PERM_CAN_ENABLE, p2.permissions)); |
michael@0 | 443 | do_check_false(gLWThemeChanged); |
michael@0 | 444 | |
michael@0 | 445 | do_execute_soon(check_test_5); |
michael@0 | 446 | }); |
michael@0 | 447 | } |
michael@0 | 448 | |
michael@0 | 449 | function check_test_5() { |
michael@0 | 450 | restartManager(); |
michael@0 | 451 | |
michael@0 | 452 | AddonManager.getAddonsByIDs(["2@personas.mozilla.org", |
michael@0 | 453 | "theme2@tests.mozilla.org"], function([p2, t2]) { |
michael@0 | 454 | do_check_true(t2.isActive); |
michael@0 | 455 | do_check_false(t2.userDisabled); |
michael@0 | 456 | do_check_false(hasFlag(AddonManager.PENDING_ENABLE, t2.pendingOperations)); |
michael@0 | 457 | do_check_false(p2.isActive); |
michael@0 | 458 | do_check_true(p2.userDisabled); |
michael@0 | 459 | do_check_false(hasFlag(AddonManager.PENDING_DISABLE, p2.pendingOperations)); |
michael@0 | 460 | |
michael@0 | 461 | do_check_true(gLWThemeChanged); |
michael@0 | 462 | gLWThemeChanged = false; |
michael@0 | 463 | |
michael@0 | 464 | do_execute_soon(run_test_6); |
michael@0 | 465 | }); |
michael@0 | 466 | } |
michael@0 | 467 | |
michael@0 | 468 | // Switching from a custom theme to a lightweight theme should require a restart |
michael@0 | 469 | function run_test_6() { |
michael@0 | 470 | prepare_test({ |
michael@0 | 471 | "2@personas.mozilla.org": [ |
michael@0 | 472 | "onEnabling", |
michael@0 | 473 | ], |
michael@0 | 474 | "theme2@tests.mozilla.org": [ |
michael@0 | 475 | "onDisabling" |
michael@0 | 476 | ] |
michael@0 | 477 | }); |
michael@0 | 478 | |
michael@0 | 479 | AddonManager.getAddonsByIDs(["2@personas.mozilla.org", |
michael@0 | 480 | "theme2@tests.mozilla.org"], function([p2, t2]) { |
michael@0 | 481 | p2.userDisabled = false; |
michael@0 | 482 | |
michael@0 | 483 | ensure_test_completed(); |
michael@0 | 484 | |
michael@0 | 485 | prepare_test({ |
michael@0 | 486 | "2@personas.mozilla.org": [ |
michael@0 | 487 | "onOperationCancelled", |
michael@0 | 488 | ], |
michael@0 | 489 | "theme2@tests.mozilla.org": [ |
michael@0 | 490 | "onOperationCancelled" |
michael@0 | 491 | ] |
michael@0 | 492 | }); |
michael@0 | 493 | |
michael@0 | 494 | t2.userDisabled = false; |
michael@0 | 495 | |
michael@0 | 496 | ensure_test_completed(); |
michael@0 | 497 | |
michael@0 | 498 | prepare_test({ |
michael@0 | 499 | "2@personas.mozilla.org": [ |
michael@0 | 500 | "onEnabling", |
michael@0 | 501 | ], |
michael@0 | 502 | "theme2@tests.mozilla.org": [ |
michael@0 | 503 | "onDisabling" |
michael@0 | 504 | ] |
michael@0 | 505 | }); |
michael@0 | 506 | |
michael@0 | 507 | p2.userDisabled = false; |
michael@0 | 508 | |
michael@0 | 509 | ensure_test_completed(); |
michael@0 | 510 | |
michael@0 | 511 | do_check_false(p2.isActive); |
michael@0 | 512 | do_check_false(p2.userDisabled); |
michael@0 | 513 | do_check_true(hasFlag(AddonManager.PENDING_ENABLE, p2.pendingOperations)); |
michael@0 | 514 | do_check_true(t2.isActive); |
michael@0 | 515 | do_check_true(t2.userDisabled); |
michael@0 | 516 | do_check_true(hasFlag(AddonManager.PENDING_DISABLE, t2.pendingOperations)); |
michael@0 | 517 | do_check_false(gLWThemeChanged); |
michael@0 | 518 | |
michael@0 | 519 | do_execute_soon(check_test_6); |
michael@0 | 520 | }); |
michael@0 | 521 | } |
michael@0 | 522 | |
michael@0 | 523 | function check_test_6() { |
michael@0 | 524 | restartManager(); |
michael@0 | 525 | |
michael@0 | 526 | AddonManager.getAddonsByIDs(["2@personas.mozilla.org", |
michael@0 | 527 | "theme2@tests.mozilla.org"], function([p2, t2]) { |
michael@0 | 528 | do_check_true(p2.isActive); |
michael@0 | 529 | do_check_false(p2.userDisabled); |
michael@0 | 530 | do_check_false(hasFlag(AddonManager.PENDING_ENABLE, p2.pendingOperations)); |
michael@0 | 531 | do_check_false(t2.isActive); |
michael@0 | 532 | do_check_true(t2.userDisabled); |
michael@0 | 533 | do_check_false(hasFlag(AddonManager.PENDING_DISABLE, t2.pendingOperations)); |
michael@0 | 534 | |
michael@0 | 535 | do_check_true(gLWThemeChanged); |
michael@0 | 536 | gLWThemeChanged = false; |
michael@0 | 537 | |
michael@0 | 538 | do_execute_soon(run_test_7); |
michael@0 | 539 | }); |
michael@0 | 540 | } |
michael@0 | 541 | |
michael@0 | 542 | // Uninstalling a lightweight theme should not require a restart |
michael@0 | 543 | function run_test_7() { |
michael@0 | 544 | prepare_test({ |
michael@0 | 545 | "1@personas.mozilla.org": [ |
michael@0 | 546 | ["onUninstalling", false], |
michael@0 | 547 | "onUninstalled" |
michael@0 | 548 | ] |
michael@0 | 549 | }); |
michael@0 | 550 | |
michael@0 | 551 | AddonManager.getAddonByID("1@personas.mozilla.org", function(p1) { |
michael@0 | 552 | p1.uninstall(); |
michael@0 | 553 | |
michael@0 | 554 | ensure_test_completed(); |
michael@0 | 555 | do_check_eq(LightweightThemeManager.usedThemes.length, 1); |
michael@0 | 556 | do_check_false(gLWThemeChanged); |
michael@0 | 557 | |
michael@0 | 558 | do_execute_soon(run_test_8); |
michael@0 | 559 | }); |
michael@0 | 560 | } |
michael@0 | 561 | |
michael@0 | 562 | // Uninstalling a lightweight theme in use should not require a restart and it |
michael@0 | 563 | // should reactivate the default theme |
michael@0 | 564 | // Also, uninstalling a lightweight theme in use should send a |
michael@0 | 565 | // "lightweight-theme-styling-update" notification through the observer service |
michael@0 | 566 | function run_test_8() { |
michael@0 | 567 | prepare_test({ |
michael@0 | 568 | "2@personas.mozilla.org": [ |
michael@0 | 569 | ["onUninstalling", false], |
michael@0 | 570 | "onUninstalled" |
michael@0 | 571 | ], |
michael@0 | 572 | "default@tests.mozilla.org": [ |
michael@0 | 573 | ["onEnabling", false], |
michael@0 | 574 | "onEnabled" |
michael@0 | 575 | ] |
michael@0 | 576 | }); |
michael@0 | 577 | |
michael@0 | 578 | AddonManager.getAddonByID("2@personas.mozilla.org", function(p2) { |
michael@0 | 579 | p2.uninstall(); |
michael@0 | 580 | |
michael@0 | 581 | ensure_test_completed(); |
michael@0 | 582 | do_check_eq(LightweightThemeManager.usedThemes.length, 0); |
michael@0 | 583 | |
michael@0 | 584 | do_check_true(gLWThemeChanged); |
michael@0 | 585 | gLWThemeChanged = false; |
michael@0 | 586 | |
michael@0 | 587 | do_execute_soon(run_test_9); |
michael@0 | 588 | }); |
michael@0 | 589 | } |
michael@0 | 590 | |
michael@0 | 591 | // Uninstalling a theme not in use should not require a restart |
michael@0 | 592 | function run_test_9() { |
michael@0 | 593 | AddonManager.getAddonByID("theme1@tests.mozilla.org", function(t1) { |
michael@0 | 594 | prepare_test({ |
michael@0 | 595 | "theme1@tests.mozilla.org": [ |
michael@0 | 596 | ["onUninstalling", false], |
michael@0 | 597 | "onUninstalled" |
michael@0 | 598 | ] |
michael@0 | 599 | }); |
michael@0 | 600 | |
michael@0 | 601 | t1.uninstall(); |
michael@0 | 602 | |
michael@0 | 603 | ensure_test_completed(); |
michael@0 | 604 | |
michael@0 | 605 | AddonManager.getAddonByID("theme1@tests.mozilla.org", function(newt1) { |
michael@0 | 606 | do_check_eq(newt1, null); |
michael@0 | 607 | do_check_false(gLWThemeChanged); |
michael@0 | 608 | |
michael@0 | 609 | do_execute_soon(run_test_10); |
michael@0 | 610 | }); |
michael@0 | 611 | }); |
michael@0 | 612 | } |
michael@0 | 613 | |
michael@0 | 614 | // Uninstalling a custom theme in use should require a restart |
michael@0 | 615 | function run_test_10() { |
michael@0 | 616 | AddonManager.getAddonByID("theme2@tests.mozilla.org", callback_soon(function(oldt2) { |
michael@0 | 617 | prepare_test({ |
michael@0 | 618 | "theme2@tests.mozilla.org": [ |
michael@0 | 619 | "onEnabling", |
michael@0 | 620 | ], |
michael@0 | 621 | "default@tests.mozilla.org": [ |
michael@0 | 622 | "onDisabling" |
michael@0 | 623 | ] |
michael@0 | 624 | }); |
michael@0 | 625 | |
michael@0 | 626 | oldt2.userDisabled = false; |
michael@0 | 627 | |
michael@0 | 628 | ensure_test_completed(); |
michael@0 | 629 | |
michael@0 | 630 | restartManager(); |
michael@0 | 631 | |
michael@0 | 632 | AddonManager.getAddonsByIDs(["default@tests.mozilla.org", |
michael@0 | 633 | "theme2@tests.mozilla.org"], function([d, t2]) { |
michael@0 | 634 | do_check_true(t2.isActive); |
michael@0 | 635 | do_check_false(t2.userDisabled); |
michael@0 | 636 | do_check_false(t2.appDisabled); |
michael@0 | 637 | do_check_false(d.isActive); |
michael@0 | 638 | do_check_true(d.userDisabled); |
michael@0 | 639 | do_check_false(d.appDisabled); |
michael@0 | 640 | |
michael@0 | 641 | prepare_test({ |
michael@0 | 642 | "theme2@tests.mozilla.org": [ |
michael@0 | 643 | "onUninstalling", |
michael@0 | 644 | ], |
michael@0 | 645 | "default@tests.mozilla.org": [ |
michael@0 | 646 | "onEnabling" |
michael@0 | 647 | ] |
michael@0 | 648 | }); |
michael@0 | 649 | |
michael@0 | 650 | t2.uninstall(); |
michael@0 | 651 | |
michael@0 | 652 | ensure_test_completed(); |
michael@0 | 653 | do_check_false(gLWThemeChanged); |
michael@0 | 654 | |
michael@0 | 655 | do_execute_soon(run_test_11); |
michael@0 | 656 | }); |
michael@0 | 657 | })); |
michael@0 | 658 | } |
michael@0 | 659 | |
michael@0 | 660 | // Installing a custom theme not in use should not require a restart |
michael@0 | 661 | function run_test_11() { |
michael@0 | 662 | restartManager(); |
michael@0 | 663 | |
michael@0 | 664 | prepare_test({ }, [ |
michael@0 | 665 | "onNewInstall" |
michael@0 | 666 | ]); |
michael@0 | 667 | |
michael@0 | 668 | AddonManager.getInstallForFile(do_get_addon("test_theme"), function(install) { |
michael@0 | 669 | ensure_test_completed(); |
michael@0 | 670 | |
michael@0 | 671 | do_check_neq(install, null); |
michael@0 | 672 | do_check_eq(install.type, "theme"); |
michael@0 | 673 | do_check_eq(install.version, "1.0"); |
michael@0 | 674 | do_check_eq(install.name, "Test Theme 1"); |
michael@0 | 675 | do_check_eq(install.state, AddonManager.STATE_DOWNLOADED); |
michael@0 | 676 | do_check_true(install.addon.skinnable, true); |
michael@0 | 677 | do_check_false(hasFlag(install.addon.operationsRequiringRestart, AddonManager.OP_NEEDS_RESTART_INSTALL)); |
michael@0 | 678 | |
michael@0 | 679 | prepare_test({ |
michael@0 | 680 | "theme1@tests.mozilla.org": [ |
michael@0 | 681 | ["onInstalling", false], |
michael@0 | 682 | "onInstalled" |
michael@0 | 683 | ] |
michael@0 | 684 | }, [ |
michael@0 | 685 | "onInstallStarted", |
michael@0 | 686 | "onInstallEnded", |
michael@0 | 687 | ], check_test_11); |
michael@0 | 688 | install.install(); |
michael@0 | 689 | }); |
michael@0 | 690 | } |
michael@0 | 691 | |
michael@0 | 692 | function check_test_11() { |
michael@0 | 693 | AddonManager.getAddonByID("theme1@tests.mozilla.org", function(t1) { |
michael@0 | 694 | do_check_neq(t1, null); |
michael@0 | 695 | var previewSpec = do_get_addon_root_uri(profileDir, "theme1@tests.mozilla.org") + "preview.png"; |
michael@0 | 696 | do_check_eq(t1.screenshots.length, 1); |
michael@0 | 697 | do_check_eq(t1.screenshots[0], previewSpec); |
michael@0 | 698 | do_check_true(t1.skinnable); |
michael@0 | 699 | do_check_false(gLWThemeChanged); |
michael@0 | 700 | |
michael@0 | 701 | do_execute_soon(run_test_12); |
michael@0 | 702 | }); |
michael@0 | 703 | } |
michael@0 | 704 | |
michael@0 | 705 | // Updating a custom theme not in use should not require a restart |
michael@0 | 706 | function run_test_12() { |
michael@0 | 707 | prepare_test({ }, [ |
michael@0 | 708 | "onNewInstall" |
michael@0 | 709 | ]); |
michael@0 | 710 | |
michael@0 | 711 | AddonManager.getInstallForFile(do_get_addon("test_theme"), function(install) { |
michael@0 | 712 | ensure_test_completed(); |
michael@0 | 713 | |
michael@0 | 714 | do_check_neq(install, null); |
michael@0 | 715 | do_check_eq(install.type, "theme"); |
michael@0 | 716 | do_check_eq(install.version, "1.0"); |
michael@0 | 717 | do_check_eq(install.name, "Test Theme 1"); |
michael@0 | 718 | do_check_eq(install.state, AddonManager.STATE_DOWNLOADED); |
michael@0 | 719 | do_check_false(hasFlag(install.addon.operationsRequiringRestart, AddonManager.OP_NEEDS_RESTART_INSTALL)); |
michael@0 | 720 | |
michael@0 | 721 | prepare_test({ |
michael@0 | 722 | "theme1@tests.mozilla.org": [ |
michael@0 | 723 | ["onInstalling", false], |
michael@0 | 724 | "onInstalled" |
michael@0 | 725 | ] |
michael@0 | 726 | }, [ |
michael@0 | 727 | "onInstallStarted", |
michael@0 | 728 | "onInstallEnded", |
michael@0 | 729 | ], check_test_12); |
michael@0 | 730 | install.install(); |
michael@0 | 731 | }); |
michael@0 | 732 | } |
michael@0 | 733 | |
michael@0 | 734 | function check_test_12() { |
michael@0 | 735 | AddonManager.getAddonByID("theme1@tests.mozilla.org", function(t1) { |
michael@0 | 736 | do_check_neq(t1, null); |
michael@0 | 737 | do_check_false(gLWThemeChanged); |
michael@0 | 738 | |
michael@0 | 739 | do_execute_soon(run_test_13); |
michael@0 | 740 | }); |
michael@0 | 741 | } |
michael@0 | 742 | |
michael@0 | 743 | // Updating a custom theme in use should require a restart |
michael@0 | 744 | function run_test_13() { |
michael@0 | 745 | AddonManager.getAddonByID("theme1@tests.mozilla.org", callback_soon(function(t1) { |
michael@0 | 746 | prepare_test({ |
michael@0 | 747 | "theme1@tests.mozilla.org": [ |
michael@0 | 748 | "onEnabling", |
michael@0 | 749 | ], |
michael@0 | 750 | "default@tests.mozilla.org": [ |
michael@0 | 751 | "onDisabling" |
michael@0 | 752 | ] |
michael@0 | 753 | }); |
michael@0 | 754 | |
michael@0 | 755 | t1.userDisabled = false; |
michael@0 | 756 | ensure_test_completed(); |
michael@0 | 757 | restartManager(); |
michael@0 | 758 | |
michael@0 | 759 | prepare_test({ }, [ |
michael@0 | 760 | "onNewInstall" |
michael@0 | 761 | ]); |
michael@0 | 762 | |
michael@0 | 763 | AddonManager.getInstallForFile(do_get_addon("test_theme"), function(install) { |
michael@0 | 764 | ensure_test_completed(); |
michael@0 | 765 | |
michael@0 | 766 | do_check_neq(install, null); |
michael@0 | 767 | do_check_eq(install.type, "theme"); |
michael@0 | 768 | do_check_eq(install.version, "1.0"); |
michael@0 | 769 | do_check_eq(install.name, "Test Theme 1"); |
michael@0 | 770 | do_check_eq(install.state, AddonManager.STATE_DOWNLOADED); |
michael@0 | 771 | do_check_true(hasFlag(install.addon.operationsRequiringRestart, AddonManager.OP_NEEDS_RESTART_INSTALL)); |
michael@0 | 772 | |
michael@0 | 773 | prepare_test({ |
michael@0 | 774 | "theme1@tests.mozilla.org": [ |
michael@0 | 775 | "onInstalling", |
michael@0 | 776 | ] |
michael@0 | 777 | }, [ |
michael@0 | 778 | "onInstallStarted", |
michael@0 | 779 | "onInstallEnded", |
michael@0 | 780 | ], callback_soon(check_test_13)); |
michael@0 | 781 | install.install(); |
michael@0 | 782 | }); |
michael@0 | 783 | })); |
michael@0 | 784 | } |
michael@0 | 785 | |
michael@0 | 786 | function check_test_13() { |
michael@0 | 787 | restartManager(); |
michael@0 | 788 | |
michael@0 | 789 | AddonManager.getAddonByID("theme1@tests.mozilla.org", callback_soon(function(t1) { |
michael@0 | 790 | do_check_neq(t1, null); |
michael@0 | 791 | do_check_true(t1.isActive); |
michael@0 | 792 | do_check_false(gLWThemeChanged); |
michael@0 | 793 | t1.uninstall(); |
michael@0 | 794 | restartManager(); |
michael@0 | 795 | |
michael@0 | 796 | do_execute_soon(run_test_14); |
michael@0 | 797 | })); |
michael@0 | 798 | } |
michael@0 | 799 | |
michael@0 | 800 | // Switching from a lightweight theme to the default theme should not require |
michael@0 | 801 | // a restart |
michael@0 | 802 | function run_test_14() { |
michael@0 | 803 | LightweightThemeManager.currentTheme = { |
michael@0 | 804 | id: "1", |
michael@0 | 805 | version: "1", |
michael@0 | 806 | name: "Test LW Theme", |
michael@0 | 807 | description: "A test theme", |
michael@0 | 808 | author: "Mozilla", |
michael@0 | 809 | homepageURL: "http://localhost/data/index.html", |
michael@0 | 810 | headerURL: "http://localhost/data/header.png", |
michael@0 | 811 | footerURL: "http://localhost/data/footer.png", |
michael@0 | 812 | previewURL: "http://localhost/data/preview.png", |
michael@0 | 813 | iconURL: "http://localhost/data/icon.png" |
michael@0 | 814 | }; |
michael@0 | 815 | |
michael@0 | 816 | AddonManager.getAddonByID("default@tests.mozilla.org", function(d) { |
michael@0 | 817 | do_check_true(d.userDisabled); |
michael@0 | 818 | do_check_false(d.isActive); |
michael@0 | 819 | |
michael@0 | 820 | prepare_test({ |
michael@0 | 821 | "1@personas.mozilla.org": [ |
michael@0 | 822 | ["onDisabling", false], |
michael@0 | 823 | "onDisabled" |
michael@0 | 824 | ], |
michael@0 | 825 | "default@tests.mozilla.org": [ |
michael@0 | 826 | ["onEnabling", false], |
michael@0 | 827 | "onEnabled" |
michael@0 | 828 | ] |
michael@0 | 829 | }); |
michael@0 | 830 | |
michael@0 | 831 | d.userDisabled = false; |
michael@0 | 832 | ensure_test_completed(); |
michael@0 | 833 | |
michael@0 | 834 | do_check_false(d.userDisabled); |
michael@0 | 835 | do_check_true(d.isActive); |
michael@0 | 836 | |
michael@0 | 837 | do_check_true(gLWThemeChanged); |
michael@0 | 838 | gLWThemeChanged = false; |
michael@0 | 839 | |
michael@0 | 840 | do_execute_soon(run_test_15); |
michael@0 | 841 | }); |
michael@0 | 842 | } |
michael@0 | 843 | |
michael@0 | 844 | // Upgrading the application with a custom theme in use should not disable it |
michael@0 | 845 | function run_test_15() { |
michael@0 | 846 | restartManager(); |
michael@0 | 847 | |
michael@0 | 848 | installAllFiles([do_get_addon("test_theme")], function() { |
michael@0 | 849 | AddonManager.getAddonByID("theme1@tests.mozilla.org", callback_soon(function(t1) { |
michael@0 | 850 | t1.userDisabled = false; |
michael@0 | 851 | |
michael@0 | 852 | restartManager(); |
michael@0 | 853 | |
michael@0 | 854 | do_check_eq(Services.prefs.getCharPref(PREF_GENERAL_SKINS_SELECTEDSKIN), "theme1/1.0"); |
michael@0 | 855 | AddonManager.getAddonsByIDs(["default@tests.mozilla.org", |
michael@0 | 856 | "theme1@tests.mozilla.org"], |
michael@0 | 857 | callback_soon(function([d, t1]) { |
michael@0 | 858 | do_check_true(d.userDisabled); |
michael@0 | 859 | do_check_false(d.appDisabled); |
michael@0 | 860 | do_check_false(d.isActive); |
michael@0 | 861 | |
michael@0 | 862 | do_check_false(t1.userDisabled); |
michael@0 | 863 | do_check_false(t1.appDisabled); |
michael@0 | 864 | do_check_true(t1.isActive); |
michael@0 | 865 | |
michael@0 | 866 | restartManager("2"); |
michael@0 | 867 | |
michael@0 | 868 | do_check_eq(Services.prefs.getCharPref(PREF_GENERAL_SKINS_SELECTEDSKIN), "theme1/1.0"); |
michael@0 | 869 | AddonManager.getAddonsByIDs(["default@tests.mozilla.org", |
michael@0 | 870 | "theme1@tests.mozilla.org"], function([d, t1]) { |
michael@0 | 871 | do_check_true(d.userDisabled); |
michael@0 | 872 | do_check_false(d.appDisabled); |
michael@0 | 873 | do_check_false(d.isActive); |
michael@0 | 874 | |
michael@0 | 875 | do_check_false(t1.userDisabled); |
michael@0 | 876 | do_check_false(t1.appDisabled); |
michael@0 | 877 | do_check_true(t1.isActive); |
michael@0 | 878 | |
michael@0 | 879 | do_execute_soon(run_test_16); |
michael@0 | 880 | }); |
michael@0 | 881 | })); |
michael@0 | 882 | })); |
michael@0 | 883 | }); |
michael@0 | 884 | } |
michael@0 | 885 | |
michael@0 | 886 | // Upgrading the application with a custom theme in use should disable it if it |
michael@0 | 887 | // is no longer compatible |
michael@0 | 888 | function run_test_16() { |
michael@0 | 889 | restartManager("3"); |
michael@0 | 890 | |
michael@0 | 891 | do_check_eq(Services.prefs.getCharPref(PREF_GENERAL_SKINS_SELECTEDSKIN), "classic/1.0"); |
michael@0 | 892 | AddonManager.getAddonsByIDs(["default@tests.mozilla.org", |
michael@0 | 893 | "theme1@tests.mozilla.org"], function([d, t1]) { |
michael@0 | 894 | do_check_false(d.userDisabled); |
michael@0 | 895 | do_check_false(d.appDisabled); |
michael@0 | 896 | do_check_true(d.isActive); |
michael@0 | 897 | |
michael@0 | 898 | do_check_true(t1.userDisabled); |
michael@0 | 899 | do_check_true(t1.appDisabled); |
michael@0 | 900 | do_check_false(t1.isActive); |
michael@0 | 901 | |
michael@0 | 902 | do_execute_soon(run_test_17); |
michael@0 | 903 | }); |
michael@0 | 904 | } |
michael@0 | 905 | |
michael@0 | 906 | // Verifies that if the selected theme pref is changed by a different version |
michael@0 | 907 | // of the application that we correctly reset it when it points to an |
michael@0 | 908 | // incompatible theme |
michael@0 | 909 | function run_test_17() { |
michael@0 | 910 | restartManager("2"); |
michael@0 | 911 | shutdownManager(); |
michael@0 | 912 | |
michael@0 | 913 | Services.prefs.setCharPref(PREF_GENERAL_SKINS_SELECTEDSKIN, "theme1/1.0"); |
michael@0 | 914 | |
michael@0 | 915 | restartManager("3"); |
michael@0 | 916 | |
michael@0 | 917 | do_check_eq(Services.prefs.getCharPref(PREF_GENERAL_SKINS_SELECTEDSKIN), "classic/1.0"); |
michael@0 | 918 | AddonManager.getAddonsByIDs(["default@tests.mozilla.org", |
michael@0 | 919 | "theme1@tests.mozilla.org"], function([d, t1]) { |
michael@0 | 920 | do_check_false(d.userDisabled); |
michael@0 | 921 | do_check_false(d.appDisabled); |
michael@0 | 922 | do_check_true(d.isActive); |
michael@0 | 923 | |
michael@0 | 924 | do_check_true(t1.userDisabled); |
michael@0 | 925 | do_check_true(t1.appDisabled); |
michael@0 | 926 | do_check_false(t1.isActive); |
michael@0 | 927 | |
michael@0 | 928 | do_execute_soon(run_test_18); |
michael@0 | 929 | }); |
michael@0 | 930 | } |
michael@0 | 931 | |
michael@0 | 932 | // Disabling the active theme should switch back to the default theme |
michael@0 | 933 | function run_test_18() { |
michael@0 | 934 | restartManager(2); |
michael@0 | 935 | |
michael@0 | 936 | AddonManager.getAddonByID("theme1@tests.mozilla.org", callback_soon(function(t1) { |
michael@0 | 937 | t1.userDisabled = false; |
michael@0 | 938 | |
michael@0 | 939 | restartManager(); |
michael@0 | 940 | |
michael@0 | 941 | AddonManager.getAddonsByIDs(["default@tests.mozilla.org", |
michael@0 | 942 | "theme1@tests.mozilla.org"], |
michael@0 | 943 | callback_soon(function([d, t1]) { |
michael@0 | 944 | do_check_true(d.userDisabled); |
michael@0 | 945 | do_check_false(d.appDisabled); |
michael@0 | 946 | do_check_false(d.isActive); |
michael@0 | 947 | |
michael@0 | 948 | do_check_false(t1.userDisabled); |
michael@0 | 949 | do_check_false(t1.appDisabled); |
michael@0 | 950 | do_check_true(t1.isActive); |
michael@0 | 951 | |
michael@0 | 952 | prepare_test({ |
michael@0 | 953 | "theme1@tests.mozilla.org": [ |
michael@0 | 954 | "onDisabling", |
michael@0 | 955 | ], |
michael@0 | 956 | "default@tests.mozilla.org": [ |
michael@0 | 957 | "onEnabling", |
michael@0 | 958 | ] |
michael@0 | 959 | }); |
michael@0 | 960 | t1.userDisabled = true; |
michael@0 | 961 | ensure_test_completed(); |
michael@0 | 962 | |
michael@0 | 963 | do_check_false(d.userDisabled); |
michael@0 | 964 | do_check_false(d.appDisabled); |
michael@0 | 965 | do_check_false(d.isActive); |
michael@0 | 966 | |
michael@0 | 967 | do_check_true(t1.userDisabled); |
michael@0 | 968 | do_check_false(t1.appDisabled); |
michael@0 | 969 | do_check_true(t1.isActive); |
michael@0 | 970 | |
michael@0 | 971 | restartManager(); |
michael@0 | 972 | |
michael@0 | 973 | AddonManager.getAddonsByIDs(["default@tests.mozilla.org", |
michael@0 | 974 | "theme1@tests.mozilla.org"], function([d, t1]) { |
michael@0 | 975 | do_check_false(d.userDisabled); |
michael@0 | 976 | do_check_false(d.appDisabled); |
michael@0 | 977 | do_check_true(d.isActive); |
michael@0 | 978 | |
michael@0 | 979 | do_check_true(t1.userDisabled); |
michael@0 | 980 | do_check_false(t1.appDisabled); |
michael@0 | 981 | do_check_false(t1.isActive); |
michael@0 | 982 | |
michael@0 | 983 | do_execute_soon(run_test_19); |
michael@0 | 984 | }); |
michael@0 | 985 | })); |
michael@0 | 986 | })); |
michael@0 | 987 | } |
michael@0 | 988 | |
michael@0 | 989 | // Disabling the active persona should switch back to the default theme |
michael@0 | 990 | function run_test_19() { |
michael@0 | 991 | AddonManager.getAddonsByIDs(["default@tests.mozilla.org", |
michael@0 | 992 | "1@personas.mozilla.org"], function([d, p1]) { |
michael@0 | 993 | p1.userDisabled = false; |
michael@0 | 994 | |
michael@0 | 995 | do_check_true(d.userDisabled); |
michael@0 | 996 | do_check_false(d.appDisabled); |
michael@0 | 997 | do_check_false(d.isActive); |
michael@0 | 998 | |
michael@0 | 999 | do_check_false(p1.userDisabled); |
michael@0 | 1000 | do_check_false(p1.appDisabled); |
michael@0 | 1001 | do_check_true(p1.isActive); |
michael@0 | 1002 | |
michael@0 | 1003 | prepare_test({ |
michael@0 | 1004 | "1@personas.mozilla.org": [ |
michael@0 | 1005 | ["onDisabling", false], |
michael@0 | 1006 | "onDisabled" |
michael@0 | 1007 | ], |
michael@0 | 1008 | "default@tests.mozilla.org": [ |
michael@0 | 1009 | ["onEnabling", false], |
michael@0 | 1010 | "onEnabled" |
michael@0 | 1011 | ] |
michael@0 | 1012 | }); |
michael@0 | 1013 | p1.userDisabled = true; |
michael@0 | 1014 | ensure_test_completed(); |
michael@0 | 1015 | |
michael@0 | 1016 | do_check_false(d.userDisabled); |
michael@0 | 1017 | do_check_false(d.appDisabled); |
michael@0 | 1018 | do_check_true(d.isActive); |
michael@0 | 1019 | |
michael@0 | 1020 | do_check_true(p1.userDisabled); |
michael@0 | 1021 | do_check_false(p1.appDisabled); |
michael@0 | 1022 | do_check_false(p1.isActive); |
michael@0 | 1023 | |
michael@0 | 1024 | do_execute_soon(run_test_20); |
michael@0 | 1025 | }); |
michael@0 | 1026 | } |
michael@0 | 1027 | |
michael@0 | 1028 | // Tests that you cannot disable the default theme |
michael@0 | 1029 | function run_test_20() { |
michael@0 | 1030 | AddonManager.getAddonByID("default@tests.mozilla.org", function(d) { |
michael@0 | 1031 | do_check_false(d.userDisabled); |
michael@0 | 1032 | do_check_false(d.appDisabled); |
michael@0 | 1033 | do_check_true(d.isActive); |
michael@0 | 1034 | |
michael@0 | 1035 | try { |
michael@0 | 1036 | d.userDisabled = true; |
michael@0 | 1037 | do_throw("Disabling the default theme should throw an exception"); |
michael@0 | 1038 | } |
michael@0 | 1039 | catch (e) { |
michael@0 | 1040 | } |
michael@0 | 1041 | |
michael@0 | 1042 | do_execute_soon(run_test_21); |
michael@0 | 1043 | }); |
michael@0 | 1044 | } |
michael@0 | 1045 | |
michael@0 | 1046 | // Tests that cached copies of a lightweight theme have the right permissions |
michael@0 | 1047 | // and pendingOperations during the onEnabling event |
michael@0 | 1048 | function run_test_21() { |
michael@0 | 1049 | AddonManager.getAddonByID("theme1@tests.mozilla.org", callback_soon(function(t1) { |
michael@0 | 1050 | // Switch to a custom theme so we can test pendingOperations properly. |
michael@0 | 1051 | |
michael@0 | 1052 | prepare_test({ |
michael@0 | 1053 | "theme1@tests.mozilla.org": [ |
michael@0 | 1054 | "onEnabling" |
michael@0 | 1055 | ], |
michael@0 | 1056 | "default@tests.mozilla.org": [ |
michael@0 | 1057 | "onDisabling" |
michael@0 | 1058 | ] |
michael@0 | 1059 | }); |
michael@0 | 1060 | |
michael@0 | 1061 | t1.userDisabled = false; |
michael@0 | 1062 | ensure_test_completed(); |
michael@0 | 1063 | |
michael@0 | 1064 | restartManager(); |
michael@0 | 1065 | |
michael@0 | 1066 | AddonManager.getAddonByID("1@personas.mozilla.org", function(p1) { |
michael@0 | 1067 | AddonManager.addAddonListener({ |
michael@0 | 1068 | onEnabling: function(aAddon) { |
michael@0 | 1069 | do_check_false(hasFlag(aAddon.permissions, AddonManager.PERM_CAN_ENABLE)); |
michael@0 | 1070 | do_check_true(hasFlag(aAddon.pendingOperations, AddonManager.PENDING_ENABLE)); |
michael@0 | 1071 | |
michael@0 | 1072 | do_check_eq(aAddon.permissions, p1.permissions); |
michael@0 | 1073 | do_check_eq(aAddon.pendingOperations, p1.pendingOperations); |
michael@0 | 1074 | } |
michael@0 | 1075 | }); |
michael@0 | 1076 | |
michael@0 | 1077 | prepare_test({ |
michael@0 | 1078 | "1@personas.mozilla.org": [ |
michael@0 | 1079 | "onEnabling" |
michael@0 | 1080 | ], |
michael@0 | 1081 | "theme1@tests.mozilla.org": [ |
michael@0 | 1082 | "onDisabling" |
michael@0 | 1083 | ] |
michael@0 | 1084 | }); |
michael@0 | 1085 | |
michael@0 | 1086 | p1.userDisabled = false; |
michael@0 | 1087 | ensure_test_completed(); |
michael@0 | 1088 | |
michael@0 | 1089 | end_test(); |
michael@0 | 1090 | }); |
michael@0 | 1091 | })); |
michael@0 | 1092 | } |