Bug 989751 - Some items in the Web Developer and Sidebar widgets have the wrong styling. r=Gijs, a=sledru
authorTim Nguyen <ntim007@gmail.com>
Wed, 30 Apr 2014 04:40:00 +0100
changeset 192197 5ad3f17e39d2
parent 192196 743afab610fa
child 192198 d41eb0c5c169
push id3519
push userryanvm@gmail.com
push date2014-05-05 16:58 +0000
treeherdermozilla-beta@c219fc2b4cc2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersGijs, sledru
bugs989751
milestone30.0
Bug 989751 - Some items in the Web Developer and Sidebar widgets have the wrong styling. r=Gijs, a=sledru
browser/components/customizableui/src/CustomizableWidgets.jsm
browser/components/customizableui/test/browser.ini
browser/components/customizableui/test/browser_989751_subviewbutton_class.js
--- a/browser/components/customizableui/src/CustomizableWidgets.jsm
+++ b/browser/components/customizableui/src/CustomizableWidgets.jsm
@@ -109,26 +109,29 @@ function fillSubviewFromMenuItems(aMenuI
       // Don't insert duplicate or leading separators. This can happen if there are
       // menus (which we don't copy) above the separator.
       if (!fragment.lastChild || fragment.lastChild.localName == "menuseparator") {
         continue;
       }
       subviewItem = doc.createElementNS(kNSXUL, "menuseparator");
     } else if (menuChild.localName == "menuitem") {
       subviewItem = doc.createElementNS(kNSXUL, "toolbarbutton");
-      subviewItem.setAttribute("class", "subviewbutton");
       addShortcut(menuChild, doc, subviewItem);
     } else {
       continue;
     }
     for (let attr of attrs) {
       let attrVal = menuChild.getAttribute(attr);
       if (attrVal)
         subviewItem.setAttribute(attr, attrVal);
     }
+    // We do this after so the .subviewbutton class doesn't get overriden.
+    if (menuChild.localName == "menuitem") {
+      subviewItem.classList.add("subviewbutton");
+    }
     fragment.appendChild(subviewItem);
   }
   aSubview.appendChild(fragment);
 }
 
 function clearSubview(aSubview) {
   let parent = aSubview.parentNode;
   // We'll take the container out of the document before cleaning it out
--- a/browser/components/customizableui/test/browser.ini
+++ b/browser/components/customizableui/test/browser.ini
@@ -83,16 +83,17 @@ skip-if = os == "linux"
 [browser_980155_add_overflow_toolbar.js]
 [browser_981418-widget-onbeforecreated-handler.js]
 
 [browser_984455_bookmarks_items_reparenting.js]
 skip-if = os == "linux"
 
 [browser_985815_propagate_setToolbarVisibility.js]
 [browser_981305_separator_insertion.js]
+[browser_989751_subviewbutton_class.js]
 [browser_987177_destroyWidget_xul.js]
 [browser_987177_xul_wrapper_updating.js]
 [browser_987492_window_api.js]
 [browser_992747_toggle_noncustomizable_toolbar.js]
 [browser_993322_widget_notoolbar.js]
 [browser_995164_registerArea_during_customize_mode.js]
 [browser_996364_registerArea_different_properties.js]
 [browser_bootstrapped_custom_toolbar.js]
new file mode 100644
--- /dev/null
+++ b/browser/components/customizableui/test/browser_989751_subviewbutton_class.js
@@ -0,0 +1,62 @@
+/* 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/. */
+
+"use strict";
+
+const kCustomClass = "acustomclassnoonewilluse";
+let tempElement = null;
+
+function insertClassNameToMenuChildren(parentMenu) {
+  let el = parentMenu.querySelector("menuitem:first-of-type");
+  el.classList.add(kCustomClass);
+  tempElement = el;
+}
+
+function checkSubviewButtonClass(menuId, buttonId, subviewId) {
+  return function() {
+    info("Checking for items without the subviewbutton class in " + buttonId + " widget");
+    let menu = document.getElementById(menuId);
+    insertClassNameToMenuChildren(menu);
+
+    let placement = CustomizableUI.getPlacementOfWidget(buttonId);
+    let changedPlacement = false;
+    if (!placement || placement.area != CustomizableUI.AREA_PANEL) {
+      CustomizableUI.addWidgetToArea(buttonId, CustomizableUI.AREA_PANEL);
+      changedPlacement = true;
+    }
+    yield PanelUI.show();
+
+    let button = document.getElementById(buttonId);
+    button.click();
+
+    yield waitForCondition(() => !PanelUI.multiView.hasAttribute("transitioning"));
+    let subview = document.getElementById(subviewId);
+    ok(subview.firstChild, "Subview should have a kid");
+    let subviewchildren = subview.querySelectorAll("toolbarbutton");
+    for (let i = 0; i < subviewchildren.length; i++) {
+      let item = subviewchildren[i];
+      let itemReadable = "Item '" + item.label + "' (classes: " + item.className + ")";
+      ok(item.classList.contains("subviewbutton"), itemReadable + " should have the subviewbutton class.");
+      if (i == 0) {
+        ok(item.classList.contains(kCustomClass), itemReadable + " should still have its own class, too.");
+      }
+    }
+
+    let panelHiddenPromise = promisePanelHidden(window);
+    PanelUI.hide();
+    yield panelHiddenPromise;
+
+    if (changedPlacement) {
+      CustomizableUI.reset();
+    }
+  };
+}
+
+add_task(checkSubviewButtonClass("menuWebDeveloperPopup", "developer-button", "PanelUI-developerItems"));
+add_task(checkSubviewButtonClass("viewSidebarMenu", "sidebar-button", "PanelUI-sidebarItems"));
+
+registerCleanupFunction(function() {
+  tempElement.classList.remove(kCustomClass)
+  tempElement = null;
+});