Bug 1177176 - Support opening the Control Center panel via UITour.showMenu. r=bgrins
authorMatthew Noorenberghe <mozilla@noorenberghe.ca>
Fri, 17 Jul 2015 16:30:37 -0700
changeset 253554 1077ce98bd4458a501acd00df17dc503f6794477
parent 253553 b0f982865190763e139d8716c9cd5610539b850b
child 253555 850d33233360f1a418e26890fa8c3a728be2ccdf
push id29070
push userttaubert@mozilla.com
push dateMon, 20 Jul 2015 07:15:19 +0000
treeherdermozilla-central@202e9233d130 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbgrins
bugs1177176
milestone42.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 1177176 - Support opening the Control Center panel via UITour.showMenu. r=bgrins
browser/components/uitour/UITour.jsm
browser/components/uitour/test/browser.ini
browser/components/uitour/test/browser_showMenu_controlCenter.js
--- a/browser/components/uitour/UITour.jsm
+++ b/browser/components/uitour/UITour.jsm
@@ -864,24 +864,27 @@ this.UITour = {
       openTourBrowsers.delete(aBrowser);
     }
 
     this.hideHighlight(aWindow);
     this.hideInfo(aWindow);
     // Ensure the menu panel is hidden before calling recreatePopup so popup events occur.
     this.hideMenu(aWindow, "appMenu");
     this.hideMenu(aWindow, "loop");
+    this.hideMenu(aWindow, "controlCenter");
 
     // Clean up panel listeners after calling hideMenu above.
     aWindow.PanelUI.panel.removeEventListener("popuphiding", this.hideAppMenuAnnotations);
     aWindow.PanelUI.panel.removeEventListener("ViewShowing", this.hideAppMenuAnnotations);
     aWindow.PanelUI.panel.removeEventListener("popuphidden", this.onPanelHidden);
     let loopPanel = aWindow.document.getElementById("loop-notification-panel");
     loopPanel.removeEventListener("popuphidden", this.onPanelHidden);
     loopPanel.removeEventListener("popuphiding", this.hideLoopPanelAnnotations);
+    let controlCenterPanel = aWindow.gIdentityHandler._identityPopup;
+    controlCenterPanel.removeEventListener("popuphiding", this.hideControlCenterAnnotations);
 
     this.endUrlbarCapture(aWindow);
     this.resetTheme();
 
     // If there are no more tour tabs left in the window, teardown the tour for the whole window.
     if (!openTourBrowsers || openTourBrowsers.size == 0) {
       this.teardownTourForWindow(aWindow);
     }
@@ -1551,16 +1554,35 @@ this.UITour = {
       aWindow.PanelUI.panel.addEventListener("popuphidden", this.onPanelHidden);
       if (aOpenCallback) {
         aWindow.PanelUI.panel.addEventListener("popupshown", onPopupShown);
       }
       aWindow.PanelUI.show();
     } else if (aMenuName == "bookmarks") {
       let menuBtn = aWindow.document.getElementById("bookmarks-menu-button");
       openMenuButton(menuBtn);
+    } else if (aMenuName == "controlCenter") {
+      let popup = aWindow.gIdentityHandler._identityPopup;
+
+      // Add the listener even if the panel is already open since it will still
+      // only get registered once even if it was UITour that opened it.
+      popup.addEventListener("popuphiding", this.hideControlCenterAnnotations);
+
+      if (popup.state == "open") {
+        if (aOpenCallback) {
+          aOpenCallback();
+        }
+        return;
+      }
+
+      // Open the control center
+      if (aOpenCallback) {
+        popup.addEventListener("popupshown", onPopupShown);
+      }
+      aWindow.document.getElementById("identity-box").click();
     } else if (aMenuName == "loop") {
       let toolbarButton = aWindow.LoopUI.toolbarButton;
       // It's possible to have a node that isn't placed anywhere
       if (!toolbarButton || !toolbarButton.node ||
           !CustomizableUI.getPlacementOfWidget(toolbarButton.node.id)) {
         log.debug("Can't show the Loop menu since the toolbarButton isn't placed");
         return;
       }
@@ -1635,16 +1657,19 @@ this.UITour = {
         aMenuBtn.boxObject.openMenu(false);
     }
 
     if (aMenuName == "appMenu") {
       aWindow.PanelUI.hide();
     } else if (aMenuName == "bookmarks") {
       let menuBtn = aWindow.document.getElementById("bookmarks-menu-button");
       closeMenuButton(menuBtn);
+    } else if (aMenuName == "controlCenter") {
+      let panel = aWindow.gIdentityHandler._identityPopup;
+      panel.hidePopup();
     } else if (aMenuName == "loop") {
       let panel = aWindow.document.getElementById("loop-notification-panel");
       panel.hidePopup();
     } else if (aMenuName == "searchEngines") {
       let menuBtn = this.targets.get("searchProvider").query(aWindow.document);
       closeMenuButton(menuBtn);
     }
   },
