@@ -20,11 +20,13 @@ import { UserCredential } from '@firebase/auth-exp';
20
20
import { expect } from 'chai' ;
21
21
import { createAnonAccount } from '../../helpers/integration/emulator_rest_helpers' ;
22
22
import { API_KEY } from '../../helpers/integration/settings' ;
23
+ import { START_FUNCTION } from './util/auth_driver' ;
23
24
import {
24
25
AnonFunction ,
25
26
CoreFunction ,
26
27
PersistenceFunction
27
28
} from './util/functions' ;
29
+ import { JsLoadCondition } from './util/js_load_condition' ;
28
30
import { browserDescribe } from './util/test_runner' ;
29
31
30
32
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
@@ -417,4 +419,73 @@ browserDescribe('WebDriver persistence test', driver => {
417
419
}
418
420
} ) ;
419
421
} ) ;
422
+
423
+ context ( 'persistence sync across windows and tabs' , ( ) => {
424
+ it ( 'sync current user across windows with indexedDB' , async ( ) => {
425
+ const cred : UserCredential = await driver . call (
426
+ AnonFunction . SIGN_IN_ANONYMOUSLY
427
+ ) ;
428
+ const uid = cred . user . uid ;
429
+ await driver . webDriver . executeScript ( 'window.open(".");' ) ;
430
+ await driver . selectPopupWindow ( ) ;
431
+ await driver . webDriver . wait ( new JsLoadCondition ( START_FUNCTION ) ) ;
432
+ await driver . injectConfigAndInitAuth ( ) ;
433
+ await driver . waitForAuthInit ( ) ;
434
+ const userInPopup = await driver . getUserSnapshot ( ) ;
435
+ expect ( userInPopup ) . not . to . be . null ;
436
+ expect ( userInPopup . uid ) . to . equal ( uid ) ;
437
+
438
+ await driver . call ( CoreFunction . SIGN_OUT ) ;
439
+ expect ( await driver . getUserSnapshot ( ) ) . to . be . null ;
440
+ await driver . selectMainWindow ( { noWait : true } ) ;
441
+ await driver . pause ( 500 ) ;
442
+ expect ( await driver . getUserSnapshot ( ) ) . to . be . null ;
443
+
444
+ const cred2 : UserCredential = await driver . call (
445
+ AnonFunction . SIGN_IN_ANONYMOUSLY
446
+ ) ;
447
+ const uid2 = cred2 . user . uid ;
448
+
449
+ await driver . selectPopupWindow ( ) ;
450
+ await driver . pause ( 500 ) ;
451
+ expect ( await driver . getUserSnapshot ( ) ) . to . contain ( { uid : uid2 } ) ;
452
+ } ) ;
453
+
454
+ it ( 'sync current user across windows with localStorage' , async ( ) => {
455
+ await driver . webDriver . navigate ( ) . refresh ( ) ;
456
+ // Simulate browsers that do not support indexedDB.
457
+ await driver . webDriver . executeScript ( 'delete window.indexedDB' ) ;
458
+ await driver . injectConfigAndInitAuth ( ) ;
459
+ await driver . waitForAuthInit ( ) ;
460
+ const cred : UserCredential = await driver . call (
461
+ AnonFunction . SIGN_IN_ANONYMOUSLY
462
+ ) ;
463
+ const uid = cred . user . uid ;
464
+ await driver . webDriver . executeScript ( 'window.open(".");' ) ;
465
+ await driver . selectPopupWindow ( ) ;
466
+ await driver . webDriver . wait ( new JsLoadCondition ( START_FUNCTION ) ) ;
467
+ // Simulate browsers that do not support indexedDB.
468
+ await driver . webDriver . executeScript ( 'delete window.indexedDB' ) ;
469
+ await driver . injectConfigAndInitAuth ( ) ;
470
+ await driver . waitForAuthInit ( ) ;
471
+ const userInPopup = await driver . getUserSnapshot ( ) ;
472
+ expect ( userInPopup ) . not . to . be . null ;
473
+ expect ( userInPopup . uid ) . to . equal ( uid ) ;
474
+
475
+ await driver . call ( CoreFunction . SIGN_OUT ) ;
476
+ expect ( await driver . getUserSnapshot ( ) ) . to . be . null ;
477
+ await driver . selectMainWindow ( { noWait : true } ) ;
478
+ await driver . pause ( 500 ) ;
479
+ expect ( await driver . getUserSnapshot ( ) ) . to . be . null ;
480
+
481
+ const cred2 : UserCredential = await driver . call (
482
+ AnonFunction . SIGN_IN_ANONYMOUSLY
483
+ ) ;
484
+ const uid2 = cred2 . user . uid ;
485
+
486
+ await driver . selectPopupWindow ( ) ;
487
+ await driver . pause ( 500 ) ;
488
+ expect ( await driver . getUserSnapshot ( ) ) . to . contain ( { uid : uid2 } ) ;
489
+ } ) ;
490
+ } ) ;
420
491
} ) ;
0 commit comments