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.

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

mercurial