diff --git a/browser/components/customizableui/src/CustomizableUI.jsm b/browser/components/customizableui/src/CustomizableUI.jsm index a7e07d1da760..2685e8527d56 100644 --- a/browser/components/customizableui/src/CustomizableUI.jsm +++ b/browser/components/customizableui/src/CustomizableUI.jsm @@ -867,24 +867,27 @@ let CustomizableUIInternal = { if (node) { let parent = node.parentNode; while (parent && !(parent.customizationTarget || - parent.localName == "toolbarpaletteitem")) { + parent == aWindow.gNavToolbox.palette)) { parent = parent.parentNode; } - if (parent && ((parent.customizationTarget == node.parentNode && - gBuildWindows.get(aWindow).has(parent.toolbox)) || - parent.localName == "toolbarpaletteitem")) { - // Normalize the removable attribute. For backwards compat, if - // the widget is not defined in a toolbox palette then absence - // of the "removable" attribute means it is not removable. - if (!node.hasAttribute("removable")) { - parent = parent.localName == "toolbarpaletteitem" ? parent.parentNode : parent; - // If we first see this in customization mode, it may be in the - // customization palette instead of the toolbox palette. - node.setAttribute("removable", !parent.customizationTarget); + if (parent) { + let nodeInArea = node.parentNode.localName == "toolbarpaletteitem" ? + node.parentNode : node; + // Check if we're in a customization target, or in the palette: + if ((parent.customizationTarget == nodeInArea.parentNode && + gBuildWindows.get(aWindow).has(parent.toolbox)) || + aWindow.gNavToolbox.palette == nodeInArea.parentNode) { + // Normalize the removable attribute. For backwards compat, if + // the widget is not located in a toolbox palette then absence + // of the "removable" attribute means it is not removable. + if (!node.hasAttribute("removable")) { + // If we first see this in customization mode, it may be in the + // customization palette instead of the toolbox palette. + node.setAttribute("removable", !parent.customizationTarget); + } + return node; } - - return node; } } @@ -896,8 +899,8 @@ let CustomizableUIInternal = { let node = toolbox.palette.querySelector(idToSelector(aId)); if (node) { // Normalize the removable attribute. For backwards compat, this - // is optional if the widget is defined in the toolbox palette, - // and defaults to *true*, unlike if it was defined elsewhere. + // is optional if the widget is located in the toolbox palette, + // and defaults to *true*, unlike if it was located elsewhere. if (!node.hasAttribute("removable")) { node.setAttribute("removable", true); } diff --git a/browser/components/customizableui/test/browser.ini b/browser/components/customizableui/test/browser.ini index e89ad23a32cb..c80d3284a82d 100644 --- a/browser/components/customizableui/test/browser.ini +++ b/browser/components/customizableui/test/browser.ini @@ -36,5 +36,6 @@ skip-if = true skip-if = os == "mac" [browser_938980_navbar_collapsed.js] +[browser_940946_removable_from_navbar_customizemode.js] [browser_941083_invalidate_wrapper_cache_createWidget.js] [browser_panel_toggle.js] diff --git a/browser/components/customizableui/test/browser_940946_removable_from_navbar_customizemode.js b/browser/components/customizableui/test/browser_940946_removable_from_navbar_customizemode.js new file mode 100644 index 000000000000..ef3b22957b96 --- /dev/null +++ b/browser/components/customizableui/test/browser_940946_removable_from_navbar_customizemode.js @@ -0,0 +1,33 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +const kTestBtnId = "test-removable-navbar-customize-mode"; + +let gTests = [ + { + desc: "Items without the removable attribute in the navbar should be considered non-removable", + setup: function() { + let btn = createDummyXULButton(kTestBtnId, "Test removable in navbar in customize mode"); + document.getElementById("nav-bar").customizationTarget.appendChild(btn); + return startCustomizing(); + }, + run: function() { + ok(!CustomizableUI.isWidgetRemovable(kTestBtnId), "Widget should not be considered removable"); + }, + teardown: function() { + yield endCustomizing(); + document.getElementById(kTestBtnId).remove(); + } + }, +]; +function asyncCleanup() { + yield endCustomizing(); + yield resetCustomization(); +} + +function test() { + waitForExplicitFinish(); + runTests(gTests, asyncCleanup); +} +