Bug 934113 - correctly mark items as removable when in customize mode, r=jaws
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Tue, 05 Nov 2013 11:39:59 +0100
changeset 170533 853a39fedb087554c05c7e1a806882896e69e860
parent 170532 232b16a39c877d4d7ab7445c70b93fef0f9c9745
child 170534 8e9d485dd741808d276f1b9cfd0e2ffd23ab1d4f
push idunknown
push userunknown
push dateunknown
reviewersjaws
bugs934113
milestone28.0a1
Bug 934113 - correctly mark items as removable when in customize mode, r=jaws
browser/components/customizableui/src/CustomizableUI.jsm
browser/components/customizableui/test/browser.ini
browser/components/customizableui/test/browser_934113_menubar_removable.js
--- a/browser/components/customizableui/src/CustomizableUI.jsm
+++ b/browser/components/customizableui/src/CustomizableUI.jsm
@@ -854,23 +854,24 @@ let CustomizableUIInternal = {
     let node = document.getElementById(aId);
     if (node) {
       let parent = node.parentNode;
       while (parent && !(parent.customizationTarget ||
                          parent.localName == "toolbarpaletteitem")) {
         parent = parent.parentNode;
       }
 
-      if ((parent && parent.customizationTarget == node.parentNode &&
-           gBuildWindows.get(aWindow).has(parent.toolbox)) ||
-          (parent && parent.localName == "toolbarpaletteitem")) {
+      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);
         }
 
         return node;
       }
     }
--- a/browser/components/customizableui/test/browser.ini
+++ b/browser/components/customizableui/test/browser.ini
@@ -25,8 +25,12 @@ support-files =
 # Because of the specific widths, this test is fragile and won't necessarily pass on other platforms
 run-if = os == "mac"
 
 [browser_914863_disabled_help_quit_buttons.js]
 [browser_918049_skipintoolbarset_dnd.js]
 [browser_923857_customize_mode_event_wrapping_during_reset.js]
 [browser_927717_customize_drag_empty_toolbar.js]
 
+[browser_934113_menubar_removable.js]
+# Because this test is about the menubar, it can't be run on mac
+skip-if = os == "mac"
+
new file mode 100644
--- /dev/null
+++ b/browser/components/customizableui/test/browser_934113_menubar_removable.js
@@ -0,0 +1,32 @@
+/* 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/. */
+
+let gTests = [
+  {
+    desc: "Attempting to drag the menubar to the navbar shouldn't work.",
+    setup: startCustomizing,
+    run: function() {
+      let menuItems = document.getElementById("menubar-items");
+      let navbar = document.getElementById("nav-bar");
+      let menubar = document.getElementById("toolbar-menubar");
+      simulateItemDrag(menuItems, navbar.customizationTarget);
+      is(getAreaWidgetIds("nav-bar").indexOf("menubar-items"), -1, "Menu bar shouldn't be in the navbar.");
+      ok(!navbar.querySelector("#menubar-items"), "Shouldn't find menubar items in the navbar.");
+      ok(menubar.querySelector("#menubar-items"), "Should find menubar items in the menubar.");
+      isnot(getAreaWidgetIds("toolbar-menubar").indexOf("menubar-items"), -1, "Menubar items shouldn't be missing from the navbar.");
+    },
+    teardown: endCustomizing
+  },
+];
+function asyncCleanup() {
+  yield endCustomizing();
+  Services.prefs.clearUserPref("browser.uiCustomization.skipSourceNodeCheck");
+  yield resetCustomization();
+}
+
+function test() {
+  Services.prefs.setBoolPref("browser.uiCustomization.skipSourceNodeCheck", true);
+  waitForExplicitFinish();
+  runTests(gTests, asyncCleanup);
+}