Bug 1636994, ensure panel is created before showing addon install notification r=Gijs,robwu
authorEmma Malysz <emalysz@mozilla.com>
Fri, 22 May 2020 17:00:44 +0000
changeset 531760 6cd8944abc662799cf0b1d273e5f3013abc6d49f
parent 531759 625f46790646368f7aa9163db21121b90c6cd593
child 531761 301cb0eb1e488475ab9f48210c12b87887d7ae0b
push id37443
push usercbrindusan@mozilla.com
push dateSat, 23 May 2020 21:42:57 +0000
treeherdermozilla-central@9a2f741cef6a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersGijs, robwu
bugs1636994
milestone78.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1636994, ensure panel is created before showing addon install notification r=Gijs,robwu Differential Revision: https://phabricator.services.mozilla.com/D76166
browser/modules/ExtensionsUI.jsm
toolkit/mozapps/extensions/test/xpinstall/browser_doorhanger_installs.js
--- a/browser/modules/ExtensionsUI.jsm
+++ b/browser/modules/ExtensionsUI.jsm
@@ -525,17 +525,16 @@ var ExtensionsUI = {
       function setCheckbox(win) {
         let checkbox = win.document.getElementById("addon-incognito-checkbox");
         checkbox.checked = hasIncognito;
         checkbox.hidden = !(
           addon.permissions &
           AddonManager.PERM_CAN_CHANGE_PRIVATEBROWSING_ACCESS
         );
       }
-      setCheckbox(window);
 
       async function actionResolve(win) {
         let checkbox = win.document.getElementById("addon-incognito-checkbox");
 
         if (checkbox.checked == hasIncognito) {
           resolve();
           return;
         }
--- a/toolkit/mozapps/extensions/test/xpinstall/browser_doorhanger_installs.js
+++ b/toolkit/mozapps/extensions/test/xpinstall/browser_doorhanger_installs.js
@@ -392,17 +392,17 @@ var TESTS = [
     await notificationPromise;
 
     let installs = await AddonManager.getAllInstalls();
     is(installs.length, 0, "Should be no pending installs");
 
     let addon = await AddonManager.getAddonByID(
       "amosigned-xpi@tests.mozilla.org"
     );
-    addon.uninstall();
+    await addon.uninstall();
 
     await BrowserTestUtils.removeTab(gBrowser.selectedTab);
   },
 
   async function test_permaBlockInstall() {
     let notificationPromise = waitForNotification("addon-install-blocked");
     let triggers = encodeURIComponent(
       JSON.stringify({
@@ -527,17 +527,17 @@ var TESTS = [
     // have been set if possible.
     await addon.reload();
     let policy = WebExtensionPolicy.getByID(addon.id);
     ok(
       !policy.privateBrowsingAllowed,
       "private browsing permission was not granted"
     );
 
-    addon.uninstall();
+    await addon.uninstall();
 
     PermissionTestUtils.remove("http://example.com/", "install");
 
     Services.prefs.clearUserPref("extensions.allowPrivateBrowsingByDefault");
     await removeTabAndWaitForNotificationClose();
   },
 
   async function test_failedDownload() {
@@ -735,17 +735,17 @@ var TESTS = [
             type: "extension",
           },
         },
       ],
       "Expect telemetry events for privateBrowsingAllowed action",
       { actionType: "privateBrowsingAllowed" }
     );
 
-    addon.uninstall();
+    await addon.uninstall();
 
     Services.prefs.clearUserPref("extensions.allowPrivateBrowsingByDefault");
 
     await removeTabAndWaitForNotificationClose();
   },
 
   async function test_wrongHost() {
     let requestedUrl = TESTROOT2 + "enabled.html";
@@ -1009,21 +1009,145 @@ var TESTS = [
             type: "extension",
           },
         },
       ],
       "Expect telemetry events for privateBrowsingAllowed action",
       { actionType: "privateBrowsingAllowed" }
     );
 
-    addon.uninstall();
+    await addon.uninstall();
 
     await removeTabAndWaitForNotificationClose();
     await SpecialPowers.popPrefEnv();
   },
