forked from GoogleChrome/lighthouse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
a11y.js
762 lines (758 loc) · 28.5 KB
/
a11y.js
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
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
/**
* @license Copyright 2017 The Lighthouse Authors. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
/**
* Config for running PWA smokehouse audits for axe.
* @type {LH.Config.Json}
*/
const config = {
extends: 'lighthouse:default',
settings: {
onlyCategories: [
'accessibility',
],
},
};
/**
* @type {Smokehouse.ExpectedRunnerResult}
* Expected Lighthouse audit values for byte efficiency tests
*/
const expectations = {
lhr: {
requestedUrl: 'http://localhost:10200/a11y/a11y_tester.html',
finalUrl: 'http://localhost:10200/a11y/a11y_tester.html',
audits: {
'aria-allowed-attr': {
score: 0,
details: {
items: [
{
node: {
'type': 'node',
'selector': 'body > section > div#aria-allowed-attr',
'snippet': '<div id="aria-allowed-attr" role="alert" aria-checked="true">',
'explanation': 'Fix any of the following:\n ARIA attribute is not allowed: aria-checked="true"',
'nodeLabel': 'body > section > div#aria-allowed-attr',
},
},
],
},
},
'aria-hidden-body': {
score: 1,
details: {
'type': 'table',
'headings': [],
'items': [],
},
},
'aria-hidden-focus': {
score: 0,
details: {
items: [
{
node: {
'type': 'node',
'boundingRect': {
'width': '>0',
'height': '>0',
},
'selector': 'body > section > div#aria-hidden-focus',
'snippet': '<div id="aria-hidden-focus" aria-hidden="true">',
'explanation': 'Fix all of the following:\n Focusable content should be disabled or be removed from the DOM',
'nodeLabel': 'Focusable Button',
},
},
],
},
},
'aria-input-field-name': {
score: 0,
details: {
items: [
{
node: {
'type': 'node',
'boundingRect': {
'width': '>0',
'height': '>0',
},
'selector': 'body > section > div#aria-input-field-name',
'snippet': '<div id="aria-input-field-name" role="textbox">',
'explanation': 'Fix any of the following:\n aria-label attribute does not exist or is empty\n aria-labelledby attribute does not exist, references elements that do not exist or references elements that are empty\n Element has no title attribute',
'nodeLabel': 'text-in-a-box',
},
},
],
},
},
'aria-meter-name': {
score: 0,
details: {
items: [
{
node: {
'type': 'node',
'boundingRect': {
'width': '>0',
'height': '>0',
},
'selector': 'body > section > div#aria-meter-name',
'snippet': '<div id="aria-meter-name" role="meter">',
'explanation': 'Fix any of the following:\n aria-label attribute does not exist or is empty\n aria-labelledby attribute does not exist, references elements that do not exist or references elements that are empty\n Element has no title attribute',
'nodeLabel': 'text-in-a-box',
},
},
],
},
},
'aria-progressbar-name': {
score: 0,
details: {
items: [
{
node: {
'type': 'node',
'boundingRect': {
'width': '>0',
'height': '>0',
},
'selector': 'body > section > div#aria-progressbar-name',
'snippet': '<div id="aria-progressbar-name" role="progressbar">',
'explanation': 'Fix any of the following:\n aria-label attribute does not exist or is empty\n aria-labelledby attribute does not exist, references elements that do not exist or references elements that are empty\n Element has no title attribute',
'nodeLabel': 'text-in-a-box',
},
},
],
},
},
'aria-treeitem-name': {
score: 0,
details: {
items: [
{
node: {
'type': 'node',
'boundingRect': {
'width': '>0',
'height': 0,
},
'selector': 'body > section > div > div#aria-treeitem-name',
'snippet': '<div id="aria-treeitem-name" role="treeitem">',
'explanation': 'Fix any of the following:\n Element does not have text that is visible to screen readers\n aria-label attribute does not exist or is empty\n aria-labelledby attribute does not exist, references elements that do not exist or references elements that are empty\n Element has no title attribute',
'nodeLabel': 'body > section > div > div#aria-treeitem-name',
},
},
],
},
},
'aria-command-name': {
score: 0,
details: {
items: [
{
node: {
'type': 'node',
'boundingRect': {
'width': '>0',
'height': 0,
},
'selector': 'body > section > div#aria-command-name',
'snippet': '<div id="aria-command-name" role="button">',
'explanation': 'Fix any of the following:\n Element does not have text that is visible to screen readers\n aria-label attribute does not exist or is empty\n aria-labelledby attribute does not exist, references elements that do not exist or references elements that are empty\n Element has no title attribute',
'nodeLabel': 'body > section > div#aria-command-name',
},
},
],
},
},
'aria-tooltip-name': {
score: 0,
details: {
items: [
{
node: {
'type': 'node',
'boundingRect': {
'width': '>0',
'height': 0,
},
'selector': 'body > section > div#aria-tooltip-name',
'snippet': '<div id="aria-tooltip-name" role="tooltip">',
'explanation': 'Fix any of the following:\n Element does not have text that is visible to screen readers\n aria-label attribute does not exist or is empty\n aria-labelledby attribute does not exist, references elements that do not exist or references elements that are empty\n Element has no title attribute',
'nodeLabel': 'body > section > div#aria-tooltip-name',
},
},
],
},
},
'aria-required-children': {
score: 0,
details: {
items: [
{
node: {
'type': 'node',
'selector': 'body > section > div#aria-required-children',
'snippet': '<div id="aria-required-children" role="radiogroup">',
'explanation': 'Fix any of the following:\n Required ARIA child role not present: radio',
'nodeLabel': 'body > section > div#aria-required-children',
},
},
],
},
},
'aria-required-parent': {
score: 0,
details: {
items: [
{
node: {
'type': 'node',
'selector': 'body > section > div > div#aria-required-parent',
'snippet': '<div id="aria-required-parent" role="option">',
'explanation': 'Fix any of the following:\n Required ARIA parents role not present: group, listbox',
'nodeLabel': 'body > section > div > div#aria-required-parent',
},
},
],
},
},
'aria-roles': {
score: 0,
details: {
items: [
{
node: {
'type': 'node',
'selector': 'body > section > div',
'snippet': '<div role="foo">',
'explanation': 'Fix all of the following:\n Role must be one of the valid ARIA roles: foo',
'nodeLabel': 'body > section > div',
},
},
],
},
},
'aria-toggle-field-name': {
score: 0,
details: {
items: [
{
node: {
'type': 'node',
'selector': 'body > section > div#aria-required-attr',
'path': '2,HTML,1,BODY,19,SECTION,0,DIV',
'snippet': '<div id="aria-required-attr" role="checkbox">',
'explanation': 'Fix any of the following:\n Element does not have text that is visible to screen readers\n aria-label attribute does not exist or is empty\n aria-labelledby attribute does not exist, references elements that do not exist or references elements that are empty\n Element has no title attribute',
'nodeLabel': 'body > section > div#aria-required-attr',
},
},
{
node: {
'type': 'node',
'selector': 'body > section > div > div#aria-required-parent',
'path': '2,HTML,1,BODY,23,SECTION,0,DIV,0,DIV',
'snippet': '<div id="aria-required-parent" role="option">',
'nodeLabel': 'body > section > div > div#aria-required-parent',
},
},
{
node: {
'type': 'node',
'selector': 'body > section > div#aria-valid-attr',
'path': '2,HTML,1,BODY,27,SECTION,0,DIV',
'snippet': '<div id="aria-valid-attr" role="checkbox" aria-chked="true">',
'nodeLabel': 'body > section > div#aria-valid-attr',
},
},
{
node: {
'type': 'node',
'selector': 'body > section > div#aria-valid-attr-value',
'path': '2,HTML,1,BODY,29,SECTION,0,DIV',
'snippet': '<div id="aria-valid-attr-value" role="checkbox" aria-checked="0">',
'nodeLabel': 'body > section > div#aria-valid-attr-value',
},
},
],
},
},
'aria-valid-attr-value': {
score: 0,
details: {
items: [
{
node: {
'type': 'node',
'selector': 'body > section > div#aria-valid-attr-value',
'snippet': '<div id="aria-valid-attr-value" role="checkbox" aria-checked="0">',
'explanation': 'Fix all of the following:\n Invalid ARIA attribute value: aria-checked="0"',
'nodeLabel': 'body > section > div#aria-valid-attr-value',
},
},
],
},
},
'aria-valid-attr': {
score: 0,
details: {
items: [
{
node: {
'type': 'node',
'selector': 'body > section > div#aria-valid-attr',
'snippet': '<div id="aria-valid-attr" role="checkbox" aria-chked="true">',
'explanation': 'Fix any of the following:\n Invalid ARIA attribute name: aria-chked',
'nodeLabel': 'body > section > div#aria-valid-attr',
},
},
],
},
},
'button-name': {
score: 0,
details: {
items: [
{
node: {
'type': 'node',
'selector': 'body > section > button#button-name',
'snippet': '<button id="button-name">',
'explanation': 'Fix any of the following:\n Element does not have inner text that is visible to screen readers\n aria-label attribute does not exist or is empty\n aria-labelledby attribute does not exist, references elements that do not exist or references elements that are empty\n Element has no title attribute\n Element\'s default semantics were not overridden with role="none" or role="presentation"',
'nodeLabel': 'body > section > button#button-name',
},
},
],
},
},
'bypass': {
score: 1,
details: {
type: 'table',
headings: [],
items: [],
},
},
'color-contrast': {
score: 0,
details: {
items: [
{
node: {
'type': 'node',
'selector': 'body > section > div#color-contrast',
'snippet': '<div id="color-contrast" style="background-color: red; color: pink;">',
// Default font size is different depending on the platform (e.g. 28.5 on travis, 30.0 on Mac), and the px-converted units may have variable precision, so use \d+.\d+.
'explanation': /^Fix any of the following:\n {2}Element has insufficient color contrast of 2\.59 \(foreground color: #ffc0cb, background color: #ff0000, font size: \d+.\d+pt \(\d+.\d+px\), font weight: normal\). Expected contrast ratio of 3:1$/,
'nodeLabel': 'Hello',
},
},
],
},
},
'definition-list': {
score: 0,
details: {
items: [
{
node: {
'type': 'node',
'selector': 'body > section > dl#definition-list',
'snippet': '<dl id="definition-list">',
'explanation': 'Fix all of the following:\n List element has direct children that are not allowed inside <dt> or <dd> elements',
'nodeLabel': 'body > section > dl#definition-list',
},
},
],
},
},
'dlitem': {
score: 0,
details: {
items: [
{
node: {
'type': 'node',
'selector': 'body > section > div#dlitem > dd',
'snippet': '<dd>',
'explanation': 'Fix any of the following:\n Description list item does not have a <dl> parent element',
'nodeLabel': 'body > section > div#dlitem > dd',
},
},
],
},
},
'document-title': {
score: 0,
details: {
items: [
{
node: {
'type': 'node',
'selector': 'html',
'snippet': '<html>',
'explanation': 'Fix any of the following:\n Document does not have a non-empty <title> element',
'nodeLabel': 'html',
},
},
],
},
},
'duplicate-id-active': {
score: 0,
details: {
items: [
{
node: {
'type': 'node',
'selector': 'body > section > textarea#duplicate-id-active',
'path': '2,HTML,1,BODY,39,SECTION,0,TEXTAREA',
'snippet': '<textarea id="duplicate-id-active" aria-label="text1">',
'explanation': 'Fix any of the following:\n Document has active elements with the same id attribute: duplicate-id-active',
'nodeLabel': 'text1',
},
subItems: {
type: 'subitems',
items: [
{
relatedNode: {
'type': 'node',
'path': '2,HTML,1,BODY,39,SECTION,1,TEXTAREA',
'selector': 'body > section > textarea#duplicate-id-active',
'snippet': '<textarea id="duplicate-id-active" aria-label="text2">',
'nodeLabel': 'text2',
},
},
],
},
},
],
},
},
'duplicate-id-aria': {
score: 0,
details: {
items: [
{
node: {
'type': 'node',
'selector': 'body > section > div#duplicate-id-aria',
'path': '2,HTML,1,BODY,41,SECTION,0,DIV',
'snippet': '<div id="duplicate-id-aria" class="duplicate-id-aria">',
'explanation': 'Fix any of the following:\n Document has multiple elements referenced with ARIA with the same id attribute: duplicate-id-aria',
'nodeLabel': 'body > section > div#duplicate-id-aria',
},
subItems: {
type: 'subitems',
items: [
{
relatedNode: {
'type': 'node',
'path': '2,HTML,1,BODY,41,SECTION,0,DIV,0,DIV',
'selector': 'body > section > div#duplicate-id-aria > div#duplicate-id-aria',
'snippet': '<div id="duplicate-id-aria">',
'nodeLabel': 'body > section > div#duplicate-id-aria > div#duplicate-id-aria',
},
},
],
},
},
],
},
},
'form-field-multiple-labels': {
score: null,
scoreDisplayMode: 'informative',
details: {
items: [
{
node: {
'type': 'node',
'selector': 'body > section > input#form-field-multiple-labels',
'path': '2,HTML,1,BODY,43,SECTION,2,INPUT',
'snippet': '<input type="checkbox" id="form-field-multiple-labels">',
'explanation': 'Fix all of the following:\n Multiple label elements is not widely supported in assistive technologies. Ensure the first label contains all necessary information.',
'nodeLabel': 'body > section > input#form-field-multiple-labels',
},
subItems: {
type: 'subitems',
items: [
{
relatedNode: {
'type': 'node',
'path': '2,HTML,1,BODY,43,SECTION,0,LABEL',
'selector': 'body > section > label#label1',
'snippet': '<label for="form-field-multiple-labels" id="label1">',
'nodeLabel': 'label1',
},
},
{
relatedNode: {
'type': 'node',
'path': '2,HTML,1,BODY,43,SECTION,1,LABEL',
'selector': 'body > section > label',
'snippet': '<label for="form-field-multiple-labels">',
'nodeLabel': 'label2',
},
},
],
},
},
],
},
},
'frame-title': {
score: 0,
details: {
items: [
{
node: {
'type': 'node',
'selector': 'body > section > iframe#frame-title',
'snippet': '<iframe id="frame-title">',
'explanation': 'Fix any of the following:\n Element has no title attribute\n aria-label attribute does not exist or is empty\n aria-labelledby attribute does not exist, references elements that do not exist or references elements that are empty\n Element\'s default semantics were not overridden with role="none" or role="presentation"',
'nodeLabel': 'body > section > iframe#frame-title',
},
},
],
},
},
'heading-order': {
score: 0,
details: {
items: [
{
node: {
'type': 'node',
'selector': 'body > section > h3',
'path': '2,HTML,1,BODY,47,SECTION,1,H3',
'snippet': '<h3>',
'explanation': 'Fix any of the following:\n Heading order invalid',
'nodeLabel': 'sub-sub-header',
},
},
],
},
},
'html-has-lang': {
score: 0,
details: {
items: [
{
node: {
'type': 'node',
'selector': 'html',
'snippet': '<html>',
'explanation': 'Fix any of the following:\n The <html> element does not have a lang attribute',
'nodeLabel': 'html',
},
},
],
},
},
'image-alt': {
score: 0,
details: {
items: [
{
node: {
'type': 'node',
'selector': 'body > section > img#image-alt',
'snippet': '<img id="image-alt" src="./bogus.jpg">',
'explanation': 'Fix any of the following:\n Element does not have an alt attribute\n aria-label attribute does not exist or is empty\n aria-labelledby attribute does not exist, references elements that do not exist or references elements that are empty\n Element has no title attribute\n Element\'s default semantics were not overridden with role="none" or role="presentation"',
'nodeLabel': 'body > section > img#image-alt',
},
},
],
},
},
'input-image-alt': {
score: 0,
details: {
items: [
{
node: {
'type': 'node',
'selector': 'body > section > input#input-image-alt',
'snippet': '<input type="image" id="input-image-alt">',
'explanation': 'Fix any of the following:\n Element has no alt attribute\n aria-label attribute does not exist or is empty\n aria-labelledby attribute does not exist, references elements that do not exist or references elements that are empty\n Element has no title attribute',
'nodeLabel': 'body > section > input#input-image-alt',
},
},
],
},
},
// TODO(paulirish): restore when we stop using --enable-features=AutofillShowTypePredictions
// See https://github.com/GoogleChrome/lighthouse/pull/11342
// 'label': {
// score: 0,
// details: {
// items: [
// {
// node: {
// 'type': 'node',
// 'selector': '#label',
// 'snippet': '<input id="label" type="text">',
// 'explanation': 'Fix any of the following:\n aria-label attribute does not exist or is empty\n aria-labelledby attribute does not exist, references elements that do not exist or references elements that are empty\n Form element does not have an implicit (wrapped) <label>\n Form element does not have an explicit <label>\n Element has no title attribute or the title attribute is empty',
// 'nodeLabel': 'input',
// },
// },
// ],
// },
// },
'link-name': {
score: 0,
details: {
items: [
{
node: {
'type': 'node',
'selector': 'body > section > a#link-name',
'snippet': '<a id="link-name" href="google.com">',
'explanation': 'Fix all of the following:\n Element is in tab order and does not have accessible text\n\nFix any of the following:\n Element does not have text that is visible to screen readers\n aria-label attribute does not exist or is empty\n aria-labelledby attribute does not exist, references elements that do not exist or references elements that are empty\n Element has no title attribute',
'nodeLabel': 'body > section > a#link-name',
},
},
],
},
},
'list': {
score: 0,
details: {
items: [
{
node: {
'type': 'node',
'selector': 'body > section > ul#list',
'snippet': '<ul id="list">',
'explanation': 'Fix all of the following:\n List element has direct children that are not allowed inside <li> elements',
'nodeLabel': 'body > section > ul#list',
},
},
],
},
},
'listitem': {
score: 0,
details: {
items: [
{
node: {
'type': 'node',
'selector': 'body > section > li#listitem',
'snippet': '<li id="listitem">',
'explanation': 'Fix any of the following:\n List item does not have a <ul>, <ol> parent element',
'nodeLabel': 'body > section > li#listitem',
},
},
],
},
},
'meta-viewport': {
score: 0,
details: {
items: [
{
node: {
'type': 'node',
'selector': 'head > meta',
'snippet': '<meta name="viewport" content="user-scalable=no, maximum-scale=1.0">',
'explanation': 'Fix any of the following:\n user-scalable=no on <meta> tag disables zooming on mobile devices',
'nodeLabel': 'head > meta',
},
},
],
},
},
'object-alt': {
score: 0,
details: {
items: [
{
node: {
'type': 'node',
'selector': 'body > section > object#object-alt',
'snippet': '<object id="object-alt">',
'explanation': 'Fix any of the following:\n aria-label attribute does not exist or is empty\n aria-labelledby attribute does not exist, references elements that do not exist or references elements that are empty\n Element has no title attribute\n Element\'s default semantics were not overridden with role="none" or role="presentation"',
'nodeLabel': 'body > section > object#object-alt',
},
},
],
},
},
'tabindex': {
score: 0,
details: {
items: [
{
node: {
'type': 'node',
'selector': 'body > section > div#tabindex',
'snippet': '<div id="tabindex" tabindex="10">',
'explanation': 'Fix any of the following:\n Element has a tabindex greater than 0',
'nodeLabel': 'body > section > div#tabindex',
},
},
],
},
},
'td-headers-attr': {
score: 0,
details: {
items: [
{
node: {
'type': 'node',
'selector': 'body > section > table#td-headers-attr',
'snippet': '<table id="td-headers-attr">',
'explanation': 'Fix all of the following:\n The headers attribute is not exclusively used to refer to other cells in the table',
'nodeLabel': 'FOO\nfoo',
},
},
],
},
},
'valid-lang': {
score: 0,
details: {
items: [
{
node: {
'type': 'node',
'selector': 'body > section > p#valid-lang',
'snippet': '<p id="valid-lang" lang="foo">',
'explanation': 'Fix all of the following:\n Value of lang attribute not included in the list of valid languages',
'nodeLabel': 'foo',
},
},
],
},
},
'accesskeys': {
score: 0,
details: {
items: [
{
node: {
'type': 'node',
'selector': 'body > section > button#accesskeys1',
'snippet': '<button id="accesskeys1" accesskey="s">',
'explanation': 'Fix all of the following:\n Document has multiple elements with the same accesskey',
'nodeLabel': 'Foo',
},
},
],
},
},
},
},
};
/** @type {Smokehouse.TestDfn} */
export default {
id: 'a11y',
expectations,
config,
};