@@ -1679,16 +1704,22 @@ this.UITour = {
   },
 
   hideLoopPanelAnnotations: function(aEvent) {
     UITour.hideAnnotationsForPanel(aEvent, (aTarget) => {
       return aTarget.targetName.startsWith("loop-") && aTarget.targetName != "loop-selectedRoomButtons";
     });
   },
 
+  hideControlCenterAnnotations(aEvent) {
+    UITour.hideAnnotationsForPanel(aEvent, (aTarget) => {
+      return aTarget.targetName.startsWith("controlCenter-");
+    });
+  },
+
   onPanelHidden: function(aEvent) {
     aEvent.target.removeAttribute("noautohide");
     UITour.recreatePopup(aEvent.target);
   },
 
   recreatePopup: function(aPanel) {
     // After changing popup attributes that relate to how the native widget is created
     // (e.g. @noautohide) we need to re-create the frame/widget for it to take effect.
--- a/browser/components/uitour/test/browser.ini
+++ b/browser/components/uitour/test/browser.ini
@@ -9,16 +9,19 @@ support-files =
 skip-if = e10s # Bug 941428 - UITour.jsm not e10s friendly
 [browser_no_tabs.js]
 [browser_openPreferences.js]
 skip-if = e10s # Bug 1073247 - UITour tests not e10s friendly
 [browser_openSearchPanel.js]
 skip-if = true # Bug 1113038 - Intermittent "Popup was opened"
 [browser_trackingProtection.js]
 tag = trackingprotection
+[browser_showMenu_controlCenter.js]
+skip-if = e10s # Bug 1073247 - UITour tests not e10s friendly
+tag = trackingprotection
 [browser_UITour.js]
 skip-if = os == "linux" || e10s # Intermittent failures, bug 951965
 [browser_UITour2.js]
 skip-if = e10s # Bug 1073247 - UITour.jsm not e10s friendly
 [browser_UITour3.js]
 skip-if = os == "linux" || e10s # Linux: Bug 986760, Bug 989101; e10s: Bug 1073247 - UITour.jsm not e10s friendly
 [browser_UITour_availableTargets.js]
 skip-if = e10s # Bug 1073247 - UITour.jsm not e10s friendly
new file mode 100644
--- /dev/null
+++ b/browser/components/uitour/test/browser_showMenu_controlCenter.js
@@ -0,0 +1,44 @@
+"use strict";
+
+const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
+const CONTROL_CENTER_PANEL = gIdentityHandler._identityPopup;
+const CONTROL_CENTER_MENU_NAME = "controlCenter";
+
+let gTestTab;
+let gContentAPI;
+let gContentWindow;
+
+function test() {
+  UITourTest();
+}
+
+let tests = [
+  taskify(function* test_showMenu() {
+    is_element_hidden(CONTROL_CENTER_PANEL, "Panel should initially be hidden");
+    yield showMenuPromise(CONTROL_CENTER_MENU_NAME);
+    is_element_visible(CONTROL_CENTER_PANEL, "Panel should be visible after showMenu");
+    yield showMenuPromise(CONTROL_CENTER_MENU_NAME);
+    is_element_visible(CONTROL_CENTER_PANEL,
+                       "Panel should remain visible and callback called after a 2nd showMenu");
+
+    yield BrowserTestUtils.withNewTab({
+      gBrowser,
+      url: "about:blank"
+    }, function*() {
+      ok(true, "Tab opened");
+    });
+
+    is_element_hidden(CONTROL_CENTER_PANEL, "Panel should hide upon tab switch");
+  }),
+
+  taskify(function* test_hideMenu() {
+    is_element_hidden(CONTROL_CENTER_PANEL, "Panel should initially be hidden");
+    yield showMenuPromise(CONTROL_CENTER_MENU_NAME);
+    is_element_visible(CONTROL_CENTER_PANEL, "Panel should be visible after showMenu");
+    let hidePromise = promisePanelElementHidden(window, CONTROL_CENTER_PANEL);
+    gContentAPI.hideMenu(CONTROL_CENTER_MENU_NAME);
+    yield hidePromise;
+
+    is_element_hidden(CONTROL_CENTER_PANEL, "Panel should hide after hideMenu");
+  }),
+];