+
+  async function test_incognito_checkbox_new_window() {
+    SpecialPowers.pushPrefEnv({
+      set: [["extensions.allowPrivateBrowsingByDefault", false]],
+    });
+    let win = await BrowserTestUtils.openNewBrowserWindow();
+    await SimpleTest.promiseFocus(win);
+    // Grant permission up front.
+    const permissionName = "internal:privateBrowsingAllowed";
+    let incognitoPermission = {
+      permissions: [permissionName],
+      origins: [],
+    };
+    await ExtensionPermissions.add(
+      "amosigned-xpi@tests.mozilla.org",
+      incognitoPermission
+    );
+
+    let panelEventPromise = new Promise(resolve => {
+      win.PopupNotifications.panel.addEventListener(
+        "PanelUpdated",
+        function eventListener(e) {
+          if (e.detail.includes("addon-webext-permissions")) {
+            win.PopupNotifications.panel.removeEventListener(
+              "PanelUpdated",
+              eventListener
+            );
+            resolve();
+          }
+        }
+      );
+    });
+
+    win.gBrowser.selectedTab = BrowserTestUtils.addTab(
+      win.gBrowser,
+      "about:blank"
+    );
+    await BrowserTestUtils.browserLoaded(win.gBrowser.selectedBrowser);
+    win.gURLBar.value = TESTROOT + "amosigned.xpi";
+    win.gURLBar.focus();
+    EventUtils.synthesizeKey("KEY_Enter", {}, win);
+
+    await panelEventPromise;
+    await waitForTick();
+
+    let panel = win.PopupNotifications.panel;
+    let installDialog = panel.childNodes[0];
+
+    let notificationPromise = new Promise(resolve => {
+      function popupshown() {
+        let notification = win.AppMenuNotifications.activeNotification;
+        if (!notification) {
+          return;
+        }
+
+        ok(win.PanelUI.isNotificationPanelOpen, "notification panel open");
+
+        win.PanelUI.notificationPanel.removeEventListener(
+          "popupshown",
+          popupshown
+        );
+
+        let checkbox = win.document.getElementById("addon-incognito-checkbox");
+        ok(!checkbox.hidden, "checkbox visibility is correct");
+        ok(checkbox.checked, "checkbox is marked as expected");
+        checkbox.checked = false;
+
+        // Dismiss the panel by clicking the primary button.
+        let popupnotificationID = win.PanelUI._getPopupId(notification);
+        let popupnotification = win.document.getElementById(
+          popupnotificationID
+        );
+        popupnotification.button.click();
+        resolve();
+      }
+      win.document.addEventListener("popupshown", popupshown);
+    });
+
+    installDialog.button.click();
+
+    await notificationPromise;
+
+    let installs = await AddonManager.getAllInstalls();
+    is(installs.length, 0, "Should be no pending installs");
+
+    let addon = await AddonManager.getAddonByID(
+      "amosigned-xpi@tests.mozilla.org"
+    );
+    // The panel is reloading the addon due to the permission change, we need some way
+    // to wait for the reload to finish. addon.startupPromise doesn't do it for
+    // us, so we'll just restart again.
+    await AddonTestUtils.promiseWebExtensionStartup(
+      "amosigned-xpi@tests.mozilla.org"
+    );
+
+    // This addon should no longer have private browsing permission.
+    let policy = WebExtensionPolicy.getByID(addon.id);
+    ok(!policy.privateBrowsingAllowed, "private browsing permission removed");
+
+    // Verify that the expected telemetry event has been collected for the extension allowed on
+    // PB windows from the "post install" notification doorhanger.
+    assertActionAMTelemetryEvent(
+      [
+        {
+          method: "action",
+          object: "doorhanger",
+          value: "off",
+          extra: {
+            action: "privateBrowsingAllowed",
+            view: "postInstall",
+            addonId: addon.id,
+            type: "extension",
+          },
+        },
+      ],
+      "Expect telemetry events for privateBrowsingAllowed action",
+      { actionType: "privateBrowsingAllowed" }
+    );
+
+    await addon.uninstall();
+
+    await SpecialPowers.popPrefEnv();
+    await BrowserTestUtils.closeWindow(win);
+  },
 ];
 
 var gTestStart = null;
 
 var XPInstallObserver = {
   observe(aSubject, aTopic, aData) {
     var installInfo = aSubject.wrappedJSObject;
     info(