summaryrefslogtreecommitdiffstats
path: root/browser/base/content/test/general/browser_contextmenu_childprocess.js
blob: 3d52be9aba51ea9d93373a962bcc82be9530772f (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
/* 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/general/";

add_task(function *() {
  let tab = yield 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");
  yield BrowserTestUtils.synthesizeMouse("#test-pagemenu", 5, 5, { type : "contextmenu", button : 2 }, tab.linkedBrowser);
  yield popupShownPromise;

  checkMenu(contextMenu);

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

  yield 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.firstChild.firstChild, 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.nextSibling;
  }
}

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.childNodes[2], items);
}