tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

browser_981305_separator_insertion.js (2598B)


      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/. */
      4 
      5 "use strict";
      6 
      7 var tempElements = [];
      8 
      9 function insertTempItemsIntoMenu(parentMenu) {
     10  // Last element is null to insert at the end:
     11  let beforeEls = [
     12    parentMenu.firstElementChild,
     13    parentMenu.lastElementChild,
     14    null,
     15  ];
     16  for (let i = 0; i < beforeEls.length; i++) {
     17    let sep = document.createXULElement("menuseparator");
     18    tempElements.push(sep);
     19    parentMenu.insertBefore(sep, beforeEls[i]);
     20    let menu = document.createXULElement("menu");
     21    tempElements.push(menu);
     22    parentMenu.insertBefore(menu, beforeEls[i]);
     23    // And another separator for good measure:
     24    sep = document.createXULElement("menuseparator");
     25    tempElements.push(sep);
     26    parentMenu.insertBefore(sep, beforeEls[i]);
     27  }
     28 }
     29 
     30 async function checkSeparatorInsertion(menuId, buttonId, subviewId) {
     31  info("Checking for duplicate separators in " + buttonId + " widget");
     32  let menu = document.getElementById(menuId);
     33  insertTempItemsIntoMenu(menu);
     34 
     35  CustomizableUI.addWidgetToArea(
     36    buttonId,
     37    CustomizableUI.AREA_FIXED_OVERFLOW_PANEL
     38  );
     39 
     40  await waitForOverflowButtonShown();
     41 
     42  await document.getElementById("nav-bar").overflowable.show();
     43 
     44  let button = document.getElementById(buttonId);
     45  button.click();
     46  let subview = document.getElementById(subviewId);
     47  await BrowserTestUtils.waitForEvent(subview, "ViewShown");
     48 
     49  let subviewBody = subview.firstElementChild;
     50  ok(subviewBody.firstElementChild, "Subview should have a kid");
     51  is(
     52    subviewBody.firstElementChild.localName,
     53    "toolbarbutton",
     54    "There should be no separators to start with"
     55  );
     56 
     57  for (let kid of subviewBody.children) {
     58    if (kid.localName == "menuseparator") {
     59      ok(
     60        kid.previousElementSibling &&
     61          kid.previousElementSibling.localName != "menuseparator",
     62        "Separators should never have another separator next to them, and should never be the first node."
     63      );
     64    }
     65  }
     66 
     67  let panelHiddenPromise = promiseOverflowHidden(window);
     68  PanelUI.overflowPanel.hidePopup();
     69  await panelHiddenPromise;
     70 
     71  CustomizableUI.reset();
     72 }
     73 
     74 add_task(async function check_devtools_separator() {
     75  const panelviewId = "PanelUI-developer-tools";
     76 
     77  await checkSeparatorInsertion(
     78    "menuWebDeveloperPopup",
     79    "developer-button",
     80    panelviewId
     81  );
     82 });
     83 
     84 registerCleanupFunction(function () {
     85  for (let el of tempElements) {
     86    el.remove();
     87  }
     88  tempElements = null;
     89 });