Bug 975719 - Australis - right clicking an empty bit of toolbar shouldn't cause errors, r=jaws
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Tue, 25 Feb 2014 00:14:41 +0000
changeset 170839 6a8b0834c5fc4c85ecf268af43a2a11200acced5
parent 170838 3e84bd445574ff1a624b15f832d4c49883996f72
child 170840 706f36fe921f078104504dcbd7731486736846ba
push id270
push userpvanderbeken@mozilla.com
push dateThu, 06 Mar 2014 09:24:21 +0000
reviewersjaws
bugs975719
milestone30.0a1
Bug 975719 - Australis - right clicking an empty bit of toolbar shouldn't cause errors, r=jaws
browser/base/content/browser.js
browser/components/customizableui/test/browser_880164_customization_context_menus.js
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -4238,26 +4238,28 @@ function onViewToolbarsPopupShowing(aEve
     return;
   }
 
   // triggerNode can be a nested child element of a toolbaritem.
   let toolbarItem = popup.triggerNode;
 
   if (toolbarItem && toolbarItem.localName == "toolbarpaletteitem") {
     toolbarItem = toolbarItem.firstChild;
-  } else {
+  } else if (toolbarItem && toolbarItem.localName != "toolbar") {
     while (toolbarItem && toolbarItem.parentNode) {
       let parent = toolbarItem.parentNode;
       if ((parent.classList && parent.classList.contains("customization-target")) ||
           parent.getAttribute("overflowfortoolbar") || // Needs to work in the overflow list as well.
           parent.localName == "toolbarpaletteitem" ||
           parent.localName == "toolbar")
         break;
       toolbarItem = parent;
     }
+  } else {
+    toolbarItem = null;
   }
 
   // Right-clicking on an empty part of the tabstrip will exit
   // the above loop with toolbarItem being the xul:document.
   // That has no parentNode, and we should disable the items in
   // this case.
   let movable = toolbarItem && toolbarItem.parentNode &&
                 CustomizableUI.isWidgetRemovable(toolbarItem);
--- a/browser/components/customizableui/test/browser_880164_customization_context_menus.js
+++ b/browser/components/customizableui/test/browser_880164_customization_context_menus.js
@@ -30,16 +30,51 @@ add_task(function() {
   );
   checkContextMenu(contextMenu, expectedEntries);
 
   let hiddenPromise = contextMenuHidden(contextMenu);
   contextMenu.hidePopup();
   yield hiddenPromise;
 });
 
+// Right-click on an empty bit of extra toolbar should
+// show a context menu with moving options disabled,
+// and a toggle option for the extra toolbar
+add_task(function() {
+  let contextMenu = document.getElementById("toolbar-context-menu");
+  let shownPromise = contextMenuShown(contextMenu);
+  let toolbar = createToolbarWithPlacements("880164_empty_toolbar", []);
+  toolbar.setAttribute("context", "toolbar-context-menu");
+  toolbar.setAttribute("toolbarname", "Fancy Toolbar for Context Menu");
+  EventUtils.synthesizeMouseAtCenter(toolbar, {type: "contextmenu", button: 2 });
+  yield shownPromise;
+
+  let expectedEntries = [
+    [".customize-context-moveToPanel", false],
+    [".customize-context-removeFromToolbar", false],
+    ["---"]
+  ];
+  if (!isOSX) {
+    expectedEntries.push(["#toggle_toolbar-menubar", true]);
+  }
+  expectedEntries.push(
+    ["#toggle_PersonalToolbar", true],
+    ["#toggle_880164_empty_toolbar", true],
+    ["---"],
+    [".viewCustomizeToolbar", true]
+  );
+  checkContextMenu(contextMenu, expectedEntries);
+
+  let hiddenPromise = contextMenuHidden(contextMenu);
+  contextMenu.hidePopup();
+  yield hiddenPromise;
+  removeCustomToolbars();
+});
+
+
 // Right-click on the urlbar-container should
 // show a context menu with disabled options to move it.
 add_task(function() {
   let contextMenu = document.getElementById("toolbar-context-menu");
   let shownPromise = contextMenuShown(contextMenu);
   let urlBarContainer = document.getElementById("urlbar-container");
   // Need to make sure not to click within an edit field.
   let urlbarRect = urlBarContainer.getBoundingClientRect();