summaryrefslogtreecommitdiffstats
path: root/devtools/server/tests/browser/browser_accessibility_keyboard_audit.js
blob: 508ccbaf3fa21ae93e779952b7a4558bc5cf87c5 (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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
/* 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";

/**
 * Checks functionality around text label audit for the AccessibleActor.
 */

const {
  accessibility: {
    AUDIT_TYPE: { KEYBOARD },
    SCORES: { FAIL, WARNING },
    ISSUE_TYPE: {
      [KEYBOARD]: {
        FOCUSABLE_NO_SEMANTICS,
        FOCUSABLE_POSITIVE_TABINDEX,
        INTERACTIVE_NO_ACTION,
        INTERACTIVE_NOT_FOCUSABLE,
        MOUSE_INTERACTIVE_ONLY,
        NO_FOCUS_VISIBLE,
      },
    },
  },
} = require("devtools/shared/constants");

add_task(async function() {
  const {
    target,
    walker,
    parentAccessibility,
    a11yWalker,
  } = await initAccessibilityFrontsForUrl(
    `${MAIN_DOMAIN}doc_accessibility_keyboard_audit.html`
  );

  const tests = [
    [
      "Focusable element (styled button) with no semantics.",
      "#button-1",
      { score: WARNING, issue: FOCUSABLE_NO_SEMANTICS },
    ],
    ["Element (styled button) with no semantics.", "#button-2", null],
    [
      "Container element for out of order focusable element.",
      "#input-container",
      null,
    ],
    [
      "Interactive element with focus out of order (-1).",
      "#input-1",
      {
        score: FAIL,
        issue: INTERACTIVE_NOT_FOCUSABLE,
      },
    ],
    [
      "Interactive element with focus out of order (-1) when disabled.",
      "#input-2",
      null,
    ],
    ["Interactive element when disabled.", "#input-3", null],
    ["Focusable interactive element.", "#input-4", null],
    [
      "Interactive accesible (link with no attributes) with no accessible actions.",
      "#link-1",
      {
        score: FAIL,
        issue: INTERACTIVE_NO_ACTION,
      },
    ],
    ["Interactive accessible (link with valid href).", "#link-2", null],
    ["Interactive accessible (link with # as href).", "#link-3", null],
    [
      "Interactive accessible (link with empty string as href).",
      "#link-4",
      null,
    ],
    ["Interactive accessible with no tabindex.", "#button-3", null],
    [
      "Interactive accessible with -1 tabindex.",
      "#button-4",
      {
        score: FAIL,
        issue: INTERACTIVE_NOT_FOCUSABLE,
      },
    ],
    ["Interactive accessible with 0 tabindex.", "#button-5", null],
    [
      "Interactive accessible with 1 tabindex.",
      "#button-6",
      { score: WARNING, issue: FOCUSABLE_POSITIVE_TABINDEX },
    ],
    [
      "Focusable ARIA button with no focus styling.",
      "#focusable-1",
      { score: WARNING, issue: NO_FOCUS_VISIBLE },
    ],
    ["Focusable ARIA button with focus styling.", "#focusable-2", null],
    ["Focusable ARIA button with browser styling.", "#focusable-3", null],
    [
      "Not focusable, non-semantic element that has a click handler.",
      "#mouse-only-1",
      { score: FAIL, issue: MOUSE_INTERACTIVE_ONLY },
    ],
    [
      "Focusable, non-semantic element that has a click handler.",
      "#focusable-4",
      { score: WARNING, issue: FOCUSABLE_NO_SEMANTICS },
    ],
    [
      "Not focusable, ARIA button that has a click handler.",
      "#button-7",
      { score: FAIL, issue: INTERACTIVE_NOT_FOCUSABLE },
    ],
    ["Focusable, ARIA button with a click handler.", "#button-8", null],
    ["Regular image, no keyboard checks should flag an issue.", "#img-1", null],
    [
      "Image with a longdesc (accessible will have showlongdesc action).",
      "#img-2",
      null,
    ],
    [
      "Clickable image with a longdesc (accessible will have click and showlongdesc actions).",
      "#img-3",
      { score: FAIL, issue: MOUSE_INTERACTIVE_ONLY },
    ],
    [
      "Clickable image (accessible will have click action).",
      "#img-4",
      { score: FAIL, issue: MOUSE_INTERACTIVE_ONLY },
    ],
    ["Focusable button with aria-haspopup.", "#buttonmenu-1", null],
    [
      "Not focusable aria button with aria-haspopup.",
      "#buttonmenu-2",
      {
        score: FAIL,
        issue: INTERACTIVE_NOT_FOCUSABLE,
      },
    ],
    ["Focusable checkbox.", "#checkbox-1", null],
    ["Focusable select element size > 1", "#listbox-1", null],
    ["Focusable select element with one option", "#combobox-1", null],
    ["Focusable select element with no options", "#combobox-2", null],
    ["Focusable select element with two options", "#combobox-3", null],
    [
      "Non-focusable aria combobox with one aria option.",
      "#editcombobox-1",
      null,
    ],
    ["Non-focusable aria combobox with no options.", "#editcombobox-2", null],
    ["Focusable aria combobox with no options.", "#editcombobox-3", null],
    [
      "Non-focusable aria switch",
      "#switch-1",
      {
        score: FAIL,
        issue: INTERACTIVE_NOT_FOCUSABLE,
      },
    ],
    ["Focusable aria switch", "#switch-2", null],
    [
      "Combobox list that is visible (has focusable state)",
      "#owned_listbox",
      null,
    ],
    [
      "Mouse interactive, label that contains form element (linked)",
      "#label-1",
      null,
    ],
    ["Mouse interactive label for external element (linked)", "#label-2", null],
    ["Not interactive unlinked label", "#label-3", null],
    [
      "Not interactive unlinked label with folloing form element",
      "#label-4",
      null,
    ],
    ["Image inside an anchor (href)", "#img-5", null],
    ["Image inside an anchor (onmousedown)", "#img-6", null],
    ["Image inside an anchor (onclick)", "#img-7", null],
    ["Image inside an anchor (onmouseup)", "#img-8", null],
    [
      "Section with a collapse action from aria-expanded attribute",
      "#section-1",
      null,
    ],
    ["Tabindex -1 should not report an element as focusable", "#main", null],
    [
      "Not keyboard focusable element with no focus styling.",
      "#not-keyboard-focusable-1",
      null,
    ],
    ["Interactive grid that is not focusable.", "#grid-1", null],
    ["Focusable interactive grid.", "#grid-2", null],
    [
      "Non interactive ARIA table does not need to be focusable.",
      "#table-1",
      null,
    ],
    [
      "Focusable ARIA table does not have interactive semantics",
      "#table-2",
      { score: "WARNING", issue: "FOCUSABLE_NO_SEMANTICS" },
    ],
    ["Non interactive table does not need to be focusable.", "#table-3", null],
    [
      "Focusable table does not have interactive semantics",
      "#table-4",
      { score: "WARNING", issue: "FOCUSABLE_NO_SEMANTICS" },
    ],
    [
      "Article that is not focusable is not considered interactive",
      "#article-1",
      null,
    ],
    ["Focusable article is considered interactive", "#article-2", null],
    [
      "Column header that is not focusable is not considered interactive (ARIA grid)",
      "#columnheader-1",
      null,
    ],
    [
      "Column header that is not focusable is not considered interactive (ARIA table)",
      "#columnheader-2",
      null,
    ],
    [
      "Column header that is not focusable is not considered interactive (table)",
      "#columnheader-3",
      null,
    ],
    [
      "Column header that is focusable is considered interactive (table)",
      "#columnheader-4",
      null,
    ],
    [
      "Column header that is not focusable is not considered interactive (table as ARIA grid)",
      "#columnheader-5",
      null,
    ],
    [
      "Column header that is focusable is considered interactive (table as ARIA grid)",
      "#columnheader-6",
      null,
    ],
    [
      "Row header that is not focusable is not considered interactive",
      "#rowheader-1",
      null,
    ],
    [
      "Row header that is not focusable is not considered interactive",
      "#rowheader-2",
      null,
    ],
    [
      "Row header that is not focusable is not considered interactive",
      "#rowheader-3",
      null,
    ],
    [
      "Row header that is focusable is considered interactive",
      "#rowheader-4",
      null,
    ],
    [
      "Row header that is not focusable is not considered interactive (table as ARIA grid)",
      "#rowheader-5",
      null,
    ],
    [
      "Row header that is focusable is considered interactive (table as ARIA grid)",
      "#rowheader-6",
      null,
    ],
    [
      "Gridcell that is not focusable is not considered interactive (ARIA grid)",
      "#gridcell-1",
      null,
    ],
    [
      "Gridcell that is focusable is considered interactive (ARIA grid)",
      "#gridcell-2",
      null,
    ],
    [
      "Gridcell that is not focusable is not considered interactive (table as ARIA grid)",
      "#gridcell-3",
      null,
    ],
    [
      "Gridcell that is focusable is considered interactive (table as ARIA grid)",
      "#gridcell-4",
      null,
    ],
    [
      "Tab list that is not focusable is not considered interactive",
      "#tablist-1",
      null,
    ],
    ["Focusable tab list is considered interactive", "#tablist-2", null],
    [
      "Scrollbar that is not focusable is not considered interactive",
      "#scrollbar-1",
      null,
    ],
    ["Focusable scrollbar is considered interactive", "#scrollbar-2", null],
    [
      "Separator that is not focusable is not considered interactive",
      "#separator-1",
      null,
    ],
    ["Focusable separator is considered interactive", "#separator-2", null],
    [
      "Toolbar that is not focusable is not considered interactive",
      "#toolbar-1",
      null,
    ],
    ["Focusable toolbar is considered interactive", "#toolbar-2", null],
    [
      "Menu popup that is not focusable is not considered interactive",
      "#menu-1",
      null,
    ],
    ["Focusable menu popup is considered interactive", "#menu-2", null],
    [
      "Menubar that is not focusable is not considered interactive",
      "#menubar-1",
      null,
    ],
    ["Focusable menubar is considered interactive", "#menubar-2", null],
  ];

  for (const [description, selector, expected] of tests) {
    info(description);
    const node = await walker.querySelector(walker.rootNode, selector);
    const front = await a11yWalker.getAccessibleFor(node);
    const audit = await front.audit({ types: [KEYBOARD] });
    Assert.deepEqual(
      audit[KEYBOARD],
      expected,
      `Audit result for ${selector} is correct.`
    );
  }

  info("Text leaf inside a link (jump action is propagated to the text link)");
  let node = await walker.querySelector(walker.rootNode, "#link-5");
  let parent = await a11yWalker.getAccessibleFor(node);
  let front = (await parent.children())[0];
  let audit = await front.audit({ types: [KEYBOARD] });
  Assert.deepEqual(
    audit[KEYBOARD],
    null,
    "Text leafs are excluded from semantics rule."
  );

  info("Combobox list that is invisible");
  node = await walker.querySelector(walker.rootNode, "#combobox-1");
  parent = await a11yWalker.getAccessibleFor(node);
  front = (await parent.children())[0];
  audit = await front.audit({ types: [KEYBOARD] });
  Assert.deepEqual(
    audit[KEYBOARD],
    null,
    "Combobox lists (invisible) are excluded from semantics rule."
  );

  await waitForA11yShutdown(parentAccessibility);
  await target.destroy();
  gBrowser.removeCurrentTab();
});