1
1
import { Platform } from '@angular/cdk/platform' ;
2
+ import { PLATFORM_ID } from '@angular/core' ;
2
3
import { inject } from '@angular/core/testing' ;
3
4
import { InteractivityChecker , IsFocusableConfig } from './interactivity-checker' ;
4
5
@@ -7,11 +8,11 @@ describe('InteractivityChecker', () => {
7
8
let testContainerElement : HTMLElement ;
8
9
let checker : InteractivityChecker ;
9
10
10
- beforeEach ( inject ( [ Platform , InteractivityChecker ] , ( p : Platform , i : InteractivityChecker ) => {
11
+ beforeEach ( inject ( [ PLATFORM_ID ] , ( platformId : Object ) => {
11
12
testContainerElement = document . createElement ( 'div' ) ;
12
13
document . body . appendChild ( testContainerElement ) ;
13
- platform = p ;
14
- checker = i ;
14
+ platform = new Platform ( platformId ) ;
15
+ checker = new InteractivityChecker ( platform ) ;
15
16
} ) ) ;
16
17
17
18
afterEach ( ( ) => {
@@ -253,45 +254,48 @@ describe('InteractivityChecker', () => {
253
254
254
255
describe ( 'isTabbable' , ( ) => {
255
256
256
- it ( 'should respect the tabindex for video elements with controls' , ( ) => {
257
- // Do not run for Blink, Firefox and iOS because those treat video elements
258
- // with controls different and are covered in other tests.
259
- if ( platform . BLINK || platform . FIREFOX || platform . IOS ) {
260
- return ;
261
- }
262
-
263
- const video = createFromTemplate ( '<video controls>' , true ) ;
264
-
265
- expect ( checker . isTabbable ( video ) ) . toBe ( true ) ;
257
+ // Some tests should not run inside of iOS browsers, because those only allow specific
258
+ // elements to be tabbable and cause the tests to always fail.
259
+ describe ( 'for non-iOS browsers' , ( ) => {
260
+ let shouldSkip : boolean ;
266
261
267
- video . tabIndex = - 1 ;
262
+ beforeEach ( ( ) => {
263
+ shouldSkip = platform . IOS ;
264
+ } ) ;
268
265
269
- expect ( checker . isTabbable ( video ) ) . toBe ( false ) ;
270
- } ) ;
266
+ it ( 'should by default treat video elements with controls as tabbable' , ( ) => {
267
+ if ( shouldSkip ) {
268
+ return ;
269
+ }
271
270
272
- it ( 'should always mark video elements with controls as tabbable (BLINK & FIREFOX)' , ( ) => {
273
- // Only run this spec for Blink and Firefox, because those always treat video
274
- // elements with controls as tabbable.
275
- if ( ! platform . BLINK && ! platform . FIREFOX ) {
276
- return ;
277
- }
271
+ const video = createFromTemplate ( '<video controls>' , true ) ;
272
+ expect ( checker . isTabbable ( video ) ) . toBe ( true ) ;
273
+ } ) ;
278
274
279
- const video = createFromTemplate ( '<video controls>' , true ) ;
275
+ it ( 'should respect the tabindex for video elements with controls' , ( ) => {
276
+ if ( shouldSkip ) {
277
+ return ;
278
+ }
280
279
281
- expect ( checker . isTabbable ( video ) ) . toBe ( true ) ;
280
+ const video = createFromTemplate ( '<video controls>' , true ) ;
281
+ expect ( checker . isTabbable ( video ) ) . toBe ( true ) ;
282
282
283
- video . tabIndex = - 1 ;
283
+ video . tabIndex = - 1 ;
284
+ expect ( checker . isTabbable ( video ) ) . toBe ( false ) ;
285
+ } ) ;
284
286
285
- expect ( checker . isTabbable ( video ) ) . toBe ( true ) ;
286
- } ) ;
287
+ // Firefox always makes video elements (regardless of the controls) as tabbable, unless
288
+ // explicitly opted-out by setting the tabindex.
289
+ it ( 'should by default treat video elements without controls as tabbable in firefox' , ( ) => {
290
+ if ( ! platform . FIREFOX ) {
291
+ return ;
292
+ }
287
293
288
- // Some tests should not run inside of iOS browsers, because those only allow specific
289
- // elements to be tabbable and cause the tests to always fail.
290
- describe ( 'for non-iOS browsers' , ( ) => {
291
- let shouldSkip : boolean ;
294
+ const video = createFromTemplate ( '<video>' , true ) ;
295
+ expect ( checker . isTabbable ( video ) ) . toBe ( true ) ;
292
296
293
- beforeEach ( ( ) => {
294
- shouldSkip = platform . IOS ;
297
+ video . tabIndex = - 1 ;
298
+ expect ( checker . isTabbable ( video ) ) . toBe ( false ) ;
295
299
} ) ;
296
300
297
301
it ( 'should mark form controls and anchors without tabindex attribute as tabbable' , ( ) => {
@@ -424,39 +428,25 @@ describe('InteractivityChecker', () => {
424
428
}
425
429
} ) ;
426
430
427
- it ( 'should always mark audio elements without controls as not tabbable' , ( ) => {
431
+ it ( 'should detect audio elements with controls as tabbable' , ( ) => {
428
432
if ( ! shouldSkip ) {
429
- const audio = createFromTemplate ( '<audio>' , true ) ;
430
-
433
+ const audio = createFromTemplate ( '<audio controls>' , true ) ;
434
+ expect ( checker . isTabbable ( audio ) ) . toBe ( true ) ;
435
+ audio . tabIndex = - 1 ;
431
436
expect ( checker . isTabbable ( audio ) ) . toBe ( false ) ;
432
437
}
433
438
} ) ;
434
439
435
- } ) ;
436
-
437
- describe ( 'for Blink and Webkit browsers' , ( ) => {
438
- let shouldSkip : boolean ;
439
-
440
- beforeEach ( ( ) => {
441
- shouldSkip = ! platform . BLINK && ! platform . WEBKIT ;
442
- } ) ;
440
+ it ( 'should always detect audio elements without controls as non-tabbable' , ( ) => {
441
+ if ( ! shouldSkip ) {
442
+ const audio = createFromTemplate ( '<audio>' , true ) ;
443
+ expect ( checker . isTabbable ( audio ) ) . toBe ( false ) ;
443
444
444
- it ( 'should not mark elements inside of object frames as tabbable' , ( ) => {
445
- if ( shouldSkip ) {
446
- return ;
445
+ // Setting a `tabindex` has no effect. The audio element is expected
446
+ // to be still not tabbable.
447
+ audio . tabIndex = 0 ;
448
+ expect ( checker . isTabbable ( audio ) ) . toBe ( false ) ;
447
449
}
448
-
449
- const objectEl = createFromTemplate ( '<object>' , true ) as HTMLObjectElement ;
450
- const button = createFromTemplate ( '<button tabindex="0">Not Tabbable</button>' ) ;
451
-
452
- appendElements ( [ objectEl ] ) ;
453
-
454
- // This creates an empty contentDocument for the frame element.
455
- objectEl . type = 'text/html' ;
456
- objectEl . contentDocument ! . body . appendChild ( button ) ;
457
-
458
- expect ( checker . isTabbable ( objectEl ) ) . toBe ( false ) ;
459
- expect ( checker . isTabbable ( button ) ) . toBe ( false ) ;
460
450
} ) ;
461
451
462
452
it ( 'should not mark elements inside of invisible frames as tabbable' , ( ) => {
@@ -482,57 +472,6 @@ describe('InteractivityChecker', () => {
482
472
expect ( checker . isTabbable ( objectEl ) ) . toBe ( false ) ;
483
473
}
484
474
} ) ;
485
-
486
- } ) ;
487
-
488
- describe ( 'for Blink browsers' , ( ) => {
489
- let shouldSkip : boolean ;
490
-
491
- beforeEach ( ( ) => {
492
- shouldSkip = ! platform . BLINK ;
493
- } ) ;
494
-
495
- it ( 'should always mark audio elements with controls as tabbable' , ( ) => {
496
- if ( shouldSkip ) {
497
- return ;
498
- }
499
-
500
- const audio = createFromTemplate ( '<audio controls>' , true ) ;
501
-
502
- expect ( checker . isTabbable ( audio ) ) . toBe ( true ) ;
503
-
504
- audio . tabIndex = - 1 ;
505
-
506
- // The audio element will be still tabbable because Blink always
507
- // considers them as tabbable.
508
- expect ( checker . isTabbable ( audio ) ) . toBe ( true ) ;
509
- } ) ;
510
-
511
- } ) ;
512
-
513
- describe ( 'for Internet Explorer' , ( ) => {
514
- let shouldSkip : boolean ;
515
-
516
- beforeEach ( ( ) => {
517
- shouldSkip = ! platform . TRIDENT ;
518
- } ) ;
519
-
520
- it ( 'should never mark video elements without controls as tabbable' , ( ) => {
521
- if ( shouldSkip ) {
522
- return ;
523
- }
524
-
525
- // In Internet Explorer video elements without controls are never tabbable.
526
- const video = createFromTemplate ( '<video>' , true ) ;
527
-
528
- expect ( checker . isTabbable ( video ) ) . toBe ( false ) ;
529
-
530
- video . tabIndex = 0 ;
531
-
532
- expect ( checker . isTabbable ( video ) ) . toBe ( false ) ;
533
-
534
- } ) ;
535
-
536
475
} ) ;
537
476
538
477
describe ( 'for iOS browsers' , ( ) => {
0 commit comments