@@ -54,7 +54,7 @@ describe('FocusMonitor', () => {
5454 dispatchKeyboardEvent ( document , 'keydown' , TAB ) ;
5555 buttonElement . focus ( ) ;
5656 fixture . detectChanges ( ) ;
57- tick ( ) ;
57+ flush ( ) ;
5858
5959 expect ( buttonElement . classList . length )
6060 . toBe ( 2 , 'button should have exactly 2 focus classes' ) ;
@@ -70,7 +70,7 @@ describe('FocusMonitor', () => {
7070 dispatchMouseEvent ( buttonElement , 'mousedown' ) ;
7171 buttonElement . focus ( ) ;
7272 fixture . detectChanges ( ) ;
73- tick ( ) ;
73+ flush ( ) ;
7474
7575 expect ( buttonElement . classList . length )
7676 . toBe ( 2 , 'button should have exactly 2 focus classes' ) ;
@@ -114,7 +114,7 @@ describe('FocusMonitor', () => {
114114
115115 it ( 'focusVia keyboard should simulate keyboard focus' , fakeAsync ( ( ) => {
116116 focusMonitor . focusVia ( buttonElement , 'keyboard' ) ;
117- tick ( ) ;
117+ flush ( ) ;
118118
119119 expect ( buttonElement . classList . length )
120120 . toBe ( 2 , 'button should have exactly 2 focus classes' ) ;
@@ -128,7 +128,7 @@ describe('FocusMonitor', () => {
128128 it ( 'focusVia mouse should simulate mouse focus' , fakeAsync ( ( ) => {
129129 focusMonitor . focusVia ( buttonElement , 'mouse' ) ;
130130 fixture . detectChanges ( ) ;
131- tick ( ) ;
131+ flush ( ) ;
132132
133133 expect ( buttonElement . classList . length )
134134 . toBe ( 2 , 'button should have exactly 2 focus classes' ) ;
@@ -142,7 +142,7 @@ describe('FocusMonitor', () => {
142142 it ( 'focusVia mouse should simulate mouse focus' , fakeAsync ( ( ) => {
143143 focusMonitor . focusVia ( buttonElement , 'touch' ) ;
144144 fixture . detectChanges ( ) ;
145- tick ( ) ;
145+ flush ( ) ;
146146
147147 expect ( buttonElement . classList . length )
148148 . toBe ( 2 , 'button should have exactly 2 focus classes' ) ;
@@ -156,7 +156,7 @@ describe('FocusMonitor', () => {
156156 it ( 'focusVia program should simulate programmatic focus' , fakeAsync ( ( ) => {
157157 focusMonitor . focusVia ( buttonElement , 'program' ) ;
158158 fixture . detectChanges ( ) ;
159- tick ( ) ;
159+ flush ( ) ;
160160
161161 expect ( buttonElement . classList . length )
162162 . toBe ( 2 , 'button should have exactly 2 focus classes' ) ;
@@ -212,6 +212,21 @@ describe('FocusMonitor', () => {
212212
213213 expect ( buttonElement . classList . length ) . toBe ( 0 , 'button should not have any focus classes' ) ;
214214 } ) ) ;
215+
216+ it ( 'should not clear the focus origin too early in the current event loop' , fakeAsync ( ( ) => {
217+ dispatchKeyboardEvent ( document , 'keydown' , TAB ) ;
218+
219+ // Simulate the behavior of Firefox 57 where the focus event sometimes happens *one* tick later.
220+ tick ( ) ;
221+
222+ buttonElement . focus ( ) ;
223+
224+ // Since the timeout doesn't clear the focus origin too early as with the `0ms` timeout, the
225+ // focus origin should be reported properly.
226+ expect ( changeHandler ) . toHaveBeenCalledWith ( 'keyboard' ) ;
227+
228+ flush ( ) ;
229+ } ) ) ;
215230} ) ;
216231
217232
@@ -250,7 +265,7 @@ describe('cdkMonitorFocus', () => {
250265 dispatchKeyboardEvent ( document , 'keydown' , TAB ) ;
251266 buttonElement . focus ( ) ;
252267 fixture . detectChanges ( ) ;
253- tick ( ) ;
268+ flush ( ) ;
254269
255270 expect ( buttonElement . classList . length )
256271 . toBe ( 2 , 'button should have exactly 2 focus classes' ) ;
@@ -266,7 +281,7 @@ describe('cdkMonitorFocus', () => {
266281 dispatchMouseEvent ( buttonElement , 'mousedown' ) ;
267282 buttonElement . focus ( ) ;
268283 fixture . detectChanges ( ) ;
269- tick ( ) ;
284+ flush ( ) ;
270285
271286 expect ( buttonElement . classList . length )
272287 . toBe ( 2 , 'button should have exactly 2 focus classes' ) ;
0 commit comments