Bug 945191 - Combined buttons show wrong context menu options when they are in the toolbar. r=Gijs
authorJared Wein <jwein@mozilla.com>
Wed, 04 Dec 2013 17:14:40 -0500
changeset 174384 7de6a7ee1fc2be5e1cf2dd2aae2c140db2e6d350
parent 174383 29ddc08281ff12b19233a2e5c33b64bed90a7861
child 174385 ef18be0ae2d1d726ee2125422ff7af2964c6b4c4
push id445
push userffxbld
push dateMon, 10 Mar 2014 22:05:19 +0000
treeherdermozilla-release@dc38b741b04e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersGijs
bugs945191
milestone28.0a1
Bug 945191 - Combined buttons show wrong context menu options when they are in the toolbar. r=Gijs
browser/components/customizableui/src/CustomizeMode.jsm
browser/components/customizableui/test/browser_880164_customization_context_menus.js
--- a/browser/components/customizableui/src/CustomizeMode.jsm
+++ b/browser/components/customizableui/src/CustomizeMode.jsm
@@ -553,20 +553,24 @@ CustomizeMode.prototype = {
                                 aNode.getAttribute("contextmenu") ? "contextmenu" : "";
     let currentContextMenu = aNode.getAttribute(contextMenuAttrName);
     let contextMenuForPlace = aPlace == "panel" ?
                                 kPanelItemContextMenu :
                                 kPaletteItemContextMenu;
     if (aPlace != "toolbar") {
       wrapper.setAttribute("context", contextMenuForPlace);
     }
-    if (currentContextMenu) {
+    // Only keep track of the menu if it is non-default.
+    if (currentContextMenu &&
+        currentContextMenu != contextMenuForPlace) {
       aNode.setAttribute("wrapped-context", currentContextMenu);
       aNode.setAttribute("wrapped-contextAttrName", contextMenuAttrName)
       aNode.removeAttribute(contextMenuAttrName);
+    } else if (currentContextMenu == contextMenuForPlace) {
+      aNode.removeAttribute(contextMenuAttrName);
     }
 
     wrapper.addEventListener("mousedown", this);
     wrapper.addEventListener("mouseup", this);
 
     return wrapper;
   },
 
--- a/browser/components/customizableui/test/browser_880164_customization_context_menus.js
+++ b/browser/components/customizableui/test/browser_880164_customization_context_menus.js
@@ -236,16 +236,61 @@ let gTests = [
       yield hiddenContextPromise;
     },
     teardown: function() {
       yield endCustomizing(this.otherWin);
       this.otherWin.close();
       this.otherWin = null;
     }
   },
+  {
+    desc: "Bug 945191 - Combined buttons show wrong context menu options when they are in the toolbar.",
+    setup: startCustomizing,
+    run: function () {
+      let contextMenu = document.getElementById("customizationPanelItemContextMenu");
+      let shownPromise = contextMenuShown(contextMenu);
+      let zoomControls = document.getElementById("wrapper-zoom-controls");
+      EventUtils.synthesizeMouse(zoomControls, 2, 2, {type: "contextmenu", button: 2});
+      yield shownPromise;
+      // Execute the command to move the item from the panel to the toolbar.
+      contextMenu.childNodes[0].doCommand();
+      let hiddenPromise = contextMenuHidden(contextMenu);
+      contextMenu.hidePopup();
+      yield hiddenPromise;
+      yield endCustomizing();
+
+      zoomControls = document.getElementById("zoom-controls");
+      is(zoomControls.parentNode.id, "nav-bar-customization-target", "Zoom-controls should be on the nav-bar");
+
+      contextMenu = document.getElementById("toolbar-context-menu");
+      shownPromise = contextMenuShown(contextMenu);
+      EventUtils.synthesizeMouse(zoomControls, 2, 2, {type: "contextmenu", button: 2});
+      yield shownPromise;
+
+      let expectedEntries = [
+        [".customize-context-addToPanel", true],
+        [".customize-context-removeFromToolbar", true],
+        ["---"]
+      ];
+      if (!isOSX) {
+        expectedEntries.push(["#toggle_toolbar-menubar", true]);
+      }
+      expectedEntries.push(
+        ["#toggle_PersonalToolbar", true],
+        ["---"],
+        [".viewCustomizeToolbar", true]
+      );
+      checkContextMenu(contextMenu, expectedEntries);
+
+      hiddenPromise = contextMenuHidden(contextMenu);
+      contextMenu.hidePopup();
+      yield hiddenPromise;
+    },
+    teardown: resetCustomization,
+  }
 ];
 
 function test() {
   waitForExplicitFinish();
   runTests(gTests);
 }
 
 function contextMenuShown(aContextMenu) {