michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ michael@0: */ michael@0: michael@0: const TESTROOT = "http://example.com/browser/toolkit/mozapps/extensions/test/xpinstall/"; michael@0: const TESTROOT2 = "http://example.org/browser/toolkit/mozapps/extensions/test/xpinstall/"; michael@0: const SECUREROOT = "https://example.com/browser/toolkit/mozapps/extensions/test/xpinstall/"; michael@0: const XPINSTALL_URL = "chrome://mozapps/content/xpinstall/xpinstallConfirm.xul"; michael@0: const PREF_INSTALL_REQUIREBUILTINCERTS = "extensions.install.requireBuiltInCerts"; michael@0: michael@0: var rootDir = getRootDirectory(gTestPath); michael@0: var path = rootDir.split('/'); michael@0: var chromeName = path[0] + '//' + path[2]; michael@0: var croot = chromeName + "/content/browser/toolkit/mozapps/extensions/test/xpinstall/"; michael@0: var jar = getJar(croot); michael@0: if (jar) { michael@0: var tmpdir = extractJarToTmp(jar); michael@0: croot = 'file://' + tmpdir.path + '/'; michael@0: } michael@0: const CHROMEROOT = croot; michael@0: michael@0: var gApp = document.getElementById("bundle_brand").getString("brandShortName"); michael@0: var gVersion = Services.appinfo.version; michael@0: var check_notification; michael@0: michael@0: function wait_for_notification(aCallback) { michael@0: info("Waiting for notification"); michael@0: check_notification = function() { michael@0: PopupNotifications.panel.removeEventListener("popupshown", check_notification, false); michael@0: info("Saw notification"); michael@0: is(PopupNotifications.panel.childNodes.length, 1, "Should be only one notification"); michael@0: aCallback(PopupNotifications.panel); michael@0: }; michael@0: PopupNotifications.panel.addEventListener("popupshown", check_notification, false); michael@0: } michael@0: michael@0: function wait_for_notification_close(aCallback) { michael@0: info("Waiting for notification to close"); michael@0: PopupNotifications.panel.addEventListener("popuphidden", function() { michael@0: PopupNotifications.panel.removeEventListener("popuphidden", arguments.callee, false); michael@0: aCallback(); michael@0: }, false); michael@0: } michael@0: michael@0: function wait_for_install_dialog(aCallback) { michael@0: info("Waiting for install dialog"); michael@0: Services.wm.addListener({ michael@0: onOpenWindow: function(aXULWindow) { michael@0: info("Install dialog opened, waiting for focus"); michael@0: Services.wm.removeListener(this); michael@0: michael@0: var domwindow = aXULWindow.QueryInterface(Ci.nsIInterfaceRequestor) michael@0: .getInterface(Ci.nsIDOMWindow); michael@0: waitForFocus(function() { michael@0: info("Saw install dialog"); michael@0: is(domwindow.document.location.href, XPINSTALL_URL, "Should have seen the right window open"); michael@0: michael@0: // Override the countdown timer on the accept button michael@0: var button = domwindow.document.documentElement.getButton("accept"); michael@0: button.disabled = false; michael@0: michael@0: aCallback(domwindow); michael@0: }, domwindow); michael@0: }, michael@0: michael@0: onCloseWindow: function(aXULWindow) { michael@0: }, michael@0: michael@0: onWindowTitleChange: function(aXULWindow, aNewTitle) { michael@0: } michael@0: }); michael@0: } michael@0: michael@0: function wait_for_single_notification(aCallback) { michael@0: function inner_waiter() { michael@0: info("Waiting for single notification"); michael@0: // Notification should never close while we wait michael@0: ok(PopupNotifications.isPanelOpen, "Notification should still be open"); michael@0: if (PopupNotifications.panel.childNodes.length == 2) { michael@0: executeSoon(inner_waiter); michael@0: return; michael@0: } michael@0: michael@0: aCallback(); michael@0: } michael@0: michael@0: executeSoon(inner_waiter); michael@0: } michael@0: michael@0: function setup_redirect(aSettings) { michael@0: var url = "https://example.com/browser/toolkit/mozapps/extensions/test/xpinstall/redirect.sjs?mode=setup"; michael@0: for (var name in aSettings) { michael@0: url += "&" + name + "=" + aSettings[name]; michael@0: } michael@0: michael@0: var req = new XMLHttpRequest(); michael@0: req.open("GET", url, false); michael@0: req.send(null); michael@0: } michael@0: michael@0: var TESTS = [ michael@0: function test_disabled_install() { michael@0: Services.prefs.setBoolPref("xpinstall.enabled", false); michael@0: michael@0: // Wait for the disabled notification michael@0: wait_for_notification(function(aPanel) { michael@0: let notification = aPanel.childNodes[0]; michael@0: is(notification.id, "xpinstall-disabled-notification", "Should have seen installs disabled"); michael@0: is(notification.button.label, "Enable", "Should have seen the right button"); michael@0: is(notification.getAttribute("label"), michael@0: "Software installation is currently disabled. Click Enable and try again."); michael@0: michael@0: wait_for_notification_close(function() { michael@0: try { michael@0: ok(Services.prefs.getBoolPref("xpinstall.enabled"), "Installation should be enabled"); michael@0: } michael@0: catch (e) { michael@0: ok(false, "xpinstall.enabled should be set"); michael@0: } michael@0: michael@0: gBrowser.removeTab(gBrowser.selectedTab); michael@0: michael@0: AddonManager.getAllInstalls(function(aInstalls) { michael@0: is(aInstalls.length, 1, "Should have been one install created"); michael@0: aInstalls[0].cancel(); michael@0: michael@0: runNextTest(); michael@0: }); michael@0: }); michael@0: michael@0: // Click on Enable michael@0: EventUtils.synthesizeMouseAtCenter(notification.button, {}); michael@0: }); michael@0: michael@0: var triggers = encodeURIComponent(JSON.stringify({ michael@0: "XPI": "unsigned.xpi" michael@0: })); michael@0: gBrowser.selectedTab = gBrowser.addTab(); michael@0: gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers); michael@0: }, michael@0: michael@0: function test_blocked_install() { michael@0: // Wait for the blocked notification michael@0: wait_for_notification(function(aPanel) { michael@0: let notification = aPanel.childNodes[0]; michael@0: is(notification.id, "addon-install-blocked-notification", "Should have seen the install blocked"); michael@0: is(notification.button.label, "Allow", "Should have seen the right button"); michael@0: is(notification.getAttribute("label"), michael@0: gApp + " prevented this site (example.com) from asking you to install " + michael@0: "software on your computer.", michael@0: "Should have seen the right message"); michael@0: michael@0: // Wait for the install confirmation dialog michael@0: wait_for_install_dialog(function(aWindow) { michael@0: // Wait for the complete notification michael@0: wait_for_notification(function(aPanel) { michael@0: let notification = aPanel.childNodes[0]; michael@0: is(notification.id, "addon-install-complete-notification", "Should have seen the install complete"); michael@0: is(notification.button.label, "Restart Now", "Should have seen the right button"); michael@0: is(notification.getAttribute("label"), michael@0: "XPI Test will be installed after you restart " + gApp + ".", michael@0: "Should have seen the right message"); michael@0: michael@0: AddonManager.getAllInstalls(function(aInstalls) { michael@0: is(aInstalls.length, 1, "Should be one pending install"); michael@0: aInstalls[0].cancel(); michael@0: michael@0: wait_for_notification_close(runNextTest); michael@0: gBrowser.removeTab(gBrowser.selectedTab); michael@0: }); michael@0: }); michael@0: michael@0: aWindow.document.documentElement.acceptDialog(); michael@0: }); michael@0: michael@0: // Click on Allow michael@0: EventUtils.synthesizeMouse(notification.button, 20, 10, {}); michael@0: michael@0: // Notification should have changed to progress notification michael@0: ok(PopupNotifications.isPanelOpen, "Notification should still be open"); michael@0: notification = aPanel.childNodes[0]; michael@0: is(notification.id, "addon-progress-notification", "Should have seen the progress notification"); michael@0: michael@0: }); michael@0: michael@0: var triggers = encodeURIComponent(JSON.stringify({ michael@0: "XPI": "unsigned.xpi" michael@0: })); michael@0: gBrowser.selectedTab = gBrowser.addTab(); michael@0: gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers); michael@0: }, michael@0: michael@0: function test_whitelisted_install() { michael@0: // Wait for the progress notification michael@0: wait_for_notification(function(aPanel) { michael@0: let notification = aPanel.childNodes[0]; michael@0: is(notification.id, "addon-progress-notification", "Should have seen the progress notification"); michael@0: michael@0: // Wait for the install confirmation dialog michael@0: wait_for_install_dialog(function(aWindow) { michael@0: // Wait for the complete notification michael@0: wait_for_notification(function(aPanel) { michael@0: let notification = aPanel.childNodes[0]; michael@0: is(notification.id, "addon-install-complete-notification", "Should have seen the install complete"); michael@0: is(notification.button.label, "Restart Now", "Should have seen the right button"); michael@0: is(notification.getAttribute("label"), michael@0: "XPI Test will be installed after you restart " + gApp + ".", michael@0: "Should have seen the right message"); michael@0: michael@0: AddonManager.getAllInstalls(function(aInstalls) { michael@0: is(aInstalls.length, 1, "Should be one pending install"); michael@0: aInstalls[0].cancel(); michael@0: michael@0: Services.perms.remove("example.com", "install"); michael@0: wait_for_notification_close(runNextTest); michael@0: gBrowser.removeTab(gBrowser.selectedTab); michael@0: }); michael@0: }); michael@0: michael@0: aWindow.document.documentElement.acceptDialog(); michael@0: }); michael@0: }); michael@0: michael@0: var pm = Services.perms; michael@0: pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION); michael@0: michael@0: var triggers = encodeURIComponent(JSON.stringify({ michael@0: "XPI": "unsigned.xpi" michael@0: })); michael@0: gBrowser.selectedTab = gBrowser.addTab(); michael@0: gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers); michael@0: }, michael@0: michael@0: function test_failed_download() { michael@0: // Wait for the progress notification michael@0: wait_for_notification(function(aPanel) { michael@0: let notification = aPanel.childNodes[0]; michael@0: is(notification.id, "addon-progress-notification", "Should have seen the progress notification"); michael@0: michael@0: // Wait for the failed notification michael@0: wait_for_notification(function(aPanel) { michael@0: let notification = aPanel.childNodes[0]; michael@0: is(notification.id, "addon-install-failed-notification", "Should have seen the install fail"); michael@0: is(notification.getAttribute("label"), michael@0: "The add-on could not be downloaded because of a connection failure " + michael@0: "on example.com.", michael@0: "Should have seen the right message"); michael@0: michael@0: Services.perms.remove("example.com", "install"); michael@0: wait_for_notification_close(runNextTest); michael@0: gBrowser.removeTab(gBrowser.selectedTab); michael@0: }); michael@0: }); michael@0: michael@0: var pm = Services.perms; michael@0: pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION); michael@0: michael@0: var triggers = encodeURIComponent(JSON.stringify({ michael@0: "XPI": "missing.xpi" michael@0: })); michael@0: gBrowser.selectedTab = gBrowser.addTab(); michael@0: gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers); michael@0: }, michael@0: michael@0: function test_corrupt_file() { michael@0: // Wait for the progress notification michael@0: wait_for_notification(function(aPanel) { michael@0: let notification = aPanel.childNodes[0]; michael@0: is(notification.id, "addon-progress-notification", "Should have seen the progress notification"); michael@0: michael@0: // Wait for the failed notification michael@0: wait_for_notification(function(aPanel) { michael@0: let notification = aPanel.childNodes[0]; michael@0: is(notification.id, "addon-install-failed-notification", "Should have seen the install fail"); michael@0: is(notification.getAttribute("label"), michael@0: "The add-on downloaded from example.com could not be installed " + michael@0: "because it appears to be corrupt.", michael@0: "Should have seen the right message"); michael@0: michael@0: Services.perms.remove("example.com", "install"); michael@0: wait_for_notification_close(runNextTest); michael@0: gBrowser.removeTab(gBrowser.selectedTab); michael@0: }); michael@0: }); michael@0: michael@0: var pm = Services.perms; michael@0: pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION); michael@0: michael@0: var triggers = encodeURIComponent(JSON.stringify({ michael@0: "XPI": "corrupt.xpi" michael@0: })); michael@0: gBrowser.selectedTab = gBrowser.addTab(); michael@0: gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers); michael@0: }, michael@0: michael@0: function test_incompatible() { michael@0: // Wait for the progress notification michael@0: wait_for_notification(function(aPanel) { michael@0: let notification = aPanel.childNodes[0]; michael@0: is(notification.id, "addon-progress-notification", "Should have seen the progress notification"); michael@0: michael@0: // Wait for the failed notification michael@0: wait_for_notification(function(aPanel) { michael@0: let notification = aPanel.childNodes[0]; michael@0: is(notification.id, "addon-install-failed-notification", "Should have seen the install fail"); michael@0: is(notification.getAttribute("label"), michael@0: "XPI Test could not be installed because it is not compatible with " + michael@0: gApp + " " + gVersion + ".", michael@0: "Should have seen the right message"); michael@0: michael@0: Services.perms.remove("example.com", "install"); michael@0: wait_for_notification_close(runNextTest); michael@0: gBrowser.removeTab(gBrowser.selectedTab); michael@0: }); michael@0: }); michael@0: michael@0: var pm = Services.perms; michael@0: pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION); michael@0: michael@0: var triggers = encodeURIComponent(JSON.stringify({ michael@0: "XPI": "incompatible.xpi" michael@0: })); michael@0: gBrowser.selectedTab = gBrowser.addTab(); michael@0: gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers); michael@0: }, michael@0: michael@0: function test_restartless() { michael@0: // Wait for the progress notification michael@0: wait_for_notification(function(aPanel) { michael@0: let notification = aPanel.childNodes[0]; michael@0: is(notification.id, "addon-progress-notification", "Should have seen the progress notification"); michael@0: michael@0: // Wait for the install confirmation dialog michael@0: wait_for_install_dialog(function(aWindow) { michael@0: // Wait for the complete notification michael@0: wait_for_notification(function(aPanel) { michael@0: let notification = aPanel.childNodes[0]; michael@0: is(notification.id, "addon-install-complete-notification", "Should have seen the install complete"); michael@0: is(notification.getAttribute("label"), michael@0: "XPI Test has been installed successfully.", michael@0: "Should have seen the right message"); michael@0: michael@0: AddonManager.getAllInstalls(function(aInstalls) { michael@0: is(aInstalls.length, 0, "Should be no pending installs"); michael@0: michael@0: AddonManager.getAddonByID("restartless-xpi@tests.mozilla.org", function(aAddon) { michael@0: aAddon.uninstall(); michael@0: michael@0: Services.perms.remove("example.com", "install"); michael@0: wait_for_notification_close(runNextTest); michael@0: gBrowser.removeTab(gBrowser.selectedTab); michael@0: }); michael@0: }); michael@0: }); michael@0: michael@0: aWindow.document.documentElement.acceptDialog(); michael@0: }); michael@0: }); michael@0: michael@0: var pm = Services.perms; michael@0: pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION); michael@0: michael@0: var triggers = encodeURIComponent(JSON.stringify({ michael@0: "XPI": "restartless.xpi" michael@0: })); michael@0: gBrowser.selectedTab = gBrowser.addTab(); michael@0: gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers); michael@0: }, michael@0: michael@0: function test_multiple() { michael@0: // Wait for the progress notification michael@0: wait_for_notification(function(aPanel) { michael@0: let notification = aPanel.childNodes[0]; michael@0: is(notification.id, "addon-progress-notification", "Should have seen the progress notification"); michael@0: michael@0: // Wait for the install confirmation dialog michael@0: wait_for_install_dialog(function(aWindow) { michael@0: // Wait for the complete notification michael@0: wait_for_notification(function(aPanel) { michael@0: let notification = aPanel.childNodes[0]; michael@0: is(notification.id, "addon-install-complete-notification", "Should have seen the install complete"); michael@0: is(notification.button.label, "Restart Now", "Should have seen the right button"); michael@0: is(notification.getAttribute("label"), michael@0: "2 add-ons will be installed after you restart " + gApp + ".", michael@0: "Should have seen the right message"); michael@0: michael@0: AddonManager.getAllInstalls(function(aInstalls) { michael@0: is(aInstalls.length, 1, "Should be one pending install"); michael@0: aInstalls[0].cancel(); michael@0: michael@0: AddonManager.getAddonByID("restartless-xpi@tests.mozilla.org", function(aAddon) { michael@0: aAddon.uninstall(); michael@0: michael@0: Services.perms.remove("example.com", "install"); michael@0: wait_for_notification_close(runNextTest); michael@0: gBrowser.removeTab(gBrowser.selectedTab); michael@0: }); michael@0: }); michael@0: }); michael@0: michael@0: aWindow.document.documentElement.acceptDialog(); michael@0: }); michael@0: }); michael@0: michael@0: var pm = Services.perms; michael@0: pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION); michael@0: michael@0: var triggers = encodeURIComponent(JSON.stringify({ michael@0: "Unsigned XPI": "unsigned.xpi", michael@0: "Restartless XPI": "restartless.xpi" michael@0: })); michael@0: gBrowser.selectedTab = gBrowser.addTab(); michael@0: gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers); michael@0: }, michael@0: michael@0: function test_url() { michael@0: // Wait for the progress notification michael@0: wait_for_notification(function(aPanel) { michael@0: let notification = aPanel.childNodes[0]; michael@0: is(notification.id, "addon-progress-notification", "Should have seen the progress notification"); michael@0: michael@0: // Wait for the install confirmation dialog michael@0: wait_for_install_dialog(function(aWindow) { michael@0: // Wait for the complete notification michael@0: wait_for_notification(function(aPanel) { michael@0: let notification = aPanel.childNodes[0]; michael@0: is(notification.id, "addon-install-complete-notification", "Should have seen the install complete"); michael@0: is(notification.button.label, "Restart Now", "Should have seen the right button"); michael@0: is(notification.getAttribute("label"), michael@0: "XPI Test will be installed after you restart " + gApp + ".", michael@0: "Should have seen the right message"); michael@0: michael@0: AddonManager.getAllInstalls(function(aInstalls) { michael@0: is(aInstalls.length, 1, "Should be one pending install"); michael@0: aInstalls[0].cancel(); michael@0: michael@0: wait_for_notification_close(runNextTest); michael@0: gBrowser.removeTab(gBrowser.selectedTab); michael@0: }); michael@0: }); michael@0: michael@0: aWindow.document.documentElement.acceptDialog(); michael@0: }); michael@0: }); michael@0: michael@0: gBrowser.selectedTab = gBrowser.addTab(); michael@0: gBrowser.loadURI(TESTROOT + "unsigned.xpi"); michael@0: }, michael@0: michael@0: function test_localfile() { michael@0: // Wait for the install to fail michael@0: Services.obs.addObserver(function() { michael@0: Services.obs.removeObserver(arguments.callee, "addon-install-failed"); michael@0: michael@0: // Wait for the browser code to add the failure notification michael@0: wait_for_single_notification(function() { michael@0: let notification = PopupNotifications.panel.childNodes[0]; michael@0: is(notification.id, "addon-install-failed-notification", "Should have seen the install fail"); michael@0: is(notification.getAttribute("label"), michael@0: "This add-on could not be installed because it appears to be corrupt.", michael@0: "Should have seen the right message"); michael@0: michael@0: wait_for_notification_close(runNextTest); michael@0: gBrowser.removeTab(gBrowser.selectedTab); michael@0: }); michael@0: }, "addon-install-failed", false); michael@0: michael@0: var cr = Components.classes["@mozilla.org/chrome/chrome-registry;1"] michael@0: .getService(Components.interfaces.nsIChromeRegistry); michael@0: try { michael@0: var path = cr.convertChromeURL(makeURI(CHROMEROOT + "corrupt.xpi")).spec; michael@0: } catch (ex) { michael@0: var path = CHROMEROOT + "corrupt.xpi"; michael@0: } michael@0: gBrowser.selectedTab = gBrowser.addTab(); michael@0: gBrowser.loadURI(path); michael@0: }, michael@0: michael@0: function test_wronghost() { michael@0: gBrowser.selectedTab = gBrowser.addTab(); michael@0: gBrowser.addEventListener("load", function() { michael@0: if (gBrowser.currentURI.spec != TESTROOT2 + "enabled.html") michael@0: return; michael@0: michael@0: gBrowser.removeEventListener("load", arguments.callee, true); michael@0: michael@0: // Wait for the progress notification michael@0: wait_for_notification(function(aPanel) { michael@0: let notification = aPanel.childNodes[0]; michael@0: is(notification.id, "addon-progress-notification", "Should have seen the progress notification"); michael@0: // Wait for the complete notification michael@0: wait_for_notification(function(aPanel) { michael@0: let notification = aPanel.childNodes[0]; michael@0: is(notification.id, "addon-install-failed-notification", "Should have seen the install fail"); michael@0: is(notification.getAttribute("label"), michael@0: "The add-on downloaded from example.com could not be installed " + michael@0: "because it appears to be corrupt.", michael@0: "Should have seen the right message"); michael@0: michael@0: wait_for_notification_close(runNextTest); michael@0: gBrowser.removeTab(gBrowser.selectedTab); michael@0: }); michael@0: }); michael@0: michael@0: gBrowser.loadURI(TESTROOT + "corrupt.xpi"); michael@0: }, true); michael@0: gBrowser.loadURI(TESTROOT2 + "enabled.html"); michael@0: }, michael@0: michael@0: function test_reload() { michael@0: // Wait for the progress notification michael@0: wait_for_notification(function(aPanel) { michael@0: let notification = aPanel.childNodes[0]; michael@0: is(notification.id, "addon-progress-notification", "Should have seen the progress notification"); michael@0: michael@0: // Wait for the install confirmation dialog michael@0: wait_for_install_dialog(function(aWindow) { michael@0: // Wait for the complete notification michael@0: wait_for_notification(function(aPanel) { michael@0: let notification = aPanel.childNodes[0]; michael@0: is(notification.id, "addon-install-complete-notification", "Should have seen the install complete"); michael@0: is(notification.button.label, "Restart Now", "Should have seen the right button"); michael@0: is(notification.getAttribute("label"), michael@0: "XPI Test will be installed after you restart " + gApp + ".", michael@0: "Should have seen the right message"); michael@0: michael@0: function test_fail() { michael@0: ok(false, "Reloading should not have hidden the notification"); michael@0: } michael@0: michael@0: PopupNotifications.panel.addEventListener("popuphiding", test_fail, false); michael@0: michael@0: gBrowser.addEventListener("load", function() { michael@0: if (gBrowser.currentURI.spec != TESTROOT2 + "enabled.html") michael@0: return; michael@0: michael@0: gBrowser.removeEventListener("load", arguments.callee, true); michael@0: michael@0: PopupNotifications.panel.removeEventListener("popuphiding", test_fail, false); michael@0: michael@0: AddonManager.getAllInstalls(function(aInstalls) { michael@0: is(aInstalls.length, 1, "Should be one pending install"); michael@0: aInstalls[0].cancel(); michael@0: michael@0: Services.perms.remove("example.com", "install"); michael@0: wait_for_notification_close(runNextTest); michael@0: gBrowser.removeTab(gBrowser.selectedTab); michael@0: }); michael@0: }, true); michael@0: gBrowser.loadURI(TESTROOT2 + "enabled.html"); michael@0: }); michael@0: michael@0: aWindow.document.documentElement.acceptDialog(); michael@0: }); michael@0: }); michael@0: michael@0: var pm = Services.perms; michael@0: pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION); michael@0: michael@0: var triggers = encodeURIComponent(JSON.stringify({ michael@0: "Unsigned XPI": "unsigned.xpi" michael@0: })); michael@0: gBrowser.selectedTab = gBrowser.addTab(); michael@0: gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers); michael@0: }, michael@0: michael@0: function test_theme() { michael@0: // Wait for the progress notification michael@0: wait_for_notification(function(aPanel) { michael@0: let notification = aPanel.childNodes[0]; michael@0: is(notification.id, "addon-progress-notification", "Should have seen the progress notification"); michael@0: michael@0: // Wait for the install confirmation dialog michael@0: wait_for_install_dialog(function(aWindow) { michael@0: // Wait for the complete notification michael@0: wait_for_notification(function(aPanel) { michael@0: let notification = aPanel.childNodes[0]; michael@0: is(notification.id, "addon-install-complete-notification", "Should have seen the install complete"); michael@0: is(notification.button.label, "Restart Now", "Should have seen the right button"); michael@0: is(notification.getAttribute("label"), michael@0: "Theme Test will be installed after you restart " + gApp + ".", michael@0: "Should have seen the right message"); michael@0: michael@0: AddonManager.getAddonByID("{972ce4c6-7e08-4474-a285-3208198ce6fd}", function(aAddon) { michael@0: ok(aAddon.userDisabled, "Should be switching away from the default theme."); michael@0: // Undo the pending theme switch michael@0: aAddon.userDisabled = false; michael@0: michael@0: AddonManager.getAddonByID("theme-xpi@tests.mozilla.org", function(aAddon) { michael@0: isnot(aAddon, null, "Test theme will have been installed"); michael@0: aAddon.uninstall(); michael@0: michael@0: Services.perms.remove("example.com", "install"); michael@0: wait_for_notification_close(runNextTest); michael@0: gBrowser.removeTab(gBrowser.selectedTab); michael@0: }); michael@0: }); michael@0: }); michael@0: michael@0: aWindow.document.documentElement.acceptDialog(); michael@0: }); michael@0: }); michael@0: michael@0: var pm = Services.perms; michael@0: pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION); michael@0: michael@0: var triggers = encodeURIComponent(JSON.stringify({ michael@0: "Theme XPI": "theme.xpi" michael@0: })); michael@0: gBrowser.selectedTab = gBrowser.addTab(); michael@0: gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers); michael@0: }, michael@0: michael@0: function test_renotify_blocked() { michael@0: // Wait for the blocked notification michael@0: wait_for_notification(function(aPanel) { michael@0: let notification = aPanel.childNodes[0]; michael@0: is(notification.id, "addon-install-blocked-notification", "Should have seen the install blocked"); michael@0: michael@0: wait_for_notification_close(function () { michael@0: info("Timeouts after this probably mean bug 589954 regressed"); michael@0: executeSoon(function () { michael@0: wait_for_notification(function(aPanel) { michael@0: let notification = aPanel.childNodes[0]; michael@0: is(notification.id, "addon-install-blocked-notification", michael@0: "Should have seen the install blocked - 2nd time"); michael@0: michael@0: AddonManager.getAllInstalls(function(aInstalls) { michael@0: is(aInstalls.length, 2, "Should be two pending installs"); michael@0: aInstalls[0].cancel(); michael@0: aInstalls[1].cancel(); michael@0: michael@0: info("Closing browser tab"); michael@0: wait_for_notification_close(runNextTest); michael@0: gBrowser.removeTab(gBrowser.selectedTab); michael@0: }); michael@0: }); michael@0: michael@0: gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers); michael@0: }); michael@0: }); michael@0: michael@0: // hide the panel (this simulates the user dismissing it) michael@0: aPanel.hidePopup(); michael@0: }); michael@0: michael@0: var triggers = encodeURIComponent(JSON.stringify({ michael@0: "XPI": "unsigned.xpi" michael@0: })); michael@0: gBrowser.selectedTab = gBrowser.addTab(); michael@0: gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers); michael@0: }, michael@0: michael@0: function test_renotify_installed() { michael@0: // Wait for the progress notification michael@0: wait_for_notification(function(aPanel) { michael@0: let notification = aPanel.childNodes[0]; michael@0: is(notification.id, "addon-progress-notification", "Should have seen the progress notification"); michael@0: michael@0: // Wait for the install confirmation dialog michael@0: wait_for_install_dialog(function(aWindow) { michael@0: // Wait for the complete notification michael@0: wait_for_notification(function(aPanel) { michael@0: let notification = aPanel.childNodes[0]; michael@0: is(notification.id, "addon-install-complete-notification", "Should have seen the install complete"); michael@0: michael@0: // Dismiss the notification michael@0: wait_for_notification_close(function () { michael@0: // Install another michael@0: executeSoon(function () { michael@0: // Wait for the progress notification michael@0: wait_for_notification(function(aPanel) { michael@0: let notification = aPanel.childNodes[0]; michael@0: is(notification.id, "addon-progress-notification", "Should have seen the progress notification"); michael@0: michael@0: // Wait for the install confirmation dialog michael@0: wait_for_install_dialog(function(aWindow) { michael@0: info("Timeouts after this probably mean bug 589954 regressed"); michael@0: michael@0: // Wait for the complete notification michael@0: wait_for_notification(function(aPanel) { michael@0: let notification = aPanel.childNodes[0]; michael@0: is(notification.id, "addon-install-complete-notification", "Should have seen the second install complete"); michael@0: michael@0: AddonManager.getAllInstalls(function(aInstalls) { michael@0: is(aInstalls.length, 1, "Should be one pending installs"); michael@0: aInstalls[0].cancel(); michael@0: michael@0: Services.perms.remove("example.com", "install"); michael@0: wait_for_notification_close(runNextTest); michael@0: gBrowser.removeTab(gBrowser.selectedTab); michael@0: }); michael@0: }); michael@0: michael@0: aWindow.document.documentElement.acceptDialog(); michael@0: }); michael@0: }); michael@0: michael@0: gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers); michael@0: }); michael@0: }); michael@0: michael@0: // hide the panel (this simulates the user dismissing it) michael@0: aPanel.hidePopup(); michael@0: }); michael@0: michael@0: aWindow.document.documentElement.acceptDialog(); michael@0: }); michael@0: }); michael@0: michael@0: var pm = Services.perms; michael@0: pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION); michael@0: michael@0: var triggers = encodeURIComponent(JSON.stringify({ michael@0: "XPI": "unsigned.xpi" michael@0: })); michael@0: gBrowser.selectedTab = gBrowser.addTab(); michael@0: gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers); michael@0: }, michael@0: michael@0: function test_cancel_restart() { michael@0: // Wait for the progress notification michael@0: wait_for_notification(function(aPanel) { michael@0: let notification = aPanel.childNodes[0]; michael@0: is(notification.id, "addon-progress-notification", "Should have seen the progress notification"); michael@0: michael@0: // Close the notification michael@0: let anchor = document.getElementById("addons-notification-icon"); michael@0: anchor.click(); michael@0: // Reopen the notification michael@0: anchor.click(); michael@0: michael@0: ok(PopupNotifications.isPanelOpen, "Notification should still be open"); michael@0: is(PopupNotifications.panel.childNodes.length, 1, "Should be only one notification"); michael@0: isnot(notification, aPanel.childNodes[0], "Should have reconstructed the notification UI"); michael@0: notification = aPanel.childNodes[0]; michael@0: is(notification.id, "addon-progress-notification", "Should have seen the progress notification"); michael@0: let button = document.getAnonymousElementByAttribute(notification, "anonid", "cancel"); michael@0: michael@0: // Cancel the download michael@0: EventUtils.synthesizeMouse(button, 2, 2, {}); michael@0: michael@0: // Notification should have changed to cancelled michael@0: notification = aPanel.childNodes[0]; michael@0: is(notification.id, "addon-install-cancelled-notification", "Should have seen the cancelled notification"); michael@0: michael@0: // Wait for the install confirmation dialog michael@0: wait_for_install_dialog(function(aWindow) { michael@0: // Wait for the complete notification michael@0: wait_for_notification(function(aPanel) { michael@0: let notification = aPanel.childNodes[0]; michael@0: is(notification.id, "addon-install-complete-notification", "Should have seen the install complete"); michael@0: is(notification.button.label, "Restart Now", "Should have seen the right button"); michael@0: is(notification.getAttribute("label"), michael@0: "XPI Test will be installed after you restart " + gApp + ".", michael@0: "Should have seen the right message"); michael@0: michael@0: AddonManager.getAllInstalls(function(aInstalls) { michael@0: is(aInstalls.length, 1, "Should be one pending install"); michael@0: aInstalls[0].cancel(); michael@0: michael@0: Services.perms.remove("example.com", "install"); michael@0: wait_for_notification_close(runNextTest); michael@0: gBrowser.removeTab(gBrowser.selectedTab); michael@0: }); michael@0: }); michael@0: michael@0: aWindow.document.documentElement.acceptDialog(); michael@0: }); michael@0: michael@0: // Restart the download michael@0: EventUtils.synthesizeMouse(notification.button, 20, 10, {}); michael@0: michael@0: // Should be back to a progress notification michael@0: ok(PopupNotifications.isPanelOpen, "Notification should still be open"); michael@0: is(PopupNotifications.panel.childNodes.length, 1, "Should be only one notification"); michael@0: notification = aPanel.childNodes[0]; michael@0: is(notification.id, "addon-progress-notification", "Should have seen the progress notification"); michael@0: }); michael@0: michael@0: var pm = Services.perms; michael@0: pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION); michael@0: michael@0: var triggers = encodeURIComponent(JSON.stringify({ michael@0: "XPI": "unsigned.xpi" michael@0: })); michael@0: gBrowser.selectedTab = gBrowser.addTab(); michael@0: gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers); michael@0: }, michael@0: michael@0: function test_failed_security() { michael@0: Services.prefs.setBoolPref(PREF_INSTALL_REQUIREBUILTINCERTS, false); michael@0: michael@0: setup_redirect({ michael@0: "Location": TESTROOT + "unsigned.xpi" michael@0: }); michael@0: michael@0: // Wait for the blocked notification michael@0: wait_for_notification(function(aPanel) { michael@0: let notification = aPanel.childNodes[0]; michael@0: is(notification.id, "addon-install-blocked-notification", "Should have seen the install blocked"); michael@0: michael@0: // Click on Allow michael@0: EventUtils.synthesizeMouse(notification.button, 20, 10, {}); michael@0: michael@0: // Notification should have changed to progress notification michael@0: ok(PopupNotifications.isPanelOpen, "Notification should still be open"); michael@0: is(PopupNotifications.panel.childNodes.length, 1, "Should be only one notification"); michael@0: notification = aPanel.childNodes[0]; michael@0: is(notification.id, "addon-progress-notification", "Should have seen the progress notification"); michael@0: michael@0: // Wait for it to fail michael@0: Services.obs.addObserver(function() { michael@0: Services.obs.removeObserver(arguments.callee, "addon-install-failed"); michael@0: michael@0: // Allow the browser code to add the failure notification and then wait michael@0: // for the progress notification to dismiss itself michael@0: wait_for_single_notification(function() { michael@0: is(PopupNotifications.panel.childNodes.length, 1, "Should be only one notification"); michael@0: notification = aPanel.childNodes[0]; michael@0: is(notification.id, "addon-install-failed-notification", "Should have seen the install fail"); michael@0: michael@0: Services.prefs.setBoolPref(PREF_INSTALL_REQUIREBUILTINCERTS, true); michael@0: wait_for_notification_close(runNextTest); michael@0: gBrowser.removeTab(gBrowser.selectedTab); michael@0: }); michael@0: }, "addon-install-failed", false); michael@0: }); michael@0: michael@0: var triggers = encodeURIComponent(JSON.stringify({ michael@0: "XPI": "redirect.sjs?mode=redirect" michael@0: })); michael@0: gBrowser.selectedTab = gBrowser.addTab(); michael@0: gBrowser.loadURI(SECUREROOT + "installtrigger.html?" + triggers); michael@0: } michael@0: ]; michael@0: michael@0: var gTestStart = null; michael@0: michael@0: function runNextTest() { michael@0: if (gTestStart) michael@0: info("Test part took " + (Date.now() - gTestStart) + "ms"); michael@0: michael@0: ok(!PopupNotifications.isPanelOpen, "Notification should be closed"); michael@0: michael@0: AddonManager.getAllInstalls(function(aInstalls) { michael@0: is(aInstalls.length, 0, "Should be no active installs"); michael@0: michael@0: if (TESTS.length == 0) { michael@0: finish(); michael@0: return; michael@0: } michael@0: michael@0: info("Running " + TESTS[0].name); michael@0: gTestStart = Date.now(); michael@0: TESTS.shift()(); michael@0: }); michael@0: }; michael@0: michael@0: var XPInstallObserver = { michael@0: observe: function (aSubject, aTopic, aData) { michael@0: var installInfo = aSubject.QueryInterface(Components.interfaces.amIWebInstallInfo); michael@0: info("Observed " + aTopic + " for " + installInfo.installs.length + " installs"); michael@0: installInfo.installs.forEach(function(aInstall) { michael@0: info("Install of " + aInstall.sourceURI.spec + " was in state " + aInstall.state); michael@0: }); michael@0: } michael@0: }; michael@0: michael@0: function test() { michael@0: requestLongerTimeout(4); michael@0: waitForExplicitFinish(); michael@0: michael@0: Services.prefs.setBoolPref("extensions.logging.enabled", true); michael@0: Services.prefs.setBoolPref("extensions.strictCompatibility", true); michael@0: michael@0: Services.obs.addObserver(XPInstallObserver, "addon-install-started", false); michael@0: Services.obs.addObserver(XPInstallObserver, "addon-install-blocked", false); michael@0: Services.obs.addObserver(XPInstallObserver, "addon-install-failed", false); michael@0: Services.obs.addObserver(XPInstallObserver, "addon-install-complete", false); michael@0: michael@0: PopupNotifications.transitionsEnabled = false; michael@0: michael@0: registerCleanupFunction(function() { michael@0: // Make sure no more test parts run in case we were timed out michael@0: TESTS = []; michael@0: PopupNotifications.panel.removeEventListener("popupshown", check_notification, false); michael@0: PopupNotifications.transitionsEnabled = true; michael@0: michael@0: AddonManager.getAllInstalls(function(aInstalls) { michael@0: aInstalls.forEach(function(aInstall) { michael@0: aInstall.cancel(); michael@0: }); michael@0: }); michael@0: michael@0: Services.prefs.clearUserPref("extensions.logging.enabled"); michael@0: Services.prefs.clearUserPref("extensions.strictCompatibility"); michael@0: michael@0: Services.obs.removeObserver(XPInstallObserver, "addon-install-started"); michael@0: Services.obs.removeObserver(XPInstallObserver, "addon-install-blocked"); michael@0: Services.obs.removeObserver(XPInstallObserver, "addon-install-failed"); michael@0: Services.obs.removeObserver(XPInstallObserver, "addon-install-complete"); michael@0: }); michael@0: michael@0: runNextTest(); michael@0: }