summaryrefslogtreecommitdiffstats
path: root/devtools/client/framework/test/browser_toolbox_contentpage_contextmenu.js
blob: 63363e4cf373804257b7d716bbf2f5c4796d2e0a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

const URL = "data:text/html;charset=utf8,<div>test content context menu</div>";

/**
 * Check that the DevTools context menu opens without triggering the content
 * context menu. See Bug 1591140.
 */
add_task(async function () {
  const tab = await addTab(URL);

  info("Test context menu conflict with dom.event.contextmenu.enabled=true");
  await pushPref("dom.event.contextmenu.enabled", true);
  await checkConflictWithContentPageMenu(tab);

  info("Test context menu conflict with dom.event.contextmenu.enabled=false");
  await pushPref("dom.event.contextmenu.enabled", false);
  await checkConflictWithContentPageMenu(tab);
});

async function checkConflictWithContentPageMenu(tab) {
  const toolbox = await gDevTools.showToolboxForTab(tab, {
    toolId: "inspector",
  });

  info("Check that the content page context menu works as expected");
  const contextMenu = document.getElementById("contentAreaContextMenu");
  is(contextMenu.state, "closed", "Content contextmenu is closed");

  info("Show the content context menu");
  const awaitPopupShown = BrowserTestUtils.waitForEvent(
    contextMenu,
    "popupshown"
  );
  await BrowserTestUtils.synthesizeMouseAtCenter(
    "div",
    {
      type: "contextmenu",
      button: 2,
      centered: true,
    },
    gBrowser.selectedBrowser
  );
  await awaitPopupShown;
  is(contextMenu.state, "open", "Content contextmenu is open");

  info("Hide the content context menu");
  const awaitPopupHidden = BrowserTestUtils.waitForEvent(
    contextMenu,
    "popuphidden"
  );
  contextMenu.hidePopup();
  await awaitPopupHidden;
  is(contextMenu.state, "closed", "Content contextmenu is closed again");

  info("Check the DevTools menu opens without opening the content menu");
  const onContextMenuPopup = toolbox.once("menu-open");
  // Use inspector search box for the test, any other element should be ok as
  // well.
  const inspector = toolbox.getPanel("inspector");
  synthesizeContextMenuEvent(inspector.searchBox);
  await onContextMenuPopup;

  const textboxContextMenu = toolbox.getTextBoxContextMenu();
  is(contextMenu.state, "closed", "Content contextmenu is still closed");
  is(textboxContextMenu.state, "open", "Toolbox contextmenu is open");

  info("Check that the toolbox context menu is closed when pressing ESCAPE");
  const onContextMenuHidden = toolbox.once("menu-close");
  if (Services.prefs.getBoolPref("widget.macos.native-context-menus", false)) {
    info("Using hidePopup semantics because of macOS native context menus.");
    textboxContextMenu.hidePopup();
  } else {
    EventUtils.sendKey("ESCAPE", toolbox.win);
  }
  await onContextMenuHidden;
  is(textboxContextMenu.state, "closed", "Toolbox contextmenu is closed.");

  await toolbox.destroy();
}