Bug 1217129: Part 6 - [webext] Test browserAction popups in both the toolbar and in the menu panel. r=gijs r=billm
authorKris Maglione <maglione.k@gmail.com>
Sun, 10 Jan 2016 19:58:09 -0800
changeset 280523 48e077b052981e34081e4b8158678fee4f52e88c
parent 280522 b62be3fd000c780e23a70aa9758a07409159ec3f
child 280524 a77324588e67bdee3aa6b77b3b38e1bdddb46c62
push id17100
push usermaglione.k@gmail.com
push dateTue, 19 Jan 2016 22:16:16 +0000
treeherderfx-team@48e077b05298 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgijs, billm
bugs1217129
milestone46.0a1
Bug 1217129: Part 6 - [webext] Test browserAction popups in both the toolbar and in the menu panel. r=gijs r=billm
browser/components/extensions/test/browser/.eslintrc
browser/components/extensions/test/browser/browser_ext_browserAction_popup.js
browser/components/extensions/test/browser/browser_ext_pageAction_popup.js
browser/components/extensions/test/browser/head.js
--- a/browser/components/extensions/test/browser/.eslintrc
+++ b/browser/components/extensions/test/browser/.eslintrc
@@ -5,16 +5,19 @@
     "webextensions": true,
   },
 
   "globals": {
     "NetUtil": true,
     "XPCOMUtils": true,
     "Task": true,
 
+    // Browser window globals.
+    "PanelUI": false,
+
     // Test harness globals
     "ExtensionTestUtils": false,
 
     "clickBrowserAction": true,
     "clickPageAction": true,
     "CustomizableUI": true,
     "focusWindow": true,
     "makeWidgetId": true,
--- a/browser/components/extensions/test/browser/browser_ext_browserAction_popup.js
+++ b/browser/components/extensions/test/browser/browser_ext_browserAction_popup.js
@@ -1,27 +1,13 @@
 /* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
 /* vim: set sts=2 sw=2 et tw=80: */
 "use strict";
 
-function promisePopupShown(popup) {
-  return new Promise(resolve => {
-    if (popup.state == "open") {
-      resolve();
-    } else {
-      let onPopupShown = event => {
-        popup.removeEventListener("popupshown", onPopupShown);
-        resolve();
-      };
-      popup.addEventListener("popupshown", onPopupShown);
-    }
-  });
-}
-
-add_task(function* testPageActionPopup() {
+function* testInArea(area) {
   let extension = ExtensionTestUtils.loadExtension({
     manifest: {
       "background": {
         "page": "data/background.html",
       },
       "browser_action": {
         "default_popup": "popup-a.html",
       },
@@ -111,35 +97,39 @@ add_task(function* testPageActionPopup()
           }
         });
 
         browser.test.sendMessage("next-test");
       },
     },
   });
 
-  let viewId = `PanelUI-webext-${makeWidgetId(extension.id)}-browser-action-view`;
-
   extension.onMessage("send-click", () => {
     clickBrowserAction(extension);
   });
 
+  let widget;
   extension.onMessage("next-test", Task.async(function* () {
-    let panel = getBrowserActionPopup(extension);
-    if (panel) {
-      yield promisePopupShown(panel);
-      panel.hidePopup();
+    if (!widget) {
+      widget = getBrowserActionWidget(extension);
+      CustomizableUI.addWidgetToArea(widget.id, area);
+    }
 
-      panel = getBrowserActionPopup(extension);
-      is(panel, null, "panel successfully removed from document after hiding");
-    }
+    yield closeBrowserAction(extension);
 
     extension.sendMessage("next-test");
   }));
 
-
   yield Promise.all([extension.startup(), extension.awaitFinish("browseraction-tests-done")]);
 
   yield extension.unload();
 
-  let view = document.getElementById(viewId);
+  let view = document.getElementById(widget.viewId);
   is(view, null, "browserAction view removed from document");
+}
+
+add_task(function* testBrowserActionInToolbar() {
+  yield testInArea(CustomizableUI.AREA_NAVBAR);
 });
+
+add_task(function* testBrowserActionInPanel() {
+  yield testInArea(CustomizableUI.AREA_PANEL);
+});
--- a/browser/components/extensions/test/browser/browser_ext_pageAction_popup.js
+++ b/browser/components/extensions/test/browser/browser_ext_pageAction_popup.js
@@ -1,26 +1,12 @@
 /* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
 /* vim: set sts=2 sw=2 et tw=80: */
 "use strict";
 
