Bug 1644519 - Remove code duplication in browser_doorhanger_installs.js. r=mixedpuppy
authorAgi Sferro <agi@sferro.dev>
Thu, 11 Jun 2020 23:38:20 +0000
changeset 535530 033ba8f1c3a2d6c0cb8929efe4a447e8148afa8b
parent 535529 54d2a804aa1deeb83710e0f6e79d268b4fc01d2e
child 535531 0b4d785bd7a16c1ccbac06957ee784d3f5c49750
push id118907
push userasferro@mozilla.com
push dateFri, 12 Jun 2020 17:50:34 +0000
treeherderautoland@0b4d785bd7a1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmixedpuppy
bugs1644519
milestone79.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 1644519 - Remove code duplication in browser_doorhanger_installs.js. r=mixedpuppy Differential Revision: https://phabricator.services.mozilla.com/D79381
toolkit/mozapps/extensions/test/xpinstall/browser_doorhanger_installs.js
--- a/toolkit/mozapps/extensions/test/xpinstall/browser_doorhanger_installs.js
+++ b/toolkit/mozapps/extensions/test/xpinstall/browser_doorhanger_installs.js
@@ -118,21 +118,24 @@ async function waitForProgressNotificati
     );
   }
 
   return PopupNotifications.panel;
 }
 
 function acceptAppMenuNotificationWhenShown(
   id,
-  { dismiss = false, checkIncognito = false, incognitoChecked = false } = {}
+  {
+    dismiss = false,
+    checkIncognito = false,
+    incognitoChecked = false,
+    global = window,
+  } = {}
 ) {
-  const { AppMenuNotifications } = ChromeUtils.import(
-    "resource://gre/modules/AppMenuNotifications.jsm"
-  );
+  const { AppMenuNotifications, PanelUI, document } = global;
   return new Promise(resolve => {
     function appMenuPopupHidden() {
       PanelUI.panel.removeEventListener("popuphidden", appMenuPopupHidden);
       is(
         PanelUI.menuButton.getAttribute("badge-status"),
         false,
         "badge is not set after addon-installed"
       );
@@ -1062,48 +1065,21 @@ var TESTS = [
     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();
-
+    let notificationPromise = acceptAppMenuNotificationWhenShown(
+      "addon-installed",
+      { incognitoChecked: true, global: win }
+    );
+    acceptInstallDialog(installDialog);
     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"
     );