browser/base/content/test/general/browser_bug553455.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 const TESTROOT = "http://example.com/browser/toolkit/mozapps/extensions/test/xpinstall/";
michael@0 6 const TESTROOT2 = "http://example.org/browser/toolkit/mozapps/extensions/test/xpinstall/";
michael@0 7 const SECUREROOT = "https://example.com/browser/toolkit/mozapps/extensions/test/xpinstall/";
michael@0 8 const XPINSTALL_URL = "chrome://mozapps/content/xpinstall/xpinstallConfirm.xul";
michael@0 9 const PREF_INSTALL_REQUIREBUILTINCERTS = "extensions.install.requireBuiltInCerts";
michael@0 10
michael@0 11 var rootDir = getRootDirectory(gTestPath);
michael@0 12 var path = rootDir.split('/');
michael@0 13 var chromeName = path[0] + '//' + path[2];
michael@0 14 var croot = chromeName + "/content/browser/toolkit/mozapps/extensions/test/xpinstall/";
michael@0 15 var jar = getJar(croot);
michael@0 16 if (jar) {
michael@0 17 var tmpdir = extractJarToTmp(jar);
michael@0 18 croot = 'file://' + tmpdir.path + '/';
michael@0 19 }
michael@0 20 const CHROMEROOT = croot;
michael@0 21
michael@0 22 var gApp = document.getElementById("bundle_brand").getString("brandShortName");
michael@0 23 var gVersion = Services.appinfo.version;
michael@0 24 var check_notification;
michael@0 25
michael@0 26 function wait_for_notification(aCallback) {
michael@0 27 info("Waiting for notification");
michael@0 28 check_notification = function() {
michael@0 29 PopupNotifications.panel.removeEventListener("popupshown", check_notification, false);
michael@0 30 info("Saw notification");
michael@0 31 is(PopupNotifications.panel.childNodes.length, 1, "Should be only one notification");
michael@0 32 aCallback(PopupNotifications.panel);
michael@0 33 };
michael@0 34 PopupNotifications.panel.addEventListener("popupshown", check_notification, false);
michael@0 35 }
michael@0 36
michael@0 37 function wait_for_notification_close(aCallback) {
michael@0 38 info("Waiting for notification to close");
michael@0 39 PopupNotifications.panel.addEventListener("popuphidden", function() {
michael@0 40 PopupNotifications.panel.removeEventListener("popuphidden", arguments.callee, false);
michael@0 41 aCallback();
michael@0 42 }, false);
michael@0 43 }
michael@0 44
michael@0 45 function wait_for_install_dialog(aCallback) {
michael@0 46 info("Waiting for install dialog");
michael@0 47 Services.wm.addListener({
michael@0 48 onOpenWindow: function(aXULWindow) {
michael@0 49 info("Install dialog opened, waiting for focus");
michael@0 50 Services.wm.removeListener(this);
michael@0 51
michael@0 52 var domwindow = aXULWindow.QueryInterface(Ci.nsIInterfaceRequestor)
michael@0 53 .getInterface(Ci.nsIDOMWindow);
michael@0 54 waitForFocus(function() {
michael@0 55 info("Saw install dialog");
michael@0 56 is(domwindow.document.location.href, XPINSTALL_URL, "Should have seen the right window open");
michael@0 57
michael@0 58 // Override the countdown timer on the accept button
michael@0 59 var button = domwindow.document.documentElement.getButton("accept");
michael@0 60 button.disabled = false;
michael@0 61
michael@0 62 aCallback(domwindow);
michael@0 63 }, domwindow);
michael@0 64 },
michael@0 65
michael@0 66 onCloseWindow: function(aXULWindow) {
michael@0 67 },
michael@0 68
michael@0 69 onWindowTitleChange: function(aXULWindow, aNewTitle) {
michael@0 70 }
michael@0 71 });
michael@0 72 }
michael@0 73
michael@0 74 function wait_for_single_notification(aCallback) {
michael@0 75 function inner_waiter() {
michael@0 76 info("Waiting for single notification");
michael@0 77 // Notification should never close while we wait
michael@0 78 ok(PopupNotifications.isPanelOpen, "Notification should still be open");
michael@0 79 if (PopupNotifications.panel.childNodes.length == 2) {
michael@0 80 executeSoon(inner_waiter);
michael@0 81 return;
michael@0 82 }
michael@0 83
michael@0 84 aCallback();
michael@0 85 }
michael@0 86
michael@0 87 executeSoon(inner_waiter);
michael@0 88 }
michael@0 89
michael@0 90 function setup_redirect(aSettings) {
michael@0 91 var url = "https://example.com/browser/toolkit/mozapps/extensions/test/xpinstall/redirect.sjs?mode=setup";
michael@0 92 for (var name in aSettings) {
michael@0 93 url += "&" + name + "=" + aSettings[name];
michael@0 94 }
michael@0 95
michael@0 96 var req = new XMLHttpRequest();
michael@0 97 req.open("GET", url, false);
michael@0 98 req.send(null);
michael@0 99 }
michael@0 100
michael@0 101 var TESTS = [
michael@0 102 function test_disabled_install() {
michael@0 103 Services.prefs.setBoolPref("xpinstall.enabled", false);
michael@0 104
michael@0 105 // Wait for the disabled notification
michael@0 106 wait_for_notification(function(aPanel) {
michael@0 107 let notification = aPanel.childNodes[0];
michael@0 108 is(notification.id, "xpinstall-disabled-notification", "Should have seen installs disabled");
michael@0 109 is(notification.button.label, "Enable", "Should have seen the right button");
michael@0 110 is(notification.getAttribute("label"),
michael@0 111 "Software installation is currently disabled. Click Enable and try again.");
michael@0 112
michael@0 113 wait_for_notification_close(function() {
michael@0 114 try {
michael@0 115 ok(Services.prefs.getBoolPref("xpinstall.enabled"), "Installation should be enabled");
michael@0 116 }
michael@0 117 catch (e) {
michael@0 118 ok(false, "xpinstall.enabled should be set");
michael@0 119 }
michael@0 120
michael@0 121 gBrowser.removeTab(gBrowser.selectedTab);
michael@0 122
michael@0 123 AddonManager.getAllInstalls(function(aInstalls) {
michael@0 124 is(aInstalls.length, 1, "Should have been one install created");
michael@0 125 aInstalls[0].cancel();
michael@0 126
michael@0 127 runNextTest();
michael@0 128 });
michael@0 129 });
michael@0 130
michael@0 131 // Click on Enable
michael@0 132 EventUtils.synthesizeMouseAtCenter(notification.button, {});
michael@0 133 });
michael@0 134
michael@0 135 var triggers = encodeURIComponent(JSON.stringify({
michael@0 136 "XPI": "unsigned.xpi"
michael@0 137 }));
michael@0 138 gBrowser.selectedTab = gBrowser.addTab();
michael@0 139 gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
michael@0 140 },
michael@0 141
michael@0 142 function test_blocked_install() {
michael@0 143 // Wait for the blocked notification
michael@0 144 wait_for_notification(function(aPanel) {
michael@0 145 let notification = aPanel.childNodes[0];
michael@0 146 is(notification.id, "addon-install-blocked-notification", "Should have seen the install blocked");
michael@0 147 is(notification.button.label, "Allow", "Should have seen the right button");
michael@0 148 is(notification.getAttribute("label"),
michael@0 149 gApp + " prevented this site (example.com) from asking you to install " +
michael@0 150 "software on your computer.",
michael@0 151 "Should have seen the right message");
michael@0 152
michael@0 153 // Wait for the install confirmation dialog
michael@0 154 wait_for_install_dialog(function(aWindow) {
michael@0 155 // Wait for the complete notification
michael@0 156 wait_for_notification(function(aPanel) {
michael@0 157 let notification = aPanel.childNodes[0];
michael@0 158 is(notification.id, "addon-install-complete-notification", "Should have seen the install complete");
michael@0 159 is(notification.button.label, "Restart Now", "Should have seen the right button");
michael@0 160 is(notification.getAttribute("label"),
michael@0 161 "XPI Test will be installed after you restart " + gApp + ".",
michael@0 162 "Should have seen the right message");
michael@0 163
michael@0 164 AddonManager.getAllInstalls(function(aInstalls) {
michael@0 165 is(aInstalls.length, 1, "Should be one pending install");
michael@0 166 aInstalls[0].cancel();
michael@0 167
michael@0 168 wait_for_notification_close(runNextTest);
michael@0 169 gBrowser.removeTab(gBrowser.selectedTab);
michael@0 170 });
michael@0 171 });
michael@0 172
michael@0 173 aWindow.document.documentElement.acceptDialog();
michael@0 174 });
michael@0 175
michael@0 176 // Click on Allow
michael@0 177 EventUtils.synthesizeMouse(notification.button, 20, 10, {});
michael@0 178
michael@0 179 // Notification should have changed to progress notification
michael@0 180 ok(PopupNotifications.isPanelOpen, "Notification should still be open");
michael@0 181 notification = aPanel.childNodes[0];
michael@0 182 is(notification.id, "addon-progress-notification", "Should have seen the progress notification");
michael@0 183
michael@0 184 });
michael@0 185
michael@0 186 var triggers = encodeURIComponent(JSON.stringify({
michael@0 187 "XPI": "unsigned.xpi"
michael@0 188 }));
michael@0 189 gBrowser.selectedTab = gBrowser.addTab();
michael@0 190 gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
michael@0 191 },
michael@0 192
michael@0 193 function test_whitelisted_install() {
michael@0 194 // Wait for the progress notification
michael@0 195 wait_for_notification(function(aPanel) {
michael@0 196 let notification = aPanel.childNodes[0];
michael@0 197 is(notification.id, "addon-progress-notification", "Should have seen the progress notification");
michael@0 198
michael@0 199 // Wait for the install confirmation dialog
michael@0 200 wait_for_install_dialog(function(aWindow) {
michael@0 201 // Wait for the complete notification
michael@0 202 wait_for_notification(function(aPanel) {
michael@0 203 let notification = aPanel.childNodes[0];
michael@0 204 is(notification.id, "addon-install-complete-notification", "Should have seen the install complete");
michael@0 205 is(notification.button.label, "Restart Now", "Should have seen the right button");
michael@0 206 is(notification.getAttribute("label"),
michael@0 207 "XPI Test will be installed after you restart " + gApp + ".",
michael@0 208 "Should have seen the right message");
michael@0 209
michael@0 210 AddonManager.getAllInstalls(function(aInstalls) {
michael@0 211 is(aInstalls.length, 1, "Should be one pending install");
michael@0 212 aInstalls[0].cancel();
michael@0 213
michael@0 214 Services.perms.remove("example.com", "install");
michael@0 215 wait_for_notification_close(runNextTest);
michael@0 216 gBrowser.removeTab(gBrowser.selectedTab);
michael@0 217 });
michael@0 218 });
michael@0 219
michael@0 220 aWindow.document.documentElement.acceptDialog();
michael@0 221 });
michael@0 222 });
michael@0 223
michael@0 224 var pm = Services.perms;
michael@0 225 pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
michael@0 226
michael@0 227 var triggers = encodeURIComponent(JSON.stringify({
michael@0 228 "XPI": "unsigned.xpi"
michael@0 229 }));
michael@0 230 gBrowser.selectedTab = gBrowser.addTab();
michael@0 231 gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
michael@0 232 },
michael@0 233
michael@0 234 function test_failed_download() {
michael@0 235 // Wait for the progress notification
michael@0 236 wait_for_notification(function(aPanel) {
michael@0 237 let notification = aPanel.childNodes[0];
michael@0 238 is(notification.id, "addon-progress-notification", "Should have seen the progress notification");
michael@0 239
michael@0 240 // Wait for the failed notification
michael@0 241 wait_for_notification(function(aPanel) {
michael@0 242 let notification = aPanel.childNodes[0];
michael@0 243 is(notification.id, "addon-install-failed-notification", "Should have seen the install fail");
michael@0 244 is(notification.getAttribute("label"),
michael@0 245 "The add-on could not be downloaded because of a connection failure " +
michael@0 246 "on example.com.",
michael@0 247 "Should have seen the right message");
michael@0 248
michael@0 249 Services.perms.remove("example.com", "install");
michael@0 250 wait_for_notification_close(runNextTest);
michael@0 251 gBrowser.removeTab(gBrowser.selectedTab);
michael@0 252 });
michael@0 253 });
michael@0 254
michael@0 255 var pm = Services.perms;
michael@0 256 pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
michael@0 257
michael@0 258 var triggers = encodeURIComponent(JSON.stringify({
michael@0 259 "XPI": "missing.xpi"
michael@0 260 }));
michael@0 261 gBrowser.selectedTab = gBrowser.addTab();
michael@0 262 gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
michael@0 263 },
michael@0 264
michael@0 265 function test_corrupt_file() {
michael@0 266 // Wait for the progress notification
michael@0 267 wait_for_notification(function(aPanel) {
michael@0 268 let notification = aPanel.childNodes[0];
michael@0 269 is(notification.id, "addon-progress-notification", "Should have seen the progress notification");
michael@0 270
michael@0 271 // Wait for the failed notification
michael@0 272 wait_for_notification(function(aPanel) {
michael@0 273 let notification = aPanel.childNodes[0];
michael@0 274 is(notification.id, "addon-install-failed-notification", "Should have seen the install fail");
michael@0 275 is(notification.getAttribute("label"),
michael@0 276 "The add-on downloaded from example.com could not be installed " +
michael@0 277 "because it appears to be corrupt.",
michael@0 278 "Should have seen the right message");
michael@0 279
michael@0 280 Services.perms.remove("example.com", "install");
michael@0 281 wait_for_notification_close(runNextTest);
michael@0 282 gBrowser.removeTab(gBrowser.selectedTab);
michael@0 283 });
michael@0 284 });
michael@0 285
michael@0 286 var pm = Services.perms;
michael@0 287 pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
michael@0 288
michael@0 289 var triggers = encodeURIComponent(JSON.stringify({
michael@0 290 "XPI": "corrupt.xpi"
michael@0 291 }));
michael@0 292 gBrowser.selectedTab = gBrowser.addTab();
michael@0 293 gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
michael@0 294 },
michael@0 295
michael@0 296 function test_incompatible() {
michael@0 297 // Wait for the progress notification
michael@0 298 wait_for_notification(function(aPanel) {
michael@0 299 let notification = aPanel.childNodes[0];
michael@0 300 is(notification.id, "addon-progress-notification", "Should have seen the progress notification");
michael@0 301
michael@0 302 // Wait for the failed notification
michael@0 303 wait_for_notification(function(aPanel) {
michael@0 304 let notification = aPanel.childNodes[0];
michael@0 305 is(notification.id, "addon-install-failed-notification", "Should have seen the install fail");
michael@0 306 is(notification.getAttribute("label"),
michael@0 307 "XPI Test could not be installed because it is not compatible with " +
michael@0 308 gApp + " " + gVersion + ".",
michael@0 309 "Should have seen the right message");
michael@0 310
michael@0 311 Services.perms.remove("example.com", "install");
michael@0 312 wait_for_notification_close(runNextTest);
michael@0 313 gBrowser.removeTab(gBrowser.selectedTab);
michael@0 314 });
michael@0 315 });
michael@0 316
michael@0 317 var pm = Services.perms;
michael@0 318 pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
michael@0 319
michael@0 320 var triggers = encodeURIComponent(JSON.stringify({
michael@0 321 "XPI": "incompatible.xpi"
michael@0 322 }));
michael@0 323 gBrowser.selectedTab = gBrowser.addTab();
michael@0 324 gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
michael@0 325 },
michael@0 326
michael@0 327 function test_restartless() {
michael@0 328 // Wait for the progress notification
michael@0 329 wait_for_notification(function(aPanel) {
michael@0 330 let notification = aPanel.childNodes[0];
michael@0 331 is(notification.id, "addon-progress-notification", "Should have seen the progress notification");
michael@0 332
michael@0 333 // Wait for the install confirmation dialog
michael@0 334 wait_for_install_dialog(function(aWindow) {
michael@0 335 // Wait for the complete notification
michael@0 336 wait_for_notification(function(aPanel) {
michael@0 337 let notification = aPanel.childNodes[0];
michael@0 338 is(notification.id, "addon-install-complete-notification", "Should have seen the install complete");
michael@0 339 is(notification.getAttribute("label"),
michael@0 340 "XPI Test has been installed successfully.",
michael@0 341 "Should have seen the right message");
michael@0 342
michael@0 343 AddonManager.getAllInstalls(function(aInstalls) {
michael@0 344 is(aInstalls.length, 0, "Should be no pending installs");
michael@0 345
michael@0 346 AddonManager.getAddonByID("restartless-xpi@tests.mozilla.org", function(aAddon) {
michael@0 347 aAddon.uninstall();
michael@0 348
michael@0 349 Services.perms.remove("example.com", "install");
michael@0 350 wait_for_notification_close(runNextTest);
michael@0 351 gBrowser.removeTab(gBrowser.selectedTab);
michael@0 352 });
michael@0 353 });
michael@0 354 });
michael@0 355
michael@0 356 aWindow.document.documentElement.acceptDialog();
michael@0 357 });
michael@0 358 });
michael@0 359
michael@0 360 var pm = Services.perms;
michael@0 361 pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
michael@0 362
michael@0 363 var triggers = encodeURIComponent(JSON.stringify({
michael@0 364 "XPI": "restartless.xpi"
michael@0 365 }));
michael@0 366 gBrowser.selectedTab = gBrowser.addTab();
michael@0 367 gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
michael@0 368 },
michael@0 369
michael@0 370 function test_multiple() {
michael@0 371 // Wait for the progress notification
michael@0 372 wait_for_notification(function(aPanel) {
michael@0 373 let notification = aPanel.childNodes[0];
michael@0 374 is(notification.id, "addon-progress-notification", "Should have seen the progress notification");
michael@0 375
michael@0 376 // Wait for the install confirmation dialog
michael@0 377 wait_for_install_dialog(function(aWindow) {
michael@0 378 // Wait for the complete notification
michael@0 379 wait_for_notification(function(aPanel) {
michael@0 380 let notification = aPanel.childNodes[0];
michael@0 381 is(notification.id, "addon-install-complete-notification", "Should have seen the install complete");
michael@0 382 is(notification.button.label, "Restart Now", "Should have seen the right button");
michael@0 383 is(notification.getAttribute("label"),
michael@0 384 "2 add-ons will be installed after you restart " + gApp + ".",
michael@0 385 "Should have seen the right message");
michael@0 386
michael@0 387 AddonManager.getAllInstalls(function(aInstalls) {
michael@0 388 is(aInstalls.length, 1, "Should be one pending install");
michael@0 389 aInstalls[0].cancel();
michael@0 390
michael@0 391 AddonManager.getAddonByID("restartless-xpi@tests.mozilla.org", function(aAddon) {
michael@0 392 aAddon.uninstall();
michael@0 393
michael@0 394 Services.perms.remove("example.com", "install");
michael@0 395 wait_for_notification_close(runNextTest);
michael@0 396 gBrowser.removeTab(gBrowser.selectedTab);
michael@0 397 });
michael@0 398 });
michael@0 399 });
michael@0 400
michael@0 401 aWindow.document.documentElement.acceptDialog();
michael@0 402 });
michael@0 403 });
michael@0 404
michael@0 405 var pm = Services.perms;
michael@0 406 pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
michael@0 407
michael@0 408 var triggers = encodeURIComponent(JSON.stringify({
michael@0 409 "Unsigned XPI": "unsigned.xpi",
michael@0 410 "Restartless XPI": "restartless.xpi"
michael@0 411 }));
michael@0 412 gBrowser.selectedTab = gBrowser.addTab();
michael@0 413 gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
michael@0 414 },
michael@0 415
michael@0 416 function test_url() {
michael@0 417 // Wait for the progress notification
michael@0 418 wait_for_notification(function(aPanel) {
michael@0 419 let notification = aPanel.childNodes[0];
michael@0 420 is(notification.id, "addon-progress-notification", "Should have seen the progress notification");
michael@0 421
michael@0 422 // Wait for the install confirmation dialog
michael@0 423 wait_for_install_dialog(function(aWindow) {
michael@0 424 // Wait for the complete notification
michael@0 425 wait_for_notification(function(aPanel) {
michael@0 426 let notification = aPanel.childNodes[0];
michael@0 427 is(notification.id, "addon-install-complete-notification", "Should have seen the install complete");
michael@0 428 is(notification.button.label, "Restart Now", "Should have seen the right button");
michael@0 429 is(notification.getAttribute("label"),
michael@0 430 "XPI Test will be installed after you restart " + gApp + ".",
michael@0 431 "Should have seen the right message");
michael@0 432
michael@0 433 AddonManager.getAllInstalls(function(aInstalls) {
michael@0 434 is(aInstalls.length, 1, "Should be one pending install");
michael@0 435 aInstalls[0].cancel();
michael@0 436
michael@0 437 wait_for_notification_close(runNextTest);
michael@0 438 gBrowser.removeTab(gBrowser.selectedTab);
michael@0 439 });
michael@0 440 });
michael@0 441
michael@0 442 aWindow.document.documentElement.acceptDialog();
michael@0 443 });
michael@0 444 });
michael@0 445
michael@0 446 gBrowser.selectedTab = gBrowser.addTab();
michael@0 447 gBrowser.loadURI(TESTROOT + "unsigned.xpi");
michael@0 448 },
michael@0 449
michael@0 450 function test_localfile() {
michael@0 451 // Wait for the install to fail
michael@0 452 Services.obs.addObserver(function() {
michael@0 453 Services.obs.removeObserver(arguments.callee, "addon-install-failed");
michael@0 454
michael@0 455 // Wait for the browser code to add the failure notification
michael@0 456 wait_for_single_notification(function() {
michael@0 457 let notification = PopupNotifications.panel.childNodes[0];
michael@0 458 is(notification.id, "addon-install-failed-notification", "Should have seen the install fail");
michael@0 459 is(notification.getAttribute("label"),
michael@0 460 "This add-on could not be installed because it appears to be corrupt.",
michael@0 461 "Should have seen the right message");
michael@0 462
michael@0 463 wait_for_notification_close(runNextTest);
michael@0 464 gBrowser.removeTab(gBrowser.selectedTab);
michael@0 465 });
michael@0 466 }, "addon-install-failed", false);
michael@0 467
michael@0 468 var cr = Components.classes["@mozilla.org/chrome/chrome-registry;1"]
michael@0 469 .getService(Components.interfaces.nsIChromeRegistry);
michael@0 470 try {
michael@0 471 var path = cr.convertChromeURL(makeURI(CHROMEROOT + "corrupt.xpi")).spec;
michael@0 472 } catch (ex) {
michael@0 473 var path = CHROMEROOT + "corrupt.xpi";
michael@0 474 }
michael@0 475 gBrowser.selectedTab = gBrowser.addTab();
michael@0 476 gBrowser.loadURI(path);
michael@0 477 },
michael@0 478
michael@0 479 function test_wronghost() {
michael@0 480 gBrowser.selectedTab = gBrowser.addTab();
michael@0 481 gBrowser.addEventListener("load", function() {
michael@0 482 if (gBrowser.currentURI.spec != TESTROOT2 + "enabled.html")
michael@0 483 return;
michael@0 484
michael@0 485 gBrowser.removeEventListener("load", arguments.callee, true);
michael@0 486
michael@0 487 // Wait for the progress notification
michael@0 488 wait_for_notification(function(aPanel) {
michael@0 489 let notification = aPanel.childNodes[0];
michael@0 490 is(notification.id, "addon-progress-notification", "Should have seen the progress notification");
michael@0 491 // Wait for the complete notification
michael@0 492 wait_for_notification(function(aPanel) {
michael@0 493 let notification = aPanel.childNodes[0];
michael@0 494 is(notification.id, "addon-install-failed-notification", "Should have seen the install fail");
michael@0 495 is(notification.getAttribute("label"),
michael@0 496 "The add-on downloaded from example.com could not be installed " +
michael@0 497 "because it appears to be corrupt.",
michael@0 498 "Should have seen the right message");
michael@0 499
michael@0 500 wait_for_notification_close(runNextTest);
michael@0 501 gBrowser.removeTab(gBrowser.selectedTab);
michael@0 502 });
michael@0 503 });
michael@0 504
michael@0 505 gBrowser.loadURI(TESTROOT + "corrupt.xpi");
michael@0 506 }, true);
michael@0 507 gBrowser.loadURI(TESTROOT2 + "enabled.html");
michael@0 508 },
michael@0 509
michael@0 510 function test_reload() {
michael@0 511 // Wait for the progress notification
michael@0 512 wait_for_notification(function(aPanel) {
michael@0 513 let notification = aPanel.childNodes[0];
michael@0 514 is(notification.id, "addon-progress-notification", "Should have seen the progress notification");
michael@0 515
michael@0 516 // Wait for the install confirmation dialog
michael@0 517 wait_for_install_dialog(function(aWindow) {
michael@0 518 // Wait for the complete notification
michael@0 519 wait_for_notification(function(aPanel) {
michael@0 520 let notification = aPanel.childNodes[0];
michael@0 521 is(notification.id, "addon-install-complete-notification", "Should have seen the install complete");
michael@0 522 is(notification.button.label, "Restart Now", "Should have seen the right button");
michael@0 523 is(notification.getAttribute("label"),
michael@0 524 "XPI Test will be installed after you restart " + gApp + ".",
michael@0 525 "Should have seen the right message");
michael@0 526
michael@0 527 function test_fail() {
michael@0 528 ok(false, "Reloading should not have hidden the notification");
michael@0 529 }
michael@0 530
michael@0 531 PopupNotifications.panel.addEventListener("popuphiding", test_fail, false);
michael@0 532
michael@0 533 gBrowser.addEventListener("load", function() {
michael@0 534 if (gBrowser.currentURI.spec != TESTROOT2 + "enabled.html")
michael@0 535 return;
michael@0 536
michael@0 537 gBrowser.removeEventListener("load", arguments.callee, true);
michael@0 538
michael@0 539 PopupNotifications.panel.removeEventListener("popuphiding", test_fail, false);
michael@0 540
michael@0 541 AddonManager.getAllInstalls(function(aInstalls) {
michael@0 542 is(aInstalls.length, 1, "Should be one pending install");
michael@0 543 aInstalls[0].cancel();
michael@0 544
michael@0 545 Services.perms.remove("example.com", "install");
michael@0 546 wait_for_notification_close(runNextTest);
michael@0 547 gBrowser.removeTab(gBrowser.selectedTab);
michael@0 548 });
michael@0 549 }, true);
michael@0 550 gBrowser.loadURI(TESTROOT2 + "enabled.html");
michael@0 551 });
michael@0 552
michael@0 553 aWindow.document.documentElement.acceptDialog();
michael@0 554 });
michael@0 555 });
michael@0 556
michael@0 557 var pm = Services.perms;
michael@0 558 pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
michael@0 559
michael@0 560 var triggers = encodeURIComponent(JSON.stringify({
michael@0 561 "Unsigned XPI": "unsigned.xpi"
michael@0 562 }));
michael@0 563 gBrowser.selectedTab = gBrowser.addTab();
michael@0 564 gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
michael@0 565 },
michael@0 566
michael@0 567 function test_theme() {
michael@0 568 // Wait for the progress notification
michael@0 569 wait_for_notification(function(aPanel) {
michael@0 570 let notification = aPanel.childNodes[0];
michael@0 571 is(notification.id, "addon-progress-notification", "Should have seen the progress notification");
michael@0 572
michael@0 573 // Wait for the install confirmation dialog
michael@0 574 wait_for_install_dialog(function(aWindow) {
michael@0 575 // Wait for the complete notification
michael@0 576 wait_for_notification(function(aPanel) {
michael@0 577 let notification = aPanel.childNodes[0];
michael@0 578 is(notification.id, "addon-install-complete-notification", "Should have seen the install complete");
michael@0 579 is(notification.button.label, "Restart Now", "Should have seen the right button");
michael@0 580 is(notification.getAttribute("label"),
michael@0 581 "Theme Test will be installed after you restart " + gApp + ".",
michael@0 582 "Should have seen the right message");
michael@0 583
michael@0 584 AddonManager.getAddonByID("{972ce4c6-7e08-4474-a285-3208198ce6fd}", function(aAddon) {
michael@0 585 ok(aAddon.userDisabled, "Should be switching away from the default theme.");
michael@0 586 // Undo the pending theme switch
michael@0 587 aAddon.userDisabled = false;
michael@0 588
michael@0 589 AddonManager.getAddonByID("theme-xpi@tests.mozilla.org", function(aAddon) {
michael@0 590 isnot(aAddon, null, "Test theme will have been installed");
michael@0 591 aAddon.uninstall();
michael@0 592
michael@0 593 Services.perms.remove("example.com", "install");
michael@0 594 wait_for_notification_close(runNextTest);
michael@0 595 gBrowser.removeTab(gBrowser.selectedTab);
michael@0 596 });
michael@0 597 });
michael@0 598 });
michael@0 599
michael@0 600 aWindow.document.documentElement.acceptDialog();
michael@0 601 });
michael@0 602 });
michael@0 603
michael@0 604 var pm = Services.perms;
michael@0 605 pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
michael@0 606
michael@0 607 var triggers = encodeURIComponent(JSON.stringify({
michael@0 608 "Theme XPI": "theme.xpi"
michael@0 609 }));
michael@0 610 gBrowser.selectedTab = gBrowser.addTab();
michael@0 611 gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
michael@0 612 },
michael@0 613
michael@0 614 function test_renotify_blocked() {
michael@0 615 // Wait for the blocked notification
michael@0 616 wait_for_notification(function(aPanel) {
michael@0 617 let notification = aPanel.childNodes[0];
michael@0 618 is(notification.id, "addon-install-blocked-notification", "Should have seen the install blocked");
michael@0 619
michael@0 620 wait_for_notification_close(function () {
michael@0 621 info("Timeouts after this probably mean bug 589954 regressed");
michael@0 622 executeSoon(function () {
michael@0 623 wait_for_notification(function(aPanel) {
michael@0 624 let notification = aPanel.childNodes[0];
michael@0 625 is(notification.id, "addon-install-blocked-notification",
michael@0 626 "Should have seen the install blocked - 2nd time");
michael@0 627
michael@0 628 AddonManager.getAllInstalls(function(aInstalls) {
michael@0 629 is(aInstalls.length, 2, "Should be two pending installs");
michael@0 630 aInstalls[0].cancel();
michael@0 631 aInstalls[1].cancel();
michael@0 632
michael@0 633 info("Closing browser tab");
michael@0 634 wait_for_notification_close(runNextTest);
michael@0 635 gBrowser.removeTab(gBrowser.selectedTab);
michael@0 636 });
michael@0 637 });
michael@0 638
michael@0 639 gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
michael@0 640 });
michael@0 641 });
michael@0 642
michael@0 643 // hide the panel (this simulates the user dismissing it)
michael@0 644 aPanel.hidePopup();
michael@0 645 });
michael@0 646
michael@0 647 var triggers = encodeURIComponent(JSON.stringify({
michael@0 648 "XPI": "unsigned.xpi"
michael@0 649 }));
michael@0 650 gBrowser.selectedTab = gBrowser.addTab();
michael@0 651 gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
michael@0 652 },
michael@0 653
michael@0 654 function test_renotify_installed() {
michael@0 655 // Wait for the progress notification
michael@0 656 wait_for_notification(function(aPanel) {
michael@0 657 let notification = aPanel.childNodes[0];
michael@0 658 is(notification.id, "addon-progress-notification", "Should have seen the progress notification");
michael@0 659
michael@0 660 // Wait for the install confirmation dialog
michael@0 661 wait_for_install_dialog(function(aWindow) {
michael@0 662 // Wait for the complete notification
michael@0 663 wait_for_notification(function(aPanel) {
michael@0 664 let notification = aPanel.childNodes[0];
michael@0 665 is(notification.id, "addon-install-complete-notification", "Should have seen the install complete");
michael@0 666
michael@0 667 // Dismiss the notification
michael@0 668 wait_for_notification_close(function () {
michael@0 669 // Install another
michael@0 670 executeSoon(function () {
michael@0 671 // Wait for the progress notification
michael@0 672 wait_for_notification(function(aPanel) {
michael@0 673 let notification = aPanel.childNodes[0];
michael@0 674 is(notification.id, "addon-progress-notification", "Should have seen the progress notification");
michael@0 675
michael@0 676 // Wait for the install confirmation dialog
michael@0 677 wait_for_install_dialog(function(aWindow) {
michael@0 678 info("Timeouts after this probably mean bug 589954 regressed");
michael@0 679
michael@0 680 // Wait for the complete notification
michael@0 681 wait_for_notification(function(aPanel) {
michael@0 682 let notification = aPanel.childNodes[0];
michael@0 683 is(notification.id, "addon-install-complete-notification", "Should have seen the second install complete");
michael@0 684
michael@0 685 AddonManager.getAllInstalls(function(aInstalls) {
michael@0 686 is(aInstalls.length, 1, "Should be one pending installs");
michael@0 687 aInstalls[0].cancel();
michael@0 688
michael@0 689 Services.perms.remove("example.com", "install");
michael@0 690 wait_for_notification_close(runNextTest);
michael@0 691 gBrowser.removeTab(gBrowser.selectedTab);
michael@0 692 });
michael@0 693 });
michael@0 694
michael@0 695 aWindow.document.documentElement.acceptDialog();
michael@0 696 });
michael@0 697 });
michael@0 698
michael@0 699 gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
michael@0 700 });
michael@0 701 });
michael@0 702
michael@0 703 // hide the panel (this simulates the user dismissing it)
michael@0 704 aPanel.hidePopup();
michael@0 705 });
michael@0 706
michael@0 707 aWindow.document.documentElement.acceptDialog();
michael@0 708 });
michael@0 709 });
michael@0 710
michael@0 711 var pm = Services.perms;
michael@0 712 pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
michael@0 713
michael@0 714 var triggers = encodeURIComponent(JSON.stringify({
michael@0 715 "XPI": "unsigned.xpi"
michael@0 716 }));
michael@0 717 gBrowser.selectedTab = gBrowser.addTab();
michael@0 718 gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
michael@0 719 },
michael@0 720
michael@0 721 function test_cancel_restart() {
michael@0 722 // Wait for the progress notification
michael@0 723 wait_for_notification(function(aPanel) {
michael@0 724 let notification = aPanel.childNodes[0];
michael@0 725 is(notification.id, "addon-progress-notification", "Should have seen the progress notification");
michael@0 726
michael@0 727 // Close the notification
michael@0 728 let anchor = document.getElementById("addons-notification-icon");
michael@0 729 anchor.click();
michael@0 730 // Reopen the notification
michael@0 731 anchor.click();
michael@0 732
michael@0 733 ok(PopupNotifications.isPanelOpen, "Notification should still be open");
michael@0 734 is(PopupNotifications.panel.childNodes.length, 1, "Should be only one notification");
michael@0 735 isnot(notification, aPanel.childNodes[0], "Should have reconstructed the notification UI");
michael@0 736 notification = aPanel.childNodes[0];
michael@0 737 is(notification.id, "addon-progress-notification", "Should have seen the progress notification");
michael@0 738 let button = document.getAnonymousElementByAttribute(notification, "anonid", "cancel");
michael@0 739
michael@0 740 // Cancel the download
michael@0 741 EventUtils.synthesizeMouse(button, 2, 2, {});
michael@0 742
michael@0 743 // Notification should have changed to cancelled
michael@0 744 notification = aPanel.childNodes[0];
michael@0 745 is(notification.id, "addon-install-cancelled-notification", "Should have seen the cancelled notification");
michael@0 746
michael@0 747 // Wait for the install confirmation dialog
michael@0 748 wait_for_install_dialog(function(aWindow) {
michael@0 749 // Wait for the complete notification
michael@0 750 wait_for_notification(function(aPanel) {
michael@0 751 let notification = aPanel.childNodes[0];
michael@0 752 is(notification.id, "addon-install-complete-notification", "Should have seen the install complete");
michael@0 753 is(notification.button.label, "Restart Now", "Should have seen the right button");
michael@0 754 is(notification.getAttribute("label"),
michael@0 755 "XPI Test will be installed after you restart " + gApp + ".",
michael@0 756 "Should have seen the right message");
michael@0 757
michael@0 758 AddonManager.getAllInstalls(function(aInstalls) {
michael@0 759 is(aInstalls.length, 1, "Should be one pending install");
michael@0 760 aInstalls[0].cancel();
michael@0 761
michael@0 762 Services.perms.remove("example.com", "install");
michael@0 763 wait_for_notification_close(runNextTest);
michael@0 764 gBrowser.removeTab(gBrowser.selectedTab);
michael@0 765 });
michael@0 766 });
michael@0 767
michael@0 768 aWindow.document.documentElement.acceptDialog();
michael@0 769 });
michael@0 770
michael@0 771 // Restart the download
michael@0 772 EventUtils.synthesizeMouse(notification.button, 20, 10, {});
michael@0 773
michael@0 774 // Should be back to a progress notification
michael@0 775 ok(PopupNotifications.isPanelOpen, "Notification should still be open");
michael@0 776 is(PopupNotifications.panel.childNodes.length, 1, "Should be only one notification");
michael@0 777 notification = aPanel.childNodes[0];
michael@0 778 is(notification.id, "addon-progress-notification", "Should have seen the progress notification");
michael@0 779 });
michael@0 780
michael@0 781 var pm = Services.perms;
michael@0 782 pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
michael@0 783
michael@0 784 var triggers = encodeURIComponent(JSON.stringify({
michael@0 785 "XPI": "unsigned.xpi"
michael@0 786 }));
michael@0 787 gBrowser.selectedTab = gBrowser.addTab();
michael@0 788 gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
michael@0 789 },
michael@0 790
michael@0 791 function test_failed_security() {
michael@0 792 Services.prefs.setBoolPref(PREF_INSTALL_REQUIREBUILTINCERTS, false);
michael@0 793
michael@0 794 setup_redirect({
michael@0 795 "Location": TESTROOT + "unsigned.xpi"
michael@0 796 });
michael@0 797
michael@0 798 // Wait for the blocked notification
michael@0 799 wait_for_notification(function(aPanel) {
michael@0 800 let notification = aPanel.childNodes[0];
michael@0 801 is(notification.id, "addon-install-blocked-notification", "Should have seen the install blocked");
michael@0 802
michael@0 803 // Click on Allow
michael@0 804 EventUtils.synthesizeMouse(notification.button, 20, 10, {});
michael@0 805
michael@0 806 // Notification should have changed to progress notification
michael@0 807 ok(PopupNotifications.isPanelOpen, "Notification should still be open");
michael@0 808 is(PopupNotifications.panel.childNodes.length, 1, "Should be only one notification");
michael@0 809 notification = aPanel.childNodes[0];
michael@0 810 is(notification.id, "addon-progress-notification", "Should have seen the progress notification");
michael@0 811
michael@0 812 // Wait for it to fail
michael@0 813 Services.obs.addObserver(function() {
michael@0 814 Services.obs.removeObserver(arguments.callee, "addon-install-failed");
michael@0 815
michael@0 816 // Allow the browser code to add the failure notification and then wait
michael@0 817 // for the progress notification to dismiss itself
michael@0 818 wait_for_single_notification(function() {
michael@0 819 is(PopupNotifications.panel.childNodes.length, 1, "Should be only one notification");
michael@0 820 notification = aPanel.childNodes[0];
michael@0 821 is(notification.id, "addon-install-failed-notification", "Should have seen the install fail");
michael@0 822
michael@0 823 Services.prefs.setBoolPref(PREF_INSTALL_REQUIREBUILTINCERTS, true);
michael@0 824 wait_for_notification_close(runNextTest);
michael@0 825 gBrowser.removeTab(gBrowser.selectedTab);
michael@0 826 });
michael@0 827 }, "addon-install-failed", false);
michael@0 828 });
michael@0 829
michael@0 830 var triggers = encodeURIComponent(JSON.stringify({
michael@0 831 "XPI": "redirect.sjs?mode=redirect"
michael@0 832 }));
michael@0 833 gBrowser.selectedTab = gBrowser.addTab();
michael@0 834 gBrowser.loadURI(SECUREROOT + "installtrigger.html?" + triggers);
michael@0 835 }
michael@0 836 ];
michael@0 837
michael@0 838 var gTestStart = null;
michael@0 839
michael@0 840 function runNextTest() {
michael@0 841 if (gTestStart)
michael@0 842 info("Test part took " + (Date.now() - gTestStart) + "ms");
michael@0 843
michael@0 844 ok(!PopupNotifications.isPanelOpen, "Notification should be closed");
michael@0 845
michael@0 846 AddonManager.getAllInstalls(function(aInstalls) {
michael@0 847 is(aInstalls.length, 0, "Should be no active installs");
michael@0 848
michael@0 849 if (TESTS.length == 0) {
michael@0 850 finish();
michael@0 851 return;
michael@0 852 }
michael@0 853
michael@0 854 info("Running " + TESTS[0].name);
michael@0 855 gTestStart = Date.now();
michael@0 856 TESTS.shift()();
michael@0 857 });
michael@0 858 };
michael@0 859
michael@0 860 var XPInstallObserver = {
michael@0 861 observe: function (aSubject, aTopic, aData) {
michael@0 862 var installInfo = aSubject.QueryInterface(Components.interfaces.amIWebInstallInfo);
michael@0 863 info("Observed " + aTopic + " for " + installInfo.installs.length + " installs");
michael@0 864 installInfo.installs.forEach(function(aInstall) {
michael@0 865 info("Install of " + aInstall.sourceURI.spec + " was in state " + aInstall.state);
michael@0 866 });
michael@0 867 }
michael@0 868 };
michael@0 869
michael@0 870 function test() {
michael@0 871 requestLongerTimeout(4);
michael@0 872 waitForExplicitFinish();
michael@0 873
michael@0 874 Services.prefs.setBoolPref("extensions.logging.enabled", true);
michael@0 875 Services.prefs.setBoolPref("extensions.strictCompatibility", true);
michael@0 876
michael@0 877 Services.obs.addObserver(XPInstallObserver, "addon-install-started", false);
michael@0 878 Services.obs.addObserver(XPInstallObserver, "addon-install-blocked", false);
michael@0 879 Services.obs.addObserver(XPInstallObserver, "addon-install-failed", false);
michael@0 880 Services.obs.addObserver(XPInstallObserver, "addon-install-complete", false);
michael@0 881
michael@0 882 PopupNotifications.transitionsEnabled = false;
michael@0 883
michael@0 884 registerCleanupFunction(function() {
michael@0 885 // Make sure no more test parts run in case we were timed out
michael@0 886 TESTS = [];
michael@0 887 PopupNotifications.panel.removeEventListener("popupshown", check_notification, false);
michael@0 888 PopupNotifications.transitionsEnabled = true;
michael@0 889
michael@0 890 AddonManager.getAllInstalls(function(aInstalls) {
michael@0 891 aInstalls.forEach(function(aInstall) {
michael@0 892 aInstall.cancel();
michael@0 893 });
michael@0 894 });
michael@0 895
michael@0 896 Services.prefs.clearUserPref("extensions.logging.enabled");
michael@0 897 Services.prefs.clearUserPref("extensions.strictCompatibility");
michael@0 898
michael@0 899 Services.obs.removeObserver(XPInstallObserver, "addon-install-started");
michael@0 900 Services.obs.removeObserver(XPInstallObserver, "addon-install-blocked");
michael@0 901 Services.obs.removeObserver(XPInstallObserver, "addon-install-failed");
michael@0 902 Services.obs.removeObserver(XPInstallObserver, "addon-install-complete");
michael@0 903 });
michael@0 904
michael@0 905 runNextTest();
michael@0 906 }

mercurial