summaryrefslogtreecommitdiffstats
path: root/accessible/tests/mochitest/events/test_focus_selects.html
blob: 2346691dfd541a0191e169f1200cd34caccf1ff6 (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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
<html>

<head>
  <title>Accessible focus testing</title>

  <link rel="stylesheet" type="text/css"
        href="chrome://mochikit/content/tests/SimpleTest/test.css" />

  <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
  <script src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>

  <script type="application/javascript"
          src="../common.js"></script>
  <script type="application/javascript"
          src="../promisified-events.js"></script>
  <script type="application/javascript"
          src="../role.js"></script>
  <script type="application/javascript"
          src="../states.js"></script>

  <script type="application/javascript">
    // gA11yEventDumpID = "eventdump"; // debug stuff
    // gA11yEventDumpToConsole = true;
    var gQueue = null;

    async function doTests() {
      // Bug 746534 - File causes crash or hang on OS X
      if (MAC) {
        todo(false, "Bug 746534 - test file causes crash or hang on OS X");
        SimpleTest.finish();
        return;
      }

      let p = waitForEvent(EVENT_FOCUS, "orange");
      // first item is focused until there's selection
      getNode("list").focus();
      await p;

      p = waitForEvents({
        expected: [[EVENT_SELECTION, "orange"]],
        unexpected: [
          [EVENT_FOCUS],
          stateChangeEventArgs("orange", EXT_STATE_ACTIVE, true, true),
        ],
      });
      // item is selected and stays focused and active
      synthesizeKey("VK_DOWN");
      await p;

      p = waitForEvents([
        stateChangeEventArgs("orange", EXT_STATE_ACTIVE, false, true),
        stateChangeEventArgs("apple", EXT_STATE_ACTIVE, true, true),
        [EVENT_FOCUS, "apple"],
      ]);
      // last selected item is focused
      synthesizeKey("VK_DOWN", { shiftKey: true });
      await p;

      p = waitForEvents({
        expected: [
          [EVENT_FOCUS, "orange"],
          stateChangeEventArgs("orange", EXT_STATE_ACTIVE, true, true),
        ],
        unexpected: [
          [EVENT_FOCUS, "apple"],
          stateChangeEventArgs("apple", EXT_STATE_ACTIVE, true, true),
        ],
      });
      // no focus event if nothing is changed
      synthesizeKey("VK_DOWN");
      // current item is focused
      synthesizeKey("VK_UP", { ctrlKey: true });
      await p;

      p = waitForEvent(EVENT_FOCUS, "emptylist");
      // focus on empty list (no items to be focused)
      synthesizeKey("VK_TAB");
      await p;

      p = waitForEvents({
        expected: [[EVENT_FOCUS, "orange"]],
        unexpected: [stateChangeEventArgs("orange", EXT_STATE_ACTIVE, true, true)],
      });
      // current item is focused
      synthesizeKey("VK_TAB", { shiftKey: true });
      await p;

      p = waitForEvent(EVENT_FOCUS, "combobox");
      getNode("combobox").focus();
      await p;

      p = waitForEvents({
        expected: [[EVENT_SELECTION, "cb_apple"]],
        unexpected: [
          [EVENT_FOCUS],
          stateChangeEventArgs("cb_apple", EXT_STATE_ACTIVE, true, true),
        ],
      });
      // collapsed combobox keeps a focus
      synthesizeKey("VK_DOWN");
      await p;

      // no focus events for unfocused list controls when current item is
      // changed

      p = waitForEvent(EVENT_FOCUS, "emptylist");
      getNode("emptylist").focus();
      await p;

      p = waitForEvents({
        expected: [[EVENT_SELECTION, "orange"]],
        unexpected: [
          [EVENT_FOCUS],
          stateChangeEventArgs("orange", EXT_STATE_ACTIVE, true, true),
        ],
      });
      // An unfocused selectable list gets selection change events,
      // but not active or focus change events.
      getNode("list").selectedIndex = getNode("orange").index;
      await p;

      p = waitForEvents({
        expected: [[EVENT_SELECTION, "cb_orange"]],
        unexpected: [
          [EVENT_FOCUS],
          stateChangeEventArgs("cb_orange", EXT_STATE_ACTIVE, true, true),
        ],
      });
      // An unfocused selectable combobox gets selection change events,
      // but not focus events nor active state change events.
      getNode("cb_orange").selected = true;
      await p;

      // Bug 1838983: Make sure we don't fail a C++ assertion when the focused
      // active item is destroyed.
      info("Focusing recreate");
      p = waitForEvent(EVENT_FOCUS, "recreateA");
      const recreate = getNode("recreate");
      recreate.focus();
      await p;
      info("Changing recreate size");
      p = waitForEvent(EVENT_FOCUS, recreate);
      // This will recreate the select and its children.
      recreate.size = 1;
      await p;

      SimpleTest.finish();
    }

    SimpleTest.waitForExplicitFinish();
    addA11yLoadEvent(doTests);
  </script>
</head>

<body>

  <a target="_blank"
     href="https://bugzilla.mozilla.org/show_bug.cgi?id=433418"
     title="Accessibles for focused HTML Select elements are not getting focused state">
    Mozilla Bug 433418
  </a>
  <a target="_blank"
     href="https://bugzilla.mozilla.org/show_bug.cgi?id=474893"
     title="List controls should fire a focus event on the selected child when tabbing or when the selected child changes while the list is focused">
    Mozilla Bug 474893
  </a>
  <p id="display"></p>
  <div id="content" style="display: none"></div>
  <pre id="test">
  </pre>

  <select id="list" size="5" multiple="">
    <option id="orange">Orange</option>
    <option id="apple">Apple</option>
  </select>

  <select id="emptylist" size="5"></select>

  <select id="combobox">
    <option id="cb_orange">Orange</option>
    <option id="cb_apple">Apple</option>
  </select>

  <select id="recreate" size="5">
    <option id="recreateA">a</option>
  </select>

  <div id="eventdump"></div>
</body>
</html>