1
- /* global xit */
2
1
describe ( 'color-contrast-matches' , function ( ) {
3
2
'use strict' ;
4
3
@@ -72,86 +71,99 @@ describe('color-contrast-matches', function () {
72
71
it ( 'should match <input type="text">' , function ( ) {
73
72
fixture . innerHTML = '<input type="text">' ;
74
73
var target = fixture . querySelector ( 'input' ) ;
75
- assert . isTrue ( rule . matches ( target ) ) ;
74
+ var tree = axe . _tree = axe . utils . getFlattenedTree ( fixture ) ;
75
+ assert . isTrue ( rule . matches ( target , axe . utils . getNodeFromTree ( tree [ 0 ] , target ) ) ) ;
76
76
} ) ;
77
77
78
78
it ( 'should not match <input type="hidden">' , function ( ) {
79
79
fixture . innerHTML = '<input type="hidden">' ;
80
80
var target = fixture . querySelector ( 'input' ) ;
81
- assert . isFalse ( rule . matches ( target ) ) ;
81
+ var tree = axe . _tree = axe . utils . getFlattenedTree ( fixture ) ;
82
+ assert . isFalse ( rule . matches ( target , axe . utils . getNodeFromTree ( tree [ 0 ] , target ) ) ) ;
82
83
} ) ;
83
84
84
85
it ( 'should not match <input type="checkbox">' , function ( ) {
85
86
fixture . innerHTML = '<input type="checkbox">' ;
86
87
var target = fixture . querySelector ( 'input' ) ;
87
- assert . isFalse ( rule . matches ( target ) ) ;
88
+ var tree = axe . _tree = axe . utils . getFlattenedTree ( fixture ) ;
89
+ assert . isFalse ( rule . matches ( target , axe . utils . getNodeFromTree ( tree [ 0 ] , target ) ) ) ;
88
90
} ) ;
89
91
90
92
it ( 'should not match <input type="radio">' , function ( ) {
91
93
fixture . innerHTML = '<input type="radio">' ;
92
94
var target = fixture . querySelector ( 'input' ) ;
93
- assert . isFalse ( rule . matches ( target ) ) ;
95
+ var tree = axe . _tree = axe . utils . getFlattenedTree ( fixture ) ;
96
+ assert . isFalse ( rule . matches ( target , axe . utils . getNodeFromTree ( tree [ 0 ] , target ) ) ) ;
94
97
} ) ;
95
98
96
99
it ( 'should not match <input type="color">' , function ( ) {
97
100
fixture . innerHTML = '<input type="color">' ;
98
101
var target = fixture . querySelector ( 'input' ) ;
102
+ var tree = axe . _tree = axe . utils . getFlattenedTree ( fixture ) ;
99
103
// Some browsers will fallback to type=text for unknown input types (looking at you IE)
100
104
if ( target . type === 'color' ) {
101
- assert . isFalse ( rule . matches ( target ) ) ;
105
+ assert . isFalse ( rule . matches ( target , axe . utils . getNodeFromTree ( tree [ 0 ] , target ) ) ) ;
102
106
}
103
107
} ) ;
104
108
105
109
it ( 'should not match <input type="range">' , function ( ) {
106
110
fixture . innerHTML = '<input type="range">' ;
107
111
var target = fixture . querySelector ( 'input' ) ;
112
+ var tree = axe . _tree = axe . utils . getFlattenedTree ( fixture ) ;
108
113
// Some browsers will fallback to type=text for unknown input types (looking at you IE)
109
114
if ( target . type === 'range' ) {
110
- assert . isFalse ( rule . matches ( target ) ) ;
115
+ assert . isFalse ( rule . matches ( target , axe . utils . getNodeFromTree ( tree [ 0 ] , target ) ) ) ;
111
116
}
112
117
} ) ;
113
118
114
119
it ( 'should match <select> with options' , function ( ) {
115
120
fixture . innerHTML = '<select><option>Hello</option></select>' ;
116
121
var target = fixture . querySelector ( 'select' ) ;
117
- assert . isTrue ( rule . matches ( target ) ) ;
122
+ var tree = axe . _tree = axe . utils . getFlattenedTree ( fixture ) ;
123
+ assert . isTrue ( rule . matches ( target , axe . utils . getNodeFromTree ( tree [ 0 ] , target ) ) ) ;
118
124
} ) ;
119
125
120
126
it ( 'should not match <select> with no options' , function ( ) {
121
127
fixture . innerHTML = '<select></select>' ;
122
128
var target = fixture . querySelector ( 'select' ) ;
123
- assert . isFalse ( rule . matches ( target ) ) ;
129
+ var tree = axe . _tree = axe . utils . getFlattenedTree ( fixture ) ;
130
+ assert . isFalse ( rule . matches ( target , axe . utils . getNodeFromTree ( tree [ 0 ] , target ) ) ) ;
124
131
} ) ;
125
132
126
133
it ( 'should match <textarea>' , function ( ) {
127
134
fixture . innerHTML = '<textarea></textarea>' ;
128
135
var target = fixture . querySelector ( 'textarea' ) ;
129
- assert . isTrue ( rule . matches ( target ) ) ;
136
+ var tree = axe . _tree = axe . utils . getFlattenedTree ( fixture ) ;
137
+ assert . isTrue ( rule . matches ( target , axe . utils . getNodeFromTree ( tree [ 0 ] , target ) ) ) ;
130
138
} ) ;
131
139
132
140
it ( 'should not match <option>' , function ( ) {
133
141
fixture . innerHTML = '<select><option>hi</option></select>' ;
134
142
var target = fixture . querySelector ( 'option' ) ;
135
- assert . isFalse ( rule . matches ( target ) ) ;
143
+ var tree = axe . _tree = axe . utils . getFlattenedTree ( fixture ) ;
144
+ assert . isFalse ( rule . matches ( target , axe . utils . getNodeFromTree ( tree [ 0 ] , target ) ) ) ;
136
145
} ) ;
137
146
138
147
it ( 'should not match inputs that are disabled' , function ( ) {
139
148
fixture . innerHTML = '<input type="text" disabled>' ;
140
149
var target = fixture . querySelector ( 'input' ) ;
141
- assert . isFalse ( rule . matches ( target ) ) ;
150
+ var tree = axe . _tree = axe . utils . getFlattenedTree ( fixture ) ;
151
+ assert . isFalse ( rule . matches ( target , axe . utils . getNodeFromTree ( tree [ 0 ] , target ) ) ) ;
142
152
143
153
} ) ;
144
154
145
155
it ( 'should not match <textarea disabled>' , function ( ) {
146
156
fixture . innerHTML = '<textarea disabled></textarea>' ;
147
157
var target = fixture . querySelector ( 'textarea' ) ;
148
- assert . isFalse ( rule . matches ( target ) ) ;
158
+ var tree = axe . _tree = axe . utils . getFlattenedTree ( fixture ) ;
159
+ assert . isFalse ( rule . matches ( target , axe . utils . getNodeFromTree ( tree [ 0 ] , target ) ) ) ;
149
160
} ) ;
150
161
151
162
it ( 'should not match <select> with options' , function ( ) {
152
163
fixture . innerHTML = '<select disabled><option>Hello</option></select>' ;
153
164
var target = fixture . querySelector ( 'select' ) ;
154
- assert . isFalse ( rule . matches ( target ) ) ;
165
+ var tree = axe . _tree = axe . utils . getFlattenedTree ( fixture ) ;
166
+ assert . isFalse ( rule . matches ( target , axe . utils . getNodeFromTree ( tree [ 0 ] , target ) ) ) ;
155
167
} ) ;
156
168
157
169
it ( 'should match <button>' , function ( ) {
@@ -164,97 +176,174 @@ describe('color-contrast-matches', function () {
164
176
it ( 'should not match <button disabled>' , function ( ) {
165
177
fixture . innerHTML = '<button disabled>hi</button>' ;
166
178
var target = fixture . querySelector ( 'button' ) ;
167
- assert . isFalse ( rule . matches ( target ) ) ;
179
+ var tree = axe . _tree = axe . utils . getFlattenedTree ( fixture ) ;
180
+ assert . isFalse ( rule . matches ( target , axe . utils . getNodeFromTree ( tree [ 0 ] , target ) ) ) ;
168
181
} ) ;
169
182
170
183
it ( 'should not match <button disabled><span></span></button>' , function ( ) {
171
184
fixture . innerHTML = '<button disabled><span>Hi</span></button>' ;
172
185
var target = fixture . querySelector ( 'button' ) ;
173
- assert . isFalse ( rule . matches ( target . querySelector ( 'span' ) ) ) ;
186
+ var tree = axe . _tree = axe . utils . getFlattenedTree ( fixture ) ;
187
+ assert . isFalse ( rule . matches ( target . querySelector ( 'span' ) , axe . utils . getNodeFromTree ( tree [ 0 ] , target . querySelector ( 'span' ) ) ) ) ;
174
188
} ) ;
175
189
176
190
it ( 'should not match <button disabled><span><i></i></span></button>' , function ( ) {
177
191
fixture . innerHTML = '<button disabled><span><i>Hi</i></span></button>' ;
178
192
var target = fixture . querySelector ( 'button' ) ;
179
- assert . isFalse ( rule . matches ( target . querySelector ( 'i' ) ) ) ;
193
+ var tree = axe . _tree = axe . utils . getFlattenedTree ( fixture ) ;
194
+ assert . isFalse ( rule . matches ( target . querySelector ( 'i' ) , axe . utils . getNodeFromTree ( tree [ 0 ] , target . querySelector ( 'i' ) ) ) ) ;
180
195
} ) ;
181
196
182
197
it ( 'should not match <input type=image>' , function ( ) {
183
198
fixture . innerHTML = '<input type="image">' ;
184
199
var target = fixture . querySelector ( 'input' ) ;
185
- assert . isFalse ( rule . matches ( target ) ) ;
200
+ var tree = axe . _tree = axe . utils . getFlattenedTree ( fixture ) ;
201
+ assert . isFalse ( rule . matches ( target , axe . utils . getNodeFromTree ( tree [ 0 ] , target ) ) ) ;
186
202
} ) ;
187
203
188
204
it ( 'should not match a disabled input\'s label - explicit label' , function ( ) {
189
205
fixture . innerHTML = '<label for="t1">Test</label><input type="text" id="t1" disabled>' ;
190
206
var target = fixture . querySelector ( 'label' ) ;
191
- assert . isFalse ( rule . matches ( target ) ) ;
207
+ var tree = axe . _tree = axe . utils . getFlattenedTree ( fixture ) ;
208
+ assert . isFalse ( rule . matches ( target , axe . utils . getNodeFromTree ( tree [ 0 ] , target ) ) ) ;
192
209
} ) ;
193
210
194
211
it ( 'should not match a disabled input\'s label - implicit label (input)' , function ( ) {
195
212
fixture . innerHTML = '<label>Test<input type="text" disabled></label>' ;
196
213
var target = fixture . querySelector ( 'label' ) ;
197
- assert . isFalse ( rule . matches ( target ) ) ;
214
+ var tree = axe . _tree = axe . utils . getFlattenedTree ( fixture ) ;
215
+ assert . isFalse ( rule . matches ( target , axe . utils . getNodeFromTree ( tree [ 0 ] , target ) ) ) ;
198
216
} ) ;
199
217
200
218
it ( 'should not match a disabled input\'s label - implicit label (textarea)' , function ( ) {
201
219
fixture . innerHTML = '<label>Test<textarea disabled>Hi</textarea></label>' ;
202
220
var target = fixture . querySelector ( 'label' ) ;
203
- assert . isFalse ( rule . matches ( target ) ) ;
221
+ var tree = axe . _tree = axe . utils . getFlattenedTree ( fixture ) ;
222
+ assert . isFalse ( rule . matches ( target , axe . utils . getNodeFromTree ( tree [ 0 ] , target ) ) ) ;
204
223
} ) ;
205
224
206
225
it ( 'should not match a disabled input\'s label - implicit label (select)' , function ( ) {
207
226
fixture . innerHTML = '<label>Test<select disabled><option>Test</option></select></label>' ;
208
227
var target = fixture . querySelector ( 'label' ) ;
209
- assert . isFalse ( rule . matches ( target ) ) ;
228
+ var tree = axe . _tree = axe . utils . getFlattenedTree ( fixture ) ;
229
+ assert . isFalse ( rule . matches ( target , axe . utils . getNodeFromTree ( tree [ 0 ] , target ) ) ) ;
210
230
} ) ;
211
231
212
232
it ( 'should not match a disabled input\'s label - aria-labelledby' , function ( ) {
213
233
fixture . innerHTML = '<div id="t1">Test</div><input type="text" aria-labelledby="bob t1 fred" disabled>' ;
214
234
var target = fixture . querySelector ( 'div' ) ;
215
- assert . isFalse ( rule . matches ( target ) ) ;
235
+ var tree = axe . _tree = axe . utils . getFlattenedTree ( fixture ) ;
236
+ assert . isFalse ( rule . matches ( target , axe . utils . getNodeFromTree ( tree [ 0 ] , target ) ) ) ;
216
237
} ) ;
217
238
218
239
it ( 'should not match aria-disabled=true' , function ( ) {
219
240
fixture . innerHTML = '<div aria-disabled="true">hi</div>' ;
220
241
var target = fixture . querySelector ( 'div' ) ;
221
- assert . isFalse ( rule . matches ( target ) ) ;
242
+ var tree = axe . _tree = axe . utils . getFlattenedTree ( fixture ) ;
243
+ assert . isFalse ( rule . matches ( target , axe . utils . getNodeFromTree ( tree [ 0 ] , target ) ) ) ;
222
244
} ) ;
223
245
224
246
it ( 'should not match a descendant of aria-disabled=true' , function ( ) {
225
247
fixture . innerHTML = '<div aria-disabled="true"><span>hi</span></div>' ;
226
248
var target = fixture . querySelector ( 'span' ) ;
227
- assert . isFalse ( rule . matches ( target ) ) ;
249
+ var tree = axe . _tree = axe . utils . getFlattenedTree ( fixture ) ;
250
+ assert . isFalse ( rule . matches ( target , axe . utils . getNodeFromTree ( tree [ 0 ] , target ) ) ) ;
228
251
} ) ;
229
252
230
253
it ( 'should not match a descendant of a disabled fieldset' , function ( ) {
231
254
fixture . innerHTML = '<fieldset disabled><label>hi <input type="checkbox"></label></fieldset>' ;
232
255
var target = fixture . querySelector ( 'label' ) ;
233
- assert . isFalse ( rule . matches ( target ) ) ;
256
+ var tree = axe . _tree = axe . utils . getFlattenedTree ( fixture ) ;
257
+ assert . isFalse ( rule . matches ( target , axe . utils . getNodeFromTree ( tree [ 0 ] , target ) ) ) ;
234
258
} ) ;
235
259
236
260
it ( 'should not match a descendant of an explicit label for a disabled input' , function ( ) {
237
261
fixture . innerHTML = '<input id="input" type="checkbox" disabled><label for="input"><span>hi</span></label>' ;
238
262
var target = fixture . querySelector ( 'span' ) ;
239
- assert . isFalse ( rule . matches ( target ) ) ;
263
+ var tree = axe . _tree = axe . utils . getFlattenedTree ( fixture ) ;
264
+ assert . isFalse ( rule . matches ( target , axe . utils . getNodeFromTree ( tree [ 0 ] , target ) ) ) ;
240
265
} ) ;
241
266
242
267
it ( 'should not match a descendant of an implicit label for a disabled input' , function ( ) {
243
268
fixture . innerHTML = '<label for="input"><span>hi</span><input id="input" type="checkbox" disabled></label>' ;
244
269
var target = fixture . querySelector ( 'span' ) ;
245
- assert . isFalse ( rule . matches ( target ) ) ;
270
+ var tree = axe . _tree = axe . utils . getFlattenedTree ( fixture ) ;
271
+ assert . isFalse ( rule . matches ( target , axe . utils . getNodeFromTree ( tree [ 0 ] , target ) ) ) ;
246
272
} ) ;
247
273
248
- ( shadowSupport ? it : xit )
249
- ( 'should match a descendant of an element across a shadow boundary' , function ( ) {
250
- fixture . innerHTML = '<div id="parent" style="background-color: #000;">' +
274
+ if ( shadowSupport ) {
275
+ it ( 'should match a descendant of an element across a shadow boundary' , function ( ) {
276
+ fixture . innerHTML = '<div id="parent" style="background-color: #000;">' +
277
+ '</div>' ;
278
+
279
+ var shadowRoot = document . getElementById ( 'parent' ) . attachShadow ( { mode : 'open' } ) ;
280
+ shadowRoot . innerHTML = '<div id="shadowTarget" style="color: #333">Text</div>' ;
281
+
282
+ var shadowTarget = fixture . firstChild . shadowRoot . querySelector ( '#shadowTarget' ) ;
283
+ var tree = axe . _tree = axe . utils . getFlattenedTree ( fixture ) ;
284
+ assert . isTrue ( rule . matches ( shadowTarget , axe . utils . getNodeFromTree ( tree [ 0 ] , shadowTarget ) ) ) ;
285
+ } ) ;
286
+
287
+ it ( 'should look at the correct root node when looking up an explicit label and disabled input' , function ( ) {
288
+ fixture . innerHTML = '<div id="parent">' +
289
+ '<input id="input">' +
251
290
'</div>' ;
252
291
253
- var shadowRoot = document . getElementById ( 'parent' ) . attachShadow ( { mode : 'open' } ) ;
254
- shadowRoot . innerHTML = '<div id="shadowTarget" style="color: #333">Text</div>' ;
292
+ var shadowRoot = document . getElementById ( 'parent' ) . attachShadow ( { mode : 'open' } ) ;
293
+ shadowRoot . innerHTML = '<div id="shadowParent">' +
294
+ '<label for="input" id="shadowLabel">Label</label>' +
295
+ '<input id="input" disabled>' +
296
+ '</div>' ;
255
297
256
- var shadowTarget = fixture . firstChild . shadowRoot . querySelector ( '#shadowTarget' ) ;
257
- var tree = axe . _tree = axe . utils . getFlattenedTree ( fixture ) ;
258
- assert . isTrue ( rule . matches ( shadowTarget , axe . utils . getNodeFromTree ( tree [ 0 ] , shadowTarget ) ) ) ;
259
- } ) ;
298
+ var shadowLabel = fixture . firstChild . shadowRoot . querySelector ( '#shadowLabel' ) ;
299
+ var tree = axe . _tree = axe . utils . getFlattenedTree ( fixture ) ;
300
+ assert . isFalse ( rule . matches ( shadowLabel , axe . utils . getNodeFromTree ( tree [ 0 ] , shadowLabel ) ) ) ;
301
+ } ) ;
302
+
303
+ it ( 'should look at the correct root node when looking up implicit label and disabled input' , function ( ) {
304
+ fixture . innerHTML = '<div id="parent">' +
305
+ '<input id="input">' +
306
+ '</div>' ;
307
+
308
+ var shadowRoot = document . getElementById ( 'parent' ) . attachShadow ( { mode : 'open' } ) ;
309
+ shadowRoot . innerHTML = '<div id="shadowParent">' +
310
+ '<label for="input" id="shadowLabel">Label' +
311
+ '<input id="input" disabled></label>' +
312
+ '</div>' ;
313
+
314
+ var shadowLabel = fixture . firstChild . shadowRoot . querySelector ( '#shadowLabel' ) ;
315
+ var tree = axe . _tree = axe . utils . getFlattenedTree ( fixture ) ;
316
+ assert . isFalse ( rule . matches ( shadowLabel , axe . utils . getNodeFromTree ( tree [ 0 ] , shadowLabel ) ) ) ;
317
+ } ) ;
318
+
319
+ it ( 'should look at the correct root node for a disabled control\'s label associated w/ aria-labelledby' , function ( ) {
320
+ fixture . innerHTML = '<div id="parent">' +
321
+ '<input id="input">' +
322
+ '</div>' ;
323
+
324
+ var shadowRoot = document . getElementById ( 'parent' ) . attachShadow ( { mode : 'open' } ) ;
325
+ shadowRoot . innerHTML = '<div id="shadowParent">' +
326
+ '<label id="shadowLabel">Label</label>' +
327
+ '<input aria-labelledby="shadowLabel" disabled>' +
328
+ '</div>' ;
329
+
330
+ var shadowLabel = fixture . firstChild . shadowRoot . querySelector ( '#shadowLabel' ) ;
331
+ var tree = axe . _tree = axe . utils . getFlattenedTree ( fixture ) ;
332
+ assert . isFalse ( rule . matches ( shadowLabel , axe . utils . getNodeFromTree ( tree [ 0 ] , shadowLabel ) ) ) ;
333
+ } ) ;
334
+
335
+ it ( 'should look at the children of a virtual node for overlap' , function ( ) {
336
+ fixture . innerHTML = '<div id="parent">' +
337
+ '<div id="firstChild" style="background-color: #ccc; color: #fff;"></div>' +
338
+ '</div>' ;
339
+
340
+ var shadowRoot = document . getElementById ( 'firstChild' ) . attachShadow ( { mode : 'open' } ) ;
341
+ shadowRoot . innerHTML = 'Some text' +
342
+ '<p style="color: #fff;" id="shadowTarget">Other text</p>' ;
343
+
344
+ var firstChild = fixture . querySelector ( '#firstChild' ) ;
345
+ var tree = axe . _tree = axe . utils . getFlattenedTree ( fixture ) ;
346
+ assert . isTrue ( rule . matches ( firstChild , axe . utils . getNodeFromTree ( tree [ 0 ] , firstChild ) ) ) ;
347
+ } ) ;
348
+ }
260
349
} ) ;
0 commit comments