@@ -54,7 +54,7 @@ describe('FocusMonitor', () => {
54
54
dispatchKeyboardEvent ( document , 'keydown' , TAB ) ;
55
55
buttonElement . focus ( ) ;
56
56
fixture . detectChanges ( ) ;
57
- tick ( ) ;
57
+ flush ( ) ;
58
58
59
59
expect ( buttonElement . classList . length )
60
60
. toBe ( 2 , 'button should have exactly 2 focus classes' ) ;
@@ -70,7 +70,7 @@ describe('FocusMonitor', () => {
70
70
dispatchMouseEvent ( buttonElement , 'mousedown' ) ;
71
71
buttonElement . focus ( ) ;
72
72
fixture . detectChanges ( ) ;
73
- tick ( ) ;
73
+ flush ( ) ;
74
74
75
75
expect ( buttonElement . classList . length )
76
76
. toBe ( 2 , 'button should have exactly 2 focus classes' ) ;
@@ -114,7 +114,7 @@ describe('FocusMonitor', () => {
114
114
115
115
it ( 'focusVia keyboard should simulate keyboard focus' , fakeAsync ( ( ) => {
116
116
focusMonitor . focusVia ( buttonElement , 'keyboard' ) ;
117
- tick ( ) ;
117
+ flush ( ) ;
118
118
119
119
expect ( buttonElement . classList . length )
120
120
. toBe ( 2 , 'button should have exactly 2 focus classes' ) ;
@@ -128,7 +128,7 @@ describe('FocusMonitor', () => {
128
128
it ( 'focusVia mouse should simulate mouse focus' , fakeAsync ( ( ) => {
129
129
focusMonitor . focusVia ( buttonElement , 'mouse' ) ;
130
130
fixture . detectChanges ( ) ;
131
- tick ( ) ;
131
+ flush ( ) ;
132
132
133
133
expect ( buttonElement . classList . length )
134
134
. toBe ( 2 , 'button should have exactly 2 focus classes' ) ;
@@ -142,7 +142,7 @@ describe('FocusMonitor', () => {
142
142
it ( 'focusVia mouse should simulate mouse focus' , fakeAsync ( ( ) => {
143
143
focusMonitor . focusVia ( buttonElement , 'touch' ) ;
144
144
fixture . detectChanges ( ) ;
145
- tick ( ) ;
145
+ flush ( ) ;
146
146
147
147
expect ( buttonElement . classList . length )
148
148
. toBe ( 2 , 'button should have exactly 2 focus classes' ) ;
@@ -156,7 +156,7 @@ describe('FocusMonitor', () => {
156
156
it ( 'focusVia program should simulate programmatic focus' , fakeAsync ( ( ) => {
157
157
focusMonitor . focusVia ( buttonElement , 'program' ) ;
158
158
fixture . detectChanges ( ) ;
159
- tick ( ) ;
159
+ flush ( ) ;
160
160
161
161
expect ( buttonElement . classList . length )
162
162
. toBe ( 2 , 'button should have exactly 2 focus classes' ) ;
@@ -218,13 +218,27 @@ describe('FocusMonitor', () => {
218
218
219
219
focusMonitor . focusVia ( buttonElement , 'program' , { preventScroll : true } ) ;
220
220
fixture . detectChanges ( ) ;
221
- tick ( ) ;
221
+ flush ( ) ;
222
222
223
223
expect ( buttonElement . focus ) . toHaveBeenCalledWith ( jasmine . objectContaining ( {
224
224
preventScroll : true
225
225
} ) ) ;
226
226
} ) ) ;
227
227
228
+ it ( 'should not clear the focus origin too early in the current event loop' , fakeAsync ( ( ) => {
229
+ dispatchKeyboardEvent ( document , 'keydown' , TAB ) ;
230
+
231
+ // Simulate the behavior of Firefox 57 where the focus event sometimes happens *one* tick later.
232
+ tick ( ) ;
233
+
234
+ buttonElement . focus ( ) ;
235
+
236
+ // Since the timeout doesn't clear the focus origin too early as with the `0ms` timeout, the
237
+ // focus origin should be reported properly.
238
+ expect ( changeHandler ) . toHaveBeenCalledWith ( 'keyboard' ) ;
239
+
240
+ flush ( ) ;
241
+ } ) ) ;
228
242
} ) ;
229
243
230
244
@@ -263,7 +277,7 @@ describe('cdkMonitorFocus', () => {
263
277
dispatchKeyboardEvent ( document , 'keydown' , TAB ) ;
264
278
buttonElement . focus ( ) ;
265
279
fixture . detectChanges ( ) ;
266
- tick ( ) ;
280
+ flush ( ) ;
267
281
268
282
expect ( buttonElement . classList . length )
269
283
. toBe ( 2 , 'button should have exactly 2 focus classes' ) ;
@@ -279,7 +293,7 @@ describe('cdkMonitorFocus', () => {
279
293
dispatchMouseEvent ( buttonElement , 'mousedown' ) ;
280
294
buttonElement . focus ( ) ;
281
295
fixture . detectChanges ( ) ;
282
- tick ( ) ;
296
+ flush ( ) ;
283
297
284
298
expect ( buttonElement . classList . length )
285
299
. toBe ( 2 , 'button should have exactly 2 focus classes' ) ;
0 commit comments