1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/base/content/test/general/browser_bug553455.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,906 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + * http://creativecommons.org/publicdomain/zero/1.0/ 1.6 + */ 1.7 + 1.8 +const TESTROOT = "http://example.com/browser/toolkit/mozapps/extensions/test/xpinstall/"; 1.9 +const TESTROOT2 = "http://example.org/browser/toolkit/mozapps/extensions/test/xpinstall/"; 1.10 +const SECUREROOT = "https://example.com/browser/toolkit/mozapps/extensions/test/xpinstall/"; 1.11 +const XPINSTALL_URL = "chrome://mozapps/content/xpinstall/xpinstallConfirm.xul"; 1.12 +const PREF_INSTALL_REQUIREBUILTINCERTS = "extensions.install.requireBuiltInCerts"; 1.13 + 1.14 +var rootDir = getRootDirectory(gTestPath); 1.15 +var path = rootDir.split('/'); 1.16 +var chromeName = path[0] + '//' + path[2]; 1.17 +var croot = chromeName + "/content/browser/toolkit/mozapps/extensions/test/xpinstall/"; 1.18 +var jar = getJar(croot); 1.19 +if (jar) { 1.20 + var tmpdir = extractJarToTmp(jar); 1.21 + croot = 'file://' + tmpdir.path + '/'; 1.22 +} 1.23 +const CHROMEROOT = croot; 1.24 + 1.25 +var gApp = document.getElementById("bundle_brand").getString("brandShortName"); 1.26 +var gVersion = Services.appinfo.version; 1.27 +var check_notification; 1.28 + 1.29 +function wait_for_notification(aCallback) { 1.30 + info("Waiting for notification"); 1.31 + check_notification = function() { 1.32 + PopupNotifications.panel.removeEventListener("popupshown", check_notification, false); 1.33 + info("Saw notification"); 1.34 + is(PopupNotifications.panel.childNodes.length, 1, "Should be only one notification"); 1.35 + aCallback(PopupNotifications.panel); 1.36 + }; 1.37 + PopupNotifications.panel.addEventListener("popupshown", check_notification, false); 1.38 +} 1.39 + 1.40 +function wait_for_notification_close(aCallback) { 1.41 + info("Waiting for notification to close"); 1.42 + PopupNotifications.panel.addEventListener("popuphidden", function() { 1.43 + PopupNotifications.panel.removeEventListener("popuphidden", arguments.callee, false); 1.44 + aCallback(); 1.45 + }, false); 1.46 +} 1.47 + 1.48 +function wait_for_install_dialog(aCallback) { 1.49 + info("Waiting for install dialog"); 1.50 + Services.wm.addListener({ 1.51 + onOpenWindow: function(aXULWindow) { 1.52 + info("Install dialog opened, waiting for focus"); 1.53 + Services.wm.removeListener(this); 1.54 + 1.55 + var domwindow = aXULWindow.QueryInterface(Ci.nsIInterfaceRequestor) 1.56 + .getInterface(Ci.nsIDOMWindow); 1.57 + waitForFocus(function() { 1.58 + info("Saw install dialog"); 1.59 + is(domwindow.document.location.href, XPINSTALL_URL, "Should have seen the right window open"); 1.60 + 1.61 + // Override the countdown timer on the accept button 1.62 + var button = domwindow.document.documentElement.getButton("accept"); 1.63 + button.disabled = false; 1.64 + 1.65 + aCallback(domwindow); 1.66 + }, domwindow); 1.67 + }, 1.68 + 1.69 + onCloseWindow: function(aXULWindow) { 1.70 + }, 1.71 + 1.72 + onWindowTitleChange: function(aXULWindow, aNewTitle) { 1.73 + } 1.74 + }); 1.75 +} 1.76 + 1.77 +function wait_for_single_notification(aCallback) { 1.78 + function inner_waiter() { 1.79 + info("Waiting for single notification"); 1.80 + // Notification should never close while we wait 1.81 + ok(PopupNotifications.isPanelOpen, "Notification should still be open"); 1.82 + if (PopupNotifications.panel.childNodes.length == 2) { 1.83 + executeSoon(inner_waiter); 1.84 + return; 1.85 + } 1.86 + 1.87 + aCallback(); 1.88 + } 1.89 + 1.90 + executeSoon(inner_waiter); 1.91 +} 1.92 + 1.93 +function setup_redirect(aSettings) { 1.94 + var url = "https://example.com/browser/toolkit/mozapps/extensions/test/xpinstall/redirect.sjs?mode=setup"; 1.95 + for (var name in aSettings) { 1.96 + url += "&" + name + "=" + aSettings[name]; 1.97 + } 1.98 + 1.99 + var req = new XMLHttpRequest(); 1.100 + req.open("GET", url, false); 1.101 + req.send(null); 1.102 +} 1.103 + 1.104 +var TESTS = [ 1.105 +function test_disabled_install() { 1.106 + Services.prefs.setBoolPref("xpinstall.enabled", false); 1.107 + 1.108 + // Wait for the disabled notification 1.109 + wait_for_notification(function(aPanel) { 1.110 + let notification = aPanel.childNodes[0]; 1.111 + is(notification.id, "xpinstall-disabled-notification", "Should have seen installs disabled"); 1.112 + is(notification.button.label, "Enable", "Should have seen the right button"); 1.113 + is(notification.getAttribute("label"), 1.114 + "Software installation is currently disabled. Click Enable and try again."); 1.115 + 1.116 + wait_for_notification_close(function() { 1.117 + try { 1.118 + ok(Services.prefs.getBoolPref("xpinstall.enabled"), "Installation should be enabled"); 1.119 + } 1.120 + catch (e) { 1.121 + ok(false, "xpinstall.enabled should be set"); 1.122 + } 1.123 + 1.124 + gBrowser.removeTab(gBrowser.selectedTab); 1.125 + 1.126 + AddonManager.getAllInstalls(function(aInstalls) { 1.127 + is(aInstalls.length, 1, "Should have been one install created"); 1.128 + aInstalls[0].cancel(); 1.129 + 1.130 + runNextTest(); 1.131 + }); 1.132 + }); 1.133 + 1.134 + // Click on Enable 1.135 + EventUtils.synthesizeMouseAtCenter(notification.button, {}); 1.136 + }); 1.137 + 1.138 + var triggers = encodeURIComponent(JSON.stringify({ 1.139 + "XPI": "unsigned.xpi" 1.140 + })); 1.141 + gBrowser.selectedTab = gBrowser.addTab(); 1.142 + gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers); 1.143 +}, 1.144 + 1.145 +function test_blocked_install() { 1.146 + // Wait for the blocked notification 1.147 + wait_for_notification(function(aPanel) { 1.148 + let notification = aPanel.childNodes[0]; 1.149 + is(notification.id, "addon-install-blocked-notification", "Should have seen the install blocked"); 1.150 + is(notification.button.label, "Allow", "Should have seen the right button"); 1.151 + is(notification.getAttribute("label"), 1.152 + gApp + " prevented this site (example.com) from asking you to install " + 1.153 + "software on your computer.", 1.154 + "Should have seen the right message"); 1.155 + 1.156 + // Wait for the install confirmation dialog 1.157 + wait_for_install_dialog(function(aWindow) { 1.158 + // Wait for the complete notification 1.159 + wait_for_notification(function(aPanel) { 1.160 + let notification = aPanel.childNodes[0]; 1.161 + is(notification.id, "addon-install-complete-notification", "Should have seen the install complete"); 1.162 + is(notification.button.label, "Restart Now", "Should have seen the right button"); 1.163 + is(notification.getAttribute("label"), 1.164 + "XPI Test will be installed after you restart " + gApp + ".", 1.165 + "Should have seen the right message"); 1.166 + 1.167 + AddonManager.getAllInstalls(function(aInstalls) { 1.168 + is(aInstalls.length, 1, "Should be one pending install"); 1.169 + aInstalls[0].cancel(); 1.170 + 1.171 + wait_for_notification_close(runNextTest); 1.172 + gBrowser.removeTab(gBrowser.selectedTab); 1.173 + }); 1.174 + }); 1.175 + 1.176 + aWindow.document.documentElement.acceptDialog(); 1.177 + }); 1.178 + 1.179 + // Click on Allow 1.180 + EventUtils.synthesizeMouse(notification.button, 20, 10, {}); 1.181 + 1.182 + // Notification should have changed to progress notification 1.183 + ok(PopupNotifications.isPanelOpen, "Notification should still be open"); 1.184 + notification = aPanel.childNodes[0]; 1.185 + is(notification.id, "addon-progress-notification", "Should have seen the progress notification"); 1.186 + 1.187 + }); 1.188 + 1.189 + var triggers = encodeURIComponent(JSON.stringify({ 1.190 + "XPI": "unsigned.xpi" 1.191 + })); 1.192 + gBrowser.selectedTab = gBrowser.addTab(); 1.193 + gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers); 1.194 +}, 1.195 + 1.196 +function test_whitelisted_install() { 1.197 + // Wait for the progress notification 1.198 + wait_for_notification(function(aPanel) { 1.199 + let notification = aPanel.childNodes[0]; 1.200 + is(notification.id, "addon-progress-notification", "Should have seen the progress notification"); 1.201 + 1.202 + // Wait for the install confirmation dialog 1.203 + wait_for_install_dialog(function(aWindow) { 1.204 + // Wait for the complete notification 1.205 + wait_for_notification(function(aPanel) { 1.206 + let notification = aPanel.childNodes[0]; 1.207 + is(notification.id, "addon-install-complete-notification", "Should have seen the install complete"); 1.208 + is(notification.button.label, "Restart Now", "Should have seen the right button"); 1.209 + is(notification.getAttribute("label"), 1.210 + "XPI Test will be installed after you restart " + gApp + ".", 1.211 + "Should have seen the right message"); 1.212 + 1.213 + AddonManager.getAllInstalls(function(aInstalls) { 1.214 + is(aInstalls.length, 1, "Should be one pending install"); 1.215 + aInstalls[0].cancel(); 1.216 + 1.217 + Services.perms.remove("example.com", "install"); 1.218 + wait_for_notification_close(runNextTest); 1.219 + gBrowser.removeTab(gBrowser.selectedTab); 1.220 + }); 1.221 + }); 1.222 + 1.223 + aWindow.document.documentElement.acceptDialog(); 1.224 + }); 1.225 + }); 1.226 + 1.227 + var pm = Services.perms; 1.228 + pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION); 1.229 + 1.230 + var triggers = encodeURIComponent(JSON.stringify({ 1.231 + "XPI": "unsigned.xpi" 1.232 + })); 1.233 + gBrowser.selectedTab = gBrowser.addTab(); 1.234 + gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers); 1.235 +}, 1.236 + 1.237 +function test_failed_download() { 1.238 + // Wait for the progress notification 1.239 + wait_for_notification(function(aPanel) { 1.240 + let notification = aPanel.childNodes[0]; 1.241 + is(notification.id, "addon-progress-notification", "Should have seen the progress notification"); 1.242 + 1.243 + // Wait for the failed notification 1.244 + wait_for_notification(function(aPanel) { 1.245 + let notification = aPanel.childNodes[0]; 1.246 + is(notification.id, "addon-install-failed-notification", "Should have seen the install fail"); 1.247 + is(notification.getAttribute("label"), 1.248 + "The add-on could not be downloaded because of a connection failure " + 1.249 + "on example.com.", 1.250 + "Should have seen the right message"); 1.251 + 1.252 + Services.perms.remove("example.com", "install"); 1.253 + wait_for_notification_close(runNextTest); 1.254 + gBrowser.removeTab(gBrowser.selectedTab); 1.255 + }); 1.256 + }); 1.257 + 1.258 + var pm = Services.perms; 1.259 + pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION); 1.260 + 1.261 + var triggers = encodeURIComponent(JSON.stringify({ 1.262 + "XPI": "missing.xpi" 1.263 + })); 1.264 + gBrowser.selectedTab = gBrowser.addTab(); 1.265 + gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers); 1.266 +}, 1.267 + 1.268 +function test_corrupt_file() { 1.269 + // Wait for the progress notification 1.270 + wait_for_notification(function(aPanel) { 1.271 + let notification = aPanel.childNodes[0]; 1.272 + is(notification.id, "addon-progress-notification", "Should have seen the progress notification"); 1.273 + 1.274 + // Wait for the failed notification 1.275 + wait_for_notification(function(aPanel) { 1.276 + let notification = aPanel.childNodes[0]; 1.277 + is(notification.id, "addon-install-failed-notification", "Should have seen the install fail"); 1.278 + is(notification.getAttribute("label"), 1.279 + "The add-on downloaded from example.com could not be installed " + 1.280 + "because it appears to be corrupt.", 1.281 + "Should have seen the right message"); 1.282 + 1.283 + Services.perms.remove("example.com", "install"); 1.284 + wait_for_notification_close(runNextTest); 1.285 + gBrowser.removeTab(gBrowser.selectedTab); 1.286 + }); 1.287 + }); 1.288 + 1.289 + var pm = Services.perms; 1.290 + pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION); 1.291 + 1.292 + var triggers = encodeURIComponent(JSON.stringify({ 1.293 + "XPI": "corrupt.xpi" 1.294 + })); 1.295 + gBrowser.selectedTab = gBrowser.addTab(); 1.296 + gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers); 1.297 +}, 1.298 + 1.299 +function test_incompatible() { 1.300 + // Wait for the progress notification 1.301 + wait_for_notification(function(aPanel) { 1.302 + let notification = aPanel.childNodes[0]; 1.303 + is(notification.id, "addon-progress-notification", "Should have seen the progress notification"); 1.304 + 1.305 + // Wait for the failed notification 1.306 + wait_for_notification(function(aPanel) { 1.307 + let notification = aPanel.childNodes[0]; 1.308 + is(notification.id, "addon-install-failed-notification", "Should have seen the install fail"); 1.309 + is(notification.getAttribute("label"), 1.310 + "XPI Test could not be installed because it is not compatible with " + 1.311 + gApp + " " + gVersion + ".", 1.312 + "Should have seen the right message"); 1.313 + 1.314 + Services.perms.remove("example.com", "install"); 1.315 + wait_for_notification_close(runNextTest); 1.316 + gBrowser.removeTab(gBrowser.selectedTab); 1.317 + }); 1.318 + }); 1.319 + 1.320 + var pm = Services.perms; 1.321 + pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION); 1.322 + 1.323 + var triggers = encodeURIComponent(JSON.stringify({ 1.324 + "XPI": "incompatible.xpi" 1.325 + })); 1.326 + gBrowser.selectedTab = gBrowser.addTab(); 1.327 + gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers); 1.328 +}, 1.329 + 1.330 +function test_restartless() { 1.331 + // Wait for the progress notification 1.332 + wait_for_notification(function(aPanel) { 1.333 + let notification = aPanel.childNodes[0]; 1.334 + is(notification.id, "addon-progress-notification", "Should have seen the progress notification"); 1.335 + 1.336 + // Wait for the install confirmation dialog 1.337 + wait_for_install_dialog(function(aWindow) { 1.338 + // Wait for the complete notification 1.339 + wait_for_notification(function(aPanel) { 1.340 + let notification = aPanel.childNodes[0]; 1.341 + is(notification.id, "addon-install-complete-notification", "Should have seen the install complete"); 1.342 + is(notification.getAttribute("label"), 1.343 + "XPI Test has been installed successfully.", 1.344 + "Should have seen the right message"); 1.345 + 1.346 + AddonManager.getAllInstalls(function(aInstalls) { 1.347 + is(aInstalls.length, 0, "Should be no pending installs"); 1.348 + 1.349 + AddonManager.getAddonByID("restartless-xpi@tests.mozilla.org", function(aAddon) { 1.350 + aAddon.uninstall(); 1.351 + 1.352 + Services.perms.remove("example.com", "install"); 1.353 + wait_for_notification_close(runNextTest); 1.354 + gBrowser.removeTab(gBrowser.selectedTab); 1.355 + }); 1.356 + }); 1.357 + }); 1.358 + 1.359 + aWindow.document.documentElement.acceptDialog(); 1.360 + }); 1.361 + }); 1.362 + 1.363 + var pm = Services.perms; 1.364 + pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION); 1.365 + 1.366 + var triggers = encodeURIComponent(JSON.stringify({ 1.367 + "XPI": "restartless.xpi" 1.368 + })); 1.369 + gBrowser.selectedTab = gBrowser.addTab(); 1.370 + gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers); 1.371 +}, 1.372 + 1.373 +function test_multiple() { 1.374 + // Wait for the progress notification 1.375 + wait_for_notification(function(aPanel) { 1.376 + let notification = aPanel.childNodes[0]; 1.377 + is(notification.id, "addon-progress-notification", "Should have seen the progress notification"); 1.378 + 1.379 + // Wait for the install confirmation dialog 1.380 + wait_for_install_dialog(function(aWindow) { 1.381 + // Wait for the complete notification 1.382 + wait_for_notification(function(aPanel) { 1.383 + let notification = aPanel.childNodes[0]; 1.384 + is(notification.id, "addon-install-complete-notification", "Should have seen the install complete"); 1.385 + is(notification.button.label, "Restart Now", "Should have seen the right button"); 1.386 + is(notification.getAttribute("label"), 1.387 + "2 add-ons will be installed after you restart " + gApp + ".", 1.388 + "Should have seen the right message"); 1.389 + 1.390 + AddonManager.getAllInstalls(function(aInstalls) { 1.391 + is(aInstalls.length, 1, "Should be one pending install"); 1.392 + aInstalls[0].cancel(); 1.393 + 1.394 + AddonManager.getAddonByID("restartless-xpi@tests.mozilla.org", function(aAddon) { 1.395 + aAddon.uninstall(); 1.396 + 1.397 + Services.perms.remove("example.com", "install"); 1.398 + wait_for_notification_close(runNextTest); 1.399 + gBrowser.removeTab(gBrowser.selectedTab); 1.400 + }); 1.401 + }); 1.402 + }); 1.403 + 1.404 + aWindow.document.documentElement.acceptDialog(); 1.405 + }); 1.406 + }); 1.407 + 1.408 + var pm = Services.perms; 1.409 + pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION); 1.410 + 1.411 + var triggers = encodeURIComponent(JSON.stringify({ 1.412 + "Unsigned XPI": "unsigned.xpi", 1.413 + "Restartless XPI": "restartless.xpi" 1.414 + })); 1.415 + gBrowser.selectedTab = gBrowser.addTab(); 1.416 + gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers); 1.417 +}, 1.418 + 1.419 +function test_url() { 1.420 + // Wait for the progress notification 1.421 + wait_for_notification(function(aPanel) { 1.422 + let notification = aPanel.childNodes[0]; 1.423 + is(notification.id, "addon-progress-notification", "Should have seen the progress notification"); 1.424 + 1.425 + // Wait for the install confirmation dialog 1.426 + wait_for_install_dialog(function(aWindow) { 1.427 + // Wait for the complete notification 1.428 + wait_for_notification(function(aPanel) { 1.429 + let notification = aPanel.childNodes[0]; 1.430 + is(notification.id, "addon-install-complete-notification", "Should have seen the install complete"); 1.431 + is(notification.button.label, "Restart Now", "Should have seen the right button"); 1.432 + is(notification.getAttribute("label"), 1.433 + "XPI Test will be installed after you restart " + gApp + ".", 1.434 + "Should have seen the right message"); 1.435 + 1.436 + AddonManager.getAllInstalls(function(aInstalls) { 1.437 + is(aInstalls.length, 1, "Should be one pending install"); 1.438 + aInstalls[0].cancel(); 1.439 + 1.440 + wait_for_notification_close(runNextTest); 1.441 + gBrowser.removeTab(gBrowser.selectedTab); 1.442 + }); 1.443 + }); 1.444 + 1.445 + aWindow.document.documentElement.acceptDialog(); 1.446 + }); 1.447 + }); 1.448 + 1.449 + gBrowser.selectedTab = gBrowser.addTab(); 1.450 + gBrowser.loadURI(TESTROOT + "unsigned.xpi"); 1.451 +}, 1.452 + 1.453 +function test_localfile() { 1.454 + // Wait for the install to fail 1.455 + Services.obs.addObserver(function() { 1.456 + Services.obs.removeObserver(arguments.callee, "addon-install-failed"); 1.457 + 1.458 + // Wait for the browser code to add the failure notification 1.459 + wait_for_single_notification(function() { 1.460 + let notification = PopupNotifications.panel.childNodes[0]; 1.461 + is(notification.id, "addon-install-failed-notification", "Should have seen the install fail"); 1.462 + is(notification.getAttribute("label"), 1.463 + "This add-on could not be installed because it appears to be corrupt.", 1.464 + "Should have seen the right message"); 1.465 + 1.466 + wait_for_notification_close(runNextTest); 1.467 + gBrowser.removeTab(gBrowser.selectedTab); 1.468 + }); 1.469 + }, "addon-install-failed", false); 1.470 + 1.471 + var cr = Components.classes["@mozilla.org/chrome/chrome-registry;1"] 1.472 + .getService(Components.interfaces.nsIChromeRegistry); 1.473 + try { 1.474 + var path = cr.convertChromeURL(makeURI(CHROMEROOT + "corrupt.xpi")).spec; 1.475 + } catch (ex) { 1.476 + var path = CHROMEROOT + "corrupt.xpi"; 1.477 + } 1.478 + gBrowser.selectedTab = gBrowser.addTab(); 1.479 + gBrowser.loadURI(path); 1.480 +}, 1.481 + 1.482 +function test_wronghost() { 1.483 + gBrowser.selectedTab = gBrowser.addTab(); 1.484 + gBrowser.addEventListener("load", function() { 1.485 + if (gBrowser.currentURI.spec != TESTROOT2 + "enabled.html") 1.486 + return; 1.487 + 1.488 + gBrowser.removeEventListener("load", arguments.callee, true); 1.489 + 1.490 + // Wait for the progress notification 1.491 + wait_for_notification(function(aPanel) { 1.492 + let notification = aPanel.childNodes[0]; 1.493 + is(notification.id, "addon-progress-notification", "Should have seen the progress notification"); 1.494 + // Wait for the complete notification 1.495 + wait_for_notification(function(aPanel) { 1.496 + let notification = aPanel.childNodes[0]; 1.497 + is(notification.id, "addon-install-failed-notification", "Should have seen the install fail"); 1.498 + is(notification.getAttribute("label"), 1.499 + "The add-on downloaded from example.com could not be installed " + 1.500 + "because it appears to be corrupt.", 1.501 + "Should have seen the right message"); 1.502 + 1.503 + wait_for_notification_close(runNextTest); 1.504 + gBrowser.removeTab(gBrowser.selectedTab); 1.505 + }); 1.506 + }); 1.507 + 1.508 + gBrowser.loadURI(TESTROOT + "corrupt.xpi"); 1.509 + }, true); 1.510 + gBrowser.loadURI(TESTROOT2 + "enabled.html"); 1.511 +}, 1.512 + 1.513 +function test_reload() { 1.514 + // Wait for the progress notification 1.515 + wait_for_notification(function(aPanel) { 1.516 + let notification = aPanel.childNodes[0]; 1.517 + is(notification.id, "addon-progress-notification", "Should have seen the progress notification"); 1.518 + 1.519 + // Wait for the install confirmation dialog 1.520 + wait_for_install_dialog(function(aWindow) { 1.521 + // Wait for the complete notification 1.522 + wait_for_notification(function(aPanel) { 1.523 + let notification = aPanel.childNodes[0]; 1.524 + is(notification.id, "addon-install-complete-notification", "Should have seen the install complete"); 1.525 + is(notification.button.label, "Restart Now", "Should have seen the right button"); 1.526 + is(notification.getAttribute("label"), 1.527 + "XPI Test will be installed after you restart " + gApp + ".", 1.528 + "Should have seen the right message"); 1.529 + 1.530 + function test_fail() { 1.531 + ok(false, "Reloading should not have hidden the notification"); 1.532 + } 1.533 + 1.534 + PopupNotifications.panel.addEventListener("popuphiding", test_fail, false); 1.535 + 1.536 + gBrowser.addEventListener("load", function() { 1.537 + if (gBrowser.currentURI.spec != TESTROOT2 + "enabled.html") 1.538 + return; 1.539 + 1.540 + gBrowser.removeEventListener("load", arguments.callee, true); 1.541 + 1.542 + PopupNotifications.panel.removeEventListener("popuphiding", test_fail, false); 1.543 + 1.544 + AddonManager.getAllInstalls(function(aInstalls) { 1.545 + is(aInstalls.length, 1, "Should be one pending install"); 1.546 + aInstalls[0].cancel(); 1.547 + 1.548 + Services.perms.remove("example.com", "install"); 1.549 + wait_for_notification_close(runNextTest); 1.550 + gBrowser.removeTab(gBrowser.selectedTab); 1.551 + }); 1.552 + }, true); 1.553 + gBrowser.loadURI(TESTROOT2 + "enabled.html"); 1.554 + }); 1.555 + 1.556 + aWindow.document.documentElement.acceptDialog(); 1.557 + }); 1.558 + }); 1.559 + 1.560 + var pm = Services.perms; 1.561 + pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION); 1.562 + 1.563 + var triggers = encodeURIComponent(JSON.stringify({ 1.564 + "Unsigned XPI": "unsigned.xpi" 1.565 + })); 1.566 + gBrowser.selectedTab = gBrowser.addTab(); 1.567 + gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers); 1.568 +}, 1.569 + 1.570 +function test_theme() { 1.571 + // Wait for the progress notification 1.572 + wait_for_notification(function(aPanel) { 1.573 + let notification = aPanel.childNodes[0]; 1.574 + is(notification.id, "addon-progress-notification", "Should have seen the progress notification"); 1.575 + 1.576 + // Wait for the install confirmation dialog 1.577 + wait_for_install_dialog(function(aWindow) { 1.578 + // Wait for the complete notification 1.579 + wait_for_notification(function(aPanel) { 1.580 + let notification = aPanel.childNodes[0]; 1.581 + is(notification.id, "addon-install-complete-notification", "Should have seen the install complete"); 1.582 + is(notification.button.label, "Restart Now", "Should have seen the right button"); 1.583 + is(notification.getAttribute("label"), 1.584 + "Theme Test will be installed after you restart " + gApp + ".", 1.585 + "Should have seen the right message"); 1.586 + 1.587 + AddonManager.getAddonByID("{972ce4c6-7e08-4474-a285-3208198ce6fd}", function(aAddon) { 1.588 + ok(aAddon.userDisabled, "Should be switching away from the default theme."); 1.589 + // Undo the pending theme switch 1.590 + aAddon.userDisabled = false; 1.591 + 1.592 + AddonManager.getAddonByID("theme-xpi@tests.mozilla.org", function(aAddon) { 1.593 + isnot(aAddon, null, "Test theme will have been installed"); 1.594 + aAddon.uninstall(); 1.595 + 1.596 + Services.perms.remove("example.com", "install"); 1.597 + wait_for_notification_close(runNextTest); 1.598 + gBrowser.removeTab(gBrowser.selectedTab); 1.599 + }); 1.600 + }); 1.601 + }); 1.602 + 1.603 + aWindow.document.documentElement.acceptDialog(); 1.604 + }); 1.605 + }); 1.606 + 1.607 + var pm = Services.perms; 1.608 + pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION); 1.609 + 1.610 + var triggers = encodeURIComponent(JSON.stringify({ 1.611 + "Theme XPI": "theme.xpi" 1.612 + })); 1.613 + gBrowser.selectedTab = gBrowser.addTab(); 1.614 + gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers); 1.615 +}, 1.616 + 1.617 +function test_renotify_blocked() { 1.618 + // Wait for the blocked notification 1.619 + wait_for_notification(function(aPanel) { 1.620 + let notification = aPanel.childNodes[0]; 1.621 + is(notification.id, "addon-install-blocked-notification", "Should have seen the install blocked"); 1.622 + 1.623 + wait_for_notification_close(function () { 1.624 + info("Timeouts after this probably mean bug 589954 regressed"); 1.625 + executeSoon(function () { 1.626 + wait_for_notification(function(aPanel) { 1.627 + let notification = aPanel.childNodes[0]; 1.628 + is(notification.id, "addon-install-blocked-notification", 1.629 + "Should have seen the install blocked - 2nd time"); 1.630 + 1.631 + AddonManager.getAllInstalls(function(aInstalls) { 1.632 + is(aInstalls.length, 2, "Should be two pending installs"); 1.633 + aInstalls[0].cancel(); 1.634 + aInstalls[1].cancel(); 1.635 + 1.636 + info("Closing browser tab"); 1.637 + wait_for_notification_close(runNextTest); 1.638 + gBrowser.removeTab(gBrowser.selectedTab); 1.639 + }); 1.640 + }); 1.641 + 1.642 + gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers); 1.643 + }); 1.644 + }); 1.645 + 1.646 + // hide the panel (this simulates the user dismissing it) 1.647 + aPanel.hidePopup(); 1.648 + }); 1.649 + 1.650 + var triggers = encodeURIComponent(JSON.stringify({ 1.651 + "XPI": "unsigned.xpi" 1.652 + })); 1.653 + gBrowser.selectedTab = gBrowser.addTab(); 1.654 + gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers); 1.655 +}, 1.656 + 1.657 +function test_renotify_installed() { 1.658 + // Wait for the progress notification 1.659 + wait_for_notification(function(aPanel) { 1.660 + let notification = aPanel.childNodes[0]; 1.661 + is(notification.id, "addon-progress-notification", "Should have seen the progress notification"); 1.662 + 1.663 + // Wait for the install confirmation dialog 1.664 + wait_for_install_dialog(function(aWindow) { 1.665 + // Wait for the complete notification 1.666 + wait_for_notification(function(aPanel) { 1.667 + let notification = aPanel.childNodes[0]; 1.668 + is(notification.id, "addon-install-complete-notification", "Should have seen the install complete"); 1.669 + 1.670 + // Dismiss the notification 1.671 + wait_for_notification_close(function () { 1.672 + // Install another 1.673 + executeSoon(function () { 1.674 + // Wait for the progress notification 1.675 + wait_for_notification(function(aPanel) { 1.676 + let notification = aPanel.childNodes[0]; 1.677 + is(notification.id, "addon-progress-notification", "Should have seen the progress notification"); 1.678 + 1.679 + // Wait for the install confirmation dialog 1.680 + wait_for_install_dialog(function(aWindow) { 1.681 + info("Timeouts after this probably mean bug 589954 regressed"); 1.682 + 1.683 + // Wait for the complete notification 1.684 + wait_for_notification(function(aPanel) { 1.685 + let notification = aPanel.childNodes[0]; 1.686 + is(notification.id, "addon-install-complete-notification", "Should have seen the second install complete"); 1.687 + 1.688 + AddonManager.getAllInstalls(function(aInstalls) { 1.689 + is(aInstalls.length, 1, "Should be one pending installs"); 1.690 + aInstalls[0].cancel(); 1.691 + 1.692 + Services.perms.remove("example.com", "install"); 1.693 + wait_for_notification_close(runNextTest); 1.694 + gBrowser.removeTab(gBrowser.selectedTab); 1.695 + }); 1.696 + }); 1.697 + 1.698 + aWindow.document.documentElement.acceptDialog(); 1.699 + }); 1.700 + }); 1.701 + 1.702 + gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers); 1.703 + }); 1.704 + }); 1.705 + 1.706 + // hide the panel (this simulates the user dismissing it) 1.707 + aPanel.hidePopup(); 1.708 + }); 1.709 + 1.710 + aWindow.document.documentElement.acceptDialog(); 1.711 + }); 1.712 + }); 1.713 + 1.714 + var pm = Services.perms; 1.715 + pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION); 1.716 + 1.717 + var triggers = encodeURIComponent(JSON.stringify({ 1.718 + "XPI": "unsigned.xpi" 1.719 + })); 1.720 + gBrowser.selectedTab = gBrowser.addTab(); 1.721 + gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers); 1.722 +}, 1.723 + 1.724 +function test_cancel_restart() { 1.725 + // Wait for the progress notification 1.726 + wait_for_notification(function(aPanel) { 1.727 + let notification = aPanel.childNodes[0]; 1.728 + is(notification.id, "addon-progress-notification", "Should have seen the progress notification"); 1.729 + 1.730 + // Close the notification 1.731 + let anchor = document.getElementById("addons-notification-icon"); 1.732 + anchor.click(); 1.733 + // Reopen the notification 1.734 + anchor.click(); 1.735 + 1.736 + ok(PopupNotifications.isPanelOpen, "Notification should still be open"); 1.737 + is(PopupNotifications.panel.childNodes.length, 1, "Should be only one notification"); 1.738 + isnot(notification, aPanel.childNodes[0], "Should have reconstructed the notification UI"); 1.739 + notification = aPanel.childNodes[0]; 1.740 + is(notification.id, "addon-progress-notification", "Should have seen the progress notification"); 1.741 + let button = document.getAnonymousElementByAttribute(notification, "anonid", "cancel"); 1.742 + 1.743 + // Cancel the download 1.744 + EventUtils.synthesizeMouse(button, 2, 2, {}); 1.745 + 1.746 + // Notification should have changed to cancelled 1.747 + notification = aPanel.childNodes[0]; 1.748 + is(notification.id, "addon-install-cancelled-notification", "Should have seen the cancelled notification"); 1.749 + 1.750 + // Wait for the install confirmation dialog 1.751 + wait_for_install_dialog(function(aWindow) { 1.752 + // Wait for the complete notification 1.753 + wait_for_notification(function(aPanel) { 1.754 + let notification = aPanel.childNodes[0]; 1.755 + is(notification.id, "addon-install-complete-notification", "Should have seen the install complete"); 1.756 + is(notification.button.label, "Restart Now", "Should have seen the right button"); 1.757 + is(notification.getAttribute("label"), 1.758 + "XPI Test will be installed after you restart " + gApp + ".", 1.759 + "Should have seen the right message"); 1.760 + 1.761 + AddonManager.getAllInstalls(function(aInstalls) { 1.762 + is(aInstalls.length, 1, "Should be one pending install"); 1.763 + aInstalls[0].cancel(); 1.764 + 1.765 + Services.perms.remove("example.com", "install"); 1.766 + wait_for_notification_close(runNextTest); 1.767 + gBrowser.removeTab(gBrowser.selectedTab); 1.768 + }); 1.769 + }); 1.770 + 1.771 + aWindow.document.documentElement.acceptDialog(); 1.772 + }); 1.773 + 1.774 + // Restart the download 1.775 + EventUtils.synthesizeMouse(notification.button, 20, 10, {}); 1.776 + 1.777 + // Should be back to a progress notification 1.778 + ok(PopupNotifications.isPanelOpen, "Notification should still be open"); 1.779 + is(PopupNotifications.panel.childNodes.length, 1, "Should be only one notification"); 1.780 + notification = aPanel.childNodes[0]; 1.781 + is(notification.id, "addon-progress-notification", "Should have seen the progress notification"); 1.782 + }); 1.783 + 1.784 + var pm = Services.perms; 1.785 + pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION); 1.786 + 1.787 + var triggers = encodeURIComponent(JSON.stringify({ 1.788 + "XPI": "unsigned.xpi" 1.789 + })); 1.790 + gBrowser.selectedTab = gBrowser.addTab(); 1.791 + gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers); 1.792 +}, 1.793 + 1.794 +function test_failed_security() { 1.795 + Services.prefs.setBoolPref(PREF_INSTALL_REQUIREBUILTINCERTS, false); 1.796 + 1.797 + setup_redirect({ 1.798 + "Location": TESTROOT + "unsigned.xpi" 1.799 + }); 1.800 + 1.801 + // Wait for the blocked notification 1.802 + wait_for_notification(function(aPanel) { 1.803 + let notification = aPanel.childNodes[0]; 1.804 + is(notification.id, "addon-install-blocked-notification", "Should have seen the install blocked"); 1.805 + 1.806 + // Click on Allow 1.807 + EventUtils.synthesizeMouse(notification.button, 20, 10, {}); 1.808 + 1.809 + // Notification should have changed to progress notification 1.810 + ok(PopupNotifications.isPanelOpen, "Notification should still be open"); 1.811 + is(PopupNotifications.panel.childNodes.length, 1, "Should be only one notification"); 1.812 + notification = aPanel.childNodes[0]; 1.813 + is(notification.id, "addon-progress-notification", "Should have seen the progress notification"); 1.814 + 1.815 + // Wait for it to fail 1.816 + Services.obs.addObserver(function() { 1.817 + Services.obs.removeObserver(arguments.callee, "addon-install-failed"); 1.818 + 1.819 + // Allow the browser code to add the failure notification and then wait 1.820 + // for the progress notification to dismiss itself 1.821 + wait_for_single_notification(function() { 1.822 + is(PopupNotifications.panel.childNodes.length, 1, "Should be only one notification"); 1.823 + notification = aPanel.childNodes[0]; 1.824 + is(notification.id, "addon-install-failed-notification", "Should have seen the install fail"); 1.825 + 1.826 + Services.prefs.setBoolPref(PREF_INSTALL_REQUIREBUILTINCERTS, true); 1.827 + wait_for_notification_close(runNextTest); 1.828 + gBrowser.removeTab(gBrowser.selectedTab); 1.829 + }); 1.830 + }, "addon-install-failed", false); 1.831 + }); 1.832 + 1.833 + var triggers = encodeURIComponent(JSON.stringify({ 1.834 + "XPI": "redirect.sjs?mode=redirect" 1.835 + })); 1.836 + gBrowser.selectedTab = gBrowser.addTab(); 1.837 + gBrowser.loadURI(SECUREROOT + "installtrigger.html?" + triggers); 1.838 +} 1.839 +]; 1.840 + 1.841 +var gTestStart = null; 1.842 + 1.843 +function runNextTest() { 1.844 + if (gTestStart) 1.845 + info("Test part took " + (Date.now() - gTestStart) + "ms"); 1.846 + 1.847 + ok(!PopupNotifications.isPanelOpen, "Notification should be closed"); 1.848 + 1.849 + AddonManager.getAllInstalls(function(aInstalls) { 1.850 + is(aInstalls.length, 0, "Should be no active installs"); 1.851 + 1.852 + if (TESTS.length == 0) { 1.853 + finish(); 1.854 + return; 1.855 + } 1.856 + 1.857 + info("Running " + TESTS[0].name); 1.858 + gTestStart = Date.now(); 1.859 + TESTS.shift()(); 1.860 + }); 1.861 +}; 1.862 + 1.863 +var XPInstallObserver = { 1.864 + observe: function (aSubject, aTopic, aData) { 1.865 + var installInfo = aSubject.QueryInterface(Components.interfaces.amIWebInstallInfo); 1.866 + info("Observed " + aTopic + " for " + installInfo.installs.length + " installs"); 1.867 + installInfo.installs.forEach(function(aInstall) { 1.868 + info("Install of " + aInstall.sourceURI.spec + " was in state " + aInstall.state); 1.869 + }); 1.870 + } 1.871 +}; 1.872 + 1.873 +function test() { 1.874 + requestLongerTimeout(4); 1.875 + waitForExplicitFinish(); 1.876 + 1.877 + Services.prefs.setBoolPref("extensions.logging.enabled", true); 1.878 + Services.prefs.setBoolPref("extensions.strictCompatibility", true); 1.879 + 1.880 + Services.obs.addObserver(XPInstallObserver, "addon-install-started", false); 1.881 + Services.obs.addObserver(XPInstallObserver, "addon-install-blocked", false); 1.882 + Services.obs.addObserver(XPInstallObserver, "addon-install-failed", false); 1.883 + Services.obs.addObserver(XPInstallObserver, "addon-install-complete", false); 1.884 + 1.885 + PopupNotifications.transitionsEnabled = false; 1.886 + 1.887 + registerCleanupFunction(function() { 1.888 + // Make sure no more test parts run in case we were timed out 1.889 + TESTS = []; 1.890 + PopupNotifications.panel.removeEventListener("popupshown", check_notification, false); 1.891 + PopupNotifications.transitionsEnabled = true; 1.892 + 1.893 + AddonManager.getAllInstalls(function(aInstalls) { 1.894 + aInstalls.forEach(function(aInstall) { 1.895 + aInstall.cancel(); 1.896 + }); 1.897 + }); 1.898 + 1.899 + Services.prefs.clearUserPref("extensions.logging.enabled"); 1.900 + Services.prefs.clearUserPref("extensions.strictCompatibility"); 1.901 + 1.902 + Services.obs.removeObserver(XPInstallObserver, "addon-install-started"); 1.903 + Services.obs.removeObserver(XPInstallObserver, "addon-install-blocked"); 1.904 + Services.obs.removeObserver(XPInstallObserver, "addon-install-failed"); 1.905 + Services.obs.removeObserver(XPInstallObserver, "addon-install-complete"); 1.906 + }); 1.907 + 1.908 + runNextTest(); 1.909 +}