1
- describe ( 'aria-prohibited-attr' , function ( ) {
1
+ describe ( 'aria-prohibited-attr' , ( ) => {
2
2
'use strict' ;
3
3
4
- var checkContext = axe . testUtils . MockCheckContext ( ) ;
5
- var checkSetup = axe . testUtils . checkSetup ;
6
- var checkEvaluate = axe . testUtils . getCheckEvaluate ( 'aria-prohibited-attr' ) ;
4
+ const checkContext = axe . testUtils . MockCheckContext ( ) ;
5
+ const checkSetup = axe . testUtils . checkSetup ;
6
+ const checkEvaluate = axe . testUtils . getCheckEvaluate ( 'aria-prohibited-attr' ) ;
7
7
8
- afterEach ( function ( ) {
8
+ afterEach ( ( ) => {
9
9
checkContext . reset ( ) ;
10
10
} ) ;
11
11
12
- it ( 'should return true for prohibited attributes and no content' , function ( ) {
13
- var params = checkSetup (
12
+ it ( 'should return true for prohibited attributes and no content' , ( ) => {
13
+ const params = checkSetup (
14
14
'<div id="target" role="code" aria-hidden="false" aria-label="foo"></div>'
15
15
) ;
16
16
assert . isTrue ( checkEvaluate . apply ( checkContext , params ) ) ;
@@ -22,8 +22,8 @@ describe('aria-prohibited-attr', function () {
22
22
} ) ;
23
23
} ) ;
24
24
25
- it ( 'should return undefined for prohibited attributes and content' , function ( ) {
26
- var params = checkSetup (
25
+ it ( 'should return undefined for prohibited attributes and content' , ( ) => {
26
+ const params = checkSetup (
27
27
'<div id="target" role="code" aria-hidden="false" aria-label="foo">Contents</div>'
28
28
) ;
29
29
assert . isUndefined ( checkEvaluate . apply ( checkContext , params ) ) ;
@@ -35,8 +35,8 @@ describe('aria-prohibited-attr', function () {
35
35
} ) ;
36
36
} ) ;
37
37
38
- it ( 'should return true for multiple prohibited attributes' , function ( ) {
39
- var params = checkSetup (
38
+ it ( 'should return true for multiple prohibited attributes' , ( ) => {
39
+ const params = checkSetup (
40
40
'<div id="target" role="code" aria-hidden="false" aria-label="foo" aria-labelledby="foo"></div>'
41
41
) ;
42
42
assert . isTrue ( checkEvaluate . apply ( checkContext , params ) ) ;
@@ -49,8 +49,10 @@ describe('aria-prohibited-attr', function () {
49
49
} ) ;
50
50
} ) ;
51
51
52
- it ( 'should return undefined if element has no role and has text content (singular)' , function ( ) {
53
- var params = checkSetup ( '<div id="target" aria-label="foo">Contents</div>' ) ;
52
+ it ( 'should return undefined if element has no role and has text content (singular)' , ( ) => {
53
+ const params = checkSetup (
54
+ '<div id="target" aria-label="foo">Contents</div>'
55
+ ) ;
54
56
assert . isUndefined ( checkEvaluate . apply ( checkContext , params ) ) ;
55
57
assert . deepEqual ( checkContext . _data , {
56
58
nodeName : 'div' ,
@@ -60,8 +62,8 @@ describe('aria-prohibited-attr', function () {
60
62
} ) ;
61
63
} ) ;
62
64
63
- it ( 'should return undefined if element has no role and has text content (plural)' , function ( ) {
64
- var params = checkSetup (
65
+ it ( 'should return undefined if element has no role and has text content (plural)' , ( ) => {
66
+ const params = checkSetup (
65
67
'<div id="target" aria-label="foo" aria-labelledby="foo">Contents</div>'
66
68
) ;
67
69
assert . isUndefined ( checkEvaluate . apply ( checkContext , params ) ) ;
@@ -73,8 +75,8 @@ describe('aria-prohibited-attr', function () {
73
75
} ) ;
74
76
} ) ;
75
77
76
- it ( 'should return true if element has no role and no text content (singular)' , function ( ) {
77
- var params = checkSetup ( '<div id="target" aria-label="foo"></div>' ) ;
78
+ it ( 'should return true if element has no role and no text content (singular)' , ( ) => {
79
+ const params = checkSetup ( '<div id="target" aria-label="foo"></div>' ) ;
78
80
assert . isTrue ( checkEvaluate . apply ( checkContext , params ) ) ;
79
81
assert . deepEqual ( checkContext . _data , {
80
82
nodeName : 'div' ,
@@ -84,8 +86,8 @@ describe('aria-prohibited-attr', function () {
84
86
} ) ;
85
87
} ) ;
86
88
87
- it ( 'should return true if element has no role and no text content (plural)' , function ( ) {
88
- var params = checkSetup (
89
+ it ( 'should return true if element has no role and no text content (plural)' , ( ) => {
90
+ const params = checkSetup (
89
91
'<div id="target" aria-label="foo" aria-labelledby="foo"></div>'
90
92
) ;
91
93
assert . isTrue ( checkEvaluate . apply ( checkContext , params ) ) ;
@@ -97,45 +99,139 @@ describe('aria-prohibited-attr', function () {
97
99
} ) ;
98
100
} ) ;
99
101
100
- it ( 'should return false if all attributes are allowed' , function ( ) {
101
- var params = checkSetup (
102
+ it ( 'should return false if all attributes are allowed' , ( ) => {
103
+ const params = checkSetup (
102
104
'<div id="target" role="button" aria-label="foo" aria-labelledby="foo">Contents</div>'
103
105
) ;
104
106
assert . isFalse ( checkEvaluate . apply ( checkContext , params ) ) ;
105
107
} ) ;
106
108
107
- it ( 'should return false if no prohibited attributes are used' , function ( ) {
108
- var params = checkSetup (
109
+ it ( 'should return false if no prohibited attributes are used' , ( ) => {
110
+ const params = checkSetup (
109
111
'<div id="target" role="code" aria-selected="true">Contents</div>'
110
112
) ;
111
113
assert . isFalse ( checkEvaluate . apply ( checkContext , params ) ) ;
112
114
} ) ;
113
115
114
- it ( 'should return false if prohibited attributes have no value' , function ( ) {
115
- var params = checkSetup (
116
+ it ( 'should return false if prohibited attributes have no value' , ( ) => {
117
+ const params = checkSetup (
116
118
'<div id="target" role="code" aria-label=" " aria-labelledby=" ">Contents</div>'
117
119
) ;
118
120
assert . isFalse ( checkEvaluate . apply ( checkContext , params ) ) ;
119
121
} ) ;
120
122
121
- it ( 'should allow `elementsAllowedAriaLabel` nodes to have aria-label' , function ( ) {
122
- var params = checkSetup (
123
+ it ( 'should allow `elementsAllowedAriaLabel` nodes to have aria-label' , ( ) => {
124
+ const params = checkSetup (
123
125
'<div id="target" aria-label="hello world"></div>' ,
124
126
{ elementsAllowedAriaLabel : [ 'div' ] }
125
127
) ;
126
128
assert . isFalse ( checkEvaluate . apply ( checkContext , params ) ) ;
127
129
} ) ;
128
130
129
- it ( 'should not allow `elementsAllowedAriaLabel` nodes with a prohibited role' , function ( ) {
130
- var params = checkSetup (
131
+ it ( 'should not allow `elementsAllowedAriaLabel` nodes with a prohibited role' , ( ) => {
132
+ const params = checkSetup (
131
133
'<div id="target" role="code" aria-label="hello world"></div>' ,
132
134
{ elementsAllowedAriaLabel : [ 'div' ] }
133
135
) ;
134
136
assert . isTrue ( checkEvaluate . apply ( checkContext , params ) ) ;
135
137
} ) ;
136
138
137
- it ( 'should allow elements that have an implicit role in chromium' , function ( ) {
138
- var params = checkSetup ( '<svg id="target" aria-label="hello world"></svg>' ) ;
139
+ it ( 'should allow elements that have an implicit role in chromium' , ( ) => {
140
+ const params = checkSetup (
141
+ '<svg id="target" aria-label="hello world"></svg>'
142
+ ) ;
139
143
assert . isFalse ( checkEvaluate . apply ( checkContext , params ) ) ;
140
144
} ) ;
145
+
146
+ describe ( 'widget ancestor' , ( ) => {
147
+ it ( 'should allow aria-label' , ( ) => {
148
+ const params = checkSetup ( `
149
+ <button>
150
+ <span>
151
+ <span id="target" aria-label="hello world"></span>
152
+ </span>
153
+ </button>
154
+ ` ) ;
155
+ assert . isFalse ( checkEvaluate . apply ( checkContext , params ) ) ;
156
+ } ) ;
157
+
158
+ it ( 'should allow aria-labelledby' , ( ) => {
159
+ const params = checkSetup ( `
160
+ <div id="foo">hello world</div>
161
+ <button>
162
+ <span>
163
+ <span id="target" aria-labelledby="foo"></span>
164
+ </span>
165
+ </button>
166
+ ` ) ;
167
+ assert . isFalse ( checkEvaluate . apply ( checkContext , params ) ) ;
168
+ } ) ;
169
+
170
+ it ( 'should skip "role=none" roles in between ancestor' , ( ) => {
171
+ const params = checkSetup ( `
172
+ <button>
173
+ <h1 role="none">
174
+ <span id="target" aria-label="hello world"></span>
175
+ </h1>
176
+ </button>
177
+ ` ) ;
178
+ assert . isFalse ( checkEvaluate . apply ( checkContext , params ) ) ;
179
+ } ) ;
180
+
181
+ it ( 'should skip "role=presentation" roles in between ancestor' , ( ) => {
182
+ const params = checkSetup ( `
183
+ <a href="#">
184
+ <h1 role="presentation">
185
+ <span id="target" aria-label="hello world"></span>
186
+ </h1>
187
+ </a>
188
+ ` ) ;
189
+ assert . isFalse ( checkEvaluate . apply ( checkContext , params ) ) ;
190
+ } ) ;
191
+
192
+ it ( 'should not allow aria-label on descendant of non-widget' , ( ) => {
193
+ const params = checkSetup ( `
194
+ <div role="grid">
195
+ <span>
196
+ <span id="target" aria-label="foo"></span>
197
+ </span>
198
+ </div>
199
+ ` ) ;
200
+ assert . isTrue ( checkEvaluate . apply ( checkContext , params ) ) ;
201
+ } ) ;
202
+
203
+ it ( 'should not allow aria-labelledby on descendant of non-widget' , ( ) => {
204
+ const params = checkSetup ( `
205
+ <div id="foo">hello world</div>
206
+ <div role="grid">
207
+ <span>
208
+ <span id="target" aria-labelledby="foo"></span>
209
+ </span>
210
+ </div>
211
+ ` ) ;
212
+ assert . isTrue ( checkEvaluate . apply ( checkContext , params ) ) ;
213
+ } ) ;
214
+
215
+ it ( 'should use closet non-presentational ancestor' , ( ) => {
216
+ const params = checkSetup ( `
217
+ <button>
218
+ <span role="grid">
219
+ <span id="target" aria-label="foo"></span>
220
+ </span>
221
+ </button>
222
+ ` ) ;
223
+ assert . isTrue ( checkEvaluate . apply ( checkContext , params ) ) ;
224
+ } ) ;
225
+
226
+ it ( 'should use closet chromium role' , ( ) => {
227
+ const params = checkSetup ( `
228
+ <button>
229
+ <label>
230
+ <span id="target" aria-label="foo"></span>
231
+ </label>
232
+ </button>
233
+ ` ) ;
234
+ assert . isTrue ( checkEvaluate . apply ( checkContext , params ) ) ;
235
+ } ) ;
236
+ } ) ;
141
237
} ) ;
0 commit comments