bug 1455269 - Cancel installation on notification dismissal. r=aswan, a=RyanVM
authorTomislav Jovanovic <tomica@gmail.com>
Thu, 17 May 2018 20:46:21 +0200
changeset 473551 251c38d653d08ec7c7b13a60a70d57283f29c65e
parent 473550 55923d75814212a1e137e17fe90962bdc5bfcd99
child 473552 228c94554dc0c2b5e4e1dac285d38d97fe778614
push id1728
push userjlund@mozilla.com
push dateMon, 18 Jun 2018 21:12:27 +0000
treeherdermozilla-release@c296fde26f5f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaswan, RyanVM
bugs1455269
milestone61.0
bug 1455269 - Cancel installation on notification dismissal. r=aswan, a=RyanVM MozReview-Commit-ID: DqbgdVTarQ8
browser/base/content/test/webextensions/browser.ini
browser/base/content/test/webextensions/browser_permissions_dismiss.js
browser/modules/ExtensionsUI.jsm
--- a/browser/base/content/test/webextensions/browser.ini
+++ b/browser/base/content/test/webextensions/browser.ini
@@ -15,16 +15,17 @@ support-files =
   browser_webext_update_perms2.xpi
   browser_webext_update_origins1.xpi
   browser_webext_update_origins2.xpi
   browser_webext_update.json
 
 [browser_extension_sideloading.js]
 [browser_extension_update_background.js]
 [browser_extension_update_background_noprompt.js]
+[browser_permissions_dismiss.js]
 [browser_permissions_installTrigger.js]
 [browser_permissions_local_file.js]
 [browser_permissions_mozAddonManager.js]
 [browser_permissions_optional.js]
 skip-if = !e10s
 [browser_permissions_pointerevent.js]
 [browser_permissions_unsigned.js]
 skip-if = require_signing
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/webextensions/browser_permissions_dismiss.js
@@ -0,0 +1,47 @@
+"use strict";
+
+const INSTALL_PAGE = `${BASE}/file_install_extensions.html`;
+const INSTALL_XPI = `${BASE}/browser_webext_permissions.xpi`;
+
+add_task(async function setup() {
+  await SpecialPowers.pushPrefEnv({set: [
+    ["extensions.webapi.testing", true],
+    ["extensions.install.requireBuiltInCerts", false],
+  ]});
+
+  registerCleanupFunction(async () => {
+    await SpecialPowers.popPrefEnv();
+  });
+});
+
+add_task(async function test_tab_switch_dismiss() {
+  let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, INSTALL_PAGE);
+
+  let installCanceled = new Promise(resolve => {
+    let listener = {
+      onInstallCancelled() {
+        AddonManager.removeInstallListener(listener);
+        resolve();
+      },
+    };
+    AddonManager.addInstallListener(listener);
+  });
+
+  ContentTask.spawn(gBrowser.selectedBrowser, INSTALL_XPI, function(url) {
+    content.wrappedJSObject.installMozAM(url);
+  });
+
+  await promisePopupNotificationShown("addon-webext-permissions");
+  let permsUL = document.getElementById("addon-webext-perm-list");
+  is(permsUL.childElementCount, 5, `Permissions list has 5 entries`);
+
+  // Switching tabs dismisses the notification and cancels the install.
+  let switchTo = await BrowserTestUtils.openNewForegroundTab(gBrowser);
+  BrowserTestUtils.removeTab(switchTo);
+  await installCanceled;
+
+  let addon = await AddonManager.getAddonByID("permissions@test.mozilla.org");
+  is(addon, null, "Extension is not installed");
+
+  BrowserTestUtils.removeTab(tab);
+});
--- a/browser/modules/ExtensionsUI.jsm
+++ b/browser/modules/ExtensionsUI.jsm
@@ -348,30 +348,31 @@ var ExtensionsUI = {
           for (let msg of strings.msgs) {
             let item = doc.createElementNS(HTML_NS, "li");
             item.textContent = msg;
             list.appendChild(item);
           }
         } else if (topic == "swapping") {
           return true;
         }
-        if (topic == "removed" || topic == "dismissed") {
+        if (topic == "removed") {
           Services.tm.dispatchToMainThread(() => {
             resolve(false);
           });
         }
         return false;
       }
 
       let popupOptions = {
         hideClose: true,
         popupIconURL: icon || DEFAULT_EXTENSION_ICON,
         persistent: true,
         eventCallback,
         name: strings.addonName,
+        removeOnDismissal: true,
       };
 
       let action = {
         label: strings.acceptText,
         accessKey: strings.acceptKey,
         callback: () => {
           if (histkey) {
             this.histogram.add(histkey + "Accepted");