@@ -4,17 +4,23 @@ import {StyleModule} from './index';
44import { By } from '@angular/platform-browser' ;
55import { TAB } from '../keyboard/keycodes' ;
66import { FocusOriginMonitor } from './focus-classes' ;
7+ import { PlatformModule } from '../platform/index' ;
8+ import { Platform } from '../platform/platform' ;
79
810
11+ // NOTE: Focus listeners fail to trigger in Firefox due to the browser window not having focus.
12+ // (see https://bugzilla.mozilla.org/show_bug.cgi?id=497839).
13+ // Therefore we skip the tests for firefox.
914describe ( 'FocusOriginMonitor' , ( ) => {
1015 let fixture : ComponentFixture < PlainButton > ;
1116 let buttonElement : HTMLElement ;
1217 let buttonRenderer : Renderer ;
1318 let focusOriginMonitor : FocusOriginMonitor ;
19+ let platform : Platform ;
1420
1521 beforeEach ( async ( ( ) => {
1622 TestBed . configureTestingModule ( {
17- imports : [ StyleModule ] ,
23+ imports : [ StyleModule , PlatformModule ] ,
1824 declarations : [
1925 PlainButton ,
2026 ] ,
@@ -23,18 +29,21 @@ describe('FocusOriginMonitor', () => {
2329 TestBed . compileComponents ( ) ;
2430 } ) ) ;
2531
26- beforeEach ( inject ( [ FocusOriginMonitor ] , ( fom : FocusOriginMonitor ) => {
32+ beforeEach ( inject ( [ FocusOriginMonitor , Platform ] , ( fom : FocusOriginMonitor , pfm : Platform ) => {
2733 fixture = TestBed . createComponent ( PlainButton ) ;
2834 fixture . detectChanges ( ) ;
2935
3036 buttonElement = fixture . debugElement . query ( By . css ( 'button' ) ) . nativeElement ;
3137 buttonRenderer = fixture . componentInstance . renderer ;
3238 focusOriginMonitor = fom ;
39+ platform = pfm ;
3340
3441 focusOriginMonitor . registerElementForFocusClasses ( buttonElement , buttonRenderer ) ;
3542 } ) ) ;
3643
3744 it ( 'manually registered element should receive focus classes' , async ( ( ) => {
45+ if ( platform . FIREFOX ) return ;
46+
3847 buttonElement . focus ( ) ;
3948 fixture . detectChanges ( ) ;
4049
@@ -47,6 +56,8 @@ describe('FocusOriginMonitor', () => {
4756 } ) ) ;
4857
4958 it ( 'should detect focus via keyboard' , async ( ( ) => {
59+ if ( platform . FIREFOX ) return ;
60+
5061 // Simulate focus via keyboard.
5162 dispatchKeydownEvent ( document , TAB ) ;
5263 buttonElement . focus ( ) ;
@@ -65,6 +76,8 @@ describe('FocusOriginMonitor', () => {
6576 } ) ) ;
6677
6778 it ( 'should detect focus via mouse' , async ( ( ) => {
79+ if ( platform . FIREFOX ) return ;
80+
6881 // Simulate focus via mouse.
6982 dispatchMousedownEvent ( document ) ;
7083 buttonElement . focus ( ) ;
@@ -83,6 +96,8 @@ describe('FocusOriginMonitor', () => {
8396 } ) ) ;
8497
8598 it ( 'should detect programmatic focus' , async ( ( ) => {
99+ if ( platform . FIREFOX ) return ;
100+
86101 // Programmatically focus.
87102 buttonElement . focus ( ) ;
88103 fixture . detectChanges ( ) ;
@@ -100,6 +115,8 @@ describe('FocusOriginMonitor', () => {
100115 } ) ) ;
101116
102117 it ( 'focusVia keyboard should simulate keyboard focus' , async ( ( ) => {
118+ if ( platform . FIREFOX ) return ;
119+
103120 focusOriginMonitor . focusVia ( buttonElement , buttonRenderer , 'keyboard' ) ;
104121 fixture . detectChanges ( ) ;
105122
@@ -116,6 +133,8 @@ describe('FocusOriginMonitor', () => {
116133 } ) ) ;
117134
118135 it ( 'focusVia mouse should simulate mouse focus' , async ( ( ) => {
136+ if ( platform . FIREFOX ) return ;
137+
119138 focusOriginMonitor . focusVia ( buttonElement , buttonRenderer , 'mouse' ) ;
120139 fixture . detectChanges ( ) ;
121140
@@ -132,6 +151,8 @@ describe('FocusOriginMonitor', () => {
132151 } ) ) ;
133152
134153 it ( 'focusVia program should simulate programmatic focus' , async ( ( ) => {
154+ if ( platform . FIREFOX ) return ;
155+
135156 focusOriginMonitor . focusVia ( buttonElement , buttonRenderer , 'program' ) ;
136157 fixture . detectChanges ( ) ;
137158
@@ -152,10 +173,11 @@ describe('FocusOriginMonitor', () => {
152173describe ( 'cdkFocusClasses' , ( ) => {
153174 let fixture : ComponentFixture < ButtonWithFocusClasses > ;
154175 let buttonElement : HTMLElement ;
176+ let platform : Platform ;
155177
156178 beforeEach ( async ( ( ) => {
157179 TestBed . configureTestingModule ( {
158- imports : [ StyleModule ] ,
180+ imports : [ StyleModule , PlatformModule ] ,
159181 declarations : [
160182 ButtonWithFocusClasses ,
161183 ] ,
@@ -164,23 +186,21 @@ describe('cdkFocusClasses', () => {
164186 TestBed . compileComponents ( ) ;
165187 } ) ) ;
166188
167- beforeEach ( ( ) => {
189+ beforeEach ( inject ( [ Platform ] , ( pfm : Platform ) => {
168190 fixture = TestBed . createComponent ( ButtonWithFocusClasses ) ;
169191 fixture . detectChanges ( ) ;
170192
171193 buttonElement = fixture . debugElement . query ( By . css ( 'button' ) ) . nativeElement ;
172- } ) ;
173-
174- afterEach ( ( ) => {
175- buttonElement . blur ( ) ;
176- fixture . detectChanges ( ) ;
177- } ) ;
194+ platform = pfm ;
195+ } ) ) ;
178196
179197 it ( 'should initially not be focused' , ( ) => {
180198 expect ( buttonElement . classList . length ) . toBe ( 0 , 'button should not have focus classes' ) ;
181199 } ) ;
182200
183201 it ( 'should detect focus via keyboard' , async ( ( ) => {
202+ if ( platform . FIREFOX ) return ;
203+
184204 // Simulate focus via keyboard.
185205 dispatchKeydownEvent ( document , TAB ) ;
186206 buttonElement . focus ( ) ;
@@ -199,6 +219,8 @@ describe('cdkFocusClasses', () => {
199219 } ) ) ;
200220
201221 it ( 'should detect focus via mouse' , async ( ( ) => {
222+ if ( platform . FIREFOX ) return ;
223+
202224 // Simulate focus via mouse.
203225 dispatchMousedownEvent ( document ) ;
204226 buttonElement . focus ( ) ;
@@ -217,6 +239,8 @@ describe('cdkFocusClasses', () => {
217239 } ) ) ;
218240
219241 it ( 'should detect programmatic focus' , async ( ( ) => {
242+ if ( platform . FIREFOX ) return ;
243+
220244 // Programmatically focus.
221245 buttonElement . focus ( ) ;
222246 fixture . detectChanges ( ) ;
0 commit comments