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 updating an add-on to a new ID works |
michael@0 | 6 | |
michael@0 | 7 | // The test extension uses an insecure update url. |
michael@0 | 8 | Services.prefs.setBoolPref("extensions.checkUpdateSecurity", false); |
michael@0 | 9 | |
michael@0 | 10 | Components.utils.import("resource://testing-common/httpd.js"); |
michael@0 | 11 | var testserver; |
michael@0 | 12 | const profileDir = gProfD.clone(); |
michael@0 | 13 | profileDir.append("extensions"); |
michael@0 | 14 | |
michael@0 | 15 | function resetPrefs() { |
michael@0 | 16 | Services.prefs.setIntPref("bootstraptest.active_version", -1); |
michael@0 | 17 | Services.prefs.setIntPref("bootstraptest.installed_version", -1); |
michael@0 | 18 | Services.prefs.setIntPref("bootstraptest.startup_reason", -1); |
michael@0 | 19 | Services.prefs.setIntPref("bootstraptest.shutdown_reason", -1); |
michael@0 | 20 | Services.prefs.setIntPref("bootstraptest.install_reason", -1); |
michael@0 | 21 | Services.prefs.setIntPref("bootstraptest.uninstall_reason", -1); |
michael@0 | 22 | } |
michael@0 | 23 | |
michael@0 | 24 | function getActiveVersion() { |
michael@0 | 25 | return Services.prefs.getIntPref("bootstraptest.active_version"); |
michael@0 | 26 | } |
michael@0 | 27 | |
michael@0 | 28 | function getInstalledVersion() { |
michael@0 | 29 | return Services.prefs.getIntPref("bootstraptest.installed_version"); |
michael@0 | 30 | } |
michael@0 | 31 | |
michael@0 | 32 | function run_test() { |
michael@0 | 33 | createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2"); |
michael@0 | 34 | |
michael@0 | 35 | // Create and configure the HTTP server. |
michael@0 | 36 | testserver = new HttpServer(); |
michael@0 | 37 | testserver.registerDirectory("/data/", do_get_file("data")); |
michael@0 | 38 | testserver.registerDirectory("/addons/", do_get_file("addons")); |
michael@0 | 39 | testserver.start(4444); |
michael@0 | 40 | |
michael@0 | 41 | do_test_pending(); |
michael@0 | 42 | run_test_1(); |
michael@0 | 43 | } |
michael@0 | 44 | |
michael@0 | 45 | function end_test() { |
michael@0 | 46 | testserver.stop(do_test_finished); |
michael@0 | 47 | } |
michael@0 | 48 | |
michael@0 | 49 | function installUpdate(aInstall, aCallback) { |
michael@0 | 50 | aInstall.addListener({ |
michael@0 | 51 | onInstallEnded: function(aInstall) { |
michael@0 | 52 | // give the startup time to run |
michael@0 | 53 | do_execute_soon(function() { |
michael@0 | 54 | aCallback(aInstall); |
michael@0 | 55 | }); |
michael@0 | 56 | } |
michael@0 | 57 | }); |
michael@0 | 58 | |
michael@0 | 59 | aInstall.install(); |
michael@0 | 60 | } |
michael@0 | 61 | |
michael@0 | 62 | // Verify that an update to an add-on with a new ID uninstalls the old add-on |
michael@0 | 63 | function run_test_1() { |
michael@0 | 64 | writeInstallRDFForExtension({ |
michael@0 | 65 | id: "addon1@tests.mozilla.org", |
michael@0 | 66 | version: "1.0", |
michael@0 | 67 | updateURL: "http://localhost:4444/data/test_updateid.rdf", |
michael@0 | 68 | targetApplications: [{ |
michael@0 | 69 | id: "xpcshell@tests.mozilla.org", |
michael@0 | 70 | minVersion: "1", |
michael@0 | 71 | maxVersion: "1" |
michael@0 | 72 | }], |
michael@0 | 73 | name: "Test Addon 1", |
michael@0 | 74 | }, profileDir); |
michael@0 | 75 | |
michael@0 | 76 | startupManager(); |
michael@0 | 77 | |
michael@0 | 78 | AddonManager.getAddonByID("addon1@tests.mozilla.org", function(a1) { |
michael@0 | 79 | do_check_neq(a1, null); |
michael@0 | 80 | do_check_eq(a1.version, "1.0"); |
michael@0 | 81 | |
michael@0 | 82 | a1.findUpdates({ |
michael@0 | 83 | onUpdateAvailable: function(addon, install) { |
michael@0 | 84 | do_check_eq(install.name, addon.name); |
michael@0 | 85 | do_check_eq(install.version, "2.0"); |
michael@0 | 86 | do_check_eq(install.state, AddonManager.STATE_AVAILABLE); |
michael@0 | 87 | do_check_eq(install.existingAddon, a1); |
michael@0 | 88 | |
michael@0 | 89 | installUpdate(install, check_test_1); |
michael@0 | 90 | } |
michael@0 | 91 | }, AddonManager.UPDATE_WHEN_USER_REQUESTED); |
michael@0 | 92 | }); |
michael@0 | 93 | } |
michael@0 | 94 | |
michael@0 | 95 | function check_test_1(install) { |
michael@0 | 96 | AddonManager.getAddonByID("addon1@tests.mozilla.org", callback_soon(function(a1) { |
michael@0 | 97 | // Existing add-on should have a pending upgrade |
michael@0 | 98 | do_check_neq(a1.pendingUpgrade, null); |
michael@0 | 99 | do_check_eq(a1.pendingUpgrade.id, "addon2@tests.mozilla.org"); |
michael@0 | 100 | do_check_eq(a1.pendingUpgrade.install.existingAddon, a1); |
michael@0 | 101 | do_check_neq(a1.syncGUID); |
michael@0 | 102 | |
michael@0 | 103 | let a1SyncGUID = a1.syncGUID; |
michael@0 | 104 | |
michael@0 | 105 | restartManager(); |
michael@0 | 106 | |
michael@0 | 107 | AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org", |
michael@0 | 108 | "addon2@tests.mozilla.org"], function([a1, a2]) { |
michael@0 | 109 | // Should have uninstalled the old and installed the new |
michael@0 | 110 | do_check_eq(a1, null); |
michael@0 | 111 | do_check_neq(a2, null); |
michael@0 | 112 | do_check_neq(a2.syncGUID, null); |
michael@0 | 113 | |
michael@0 | 114 | // The Sync GUID should change when the ID changes |
michael@0 | 115 | do_check_neq(a1SyncGUID, a2.syncGUID); |
michael@0 | 116 | |
michael@0 | 117 | a2.uninstall(); |
michael@0 | 118 | |
michael@0 | 119 | do_execute_soon(run_test_2); |
michael@0 | 120 | }); |
michael@0 | 121 | })); |
michael@0 | 122 | } |
michael@0 | 123 | |
michael@0 | 124 | // Test that when the new add-on already exists we just upgrade that |
michael@0 | 125 | function run_test_2() { |
michael@0 | 126 | restartManager(); |
michael@0 | 127 | shutdownManager(); |
michael@0 | 128 | |
michael@0 | 129 | writeInstallRDFForExtension({ |
michael@0 | 130 | id: "addon1@tests.mozilla.org", |
michael@0 | 131 | version: "1.0", |
michael@0 | 132 | updateURL: "http://localhost:4444/data/test_updateid.rdf", |
michael@0 | 133 | targetApplications: [{ |
michael@0 | 134 | id: "xpcshell@tests.mozilla.org", |
michael@0 | 135 | minVersion: "1", |
michael@0 | 136 | maxVersion: "1" |
michael@0 | 137 | }], |
michael@0 | 138 | name: "Test Addon 1", |
michael@0 | 139 | }, profileDir); |
michael@0 | 140 | writeInstallRDFForExtension({ |
michael@0 | 141 | id: "addon2@tests.mozilla.org", |
michael@0 | 142 | version: "1.0", |
michael@0 | 143 | targetApplications: [{ |
michael@0 | 144 | id: "xpcshell@tests.mozilla.org", |
michael@0 | 145 | minVersion: "1", |
michael@0 | 146 | maxVersion: "1" |
michael@0 | 147 | }], |
michael@0 | 148 | name: "Test Addon 2", |
michael@0 | 149 | }, profileDir); |
michael@0 | 150 | |
michael@0 | 151 | startupManager(); |
michael@0 | 152 | |
michael@0 | 153 | AddonManager.getAddonByID("addon1@tests.mozilla.org", function(a1) { |
michael@0 | 154 | do_check_neq(a1, null); |
michael@0 | 155 | do_check_eq(a1.version, "1.0"); |
michael@0 | 156 | |
michael@0 | 157 | a1.findUpdates({ |
michael@0 | 158 | onUpdateAvailable: function(addon, install) { |
michael@0 | 159 | installUpdate(install, check_test_2); |
michael@0 | 160 | } |
michael@0 | 161 | }, AddonManager.UPDATE_WHEN_USER_REQUESTED); |
michael@0 | 162 | }); |
michael@0 | 163 | } |
michael@0 | 164 | |
michael@0 | 165 | function check_test_2(install) { |
michael@0 | 166 | AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org", |
michael@0 | 167 | "addon2@tests.mozilla.org"], |
michael@0 | 168 | callback_soon(function([a1, a2]) { |
michael@0 | 169 | do_check_eq(a1.pendingUpgrade, null); |
michael@0 | 170 | // Existing add-on should have a pending upgrade |
michael@0 | 171 | do_check_neq(a2.pendingUpgrade, null); |
michael@0 | 172 | do_check_eq(a2.pendingUpgrade.id, "addon2@tests.mozilla.org"); |
michael@0 | 173 | do_check_eq(a2.pendingUpgrade.install.existingAddon, a2); |
michael@0 | 174 | |
michael@0 | 175 | restartManager(); |
michael@0 | 176 | |
michael@0 | 177 | AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org", |
michael@0 | 178 | "addon2@tests.mozilla.org"], function([a1, a2]) { |
michael@0 | 179 | // Should have uninstalled the old and installed the new |
michael@0 | 180 | do_check_neq(a1, null); |
michael@0 | 181 | do_check_neq(a2, null); |
michael@0 | 182 | |
michael@0 | 183 | a1.uninstall(); |
michael@0 | 184 | a2.uninstall(); |
michael@0 | 185 | |
michael@0 | 186 | do_execute_soon(run_test_3); |
michael@0 | 187 | }); |
michael@0 | 188 | })); |
michael@0 | 189 | } |
michael@0 | 190 | |
michael@0 | 191 | // Test that we rollback correctly when removing the old add-on fails |
michael@0 | 192 | function run_test_3() { |
michael@0 | 193 | restartManager(); |
michael@0 | 194 | shutdownManager(); |
michael@0 | 195 | |
michael@0 | 196 | // This test only works on Windows |
michael@0 | 197 | if (!("nsIWindowsRegKey" in AM_Ci)) { |
michael@0 | 198 | run_test_4(); |
michael@0 | 199 | return; |
michael@0 | 200 | } |
michael@0 | 201 | |
michael@0 | 202 | writeInstallRDFForExtension({ |
michael@0 | 203 | id: "addon1@tests.mozilla.org", |
michael@0 | 204 | version: "1.0", |
michael@0 | 205 | updateURL: "http://localhost:4444/data/test_updateid.rdf", |
michael@0 | 206 | targetApplications: [{ |
michael@0 | 207 | id: "xpcshell@tests.mozilla.org", |
michael@0 | 208 | minVersion: "1", |
michael@0 | 209 | maxVersion: "1" |
michael@0 | 210 | }], |
michael@0 | 211 | name: "Test Addon 1", |
michael@0 | 212 | }, profileDir); |
michael@0 | 213 | |
michael@0 | 214 | startupManager(); |
michael@0 | 215 | |
michael@0 | 216 | AddonManager.getAddonByID("addon1@tests.mozilla.org", function(a1) { |
michael@0 | 217 | do_check_neq(a1, null); |
michael@0 | 218 | do_check_eq(a1.version, "1.0"); |
michael@0 | 219 | |
michael@0 | 220 | a1.findUpdates({ |
michael@0 | 221 | onUpdateAvailable: function(addon, install) { |
michael@0 | 222 | installUpdate(install, check_test_3); |
michael@0 | 223 | } |
michael@0 | 224 | }, AddonManager.UPDATE_WHEN_USER_REQUESTED); |
michael@0 | 225 | }); |
michael@0 | 226 | } |
michael@0 | 227 | |
michael@0 | 228 | function check_test_3(install) { |
michael@0 | 229 | AddonManager.getAddonByID("addon1@tests.mozilla.org", callback_soon(function(a1) { |
michael@0 | 230 | // Existing add-on should have a pending upgrade |
michael@0 | 231 | do_check_neq(a1.pendingUpgrade, null); |
michael@0 | 232 | do_check_eq(a1.pendingUpgrade.id, "addon2@tests.mozilla.org"); |
michael@0 | 233 | do_check_eq(a1.pendingUpgrade.install.existingAddon, a1); |
michael@0 | 234 | |
michael@0 | 235 | // Lock the old add-on open so it can't be uninstalled |
michael@0 | 236 | var file = profileDir.clone(); |
michael@0 | 237 | file.append("addon1@tests.mozilla.org"); |
michael@0 | 238 | if (!file.exists()) |
michael@0 | 239 | file.leafName += ".xpi"; |
michael@0 | 240 | else |
michael@0 | 241 | file.append("install.rdf"); |
michael@0 | 242 | |
michael@0 | 243 | var fstream = AM_Cc["@mozilla.org/network/file-output-stream;1"]. |
michael@0 | 244 | createInstance(AM_Ci.nsIFileOutputStream); |
michael@0 | 245 | fstream.init(file, FileUtils.MODE_APPEND | FileUtils.MODE_WRONLY, FileUtils.PERMS_FILE, 0); |
michael@0 | 246 | |
michael@0 | 247 | restartManager(); |
michael@0 | 248 | |
michael@0 | 249 | fstream.close(); |
michael@0 | 250 | |
michael@0 | 251 | AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org", |
michael@0 | 252 | "addon2@tests.mozilla.org"], |
michael@0 | 253 | callback_soon(function([a1, a2]) { |
michael@0 | 254 | // Should not have installed the new add-on but it should still be |
michael@0 | 255 | // pending install |
michael@0 | 256 | do_check_neq(a1, null); |
michael@0 | 257 | do_check_eq(a2, null); |
michael@0 | 258 | |
michael@0 | 259 | restartManager(); |
michael@0 | 260 | |
michael@0 | 261 | AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org", |
michael@0 | 262 | "addon2@tests.mozilla.org"], function([a1, a2]) { |
michael@0 | 263 | // Should have installed the new add-on |
michael@0 | 264 | do_check_eq(a1, null); |
michael@0 | 265 | do_check_neq(a2, null); |
michael@0 | 266 | |
michael@0 | 267 | a2.uninstall(); |
michael@0 | 268 | |
michael@0 | 269 | do_execute_soon(run_test_4); |
michael@0 | 270 | }); |
michael@0 | 271 | })); |
michael@0 | 272 | })); |
michael@0 | 273 | } |
michael@0 | 274 | |
michael@0 | 275 | // Tests that upgrading to a bootstrapped add-on works but requires a restart |
michael@0 | 276 | function run_test_4() { |
michael@0 | 277 | restartManager(); |
michael@0 | 278 | shutdownManager(); |
michael@0 | 279 | |
michael@0 | 280 | writeInstallRDFForExtension({ |
michael@0 | 281 | id: "addon2@tests.mozilla.org", |
michael@0 | 282 | version: "2.0", |
michael@0 | 283 | updateURL: "http://localhost:4444/data/test_updateid.rdf", |
michael@0 | 284 | targetApplications: [{ |
michael@0 | 285 | id: "xpcshell@tests.mozilla.org", |
michael@0 | 286 | minVersion: "1", |
michael@0 | 287 | maxVersion: "1" |
michael@0 | 288 | }], |
michael@0 | 289 | name: "Test Addon 2", |
michael@0 | 290 | }, profileDir); |
michael@0 | 291 | |
michael@0 | 292 | startupManager(); |
michael@0 | 293 | |
michael@0 | 294 | resetPrefs(); |
michael@0 | 295 | |
michael@0 | 296 | AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) { |
michael@0 | 297 | do_check_neq(a2, null); |
michael@0 | 298 | do_check_neq(a2.syncGUID, null); |
michael@0 | 299 | do_check_eq(a2.version, "2.0"); |
michael@0 | 300 | |
michael@0 | 301 | a2.findUpdates({ |
michael@0 | 302 | onUpdateAvailable: function(addon, install) { |
michael@0 | 303 | installUpdate(install, check_test_4); |
michael@0 | 304 | } |
michael@0 | 305 | }, AddonManager.UPDATE_WHEN_USER_REQUESTED); |
michael@0 | 306 | }); |
michael@0 | 307 | } |
michael@0 | 308 | |
michael@0 | 309 | function check_test_4() { |
michael@0 | 310 | AddonManager.getAddonsByIDs(["addon2@tests.mozilla.org", |
michael@0 | 311 | "addon3@tests.mozilla.org"], |
michael@0 | 312 | callback_soon(function([a2, a3]) { |
michael@0 | 313 | // Should still be pending install even though the new add-on is restartless |
michael@0 | 314 | do_check_neq(a2, null); |
michael@0 | 315 | do_check_eq(a3, null); |
michael@0 | 316 | |
michael@0 | 317 | do_check_neq(a2.pendingUpgrade, null); |
michael@0 | 318 | do_check_eq(a2.pendingUpgrade.id, "addon3@tests.mozilla.org"); |
michael@0 | 319 | |
michael@0 | 320 | do_check_eq(getInstalledVersion(), -1); |
michael@0 | 321 | do_check_eq(getActiveVersion(), -1); |
michael@0 | 322 | |
michael@0 | 323 | restartManager(); |
michael@0 | 324 | |
michael@0 | 325 | AddonManager.getAddonsByIDs(["addon2@tests.mozilla.org", |
michael@0 | 326 | "addon3@tests.mozilla.org"], function([a2, a3]) { |
michael@0 | 327 | // Should have updated |
michael@0 | 328 | do_check_eq(a2, null); |
michael@0 | 329 | do_check_neq(a3, null); |
michael@0 | 330 | |
michael@0 | 331 | do_check_eq(getInstalledVersion(), 3); |
michael@0 | 332 | do_check_eq(getActiveVersion(), 3); |
michael@0 | 333 | |
michael@0 | 334 | do_execute_soon(run_test_5); |
michael@0 | 335 | }); |
michael@0 | 336 | })); |
michael@0 | 337 | } |
michael@0 | 338 | |
michael@0 | 339 | // Tests that upgrading to another bootstrapped add-on works without a restart |
michael@0 | 340 | function run_test_5() { |
michael@0 | 341 | AddonManager.getAddonByID("addon3@tests.mozilla.org", function(a3) { |
michael@0 | 342 | do_check_neq(a3, null); |
michael@0 | 343 | do_check_eq(a3.version, "3.0"); |
michael@0 | 344 | |
michael@0 | 345 | a3.findUpdates({ |
michael@0 | 346 | onUpdateAvailable: function(addon, install) { |
michael@0 | 347 | installUpdate(install, check_test_5); |
michael@0 | 348 | } |
michael@0 | 349 | }, AddonManager.UPDATE_WHEN_USER_REQUESTED); |
michael@0 | 350 | }); |
michael@0 | 351 | } |
michael@0 | 352 | |
michael@0 | 353 | function check_test_5() { |
michael@0 | 354 | AddonManager.getAddonsByIDs(["addon3@tests.mozilla.org", |
michael@0 | 355 | "addon4@tests.mozilla.org"], |
michael@0 | 356 | callback_soon(function([a3, a4]) { |
michael@0 | 357 | // Should have updated |
michael@0 | 358 | do_check_eq(a3, null); |
michael@0 | 359 | do_check_neq(a4, null); |
michael@0 | 360 | |
michael@0 | 361 | do_check_eq(getInstalledVersion(), 4); |
michael@0 | 362 | do_check_eq(getActiveVersion(), 4); |
michael@0 | 363 | |
michael@0 | 364 | restartManager(); |
michael@0 | 365 | |
michael@0 | 366 | AddonManager.getAddonsByIDs(["addon3@tests.mozilla.org", |
michael@0 | 367 | "addon4@tests.mozilla.org"], function([a3, a4]) { |
michael@0 | 368 | // Should still be gone |
michael@0 | 369 | do_check_eq(a3, null); |
michael@0 | 370 | do_check_neq(a4, null); |
michael@0 | 371 | |
michael@0 | 372 | do_check_eq(getInstalledVersion(), 4); |
michael@0 | 373 | do_check_eq(getActiveVersion(), 4); |
michael@0 | 374 | |
michael@0 | 375 | run_test_6(); |
michael@0 | 376 | }); |
michael@0 | 377 | })); |
michael@0 | 378 | } |
michael@0 | 379 | |
michael@0 | 380 | // Tests that upgrading to a non-bootstrapped add-on works but requires a restart |
michael@0 | 381 | function run_test_6() { |
michael@0 | 382 | AddonManager.getAddonByID("addon4@tests.mozilla.org", function(a4) { |
michael@0 | 383 | do_check_neq(a4, null); |
michael@0 | 384 | do_check_eq(a4.version, "4.0"); |
michael@0 | 385 | |
michael@0 | 386 | a4.findUpdates({ |
michael@0 | 387 | onUpdateAvailable: function(addon, install) { |
michael@0 | 388 | installUpdate(install, check_test_6); |
michael@0 | 389 | } |
michael@0 | 390 | }, AddonManager.UPDATE_WHEN_USER_REQUESTED); |
michael@0 | 391 | }); |
michael@0 | 392 | } |
michael@0 | 393 | |
michael@0 | 394 | function check_test_6() { |
michael@0 | 395 | AddonManager.getAddonsByIDs(["addon4@tests.mozilla.org", |
michael@0 | 396 | "addon2@tests.mozilla.org"], |
michael@0 | 397 | callback_soon(function([a4, a2]) { |
michael@0 | 398 | // Should still be pending install even though the old add-on is restartless |
michael@0 | 399 | do_check_neq(a4, null); |
michael@0 | 400 | do_check_eq(a2, null); |
michael@0 | 401 | |
michael@0 | 402 | do_check_neq(a4.pendingUpgrade, null); |
michael@0 | 403 | do_check_eq(a4.pendingUpgrade.id, "addon2@tests.mozilla.org"); |
michael@0 | 404 | |
michael@0 | 405 | do_check_eq(getInstalledVersion(), 4); |
michael@0 | 406 | do_check_eq(getActiveVersion(), 4); |
michael@0 | 407 | |
michael@0 | 408 | restartManager(); |
michael@0 | 409 | |
michael@0 | 410 | AddonManager.getAddonsByIDs(["addon4@tests.mozilla.org", |
michael@0 | 411 | "addon2@tests.mozilla.org"], function([a4, a2]) { |
michael@0 | 412 | // Should have updated |
michael@0 | 413 | do_check_eq(a4, null); |
michael@0 | 414 | do_check_neq(a2, null); |
michael@0 | 415 | |
michael@0 | 416 | do_check_eq(getInstalledVersion(), 0); |
michael@0 | 417 | do_check_eq(getActiveVersion(), 0); |
michael@0 | 418 | |
michael@0 | 419 | end_test(); |
michael@0 | 420 | }); |
michael@0 | 421 | })); |
michael@0 | 422 | } |