tor-browser

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

browser_aboutdebugging_devtoolstoolbox_contextmenu.js (2805B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 /* import-globals-from helper-collapsibilities.js */
      7 Services.scriptloader.loadSubScript(
      8  CHROME_URL_ROOT + "helper-collapsibilities.js",
      9  this
     10 );
     11 
     12 /**
     13 * Test context menu on about:devtools-toolbox page.
     14 */
     15 add_task(async function () {
     16  info("Force all debug target panes to be expanded");
     17  prepareCollapsibilitiesTest();
     18 
     19  const { document, tab, window } = await openAboutDebugging();
     20  await selectThisFirefoxPage(document, window.AboutDebugging.store);
     21  const { devtoolsBrowser, devtoolsTab } = await openAboutDevtoolsToolbox(
     22    document,
     23    tab,
     24    window
     25  );
     26 
     27  info("Check whether the menu item which opens devtools is disabled");
     28  const rootDocument = devtoolsTab.ownerDocument;
     29  await assertContextMenu(
     30    rootDocument,
     31    devtoolsBrowser,
     32    ".debug-target-info",
     33    false
     34  );
     35 
     36  info("Force to select about:debugging page");
     37  await updateSelectedTab(gBrowser, tab, window.AboutDebugging.store);
     38 
     39  info("Check whether the menu item which opens devtools is enabled");
     40  await assertContextMenu(rootDocument, devtoolsBrowser, "#mount", true);
     41 
     42  await closeAboutDevtoolsToolbox(document, devtoolsTab, window);
     43  await removeTab(tab);
     44 });
     45 
     46 async function assertContextMenu(
     47  rootDocument,
     48  browser,
     49  targetSelector,
     50  shouldBeEnabled
     51 ) {
     52  if (shouldBeEnabled) {
     53    await assertContextMenuEnabled(rootDocument, browser, targetSelector);
     54  } else {
     55    await assertContextMenuDisabled(rootDocument, browser, targetSelector);
     56  }
     57 }
     58 
     59 async function assertContextMenuDisabled(
     60  rootDocument,
     61  browser,
     62  targetSelector
     63 ) {
     64  const contextMenu = rootDocument.getElementById("contentAreaContextMenu");
     65  let isPopupShown = false;
     66  const listener = () => {
     67    isPopupShown = true;
     68  };
     69  contextMenu.addEventListener("popupshown", listener);
     70  BrowserTestUtils.synthesizeMouseAtCenter(
     71    targetSelector,
     72    { type: "contextmenu" },
     73    browser
     74  );
     75  await wait(1000);
     76  ok(!isPopupShown, `Context menu should not be shown`);
     77  contextMenu.removeEventListener("popupshown", listener);
     78 }
     79 
     80 async function assertContextMenuEnabled(rootDocument, browser, targetSelector) {
     81  // Show content context menu.
     82  const contextMenu = rootDocument.getElementById("contentAreaContextMenu");
     83  const popupShownPromise = BrowserTestUtils.waitForEvent(
     84    contextMenu,
     85    "popupshown"
     86  );
     87  BrowserTestUtils.synthesizeMouseAtCenter(
     88    targetSelector,
     89    { type: "contextmenu" },
     90    browser
     91  );
     92  await popupShownPromise;
     93  ok(true, `Context menu should be shown`);
     94 
     95  // Hide content context menu.
     96  const popupHiddenPromise = BrowserTestUtils.waitForEvent(
     97    contextMenu,
     98    "popuphidden"
     99  );
    100  contextMenu.hidePopup();
    101  await popupHiddenPromise;
    102 }