bug 1320439 - Fix submenus in page_action, browser_action contextMenus, r=kmag
authorTomislav Jovanovic <tomica@gmail.com>
Mon, 28 Nov 2016 03:15:02 +0100
changeset 324591 1a5839f86e7936d208929eb2e929f99421ebc871
parent 324590 be6f5b8a484e90088ec40f4ae18a5e009e1979ec
child 324592 a662d5cccbe5e80d31a3538b71a5953999dcad50
push id84456
push usercbook@mozilla.com
push dateTue, 29 Nov 2016 15:49:58 +0000
treeherdermozilla-inbound@00596bfe1df0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskmag
bugs1320439
milestone53.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 1320439 - Fix submenus in page_action, browser_action contextMenus, r=kmag MozReview-Commit-ID: AGhu1tbofrB
browser/components/extensions/ext-browserAction.js
browser/components/extensions/ext-pageAction.js
browser/components/extensions/test/browser/browser_ext_contextMenus_actionMenus.js
browser/components/extensions/test/browser/head.js
--- a/browser/components/extensions/ext-browserAction.js
+++ b/browser/components/extensions/ext-browserAction.js
@@ -229,18 +229,19 @@ BrowserAction.prototype = {
           }
         }
         break;
 
       case "popupshowing":
         const menu = event.target;
         const trigger = menu.triggerNode;
         const node = window.document.getElementById(this.id);
+        const contexts = ["toolbar-context-menu", "customizationPanelItemContextMenu"];
 
-        if (menu.localName === "menupopup" && node && isAncestorOrSelf(node, trigger)) {
+        if (contexts.includes(menu.id) && node && isAncestorOrSelf(node, trigger)) {
           global.actionContextMenu({
             extension: this.extension,
             onBrowserAction: true,
             menu: menu,
           });
         }
         break;
     }
--- a/browser/components/extensions/ext-pageAction.js
+++ b/browser/components/extensions/ext-pageAction.js
@@ -162,17 +162,17 @@ PageAction.prototype = {
           this.handleClick(window);
         }
         break;
 
       case "popupshowing":
         const menu = event.target;
         const trigger = menu.triggerNode;
 
-        if (menu.localName === "menupopup" && trigger && trigger.id === this.id) {
+        if (menu.id === "toolbar-context-menu" && trigger && trigger.id === this.id) {
           global.actionContextMenu({
             extension: this.extension,
             onPageAction: true,
             menu: menu,
           });
         }
         break;
     }
--- a/browser/components/extensions/test/browser/browser_ext_contextMenus_actionMenus.js
+++ b/browser/components/extensions/test/browser/browser_ext_contextMenus_actionMenus.js
@@ -37,25 +37,28 @@ add_task(function* () {
   const tabId = yield extension.awaitMessage("ready");
 
   for (const kind of ["page", "browser"]) {
     const menu = yield openActionContextMenu(extension, kind);
     const [submenu, second, , , , last, separator] = menu.children;
 
     is(submenu.tagName, "menu", "Correct submenu type");
     is(submenu.label, "parent", "Correct submenu title");
-    is(submenu.firstChild.children.length, 2, "Correct number of submenu items");
+
+    const popup = yield openActionSubmenu(submenu);
+    is(popup, submenu.firstChild, "Correct submenu opened");
+    is(popup.children.length, 2, "Correct number of submenu items");
 
     is(second.tagName, "menuitem", "Second menu item type is correct");
     is(second.label, "click 1", "Second menu item title is correct");
 
     is(last.label, "click 5", "Last menu item title is correct");
     is(separator.tagName, "menuseparator", "Separator after last menu item");
 
-    yield closeActionContextMenu(last);
+    yield closeActionContextMenu(popup.firstChild);
     const {info, tab} = yield extension.awaitMessage("click");
     is(info.pageUrl, "http://example.com/", "Click info pageUrl is correct");
     is(tab.id, tabId, "Click event tab ID is correct");
   }
 
   yield BrowserTestUtils.removeTab(tab);
   yield extension.unload();
 });
--- a/browser/components/extensions/test/browser/head.js
+++ b/browser/components/extensions/test/browser/head.js
@@ -5,17 +5,17 @@
 /* exported CustomizableUI makeWidgetId focusWindow forceGC
  *          getBrowserActionWidget
  *          clickBrowserAction clickPageAction
  *          getBrowserActionPopup getPageActionPopup
  *          closeBrowserAction closePageAction
  *          promisePopupShown promisePopupHidden
  *          openContextMenu closeContextMenu
  *          openExtensionContextMenu closeExtensionContextMenu
- *          openActionContextMenu closeActionContextMenu
+ *          openActionContextMenu openActionSubmenu closeActionContextMenu
  *          imageBuffer getListStyleImage getPanelForNode
  *          awaitExtensionPanel awaitPopupResize
  *          promiseContentDimensions alterContent
  */
 
 const {AppConstants} = Cu.import("resource://gre/modules/AppConstants.jsm");
 const {CustomizableUI} = Cu.import("resource:///modules/CustomizableUI.jsm");
 
@@ -249,16 +249,24 @@ function* openActionContextMenu(extensio
 
   const shown = BrowserTestUtils.waitForEvent(menu, "popupshown");
   EventUtils.synthesizeMouseAtCenter(button, {type: "contextmenu"}, win);
   yield shown;
 
   return menu;
 }
 
+function* openActionSubmenu(submenuItem, win = window) {
+  const submenu = submenuItem.firstChild;
+  const shown = BrowserTestUtils.waitForEvent(submenu, "popupshown");
+  EventUtils.synthesizeMouseAtCenter(submenuItem, {}, win);
+  yield shown;
+  return submenu;
+}
+
 function closeActionContextMenu(itemToSelect, win = window) {
   const menu = win.document.getElementById("toolbar-context-menu");
   const hidden = BrowserTestUtils.waitForEvent(menu, "popuphidden");
   if (itemToSelect) {
     EventUtils.synthesizeMouseAtCenter(itemToSelect, {}, win);
   } else {
     menu.hidePopup();
   }