@@ -4,17 +4,23 @@ import {StyleModule} from './index';
4
4
import { By } from '@angular/platform-browser' ;
5
5
import { TAB } from '../keyboard/keycodes' ;
6
6
import { FocusOriginMonitor } from './focus-classes' ;
7
+ import { PlatformModule } from '../platform/index' ;
8
+ import { Platform } from '../platform/platform' ;
7
9
8
10
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.
9
14
describe ( 'FocusOriginMonitor' , ( ) => {
10
15
let fixture : ComponentFixture < PlainButton > ;
11
16
let buttonElement : HTMLElement ;
12
17
let buttonRenderer : Renderer ;
13
18
let focusOriginMonitor : FocusOriginMonitor ;
19
+ let platform : Platform ;
14
20
15
21
beforeEach ( async ( ( ) => {
16
22
TestBed . configureTestingModule ( {
17
- imports : [ StyleModule ] ,
23
+ imports : [ StyleModule , PlatformModule ] ,
18
24
declarations : [
19
25
PlainButton ,
20
26
] ,
@@ -23,18 +29,21 @@ describe('FocusOriginMonitor', () => {
23
29
TestBed . compileComponents ( ) ;
24
30
} ) ) ;
25
31
26
- beforeEach ( inject ( [ FocusOriginMonitor ] , ( fom : FocusOriginMonitor ) => {
32
+ beforeEach ( inject ( [ FocusOriginMonitor , Platform ] , ( fom : FocusOriginMonitor , pfm : Platform ) => {
27
33
fixture = TestBed . createComponent ( PlainButton ) ;
28
34
fixture . detectChanges ( ) ;
29
35
30
36
buttonElement = fixture . debugElement . query ( By . css ( 'button' ) ) . nativeElement ;
31
37
buttonRenderer = fixture . componentInstance . renderer ;
32
38
focusOriginMonitor = fom ;
39
+ platform = pfm ;
33
40
34
41
focusOriginMonitor . registerElementForFocusClasses ( buttonElement , buttonRenderer ) ;
35
42
} ) ) ;
36
43
37
44
it ( 'manually registered element should receive focus classes' , async ( ( ) => {
45
+ if ( platform . FIREFOX ) return ;
46
+
38
47
buttonElement . focus ( ) ;
39
48
fixture . detectChanges ( ) ;
40
49
@@ -47,6 +56,8 @@ describe('FocusOriginMonitor', () => {
47
56
} ) ) ;
48
57
49
58
it ( 'should detect focus via keyboard' , async ( ( ) => {
59
+ if ( platform . FIREFOX ) return ;
60
+
50
61
// Simulate focus via keyboard.
51
62
dispatchKeydownEvent ( document , TAB ) ;
52
63
buttonElement . focus ( ) ;
@@ -65,6 +76,8 @@ describe('FocusOriginMonitor', () => {
65
76
} ) ) ;
66
77
67
78
it ( 'should detect focus via mouse' , async ( ( ) => {
79
+ if ( platform . FIREFOX ) return ;
80
+
68
81
// Simulate focus via mouse.
69
82
dispatchMousedownEvent ( document ) ;
70
83
buttonElement . focus ( ) ;
@@ -83,6 +96,8 @@ describe('FocusOriginMonitor', () => {
83
96
} ) ) ;
84
97
85
98
it ( 'should detect programmatic focus' , async ( ( ) => {
99
+ if ( platform . FIREFOX ) return ;
100
+
86
101
// Programmatically focus.
87
102
buttonElement . focus ( ) ;
88
103
fixture . detectChanges ( ) ;
@@ -100,6 +115,8 @@ describe('FocusOriginMonitor', () => {
100
115
} ) ) ;
101
116
102
117
it ( 'focusVia keyboard should simulate keyboard focus' , async ( ( ) => {
118
+ if ( platform . FIREFOX ) return ;
119
+
103
120
focusOriginMonitor . focusVia ( buttonElement , buttonRenderer , 'keyboard' ) ;
104
121
fixture . detectChanges ( ) ;
105
122
@@ -116,6 +133,8 @@ describe('FocusOriginMonitor', () => {
116
133
} ) ) ;
117
134
118
135
it ( 'focusVia mouse should simulate mouse focus' , async ( ( ) => {
136
+ if ( platform . FIREFOX ) return ;
137
+
119
138
focusOriginMonitor . focusVia ( buttonElement , buttonRenderer , 'mouse' ) ;
120
139
fixture . detectChanges ( ) ;
121
140
@@ -132,6 +151,8 @@ describe('FocusOriginMonitor', () => {
132
151
} ) ) ;
133
152
134
153
it ( 'focusVia program should simulate programmatic focus' , async ( ( ) => {
154
+ if ( platform . FIREFOX ) return ;
155
+
135
156
focusOriginMonitor . focusVia ( buttonElement , buttonRenderer , 'program' ) ;
136
157
fixture . detectChanges ( ) ;
137
158
@@ -152,10 +173,11 @@ describe('FocusOriginMonitor', () => {
152
173
describe ( 'cdkFocusClasses' , ( ) => {
153
174
let fixture : ComponentFixture < ButtonWithFocusClasses > ;
154
175
let buttonElement : HTMLElement ;
176
+ let platform : Platform ;
155
177
156
178
beforeEach ( async ( ( ) => {
157
179
TestBed . configureTestingModule ( {
158
- imports : [ StyleModule ] ,
180
+ imports : [ StyleModule , PlatformModule ] ,
159
181
declarations : [
160
182
ButtonWithFocusClasses ,
161
183
] ,
@@ -164,23 +186,21 @@ describe('cdkFocusClasses', () => {
164
186
TestBed . compileComponents ( ) ;
165
187
} ) ) ;
166
188
167
- beforeEach ( ( ) => {
189
+ beforeEach ( inject ( [ Platform ] , ( pfm : Platform ) => {
168
190
fixture = TestBed . createComponent ( ButtonWithFocusClasses ) ;
169
191
fixture . detectChanges ( ) ;
170
192
171
193
buttonElement = fixture . debugElement . query ( By . css ( 'button' ) ) . nativeElement ;
172
- } ) ;
173
-
174
- afterEach ( ( ) => {
175
- buttonElement . blur ( ) ;
176
- fixture . detectChanges ( ) ;
177
- } ) ;
194
+ platform = pfm ;
195
+ } ) ) ;
178
196
179
197
it ( 'should initially not be focused' , ( ) => {
180
198
expect ( buttonElement . classList . length ) . toBe ( 0 , 'button should not have focus classes' ) ;
181
199
} ) ;
182
200
183
201
it ( 'should detect focus via keyboard' , async ( ( ) => {
202
+ if ( platform . FIREFOX ) return ;
203
+
184
204
// Simulate focus via keyboard.
185
205
dispatchKeydownEvent ( document , TAB ) ;
186
206
buttonElement . focus ( ) ;
@@ -199,6 +219,8 @@ describe('cdkFocusClasses', () => {
199
219
} ) ) ;
200
220
201
221
it ( 'should detect focus via mouse' , async ( ( ) => {
222
+ if ( platform . FIREFOX ) return ;
223
+
202
224
// Simulate focus via mouse.
203
225
dispatchMousedownEvent ( document ) ;
204
226
buttonElement . focus ( ) ;
@@ -217,6 +239,8 @@ describe('cdkFocusClasses', () => {
217
239
} ) ) ;
218
240
219
241
it ( 'should detect programmatic focus' , async ( ( ) => {
242
+ if ( platform . FIREFOX ) return ;
243
+
220
244
// Programmatically focus.
221
245
buttonElement . focus ( ) ;
222
246
fixture . detectChanges ( ) ;
0 commit comments