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 | // This verifies that add-on update checks work |
michael@0 | 6 | |
michael@0 | 7 | const PREF_MATCH_OS_LOCALE = "intl.locale.matchOS"; |
michael@0 | 8 | const PREF_SELECTED_LOCALE = "general.useragent.locale"; |
michael@0 | 9 | const PREF_GETADDONS_CACHE_ENABLED = "extensions.getAddons.cache.enabled"; |
michael@0 | 10 | |
michael@0 | 11 | // The test extension uses an insecure update url. |
michael@0 | 12 | Services.prefs.setBoolPref("extensions.checkUpdateSecurity", false); |
michael@0 | 13 | // This test requires lightweight themes update to be enabled even if the app |
michael@0 | 14 | // doesn't support lightweight themes. |
michael@0 | 15 | Services.prefs.setBoolPref("lightweightThemes.update.enabled", true); |
michael@0 | 16 | |
michael@0 | 17 | Components.utils.import("resource://gre/modules/LightweightThemeManager.jsm"); |
michael@0 | 18 | |
michael@0 | 19 | const PARAMS = "?%REQ_VERSION%/%ITEM_ID%/%ITEM_VERSION%/%ITEM_MAXAPPVERSION%/" + |
michael@0 | 20 | "%ITEM_STATUS%/%APP_ID%/%APP_VERSION%/%CURRENT_APP_VERSION%/" + |
michael@0 | 21 | "%APP_OS%/%APP_ABI%/%APP_LOCALE%/%UPDATE_TYPE%"; |
michael@0 | 22 | |
michael@0 | 23 | var gInstallDate; |
michael@0 | 24 | |
michael@0 | 25 | Components.utils.import("resource://testing-common/httpd.js"); |
michael@0 | 26 | var testserver = new HttpServer(); |
michael@0 | 27 | testserver.start(-1); |
michael@0 | 28 | gPort = testserver.identity.primaryPort; |
michael@0 | 29 | mapFile("/data/test_update.rdf", testserver); |
michael@0 | 30 | mapFile("/data/test_update.xml", testserver); |
michael@0 | 31 | testserver.registerDirectory("/addons/", do_get_file("addons")); |
michael@0 | 32 | |
michael@0 | 33 | const profileDir = gProfD.clone(); |
michael@0 | 34 | profileDir.append("extensions"); |
michael@0 | 35 | |
michael@0 | 36 | function run_test() { |
michael@0 | 37 | createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2"); |
michael@0 | 38 | Services.prefs.setBoolPref(PREF_MATCH_OS_LOCALE, false); |
michael@0 | 39 | Services.prefs.setCharPref(PREF_SELECTED_LOCALE, "fr-FR"); |
michael@0 | 40 | Services.prefs.setBoolPref(PREF_EM_STRICT_COMPATIBILITY, true); |
michael@0 | 41 | |
michael@0 | 42 | writeInstallRDFForExtension({ |
michael@0 | 43 | id: "addon1@tests.mozilla.org", |
michael@0 | 44 | version: "1.0", |
michael@0 | 45 | updateURL: "http://localhost:" + gPort + "/data/test_update.rdf", |
michael@0 | 46 | targetApplications: [{ |
michael@0 | 47 | id: "xpcshell@tests.mozilla.org", |
michael@0 | 48 | minVersion: "1", |
michael@0 | 49 | maxVersion: "1" |
michael@0 | 50 | }], |
michael@0 | 51 | name: "Test Addon 1", |
michael@0 | 52 | }, profileDir); |
michael@0 | 53 | |
michael@0 | 54 | writeInstallRDFForExtension({ |
michael@0 | 55 | id: "addon2@tests.mozilla.org", |
michael@0 | 56 | version: "1.0", |
michael@0 | 57 | updateURL: "http://localhost:" + gPort + "/data/test_update.rdf", |
michael@0 | 58 | targetApplications: [{ |
michael@0 | 59 | id: "xpcshell@tests.mozilla.org", |
michael@0 | 60 | minVersion: "0", |
michael@0 | 61 | maxVersion: "0" |
michael@0 | 62 | }], |
michael@0 | 63 | name: "Test Addon 2", |
michael@0 | 64 | }, profileDir); |
michael@0 | 65 | |
michael@0 | 66 | writeInstallRDFForExtension({ |
michael@0 | 67 | id: "addon3@tests.mozilla.org", |
michael@0 | 68 | version: "1.0", |
michael@0 | 69 | updateURL: "http://localhost:" + gPort + "/data/test_update.rdf", |
michael@0 | 70 | targetApplications: [{ |
michael@0 | 71 | id: "xpcshell@tests.mozilla.org", |
michael@0 | 72 | minVersion: "5", |
michael@0 | 73 | maxVersion: "5" |
michael@0 | 74 | }], |
michael@0 | 75 | name: "Test Addon 3", |
michael@0 | 76 | }, profileDir); |
michael@0 | 77 | |
michael@0 | 78 | startupManager(); |
michael@0 | 79 | |
michael@0 | 80 | do_test_pending(); |
michael@0 | 81 | run_test_1(); |
michael@0 | 82 | } |
michael@0 | 83 | |
michael@0 | 84 | function end_test() { |
michael@0 | 85 | Services.prefs.clearUserPref(PREF_EM_STRICT_COMPATIBILITY); |
michael@0 | 86 | |
michael@0 | 87 | testserver.stop(do_test_finished); |
michael@0 | 88 | } |
michael@0 | 89 | |
michael@0 | 90 | // Verify that an update is available and can be installed. |
michael@0 | 91 | function run_test_1() { |
michael@0 | 92 | AddonManager.getAddonByID("addon1@tests.mozilla.org", function(a1) { |
michael@0 | 93 | do_check_neq(a1, null); |
michael@0 | 94 | do_check_eq(a1.version, "1.0"); |
michael@0 | 95 | do_check_eq(a1.applyBackgroundUpdates, AddonManager.AUTOUPDATE_DEFAULT); |
michael@0 | 96 | do_check_eq(a1.releaseNotesURI, null); |
michael@0 | 97 | |
michael@0 | 98 | a1.applyBackgroundUpdates = AddonManager.AUTOUPDATE_DEFAULT; |
michael@0 | 99 | |
michael@0 | 100 | prepare_test({ |
michael@0 | 101 | "addon1@tests.mozilla.org": [ |
michael@0 | 102 | ["onPropertyChanged", ["applyBackgroundUpdates"]] |
michael@0 | 103 | ] |
michael@0 | 104 | }); |
michael@0 | 105 | a1.applyBackgroundUpdates = AddonManager.AUTOUPDATE_DISABLE; |
michael@0 | 106 | check_test_completed(); |
michael@0 | 107 | |
michael@0 | 108 | a1.applyBackgroundUpdates = AddonManager.AUTOUPDATE_DISABLE; |
michael@0 | 109 | |
michael@0 | 110 | prepare_test({}, [ |
michael@0 | 111 | "onNewInstall", |
michael@0 | 112 | ]); |
michael@0 | 113 | |
michael@0 | 114 | a1.findUpdates({ |
michael@0 | 115 | onNoCompatibilityUpdateAvailable: function(addon) { |
michael@0 | 116 | do_throw("Should not have seen onNoCompatibilityUpdateAvailable notification"); |
michael@0 | 117 | }, |
michael@0 | 118 | |
michael@0 | 119 | onUpdateAvailable: function(addon, install) { |
michael@0 | 120 | ensure_test_completed(); |
michael@0 | 121 | |
michael@0 | 122 | AddonManager.getAllInstalls(function(aInstalls) { |
michael@0 | 123 | do_check_eq(aInstalls.length, 1); |
michael@0 | 124 | do_check_eq(aInstalls[0], install); |
michael@0 | 125 | |
michael@0 | 126 | do_check_eq(addon, a1); |
michael@0 | 127 | do_check_eq(install.name, addon.name); |
michael@0 | 128 | do_check_eq(install.version, "2.0"); |
michael@0 | 129 | do_check_eq(install.state, AddonManager.STATE_AVAILABLE); |
michael@0 | 130 | do_check_eq(install.existingAddon, addon); |
michael@0 | 131 | do_check_eq(install.releaseNotesURI.spec, "http://example.com/updateInfo.xhtml"); |
michael@0 | 132 | |
michael@0 | 133 | // Verify that another update check returns the same AddonInstall |
michael@0 | 134 | a1.findUpdates({ |
michael@0 | 135 | onNoCompatibilityUpdateAvailable: function(addon) { |
michael@0 | 136 | do_throw("Should not have seen onNoCompatibilityUpdateAvailable notification"); |
michael@0 | 137 | }, |
michael@0 | 138 | |
michael@0 | 139 | onUpdateAvailable: function(newAddon, newInstall) { |
michael@0 | 140 | AddonManager.getAllInstalls(function(aInstalls) { |
michael@0 | 141 | do_check_eq(aInstalls.length, 1); |
michael@0 | 142 | do_check_eq(aInstalls[0], install); |
michael@0 | 143 | do_check_eq(newAddon, addon); |
michael@0 | 144 | do_check_eq(newInstall, install); |
michael@0 | 145 | |
michael@0 | 146 | prepare_test({}, [ |
michael@0 | 147 | "onDownloadStarted", |
michael@0 | 148 | "onDownloadEnded", |
michael@0 | 149 | ], check_test_1); |
michael@0 | 150 | install.install(); |
michael@0 | 151 | }); |
michael@0 | 152 | }, |
michael@0 | 153 | |
michael@0 | 154 | onNoUpdateAvailable: function(addon) { |
michael@0 | 155 | do_throw("Should not have seen onNoUpdateAvailable notification"); |
michael@0 | 156 | } |
michael@0 | 157 | }, AddonManager.UPDATE_WHEN_USER_REQUESTED); |
michael@0 | 158 | }); |
michael@0 | 159 | }, |
michael@0 | 160 | |
michael@0 | 161 | onNoUpdateAvailable: function(addon) { |
michael@0 | 162 | do_throw("Should not have seen onNoUpdateAvailable notification"); |
michael@0 | 163 | } |
michael@0 | 164 | }, AddonManager.UPDATE_WHEN_USER_REQUESTED); |
michael@0 | 165 | }); |
michael@0 | 166 | } |
michael@0 | 167 | |
michael@0 | 168 | function check_test_1(install) { |
michael@0 | 169 | ensure_test_completed(); |
michael@0 | 170 | do_check_eq(install.state, AddonManager.STATE_DOWNLOADED); |
michael@0 | 171 | run_test_2(install); |
michael@0 | 172 | return false; |
michael@0 | 173 | } |
michael@0 | 174 | |
michael@0 | 175 | // Continue installing the update. |
michael@0 | 176 | function run_test_2(install) { |
michael@0 | 177 | // Verify that another update check returns no new update |
michael@0 | 178 | install.existingAddon.findUpdates({ |
michael@0 | 179 | onNoCompatibilityUpdateAvailable: function(addon) { |
michael@0 | 180 | do_throw("Should not have seen onNoCompatibilityUpdateAvailable notification"); |
michael@0 | 181 | }, |
michael@0 | 182 | |
michael@0 | 183 | onUpdateAvailable: function(addon, install) { |
michael@0 | 184 | do_throw("Should find no available update when one is already downloading"); |
michael@0 | 185 | }, |
michael@0 | 186 | |
michael@0 | 187 | onNoUpdateAvailable: function(addon) { |
michael@0 | 188 | AddonManager.getAllInstalls(function(aInstalls) { |
michael@0 | 189 | do_check_eq(aInstalls.length, 1); |
michael@0 | 190 | do_check_eq(aInstalls[0], install); |
michael@0 | 191 | |
michael@0 | 192 | prepare_test({ |
michael@0 | 193 | "addon1@tests.mozilla.org": [ |
michael@0 | 194 | "onInstalling" |
michael@0 | 195 | ] |
michael@0 | 196 | }, [ |
michael@0 | 197 | "onInstallStarted", |
michael@0 | 198 | "onInstallEnded", |
michael@0 | 199 | ], check_test_2); |
michael@0 | 200 | install.install(); |
michael@0 | 201 | }); |
michael@0 | 202 | } |
michael@0 | 203 | }, AddonManager.UPDATE_WHEN_USER_REQUESTED); |
michael@0 | 204 | } |
michael@0 | 205 | |
michael@0 | 206 | function check_test_2() { |
michael@0 | 207 | ensure_test_completed(); |
michael@0 | 208 | |
michael@0 | 209 | AddonManager.getAddonByID("addon1@tests.mozilla.org", callback_soon(function(olda1) { |
michael@0 | 210 | do_check_neq(olda1, null); |
michael@0 | 211 | do_check_eq(olda1.version, "1.0"); |
michael@0 | 212 | do_check_true(isExtensionInAddonsList(profileDir, olda1.id)); |
michael@0 | 213 | |
michael@0 | 214 | shutdownManager(); |
michael@0 | 215 | |
michael@0 | 216 | startupManager(); |
michael@0 | 217 | |
michael@0 | 218 | do_check_true(isExtensionInAddonsList(profileDir, olda1.id)); |
michael@0 | 219 | |
michael@0 | 220 | AddonManager.getAddonByID("addon1@tests.mozilla.org", function(a1) { |
michael@0 | 221 | do_check_neq(a1, null); |
michael@0 | 222 | do_check_eq(a1.version, "2.0"); |
michael@0 | 223 | do_check_true(isExtensionInAddonsList(profileDir, a1.id)); |
michael@0 | 224 | do_check_eq(a1.applyBackgroundUpdates, AddonManager.AUTOUPDATE_DISABLE); |
michael@0 | 225 | do_check_eq(a1.releaseNotesURI.spec, "http://example.com/updateInfo.xhtml"); |
michael@0 | 226 | |
michael@0 | 227 | a1.uninstall(); |
michael@0 | 228 | do_execute_soon(run_test_3); |
michael@0 | 229 | }); |
michael@0 | 230 | })); |
michael@0 | 231 | } |
michael@0 | 232 | |
michael@0 | 233 | |
michael@0 | 234 | // Check that an update check finds compatibility updates and applies them |
michael@0 | 235 | function run_test_3() { |
michael@0 | 236 | restartManager(); |
michael@0 | 237 | |
michael@0 | 238 | AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) { |
michael@0 | 239 | do_check_neq(a2, null); |
michael@0 | 240 | do_check_false(a2.isActive); |
michael@0 | 241 | do_check_false(a2.isCompatible); |
michael@0 | 242 | do_check_true(a2.appDisabled); |
michael@0 | 243 | do_check_true(a2.isCompatibleWith("0")); |
michael@0 | 244 | |
michael@0 | 245 | a2.findUpdates({ |
michael@0 | 246 | onCompatibilityUpdateAvailable: function(addon) { |
michael@0 | 247 | do_check_true(a2.isCompatible); |
michael@0 | 248 | do_check_false(a2.appDisabled); |
michael@0 | 249 | do_check_false(a2.isActive); |
michael@0 | 250 | }, |
michael@0 | 251 | |
michael@0 | 252 | onUpdateAvailable: function(addon, install) { |
michael@0 | 253 | do_throw("Should not have seen an available update"); |
michael@0 | 254 | }, |
michael@0 | 255 | |
michael@0 | 256 | onNoUpdateAvailable: function(addon) { |
michael@0 | 257 | do_check_eq(addon, a2); |
michael@0 | 258 | do_execute_soon(check_test_3); |
michael@0 | 259 | } |
michael@0 | 260 | }, AddonManager.UPDATE_WHEN_USER_REQUESTED); |
michael@0 | 261 | }); |
michael@0 | 262 | } |
michael@0 | 263 | |
michael@0 | 264 | function check_test_3() { |
michael@0 | 265 | restartManager(); |
michael@0 | 266 | AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) { |
michael@0 | 267 | do_check_neq(a2, null); |
michael@0 | 268 | do_check_true(a2.isActive); |
michael@0 | 269 | do_check_true(a2.isCompatible); |
michael@0 | 270 | do_check_false(a2.appDisabled); |
michael@0 | 271 | a2.uninstall(); |
michael@0 | 272 | |
michael@0 | 273 | run_test_4(); |
michael@0 | 274 | }); |
michael@0 | 275 | } |
michael@0 | 276 | |
michael@0 | 277 | // Checks that we see no compatibility information when there is none. |
michael@0 | 278 | function run_test_4() { |
michael@0 | 279 | AddonManager.getAddonByID("addon3@tests.mozilla.org", function(a3) { |
michael@0 | 280 | do_check_neq(a3, null); |
michael@0 | 281 | do_check_false(a3.isActive); |
michael@0 | 282 | do_check_false(a3.isCompatible); |
michael@0 | 283 | do_check_true(a3.appDisabled); |
michael@0 | 284 | do_check_true(a3.isCompatibleWith("5")); |
michael@0 | 285 | do_check_false(a3.isCompatibleWith("2")); |
michael@0 | 286 | |
michael@0 | 287 | a3.findUpdates({ |
michael@0 | 288 | sawUpdate: false, |
michael@0 | 289 | onCompatibilityUpdateAvailable: function(addon) { |
michael@0 | 290 | do_throw("Should not have seen compatibility information"); |
michael@0 | 291 | }, |
michael@0 | 292 | |
michael@0 | 293 | onNoCompatibilityUpdateAvailable: function(addon) { |
michael@0 | 294 | this.sawUpdate = true; |
michael@0 | 295 | }, |
michael@0 | 296 | |
michael@0 | 297 | onUpdateAvailable: function(addon, install) { |
michael@0 | 298 | do_throw("Should not have seen an available update"); |
michael@0 | 299 | }, |
michael@0 | 300 | |
michael@0 | 301 | onNoUpdateAvailable: function(addon) { |
michael@0 | 302 | do_check_true(this.sawUpdate); |
michael@0 | 303 | run_test_5(); |
michael@0 | 304 | } |
michael@0 | 305 | }, AddonManager.UPDATE_WHEN_USER_REQUESTED); |
michael@0 | 306 | }); |
michael@0 | 307 | } |
michael@0 | 308 | |
michael@0 | 309 | // Checks that compatibility info for future apps are detected but don't make |
michael@0 | 310 | // the item compatibile. |
michael@0 | 311 | function run_test_5() { |
michael@0 | 312 | AddonManager.getAddonByID("addon3@tests.mozilla.org", function(a3) { |
michael@0 | 313 | do_check_neq(a3, null); |
michael@0 | 314 | do_check_false(a3.isActive); |
michael@0 | 315 | do_check_false(a3.isCompatible); |
michael@0 | 316 | do_check_true(a3.appDisabled); |
michael@0 | 317 | do_check_true(a3.isCompatibleWith("5")); |
michael@0 | 318 | do_check_false(a3.isCompatibleWith("2")); |
michael@0 | 319 | |
michael@0 | 320 | a3.findUpdates({ |
michael@0 | 321 | sawUpdate: false, |
michael@0 | 322 | onCompatibilityUpdateAvailable: function(addon) { |
michael@0 | 323 | do_check_false(a3.isCompatible); |
michael@0 | 324 | do_check_true(a3.appDisabled); |
michael@0 | 325 | do_check_false(a3.isActive); |
michael@0 | 326 | this.sawUpdate = true; |
michael@0 | 327 | }, |
michael@0 | 328 | |
michael@0 | 329 | onNoCompatibilityUpdateAvailable: function(addon) { |
michael@0 | 330 | do_throw("Should have seen some compatibility information"); |
michael@0 | 331 | }, |
michael@0 | 332 | |
michael@0 | 333 | onUpdateAvailable: function(addon, install) { |
michael@0 | 334 | do_throw("Should not have seen an available update"); |
michael@0 | 335 | }, |
michael@0 | 336 | |
michael@0 | 337 | onNoUpdateAvailable: function(addon) { |
michael@0 | 338 | do_check_true(this.sawUpdate); |
michael@0 | 339 | do_execute_soon(check_test_5); |
michael@0 | 340 | } |
michael@0 | 341 | }, AddonManager.UPDATE_WHEN_USER_REQUESTED, "3.0"); |
michael@0 | 342 | }); |
michael@0 | 343 | } |
michael@0 | 344 | |
michael@0 | 345 | function check_test_5() { |
michael@0 | 346 | restartManager(); |
michael@0 | 347 | AddonManager.getAddonByID("addon3@tests.mozilla.org", function(a3) { |
michael@0 | 348 | do_check_neq(a3, null); |
michael@0 | 349 | do_check_false(a3.isActive); |
michael@0 | 350 | do_check_false(a3.isCompatible); |
michael@0 | 351 | do_check_true(a3.appDisabled); |
michael@0 | 352 | |
michael@0 | 353 | a3.uninstall(); |
michael@0 | 354 | do_execute_soon(run_test_6); |
michael@0 | 355 | }); |
michael@0 | 356 | } |
michael@0 | 357 | |
michael@0 | 358 | // Test that background update checks work |
michael@0 | 359 | function run_test_6() { |
michael@0 | 360 | restartManager(); |
michael@0 | 361 | |
michael@0 | 362 | writeInstallRDFForExtension({ |
michael@0 | 363 | id: "addon1@tests.mozilla.org", |
michael@0 | 364 | version: "1.0", |
michael@0 | 365 | updateURL: "http://localhost:" + gPort + "/data/test_update.rdf", |
michael@0 | 366 | targetApplications: [{ |
michael@0 | 367 | id: "xpcshell@tests.mozilla.org", |
michael@0 | 368 | minVersion: "1", |
michael@0 | 369 | maxVersion: "1" |
michael@0 | 370 | }], |
michael@0 | 371 | name: "Test Addon 1", |
michael@0 | 372 | }, profileDir); |
michael@0 | 373 | restartManager(); |
michael@0 | 374 | |
michael@0 | 375 | prepare_test({}, [ |
michael@0 | 376 | "onNewInstall", |
michael@0 | 377 | "onDownloadStarted", |
michael@0 | 378 | "onDownloadEnded" |
michael@0 | 379 | ], continue_test_6); |
michael@0 | 380 | |
michael@0 | 381 | // Fake a timer event to cause a background update and wait for the magic to |
michael@0 | 382 | // happen |
michael@0 | 383 | gInternalManager.notify(null); |
michael@0 | 384 | } |
michael@0 | 385 | |
michael@0 | 386 | function continue_test_6(install) { |
michael@0 | 387 | do_check_neq(install.existingAddon, null); |
michael@0 | 388 | do_check_eq(install.existingAddon.id, "addon1@tests.mozilla.org"); |
michael@0 | 389 | |
michael@0 | 390 | prepare_test({ |
michael@0 | 391 | "addon1@tests.mozilla.org": [ |
michael@0 | 392 | "onInstalling" |
michael@0 | 393 | ] |
michael@0 | 394 | }, [ |
michael@0 | 395 | "onInstallStarted", |
michael@0 | 396 | "onInstallEnded", |
michael@0 | 397 | ], callback_soon(check_test_6)); |
michael@0 | 398 | } |
michael@0 | 399 | |
michael@0 | 400 | function check_test_6(install) { |
michael@0 | 401 | do_check_eq(install.existingAddon.pendingUpgrade.install, install); |
michael@0 | 402 | |
michael@0 | 403 | restartManager(); |
michael@0 | 404 | AddonManager.getAddonByID("addon1@tests.mozilla.org", function(a1) { |
michael@0 | 405 | do_check_neq(a1, null); |
michael@0 | 406 | do_check_eq(a1.version, "2.0"); |
michael@0 | 407 | do_check_eq(a1.releaseNotesURI.spec, "http://example.com/updateInfo.xhtml"); |
michael@0 | 408 | a1.uninstall(); |
michael@0 | 409 | do_execute_soon(run_test_7); |
michael@0 | 410 | }); |
michael@0 | 411 | } |
michael@0 | 412 | |
michael@0 | 413 | // Test that background update checks work for lightweight themes |
michael@0 | 414 | function run_test_7() { |
michael@0 | 415 | restartManager(); |
michael@0 | 416 | |
michael@0 | 417 | LightweightThemeManager.currentTheme = { |
michael@0 | 418 | id: "1", |
michael@0 | 419 | version: "1", |
michael@0 | 420 | name: "Test LW Theme", |
michael@0 | 421 | description: "A test theme", |
michael@0 | 422 | author: "Mozilla", |
michael@0 | 423 | homepageURL: "http://localhost:" + gPort + "/data/index.html", |
michael@0 | 424 | headerURL: "http://localhost:" + gPort + "/data/header.png", |
michael@0 | 425 | footerURL: "http://localhost:" + gPort + "/data/footer.png", |
michael@0 | 426 | previewURL: "http://localhost:" + gPort + "/data/preview.png", |
michael@0 | 427 | iconURL: "http://localhost:" + gPort + "/data/icon.png", |
michael@0 | 428 | updateURL: "http://localhost:" + gPort + "/data/lwtheme.js" |
michael@0 | 429 | }; |
michael@0 | 430 | |
michael@0 | 431 | // XXX The lightweight theme manager strips non-https updateURLs so hack it |
michael@0 | 432 | // back in. |
michael@0 | 433 | let themes = JSON.parse(Services.prefs.getCharPref("lightweightThemes.usedThemes")); |
michael@0 | 434 | do_check_eq(themes.length, 1); |
michael@0 | 435 | themes[0].updateURL = "http://localhost:" + gPort + "/data/lwtheme.js"; |
michael@0 | 436 | Services.prefs.setCharPref("lightweightThemes.usedThemes", JSON.stringify(themes)); |
michael@0 | 437 | |
michael@0 | 438 | testserver.registerPathHandler("/data/lwtheme.js", function(request, response) { |
michael@0 | 439 | response.write(JSON.stringify({ |
michael@0 | 440 | id: "1", |
michael@0 | 441 | version: "2", |
michael@0 | 442 | name: "Updated Theme", |
michael@0 | 443 | description: "A test theme", |
michael@0 | 444 | author: "Mozilla", |
michael@0 | 445 | homepageURL: "http://localhost:" + gPort + "/data/index2.html", |
michael@0 | 446 | headerURL: "http://localhost:" + gPort + "/data/header.png", |
michael@0 | 447 | footerURL: "http://localhost:" + gPort + "/data/footer.png", |
michael@0 | 448 | previewURL: "http://localhost:" + gPort + "/data/preview.png", |
michael@0 | 449 | iconURL: "http://localhost:" + gPort + "/data/icon2.png", |
michael@0 | 450 | updateURL: "http://localhost:" + gPort + "/data/lwtheme.js" |
michael@0 | 451 | })); |
michael@0 | 452 | }); |
michael@0 | 453 | |
michael@0 | 454 | AddonManager.getAddonByID("1@personas.mozilla.org", function(p1) { |
michael@0 | 455 | do_check_neq(p1, null); |
michael@0 | 456 | do_check_eq(p1.version, "1"); |
michael@0 | 457 | do_check_eq(p1.name, "Test LW Theme"); |
michael@0 | 458 | do_check_true(p1.isActive); |
michael@0 | 459 | do_check_eq(p1.installDate.getTime(), p1.updateDate.getTime()); |
michael@0 | 460 | |
michael@0 | 461 | // 5 seconds leeway seems like a lot, but tests can run slow and really if |
michael@0 | 462 | // this is within 5 seconds it is fine. If it is going to be wrong then it |
michael@0 | 463 | // is likely to be hours out at least |
michael@0 | 464 | do_check_true((Date.now() - p1.installDate.getTime()) < 5000); |
michael@0 | 465 | |
michael@0 | 466 | gInstallDate = p1.installDate.getTime(); |
michael@0 | 467 | |
michael@0 | 468 | prepare_test({ |
michael@0 | 469 | "1@personas.mozilla.org": [ |
michael@0 | 470 | ["onInstalling", false], |
michael@0 | 471 | "onInstalled" |
michael@0 | 472 | ] |
michael@0 | 473 | }, [ |
michael@0 | 474 | "onExternalInstall" |
michael@0 | 475 | ], check_test_7); |
michael@0 | 476 | |
michael@0 | 477 | // Fake a timer event to cause a background update and wait for the magic to |
michael@0 | 478 | // happen |
michael@0 | 479 | gInternalManager.notify(null); |
michael@0 | 480 | }); |
michael@0 | 481 | } |
michael@0 | 482 | |
michael@0 | 483 | function check_test_7() { |
michael@0 | 484 | AddonManager.getAddonByID("1@personas.mozilla.org", function(p1) { |
michael@0 | 485 | do_check_neq(p1, null); |
michael@0 | 486 | do_check_eq(p1.version, "2"); |
michael@0 | 487 | do_check_eq(p1.name, "Updated Theme"); |
michael@0 | 488 | do_check_eq(p1.installDate.getTime(), gInstallDate); |
michael@0 | 489 | do_check_true(p1.installDate.getTime() < p1.updateDate.getTime()); |
michael@0 | 490 | |
michael@0 | 491 | // 5 seconds leeway seems like a lot, but tests can run slow and really if |
michael@0 | 492 | // this is within 5 seconds it is fine. If it is going to be wrong then it |
michael@0 | 493 | // is likely to be hours out at least |
michael@0 | 494 | do_check_true((Date.now() - p1.updateDate.getTime()) < 5000); |
michael@0 | 495 | |
michael@0 | 496 | gInstallDate = p1.installDate.getTime(); |
michael@0 | 497 | |
michael@0 | 498 | do_execute_soon(run_test_8); |
michael@0 | 499 | }); |
michael@0 | 500 | } |
michael@0 | 501 | |
michael@0 | 502 | // Verify the parameter escaping in update urls. |
michael@0 | 503 | function run_test_8() { |
michael@0 | 504 | writeInstallRDFForExtension({ |
michael@0 | 505 | id: "addon1@tests.mozilla.org", |
michael@0 | 506 | version: "5.0", |
michael@0 | 507 | updateURL: "http://localhost:" + gPort + "/data/param_test.rdf" + PARAMS, |
michael@0 | 508 | targetApplications: [{ |
michael@0 | 509 | id: "xpcshell@tests.mozilla.org", |
michael@0 | 510 | minVersion: "1", |
michael@0 | 511 | maxVersion: "2" |
michael@0 | 512 | }], |
michael@0 | 513 | name: "Test Addon 1", |
michael@0 | 514 | }, profileDir); |
michael@0 | 515 | |
michael@0 | 516 | writeInstallRDFForExtension({ |
michael@0 | 517 | id: "addon2@tests.mozilla.org", |
michael@0 | 518 | version: "67.0.5b1", |
michael@0 | 519 | updateURL: "http://localhost:" + gPort + "/data/param_test.rdf" + PARAMS, |
michael@0 | 520 | targetApplications: [{ |
michael@0 | 521 | id: "toolkit@mozilla.org", |
michael@0 | 522 | minVersion: "0", |
michael@0 | 523 | maxVersion: "3" |
michael@0 | 524 | }], |
michael@0 | 525 | name: "Test Addon 2", |
michael@0 | 526 | }, profileDir); |
michael@0 | 527 | |
michael@0 | 528 | writeInstallRDFForExtension({ |
michael@0 | 529 | id: "addon3@tests.mozilla.org", |
michael@0 | 530 | version: "1.3+", |
michael@0 | 531 | updateURL: "http://localhost:" + gPort + "/data/param_test.rdf" + PARAMS, |
michael@0 | 532 | targetApplications: [{ |
michael@0 | 533 | id: "xpcshell@tests.mozilla.org", |
michael@0 | 534 | minVersion: "0", |
michael@0 | 535 | maxVersion: "0" |
michael@0 | 536 | }, { |
michael@0 | 537 | id: "toolkit@mozilla.org", |
michael@0 | 538 | minVersion: "0", |
michael@0 | 539 | maxVersion: "3" |
michael@0 | 540 | }], |
michael@0 | 541 | name: "Test Addon 3", |
michael@0 | 542 | }, profileDir); |
michael@0 | 543 | |
michael@0 | 544 | writeInstallRDFForExtension({ |
michael@0 | 545 | id: "addon4@tests.mozilla.org", |
michael@0 | 546 | version: "0.5ab6", |
michael@0 | 547 | updateURL: "http://localhost:" + gPort + "/data/param_test.rdf" + PARAMS, |
michael@0 | 548 | targetApplications: [{ |
michael@0 | 549 | id: "xpcshell@tests.mozilla.org", |
michael@0 | 550 | minVersion: "1", |
michael@0 | 551 | maxVersion: "5" |
michael@0 | 552 | }], |
michael@0 | 553 | name: "Test Addon 4", |
michael@0 | 554 | }, profileDir); |
michael@0 | 555 | |
michael@0 | 556 | writeInstallRDFForExtension({ |
michael@0 | 557 | id: "addon5@tests.mozilla.org", |
michael@0 | 558 | version: "1.0", |
michael@0 | 559 | updateURL: "http://localhost:" + gPort + "/data/param_test.rdf" + PARAMS, |
michael@0 | 560 | targetApplications: [{ |
michael@0 | 561 | id: "xpcshell@tests.mozilla.org", |
michael@0 | 562 | minVersion: "1", |
michael@0 | 563 | maxVersion: "1" |
michael@0 | 564 | }], |
michael@0 | 565 | name: "Test Addon 5", |
michael@0 | 566 | }, profileDir); |
michael@0 | 567 | |
michael@0 | 568 | writeInstallRDFForExtension({ |
michael@0 | 569 | id: "addon6@tests.mozilla.org", |
michael@0 | 570 | version: "1.0", |
michael@0 | 571 | updateURL: "http://localhost:" + gPort + "/data/param_test.rdf" + PARAMS, |
michael@0 | 572 | targetApplications: [{ |
michael@0 | 573 | id: "xpcshell@tests.mozilla.org", |
michael@0 | 574 | minVersion: "1", |
michael@0 | 575 | maxVersion: "1" |
michael@0 | 576 | }], |
michael@0 | 577 | name: "Test Addon 6", |
michael@0 | 578 | }, profileDir); |
michael@0 | 579 | |
michael@0 | 580 | restartManager(); |
michael@0 | 581 | |
michael@0 | 582 | AddonManager.getAddonByID("addon2@tests.mozilla.org", callback_soon(function(a2) { |
michael@0 | 583 | a2.userDisabled = true; |
michael@0 | 584 | restartManager(); |
michael@0 | 585 | |
michael@0 | 586 | testserver.registerPathHandler("/data/param_test.rdf", function(request, response) { |
michael@0 | 587 | do_check_neq(request.queryString, ""); |
michael@0 | 588 | let [req_version, item_id, item_version, |
michael@0 | 589 | item_maxappversion, item_status, |
michael@0 | 590 | app_id, app_version, current_app_version, |
michael@0 | 591 | app_os, app_abi, app_locale, update_type] = |
michael@0 | 592 | [decodeURIComponent(a) for each (a in request.queryString.split("/"))]; |
michael@0 | 593 | |
michael@0 | 594 | do_check_eq(req_version, "2"); |
michael@0 | 595 | |
michael@0 | 596 | switch(item_id) { |
michael@0 | 597 | case "addon1@tests.mozilla.org": |
michael@0 | 598 | do_check_eq(item_version, "5.0"); |
michael@0 | 599 | do_check_eq(item_maxappversion, "2"); |
michael@0 | 600 | do_check_eq(item_status, "userEnabled"); |
michael@0 | 601 | do_check_eq(app_version, "1"); |
michael@0 | 602 | do_check_eq(update_type, "97"); |
michael@0 | 603 | break; |
michael@0 | 604 | case "addon2@tests.mozilla.org": |
michael@0 | 605 | do_check_eq(item_version, "67.0.5b1"); |
michael@0 | 606 | do_check_eq(item_maxappversion, "3"); |
michael@0 | 607 | do_check_eq(item_status, "userDisabled"); |
michael@0 | 608 | do_check_eq(app_version, "1"); |
michael@0 | 609 | do_check_eq(update_type, "49"); |
michael@0 | 610 | break; |
michael@0 | 611 | case "addon3@tests.mozilla.org": |
michael@0 | 612 | do_check_eq(item_version, "1.3+"); |
michael@0 | 613 | do_check_eq(item_maxappversion, "0"); |
michael@0 | 614 | do_check_eq(item_status, "userEnabled,incompatible"); |
michael@0 | 615 | do_check_eq(app_version, "1"); |
michael@0 | 616 | do_check_eq(update_type, "112"); |
michael@0 | 617 | break; |
michael@0 | 618 | case "addon4@tests.mozilla.org": |
michael@0 | 619 | do_check_eq(item_version, "0.5ab6"); |
michael@0 | 620 | do_check_eq(item_maxappversion, "5"); |
michael@0 | 621 | do_check_eq(item_status, "userEnabled"); |
michael@0 | 622 | do_check_eq(app_version, "2"); |
michael@0 | 623 | do_check_eq(update_type, "98"); |
michael@0 | 624 | break; |
michael@0 | 625 | case "addon5@tests.mozilla.org": |
michael@0 | 626 | do_check_eq(item_version, "1.0"); |
michael@0 | 627 | do_check_eq(item_maxappversion, "1"); |
michael@0 | 628 | do_check_eq(item_status, "userEnabled"); |
michael@0 | 629 | do_check_eq(app_version, "1"); |
michael@0 | 630 | do_check_eq(update_type, "35"); |
michael@0 | 631 | break; |
michael@0 | 632 | case "addon6@tests.mozilla.org": |
michael@0 | 633 | do_check_eq(item_version, "1.0"); |
michael@0 | 634 | do_check_eq(item_maxappversion, "1"); |
michael@0 | 635 | do_check_eq(item_status, "userEnabled"); |
michael@0 | 636 | do_check_eq(app_version, "1"); |
michael@0 | 637 | do_check_eq(update_type, "99"); |
michael@0 | 638 | break; |
michael@0 | 639 | default: |
michael@0 | 640 | do_throw("Update request for unexpected add-on " + item_id); |
michael@0 | 641 | } |
michael@0 | 642 | |
michael@0 | 643 | do_check_eq(app_id, "xpcshell@tests.mozilla.org"); |
michael@0 | 644 | do_check_eq(current_app_version, "1"); |
michael@0 | 645 | do_check_eq(app_os, "XPCShell"); |
michael@0 | 646 | do_check_eq(app_abi, "noarch-spidermonkey"); |
michael@0 | 647 | do_check_eq(app_locale, "fr-FR"); |
michael@0 | 648 | |
michael@0 | 649 | request.setStatusLine(null, 500, "Server Error"); |
michael@0 | 650 | }); |
michael@0 | 651 | |
michael@0 | 652 | AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org", |
michael@0 | 653 | "addon2@tests.mozilla.org", |
michael@0 | 654 | "addon3@tests.mozilla.org", |
michael@0 | 655 | "addon4@tests.mozilla.org", |
michael@0 | 656 | "addon5@tests.mozilla.org", |
michael@0 | 657 | "addon6@tests.mozilla.org"], |
michael@0 | 658 | function([a1, a2, a3, a4, a5, a6]) { |
michael@0 | 659 | let count = 6; |
michael@0 | 660 | |
michael@0 | 661 | function run_next_test() { |
michael@0 | 662 | a1.uninstall(); |
michael@0 | 663 | a2.uninstall(); |
michael@0 | 664 | a3.uninstall(); |
michael@0 | 665 | a4.uninstall(); |
michael@0 | 666 | a5.uninstall(); |
michael@0 | 667 | a6.uninstall(); |
michael@0 | 668 | |
michael@0 | 669 | restartManager(); |
michael@0 | 670 | run_test_9(); |
michael@0 | 671 | } |
michael@0 | 672 | |
michael@0 | 673 | let compatListener = { |
michael@0 | 674 | onUpdateFinished: function(addon, error) { |
michael@0 | 675 | if (--count == 0) |
michael@0 | 676 | do_execute_soon(run_next_test); |
michael@0 | 677 | } |
michael@0 | 678 | }; |
michael@0 | 679 | |
michael@0 | 680 | let updateListener = { |
michael@0 | 681 | onUpdateAvailable: function(addon, update) { |
michael@0 | 682 | // Dummy so the update checker knows we care about new versions |
michael@0 | 683 | }, |
michael@0 | 684 | |
michael@0 | 685 | onUpdateFinished: function(addon, error) { |
michael@0 | 686 | if (--count == 0) |
michael@0 | 687 | do_execute_soon(run_next_test); |
michael@0 | 688 | } |
michael@0 | 689 | }; |
michael@0 | 690 | |
michael@0 | 691 | a1.findUpdates(updateListener, AddonManager.UPDATE_WHEN_USER_REQUESTED); |
michael@0 | 692 | a2.findUpdates(compatListener, AddonManager.UPDATE_WHEN_ADDON_INSTALLED); |
michael@0 | 693 | a3.findUpdates(updateListener, AddonManager.UPDATE_WHEN_PERIODIC_UPDATE); |
michael@0 | 694 | a4.findUpdates(updateListener, AddonManager.UPDATE_WHEN_NEW_APP_DETECTED, "2"); |
michael@0 | 695 | a5.findUpdates(compatListener, AddonManager.UPDATE_WHEN_NEW_APP_INSTALLED); |
michael@0 | 696 | a6.findUpdates(updateListener, AddonManager.UPDATE_WHEN_NEW_APP_INSTALLED); |
michael@0 | 697 | }); |
michael@0 | 698 | })); |
michael@0 | 699 | } |
michael@0 | 700 | |
michael@0 | 701 | // Tests that if an install.rdf claims compatibility then the add-on will be |
michael@0 | 702 | // seen as compatible regardless of what the update.rdf says. |
michael@0 | 703 | function run_test_9() { |
michael@0 | 704 | writeInstallRDFForExtension({ |
michael@0 | 705 | id: "addon4@tests.mozilla.org", |
michael@0 | 706 | version: "5.0", |
michael@0 | 707 | updateURL: "http://localhost:" + gPort + "/data/test_update.rdf", |
michael@0 | 708 | targetApplications: [{ |
michael@0 | 709 | id: "xpcshell@tests.mozilla.org", |
michael@0 | 710 | minVersion: "0", |
michael@0 | 711 | maxVersion: "1" |
michael@0 | 712 | }], |
michael@0 | 713 | name: "Test Addon 1", |
michael@0 | 714 | }, profileDir); |
michael@0 | 715 | |
michael@0 | 716 | restartManager(); |
michael@0 | 717 | |
michael@0 | 718 | AddonManager.getAddonByID("addon4@tests.mozilla.org", function(a4) { |
michael@0 | 719 | do_check_true(a4.isActive); |
michael@0 | 720 | do_check_true(a4.isCompatible); |
michael@0 | 721 | |
michael@0 | 722 | run_test_10(); |
michael@0 | 723 | }); |
michael@0 | 724 | } |
michael@0 | 725 | |
michael@0 | 726 | // Tests that a normal update check won't decrease a targetApplication's |
michael@0 | 727 | // maxVersion. |
michael@0 | 728 | function run_test_10() { |
michael@0 | 729 | AddonManager.getAddonByID("addon4@tests.mozilla.org", function(a4) { |
michael@0 | 730 | a4.findUpdates({ |
michael@0 | 731 | onUpdateFinished: function(addon) { |
michael@0 | 732 | do_check_true(addon.isCompatible); |
michael@0 | 733 | |
michael@0 | 734 | run_test_11(); |
michael@0 | 735 | } |
michael@0 | 736 | }, AddonManager.UPDATE_WHEN_PERIODIC_UPDATE); |
michael@0 | 737 | }); |
michael@0 | 738 | } |
michael@0 | 739 | |
michael@0 | 740 | // Tests that an update check for a new application will decrease a |
michael@0 | 741 | // targetApplication's maxVersion. |
michael@0 | 742 | function run_test_11() { |
michael@0 | 743 | AddonManager.getAddonByID("addon4@tests.mozilla.org", function(a4) { |
michael@0 | 744 | a4.findUpdates({ |
michael@0 | 745 | onUpdateFinished: function(addon) { |
michael@0 | 746 | do_check_false(addon.isCompatible); |
michael@0 | 747 | |
michael@0 | 748 | do_execute_soon(run_test_12); |
michael@0 | 749 | } |
michael@0 | 750 | }, AddonManager.UPDATE_WHEN_NEW_APP_INSTALLED); |
michael@0 | 751 | }); |
michael@0 | 752 | } |
michael@0 | 753 | |
michael@0 | 754 | // Check that the decreased maxVersion applied and disables the add-on |
michael@0 | 755 | function run_test_12() { |
michael@0 | 756 | restartManager(); |
michael@0 | 757 | |
michael@0 | 758 | AddonManager.getAddonByID("addon4@tests.mozilla.org", function(a4) { |
michael@0 | 759 | do_check_false(a4.isActive); |
michael@0 | 760 | do_check_false(a4.isCompatible); |
michael@0 | 761 | |
michael@0 | 762 | a4.uninstall(); |
michael@0 | 763 | do_execute_soon(run_test_13); |
michael@0 | 764 | }); |
michael@0 | 765 | } |
michael@0 | 766 | |
michael@0 | 767 | // Tests that no compatibility update is passed to the listener when there is |
michael@0 | 768 | // compatibility info for the current version of the app but not for the |
michael@0 | 769 | // version of the app that the caller requested an update check for. |
michael@0 | 770 | function run_test_13() { |
michael@0 | 771 | restartManager(); |
michael@0 | 772 | |
michael@0 | 773 | // Not initially compatible but the update check will make it compatible |
michael@0 | 774 | writeInstallRDFForExtension({ |
michael@0 | 775 | id: "addon7@tests.mozilla.org", |
michael@0 | 776 | version: "1.0", |
michael@0 | 777 | updateURL: "http://localhost:" + gPort + "/data/test_update.rdf", |
michael@0 | 778 | targetApplications: [{ |
michael@0 | 779 | id: "xpcshell@tests.mozilla.org", |
michael@0 | 780 | minVersion: "0", |
michael@0 | 781 | maxVersion: "0" |
michael@0 | 782 | }], |
michael@0 | 783 | name: "Test Addon 7", |
michael@0 | 784 | }, profileDir); |
michael@0 | 785 | restartManager(); |
michael@0 | 786 | |
michael@0 | 787 | AddonManager.getAddonByID("addon7@tests.mozilla.org", function(a7) { |
michael@0 | 788 | do_check_neq(a7, null); |
michael@0 | 789 | do_check_false(a7.isActive); |
michael@0 | 790 | do_check_false(a7.isCompatible); |
michael@0 | 791 | do_check_true(a7.appDisabled); |
michael@0 | 792 | do_check_true(a7.isCompatibleWith("0")); |
michael@0 | 793 | |
michael@0 | 794 | a7.findUpdates({ |
michael@0 | 795 | sawUpdate: false, |
michael@0 | 796 | onCompatibilityUpdateAvailable: function(addon) { |
michael@0 | 797 | do_throw("Should have not have seen compatibility information"); |
michael@0 | 798 | }, |
michael@0 | 799 | |
michael@0 | 800 | onUpdateAvailable: function(addon, install) { |
michael@0 | 801 | do_throw("Should not have seen an available update"); |
michael@0 | 802 | }, |
michael@0 | 803 | |
michael@0 | 804 | onUpdateFinished: function(addon) { |
michael@0 | 805 | do_check_true(addon.isCompatible); |
michael@0 | 806 | do_execute_soon(check_test_13); |
michael@0 | 807 | } |
michael@0 | 808 | }, AddonManager.UPDATE_WHEN_NEW_APP_DETECTED, "3.0"); |
michael@0 | 809 | }); |
michael@0 | 810 | } |
michael@0 | 811 | |
michael@0 | 812 | function check_test_13() { |
michael@0 | 813 | restartManager(); |
michael@0 | 814 | AddonManager.getAddonByID("addon7@tests.mozilla.org", function(a7) { |
michael@0 | 815 | do_check_neq(a7, null); |
michael@0 | 816 | do_check_true(a7.isActive); |
michael@0 | 817 | do_check_true(a7.isCompatible); |
michael@0 | 818 | do_check_false(a7.appDisabled); |
michael@0 | 819 | |
michael@0 | 820 | a7.uninstall(); |
michael@0 | 821 | do_execute_soon(run_test_14); |
michael@0 | 822 | }); |
michael@0 | 823 | } |
michael@0 | 824 | |
michael@0 | 825 | // Test that background update checks doesn't update an add-on that isn't |
michael@0 | 826 | // allowed to update automatically. |
michael@0 | 827 | function run_test_14() { |
michael@0 | 828 | restartManager(); |
michael@0 | 829 | |
michael@0 | 830 | // Have an add-on there that will be updated so we see some events from it |
michael@0 | 831 | writeInstallRDFForExtension({ |
michael@0 | 832 | id: "addon1@tests.mozilla.org", |
michael@0 | 833 | version: "1.0", |
michael@0 | 834 | updateURL: "http://localhost:" + gPort + "/data/test_update.rdf", |
michael@0 | 835 | targetApplications: [{ |
michael@0 | 836 | id: "xpcshell@tests.mozilla.org", |
michael@0 | 837 | minVersion: "1", |
michael@0 | 838 | maxVersion: "1" |
michael@0 | 839 | }], |
michael@0 | 840 | name: "Test Addon 1", |
michael@0 | 841 | }, profileDir); |
michael@0 | 842 | |
michael@0 | 843 | writeInstallRDFForExtension({ |
michael@0 | 844 | id: "addon8@tests.mozilla.org", |
michael@0 | 845 | version: "1.0", |
michael@0 | 846 | updateURL: "http://localhost:" + gPort + "/data/test_update.rdf", |
michael@0 | 847 | targetApplications: [{ |
michael@0 | 848 | id: "xpcshell@tests.mozilla.org", |
michael@0 | 849 | minVersion: "1", |
michael@0 | 850 | maxVersion: "1" |
michael@0 | 851 | }], |
michael@0 | 852 | name: "Test Addon 8", |
michael@0 | 853 | }, profileDir); |
michael@0 | 854 | restartManager(); |
michael@0 | 855 | |
michael@0 | 856 | AddonManager.getAddonByID("addon8@tests.mozilla.org", function(a8) { |
michael@0 | 857 | a8.applyBackgroundUpdates = AddonManager.AUTOUPDATE_DISABLE; |
michael@0 | 858 | |
michael@0 | 859 | // The background update check will find updates for both add-ons but only |
michael@0 | 860 | // proceed to install one of them. |
michael@0 | 861 | AddonManager.addInstallListener({ |
michael@0 | 862 | onNewInstall: function(aInstall) { |
michael@0 | 863 | if (aInstall.existingAddon.id != "addon1@tests.mozilla.org" && |
michael@0 | 864 | aInstall.existingAddon.id != "addon8@tests.mozilla.org") |
michael@0 | 865 | do_throw("Saw unexpected onNewInstall for " + aInstall.existingAddon.id); |
michael@0 | 866 | }, |
michael@0 | 867 | |
michael@0 | 868 | onDownloadStarted: function(aInstall) { |
michael@0 | 869 | do_check_eq(aInstall.existingAddon.id, "addon1@tests.mozilla.org"); |
michael@0 | 870 | }, |
michael@0 | 871 | |
michael@0 | 872 | onDownloadEnded: function(aInstall) { |
michael@0 | 873 | do_check_eq(aInstall.existingAddon.id, "addon1@tests.mozilla.org"); |
michael@0 | 874 | }, |
michael@0 | 875 | |
michael@0 | 876 | onDownloadFailed: function(aInstall) { |
michael@0 | 877 | do_throw("Should not have seen onDownloadFailed event"); |
michael@0 | 878 | }, |
michael@0 | 879 | |
michael@0 | 880 | onDownloadCancelled: function(aInstall) { |
michael@0 | 881 | do_throw("Should not have seen onDownloadCancelled event"); |
michael@0 | 882 | }, |
michael@0 | 883 | |
michael@0 | 884 | onInstallStarted: function(aInstall) { |
michael@0 | 885 | do_check_eq(aInstall.existingAddon.id, "addon1@tests.mozilla.org"); |
michael@0 | 886 | }, |
michael@0 | 887 | |
michael@0 | 888 | onInstallEnded: function(aInstall) { |
michael@0 | 889 | do_check_eq(aInstall.existingAddon.id, "addon1@tests.mozilla.org"); |
michael@0 | 890 | do_check_eq(aInstall.existingAddon.pendingUpgrade.install, aInstall); |
michael@0 | 891 | do_execute_soon(check_test_14); |
michael@0 | 892 | }, |
michael@0 | 893 | |
michael@0 | 894 | onInstallFailed: function(aInstall) { |
michael@0 | 895 | do_throw("Should not have seen onInstallFailed event"); |
michael@0 | 896 | }, |
michael@0 | 897 | |
michael@0 | 898 | onInstallCancelled: function(aInstall) { |
michael@0 | 899 | do_throw("Should not have seen onInstallCancelled event"); |
michael@0 | 900 | }, |
michael@0 | 901 | }); |
michael@0 | 902 | |
michael@0 | 903 | // Fake a timer event |
michael@0 | 904 | gInternalManager.notify(null); |
michael@0 | 905 | }); |
michael@0 | 906 | } |
michael@0 | 907 | |
michael@0 | 908 | function check_test_14() { |
michael@0 | 909 | restartManager(); |
michael@0 | 910 | AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org", |
michael@0 | 911 | "addon8@tests.mozilla.org"], function([a1, a8]) { |
michael@0 | 912 | do_check_neq(a1, null); |
michael@0 | 913 | do_check_eq(a1.version, "2.0"); |
michael@0 | 914 | a1.uninstall(); |
michael@0 | 915 | |
michael@0 | 916 | do_check_neq(a8, null); |
michael@0 | 917 | do_check_eq(a8.version, "1.0"); |
michael@0 | 918 | a8.uninstall(); |
michael@0 | 919 | |
michael@0 | 920 | do_execute_soon(run_test_15); |
michael@0 | 921 | }); |
michael@0 | 922 | } |
michael@0 | 923 | |
michael@0 | 924 | // Test that background update checks doesn't update an add-on that is |
michael@0 | 925 | // pending uninstall |
michael@0 | 926 | function run_test_15() { |
michael@0 | 927 | restartManager(); |
michael@0 | 928 | |
michael@0 | 929 | // Have an add-on there that will be updated so we see some events from it |
michael@0 | 930 | writeInstallRDFForExtension({ |
michael@0 | 931 | id: "addon1@tests.mozilla.org", |
michael@0 | 932 | version: "1.0", |
michael@0 | 933 | updateURL: "http://localhost:" + gPort + "/data/test_update.rdf", |
michael@0 | 934 | targetApplications: [{ |
michael@0 | 935 | id: "xpcshell@tests.mozilla.org", |
michael@0 | 936 | minVersion: "1", |
michael@0 | 937 | maxVersion: "1" |
michael@0 | 938 | }], |
michael@0 | 939 | name: "Test Addon 1", |
michael@0 | 940 | }, profileDir); |
michael@0 | 941 | |
michael@0 | 942 | writeInstallRDFForExtension({ |
michael@0 | 943 | id: "addon8@tests.mozilla.org", |
michael@0 | 944 | version: "1.0", |
michael@0 | 945 | updateURL: "http://localhost:" + gPort + "/data/test_update.rdf", |
michael@0 | 946 | targetApplications: [{ |
michael@0 | 947 | id: "xpcshell@tests.mozilla.org", |
michael@0 | 948 | minVersion: "1", |
michael@0 | 949 | maxVersion: "1" |
michael@0 | 950 | }], |
michael@0 | 951 | name: "Test Addon 8", |
michael@0 | 952 | }, profileDir); |
michael@0 | 953 | restartManager(); |
michael@0 | 954 | |
michael@0 | 955 | AddonManager.getAddonByID("addon8@tests.mozilla.org", function(a8) { |
michael@0 | 956 | a8.uninstall(); |
michael@0 | 957 | do_check_false(hasFlag(a8.permissions, AddonManager.PERM_CAN_UPGRADE)); |
michael@0 | 958 | |
michael@0 | 959 | // The background update check will find updates for both add-ons but only |
michael@0 | 960 | // proceed to install one of them. |
michael@0 | 961 | AddonManager.addInstallListener({ |
michael@0 | 962 | onNewInstall: function(aInstall) { |
michael@0 | 963 | if (aInstall.existingAddon.id != "addon1@tests.mozilla.org" && |
michael@0 | 964 | aInstall.existingAddon.id != "addon8@tests.mozilla.org") |
michael@0 | 965 | do_throw("Saw unexpected onNewInstall for " + aInstall.existingAddon.id); |
michael@0 | 966 | }, |
michael@0 | 967 | |
michael@0 | 968 | onDownloadStarted: function(aInstall) { |
michael@0 | 969 | do_check_eq(aInstall.existingAddon.id, "addon1@tests.mozilla.org"); |
michael@0 | 970 | }, |
michael@0 | 971 | |
michael@0 | 972 | onDownloadEnded: function(aInstall) { |
michael@0 | 973 | do_check_eq(aInstall.existingAddon.id, "addon1@tests.mozilla.org"); |
michael@0 | 974 | }, |
michael@0 | 975 | |
michael@0 | 976 | onDownloadFailed: function(aInstall) { |
michael@0 | 977 | do_throw("Should not have seen onDownloadFailed event"); |
michael@0 | 978 | }, |
michael@0 | 979 | |
michael@0 | 980 | onDownloadCancelled: function(aInstall) { |
michael@0 | 981 | do_throw("Should not have seen onDownloadCancelled event"); |
michael@0 | 982 | }, |
michael@0 | 983 | |
michael@0 | 984 | onInstallStarted: function(aInstall) { |
michael@0 | 985 | do_check_eq(aInstall.existingAddon.id, "addon1@tests.mozilla.org"); |
michael@0 | 986 | }, |
michael@0 | 987 | |
michael@0 | 988 | onInstallEnded: function(aInstall) { |
michael@0 | 989 | do_check_eq(aInstall.existingAddon.id, "addon1@tests.mozilla.org"); |
michael@0 | 990 | do_execute_soon(check_test_15); |
michael@0 | 991 | }, |
michael@0 | 992 | |
michael@0 | 993 | onInstallFailed: function(aInstall) { |
michael@0 | 994 | do_throw("Should not have seen onInstallFailed event"); |
michael@0 | 995 | }, |
michael@0 | 996 | |
michael@0 | 997 | onInstallCancelled: function(aInstall) { |
michael@0 | 998 | do_throw("Should not have seen onInstallCancelled event"); |
michael@0 | 999 | }, |
michael@0 | 1000 | }); |
michael@0 | 1001 | |
michael@0 | 1002 | // Fake a timer event |
michael@0 | 1003 | gInternalManager.notify(null); |
michael@0 | 1004 | }); |
michael@0 | 1005 | } |
michael@0 | 1006 | |
michael@0 | 1007 | function check_test_15() { |
michael@0 | 1008 | restartManager(); |
michael@0 | 1009 | AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org", |
michael@0 | 1010 | "addon8@tests.mozilla.org"], function([a1, a8]) { |
michael@0 | 1011 | do_check_neq(a1, null); |
michael@0 | 1012 | do_check_eq(a1.version, "2.0"); |
michael@0 | 1013 | a1.uninstall(); |
michael@0 | 1014 | |
michael@0 | 1015 | do_check_eq(a8, null); |
michael@0 | 1016 | |
michael@0 | 1017 | do_execute_soon(run_test_16); |
michael@0 | 1018 | }); |
michael@0 | 1019 | } |
michael@0 | 1020 | |
michael@0 | 1021 | // Test that the update check correctly observes the |
michael@0 | 1022 | // extensions.strictCompatibility pref and compatibility overrides. |
michael@0 | 1023 | function run_test_16() { |
michael@0 | 1024 | restartManager(); |
michael@0 | 1025 | |
michael@0 | 1026 | writeInstallRDFForExtension({ |
michael@0 | 1027 | id: "addon9@tests.mozilla.org", |
michael@0 | 1028 | version: "1.0", |
michael@0 | 1029 | updateURL: "http://localhost:" + gPort + "/data/test_update.rdf", |
michael@0 | 1030 | targetApplications: [{ |
michael@0 | 1031 | id: "xpcshell@tests.mozilla.org", |
michael@0 | 1032 | minVersion: "0.1", |
michael@0 | 1033 | maxVersion: "0.2" |
michael@0 | 1034 | }], |
michael@0 | 1035 | name: "Test Addon 9", |
michael@0 | 1036 | }, profileDir); |
michael@0 | 1037 | restartManager(); |
michael@0 | 1038 | |
michael@0 | 1039 | AddonManager.addInstallListener({ |
michael@0 | 1040 | onNewInstall: function(aInstall) { |
michael@0 | 1041 | if (aInstall.existingAddon.id != "addon9@tests.mozilla.org") |
michael@0 | 1042 | do_throw("Saw unexpected onNewInstall for " + aInstall.existingAddon.id); |
michael@0 | 1043 | do_check_eq(aInstall.version, "2.0"); |
michael@0 | 1044 | }, |
michael@0 | 1045 | onDownloadFailed: function(aInstall) { |
michael@0 | 1046 | do_execute_soon(run_test_17); |
michael@0 | 1047 | } |
michael@0 | 1048 | }); |
michael@0 | 1049 | |
michael@0 | 1050 | Services.prefs.setCharPref(PREF_GETADDONS_BYIDS_PERFORMANCE, |
michael@0 | 1051 | "http://localhost:" + gPort + "/data/test_update.xml"); |
michael@0 | 1052 | Services.prefs.setBoolPref(PREF_GETADDONS_CACHE_ENABLED, true); |
michael@0 | 1053 | // Fake a timer event |
michael@0 | 1054 | gInternalManager.notify(null); |
michael@0 | 1055 | } |
michael@0 | 1056 | |
michael@0 | 1057 | // Test that the update check correctly observes when an addon opts-in to |
michael@0 | 1058 | // strict compatibility checking. |
michael@0 | 1059 | function run_test_17() { |
michael@0 | 1060 | |
michael@0 | 1061 | writeInstallRDFForExtension({ |
michael@0 | 1062 | id: "addon11@tests.mozilla.org", |
michael@0 | 1063 | version: "1.0", |
michael@0 | 1064 | updateURL: "http://localhost:" + gPort + "/data/test_update.rdf", |
michael@0 | 1065 | targetApplications: [{ |
michael@0 | 1066 | id: "xpcshell@tests.mozilla.org", |
michael@0 | 1067 | minVersion: "0.1", |
michael@0 | 1068 | maxVersion: "0.2" |
michael@0 | 1069 | }], |
michael@0 | 1070 | name: "Test Addon 11", |
michael@0 | 1071 | }, profileDir); |
michael@0 | 1072 | restartManager(); |
michael@0 | 1073 | |
michael@0 | 1074 | AddonManager.getAddonByID("addon11@tests.mozilla.org", function(a11) { |
michael@0 | 1075 | do_check_neq(a11, null); |
michael@0 | 1076 | |
michael@0 | 1077 | a11.findUpdates({ |
michael@0 | 1078 | onCompatibilityUpdateAvailable: function() { |
michael@0 | 1079 | do_throw("Should have not have seen compatibility information"); |
michael@0 | 1080 | }, |
michael@0 | 1081 | |
michael@0 | 1082 | onUpdateAvailable: function() { |
michael@0 | 1083 | do_throw("Should not have seen an available update"); |
michael@0 | 1084 | }, |
michael@0 | 1085 | |
michael@0 | 1086 | onUpdateFinished: function() { |
michael@0 | 1087 | do_execute_soon(end_test); |
michael@0 | 1088 | } |
michael@0 | 1089 | }, AddonManager.UPDATE_WHEN_USER_REQUESTED); |
michael@0 | 1090 | }); |
michael@0 | 1091 | } |