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