toolkit/mozapps/extensions/test/xpcshell/test_install.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

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-ons can be installed from XPI files
michael@0 6 const Cc = Components.classes;
michael@0 7 const Ci = Components.interfaces;
michael@0 8 const Cu = Components.utils;
michael@0 9
michael@0 10 // Maximum error in file modification times. Some file systems don't store
michael@0 11 // modification times exactly. As long as we are closer than this then it
michael@0 12 // still passes.
michael@0 13 const MAX_TIME_DIFFERENCE = 3000;
michael@0 14
michael@0 15 // install.rdf size, icon.png, icon64.png size
michael@0 16 const ADDON1_SIZE = 705 + 16 + 16;
michael@0 17
michael@0 18 Cu.import("resource://gre/modules/Services.jsm");
michael@0 19 Cu.import("resource://gre/modules/NetUtil.jsm");
michael@0 20 Cu.import("resource://testing-common/httpd.js");
michael@0 21
michael@0 22 var testserver;
michael@0 23 var gInstallDate;
michael@0 24 var gInstall = null;
michael@0 25
michael@0 26 // The test extension uses an insecure update url.
michael@0 27 Services.prefs.setBoolPref(PREF_EM_CHECK_UPDATE_SECURITY, false);
michael@0 28 Services.prefs.setBoolPref(PREF_EM_STRICT_COMPATIBILITY, false);
michael@0 29
michael@0 30 const profileDir = gProfD.clone();
michael@0 31 profileDir.append("extensions");
michael@0 32
michael@0 33 function run_test() {
michael@0 34 createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
michael@0 35
michael@0 36 startupManager();
michael@0 37 // Make sure we only register once despite multiple calls
michael@0 38 AddonManager.addInstallListener(InstallListener);
michael@0 39 AddonManager.addAddonListener(AddonListener);
michael@0 40 AddonManager.addInstallListener(InstallListener);
michael@0 41 AddonManager.addAddonListener(AddonListener);
michael@0 42
michael@0 43 // Create and configure the HTTP server.
michael@0 44 testserver = new HttpServer();
michael@0 45 testserver.registerDirectory("/addons/", do_get_file("addons"));
michael@0 46 testserver.registerDirectory("/data/", do_get_file("data"));
michael@0 47 testserver.registerPathHandler("/redirect", function(aRequest, aResponse) {
michael@0 48 aResponse.setStatusLine(null, 301, "Moved Permanently");
michael@0 49 let url = aRequest.host + ":" + aRequest.port + aRequest.queryString;
michael@0 50 aResponse.setHeader("Location", "http://" + url);
michael@0 51 });
michael@0 52 testserver.start(-1);
michael@0 53 gPort = testserver.identity.primaryPort;
michael@0 54
michael@0 55 do_test_pending();
michael@0 56 run_test_1();
michael@0 57 }
michael@0 58
michael@0 59 function end_test() {
michael@0 60 testserver.stop(do_test_finished);
michael@0 61 }
michael@0 62
michael@0 63 // Checks that an install from a local file proceeds as expected
michael@0 64 function run_test_1() {
michael@0 65 prepare_test({ }, [
michael@0 66 "onNewInstall"
michael@0 67 ]);
michael@0 68
michael@0 69 AddonManager.getInstallForFile(do_get_addon("test_install1"), function(install) {
michael@0 70 ensure_test_completed();
michael@0 71
michael@0 72 do_check_neq(install, null);
michael@0 73 do_check_eq(install.linkedInstalls, null);
michael@0 74 do_check_eq(install.type, "extension");
michael@0 75 do_check_eq(install.version, "1.0");
michael@0 76 do_check_eq(install.name, "Test 1");
michael@0 77 do_check_eq(install.state, AddonManager.STATE_DOWNLOADED);
michael@0 78 do_check_true(install.addon.hasResource("install.rdf"));
michael@0 79 do_check_neq(install.addon.syncGUID, null);
michael@0 80 do_check_eq(install.addon.install, install);
michael@0 81 do_check_eq(install.addon.size, ADDON1_SIZE);
michael@0 82 do_check_true(hasFlag(install.addon.operationsRequiringRestart,
michael@0 83 AddonManager.OP_NEEDS_RESTART_INSTALL));
michael@0 84 let file = do_get_addon("test_install1");
michael@0 85 let uri = Services.io.newFileURI(file).spec;
michael@0 86 do_check_eq(install.addon.getResourceURI("install.rdf").spec, "jar:" + uri + "!/install.rdf");
michael@0 87 do_check_eq(install.addon.iconURL, "jar:" + uri + "!/icon.png");
michael@0 88 do_check_eq(install.addon.icon64URL, "jar:" + uri + "!/icon64.png");
michael@0 89 do_check_eq(install.iconURL, null);
michael@0 90
michael@0 91 do_check_eq(install.sourceURI.spec, uri);
michael@0 92 do_check_eq(install.addon.sourceURI.spec, uri);
michael@0 93
michael@0 94 AddonManager.getAllInstalls(function(activeInstalls) {
michael@0 95 do_check_eq(activeInstalls.length, 1);
michael@0 96 do_check_eq(activeInstalls[0], install);
michael@0 97
michael@0 98 AddonManager.getInstallsByTypes(["foo"], function(fooInstalls) {
michael@0 99 do_check_eq(fooInstalls.length, 0);
michael@0 100
michael@0 101 AddonManager.getInstallsByTypes(["extension"], function(extensionInstalls) {
michael@0 102 do_check_eq(extensionInstalls.length, 1);
michael@0 103 do_check_eq(extensionInstalls[0], install);
michael@0 104
michael@0 105 prepare_test({
michael@0 106 "addon1@tests.mozilla.org": [
michael@0 107 "onInstalling"
michael@0 108 ]
michael@0 109 }, [
michael@0 110 "onInstallStarted",
michael@0 111 "onInstallEnded",
michael@0 112 ], function() {
michael@0 113 check_test_1(install.addon.syncGUID);
michael@0 114 });
michael@0 115 install.install();
michael@0 116 });
michael@0 117 });
michael@0 118 });
michael@0 119 });
michael@0 120 }
michael@0 121
michael@0 122 function check_test_1(installSyncGUID) {
michael@0 123 ensure_test_completed();
michael@0 124 AddonManager.getAddonByID("addon1@tests.mozilla.org", function(olda1) {
michael@0 125 do_check_eq(olda1, null);
michael@0 126
michael@0 127 AddonManager.getAddonsWithOperationsByTypes(null, callback_soon(function(pendingAddons) {
michael@0 128 do_check_eq(pendingAddons.length, 1);
michael@0 129 do_check_eq(pendingAddons[0].id, "addon1@tests.mozilla.org");
michael@0 130 let uri = NetUtil.newURI(pendingAddons[0].iconURL);
michael@0 131 if (uri instanceof AM_Ci.nsIJARURI) {
michael@0 132 let jarURI = uri.QueryInterface(AM_Ci.nsIJARURI);
michael@0 133 let archiveURI = jarURI.JARFile;
michael@0 134 let archiveFile = archiveURI.QueryInterface(AM_Ci.nsIFileURL).file;
michael@0 135 let zipReader = Cc["@mozilla.org/libjar/zip-reader;1"].
michael@0 136 createInstance(Ci.nsIZipReader);
michael@0 137 try {
michael@0 138 zipReader.open(archiveFile);
michael@0 139 do_check_true(zipReader.hasEntry(jarURI.JAREntry));
michael@0 140 }
michael@0 141 finally {
michael@0 142 zipReader.close();
michael@0 143 }
michael@0 144 }
michael@0 145 else {
michael@0 146 let iconFile = uri.QueryInterface(AM_Ci.nsIFileURL).file;
michael@0 147 do_check_true(iconFile.exists());
michael@0 148 }
michael@0 149
michael@0 150 // Make the pending install have a sensible date
michael@0 151 let updateDate = Date.now();
michael@0 152 let extURI = pendingAddons[0].getResourceURI("");
michael@0 153 let ext = extURI.QueryInterface(AM_Ci.nsIFileURL).file;
michael@0 154 setExtensionModifiedTime(ext, updateDate);
michael@0 155
michael@0 156 // The pending add-on cannot be disabled or enabled.
michael@0 157 do_check_false(hasFlag(pendingAddons[0].permissions, AddonManager.PERM_CAN_ENABLE));
michael@0 158 do_check_false(hasFlag(pendingAddons[0].permissions, AddonManager.PERM_CAN_DISABLE));
michael@0 159
michael@0 160 restartManager();
michael@0 161
michael@0 162 AddonManager.getAllInstalls(function(activeInstalls) {
michael@0 163 do_check_eq(activeInstalls, 0);
michael@0 164
michael@0 165 AddonManager.getAddonByID("addon1@tests.mozilla.org", callback_soon(function(a1) {
michael@0 166 do_check_neq(a1, null);
michael@0 167 do_check_neq(a1.syncGUID, null);
michael@0 168 do_check_true(a1.syncGUID.length >= 9);
michael@0 169 do_check_eq(a1.syncGUID, installSyncGUID);
michael@0 170 do_check_eq(a1.type, "extension");
michael@0 171 do_check_eq(a1.version, "1.0");
michael@0 172 do_check_eq(a1.name, "Test 1");
michael@0 173 do_check_true(isExtensionInAddonsList(profileDir, a1.id));
michael@0 174 do_check_true(do_get_addon("test_install1").exists());
michael@0 175 do_check_in_crash_annotation(a1.id, a1.version);
michael@0 176 do_check_eq(a1.size, ADDON1_SIZE);
michael@0 177 do_check_false(a1.foreignInstall);
michael@0 178
michael@0 179 do_check_eq(a1.sourceURI.spec,
michael@0 180 Services.io.newFileURI(do_get_addon("test_install1")).spec);
michael@0 181 let difference = a1.installDate.getTime() - updateDate;
michael@0 182 if (Math.abs(difference) > MAX_TIME_DIFFERENCE)
michael@0 183 do_throw("Add-on install time was out by " + difference + "ms");
michael@0 184
michael@0 185 difference = a1.updateDate.getTime() - updateDate;
michael@0 186 if (Math.abs(difference) > MAX_TIME_DIFFERENCE)
michael@0 187 do_throw("Add-on update time was out by " + difference + "ms");
michael@0 188
michael@0 189 do_check_true(a1.hasResource("install.rdf"));
michael@0 190 do_check_false(a1.hasResource("foo.bar"));
michael@0 191
michael@0 192 let uri = do_get_addon_root_uri(profileDir, "addon1@tests.mozilla.org");
michael@0 193 do_check_eq(a1.getResourceURI("install.rdf").spec, uri + "install.rdf");
michael@0 194 do_check_eq(a1.iconURL, uri + "icon.png");
michael@0 195 do_check_eq(a1.icon64URL, uri + "icon64.png");
michael@0 196
michael@0 197 a1.uninstall();
michael@0 198 restartManager();
michael@0 199 do_check_not_in_crash_annotation(a1.id, a1.version);
michael@0 200
michael@0 201 do_execute_soon(run_test_2);
michael@0 202 }));
michael@0 203 });
michael@0 204 }));
michael@0 205 });
michael@0 206 }
michael@0 207
michael@0 208 // Tests that an install from a url downloads.
michael@0 209 function run_test_2() {
michael@0 210 let url = "http://localhost:" + gPort + "/addons/test_install2_1.xpi";
michael@0 211 AddonManager.getInstallForURL(url, function(install) {
michael@0 212 do_check_neq(install, null);
michael@0 213 do_check_eq(install.linkedInstalls, null);
michael@0 214 do_check_eq(install.version, "1.0");
michael@0 215 do_check_eq(install.name, "Test 2");
michael@0 216 do_check_eq(install.state, AddonManager.STATE_AVAILABLE);
michael@0 217 do_check_eq(install.iconURL, null);
michael@0 218 do_check_eq(install.sourceURI.spec, url);
michael@0 219
michael@0 220 AddonManager.getAllInstalls(function(activeInstalls) {
michael@0 221 do_check_eq(activeInstalls.length, 1);
michael@0 222 do_check_eq(activeInstalls[0], install);
michael@0 223
michael@0 224 prepare_test({}, [
michael@0 225 "onDownloadStarted",
michael@0 226 "onDownloadEnded",
michael@0 227 ], check_test_2);
michael@0 228
michael@0 229 install.addListener({
michael@0 230 onDownloadProgress: function(install) {
michael@0 231 do_execute_soon(function() {
michael@0 232 Components.utils.forceGC();
michael@0 233 });
michael@0 234 }
michael@0 235 });
michael@0 236
michael@0 237 install.install();
michael@0 238 });
michael@0 239 }, "application/x-xpinstall", null, "Test 2", null, "1.0");
michael@0 240 }
michael@0 241
michael@0 242 function check_test_2(install) {
michael@0 243 ensure_test_completed();
michael@0 244 do_check_eq(install.version, "2.0");
michael@0 245 do_check_eq(install.name, "Real Test 2");
michael@0 246 do_check_eq(install.state, AddonManager.STATE_DOWNLOADED);
michael@0 247 do_check_eq(install.addon.install, install);
michael@0 248 do_check_true(hasFlag(install.addon.operationsRequiringRestart,
michael@0 249 AddonManager.OP_NEEDS_RESTART_INSTALL));
michael@0 250 do_check_eq(install.iconURL, null);
michael@0 251
michael@0 252 // Pause the install here and start it again in run_test_3
michael@0 253 do_execute_soon(function() { run_test_3(install); });
michael@0 254 return false;
michael@0 255 }
michael@0 256
michael@0 257 // Tests that the downloaded XPI installs ok
michael@0 258 function run_test_3(install) {
michael@0 259 prepare_test({
michael@0 260 "addon2@tests.mozilla.org": [
michael@0 261 "onInstalling"
michael@0 262 ]
michael@0 263 }, [
michael@0 264 "onInstallStarted",
michael@0 265 "onInstallEnded",
michael@0 266 ], check_test_3);
michael@0 267 install.install();
michael@0 268 }
michael@0 269
michael@0 270 function check_test_3(aInstall) {
michael@0 271 // Make the pending install have a sensible date
michael@0 272 let updateDate = Date.now();
michael@0 273 let extURI = aInstall.addon.getResourceURI("");
michael@0 274 let ext = extURI.QueryInterface(AM_Ci.nsIFileURL).file;
michael@0 275 setExtensionModifiedTime(ext, updateDate);
michael@0 276
michael@0 277 ensure_test_completed();
michael@0 278 AddonManager.getAddonByID("addon2@tests.mozilla.org", callback_soon(function(olda2) {
michael@0 279 do_check_eq(olda2, null);
michael@0 280 restartManager();
michael@0 281
michael@0 282 AddonManager.getAllInstalls(function(installs) {
michael@0 283 do_check_eq(installs, 0);
michael@0 284
michael@0 285 AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) {
michael@0 286 do_check_neq(a2, null);
michael@0 287 do_check_neq(a2.syncGUID, null);
michael@0 288 do_check_eq(a2.type, "extension");
michael@0 289 do_check_eq(a2.version, "2.0");
michael@0 290 do_check_eq(a2.name, "Real Test 2");
michael@0 291 do_check_true(isExtensionInAddonsList(profileDir, a2.id));
michael@0 292 do_check_true(do_get_addon("test_install2_1").exists());
michael@0 293 do_check_in_crash_annotation(a2.id, a2.version);
michael@0 294 do_check_eq(a2.sourceURI.spec,
michael@0 295 "http://localhost:" + gPort + "/addons/test_install2_1.xpi");
michael@0 296
michael@0 297 let difference = a2.installDate.getTime() - updateDate;
michael@0 298 if (Math.abs(difference) > MAX_TIME_DIFFERENCE)
michael@0 299 do_throw("Add-on install time was out by " + difference + "ms");
michael@0 300
michael@0 301 difference = a2.updateDate.getTime() - updateDate;
michael@0 302 if (Math.abs(difference) > MAX_TIME_DIFFERENCE)
michael@0 303 do_throw("Add-on update time was out by " + difference + "ms");
michael@0 304
michael@0 305 gInstallDate = a2.installDate.getTime();
michael@0 306
michael@0 307 run_test_4();
michael@0 308 });
michael@0 309 });
michael@0 310 }));
michael@0 311 }
michael@0 312
michael@0 313 // Tests that installing a new version of an existing add-on works
michael@0 314 function run_test_4() {
michael@0 315 prepare_test({ }, [
michael@0 316 "onNewInstall"
michael@0 317 ]);
michael@0 318
michael@0 319 let url = "http://localhost:" + gPort + "/addons/test_install2_2.xpi";
michael@0 320 AddonManager.getInstallForURL(url, function(install) {
michael@0 321 ensure_test_completed();
michael@0 322
michael@0 323 do_check_neq(install, null);
michael@0 324 do_check_eq(install.version, "3.0");
michael@0 325 do_check_eq(install.name, "Test 3");
michael@0 326 do_check_eq(install.state, AddonManager.STATE_AVAILABLE);
michael@0 327
michael@0 328 AddonManager.getAllInstalls(function(activeInstalls) {
michael@0 329 do_check_eq(activeInstalls.length, 1);
michael@0 330 do_check_eq(activeInstalls[0], install);
michael@0 331 do_check_eq(install.existingAddon, null);
michael@0 332
michael@0 333 prepare_test({}, [
michael@0 334 "onDownloadStarted",
michael@0 335 "onDownloadEnded",
michael@0 336 ], check_test_4);
michael@0 337 install.install();
michael@0 338 });
michael@0 339 }, "application/x-xpinstall", null, "Test 3", null, "3.0");
michael@0 340 }
michael@0 341
michael@0 342 function check_test_4(install) {
michael@0 343 ensure_test_completed();
michael@0 344
michael@0 345 do_check_eq(install.version, "3.0");
michael@0 346 do_check_eq(install.name, "Real Test 3");
michael@0 347 do_check_eq(install.state, AddonManager.STATE_DOWNLOADED);
michael@0 348 do_check_neq(install.existingAddon);
michael@0 349 do_check_eq(install.existingAddon.id, "addon2@tests.mozilla.org");
michael@0 350 do_check_eq(install.addon.install, install);
michael@0 351 do_check_true(hasFlag(install.addon.operationsRequiringRestart,
michael@0 352 AddonManager.OP_NEEDS_RESTART_INSTALL));
michael@0 353
michael@0 354 run_test_5();
michael@0 355 // Installation will continue when there is nothing returned.
michael@0 356 }
michael@0 357
michael@0 358 // Continue installing the new version
michael@0 359 function run_test_5() {
michael@0 360 prepare_test({
michael@0 361 "addon2@tests.mozilla.org": [
michael@0 362 "onInstalling"
michael@0 363 ]
michael@0 364 }, [
michael@0 365 "onInstallStarted",
michael@0 366 "onInstallEnded",
michael@0 367 ], check_test_5);
michael@0 368 }
michael@0 369
michael@0 370 function check_test_5(install) {
michael@0 371 ensure_test_completed();
michael@0 372
michael@0 373 do_check_eq(install.existingAddon.pendingUpgrade.install, install);
michael@0 374
michael@0 375 AddonManager.getAddonByID("addon2@tests.mozilla.org", function(olda2) {
michael@0 376 do_check_neq(olda2, null);
michael@0 377 do_check_true(hasFlag(olda2.pendingOperations, AddonManager.PENDING_UPGRADE));
michael@0 378
michael@0 379 AddonManager.getInstallsByTypes(null, callback_soon(function(installs) {
michael@0 380 do_check_eq(installs.length, 1);
michael@0 381 do_check_eq(installs[0].addon, olda2.pendingUpgrade);
michael@0 382 restartManager();
michael@0 383
michael@0 384 AddonManager.getInstallsByTypes(null, function(installs) {
michael@0 385 do_check_eq(installs.length, 0);
michael@0 386
michael@0 387 AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) {
michael@0 388 do_check_neq(a2, null);
michael@0 389 do_check_eq(a2.type, "extension");
michael@0 390 do_check_eq(a2.version, "3.0");
michael@0 391 do_check_eq(a2.name, "Real Test 3");
michael@0 392 do_check_true(a2.isActive);
michael@0 393 do_check_true(isExtensionInAddonsList(profileDir, a2.id));
michael@0 394 do_check_true(do_get_addon("test_install2_2").exists());
michael@0 395 do_check_in_crash_annotation(a2.id, a2.version);
michael@0 396 do_check_eq(a2.sourceURI.spec,
michael@0 397 "http://localhost:" + gPort + "/addons/test_install2_2.xpi");
michael@0 398 do_check_false(a2.foreignInstall);
michael@0 399
michael@0 400 do_check_eq(a2.installDate.getTime(), gInstallDate);
michael@0 401 // Update date should be later (or the same if this test is too fast)
michael@0 402 do_check_true(a2.installDate <= a2.updateDate);
michael@0 403
michael@0 404 a2.uninstall();
michael@0 405 do_execute_soon(run_test_6);
michael@0 406 });
michael@0 407 });
michael@0 408 }));
michael@0 409 });
michael@0 410 }
michael@0 411
michael@0 412 // Tests that an install that requires a compatibility update works
michael@0 413 function run_test_6() {
michael@0 414 restartManager();
michael@0 415
michael@0 416 prepare_test({ }, [
michael@0 417 "onNewInstall"
michael@0 418 ]);
michael@0 419
michael@0 420 let url = "http://localhost:" + gPort + "/addons/test_install3.xpi";
michael@0 421 AddonManager.getInstallForURL(url, function(install) {
michael@0 422 ensure_test_completed();
michael@0 423
michael@0 424 do_check_neq(install, null);
michael@0 425 do_check_eq(install.version, "1.0");
michael@0 426 do_check_eq(install.name, "Real Test 4");
michael@0 427 do_check_eq(install.state, AddonManager.STATE_AVAILABLE);
michael@0 428
michael@0 429 AddonManager.getInstallsByTypes(null, function(activeInstalls) {
michael@0 430 do_check_eq(activeInstalls.length, 1);
michael@0 431 do_check_eq(activeInstalls[0], install);
michael@0 432
michael@0 433 prepare_test({}, [
michael@0 434 "onDownloadStarted",
michael@0 435 "onDownloadEnded",
michael@0 436 ], check_test_6);
michael@0 437 install.install();
michael@0 438 });
michael@0 439 }, "application/x-xpinstall", null, "Real Test 4", null, "1.0");
michael@0 440 }
michael@0 441
michael@0 442 function check_test_6(install) {
michael@0 443 ensure_test_completed();
michael@0 444 do_check_eq(install.version, "1.0");
michael@0 445 do_check_eq(install.name, "Real Test 4");
michael@0 446 do_check_eq(install.state, AddonManager.STATE_DOWNLOADED);
michael@0 447 do_check_eq(install.existingAddon, null);
michael@0 448 do_check_false(install.addon.appDisabled);
michael@0 449 run_test_7();
michael@0 450 return true;
michael@0 451 }
michael@0 452
michael@0 453 // Continue the install
michael@0 454 function run_test_7() {
michael@0 455 prepare_test({
michael@0 456 "addon3@tests.mozilla.org": [
michael@0 457 "onInstalling"
michael@0 458 ]
michael@0 459 }, [
michael@0 460 "onInstallStarted",
michael@0 461 "onInstallEnded",
michael@0 462 ], check_test_7);
michael@0 463 }
michael@0 464
michael@0 465 function check_test_7() {
michael@0 466 ensure_test_completed();
michael@0 467 AddonManager.getAddonByID("addon3@tests.mozilla.org", callback_soon(function(olda3) {
michael@0 468 do_check_eq(olda3, null);
michael@0 469 restartManager();
michael@0 470
michael@0 471 AddonManager.getAllInstalls(function(installs) {
michael@0 472 do_check_eq(installs, 0);
michael@0 473
michael@0 474 AddonManager.getAddonByID("addon3@tests.mozilla.org", function(a3) {
michael@0 475 do_check_neq(a3, null);
michael@0 476 do_check_neq(a3.syncGUID, null);
michael@0 477 do_check_eq(a3.type, "extension");
michael@0 478 do_check_eq(a3.version, "1.0");
michael@0 479 do_check_eq(a3.name, "Real Test 4");
michael@0 480 do_check_true(a3.isActive);
michael@0 481 do_check_false(a3.appDisabled);
michael@0 482 do_check_true(isExtensionInAddonsList(profileDir, a3.id));
michael@0 483 do_check_true(do_get_addon("test_install3").exists());
michael@0 484 a3.uninstall();
michael@0 485 do_execute_soon(run_test_8);
michael@0 486 });
michael@0 487 });
michael@0 488 }));
michael@0 489 }
michael@0 490
michael@0 491 function run_test_8() {
michael@0 492 restartManager();
michael@0 493
michael@0 494 AddonManager.addInstallListener(InstallListener);
michael@0 495 AddonManager.addAddonListener(AddonListener);
michael@0 496
michael@0 497 prepare_test({ }, [
michael@0 498 "onNewInstall"
michael@0 499 ]);
michael@0 500
michael@0 501 AddonManager.getInstallForFile(do_get_addon("test_install3"), function(install) {
michael@0 502 do_check_true(install.addon.isCompatible);
michael@0 503
michael@0 504 prepare_test({
michael@0 505 "addon3@tests.mozilla.org": [
michael@0 506 "onInstalling"
michael@0 507 ]
michael@0 508 }, [
michael@0 509 "onInstallStarted",
michael@0 510 "onInstallEnded",
michael@0 511 ], callback_soon(check_test_8));
michael@0 512 install.install();
michael@0 513 });
michael@0 514 }
michael@0 515
michael@0 516 function check_test_8() {
michael@0 517 restartManager();
michael@0 518
michael@0 519 AddonManager.getAddonByID("addon3@tests.mozilla.org", function(a3) {
michael@0 520 do_check_neq(a3, null);
michael@0 521 do_check_neq(a3.syncGUID, null);
michael@0 522 do_check_eq(a3.type, "extension");
michael@0 523 do_check_eq(a3.version, "1.0");
michael@0 524 do_check_eq(a3.name, "Real Test 4");
michael@0 525 do_check_true(a3.isActive);
michael@0 526 do_check_false(a3.appDisabled);
michael@0 527 do_check_true(isExtensionInAddonsList(profileDir, a3.id));
michael@0 528 do_check_true(do_get_addon("test_install3").exists());
michael@0 529 a3.uninstall();
michael@0 530 do_execute_soon(run_test_9);
michael@0 531 });
michael@0 532 }
michael@0 533
michael@0 534 // Test that after cancelling a download it is removed from the active installs
michael@0 535 function run_test_9() {
michael@0 536 restartManager();
michael@0 537
michael@0 538 prepare_test({ }, [
michael@0 539 "onNewInstall"
michael@0 540 ]);
michael@0 541
michael@0 542 let url = "http://localhost:" + gPort + "/addons/test_install3.xpi";
michael@0 543 AddonManager.getInstallForURL(url, function(install) {
michael@0 544 ensure_test_completed();
michael@0 545
michael@0 546 do_check_neq(install, null);
michael@0 547 do_check_eq(install.version, "1.0");
michael@0 548 do_check_eq(install.name, "Real Test 4");
michael@0 549 do_check_eq(install.state, AddonManager.STATE_AVAILABLE);
michael@0 550
michael@0 551 AddonManager.getInstallsByTypes(null, function(activeInstalls) {
michael@0 552 do_check_eq(activeInstalls.length, 1);
michael@0 553 do_check_eq(activeInstalls[0], install);
michael@0 554
michael@0 555 prepare_test({}, [
michael@0 556 "onDownloadStarted",
michael@0 557 "onDownloadEnded",
michael@0 558 ], check_test_9);
michael@0 559 install.install();
michael@0 560 });
michael@0 561 }, "application/x-xpinstall", null, "Real Test 4", null, "1.0");
michael@0 562 }
michael@0 563
michael@0 564 function check_test_9(install) {
michael@0 565 prepare_test({}, [
michael@0 566 "onDownloadCancelled"
michael@0 567 ]);
michael@0 568
michael@0 569 install.cancel();
michael@0 570
michael@0 571 ensure_test_completed();
michael@0 572
michael@0 573 AddonManager.getAllInstalls(function(activeInstalls) {
michael@0 574 do_check_eq(activeInstalls.length, 0);
michael@0 575
michael@0 576 run_test_10();
michael@0 577 });
michael@0 578 }
michael@0 579
michael@0 580 // Tests that after cancelling a pending install it is removed from the active
michael@0 581 // installs
michael@0 582 function run_test_10() {
michael@0 583 prepare_test({ }, [
michael@0 584 "onNewInstall"
michael@0 585 ]);
michael@0 586
michael@0 587 let url = "http://localhost:" + gPort + "/addons/test_install3.xpi";
michael@0 588 AddonManager.getInstallForURL(url, function(install) {
michael@0 589 ensure_test_completed();
michael@0 590
michael@0 591 do_check_neq(install, null);
michael@0 592 do_check_eq(install.version, "1.0");
michael@0 593 do_check_eq(install.name, "Real Test 4");
michael@0 594 do_check_eq(install.state, AddonManager.STATE_AVAILABLE);
michael@0 595
michael@0 596 AddonManager.getInstallsByTypes(null, function(activeInstalls) {
michael@0 597 do_check_eq(activeInstalls.length, 1);
michael@0 598 do_check_eq(activeInstalls[0], install);
michael@0 599
michael@0 600 prepare_test({
michael@0 601 "addon3@tests.mozilla.org": [
michael@0 602 "onInstalling"
michael@0 603 ]
michael@0 604 }, [
michael@0 605 "onDownloadStarted",
michael@0 606 "onDownloadEnded",
michael@0 607 "onInstallStarted",
michael@0 608 "onInstallEnded"
michael@0 609 ], check_test_10);
michael@0 610 install.install();
michael@0 611 });
michael@0 612 }, "application/x-xpinstall", null, "Real Test 4", null, "1.0");
michael@0 613 }
michael@0 614
michael@0 615 function check_test_10(install) {
michael@0 616 prepare_test({
michael@0 617 "addon3@tests.mozilla.org": [
michael@0 618 "onOperationCancelled"
michael@0 619 ]
michael@0 620 }, [
michael@0 621 "onInstallCancelled"
michael@0 622 ]);
michael@0 623
michael@0 624 install.cancel();
michael@0 625
michael@0 626 ensure_test_completed();
michael@0 627
michael@0 628 AddonManager.getAllInstalls(callback_soon(function(activeInstalls) {
michael@0 629 do_check_eq(activeInstalls.length, 0);
michael@0 630
michael@0 631 restartManager();
michael@0 632
michael@0 633 // Check that the install did not complete
michael@0 634 AddonManager.getAddonByID("addon3@tests.mozilla.org", function(a3) {
michael@0 635 do_check_eq(a3, null);
michael@0 636
michael@0 637 do_execute_soon(run_test_11);
michael@0 638 });
michael@0 639 }));
michael@0 640 }
michael@0 641
michael@0 642 // Tests that a multi-package install shows up as multiple installs with the
michael@0 643 // correct sourceURI.
michael@0 644 function run_test_11() {
michael@0 645 prepare_test({ }, [
michael@0 646 "onNewInstall",
michael@0 647 "onNewInstall",
michael@0 648 "onNewInstall",
michael@0 649 "onNewInstall"
michael@0 650 ]);
michael@0 651
michael@0 652 AddonManager.getInstallForFile(do_get_addon("test_install4"), function(install) {
michael@0 653 ensure_test_completed();
michael@0 654 do_check_neq(install, null);
michael@0 655 do_check_neq(install.linkedInstalls, null);
michael@0 656 do_check_eq(install.linkedInstalls.length, 3);
michael@0 657
michael@0 658 // Might be in any order so sort them based on ID
michael@0 659 let installs = [install].concat(install.linkedInstalls);
michael@0 660 installs.sort(function(a, b) {
michael@0 661 if (a.addon.id < b.addon.id)
michael@0 662 return -1;
michael@0 663 if (a.addon.id > b.addon.id)
michael@0 664 return 1;
michael@0 665 return 0;
michael@0 666 });
michael@0 667
michael@0 668 // Comes from addon4.xpi and is made compatible by an update check
michael@0 669 do_check_eq(installs[0].sourceURI, install.sourceURI);
michael@0 670 do_check_eq(installs[0].addon.id, "addon4@tests.mozilla.org");
michael@0 671 do_check_false(installs[0].addon.appDisabled);
michael@0 672 do_check_eq(installs[0].version, "1.0");
michael@0 673 do_check_eq(installs[0].name, "Multi Test 1");
michael@0 674 do_check_eq(installs[0].state, AddonManager.STATE_DOWNLOADED);
michael@0 675 do_check_true(hasFlag(installs[0].addon.operationsRequiringRestart,
michael@0 676 AddonManager.OP_NEEDS_RESTART_INSTALL));
michael@0 677
michael@0 678 // Comes from addon5.jar and is compatible by default
michael@0 679 do_check_eq(installs[1].sourceURI, install.sourceURI);
michael@0 680 do_check_eq(installs[1].addon.id, "addon5@tests.mozilla.org");
michael@0 681 do_check_false(installs[1].addon.appDisabled);
michael@0 682 do_check_eq(installs[1].version, "3.0");
michael@0 683 do_check_eq(installs[1].name, "Multi Test 2");
michael@0 684 do_check_eq(installs[1].state, AddonManager.STATE_DOWNLOADED);
michael@0 685 do_check_true(hasFlag(installs[1].addon.operationsRequiringRestart,
michael@0 686 AddonManager.OP_NEEDS_RESTART_INSTALL));
michael@0 687
michael@0 688 // Comes from addon6.xpi and would be incompatible with strict compat enabled
michael@0 689 do_check_eq(installs[2].sourceURI, install.sourceURI);
michael@0 690 do_check_eq(installs[2].addon.id, "addon6@tests.mozilla.org");
michael@0 691 do_check_false(installs[2].addon.appDisabled);
michael@0 692 do_check_eq(installs[2].version, "2.0");
michael@0 693 do_check_eq(installs[2].name, "Multi Test 3");
michael@0 694 do_check_eq(installs[2].state, AddonManager.STATE_DOWNLOADED);
michael@0 695 do_check_true(hasFlag(installs[2].addon.operationsRequiringRestart,
michael@0 696 AddonManager.OP_NEEDS_RESTART_INSTALL));
michael@0 697
michael@0 698 // Comes from addon7.jar and is made compatible by an update check
michael@0 699 do_check_eq(installs[3].sourceURI, install.sourceURI);
michael@0 700 do_check_eq(installs[3].addon.id, "addon7@tests.mozilla.org");
michael@0 701 do_check_false(installs[3].addon.appDisabled);
michael@0 702 do_check_eq(installs[3].version, "5.0");
michael@0 703 do_check_eq(installs[3].name, "Multi Test 4");
michael@0 704 do_check_eq(installs[3].state, AddonManager.STATE_DOWNLOADED);
michael@0 705 do_check_true(hasFlag(installs[3].addon.operationsRequiringRestart,
michael@0 706 AddonManager.OP_NEEDS_RESTART_INSTALL));
michael@0 707
michael@0 708 AddonManager.getAllInstalls(function(aInstalls) {
michael@0 709 do_check_eq(aInstalls.length, 4);
michael@0 710
michael@0 711 prepare_test({
michael@0 712 "addon4@tests.mozilla.org": [
michael@0 713 "onInstalling"
michael@0 714 ],
michael@0 715 "addon5@tests.mozilla.org": [
michael@0 716 "onInstalling"
michael@0 717 ],
michael@0 718 "addon6@tests.mozilla.org": [
michael@0 719 "onInstalling"
michael@0 720 ],
michael@0 721 "addon7@tests.mozilla.org": [
michael@0 722 "onInstalling"
michael@0 723 ]
michael@0 724 }, {
michael@0 725 "addon4@tests.mozilla.org": [
michael@0 726 "onInstallStarted",
michael@0 727 "onInstallEnded"
michael@0 728 ],
michael@0 729 "addon5@tests.mozilla.org": [
michael@0 730 "onInstallStarted",
michael@0 731 "onInstallEnded"
michael@0 732 ],
michael@0 733 "addon6@tests.mozilla.org": [
michael@0 734 "onInstallStarted",
michael@0 735 "onInstallEnded"
michael@0 736 ],
michael@0 737 "addon7@tests.mozilla.org": [
michael@0 738 "onInstallStarted",
michael@0 739 "onInstallEnded"
michael@0 740 ]
michael@0 741 }, callback_soon(check_test_11));
michael@0 742
michael@0 743 installs[0].install();
michael@0 744 installs[1].install();
michael@0 745 installs[3].install();
michael@0 746
michael@0 747 // Note that we install addon6 last. Since it doesn't need a restart to
michael@0 748 // install it completes asynchronously which would otherwise make the
michael@0 749 // onInstallStarted/onInstallEnded events go out of sequence unless this
michael@0 750 // is the last install operation
michael@0 751 installs[2].install();
michael@0 752 });
michael@0 753 });
michael@0 754 }
michael@0 755
michael@0 756 function check_test_11() {
michael@0 757 restartManager();
michael@0 758
michael@0 759 AddonManager.getAddonsByIDs(["addon4@tests.mozilla.org",
michael@0 760 "addon5@tests.mozilla.org",
michael@0 761 "addon6@tests.mozilla.org",
michael@0 762 "addon7@tests.mozilla.org"],
michael@0 763 function([a4, a5, a6, a7]) {
michael@0 764 do_check_neq(a4, null);
michael@0 765 do_check_neq(a5, null);
michael@0 766 do_check_neq(a6, null);
michael@0 767 do_check_neq(a7, null);
michael@0 768
michael@0 769 a4.uninstall();
michael@0 770 a5.uninstall();
michael@0 771 a6.uninstall();
michael@0 772 a7.uninstall();
michael@0 773
michael@0 774 do_execute_soon(run_test_12);
michael@0 775 });
michael@0 776 }
michael@0 777
michael@0 778 // Same as test 11 but for a remote XPI
michael@0 779 function run_test_12() {
michael@0 780 restartManager();
michael@0 781
michael@0 782 prepare_test({ }, [
michael@0 783 "onNewInstall",
michael@0 784 ]);
michael@0 785
michael@0 786 let url = "http://localhost:" + gPort + "/addons/test_install4.xpi";
michael@0 787 AddonManager.getInstallForURL(url, function(install) {
michael@0 788 gInstall = install;
michael@0 789
michael@0 790 ensure_test_completed();
michael@0 791 do_check_neq(install, null);
michael@0 792 do_check_eq(install.linkedInstalls, null);
michael@0 793 do_check_eq(install.state, AddonManager.STATE_AVAILABLE);
michael@0 794
michael@0 795 prepare_test({
michael@0 796 "addon4@tests.mozilla.org": [
michael@0 797 "onInstalling"
michael@0 798 ],
michael@0 799 "addon5@tests.mozilla.org": [
michael@0 800 "onInstalling"
michael@0 801 ],
michael@0 802 "addon6@tests.mozilla.org": [
michael@0 803 "onInstalling"
michael@0 804 ],
michael@0 805 "addon7@tests.mozilla.org": [
michael@0 806 "onInstalling"
michael@0 807 ]
michael@0 808 }, {
michael@0 809 "NO_ID": [
michael@0 810 "onDownloadStarted",
michael@0 811 "onNewInstall",
michael@0 812 "onNewInstall",
michael@0 813 "onNewInstall",
michael@0 814 "onDownloadEnded"
michael@0 815 ],
michael@0 816 "addon4@tests.mozilla.org": [
michael@0 817 "onInstallStarted",
michael@0 818 "onInstallEnded"
michael@0 819 ],
michael@0 820 "addon5@tests.mozilla.org": [
michael@0 821 "onInstallStarted",
michael@0 822 "onInstallEnded"
michael@0 823 ],
michael@0 824 "addon6@tests.mozilla.org": [
michael@0 825 "onInstallStarted",
michael@0 826 "onInstallEnded"
michael@0 827 ],
michael@0 828 "addon7@tests.mozilla.org": [
michael@0 829 "onInstallStarted",
michael@0 830 "onInstallEnded"
michael@0 831 ]
michael@0 832 }, callback_soon(check_test_12));
michael@0 833 install.install();
michael@0 834 }, "application/x-xpinstall", null, "Multi Test 4");
michael@0 835 }
michael@0 836
michael@0 837 function check_test_12() {
michael@0 838 do_check_eq(gInstall.linkedInstalls.length, 3);
michael@0 839
michael@0 840 // Might be in any order so sort them based on ID
michael@0 841 let installs = [gInstall].concat(gInstall.linkedInstalls);
michael@0 842 installs.sort(function(a, b) {
michael@0 843 if (a.addon.id < b.addon.id)
michael@0 844 return -1;
michael@0 845 if (a.addon.id > b.addon.id)
michael@0 846 return 1;
michael@0 847 return 0;
michael@0 848 });
michael@0 849
michael@0 850 // Comes from addon4.xpi and is made compatible by an update check
michael@0 851 do_check_eq(installs[0].sourceURI, gInstall.sourceURI);
michael@0 852 do_check_eq(installs[0].addon.id, "addon4@tests.mozilla.org");
michael@0 853 do_check_false(installs[0].addon.appDisabled);
michael@0 854 do_check_eq(installs[0].version, "1.0");
michael@0 855 do_check_eq(installs[0].name, "Multi Test 1");
michael@0 856 do_check_eq(installs[0].state, AddonManager.STATE_INSTALLED);
michael@0 857
michael@0 858 // Comes from addon5.jar and is compatible by default
michael@0 859 do_check_eq(installs[1].sourceURI, gInstall.sourceURI);
michael@0 860 do_check_eq(installs[1].addon.id, "addon5@tests.mozilla.org");
michael@0 861 do_check_false(installs[1].addon.appDisabled);
michael@0 862 do_check_eq(installs[1].version, "3.0");
michael@0 863 do_check_eq(installs[1].name, "Multi Test 2");
michael@0 864 do_check_eq(installs[1].state, AddonManager.STATE_INSTALLED);
michael@0 865
michael@0 866 // Comes from addon6.xpi and would be incompatible with strict compat enabled
michael@0 867 do_check_eq(installs[2].sourceURI, gInstall.sourceURI);
michael@0 868 do_check_eq(installs[2].addon.id, "addon6@tests.mozilla.org");
michael@0 869 do_check_false(installs[2].addon.appDisabled);
michael@0 870 do_check_eq(installs[2].version, "2.0");
michael@0 871 do_check_eq(installs[2].name, "Multi Test 3");
michael@0 872 do_check_eq(installs[2].state, AddonManager.STATE_INSTALLED);
michael@0 873
michael@0 874 // Comes from addon7.jar and is made compatible by an update check
michael@0 875 do_check_eq(installs[3].sourceURI, gInstall.sourceURI);
michael@0 876 do_check_eq(installs[3].addon.id, "addon7@tests.mozilla.org");
michael@0 877 do_check_false(installs[3].addon.appDisabled);
michael@0 878 do_check_eq(installs[3].version, "5.0");
michael@0 879 do_check_eq(installs[3].name, "Multi Test 4");
michael@0 880 do_check_eq(installs[3].state, AddonManager.STATE_INSTALLED);
michael@0 881
michael@0 882 restartManager();
michael@0 883
michael@0 884 AddonManager.getAddonsByIDs(["addon4@tests.mozilla.org",
michael@0 885 "addon5@tests.mozilla.org",
michael@0 886 "addon6@tests.mozilla.org",
michael@0 887 "addon7@tests.mozilla.org"],
michael@0 888 function([a4, a5, a6, a7]) {
michael@0 889 do_check_neq(a4, null);
michael@0 890 do_check_neq(a5, null);
michael@0 891 do_check_neq(a6, null);
michael@0 892 do_check_neq(a7, null);
michael@0 893
michael@0 894 a4.uninstall();
michael@0 895 a5.uninstall();
michael@0 896 a6.uninstall();
michael@0 897 a7.uninstall();
michael@0 898
michael@0 899 do_execute_soon(run_test_13);
michael@0 900 });
michael@0 901 }
michael@0 902
michael@0 903
michael@0 904 // Tests that cancelling an upgrade leaves the original add-on's pendingOperations
michael@0 905 // correct
michael@0 906 function run_test_13() {
michael@0 907 restartManager();
michael@0 908
michael@0 909 installAllFiles([do_get_addon("test_install2_1")], function() {
michael@0 910 restartManager();
michael@0 911
michael@0 912 prepare_test({ }, [
michael@0 913 "onNewInstall"
michael@0 914 ]);
michael@0 915
michael@0 916 let url = "http://localhost:" + gPort + "/addons/test_install2_2.xpi";
michael@0 917 AddonManager.getInstallForURL(url, function(install) {
michael@0 918 ensure_test_completed();
michael@0 919
michael@0 920 do_check_neq(install, null);
michael@0 921 do_check_eq(install.version, "3.0");
michael@0 922 do_check_eq(install.name, "Test 3");
michael@0 923 do_check_eq(install.state, AddonManager.STATE_AVAILABLE);
michael@0 924
michael@0 925 AddonManager.getAllInstalls(function(activeInstalls) {
michael@0 926 do_check_eq(activeInstalls.length, 1);
michael@0 927 do_check_eq(activeInstalls[0], install);
michael@0 928 do_check_eq(install.existingAddon, null);
michael@0 929
michael@0 930 prepare_test({
michael@0 931 "addon2@tests.mozilla.org": [
michael@0 932 "onInstalling"
michael@0 933 ]
michael@0 934 }, [
michael@0 935 "onDownloadStarted",
michael@0 936 "onDownloadEnded",
michael@0 937 "onInstallStarted",
michael@0 938 "onInstallEnded",
michael@0 939 ], check_test_13);
michael@0 940 install.install();
michael@0 941 });
michael@0 942 }, "application/x-xpinstall", null, "Test 3", null, "3.0");
michael@0 943 });
michael@0 944 }
michael@0 945
michael@0 946 function check_test_13(install) {
michael@0 947 ensure_test_completed();
michael@0 948
michael@0 949 do_check_eq(install.version, "3.0");
michael@0 950 do_check_eq(install.name, "Real Test 3");
michael@0 951 do_check_eq(install.state, AddonManager.STATE_INSTALLED);
michael@0 952 do_check_neq(install.existingAddon, null);
michael@0 953 do_check_eq(install.existingAddon.id, "addon2@tests.mozilla.org");
michael@0 954 do_check_eq(install.addon.install, install);
michael@0 955
michael@0 956 AddonManager.getAddonByID("addon2@tests.mozilla.org", callback_soon(function(olda2) {
michael@0 957 do_check_neq(olda2, null);
michael@0 958 do_check_true(hasFlag(olda2.pendingOperations, AddonManager.PENDING_UPGRADE));
michael@0 959 do_check_eq(olda2.pendingUpgrade, install.addon);
michael@0 960
michael@0 961 do_check_true(hasFlag(install.addon.pendingOperations,
michael@0 962 AddonManager.PENDING_INSTALL));
michael@0 963
michael@0 964 prepare_test({
michael@0 965 "addon2@tests.mozilla.org": [
michael@0 966 "onOperationCancelled"
michael@0 967 ]
michael@0 968 }, [
michael@0 969 "onInstallCancelled",
michael@0 970 ]);
michael@0 971
michael@0 972 install.cancel();
michael@0 973
michael@0 974 do_check_false(hasFlag(install.addon.pendingOperations, AddonManager.PENDING_INSTALL));
michael@0 975
michael@0 976 do_check_false(hasFlag(olda2.pendingOperations, AddonManager.PENDING_UPGRADE));
michael@0 977 do_check_eq(olda2.pendingUpgrade, null);
michael@0 978
michael@0 979 restartManager();
michael@0 980
michael@0 981 // Check that the upgrade did not complete
michael@0 982 AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) {
michael@0 983 do_check_eq(a2.version, "2.0");
michael@0 984
michael@0 985 a2.uninstall();
michael@0 986
michael@0 987 do_execute_soon(run_test_14);
michael@0 988 });
michael@0 989 }));
michael@0 990 }
michael@0 991
michael@0 992 // Check that cancelling the install from onDownloadStarted actually cancels it
michael@0 993 function run_test_14() {
michael@0 994 restartManager();
michael@0 995
michael@0 996 prepare_test({ }, [
michael@0 997 "onNewInstall"
michael@0 998 ]);
michael@0 999
michael@0 1000 let url = "http://localhost:" + gPort + "/addons/test_install2_1.xpi";
michael@0 1001 AddonManager.getInstallForURL(url, function(install) {
michael@0 1002 ensure_test_completed();
michael@0 1003
michael@0 1004 do_check_eq(install.file, null);
michael@0 1005
michael@0 1006 prepare_test({ }, [
michael@0 1007 "onDownloadStarted"
michael@0 1008 ], check_test_14);
michael@0 1009 install.install();
michael@0 1010 }, "application/x-xpinstall");
michael@0 1011 }
michael@0 1012
michael@0 1013 function check_test_14(install) {
michael@0 1014 prepare_test({ }, [
michael@0 1015 "onDownloadCancelled"
michael@0 1016 ]);
michael@0 1017
michael@0 1018 install.cancel();
michael@0 1019
michael@0 1020 ensure_test_completed();
michael@0 1021
michael@0 1022 install.addListener({
michael@0 1023 onDownloadProgress: function() {
michael@0 1024 do_throw("Download should not have continued");
michael@0 1025 },
michael@0 1026 onDownloadEnded: function() {
michael@0 1027 do_throw("Download should not have continued");
michael@0 1028 }
michael@0 1029 });
michael@0 1030
michael@0 1031 // Allow the listener to return to see if it continues downloading. The
michael@0 1032 // The listener only really tests if we give it time to see progress, the
michael@0 1033 // file check isn't ideal either
michael@0 1034 do_execute_soon(function() {
michael@0 1035 do_check_eq(install.file, null);
michael@0 1036
michael@0 1037 run_test_15();
michael@0 1038 });
michael@0 1039 }
michael@0 1040
michael@0 1041 // Checks that cancelling the install from onDownloadEnded actually cancels it
michael@0 1042 function run_test_15() {
michael@0 1043 prepare_test({ }, [
michael@0 1044 "onNewInstall"
michael@0 1045 ]);
michael@0 1046
michael@0 1047 let url = "http://localhost:" + gPort + "/addons/test_install2_1.xpi";
michael@0 1048 AddonManager.getInstallForURL(url, function(install) {
michael@0 1049 ensure_test_completed();
michael@0 1050
michael@0 1051 do_check_eq(install.file, null);
michael@0 1052
michael@0 1053 prepare_test({ }, [
michael@0 1054 "onDownloadStarted",
michael@0 1055 "onDownloadEnded"
michael@0 1056 ], check_test_15);
michael@0 1057 install.install();
michael@0 1058 }, "application/x-xpinstall");
michael@0 1059 }
michael@0 1060
michael@0 1061 function check_test_15(install) {
michael@0 1062 prepare_test({ }, [
michael@0 1063 "onDownloadCancelled"
michael@0 1064 ]);
michael@0 1065
michael@0 1066 install.cancel();
michael@0 1067
michael@0 1068 ensure_test_completed();
michael@0 1069
michael@0 1070 install.addListener({
michael@0 1071 onInstallStarted: function() {
michael@0 1072 do_throw("Install should not have continued");
michael@0 1073 }
michael@0 1074 });
michael@0 1075
michael@0 1076 // Allow the listener to return to see if it starts installing
michael@0 1077 do_execute_soon(run_test_16);
michael@0 1078 }
michael@0 1079
michael@0 1080 // Verify that the userDisabled value carries over to the upgrade by default
michael@0 1081 function run_test_16() {
michael@0 1082 restartManager();
michael@0 1083
michael@0 1084 let url = "http://localhost:" + gPort + "/addons/test_install2_1.xpi";
michael@0 1085 AddonManager.getInstallForURL(url, function(aInstall) {
michael@0 1086 aInstall.addListener({
michael@0 1087 onInstallStarted: function() {
michael@0 1088 do_check_false(aInstall.addon.userDisabled);
michael@0 1089 aInstall.addon.userDisabled = true;
michael@0 1090 },
michael@0 1091
michael@0 1092 onInstallEnded: function() {
michael@0 1093 do_execute_soon(function install2_1_ended() {
michael@0 1094 restartManager();
michael@0 1095
michael@0 1096 AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) {
michael@0 1097 do_check_true(a2.userDisabled);
michael@0 1098 do_check_false(a2.isActive);
michael@0 1099
michael@0 1100 let url = "http://localhost:" + gPort + "/addons/test_install2_2.xpi";
michael@0 1101 AddonManager.getInstallForURL(url, function(aInstall) {
michael@0 1102 aInstall.addListener({
michael@0 1103 onInstallEnded: function() {
michael@0 1104 do_execute_soon(function install2_2_ended() {
michael@0 1105 do_check_true(aInstall.addon.userDisabled);
michael@0 1106
michael@0 1107 restartManager();
michael@0 1108
michael@0 1109 AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) {
michael@0 1110 do_check_true(a2.userDisabled);
michael@0 1111 do_check_false(a2.isActive);
michael@0 1112
michael@0 1113 a2.uninstall();
michael@0 1114 do_execute_soon(run_test_17);
michael@0 1115 });
michael@0 1116 });
michael@0 1117 }
michael@0 1118 });
michael@0 1119 aInstall.install();
michael@0 1120 }, "application/x-xpinstall");
michael@0 1121 });
michael@0 1122 });
michael@0 1123 }
michael@0 1124 });
michael@0 1125 aInstall.install();
michael@0 1126 }, "application/x-xpinstall");
michael@0 1127 }
michael@0 1128
michael@0 1129 // Verify that changing the userDisabled value before onInstallEnded works
michael@0 1130 function run_test_17() {
michael@0 1131 restartManager();
michael@0 1132
michael@0 1133 let url = "http://localhost:" + gPort + "/addons/test_install2_1.xpi";
michael@0 1134 AddonManager.getInstallForURL(url, function(aInstall) {
michael@0 1135 aInstall.addListener({
michael@0 1136 onInstallEnded: function() {
michael@0 1137 do_execute_soon(function install2_1_ended2() {
michael@0 1138 do_check_false(aInstall.addon.userDisabled);
michael@0 1139
michael@0 1140 restartManager();
michael@0 1141
michael@0 1142 AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) {
michael@0 1143 do_check_false(a2.userDisabled);
michael@0 1144 do_check_true(a2.isActive);
michael@0 1145
michael@0 1146 let url = "http://localhost:" + gPort + "/addons/test_install2_2.xpi";
michael@0 1147 AddonManager.getInstallForURL(url, function(aInstall) {
michael@0 1148 aInstall.addListener({
michael@0 1149 onInstallStarted: function() {
michael@0 1150 do_check_false(aInstall.addon.userDisabled);
michael@0 1151 aInstall.addon.userDisabled = true;
michael@0 1152 },
michael@0 1153
michael@0 1154 onInstallEnded: function() {
michael@0 1155 do_execute_soon(function install2_2_ended2() {
michael@0 1156 restartManager();
michael@0 1157
michael@0 1158 AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) {
michael@0 1159 do_check_true(a2.userDisabled);
michael@0 1160 do_check_false(a2.isActive);
michael@0 1161
michael@0 1162 a2.uninstall();
michael@0 1163 do_execute_soon(run_test_18);
michael@0 1164 });
michael@0 1165 });
michael@0 1166 }
michael@0 1167 });
michael@0 1168 aInstall.install();
michael@0 1169 }, "application/x-xpinstall");
michael@0 1170 });
michael@0 1171 });
michael@0 1172 }
michael@0 1173 });
michael@0 1174 aInstall.install();
michael@0 1175 }, "application/x-xpinstall");
michael@0 1176 }
michael@0 1177
michael@0 1178 // Verify that changing the userDisabled value before onInstallEnded works
michael@0 1179 function run_test_18() {
michael@0 1180 restartManager();
michael@0 1181
michael@0 1182 let url = "http://localhost:" + gPort + "/addons/test_install2_1.xpi";
michael@0 1183 AddonManager.getInstallForURL(url, function(aInstall) {
michael@0 1184 aInstall.addListener({
michael@0 1185 onInstallStarted: function() {
michael@0 1186 do_check_false(aInstall.addon.userDisabled);
michael@0 1187 aInstall.addon.userDisabled = true;
michael@0 1188 },
michael@0 1189
michael@0 1190 onInstallEnded: function() {
michael@0 1191 do_execute_soon(function install_2_1_ended3() {
michael@0 1192 restartManager();
michael@0 1193
michael@0 1194 AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) {
michael@0 1195 do_check_true(a2.userDisabled);
michael@0 1196 do_check_false(a2.isActive);
michael@0 1197
michael@0 1198 let url = "http://localhost:" + gPort + "/addons/test_install2_2.xpi";
michael@0 1199 AddonManager.getInstallForURL(url, function(aInstall) {
michael@0 1200 aInstall.addListener({
michael@0 1201 onInstallStarted: function() {
michael@0 1202 do_check_true(aInstall.addon.userDisabled);
michael@0 1203 aInstall.addon.userDisabled = false;
michael@0 1204 },
michael@0 1205
michael@0 1206 onInstallEnded: function() {
michael@0 1207 do_execute_soon(function install_2_2_ended3() {
michael@0 1208 restartManager();
michael@0 1209
michael@0 1210 AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) {
michael@0 1211 do_check_false(a2.userDisabled);
michael@0 1212 do_check_true(a2.isActive);
michael@0 1213
michael@0 1214 a2.uninstall();
michael@0 1215 do_execute_soon(run_test_18_1);
michael@0 1216 });
michael@0 1217 });
michael@0 1218 }
michael@0 1219 });
michael@0 1220 aInstall.install();
michael@0 1221 }, "application/x-xpinstall");
michael@0 1222 });
michael@0 1223 });
michael@0 1224 }
michael@0 1225 });
michael@0 1226 aInstall.install();
michael@0 1227 }, "application/x-xpinstall");
michael@0 1228 }
michael@0 1229
michael@0 1230
michael@0 1231 // Checks that metadata is not stored if the pref is set to false
michael@0 1232 function run_test_18_1() {
michael@0 1233 restartManager();
michael@0 1234
michael@0 1235 Services.prefs.setBoolPref("extensions.getAddons.cache.enabled", true);
michael@0 1236 Services.prefs.setCharPref(PREF_GETADDONS_BYIDS,
michael@0 1237 "http://localhost:" + gPort + "/data/test_install.xml");
michael@0 1238
michael@0 1239 Services.prefs.setBoolPref("extensions.addon2@tests.mozilla.org.getAddons.cache.enabled", false);
michael@0 1240
michael@0 1241 let url = "http://localhost:" + gPort + "/addons/test_install2_1.xpi";
michael@0 1242 AddonManager.getInstallForURL(url, function(aInstall) {
michael@0 1243 aInstall.addListener({
michael@0 1244 onInstallEnded: function(aInstall, aAddon) {
michael@0 1245 do_execute_soon(function test18_1_install_ended() {
michael@0 1246 do_check_neq(aAddon.fullDescription, "Repository description");
michael@0 1247
michael@0 1248 restartManager();
michael@0 1249
michael@0 1250 AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) {
michael@0 1251 do_check_neq(a2.fullDescription, "Repository description");
michael@0 1252
michael@0 1253 a2.uninstall();
michael@0 1254 do_execute_soon(run_test_19);
michael@0 1255 });
michael@0 1256 });
michael@0 1257 }
michael@0 1258 });
michael@0 1259 aInstall.install();
michael@0 1260 }, "application/x-xpinstall");
michael@0 1261 }
michael@0 1262
michael@0 1263 // Checks that metadata is downloaded for new installs and is visible before and
michael@0 1264 // after restart
michael@0 1265 function run_test_19() {
michael@0 1266 restartManager();
michael@0 1267 Services.prefs.setBoolPref("extensions.addon2@tests.mozilla.org.getAddons.cache.enabled", true);
michael@0 1268
michael@0 1269 let url = "http://localhost:" + gPort + "/addons/test_install2_1.xpi";
michael@0 1270 AddonManager.getInstallForURL(url, function(aInstall) {
michael@0 1271 aInstall.addListener({
michael@0 1272 onInstallEnded: function(aInstall, aAddon) {
michael@0 1273 do_execute_soon(function test19_install_ended() {
michael@0 1274 do_check_eq(aAddon.fullDescription, "Repository description");
michael@0 1275
michael@0 1276 restartManager();
michael@0 1277
michael@0 1278 AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) {
michael@0 1279 do_check_eq(a2.fullDescription, "Repository description");
michael@0 1280
michael@0 1281 a2.uninstall();
michael@0 1282 do_execute_soon(run_test_20);
michael@0 1283 });
michael@0 1284 });
michael@0 1285 }
michael@0 1286 });
michael@0 1287 aInstall.install();
michael@0 1288 }, "application/x-xpinstall");
michael@0 1289 }
michael@0 1290
michael@0 1291 // Do the same again to make sure it works when the data is already in the cache
michael@0 1292 function run_test_20() {
michael@0 1293 restartManager();
michael@0 1294
michael@0 1295 let url = "http://localhost:" + gPort + "/addons/test_install2_1.xpi";
michael@0 1296 AddonManager.getInstallForURL(url, function(aInstall) {
michael@0 1297 aInstall.addListener({
michael@0 1298 onInstallEnded: function(aInstall, aAddon) {
michael@0 1299 do_execute_soon(function test20_install_ended() {
michael@0 1300 do_check_eq(aAddon.fullDescription, "Repository description");
michael@0 1301
michael@0 1302 restartManager();
michael@0 1303
michael@0 1304 AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) {
michael@0 1305 do_check_eq(a2.fullDescription, "Repository description");
michael@0 1306
michael@0 1307 a2.uninstall();
michael@0 1308 do_execute_soon(run_test_21);
michael@0 1309 });
michael@0 1310 });
michael@0 1311 }
michael@0 1312 });
michael@0 1313 aInstall.install();
michael@0 1314 }, "application/x-xpinstall");
michael@0 1315 }
michael@0 1316
michael@0 1317 // Verify that installing an add-on that is already pending install cancels the
michael@0 1318 // first install
michael@0 1319 function run_test_21() {
michael@0 1320 restartManager();
michael@0 1321 Services.prefs.setBoolPref("extensions.getAddons.cache.enabled", false);
michael@0 1322
michael@0 1323 installAllFiles([do_get_addon("test_install2_1")], function() {
michael@0 1324 AddonManager.getAllInstalls(function(aInstalls) {
michael@0 1325 do_check_eq(aInstalls.length, 1);
michael@0 1326
michael@0 1327 prepare_test({
michael@0 1328 "addon2@tests.mozilla.org": [
michael@0 1329 "onOperationCancelled",
michael@0 1330 "onInstalling"
michael@0 1331 ]
michael@0 1332 }, [
michael@0 1333 "onNewInstall",
michael@0 1334 "onDownloadStarted",
michael@0 1335 "onDownloadEnded",
michael@0 1336 "onInstallStarted",
michael@0 1337 "onInstallCancelled",
michael@0 1338 "onInstallEnded",
michael@0 1339 ], check_test_21);
michael@0 1340
michael@0 1341 let url = "http://localhost:" + gPort + "/addons/test_install2_1.xpi";
michael@0 1342 AddonManager.getInstallForURL(url, function(aInstall) {
michael@0 1343 aInstall.install();
michael@0 1344 }, "application/x-xpinstall");
michael@0 1345 });
michael@0 1346 });
michael@0 1347 }
michael@0 1348
michael@0 1349 function check_test_21(aInstall) {
michael@0 1350 AddonManager.getAllInstalls(callback_soon(function(aInstalls) {
michael@0 1351 do_check_eq(aInstalls.length, 1);
michael@0 1352 do_check_eq(aInstalls[0], aInstall);
michael@0 1353
michael@0 1354 prepare_test({
michael@0 1355 "addon2@tests.mozilla.org": [
michael@0 1356 "onOperationCancelled"
michael@0 1357 ]
michael@0 1358 }, [
michael@0 1359 "onInstallCancelled",
michael@0 1360 ]);
michael@0 1361
michael@0 1362 aInstall.cancel();
michael@0 1363
michael@0 1364 ensure_test_completed();
michael@0 1365
michael@0 1366 restartManager();
michael@0 1367
michael@0 1368 AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) {
michael@0 1369 do_check_eq(a2, null);
michael@0 1370
michael@0 1371 run_test_22();
michael@0 1372 });
michael@0 1373 }));
michael@0 1374 }
michael@0 1375
michael@0 1376 // Tests that an install can be restarted after being cancelled
michael@0 1377 function run_test_22() {
michael@0 1378 prepare_test({ }, [
michael@0 1379 "onNewInstall"
michael@0 1380 ]);
michael@0 1381
michael@0 1382 let url = "http://localhost:" + gPort + "/addons/test_install3.xpi";
michael@0 1383 AddonManager.getInstallForURL(url, function(aInstall) {
michael@0 1384 ensure_test_completed();
michael@0 1385
michael@0 1386 do_check_neq(aInstall, null);
michael@0 1387 do_check_eq(aInstall.state, AddonManager.STATE_AVAILABLE);
michael@0 1388
michael@0 1389 prepare_test({}, [
michael@0 1390 "onDownloadStarted",
michael@0 1391 "onDownloadEnded",
michael@0 1392 ], check_test_22);
michael@0 1393 aInstall.install();
michael@0 1394 }, "application/x-xpinstall");
michael@0 1395 }
michael@0 1396
michael@0 1397 function check_test_22(aInstall) {
michael@0 1398 prepare_test({}, [
michael@0 1399 "onDownloadCancelled"
michael@0 1400 ]);
michael@0 1401
michael@0 1402 aInstall.cancel();
michael@0 1403
michael@0 1404 ensure_test_completed();
michael@0 1405
michael@0 1406 prepare_test({
michael@0 1407 "addon3@tests.mozilla.org": [
michael@0 1408 "onInstalling"
michael@0 1409 ]
michael@0 1410 }, [
michael@0 1411 "onDownloadStarted",
michael@0 1412 "onDownloadEnded",
michael@0 1413 "onInstallStarted",
michael@0 1414 "onInstallEnded"
michael@0 1415 ], finish_test_22);
michael@0 1416
michael@0 1417 aInstall.install();
michael@0 1418 }
michael@0 1419
michael@0 1420 function finish_test_22(aInstall) {
michael@0 1421 prepare_test({
michael@0 1422 "addon3@tests.mozilla.org": [
michael@0 1423 "onOperationCancelled"
michael@0 1424 ]
michael@0 1425 }, [
michael@0 1426 "onInstallCancelled"
michael@0 1427 ]);
michael@0 1428
michael@0 1429 aInstall.cancel();
michael@0 1430
michael@0 1431 ensure_test_completed();
michael@0 1432
michael@0 1433 run_test_23();
michael@0 1434 }
michael@0 1435
michael@0 1436 // Tests that an install can be restarted after being cancelled when a hash
michael@0 1437 // was provided
michael@0 1438 function run_test_23() {
michael@0 1439 prepare_test({ }, [
michael@0 1440 "onNewInstall"
michael@0 1441 ]);
michael@0 1442
michael@0 1443 let url = "http://localhost:" + gPort + "/addons/test_install3.xpi";
michael@0 1444 AddonManager.getInstallForURL(url, function(aInstall) {
michael@0 1445 ensure_test_completed();
michael@0 1446
michael@0 1447 do_check_neq(aInstall, null);
michael@0 1448 do_check_eq(aInstall.state, AddonManager.STATE_AVAILABLE);
michael@0 1449
michael@0 1450 prepare_test({}, [
michael@0 1451 "onDownloadStarted",
michael@0 1452 "onDownloadEnded",
michael@0 1453 ], check_test_23);
michael@0 1454 aInstall.install();
michael@0 1455 }, "application/x-xpinstall", do_get_addon_hash("test_install3"));
michael@0 1456 }
michael@0 1457
michael@0 1458 function check_test_23(aInstall) {
michael@0 1459 prepare_test({}, [
michael@0 1460 "onDownloadCancelled"
michael@0 1461 ]);
michael@0 1462
michael@0 1463 aInstall.cancel();
michael@0 1464
michael@0 1465 ensure_test_completed();
michael@0 1466
michael@0 1467 prepare_test({
michael@0 1468 "addon3@tests.mozilla.org": [
michael@0 1469 "onInstalling"
michael@0 1470 ]
michael@0 1471 }, [
michael@0 1472 "onDownloadStarted",
michael@0 1473 "onDownloadEnded",
michael@0 1474 "onInstallStarted",
michael@0 1475 "onInstallEnded"
michael@0 1476 ], finish_test_23);
michael@0 1477
michael@0 1478 aInstall.install();
michael@0 1479 }
michael@0 1480
michael@0 1481 function finish_test_23(aInstall) {
michael@0 1482 prepare_test({
michael@0 1483 "addon3@tests.mozilla.org": [
michael@0 1484 "onOperationCancelled"
michael@0 1485 ]
michael@0 1486 }, [
michael@0 1487 "onInstallCancelled"
michael@0 1488 ]);
michael@0 1489
michael@0 1490 aInstall.cancel();
michael@0 1491
michael@0 1492 ensure_test_completed();
michael@0 1493
michael@0 1494 run_test_24();
michael@0 1495 }
michael@0 1496
michael@0 1497 // Tests that an install with a bad hash can be restarted after it fails, though
michael@0 1498 // it will only fail again
michael@0 1499 function run_test_24() {
michael@0 1500 prepare_test({ }, [
michael@0 1501 "onNewInstall"
michael@0 1502 ]);
michael@0 1503
michael@0 1504 let url = "http://localhost:" + gPort + "/addons/test_install3.xpi";
michael@0 1505 AddonManager.getInstallForURL(url, function(aInstall) {
michael@0 1506 ensure_test_completed();
michael@0 1507
michael@0 1508 do_check_neq(aInstall, null);
michael@0 1509 do_check_eq(aInstall.state, AddonManager.STATE_AVAILABLE);
michael@0 1510
michael@0 1511 prepare_test({}, [
michael@0 1512 "onDownloadStarted",
michael@0 1513 "onDownloadFailed",
michael@0 1514 ], check_test_24);
michael@0 1515 aInstall.install();
michael@0 1516 }, "application/x-xpinstall", "sha1:foo");
michael@0 1517 }
michael@0 1518
michael@0 1519 function check_test_24(aInstall) {
michael@0 1520 prepare_test({ }, [
michael@0 1521 "onDownloadStarted",
michael@0 1522 "onDownloadFailed"
michael@0 1523 ], run_test_25);
michael@0 1524
michael@0 1525 aInstall.install();
michael@0 1526 }
michael@0 1527
michael@0 1528 // Tests that installs with a hash for a local file work
michael@0 1529 function run_test_25() {
michael@0 1530 prepare_test({ }, [
michael@0 1531 "onNewInstall"
michael@0 1532 ]);
michael@0 1533
michael@0 1534 let url = Services.io.newFileURI(do_get_addon("test_install3")).spec;
michael@0 1535 AddonManager.getInstallForURL(url, function(aInstall) {
michael@0 1536 ensure_test_completed();
michael@0 1537
michael@0 1538 do_check_neq(aInstall, null);
michael@0 1539 do_check_eq(aInstall.state, AddonManager.STATE_DOWNLOADED);
michael@0 1540 do_check_eq(aInstall.error, 0);
michael@0 1541
michael@0 1542 prepare_test({ }, [
michael@0 1543 "onDownloadCancelled"
michael@0 1544 ]);
michael@0 1545
michael@0 1546 aInstall.cancel();
michael@0 1547
michael@0 1548 ensure_test_completed();
michael@0 1549
michael@0 1550 run_test_26();
michael@0 1551 }, "application/x-xpinstall", do_get_addon_hash("test_install3"));
michael@0 1552 }
michael@0 1553
michael@0 1554 function run_test_26() {
michael@0 1555 prepare_test({ }, [
michael@0 1556 "onNewInstall",
michael@0 1557 "onDownloadStarted",
michael@0 1558 "onDownloadCancelled"
michael@0 1559 ]);
michael@0 1560
michael@0 1561 let observerService = AM_Cc["@mozilla.org/network/http-activity-distributor;1"].
michael@0 1562 getService(AM_Ci.nsIHttpActivityDistributor);
michael@0 1563 observerService.addObserver({
michael@0 1564 observeActivity: function(aChannel, aType, aSubtype, aTimestamp, aSizeData,
michael@0 1565 aStringData) {
michael@0 1566 aChannel.QueryInterface(AM_Ci.nsIChannel);
michael@0 1567 // Wait for the final event for the redirected URL
michael@0 1568 if (aChannel.URI.spec != "http://localhost:" + gPort + "/addons/test_install1.xpi" ||
michael@0 1569 aType != AM_Ci.nsIHttpActivityObserver.ACTIVITY_TYPE_HTTP_TRANSACTION ||
michael@0 1570 aSubtype != AM_Ci.nsIHttpActivityObserver.ACTIVITY_SUBTYPE_TRANSACTION_CLOSE)
michael@0 1571 return;
michael@0 1572
michael@0 1573 // Request should have been cancelled
michael@0 1574 do_check_eq(aChannel.status, Components.results.NS_BINDING_ABORTED);
michael@0 1575
michael@0 1576 observerService.removeObserver(this);
michael@0 1577
michael@0 1578 run_test_27();
michael@0 1579 }
michael@0 1580 });
michael@0 1581
michael@0 1582 let url = "http://localhost:" + gPort + "/redirect?/addons/test_install1.xpi";
michael@0 1583 AddonManager.getInstallForURL(url, function(aInstall) {
michael@0 1584 aInstall.addListener({
michael@0 1585 onDownloadProgress: function(aInstall) {
michael@0 1586 aInstall.cancel();
michael@0 1587 }
michael@0 1588 });
michael@0 1589
michael@0 1590 aInstall.install();
michael@0 1591 }, "application/x-xpinstall");
michael@0 1592 }
michael@0 1593
michael@0 1594
michael@0 1595 // Tests that an install can be restarted during onDownloadCancelled after being
michael@0 1596 // cancelled in mid-download
michael@0 1597 function run_test_27() {
michael@0 1598 prepare_test({ }, [
michael@0 1599 "onNewInstall"
michael@0 1600 ]);
michael@0 1601
michael@0 1602 let url = "http://localhost:" + gPort + "/addons/test_install3.xpi";
michael@0 1603 AddonManager.getInstallForURL(url, function(aInstall) {
michael@0 1604 ensure_test_completed();
michael@0 1605
michael@0 1606 do_check_neq(aInstall, null);
michael@0 1607 do_check_eq(aInstall.state, AddonManager.STATE_AVAILABLE);
michael@0 1608
michael@0 1609 aInstall.addListener({
michael@0 1610 onDownloadProgress: function() {
michael@0 1611 aInstall.removeListener(this);
michael@0 1612 aInstall.cancel();
michael@0 1613 }
michael@0 1614 });
michael@0 1615
michael@0 1616 prepare_test({}, [
michael@0 1617 "onDownloadStarted",
michael@0 1618 "onDownloadCancelled",
michael@0 1619 ], check_test_27);
michael@0 1620 aInstall.install();
michael@0 1621 }, "application/x-xpinstall");
michael@0 1622 }
michael@0 1623
michael@0 1624 function check_test_27(aInstall) {
michael@0 1625 prepare_test({
michael@0 1626 "addon3@tests.mozilla.org": [
michael@0 1627 "onInstalling"
michael@0 1628 ]
michael@0 1629 }, [
michael@0 1630 "onDownloadStarted",
michael@0 1631 "onDownloadEnded",
michael@0 1632 "onInstallStarted",
michael@0 1633 "onInstallEnded"
michael@0 1634 ], finish_test_27);
michael@0 1635
michael@0 1636 aInstall.install();
michael@0 1637 }
michael@0 1638
michael@0 1639 function finish_test_27(aInstall) {
michael@0 1640 prepare_test({
michael@0 1641 "addon3@tests.mozilla.org": [
michael@0 1642 "onOperationCancelled"
michael@0 1643 ]
michael@0 1644 }, [
michael@0 1645 "onInstallCancelled"
michael@0 1646 ]);
michael@0 1647
michael@0 1648 aInstall.cancel();
michael@0 1649
michael@0 1650 ensure_test_completed();
michael@0 1651
michael@0 1652 run_test_28();
michael@0 1653 }
michael@0 1654
michael@0 1655 // Tests that an install that isn't strictly compatible and has
michael@0 1656 // binary components correctly has appDisabled set (see bug 702868).
michael@0 1657 function run_test_28() {
michael@0 1658 prepare_test({ }, [
michael@0 1659 "onNewInstall"
michael@0 1660 ]);
michael@0 1661
michael@0 1662 let url = "http://localhost:" + gPort + "/addons/test_install5.xpi";
michael@0 1663 AddonManager.getInstallForURL(url, function(install) {
michael@0 1664 ensure_test_completed();
michael@0 1665
michael@0 1666 do_check_neq(install, null);
michael@0 1667 do_check_eq(install.version, "1.0");
michael@0 1668 do_check_eq(install.name, "Real Test 5");
michael@0 1669 do_check_eq(install.state, AddonManager.STATE_AVAILABLE);
michael@0 1670
michael@0 1671 AddonManager.getInstallsByTypes(null, function(activeInstalls) {
michael@0 1672 do_check_eq(activeInstalls.length, 1);
michael@0 1673 do_check_eq(activeInstalls[0], install);
michael@0 1674
michael@0 1675 prepare_test({}, [
michael@0 1676 "onDownloadStarted",
michael@0 1677 "onDownloadEnded",
michael@0 1678 "onInstallStarted"
michael@0 1679 ], check_test_28);
michael@0 1680 install.install();
michael@0 1681 });
michael@0 1682 }, "application/x-xpinstall", null, "Real Test 5", null, "1.0");
michael@0 1683 }
michael@0 1684
michael@0 1685 function check_test_28(install) {
michael@0 1686 ensure_test_completed();
michael@0 1687 do_check_eq(install.version, "1.0");
michael@0 1688 do_check_eq(install.name, "Real Test 5");
michael@0 1689 do_check_eq(install.state, AddonManager.STATE_INSTALLING);
michael@0 1690 do_check_eq(install.existingAddon, null);
michael@0 1691 do_check_false(install.addon.isCompatible);
michael@0 1692 do_check_true(install.addon.appDisabled);
michael@0 1693
michael@0 1694 prepare_test({}, [
michael@0 1695 "onInstallCancelled"
michael@0 1696 ], finish_test_28);
michael@0 1697 return false;
michael@0 1698 }
michael@0 1699
michael@0 1700 function finish_test_28(install) {
michael@0 1701 prepare_test({}, [
michael@0 1702 "onDownloadCancelled"
michael@0 1703 ], run_test_29);
michael@0 1704
michael@0 1705 install.cancel();
michael@0 1706 }
michael@0 1707
michael@0 1708 // Tests that an install with a matching compatibility override has appDisabled
michael@0 1709 // set correctly.
michael@0 1710 function run_test_29() {
michael@0 1711 Services.prefs.setBoolPref("extensions.getAddons.cache.enabled", true);
michael@0 1712
michael@0 1713 prepare_test({ }, [
michael@0 1714 "onNewInstall"
michael@0 1715 ]);
michael@0 1716
michael@0 1717 let url = "http://localhost:" + gPort + "/addons/test_install6.xpi";
michael@0 1718 AddonManager.getInstallForURL(url, function(install) {
michael@0 1719 ensure_test_completed();
michael@0 1720
michael@0 1721 do_check_neq(install, null);
michael@0 1722 do_check_eq(install.version, "1.0");
michael@0 1723 do_check_eq(install.name, "Addon Test 6");
michael@0 1724 do_check_eq(install.state, AddonManager.STATE_AVAILABLE);
michael@0 1725
michael@0 1726 AddonManager.getInstallsByTypes(null, function(activeInstalls) {
michael@0 1727 do_check_eq(activeInstalls.length, 1);
michael@0 1728 do_check_eq(activeInstalls[0], install);
michael@0 1729
michael@0 1730 prepare_test({}, [
michael@0 1731 "onDownloadStarted",
michael@0 1732 "onDownloadEnded"
michael@0 1733 ], check_test_29);
michael@0 1734 install.install();
michael@0 1735 });
michael@0 1736 }, "application/x-xpinstall", null, "Addon Test 6", null, "1.0");
michael@0 1737 }
michael@0 1738
michael@0 1739 function check_test_29(install) {
michael@0 1740 //ensure_test_completed();
michael@0 1741 do_check_eq(install.state, AddonManager.STATE_DOWNLOADED);
michael@0 1742 do_check_neq(install.addon, null);
michael@0 1743 do_check_false(install.addon.isCompatible);
michael@0 1744 do_check_true(install.addon.appDisabled);
michael@0 1745
michael@0 1746 prepare_test({}, [
michael@0 1747 "onDownloadCancelled"
michael@0 1748 ], do_test_finished);
michael@0 1749 install.cancel();
michael@0 1750 return false;
michael@0 1751 }

mercurial