michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: "use strict"; michael@0: michael@0: let tempElements = []; michael@0: michael@0: function insertTempItemsIntoMenu(parentMenu) { michael@0: // Last element is null to insert at the end: michael@0: let beforeEls = [parentMenu.firstChild, parentMenu.lastChild, null]; michael@0: for (let i = 0; i < beforeEls.length; i++) { michael@0: let sep = document.createElement("menuseparator"); michael@0: tempElements.push(sep); michael@0: parentMenu.insertBefore(sep, beforeEls[i]); michael@0: let menu = document.createElement("menu"); michael@0: tempElements.push(menu); michael@0: parentMenu.insertBefore(menu, beforeEls[i]); michael@0: // And another separator for good measure: michael@0: sep = document.createElement("menuseparator"); michael@0: tempElements.push(sep); michael@0: parentMenu.insertBefore(sep, beforeEls[i]); michael@0: } michael@0: } michael@0: michael@0: function checkSeparatorInsertion(menuId, buttonId, subviewId) { michael@0: return function() { michael@0: info("Checking for duplicate separators in " + buttonId + " widget"); michael@0: let menu = document.getElementById(menuId); michael@0: insertTempItemsIntoMenu(menu); michael@0: michael@0: let placement = CustomizableUI.getPlacementOfWidget(buttonId); michael@0: let changedPlacement = false; michael@0: if (!placement || placement.area != CustomizableUI.AREA_PANEL) { michael@0: CustomizableUI.addWidgetToArea(buttonId, CustomizableUI.AREA_PANEL); michael@0: changedPlacement = true; michael@0: } michael@0: yield PanelUI.show(); michael@0: michael@0: let button = document.getElementById(buttonId); michael@0: button.click(); michael@0: michael@0: yield waitForCondition(() => !PanelUI.multiView.hasAttribute("transitioning")); michael@0: let subview = document.getElementById(subviewId); michael@0: ok(subview.firstChild, "Subview should have a kid"); michael@0: is(subview.firstChild.localName, "toolbarbutton", "There should be no separators to start with"); michael@0: michael@0: for (let kid of subview.children) { michael@0: if (kid.localName == "menuseparator") { michael@0: ok(kid.previousSibling && kid.previousSibling.localName != "menuseparator", michael@0: "Separators should never have another separator next to them, and should never be the first node."); michael@0: } michael@0: } michael@0: michael@0: let panelHiddenPromise = promisePanelHidden(window); michael@0: PanelUI.hide(); michael@0: yield panelHiddenPromise; michael@0: michael@0: if (changedPlacement) { michael@0: CustomizableUI.reset(); michael@0: } michael@0: }; michael@0: } michael@0: michael@0: add_task(checkSeparatorInsertion("menuWebDeveloperPopup", "developer-button", "PanelUI-developerItems")); michael@0: add_task(checkSeparatorInsertion("viewSidebarMenu", "sidebar-button", "PanelUI-sidebarItems")); michael@0: michael@0: registerCleanupFunction(function() { michael@0: for (let el of tempElements) { michael@0: el.remove(); michael@0: } michael@0: tempElements = null; michael@0: });