summaryrefslogtreecommitdiffstats
path: root/accessible/tests/browser/mac/browser_menulist.js
blob: b26a0be782d311f25ce7886f1f8bee1fa93d1255 (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
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

"use strict";

/* import-globals-from ../../mochitest/attributes.js */
/* import-globals-from ../../mochitest/role.js */
/* import-globals-from ../../mochitest/states.js */
loadScripts(
  { name: "role.js", dir: MOCHITESTS_DIR },
  { name: "states.js", dir: MOCHITESTS_DIR },
  { name: "attributes.js", dir: MOCHITESTS_DIR }
);

addAccessibleTask(
  "mac/doc_menulist.xhtml",
  async (browser, accDoc) => {
    const menulist = getNativeInterface(accDoc, "defaultZoom");

    let actions = menulist.actionNames;
    ok(actions.includes("AXPress"), "menu has press action");

    let event = waitForMacEvent("AXMenuOpened");
    menulist.performAction("AXPress");
    const menupopup = await event;

    const menuItems = menupopup.getAttributeValue("AXChildren");
    is(menuItems.length, 4, "Found four children in menulist");
    is(
      menuItems[0].getAttributeValue("AXTitle"),
      "50%",
      "First item has correct title"
    );
    is(
      menuItems[1].getAttributeValue("AXTitle"),
      "100%",
      "Second item has correct title"
    );
    is(
      menuItems[2].getAttributeValue("AXTitle"),
      "150%",
      "Third item has correct title"
    );
    is(
      menuItems[3].getAttributeValue("AXTitle"),
      "200%",
      "Fourth item has correct title"
    );
  },
  { topLevel: false, chrome: true }
);

addAccessibleTask(
  "mac/doc_menulist.xhtml",
  async (browser, accDoc) => {
    const menulist = getNativeInterface(accDoc, "defaultZoom");

    const actions = menulist.actionNames;
    ok(actions.includes("AXPress"), "menu has press action");
    let event = waitForMacEvent("AXMenuOpened");
    menulist.performAction("AXPress");
    await event;

    const menu = menulist.getAttributeValue("AXChildren")[0];
    ok(menu, "Menulist contains menu");
    const children = menu.getAttributeValue("AXChildren");
    is(children.length, 4, "Menu has 4 items");

    // Menu is open, initial focus should land on the first item
    is(
      children[0].getAttributeValue("AXSelected"),
      1,
      "First menu item is selected"
    );
    // focus the second item, and verify it is selected
    event = waitForMacEvent("AXFocusedUIElementChanged", (iface, data) => {
      try {
        return iface.getAttributeValue("AXTitle") == "100%";
      } catch (e) {
        return false;
      }
    });
    EventUtils.synthesizeKey("KEY_ArrowDown");
    await event;

    is(
      children[0].getAttributeValue("AXSelected"),
      0,
      "First menu item is no longer selected"
    );
    is(
      children[1].getAttributeValue("AXSelected"),
      1,
      "Second menu item is selected"
    );
    // press the second item, check for selected event
    event = waitForMacEvent("AXMenuItemSelected");
    children[1].performAction("AXPress");
    await event;
  },
  { topLevel: false, chrome: true }
);