tor-browser

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

browser_989751_subviewbutton_class.js (2845B)


      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 const kCustomClass = "acustomclassnoonewilluse";
      8 const kDevPanelId = "PanelUI-developer-tools";
      9 var tempElement = null;
     10 
     11 function insertClassNameToMenuChildren(parentMenu) {
     12  // Skip hidden menuitem elements, not copied via fillSubviewFromMenuItems.
     13  let el = parentMenu.querySelector("menuitem:not([hidden])");
     14  el.classList.add(kCustomClass);
     15  tempElement = el;
     16 }
     17 
     18 function checkSubviewButtonClass(menuId, buttonId, subviewId) {
     19  return async function () {
     20    // Initialize DevTools before starting the test in order to create menuitems in
     21    // menuWebDeveloperPopup.
     22    ChromeUtils.importESModule(
     23      "resource://devtools/shared/loader/Loader.sys.mjs"
     24    ).require("devtools/client/framework/devtools-browser");
     25 
     26    info(
     27      "Checking for items without the subviewbutton class in " +
     28        buttonId +
     29        " widget"
     30    );
     31    let menu = document.getElementById(menuId);
     32    insertClassNameToMenuChildren(menu);
     33 
     34    CustomizableUI.addWidgetToArea(
     35      buttonId,
     36      CustomizableUI.AREA_FIXED_OVERFLOW_PANEL
     37    );
     38 
     39    await waitForOverflowButtonShown();
     40 
     41    await document.getElementById("nav-bar").overflowable.show();
     42 
     43    let button = document.getElementById(buttonId);
     44    button.click();
     45 
     46    await BrowserTestUtils.waitForEvent(PanelUI.overflowPanel, "ViewShown");
     47    let subview = document.getElementById(subviewId);
     48    ok(subview.firstElementChild, "Subview should have a kid");
     49 
     50    // The Developer Panel contains the Customize Toolbar item,
     51    // as well as the Developer Tools items (bug 1703150). We only want to query for
     52    // the Developer Tools items in this case.
     53    let query = "#appmenu-developer-tools-view toolbarbutton";
     54    let subviewchildren = subview.querySelectorAll(query);
     55 
     56    for (let i = 0; i < subviewchildren.length; i++) {
     57      let item = subviewchildren[i];
     58      let itemReadable =
     59        "Item '" + item.label + "' (classes: " + item.className + ")";
     60      ok(
     61        item.classList.contains("subviewbutton"),
     62        itemReadable + " should have the subviewbutton class."
     63      );
     64      if (i == 0) {
     65        ok(
     66          item.classList.contains(kCustomClass),
     67          itemReadable + " should still have its own class, too."
     68        );
     69      }
     70    }
     71 
     72    let panelHiddenPromise = promiseOverflowHidden(window);
     73    PanelUI.overflowPanel.hidePopup();
     74    await panelHiddenPromise;
     75 
     76    CustomizableUI.reset();
     77  };
     78 }
     79 
     80 add_task(
     81  checkSubviewButtonClass(
     82    "menuWebDeveloperPopup",
     83    "developer-button",
     84    kDevPanelId
     85  )
     86 );
     87 
     88 registerCleanupFunction(function () {
     89  tempElement.classList.remove(kCustomClass);
     90  tempElement = null;
     91 });