browser/components/customizableui/test/browser_981305_separator_insertion.js

Wed, 31 Dec 2014 13:27:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 13:27:57 +0100
branch
TOR_BUG_3246
changeset 6
8bccb770b82d
permissions
-rw-r--r--

Ignore runtime configuration files generated during quality assurance.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 "use strict";
michael@0 6
michael@0 7 let tempElements = [];
michael@0 8
michael@0 9 function insertTempItemsIntoMenu(parentMenu) {
michael@0 10 // Last element is null to insert at the end:
michael@0 11 let beforeEls = [parentMenu.firstChild, parentMenu.lastChild, null];
michael@0 12 for (let i = 0; i < beforeEls.length; i++) {
michael@0 13 let sep = document.createElement("menuseparator");
michael@0 14 tempElements.push(sep);
michael@0 15 parentMenu.insertBefore(sep, beforeEls[i]);
michael@0 16 let menu = document.createElement("menu");
michael@0 17 tempElements.push(menu);
michael@0 18 parentMenu.insertBefore(menu, beforeEls[i]);
michael@0 19 // And another separator for good measure:
michael@0 20 sep = document.createElement("menuseparator");
michael@0 21 tempElements.push(sep);
michael@0 22 parentMenu.insertBefore(sep, beforeEls[i]);
michael@0 23 }
michael@0 24 }
michael@0 25
michael@0 26 function checkSeparatorInsertion(menuId, buttonId, subviewId) {
michael@0 27 return function() {
michael@0 28 info("Checking for duplicate separators in " + buttonId + " widget");
michael@0 29 let menu = document.getElementById(menuId);
michael@0 30 insertTempItemsIntoMenu(menu);
michael@0 31
michael@0 32 let placement = CustomizableUI.getPlacementOfWidget(buttonId);
michael@0 33 let changedPlacement = false;
michael@0 34 if (!placement || placement.area != CustomizableUI.AREA_PANEL) {
michael@0 35 CustomizableUI.addWidgetToArea(buttonId, CustomizableUI.AREA_PANEL);
michael@0 36 changedPlacement = true;
michael@0 37 }
michael@0 38 yield PanelUI.show();
michael@0 39
michael@0 40 let button = document.getElementById(buttonId);
michael@0 41 button.click();
michael@0 42
michael@0 43 yield waitForCondition(() => !PanelUI.multiView.hasAttribute("transitioning"));
michael@0 44 let subview = document.getElementById(subviewId);
michael@0 45 ok(subview.firstChild, "Subview should have a kid");
michael@0 46 is(subview.firstChild.localName, "toolbarbutton", "There should be no separators to start with");
michael@0 47
michael@0 48 for (let kid of subview.children) {
michael@0 49 if (kid.localName == "menuseparator") {
michael@0 50 ok(kid.previousSibling && kid.previousSibling.localName != "menuseparator",
michael@0 51 "Separators should never have another separator next to them, and should never be the first node.");
michael@0 52 }
michael@0 53 }
michael@0 54
michael@0 55 let panelHiddenPromise = promisePanelHidden(window);
michael@0 56 PanelUI.hide();
michael@0 57 yield panelHiddenPromise;
michael@0 58
michael@0 59 if (changedPlacement) {
michael@0 60 CustomizableUI.reset();
michael@0 61 }
michael@0 62 };
michael@0 63 }
michael@0 64
michael@0 65 add_task(checkSeparatorInsertion("menuWebDeveloperPopup", "developer-button", "PanelUI-developerItems"));
michael@0 66 add_task(checkSeparatorInsertion("viewSidebarMenu", "sidebar-button", "PanelUI-sidebarItems"));
michael@0 67
michael@0 68 registerCleanupFunction(function() {
michael@0 69 for (let el of tempElements) {
michael@0 70 el.remove();
michael@0 71 }
michael@0 72 tempElements = null;
michael@0 73 });

mercurial