summaryrefslogtreecommitdiffstats
path: root/browser/base/content/test/contextMenu/browser_contextmenu_childprocess.js
blob: af85d0a62cac0bd2ae2eb947ed0d8aef88b62fc9 (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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

const gBaseURL =
  "https://example.com/browser/browser/base/content/test/contextMenu/";

add_task(async function() {
  await SpecialPowers.pushPrefEnv({
    set: [["dom.menuitem.enabled", true]],
  });

  let tab = await BrowserTestUtils.openNewForegroundTab(
    gBrowser,
    gBaseURL + "subtst_contextmenu.html"
  );

  let contextMenu = document.getElementById("contentAreaContextMenu");

  // Get the point of the element with the page menu (test-pagemenu) and
  // synthesize a right mouse click there.
  let popupShownPromise = BrowserTestUtils.waitForEvent(
    contextMenu,
    "popupshown"
  );
  await BrowserTestUtils.synthesizeMouse(
    "#test-pagemenu",
    5,
    5,
    { type: "contextmenu", button: 2 },
    tab.linkedBrowser
  );
  await popupShownPromise;

  checkMenu(contextMenu);

  let popupHiddenPromise = BrowserTestUtils.waitForEvent(
    contextMenu,
    "popuphidden"
  );
  contextMenu.hidePopup();
  await popupHiddenPromise;

  BrowserTestUtils.removeTab(tab);
});

function checkItems(menuitem, arr) {
  for (let i = 0; i < arr.length; i += 2) {
    let str = arr[i];
    let details = arr[i + 1];
    if (str == "---") {
      is(menuitem.localName, "menuseparator", "menuseparator");
    } else if ("children" in details) {
      is(menuitem.localName, "menu", "submenu");
      is(menuitem.getAttribute("label"), str, str + " label");
      checkItems(menuitem.menupopup.firstElementChild, details.children);
    } else {
      is(menuitem.localName, "menuitem", str + " menuitem");

      is(menuitem.getAttribute("label"), str, str + " label");
      is(menuitem.getAttribute("type"), details.type, str + " type");
      is(
        menuitem.getAttribute("image"),
        details.icon ? gBaseURL + details.icon : "",
        str + " icon"
      );

      if (details.checked) {
        is(menuitem.getAttribute("checked"), "true", str + " checked");
      } else {
        ok(!menuitem.hasAttribute("checked"), str + " checked");
      }

      if (details.disabled) {
        is(menuitem.getAttribute("disabled"), "true", str + " disabled");
      } else {
        ok(!menuitem.hasAttribute("disabled"), str + " disabled");
      }
    }

    menuitem = menuitem.nextElementSibling;
  }
}

function checkMenu(contextMenu) {
  let items = [
    "Plain item",
    { type: "", icon: "", checked: false, disabled: false },
    "Disabled item",
    { type: "", icon: "", checked: false, disabled: true },
    "Item w/ textContent",
    { type: "", icon: "", checked: false, disabled: false },
    "---",
    null,
    "Checkbox",
    { type: "checkbox", icon: "", checked: true, disabled: false },
    "---",
    null,
    "Radio1",
    { type: "checkbox", icon: "", checked: true, disabled: false },
    "Radio2",
    { type: "checkbox", icon: "", checked: false, disabled: false },
    "Radio3",
    { type: "checkbox", icon: "", checked: false, disabled: false },
    "---",
    null,
    "Item w/ icon",
    { type: "", icon: "favicon.ico", checked: false, disabled: false },
    "Item w/ bad icon",
    { type: "", icon: "", checked: false, disabled: false },
    "---",
    null,
    "Submenu",
    {
      children: [
        "Radio1",
        { type: "checkbox", icon: "", checked: false, disabled: false },
        "Radio2",
        { type: "checkbox", icon: "", checked: true, disabled: false },
        "Radio3",
        { type: "checkbox", icon: "", checked: false, disabled: false },
        "---",
        null,
        "Checkbox",
        { type: "checkbox", icon: "", checked: false, disabled: false },
      ],
    },
  ];
  checkItems(contextMenu.children[2], items);
}