tor-browser

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

browser_toolbox_contentpage_contextmenu.js (2870B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 const URL = "data:text/html;charset=utf8,<div>test content context menu</div>";
      7 
      8 /**
      9 * Check that the DevTools context menu opens without triggering the content
     10 * context menu. See Bug 1591140.
     11 */
     12 add_task(async function () {
     13  const tab = await addTab(URL);
     14 
     15  info("Test context menu conflict with dom.event.contextmenu.enabled=true");
     16  await pushPref("dom.event.contextmenu.enabled", true);
     17  await checkConflictWithContentPageMenu(tab);
     18 
     19  info("Test context menu conflict with dom.event.contextmenu.enabled=false");
     20  await pushPref("dom.event.contextmenu.enabled", false);
     21  await checkConflictWithContentPageMenu(tab);
     22 });
     23 
     24 async function checkConflictWithContentPageMenu(tab) {
     25  const toolbox = await gDevTools.showToolboxForTab(tab, {
     26    toolId: "inspector",
     27  });
     28 
     29  info("Check that the content page context menu works as expected");
     30  const contextMenu = document.getElementById("contentAreaContextMenu");
     31  is(contextMenu.state, "closed", "Content contextmenu is closed");
     32 
     33  info("Show the content context menu");
     34  const awaitPopupShown = BrowserTestUtils.waitForEvent(
     35    contextMenu,
     36    "popupshown"
     37  );
     38  await BrowserTestUtils.synthesizeMouseAtCenter(
     39    "div",
     40    {
     41      type: "contextmenu",
     42      button: 2,
     43      centered: true,
     44    },
     45    gBrowser.selectedBrowser
     46  );
     47  await awaitPopupShown;
     48  is(contextMenu.state, "open", "Content contextmenu is open");
     49 
     50  info("Hide the content context menu");
     51  const awaitPopupHidden = BrowserTestUtils.waitForEvent(
     52    contextMenu,
     53    "popuphidden"
     54  );
     55  contextMenu.hidePopup();
     56  await awaitPopupHidden;
     57  is(contextMenu.state, "closed", "Content contextmenu is closed again");
     58 
     59  info("Check the DevTools menu opens without opening the content menu");
     60  const onContextMenuPopup = toolbox.once("menu-open");
     61  // Use inspector search box for the test, any other element should be ok as
     62  // well.
     63  const inspector = toolbox.getPanel("inspector");
     64  synthesizeContextMenuEvent(inspector.searchBox);
     65  await onContextMenuPopup;
     66 
     67  const textboxContextMenu = toolbox.getTextBoxContextMenu();
     68  is(contextMenu.state, "closed", "Content contextmenu is still closed");
     69  is(textboxContextMenu.state, "open", "Toolbox contextmenu is open");
     70 
     71  info("Check that the toolbox context menu is closed when pressing ESCAPE");
     72  const onContextMenuHidden = toolbox.once("menu-close");
     73  if (Services.prefs.getBoolPref("widget.macos.native-context-menus", false)) {
     74    info("Using hidePopup semantics because of macOS native context menus.");
     75    textboxContextMenu.hidePopup();
     76  } else {
     77    EventUtils.sendKey("ESCAPE", toolbox.win);
     78  }
     79  await onContextMenuHidden;
     80  is(textboxContextMenu.state, "closed", "Toolbox contextmenu is closed.");
     81 
     82  await toolbox.destroy();
     83 }