summaryrefslogtreecommitdiffstats
path: root/devtools/client/inspector/markup/test/browser_markup_accessibility_navigation.js
blob: 41e35afef2407fff7a72fbe83583e2694c863d52 (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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
/* 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/. */
/* import-globals-from helper_markup_accessibility_navigation.js */

"use strict";

// Test keyboard navigation accessibility of inspector's markup view.

loadHelperScript("helper_markup_accessibility_navigation.js");

/**
 * Test data has the format of:
 * {
 *   desc              {String}   description for better logging
 *   key               {String}   key event's key
 *   options           {?Object}  optional event data such as shiftKey, etc
 *   focused           {String}   path to expected focused element relative to
 *                                its container
 *   activedescendant  {String}   path to expected aria-activedescendant element
 *                                relative to its container
 *   waitFor           {String}   optional event to wait for if keyboard actions
 *                                result in asynchronous updates
 * }
 */
const TESTS = [
  {
    desc: "Collapse body container",
    focused: "root.elt",
    activedescendant: "body.tagLine",
    key: "VK_LEFT",
    options: { },
    waitFor: "collapsed"
  },
  {
    desc: "Expand body container",
    focused: "root.elt",
    activedescendant: "body.tagLine",
    key: "VK_RIGHT",
    options: { },
    waitFor: "expanded"
  },
  {
    desc: "Select header container",
    focused: "root.elt",
    activedescendant: "header.tagLine",
    key: "VK_DOWN",
    options: { },
    waitFor: "inspector-updated"
  },
  {
    desc: "Expand header container",
    focused: "root.elt",
    activedescendant: "header.tagLine",
    key: "VK_RIGHT",
    options: { },
    waitFor: "expanded"
  },
  {
    desc: "Select text container",
    focused: "root.elt",
    activedescendant: "container-0.tagLine",
    key: "VK_DOWN",
    options: { },
    waitFor: "inspector-updated"
  },
  {
    desc: "Select header container again",
    focused: "root.elt",
    activedescendant: "header.tagLine",
    key: "VK_UP",
    options: { },
    waitFor: "inspector-updated"
  },
  {
    desc: "Collapse header container",
    focused: "root.elt",
    activedescendant: "header.tagLine",
    key: "VK_LEFT",
    options: { },
    waitFor: "collapsed"
  },
  {
    desc: "Focus on header container tag",
    focused: "header.focusableElms.0",
    activedescendant: "header.tagLine",
    key: "VK_RETURN",
    options: { }
  },
  {
    desc: "Remove focus from header container tag",
    focused: "root.elt",
    activedescendant: "header.tagLine",
    key: "VK_ESCAPE",
    options: { }
  },
  {
    desc: "Focus on header container tag again",
    focused: "header.focusableElms.0",
    activedescendant: "header.tagLine",
    key: "VK_SPACE",
    options: { }
  },
  {
    desc: "Focus on header id attribute",
    focused: "header.focusableElms.1",
    activedescendant: "header.tagLine",
    key: "VK_TAB",
    options: { }
  },
  {
    desc: "Focus on header class attribute",
    focused: "header.focusableElms.2",
    activedescendant: "header.tagLine",
    key: "VK_TAB",
    options: { }
  },
  {
    desc: "Focus on header new attribute",
    focused: "header.focusableElms.3",
    activedescendant: "header.tagLine",
    key: "VK_TAB",
    options: { }
  },
  {
    desc: "Circle back and focus on header tag again",
    focused: "header.focusableElms.0",
    activedescendant: "header.tagLine",
    key: "VK_TAB",
    options: { }
  },
  {
    desc: "Circle back and focus on header new attribute again",
    focused: "header.focusableElms.3",
    activedescendant: "header.tagLine",
    key: "VK_TAB",
    options: { shiftKey: true }
  },
  {
    desc: "Tab back and focus on header class attribute",
    focused: "header.focusableElms.2",
    activedescendant: "header.tagLine",
    key: "VK_TAB",
    options: { shiftKey: true }
  },
  {
    desc: "Tab back and focus on header id attribute",
    focused: "header.focusableElms.1",
    activedescendant: "header.tagLine",
    key: "VK_TAB",
    options: { shiftKey: true }
  },
  {
    desc: "Tab back and focus on header tag",
    focused: "header.focusableElms.0",
    activedescendant: "header.tagLine",
    key: "VK_TAB",
    options: { shiftKey: true }
  },
  {
    desc: "Expand header container, ensure that focus is still on header tag",
    focused: "header.focusableElms.0",
    activedescendant: "header.tagLine",
    key: "VK_RIGHT",
    options: { },
    waitFor: "expanded"
  },
  {
    desc: "Activate header tag editor",
    focused: "header.editor.tag.inplaceEditor.input",
    activedescendant: "header.tagLine",
    key: "VK_RETURN",
    options: { }
  },
  {
    desc: "Activate header id attribute editor",
    focused: "header.editor.attrList.children.0.children.1.inplaceEditor.input",
    activedescendant: "header.tagLine",
    key: "VK_TAB",
    options: { }
  },
  {
    desc: "Deselect text in header id attribute editor",
    focused: "header.editor.attrList.children.0.children.1.inplaceEditor.input",
    activedescendant: "header.tagLine",
    key: "VK_TAB",
    options: { }
  },
  {
    desc: "Activate header class attribute editor",
    focused: "header.editor.attrList.children.1.children.1.inplaceEditor.input",
    activedescendant: "header.tagLine",
    key: "VK_TAB",
    options: { }
  },
  {
    desc: "Deselect text in header class attribute editor",
    focused: "header.editor.attrList.children.1.children.1.inplaceEditor.input",
    activedescendant: "header.tagLine",
    key: "VK_TAB",
    options: { }
  },
  {
    desc: "Activate header new attribute editor",
    focused: "header.editor.newAttr.inplaceEditor.input",
    activedescendant: "header.tagLine",
    key: "VK_TAB",
    options: { }
  },
  {
    desc: "Circle back and activate header tag editor again",
    focused: "header.editor.tag.inplaceEditor.input",
    activedescendant: "header.tagLine",
    key: "VK_TAB",
    options: { }
  },
  {
    desc: "Circle back and activate header new attribute editor again",
    focused: "header.editor.newAttr.inplaceEditor.input",
    activedescendant: "header.tagLine",
    key: "VK_TAB",
    options: { shiftKey: true }
  },
  {
    desc: "Exit edit mode and keep focus on header new attribute",
    focused: "header.focusableElms.3",
    activedescendant: "header.tagLine",
    key: "VK_ESCAPE",
    options: { }
  },
  {
    desc: "Move the selection to body and reset focus to container tree",
    focused: "docBody",
    activedescendant: "body.tagLine",
    key: "VK_UP",
    options: { },
    waitFor: "inspector-updated"
  },
];

let containerID = 0;
let elms = {};

add_task(function* () {
  let { inspector } = yield openInspectorForURL(`data:text/html;charset=utf-8,
    <h1 id="some-id" class="some-class">foo<span>Child span<span></h1>`);

  // Record containers that are created after inspector is initialized to be
  // useful in testing.
  inspector.on("container-created", memorizeContainer);
  registerCleanupFunction(() => {
    inspector.off("container-created", memorizeContainer);
  });

  elms.docBody = inspector.markup.doc.body;
  elms.root = inspector.markup.getContainer(inspector.markup._rootNode);
  elms.header = yield getContainerForSelector("h1", inspector);
  elms.body = yield getContainerForSelector("body", inspector);

  // Initial focus is on root element and active descendant should be set on
  // body tag line.
  testNavigationState(inspector, elms, elms.docBody, elms.body.tagLine);

  // Focus on the tree element.
  elms.root.elt.focus();

  for (let testData of TESTS) {
    yield runAccessibilityNavigationTest(inspector, elms, testData);
  }

  elms = null;
});

// Record all containers that are created dynamically into elms object.
function memorizeContainer(event, container) {
  elms[`container-${containerID++}`] = container;
}