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 | // using a dynamic port in the addon metadata |
michael@0 | 8 | Components.utils.import("resource://testing-common/httpd.js"); |
michael@0 | 9 | let gServer = new HttpServer(); |
michael@0 | 10 | gServer.start(-1); |
michael@0 | 11 | gPort = gServer.identity.primaryPort; |
michael@0 | 12 | |
michael@0 | 13 | // This verifies that themes behave as expected |
michael@0 | 14 | |
michael@0 | 15 | const PREF_GENERAL_SKINS_SELECTEDSKIN = "general.skins.selectedSkin"; |
michael@0 | 16 | const PREF_EXTENSIONS_DSS_ENABLED = "extensions.dss.enabled"; |
michael@0 | 17 | |
michael@0 | 18 | Components.utils.import("resource://gre/modules/LightweightThemeManager.jsm"); |
michael@0 | 19 | |
michael@0 | 20 | const profileDir = gProfD.clone(); |
michael@0 | 21 | profileDir.append("extensions"); |
michael@0 | 22 | |
michael@0 | 23 | // Observer to ensure a "lightweight-theme-styling-update" notification is sent |
michael@0 | 24 | // when expected |
michael@0 | 25 | var gLWThemeChanged = false; |
michael@0 | 26 | var LightweightThemeObserver = { |
michael@0 | 27 | observe: function(aSubject, aTopic, aData) { |
michael@0 | 28 | if (aTopic != "lightweight-theme-styling-update") |
michael@0 | 29 | return; |
michael@0 | 30 | |
michael@0 | 31 | gLWThemeChanged = true; |
michael@0 | 32 | } |
michael@0 | 33 | }; |
michael@0 | 34 | |
michael@0 | 35 | AM_Cc["@mozilla.org/observer-service;1"] |
michael@0 | 36 | .getService(Components.interfaces.nsIObserverService) |
michael@0 | 37 | .addObserver(LightweightThemeObserver, "lightweight-theme-styling-update", false); |
michael@0 | 38 | |
michael@0 | 39 | |
michael@0 | 40 | function run_test() { |
michael@0 | 41 | do_test_pending(); |
michael@0 | 42 | createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2"); |
michael@0 | 43 | |
michael@0 | 44 | Services.prefs.setCharPref(PREF_GENERAL_SKINS_SELECTEDSKIN, "theme1/1.0"); |
michael@0 | 45 | Services.prefs.setBoolPref(PREF_EXTENSIONS_DSS_ENABLED, true); |
michael@0 | 46 | writeInstallRDFForExtension({ |
michael@0 | 47 | id: "theme1@tests.mozilla.org", |
michael@0 | 48 | version: "1.0", |
michael@0 | 49 | name: "Test 1", |
michael@0 | 50 | type: 4, |
michael@0 | 51 | internalName: "theme1/1.0", |
michael@0 | 52 | targetApplications: [{ |
michael@0 | 53 | id: "xpcshell@tests.mozilla.org", |
michael@0 | 54 | minVersion: "1", |
michael@0 | 55 | maxVersion: "2" |
michael@0 | 56 | }] |
michael@0 | 57 | }, profileDir); |
michael@0 | 58 | |
michael@0 | 59 | writeInstallRDFForExtension({ |
michael@0 | 60 | id: "theme2@tests.mozilla.org", |
michael@0 | 61 | version: "1.0", |
michael@0 | 62 | name: "Test 1", |
michael@0 | 63 | internalName: "theme2/1.0", |
michael@0 | 64 | targetApplications: [{ |
michael@0 | 65 | id: "xpcshell@tests.mozilla.org", |
michael@0 | 66 | minVersion: "1", |
michael@0 | 67 | maxVersion: "2" |
michael@0 | 68 | }] |
michael@0 | 69 | }, profileDir); |
michael@0 | 70 | |
michael@0 | 71 | // We need a default theme for some of these things to work but we have hidden |
michael@0 | 72 | // the one in the application directory. |
michael@0 | 73 | writeInstallRDFForExtension({ |
michael@0 | 74 | id: "default@tests.mozilla.org", |
michael@0 | 75 | version: "1.0", |
michael@0 | 76 | name: "Default", |
michael@0 | 77 | internalName: "classic/1.0", |
michael@0 | 78 | targetApplications: [{ |
michael@0 | 79 | id: "xpcshell@tests.mozilla.org", |
michael@0 | 80 | minVersion: "1", |
michael@0 | 81 | maxVersion: "2" |
michael@0 | 82 | }] |
michael@0 | 83 | }, profileDir); |
michael@0 | 84 | |
michael@0 | 85 | startupManager(); |
michael@0 | 86 | // Make sure we only register once despite multiple calls |
michael@0 | 87 | AddonManager.addInstallListener(InstallListener); |
michael@0 | 88 | AddonManager.addAddonListener(AddonListener); |
michael@0 | 89 | AddonManager.addInstallListener(InstallListener); |
michael@0 | 90 | AddonManager.addAddonListener(AddonListener); |
michael@0 | 91 | AddonManager.addInstallListener(InstallListener); |
michael@0 | 92 | |
michael@0 | 93 | AddonManager.getAddonsByIDs(["theme1@tests.mozilla.org", |
michael@0 | 94 | "theme2@tests.mozilla.org"], function([t1, t2]) { |
michael@0 | 95 | do_check_neq(t1, null); |
michael@0 | 96 | do_check_false(t1.userDisabled); |
michael@0 | 97 | do_check_false(t1.appDisabled); |
michael@0 | 98 | do_check_true(t1.isActive); |
michael@0 | 99 | do_check_eq(t1.screenshots, null); |
michael@0 | 100 | do_check_true(isThemeInAddonsList(profileDir, t1.id)); |
michael@0 | 101 | do_check_false(hasFlag(t1.permissions, AddonManager.PERM_CAN_DISABLE)); |
michael@0 | 102 | do_check_false(hasFlag(t1.permissions, AddonManager.PERM_CAN_ENABLE)); |
michael@0 | 103 | |
michael@0 | 104 | do_check_neq(t2, null); |
michael@0 | 105 | do_check_true(t2.userDisabled); |
michael@0 | 106 | do_check_false(t2.appDisabled); |
michael@0 | 107 | do_check_false(t2.isActive); |
michael@0 | 108 | do_check_eq(t2.screenshots, null); |
michael@0 | 109 | do_check_true(isThemeInAddonsList(profileDir, t2.id)); |
michael@0 | 110 | do_check_false(hasFlag(t2.permissions, AddonManager.PERM_CAN_DISABLE)); |
michael@0 | 111 | do_check_true(hasFlag(t2.permissions, AddonManager.PERM_CAN_ENABLE)); |
michael@0 | 112 | |
michael@0 | 113 | do_execute_soon(run_test_1); |
michael@0 | 114 | }); |
michael@0 | 115 | } |
michael@0 | 116 | |
michael@0 | 117 | function end_test() { |
michael@0 | 118 | do_execute_soon(do_test_finished); |
michael@0 | 119 | } |
michael@0 | 120 | |
michael@0 | 121 | // Checks enabling one theme disables the others |
michael@0 | 122 | function run_test_1() { |
michael@0 | 123 | prepare_test({ |
michael@0 | 124 | "theme1@tests.mozilla.org": [ |
michael@0 | 125 | ["onDisabling", false], |
michael@0 | 126 | "onDisabled" |
michael@0 | 127 | ], |
michael@0 | 128 | "theme2@tests.mozilla.org": [ |
michael@0 | 129 | ["onEnabling", false], |
michael@0 | 130 | "onEnabled" |
michael@0 | 131 | ] |
michael@0 | 132 | }); |
michael@0 | 133 | AddonManager.getAddonsByIDs(["theme1@tests.mozilla.org", |
michael@0 | 134 | "theme2@tests.mozilla.org"], function([t1, t2]) { |
michael@0 | 135 | t2.userDisabled = false; |
michael@0 | 136 | |
michael@0 | 137 | ensure_test_completed(); |
michael@0 | 138 | do_check_false(hasFlag(t2.permissions, AddonManager.PERM_CAN_DISABLE)); |
michael@0 | 139 | do_check_false(hasFlag(t2.permissions, AddonManager.PERM_CAN_ENABLE)); |
michael@0 | 140 | |
michael@0 | 141 | do_check_true(t1.userDisabled); |
michael@0 | 142 | do_check_false(hasFlag(t1.permissions, AddonManager.PERM_CAN_DISABLE)); |
michael@0 | 143 | do_check_true(hasFlag(t1.permissions, AddonManager.PERM_CAN_ENABLE)); |
michael@0 | 144 | |
michael@0 | 145 | do_execute_soon(check_test_1); |
michael@0 | 146 | }); |
michael@0 | 147 | } |
michael@0 | 148 | |
michael@0 | 149 | function check_test_1() { |
michael@0 | 150 | restartManager(); |
michael@0 | 151 | do_check_eq(Services.prefs.getCharPref(PREF_GENERAL_SKINS_SELECTEDSKIN), "theme2/1.0"); |
michael@0 | 152 | |
michael@0 | 153 | AddonManager.getAddonsByIDs(["theme1@tests.mozilla.org", |
michael@0 | 154 | "theme2@tests.mozilla.org"], function([t1, t2]) { |
michael@0 | 155 | do_check_neq(t1, null); |
michael@0 | 156 | do_check_true(t1.userDisabled); |
michael@0 | 157 | do_check_false(t1.appDisabled); |
michael@0 | 158 | do_check_false(t1.isActive); |
michael@0 | 159 | do_check_true(isThemeInAddonsList(profileDir, t1.id)); |
michael@0 | 160 | do_check_false(hasFlag(t1.permissions, AddonManager.PERM_CAN_DISABLE)); |
michael@0 | 161 | do_check_true(hasFlag(t1.permissions, AddonManager.PERM_CAN_ENABLE)); |
michael@0 | 162 | |
michael@0 | 163 | do_check_neq(t2, null); |
michael@0 | 164 | do_check_false(t2.userDisabled); |
michael@0 | 165 | do_check_false(t2.appDisabled); |
michael@0 | 166 | do_check_true(t2.isActive); |
michael@0 | 167 | do_check_true(isThemeInAddonsList(profileDir, t2.id)); |
michael@0 | 168 | do_check_false(hasFlag(t2.permissions, AddonManager.PERM_CAN_DISABLE)); |
michael@0 | 169 | do_check_false(hasFlag(t2.permissions, AddonManager.PERM_CAN_ENABLE)); |
michael@0 | 170 | do_check_false(gLWThemeChanged); |
michael@0 | 171 | |
michael@0 | 172 | do_execute_soon(run_test_2); |
michael@0 | 173 | }); |
michael@0 | 174 | } |
michael@0 | 175 | |
michael@0 | 176 | // Removing the active theme should fall back to the default (not ideal in this |
michael@0 | 177 | // case since we don't have the default theme installed) |
michael@0 | 178 | function run_test_2() { |
michael@0 | 179 | var dest = profileDir.clone(); |
michael@0 | 180 | dest.append(do_get_expected_addon_name("theme2@tests.mozilla.org")); |
michael@0 | 181 | dest.remove(true); |
michael@0 | 182 | |
michael@0 | 183 | restartManager(); |
michael@0 | 184 | do_check_eq(Services.prefs.getCharPref(PREF_GENERAL_SKINS_SELECTEDSKIN), "classic/1.0"); |
michael@0 | 185 | |
michael@0 | 186 | AddonManager.getAddonsByIDs(["theme1@tests.mozilla.org", |
michael@0 | 187 | "theme2@tests.mozilla.org"], function([t1, t2]) { |
michael@0 | 188 | do_check_neq(t1, null); |
michael@0 | 189 | do_check_true(t1.userDisabled); |
michael@0 | 190 | do_check_false(t1.appDisabled); |
michael@0 | 191 | do_check_false(t1.isActive); |
michael@0 | 192 | do_check_true(isThemeInAddonsList(profileDir, t1.id)); |
michael@0 | 193 | do_check_false(hasFlag(t1.permissions, AddonManager.PERM_CAN_DISABLE)); |
michael@0 | 194 | do_check_true(hasFlag(t1.permissions, AddonManager.PERM_CAN_ENABLE)); |
michael@0 | 195 | |
michael@0 | 196 | do_check_eq(t2, null); |
michael@0 | 197 | do_check_false(isThemeInAddonsList(profileDir, "theme2@tests.mozilla.org")); |
michael@0 | 198 | do_check_false(gLWThemeChanged); |
michael@0 | 199 | |
michael@0 | 200 | do_execute_soon(run_test_3); |
michael@0 | 201 | }); |
michael@0 | 202 | } |
michael@0 | 203 | |
michael@0 | 204 | // Installing a lightweight theme should happen instantly and disable the default theme |
michael@0 | 205 | function run_test_3() { |
michael@0 | 206 | writeInstallRDFForExtension({ |
michael@0 | 207 | id: "theme2@tests.mozilla.org", |
michael@0 | 208 | version: "1.0", |
michael@0 | 209 | name: "Test 1", |
michael@0 | 210 | internalName: "theme2/1.0", |
michael@0 | 211 | targetApplications: [{ |
michael@0 | 212 | id: "xpcshell@tests.mozilla.org", |
michael@0 | 213 | minVersion: "1", |
michael@0 | 214 | maxVersion: "2" |
michael@0 | 215 | }] |
michael@0 | 216 | }, profileDir); |
michael@0 | 217 | restartManager(); |
michael@0 | 218 | |
michael@0 | 219 | prepare_test({ |
michael@0 | 220 | "1@personas.mozilla.org": [ |
michael@0 | 221 | ["onInstalling", false], |
michael@0 | 222 | "onInstalled", |
michael@0 | 223 | ["onEnabling", false], |
michael@0 | 224 | "onEnabled" |
michael@0 | 225 | ], |
michael@0 | 226 | "default@tests.mozilla.org": [ |
michael@0 | 227 | ["onDisabling", false], |
michael@0 | 228 | "onDisabled", |
michael@0 | 229 | ] |
michael@0 | 230 | }, [ |
michael@0 | 231 | "onExternalInstall" |
michael@0 | 232 | ]); |
michael@0 | 233 | |
michael@0 | 234 | LightweightThemeManager.currentTheme = { |
michael@0 | 235 | id: "1", |
michael@0 | 236 | version: "1", |
michael@0 | 237 | name: "Test LW Theme", |
michael@0 | 238 | description: "A test theme", |
michael@0 | 239 | author: "Mozilla", |
michael@0 | 240 | homepageURL: "http://localhost:" + gPort + "/data/index.html", |
michael@0 | 241 | headerURL: "http://localhost:" + gPort + "/data/header.png", |
michael@0 | 242 | footerURL: "http://localhost:" + gPort + "/data/footer.png", |
michael@0 | 243 | previewURL: "http://localhost:" + gPort + "/data/preview.png", |
michael@0 | 244 | iconURL: "http://localhost:" + gPort + "/data/icon.png" |
michael@0 | 245 | }; |
michael@0 | 246 | |
michael@0 | 247 | ensure_test_completed(); |
michael@0 | 248 | |
michael@0 | 249 | AddonManager.getAddonByID("1@personas.mozilla.org", function(p1) { |
michael@0 | 250 | do_check_neq(null, p1); |
michael@0 | 251 | do_check_eq(p1.name, "Test LW Theme"); |
michael@0 | 252 | do_check_eq(p1.version, "1"); |
michael@0 | 253 | do_check_eq(p1.type, "theme"); |
michael@0 | 254 | do_check_eq(p1.description, "A test theme"); |
michael@0 | 255 | do_check_eq(p1.creator, "Mozilla"); |
michael@0 | 256 | do_check_eq(p1.homepageURL, "http://localhost:" + gPort + "/data/index.html"); |
michael@0 | 257 | do_check_eq(p1.iconURL, "http://localhost:" + gPort + "/data/icon.png"); |
michael@0 | 258 | do_check_eq(p1.screenshots.length, 1); |
michael@0 | 259 | do_check_eq(p1.screenshots[0], "http://localhost:" + gPort + "/data/preview.png"); |
michael@0 | 260 | do_check_false(p1.appDisabled); |
michael@0 | 261 | do_check_false(p1.userDisabled); |
michael@0 | 262 | do_check_true(p1.isCompatible); |
michael@0 | 263 | do_check_true(p1.providesUpdatesSecurely); |
michael@0 | 264 | do_check_eq(p1.blocklistState, 0); |
michael@0 | 265 | do_check_true(p1.isActive); |
michael@0 | 266 | do_check_eq(p1.pendingOperations, 0); |
michael@0 | 267 | do_check_eq(p1.permissions, AddonManager.PERM_CAN_UNINSTALL | AddonManager.PERM_CAN_DISABLE); |
michael@0 | 268 | do_check_eq(p1.scope, AddonManager.SCOPE_PROFILE); |
michael@0 | 269 | do_check_true("isCompatibleWith" in p1); |
michael@0 | 270 | do_check_true("findUpdates" in p1); |
michael@0 | 271 | |
michael@0 | 272 | AddonManager.getAddonsByTypes(["theme"], function(addons) { |
michael@0 | 273 | let seen = false; |
michael@0 | 274 | addons.forEach(function(a) { |
michael@0 | 275 | if (a.id == "1@personas.mozilla.org") { |
michael@0 | 276 | seen = true; |
michael@0 | 277 | } |
michael@0 | 278 | else { |
michael@0 | 279 | dump("Checking theme " + a.id + "\n"); |
michael@0 | 280 | do_check_false(a.isActive); |
michael@0 | 281 | do_check_true(a.userDisabled); |
michael@0 | 282 | } |
michael@0 | 283 | }); |
michael@0 | 284 | do_check_true(seen); |
michael@0 | 285 | |
michael@0 | 286 | do_check_true(gLWThemeChanged); |
michael@0 | 287 | gLWThemeChanged = false; |
michael@0 | 288 | |
michael@0 | 289 | do_execute_soon(run_test_4); |
michael@0 | 290 | }); |
michael@0 | 291 | }); |
michael@0 | 292 | } |
michael@0 | 293 | |
michael@0 | 294 | // Installing a second lightweight theme should disable the first with no restart |
michael@0 | 295 | function run_test_4() { |
michael@0 | 296 | prepare_test({ |
michael@0 | 297 | "1@personas.mozilla.org": [ |
michael@0 | 298 | ["onDisabling", false], |
michael@0 | 299 | "onDisabled", |
michael@0 | 300 | ], |
michael@0 | 301 | "2@personas.mozilla.org": [ |
michael@0 | 302 | ["onInstalling", false], |
michael@0 | 303 | "onInstalled", |
michael@0 | 304 | ["onEnabling", false], |
michael@0 | 305 | "onEnabled" |
michael@0 | 306 | ] |
michael@0 | 307 | }, [ |
michael@0 | 308 | "onExternalInstall" |
michael@0 | 309 | ]); |
michael@0 | 310 | |
michael@0 | 311 | LightweightThemeManager.currentTheme = { |
michael@0 | 312 | id: "2", |
michael@0 | 313 | version: "1", |
michael@0 | 314 | name: "Test LW Theme", |
michael@0 | 315 | description: "A second test theme", |
michael@0 | 316 | author: "Mozilla", |
michael@0 | 317 | homepageURL: "http://localhost:" + gPort + "/data/index.html", |
michael@0 | 318 | headerURL: "http://localhost:" + gPort + "/data/header.png", |
michael@0 | 319 | footerURL: "http://localhost:" + gPort + "/data/footer.png", |
michael@0 | 320 | previewURL: "http://localhost:" + gPort + "/data/preview.png", |
michael@0 | 321 | iconURL: "http://localhost:" + gPort + "/data/icon.png" |
michael@0 | 322 | }; |
michael@0 | 323 | |
michael@0 | 324 | ensure_test_completed(); |
michael@0 | 325 | |
michael@0 | 326 | AddonManager.getAddonsByIDs(["1@personas.mozilla.org", |
michael@0 | 327 | "2@personas.mozilla.org"], function([p1, p2]) { |
michael@0 | 328 | do_check_neq(null, p2); |
michael@0 | 329 | do_check_false(p2.appDisabled); |
michael@0 | 330 | do_check_false(p2.userDisabled); |
michael@0 | 331 | do_check_true(p2.isActive); |
michael@0 | 332 | do_check_eq(p2.pendingOperations, 0); |
michael@0 | 333 | do_check_eq(p2.permissions, AddonManager.PERM_CAN_UNINSTALL | AddonManager.PERM_CAN_DISABLE); |
michael@0 | 334 | |
michael@0 | 335 | do_check_neq(null, p1); |
michael@0 | 336 | do_check_false(p1.appDisabled); |
michael@0 | 337 | do_check_true(p1.userDisabled); |
michael@0 | 338 | do_check_false(p1.isActive); |
michael@0 | 339 | do_check_eq(p1.pendingOperations, 0); |
michael@0 | 340 | do_check_eq(p1.permissions, AddonManager.PERM_CAN_UNINSTALL | AddonManager.PERM_CAN_ENABLE); |
michael@0 | 341 | |
michael@0 | 342 | AddonManager.getAddonsByTypes(["theme"], function(addons) { |
michael@0 | 343 | let seen = false; |
michael@0 | 344 | addons.forEach(function(a) { |
michael@0 | 345 | if (a.id == "2@personas.mozilla.org") { |
michael@0 | 346 | seen = true; |
michael@0 | 347 | } |
michael@0 | 348 | else { |
michael@0 | 349 | dump("Checking theme " + a.id + "\n"); |
michael@0 | 350 | do_check_false(a.isActive); |
michael@0 | 351 | do_check_true(a.userDisabled); |
michael@0 | 352 | } |
michael@0 | 353 | }); |
michael@0 | 354 | do_check_true(seen); |
michael@0 | 355 | |
michael@0 | 356 | do_check_true(gLWThemeChanged); |
michael@0 | 357 | gLWThemeChanged = false; |
michael@0 | 358 | |
michael@0 | 359 | do_execute_soon(run_test_5); |
michael@0 | 360 | }); |
michael@0 | 361 | }); |
michael@0 | 362 | } |
michael@0 | 363 | |
michael@0 | 364 | // Switching to a custom theme should disable the lightweight theme and require |
michael@0 | 365 | // a restart. Cancelling that should also be possible. |
michael@0 | 366 | function run_test_5() { |
michael@0 | 367 | prepare_test({ |
michael@0 | 368 | "2@personas.mozilla.org": [ |
michael@0 | 369 | ["onDisabling", false], |
michael@0 | 370 | "onDisabled" |
michael@0 | 371 | ], |
michael@0 | 372 | "theme2@tests.mozilla.org": [ |
michael@0 | 373 | ["onEnabling", false], |
michael@0 | 374 | "onEnabled" |
michael@0 | 375 | ] |
michael@0 | 376 | }); |
michael@0 | 377 | |
michael@0 | 378 | AddonManager.getAddonsByIDs(["2@personas.mozilla.org", |
michael@0 | 379 | "theme2@tests.mozilla.org"], function([p2, t2]) { |
michael@0 | 380 | t2.userDisabled = false; |
michael@0 | 381 | |
michael@0 | 382 | ensure_test_completed(); |
michael@0 | 383 | |
michael@0 | 384 | prepare_test({ |
michael@0 | 385 | "2@personas.mozilla.org": [ |
michael@0 | 386 | "onEnabling" |
michael@0 | 387 | ], |
michael@0 | 388 | "theme2@tests.mozilla.org": [ |
michael@0 | 389 | ["onDisabling", false], |
michael@0 | 390 | "onDisabled" |
michael@0 | 391 | ] |
michael@0 | 392 | }); |
michael@0 | 393 | |
michael@0 | 394 | p2.userDisabled = false; |
michael@0 | 395 | |
michael@0 | 396 | ensure_test_completed(); |
michael@0 | 397 | |
michael@0 | 398 | prepare_test({ |
michael@0 | 399 | "2@personas.mozilla.org": [ |
michael@0 | 400 | ["onOperationCancelled", true] |
michael@0 | 401 | ], |
michael@0 | 402 | "theme2@tests.mozilla.org": [ |
michael@0 | 403 | ["onEnabling", false], |
michael@0 | 404 | "onEnabled" |
michael@0 | 405 | ] |
michael@0 | 406 | }); |
michael@0 | 407 | |
michael@0 | 408 | t2.userDisabled = false; |
michael@0 | 409 | |
michael@0 | 410 | ensure_test_completed(); |
michael@0 | 411 | |
michael@0 | 412 | do_check_true(t2.isActive); |
michael@0 | 413 | do_check_false(t2.userDisabled); |
michael@0 | 414 | do_check_false(hasFlag(AddonManager.PENDING_ENABLE, t2.pendingOperations)); |
michael@0 | 415 | do_check_false(p2.isActive); |
michael@0 | 416 | do_check_true(p2.userDisabled); |
michael@0 | 417 | do_check_false(hasFlag(AddonManager.PENDING_DISABLE, p2.pendingOperations)); |
michael@0 | 418 | do_check_true(hasFlag(AddonManager.PERM_CAN_ENABLE, p2.permissions)); |
michael@0 | 419 | do_check_true(gLWThemeChanged); |
michael@0 | 420 | |
michael@0 | 421 | do_execute_soon(check_test_5); |
michael@0 | 422 | }); |
michael@0 | 423 | } |
michael@0 | 424 | |
michael@0 | 425 | function check_test_5() { |
michael@0 | 426 | restartManager(); |
michael@0 | 427 | |
michael@0 | 428 | AddonManager.getAddonsByIDs(["2@personas.mozilla.org", |
michael@0 | 429 | "theme2@tests.mozilla.org"], function([p2, t2]) { |
michael@0 | 430 | do_check_true(t2.isActive); |
michael@0 | 431 | do_check_false(t2.userDisabled); |
michael@0 | 432 | do_check_false(hasFlag(AddonManager.PENDING_ENABLE, t2.pendingOperations)); |
michael@0 | 433 | do_check_false(p2.isActive); |
michael@0 | 434 | do_check_true(p2.userDisabled); |
michael@0 | 435 | do_check_false(hasFlag(AddonManager.PENDING_DISABLE, p2.pendingOperations)); |
michael@0 | 436 | |
michael@0 | 437 | do_check_true(gLWThemeChanged); |
michael@0 | 438 | gLWThemeChanged = false; |
michael@0 | 439 | |
michael@0 | 440 | do_execute_soon(run_test_6); |
michael@0 | 441 | }); |
michael@0 | 442 | } |
michael@0 | 443 | |
michael@0 | 444 | // Switching from a custom theme to a lightweight theme should require a restart |
michael@0 | 445 | function run_test_6() { |
michael@0 | 446 | prepare_test({ |
michael@0 | 447 | "2@personas.mozilla.org": [ |
michael@0 | 448 | "onEnabling", |
michael@0 | 449 | ], |
michael@0 | 450 | "theme2@tests.mozilla.org": [ |
michael@0 | 451 | ["onDisabling", false], |
michael@0 | 452 | "onDisabled" |
michael@0 | 453 | ] |
michael@0 | 454 | }); |
michael@0 | 455 | |
michael@0 | 456 | AddonManager.getAddonsByIDs(["2@personas.mozilla.org", |
michael@0 | 457 | "theme2@tests.mozilla.org"], function([p2, t2]) { |
michael@0 | 458 | p2.userDisabled = false; |
michael@0 | 459 | |
michael@0 | 460 | ensure_test_completed(); |
michael@0 | 461 | |
michael@0 | 462 | prepare_test({ |
michael@0 | 463 | "2@personas.mozilla.org": [ |
michael@0 | 464 | "onOperationCancelled", |
michael@0 | 465 | ], |
michael@0 | 466 | "theme2@tests.mozilla.org": [ |
michael@0 | 467 | ["onEnabling", false], |
michael@0 | 468 | "onEnabled" |
michael@0 | 469 | ] |
michael@0 | 470 | }); |
michael@0 | 471 | |
michael@0 | 472 | t2.userDisabled = false; |
michael@0 | 473 | |
michael@0 | 474 | ensure_test_completed(); |
michael@0 | 475 | |
michael@0 | 476 | prepare_test({ |
michael@0 | 477 | "2@personas.mozilla.org": [ |
michael@0 | 478 | "onEnabling", |
michael@0 | 479 | ], |
michael@0 | 480 | "theme2@tests.mozilla.org": [ |
michael@0 | 481 | ["onDisabling", false], |
michael@0 | 482 | "onDisabled" |
michael@0 | 483 | ] |
michael@0 | 484 | }); |
michael@0 | 485 | |
michael@0 | 486 | p2.userDisabled = false; |
michael@0 | 487 | |
michael@0 | 488 | ensure_test_completed(); |
michael@0 | 489 | |
michael@0 | 490 | do_check_false(p2.isActive); |
michael@0 | 491 | do_check_false(p2.userDisabled); |
michael@0 | 492 | do_check_true(hasFlag(AddonManager.PENDING_ENABLE, p2.pendingOperations)); |
michael@0 | 493 | do_check_false(t2.isActive); |
michael@0 | 494 | do_check_true(t2.userDisabled); |
michael@0 | 495 | do_check_false(hasFlag(AddonManager.PENDING_DISABLE, t2.pendingOperations)); |
michael@0 | 496 | do_check_false(gLWThemeChanged); |
michael@0 | 497 | |
michael@0 | 498 | do_execute_soon(check_test_6); |
michael@0 | 499 | }); |
michael@0 | 500 | } |
michael@0 | 501 | |
michael@0 | 502 | function check_test_6() { |
michael@0 | 503 | restartManager(); |
michael@0 | 504 | |
michael@0 | 505 | AddonManager.getAddonsByIDs(["2@personas.mozilla.org", |
michael@0 | 506 | "theme2@tests.mozilla.org"], function([p2, t2]) { |
michael@0 | 507 | do_check_true(p2.isActive); |
michael@0 | 508 | do_check_false(p2.userDisabled); |
michael@0 | 509 | do_check_false(hasFlag(AddonManager.PENDING_ENABLE, p2.pendingOperations)); |
michael@0 | 510 | do_check_false(t2.isActive); |
michael@0 | 511 | do_check_true(t2.userDisabled); |
michael@0 | 512 | do_check_false(hasFlag(AddonManager.PENDING_DISABLE, t2.pendingOperations)); |
michael@0 | 513 | |
michael@0 | 514 | do_check_true(gLWThemeChanged); |
michael@0 | 515 | gLWThemeChanged = false; |
michael@0 | 516 | |
michael@0 | 517 | do_execute_soon(run_test_7); |
michael@0 | 518 | }); |
michael@0 | 519 | } |
michael@0 | 520 | |
michael@0 | 521 | // Uninstalling a lightweight theme should not require a restart |
michael@0 | 522 | function run_test_7() { |
michael@0 | 523 | prepare_test({ |
michael@0 | 524 | "1@personas.mozilla.org": [ |
michael@0 | 525 | ["onUninstalling", false], |
michael@0 | 526 | "onUninstalled" |
michael@0 | 527 | ] |
michael@0 | 528 | }); |
michael@0 | 529 | |
michael@0 | 530 | AddonManager.getAddonByID("1@personas.mozilla.org", function(p1) { |
michael@0 | 531 | p1.uninstall(); |
michael@0 | 532 | |
michael@0 | 533 | ensure_test_completed(); |
michael@0 | 534 | do_check_eq(LightweightThemeManager.usedThemes.length, 1); |
michael@0 | 535 | do_check_false(gLWThemeChanged); |
michael@0 | 536 | |
michael@0 | 537 | do_execute_soon(run_test_8); |
michael@0 | 538 | }); |
michael@0 | 539 | } |
michael@0 | 540 | |
michael@0 | 541 | // Uninstalling a lightweight theme in use should not require a restart and it |
michael@0 | 542 | // should reactivate the default theme |
michael@0 | 543 | // Also, uninstalling a lightweight theme in use should send a |
michael@0 | 544 | // "lightweight-theme-styling-update" notification through the observer service |
michael@0 | 545 | function run_test_8() { |
michael@0 | 546 | prepare_test({ |
michael@0 | 547 | "2@personas.mozilla.org": [ |
michael@0 | 548 | ["onUninstalling", false], |
michael@0 | 549 | "onUninstalled" |
michael@0 | 550 | ], |
michael@0 | 551 | "default@tests.mozilla.org": [ |
michael@0 | 552 | ["onEnabling", false], |
michael@0 | 553 | "onEnabled" |
michael@0 | 554 | ] |
michael@0 | 555 | }); |
michael@0 | 556 | |
michael@0 | 557 | AddonManager.getAddonByID("2@personas.mozilla.org", function(p2) { |
michael@0 | 558 | p2.uninstall(); |
michael@0 | 559 | |
michael@0 | 560 | ensure_test_completed(); |
michael@0 | 561 | do_check_eq(LightweightThemeManager.usedThemes.length, 0); |
michael@0 | 562 | |
michael@0 | 563 | do_check_true(gLWThemeChanged); |
michael@0 | 564 | gLWThemeChanged = false; |
michael@0 | 565 | |
michael@0 | 566 | do_execute_soon(run_test_9); |
michael@0 | 567 | }); |
michael@0 | 568 | } |
michael@0 | 569 | |
michael@0 | 570 | // Uninstalling a theme not in use should not require a restart |
michael@0 | 571 | function run_test_9() { |
michael@0 | 572 | AddonManager.getAddonByID("theme1@tests.mozilla.org", function(t1) { |
michael@0 | 573 | prepare_test({ |
michael@0 | 574 | "theme1@tests.mozilla.org": [ |
michael@0 | 575 | ["onUninstalling", false], |
michael@0 | 576 | "onUninstalled" |
michael@0 | 577 | ] |
michael@0 | 578 | }); |
michael@0 | 579 | |
michael@0 | 580 | t1.uninstall(); |
michael@0 | 581 | |
michael@0 | 582 | ensure_test_completed(); |
michael@0 | 583 | |
michael@0 | 584 | AddonManager.getAddonByID("theme1@tests.mozilla.org", function(newt1) { |
michael@0 | 585 | do_check_eq(newt1, null); |
michael@0 | 586 | do_check_false(gLWThemeChanged); |
michael@0 | 587 | |
michael@0 | 588 | do_execute_soon(run_test_10); |
michael@0 | 589 | }); |
michael@0 | 590 | }); |
michael@0 | 591 | } |
michael@0 | 592 | |
michael@0 | 593 | // Uninstalling a custom theme in use should require a restart |
michael@0 | 594 | function run_test_10() { |
michael@0 | 595 | AddonManager.getAddonByID("theme2@tests.mozilla.org", callback_soon(function(oldt2) { |
michael@0 | 596 | prepare_test({ |
michael@0 | 597 | "theme2@tests.mozilla.org": [ |
michael@0 | 598 | ["onEnabling", false], |
michael@0 | 599 | "onEnabled" |
michael@0 | 600 | ], |
michael@0 | 601 | "default@tests.mozilla.org": [ |
michael@0 | 602 | ["onDisabling", false], |
michael@0 | 603 | "onDisabled" |
michael@0 | 604 | ] |
michael@0 | 605 | }); |
michael@0 | 606 | |
michael@0 | 607 | oldt2.userDisabled = false; |
michael@0 | 608 | |
michael@0 | 609 | ensure_test_completed(); |
michael@0 | 610 | |
michael@0 | 611 | restartManager(); |
michael@0 | 612 | |
michael@0 | 613 | AddonManager.getAddonsByIDs(["default@tests.mozilla.org", |
michael@0 | 614 | "theme2@tests.mozilla.org"], |
michael@0 | 615 | callback_soon(function([d, t2]) { |
michael@0 | 616 | do_check_true(t2.isActive); |
michael@0 | 617 | do_check_false(t2.userDisabled); |
michael@0 | 618 | do_check_false(t2.appDisabled); |
michael@0 | 619 | do_check_false(d.isActive); |
michael@0 | 620 | do_check_true(d.userDisabled); |
michael@0 | 621 | do_check_false(d.appDisabled); |
michael@0 | 622 | |
michael@0 | 623 | prepare_test({ |
michael@0 | 624 | "theme2@tests.mozilla.org": [ |
michael@0 | 625 | ["onUninstalling", false], |
michael@0 | 626 | "onUninstalled" |
michael@0 | 627 | ], |
michael@0 | 628 | "default@tests.mozilla.org": [ |
michael@0 | 629 | ["onEnabling", false], |
michael@0 | 630 | "onEnabled" |
michael@0 | 631 | ] |
michael@0 | 632 | }); |
michael@0 | 633 | |
michael@0 | 634 | t2.uninstall(); |
michael@0 | 635 | |
michael@0 | 636 | ensure_test_completed(); |
michael@0 | 637 | do_check_false(gLWThemeChanged); |
michael@0 | 638 | |
michael@0 | 639 | restartManager(); |
michael@0 | 640 | |
michael@0 | 641 | do_execute_soon(run_test_11); |
michael@0 | 642 | })); |
michael@0 | 643 | })); |
michael@0 | 644 | } |
michael@0 | 645 | |
michael@0 | 646 | // Installing a custom theme not in use should not require a restart |
michael@0 | 647 | function run_test_11() { |
michael@0 | 648 | prepare_test({ }, [ |
michael@0 | 649 | "onNewInstall" |
michael@0 | 650 | ]); |
michael@0 | 651 | |
michael@0 | 652 | AddonManager.getInstallForFile(do_get_addon("test_theme"), function(install) { |
michael@0 | 653 | ensure_test_completed(); |
michael@0 | 654 | |
michael@0 | 655 | do_check_neq(install, null); |
michael@0 | 656 | do_check_eq(install.type, "theme"); |
michael@0 | 657 | do_check_eq(install.version, "1.0"); |
michael@0 | 658 | do_check_eq(install.name, "Test Theme 1"); |
michael@0 | 659 | do_check_eq(install.state, AddonManager.STATE_DOWNLOADED); |
michael@0 | 660 | |
michael@0 | 661 | prepare_test({ |
michael@0 | 662 | "theme1@tests.mozilla.org": [ |
michael@0 | 663 | ["onInstalling", false], |
michael@0 | 664 | "onInstalled" |
michael@0 | 665 | ] |
michael@0 | 666 | }, [ |
michael@0 | 667 | "onInstallStarted", |
michael@0 | 668 | "onInstallEnded", |
michael@0 | 669 | ], callback_soon(check_test_11)); |
michael@0 | 670 | install.install(); |
michael@0 | 671 | }); |
michael@0 | 672 | } |
michael@0 | 673 | |
michael@0 | 674 | function check_test_11() { |
michael@0 | 675 | restartManager(); |
michael@0 | 676 | AddonManager.getAddonByID("theme1@tests.mozilla.org", function(t1) { |
michael@0 | 677 | do_check_neq(t1, null); |
michael@0 | 678 | var previewSpec = do_get_addon_root_uri(profileDir, "theme1@tests.mozilla.org") + "preview.png"; |
michael@0 | 679 | do_check_eq(t1.screenshots.length, 1); |
michael@0 | 680 | do_check_eq(t1.screenshots[0], previewSpec); |
michael@0 | 681 | do_check_false(gLWThemeChanged); |
michael@0 | 682 | |
michael@0 | 683 | do_execute_soon(run_test_12); |
michael@0 | 684 | }); |
michael@0 | 685 | } |
michael@0 | 686 | |
michael@0 | 687 | // Updating a custom theme not in use should not require a restart |
michael@0 | 688 | function run_test_12() { |
michael@0 | 689 | prepare_test({ }, [ |
michael@0 | 690 | "onNewInstall" |
michael@0 | 691 | ]); |
michael@0 | 692 | |
michael@0 | 693 | AddonManager.getInstallForFile(do_get_addon("test_theme"), function(install) { |
michael@0 | 694 | ensure_test_completed(); |
michael@0 | 695 | |
michael@0 | 696 | do_check_neq(install, null); |
michael@0 | 697 | do_check_eq(install.type, "theme"); |
michael@0 | 698 | do_check_eq(install.version, "1.0"); |
michael@0 | 699 | do_check_eq(install.name, "Test Theme 1"); |
michael@0 | 700 | do_check_eq(install.state, AddonManager.STATE_DOWNLOADED); |
michael@0 | 701 | |
michael@0 | 702 | prepare_test({ |
michael@0 | 703 | "theme1@tests.mozilla.org": [ |
michael@0 | 704 | ["onInstalling", false], |
michael@0 | 705 | "onInstalled" |
michael@0 | 706 | ] |
michael@0 | 707 | }, [ |
michael@0 | 708 | "onInstallStarted", |
michael@0 | 709 | "onInstallEnded", |
michael@0 | 710 | ], check_test_12); |
michael@0 | 711 | install.install(); |
michael@0 | 712 | }); |
michael@0 | 713 | } |
michael@0 | 714 | |
michael@0 | 715 | function check_test_12() { |
michael@0 | 716 | AddonManager.getAddonByID("theme1@tests.mozilla.org", function(t1) { |
michael@0 | 717 | do_check_neq(t1, null); |
michael@0 | 718 | do_check_false(gLWThemeChanged); |
michael@0 | 719 | |
michael@0 | 720 | do_execute_soon(run_test_13); |
michael@0 | 721 | }); |
michael@0 | 722 | } |
michael@0 | 723 | |
michael@0 | 724 | // Updating a custom theme in use should require a restart |
michael@0 | 725 | function run_test_13() { |
michael@0 | 726 | AddonManager.getAddonByID("theme1@tests.mozilla.org", callback_soon(function(t1) { |
michael@0 | 727 | prepare_test({ |
michael@0 | 728 | "theme1@tests.mozilla.org": [ |
michael@0 | 729 | ["onEnabling", false], |
michael@0 | 730 | "onEnabled" |
michael@0 | 731 | ], |
michael@0 | 732 | "default@tests.mozilla.org": [ |
michael@0 | 733 | ["onDisabling", false], |
michael@0 | 734 | "onDisabled" |
michael@0 | 735 | ] |
michael@0 | 736 | }); |
michael@0 | 737 | |
michael@0 | 738 | t1.userDisabled = false; |
michael@0 | 739 | ensure_test_completed(); |
michael@0 | 740 | restartManager(); |
michael@0 | 741 | |
michael@0 | 742 | prepare_test({ }, [ |
michael@0 | 743 | "onNewInstall" |
michael@0 | 744 | ]); |
michael@0 | 745 | |
michael@0 | 746 | AddonManager.getInstallForFile(do_get_addon("test_theme"), function(install) { |
michael@0 | 747 | ensure_test_completed(); |
michael@0 | 748 | |
michael@0 | 749 | do_check_neq(install, null); |
michael@0 | 750 | do_check_eq(install.type, "theme"); |
michael@0 | 751 | do_check_eq(install.version, "1.0"); |
michael@0 | 752 | do_check_eq(install.name, "Test Theme 1"); |
michael@0 | 753 | do_check_eq(install.state, AddonManager.STATE_DOWNLOADED); |
michael@0 | 754 | |
michael@0 | 755 | prepare_test({ |
michael@0 | 756 | "theme1@tests.mozilla.org": [ |
michael@0 | 757 | "onInstalling", |
michael@0 | 758 | ] |
michael@0 | 759 | }, [ |
michael@0 | 760 | "onInstallStarted", |
michael@0 | 761 | "onInstallEnded", |
michael@0 | 762 | ], callback_soon(check_test_13)); |
michael@0 | 763 | install.install(); |
michael@0 | 764 | }); |
michael@0 | 765 | })); |
michael@0 | 766 | } |
michael@0 | 767 | |
michael@0 | 768 | function check_test_13() { |
michael@0 | 769 | restartManager(); |
michael@0 | 770 | |
michael@0 | 771 | AddonManager.getAddonByID("theme1@tests.mozilla.org", function(t1) { |
michael@0 | 772 | do_check_neq(t1, null); |
michael@0 | 773 | do_check_true(t1.isActive); |
michael@0 | 774 | do_check_false(gLWThemeChanged); |
michael@0 | 775 | t1.uninstall(); |
michael@0 | 776 | |
michael@0 | 777 | do_execute_soon(run_test_14); |
michael@0 | 778 | }); |
michael@0 | 779 | } |
michael@0 | 780 | |
michael@0 | 781 | // Switching from a lightweight theme to the default theme should not require |
michael@0 | 782 | // a restart |
michael@0 | 783 | function run_test_14() { |
michael@0 | 784 | restartManager(); |
michael@0 | 785 | LightweightThemeManager.currentTheme = { |
michael@0 | 786 | id: "1", |
michael@0 | 787 | version: "1", |
michael@0 | 788 | name: "Test LW Theme", |
michael@0 | 789 | description: "A test theme", |
michael@0 | 790 | author: "Mozilla", |
michael@0 | 791 | homepageURL: "http://localhost:" + gPort + "/data/index.html", |
michael@0 | 792 | headerURL: "http://localhost:" + gPort + "/data/header.png", |
michael@0 | 793 | footerURL: "http://localhost:" + gPort + "/data/footer.png", |
michael@0 | 794 | previewURL: "http://localhost:" + gPort + "/data/preview.png", |
michael@0 | 795 | iconURL: "http://localhost:" + gPort + "/data/icon.png" |
michael@0 | 796 | }; |
michael@0 | 797 | |
michael@0 | 798 | AddonManager.getAddonByID("default@tests.mozilla.org", function(d) { |
michael@0 | 799 | do_check_true(d.userDisabled); |
michael@0 | 800 | do_check_false(d.isActive); |
michael@0 | 801 | |
michael@0 | 802 | prepare_test({ |
michael@0 | 803 | "1@personas.mozilla.org": [ |
michael@0 | 804 | ["onDisabling", false], |
michael@0 | 805 | "onDisabled" |
michael@0 | 806 | ], |
michael@0 | 807 | "default@tests.mozilla.org": [ |
michael@0 | 808 | ["onEnabling", false], |
michael@0 | 809 | "onEnabled" |
michael@0 | 810 | ] |
michael@0 | 811 | }); |
michael@0 | 812 | |
michael@0 | 813 | d.userDisabled = false; |
michael@0 | 814 | ensure_test_completed(); |
michael@0 | 815 | |
michael@0 | 816 | do_check_false(d.userDisabled); |
michael@0 | 817 | do_check_true(d.isActive); |
michael@0 | 818 | |
michael@0 | 819 | do_check_true(gLWThemeChanged); |
michael@0 | 820 | gLWThemeChanged = false; |
michael@0 | 821 | |
michael@0 | 822 | end_test(); |
michael@0 | 823 | }); |
michael@0 | 824 | } |