1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/components/customizableui/test/browser_981305_separator_insertion.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,73 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +"use strict"; 1.9 + 1.10 +let tempElements = []; 1.11 + 1.12 +function insertTempItemsIntoMenu(parentMenu) { 1.13 + // Last element is null to insert at the end: 1.14 + let beforeEls = [parentMenu.firstChild, parentMenu.lastChild, null]; 1.15 + for (let i = 0; i < beforeEls.length; i++) { 1.16 + let sep = document.createElement("menuseparator"); 1.17 + tempElements.push(sep); 1.18 + parentMenu.insertBefore(sep, beforeEls[i]); 1.19 + let menu = document.createElement("menu"); 1.20 + tempElements.push(menu); 1.21 + parentMenu.insertBefore(menu, beforeEls[i]); 1.22 + // And another separator for good measure: 1.23 + sep = document.createElement("menuseparator"); 1.24 + tempElements.push(sep); 1.25 + parentMenu.insertBefore(sep, beforeEls[i]); 1.26 + } 1.27 +} 1.28 + 1.29 +function checkSeparatorInsertion(menuId, buttonId, subviewId) { 1.30 + return function() { 1.31 + info("Checking for duplicate separators in " + buttonId + " widget"); 1.32 + let menu = document.getElementById(menuId); 1.33 + insertTempItemsIntoMenu(menu); 1.34 + 1.35 + let placement = CustomizableUI.getPlacementOfWidget(buttonId); 1.36 + let changedPlacement = false; 1.37 + if (!placement || placement.area != CustomizableUI.AREA_PANEL) { 1.38 + CustomizableUI.addWidgetToArea(buttonId, CustomizableUI.AREA_PANEL); 1.39 + changedPlacement = true; 1.40 + } 1.41 + yield PanelUI.show(); 1.42 + 1.43 + let button = document.getElementById(buttonId); 1.44 + button.click(); 1.45 + 1.46 + yield waitForCondition(() => !PanelUI.multiView.hasAttribute("transitioning")); 1.47 + let subview = document.getElementById(subviewId); 1.48 + ok(subview.firstChild, "Subview should have a kid"); 1.49 + is(subview.firstChild.localName, "toolbarbutton", "There should be no separators to start with"); 1.50 + 1.51 + for (let kid of subview.children) { 1.52 + if (kid.localName == "menuseparator") { 1.53 + ok(kid.previousSibling && kid.previousSibling.localName != "menuseparator", 1.54 + "Separators should never have another separator next to them, and should never be the first node."); 1.55 + } 1.56 + } 1.57 + 1.58 + let panelHiddenPromise = promisePanelHidden(window); 1.59 + PanelUI.hide(); 1.60 + yield panelHiddenPromise; 1.61 + 1.62 + if (changedPlacement) { 1.63 + CustomizableUI.reset(); 1.64 + } 1.65 + }; 1.66 +} 1.67 + 1.68 +add_task(checkSeparatorInsertion("menuWebDeveloperPopup", "developer-button", "PanelUI-developerItems")); 1.69 +add_task(checkSeparatorInsertion("viewSidebarMenu", "sidebar-button", "PanelUI-sidebarItems")); 1.70 + 1.71 +registerCleanupFunction(function() { 1.72 + for (let el of tempElements) { 1.73 + el.remove(); 1.74 + } 1.75 + tempElements = null; 1.76 +});