diff --git a/browser/base/content/browser-addons.js b/browser/base/content/browser-addons.js index 6f721f6e5169..4132cf84b1a5 100644 --- a/browser/base/content/browser-addons.js +++ b/browser/base/content/browser-addons.js @@ -54,6 +54,22 @@ const gXPInstallObserver = { // originatingURI might be missing or 'host' might throw for non-nsStandardURL nsIURIs. } + let cancelInstallation = () => { + if (installInfo) { + for (let install of installInfo.installs) + install.cancel(); + } + + if (aTopic == "addon-install-confirmation") + this.acceptInstallation = null; + + let tab = gBrowser.getTabForBrowser(browser); + if (tab) + tab.removeEventListener("TabClose", cancelInstallation); + + window.removeEventListener("unload", cancelInstallation); + }; + switch (aTopic) { case "addon-install-disabled": { notificationID = "xpinstall-disabled"; @@ -170,11 +186,7 @@ const gXPInstallObserver = { options.eventCallback = (aEvent) => { switch (aEvent) { case "removed": - if (installInfo) { - for (let install of installInfo.installs) - install.cancel(); - } - this.acceptInstallation = null; + cancelInstallation(); break; case "shown": let addonList = document.getElementById("addon-install-confirmation-content"); @@ -247,8 +259,12 @@ const gXPInstallObserver = { let showNotification = () => { let tab = gBrowser.getTabForBrowser(browser); - if (tab) + if (tab) { gBrowser.selectedTab = tab; + tab.addEventListener("TabClose", cancelInstallation); + } + + window.addEventListener("unload", cancelInstallation); if (PopupNotifications.isPanelOpen) { let rect = document.getElementById("addon-progress-notification").getBoundingClientRect(); diff --git a/browser/base/content/test/general/browser_bug553455.js b/browser/base/content/test/general/browser_bug553455.js index 69dc63058f80..e0560b751de3 100644 --- a/browser/base/content/test/general/browser_bug553455.js +++ b/browser/base/content/test/general/browser_bug553455.js @@ -620,6 +620,35 @@ function test_localfile() { gBrowser.loadURI(path); }, +function test_tabclose() { + if (!Preferences.get("xpinstall.customConfirmationUI", false)) { + runNextTest(); + return; + } + + // Wait for the progress notification + wait_for_progress_notification(aPanel => { + // Wait for the install confirmation dialog + wait_for_install_dialog(() => { + AddonManager.getAllInstalls(aInstalls => { + is(aInstalls.length, 1, "Should be one pending install"); + + wait_for_notification_close(() => { + AddonManager.getAllInstalls(aInstalls => { + is(aInstalls.length, 0, "Should be no pending install since the tab is closed"); + runNextTest(); + }); + }); + + gBrowser.removeTab(gBrowser.selectedTab); + }); + }); + }); + + gBrowser.selectedTab = gBrowser.addTab(); + gBrowser.loadURI(TESTROOT + "unsigned.xpi"); +}, + function test_wronghost() { gBrowser.selectedTab = gBrowser.addTab(); gBrowser.addEventListener("load", function() {