-function promisePopupShown(popup) {
-  return new Promise(resolve => {
-    if (popup.popupOpen) {
-      resolve();
-    } else {
-      let onPopupShown = event => {
-        popup.removeEventListener("popupshown", onPopupShown);
-        resolve();
-      };
-      popup.addEventListener("popupshown", onPopupShown);
-    }
-  });
-}
-
 add_task(function* testPageActionPopup() {
   let scriptPage = url => `<html><head><meta charset="utf-8"><script src="${url}"></script></head></html>`;
 
   let extension = ExtensionTestUtils.loadExtension({
     manifest: {
       "background": {
         "page": "data/background.html",
       },
--- a/browser/components/extensions/test/browser/head.js
+++ b/browser/components/extensions/test/browser/head.js
@@ -1,16 +1,18 @@
 /* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
 /* vim: set sts=2 sw=2 et tw=80: */
 "use strict";
 
 /* exported CustomizableUI makeWidgetId focusWindow forceGC
+ *          getBrowserActionWidget
  *          clickBrowserAction clickPageAction
  *          getBrowserActionPopup getPageActionPopup
  *          closeBrowserAction closePageAction
+ *          promisePopupShown
  */
 
 var {AppConstants} = Cu.import("resource://gre/modules/AppConstants.jsm");
 var {CustomizableUI} = Cu.import("resource:///modules/CustomizableUI.jsm");
 
 // Bug 1239884: Our tests occasionally hit a long GC pause at unpredictable
 // times in debug builds, which results in intermittent timeouts. Until we have
 // a better solution, we force a GC after certain strategic tests, which tend to
@@ -38,33 +40,61 @@ var focusWindow = Task.async(function* f
       resolve();
     }, true);
   });
 
   win.focus();
   yield promise;
 });
 
-function getBrowserActionPopup(extension, win = window) {
-  return win.document.getElementById("customizationui-widget-panel");
+function promisePopupShown(popup) {
+  return new Promise(resolve => {
+    if (popup.state == "open") {
+      resolve();
+    } else {
+      let onPopupShown = event => {
+        popup.removeEventListener("popupshown", onPopupShown);
+        resolve();
+      };
+      popup.addEventListener("popupshown", onPopupShown);
+    }
+  });
+}
+
+function getBrowserActionWidget(extension) {
+  return CustomizableUI.getWidget(makeWidgetId(extension.id) + "-browser-action");
 }
 
-function clickBrowserAction(extension, win = window) {
-  let browserActionId = makeWidgetId(extension.id) + "-browser-action";
-  let elem = win.document.getElementById(browserActionId);
+function getBrowserActionPopup(extension, win = window) {
+  let group = getBrowserActionWidget(extension);
 
-  EventUtils.synthesizeMouseAtCenter(elem, {}, win);
-  return new Promise(SimpleTest.executeSoon);
+  if (group.areaType == CustomizableUI.TYPE_TOOLBAR) {
+    return win.document.getElementById("customizationui-widget-panel");
+  }
+  return null;
 }
 
+var clickBrowserAction = Task.async(function* (extension, win = window) {
+  let group = getBrowserActionWidget(extension);
+  let widget = group.forWindow(win);
+
+  if (group.areaType == CustomizableUI.TYPE_TOOLBAR) {
+    ok(!widget.overflowed, "Expect widget not to be overflowed");
+  } else if (group.areaType == CustomizableUI.TYPE_MENU_PANEL) {
+    yield win.PanelUI.show();
+  }
+
+  EventUtils.synthesizeMouseAtCenter(widget.node, {}, win);
+});
+
 function closeBrowserAction(extension, win = window) {
-  let node = getBrowserActionPopup(extension, win);
-  if (node) {
-    node.hidePopup();
-  }
+  let group = getBrowserActionWidget(extension);
+
+  let node = win.document.getElementById(group.viewId);
+  CustomizableUI.hidePanelForNode(node);
 
   return Promise.resolve();
 }
 
 function getPageActionPopup(extension, win = window) {
   let panelId = makeWidgetId(extension.id) + "-panel";
   return win.document.getElementById(panelId);
 }