Bug 942626 - fix filtering for customize context menus in Australis, r=jaws
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Tue, 26 Nov 2013 00:24:33 +0100
changeset 157495 763b04634768aa15d450a8673949eb614593face
parent 157494 0e0787161168d8380013b7612838fb28fb67767a
child 157496 b6cbed05a206c4532e70024ac7acc191b9045e18
push id25714
push usercbook@mozilla.com
push dateTue, 26 Nov 2013 11:39:03 +0000
treeherdermozilla-central@4a8c40940659 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjaws
bugs942626
milestone28.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 942626 - fix filtering for customize context menus in Australis, r=jaws
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
@@ -354,31 +354,43 @@ CustomizeMode.prototype = {
   },
 
   dispatchToolboxEvent: function(aEventType, aDetails={}) {
     let evt = this.document.createEvent("CustomEvent");
     evt.initCustomEvent(aEventType, true, true, {changed: this._changed});
     let result = this.window.gNavToolbox.dispatchEvent(evt);
   },
 
+  _getCustomizableChildForNode: function(aNode) {
+    let area = this._getCustomizableParent(aNode);
+    area = area.customizationTarget || area;
+    while (aNode && aNode.parentNode != area) {
+      aNode = aNode.parentNode;
+    }
+    return aNode;
+  },
+
   addToToolbar: function(aNode) {
+    aNode = this._getCustomizableChildForNode(aNode);
     if (aNode.localName == "toolbarpaletteitem" && aNode.firstChild) {
       aNode = aNode.firstChild;
     }
     CustomizableUI.addWidgetToArea(aNode.id, CustomizableUI.AREA_NAVBAR);
   },
 
   addToPanel: function(aNode) {
+    aNode = this._getCustomizableChildForNode(aNode);
     if (aNode.localName == "toolbarpaletteitem" && aNode.firstChild) {
       aNode = aNode.firstChild;
     }
     CustomizableUI.addWidgetToArea(aNode.id, CustomizableUI.AREA_PANEL);
   },
 
   removeFromArea: function(aNode) {
+    aNode = this._getCustomizableChildForNode(aNode);
     if (aNode.localName == "toolbarpaletteitem" && aNode.firstChild) {
       aNode = aNode.firstChild;
     }
     CustomizableUI.removeWidgetFromArea(aNode.id);
   },
 
   populatePalette: function() {
     let fragment = this.document.createDocumentFragment();
--- a/browser/components/customizableui/test/browser_880164_customization_context_menus.js
+++ b/browser/components/customizableui/test/browser_880164_customization_context_menus.js
@@ -67,16 +67,42 @@ let gTests = [
 
       let hiddenPromise = contextMenuHidden(contextMenu);
       contextMenu.hidePopup();
       yield hiddenPromise;
     },
     teardown: null
   },
   {
+    desc: "Right-click on the searchbar and moving it to the menu and back should move the search-container instead.",
+    run: function() {
+      let searchbar = document.getElementById("searchbar");
+      gCustomizeMode.addToPanel(searchbar);
+      let placement = CustomizableUI.getPlacementOfWidget("search-container");
+      is(placement.area, CustomizableUI.AREA_PANEL, "Should be in panel");
+
+      let shownPanelPromise = promisePanelShown(window);
+      PanelUI.toggle({type: "command"});
+      yield shownPanelPromise;
+      let hiddenPanelPromise = promisePanelHidden(window);
+      PanelUI.toggle({type: "command"});
+      yield hiddenPanelPromise;
+
+      gCustomizeMode.addToToolbar(searchbar);
+      placement = CustomizableUI.getPlacementOfWidget("search-container");
+      is(placement.area, CustomizableUI.AREA_NAVBAR, "Should be in navbar");
+      gCustomizeMode.removeFromArea(searchbar);
+      placement = CustomizableUI.getPlacementOfWidget("search-container");
+      is(placement, null, "Should be in palette");
+      CustomizableUI.reset();
+      placement = CustomizableUI.getPlacementOfWidget("search-container");
+      is(placement.area, CustomizableUI.AREA_NAVBAR, "Should be in navbar");
+    }
+  },
+  {
     desc: "Right-click on an item within the menu panel should show a context menu with options to move it.",
     setup: null,
     run: function() {
       let shownPanelPromise = promisePanelShown(window);
       PanelUI.toggle({type: "command"});
       yield shownPanelPromise;
 
       let contextMenu = document.getElementById("customizationPanelItemContextMenu");