@@ -1611,7 +1611,12 @@ function testAuthEventManager_nonCordovaIosOrAndroidFileEnvironment() {
1611
1611
// All popup/redirect methods should fail with operation not supported errors.
1612
1612
manager . getRedirectResult ( ) . thenCatch ( function ( error ) {
1613
1613
assertErrorEquals ( expectedError , error ) ;
1614
- asyncTestCase . signal ( ) ;
1614
+ // Clear redirect result will not clear an operation not supported error.
1615
+ manager . clearRedirectResult ( ) ;
1616
+ manager . getRedirectResult ( ) . thenCatch ( function ( error ) {
1617
+ assertErrorEquals ( expectedError , error ) ;
1618
+ asyncTestCase . signal ( ) ;
1619
+ } ) ;
1615
1620
} ) ;
1616
1621
manager . processRedirect ( 'linkViaRedirect' , provider , '1234' )
1617
1622
. thenCatch ( function ( error ) {
@@ -1781,7 +1786,12 @@ function testProcessRedirect_error_cordovahandler() {
1781
1786
assertFalse ( status ) ;
1782
1787
manager . getRedirectResult ( ) . thenCatch ( function ( error ) {
1783
1788
assertErrorEquals ( expectedError , error ) ;
1784
- asyncTestCase . signal ( ) ;
1789
+ // Clear redirect result should clear recoverable errors.
1790
+ manager . clearRedirectResult ( ) ;
1791
+ manager . getRedirectResult ( ) . then ( function ( result ) {
1792
+ assertNull ( result . user ) ;
1793
+ asyncTestCase . signal ( ) ;
1794
+ } ) ;
1785
1795
} ) ;
1786
1796
} ) ;
1787
1797
}
@@ -1902,7 +1912,12 @@ function testGetRedirectResult_success_cordovahandler() {
1902
1912
// Initial expected result should resolve.
1903
1913
manager . getRedirectResult ( ) . then ( function ( result ) {
1904
1914
assertEquals ( expectedResult , result ) ;
1905
- asyncTestCase . signal ( ) ;
1915
+ // Clear redirect result should clear successful results.
1916
+ manager . clearRedirectResult ( ) ;
1917
+ manager . getRedirectResult ( ) . then ( function ( result ) {
1918
+ assertNull ( result . user ) ;
1919
+ asyncTestCase . signal ( ) ;
1920
+ } ) ;
1906
1921
} ) ;
1907
1922
} ) ;
1908
1923
}
@@ -1946,7 +1961,12 @@ function testGetRedirectResult_error_cordovahandler() {
1946
1961
// Initial expected result should resolve.
1947
1962
manager . getRedirectResult ( ) . thenCatch ( function ( error ) {
1948
1963
assertErrorEquals ( expectedError , error ) ;
1949
- asyncTestCase . signal ( ) ;
1964
+ // Clear redirect result should clear recoverable errors.
1965
+ manager . clearRedirectResult ( ) ;
1966
+ manager . getRedirectResult ( ) . then ( function ( result ) {
1967
+ assertNull ( result . user ) ;
1968
+ asyncTestCase . signal ( ) ;
1969
+ } ) ;
1950
1970
} ) ;
1951
1971
} ) ;
1952
1972
}
@@ -2177,7 +2197,7 @@ function testProcessAuthEvent_invalidAuthEvent() {
2177
2197
var expectedAuthEvent = null ;
2178
2198
var manager = fireauth . AuthEventManager . getManager (
2179
2199
authDomain1 , apiKey1 , appName1 ) ;
2180
- manager . redirectAuthEventProcessor_ . processAuthEvent (
2200
+ manager . getRedirectAuthEventProcessor ( ) . processAuthEvent (
2181
2201
expectedAuthEvent , handler ) . thenCatch ( function ( error ) {
2182
2202
assertErrorEquals (
2183
2203
new fireauth . AuthError ( fireauth . authenum . Error . INVALID_AUTH_EVENT ) ,
@@ -2204,7 +2224,7 @@ function testProcessAuthEvent_unknownAuthEvent() {
2204
2224
assertObjectEquals ( expectedResult , result ) ;
2205
2225
asyncTestCase . signal ( ) ;
2206
2226
} ) ;
2207
- manager . redirectAuthEventProcessor_ . processAuthEvent (
2227
+ manager . getRedirectAuthEventProcessor ( ) . processAuthEvent (
2208
2228
expectedAuthEvent , handler ) . then ( function ( ) {
2209
2229
asyncTestCase . signal ( ) ;
2210
2230
} ) ;
@@ -2261,7 +2281,13 @@ function testProcessAuthEvent_unknownAuthEvent_webStorageNotSupported() {
2261
2281
manager . subscribe ( handler ) ;
2262
2282
manager . getRedirectResult ( ) . thenCatch ( function ( error ) {
2263
2283
assertErrorEquals ( expectedError , error ) ;
2264
- asyncTestCase . signal ( ) ;
2284
+ // Unrecoverable errors like unsupported web storage should not be
2285
+ // cleared.
2286
+ manager . clearRedirectResult ( ) ;
2287
+ manager . getRedirectResult ( ) . thenCatch ( function ( error ) {
2288
+ assertErrorEquals ( expectedError , error ) ;
2289
+ asyncTestCase . signal ( ) ;
2290
+ } ) ;
2265
2291
} ) ;
2266
2292
} ) ;
2267
2293
}
@@ -2279,7 +2305,7 @@ function testProcessAuthEvent_popupErrorAuthEvent() {
2279
2305
new fireauth . AuthError ( fireauth . authenum . Error . INTERNAL_ERROR ) ) ;
2280
2306
var manager = fireauth . AuthEventManager . getManager (
2281
2307
authDomain1 , apiKey1 , appName1 ) ;
2282
- manager . popupAuthEventProcessor_ . processAuthEvent (
2308
+ manager . getPopupAuthEventProcessor ( ) . processAuthEvent (
2283
2309
expectedAuthEvent , handler ) . then ( function ( ) {
2284
2310
// Resolve popup with error.
2285
2311
assertEquals ( 1 , handler . resolvePendingPopupEvent . getCallCount ( ) ) ;
@@ -2316,7 +2342,7 @@ function testProcessAuthEvent_redirectErrorAuthEvent() {
2316
2342
assertErrorEquals ( expectedError , error ) ;
2317
2343
asyncTestCase . signal ( ) ;
2318
2344
} ) ;
2319
- manager . redirectAuthEventProcessor_ . processAuthEvent (
2345
+ manager . getRedirectAuthEventProcessor ( ) . processAuthEvent (
2320
2346
expectedAuthEvent , handler ) . then ( function ( ) {
2321
2347
// Should not be called as event is not a popup type.
2322
2348
assertEquals ( 0 , handler . resolvePendingPopupEvent . getCallCount ( ) ) ;
@@ -2348,7 +2374,7 @@ function testProcessAuthEvent_finisher_successfulPopupAuthEvent() {
2348
2374
'SESSION_ID' ) ;
2349
2375
var manager = fireauth . AuthEventManager . getManager (
2350
2376
authDomain1 , apiKey1 , appName1 ) ;
2351
- manager . popupAuthEventProcessor_ . processAuthEvent (
2377
+ manager . getPopupAuthEventProcessor ( ) . processAuthEvent (
2352
2378
expectedAuthEvent , handler ) . then ( function ( ) {
2353
2379
// Resolve popup with success.
2354
2380
assertEquals ( 1 , handler . resolvePendingPopupEvent . getCallCount ( ) ) ;
@@ -2389,7 +2415,7 @@ function testProcessAuthEvent_finisher_errorPopupAuthEvent() {
2389
2415
'SESSION_ID' ) ;
2390
2416
var manager = fireauth . AuthEventManager . getManager (
2391
2417
authDomain1 , apiKey1 , appName1 ) ;
2392
- manager . popupAuthEventProcessor_ . processAuthEvent (
2418
+ manager . getPopupAuthEventProcessor ( ) . processAuthEvent (
2393
2419
expectedAuthEvent , handler ) . then ( function ( ) {
2394
2420
// Resolve popup with error.
2395
2421
assertEquals ( 1 , handler . resolvePendingPopupEvent . getCallCount ( ) ) ;
@@ -2439,7 +2465,7 @@ function testProcessAuthEvent_finisher_successfulRedirectAuthEvent() {
2439
2465
assertObjectEquals ( expectedRedirectResult , result ) ;
2440
2466
asyncTestCase . signal ( ) ;
2441
2467
} ) ;
2442
- manager . redirectAuthEventProcessor_ . processAuthEvent (
2468
+ manager . getRedirectAuthEventProcessor ( ) . processAuthEvent (
2443
2469
expectedAuthEvent , handler ) . then ( function ( ) {
2444
2470
// Popup resolve should not be called as this is not a popup event.
2445
2471
assertEquals ( 0 , handler . resolvePendingPopupEvent . getCallCount ( ) ) ;
@@ -2472,7 +2498,7 @@ function testProcessAuthEvent_finisher_errorRedirectAuthEvent() {
2472
2498
assertErrorEquals ( expectedError , error ) ;
2473
2499
asyncTestCase . signal ( ) ;
2474
2500
} ) ;
2475
- manager . redirectAuthEventProcessor_ . processAuthEvent (
2501
+ manager . getRedirectAuthEventProcessor ( ) . processAuthEvent (
2476
2502
expectedAuthEvent , handler ) . then ( function ( ) {
2477
2503
// Popup resolve should not be called as this is not a popup event.
2478
2504
assertEquals ( 0 , handler . resolvePendingPopupEvent . getCallCount ( ) ) ;
@@ -2494,7 +2520,7 @@ function testProcessAuthEvent_noHandler() {
2494
2520
'SESSION_ID' ) ;
2495
2521
var manager = fireauth . AuthEventManager . getManager (
2496
2522
authDomain1 , apiKey1 , appName1 ) ;
2497
- manager . redirectAuthEventProcessor_ . processAuthEvent (
2523
+ manager . getRedirectAuthEventProcessor ( ) . processAuthEvent (
2498
2524
expectedAuthEvent , handler ) . thenCatch ( function ( error ) {
2499
2525
assertErrorEquals ( expectedError , error ) ;
2500
2526
asyncTestCase . signal ( ) ;
@@ -2556,7 +2582,12 @@ function testRedirectResult_timeout() {
2556
2582
authDomain1 , apiKey1 , appName1 ) ;
2557
2583
manager . getRedirectResult ( ) . thenCatch ( function ( error ) {
2558
2584
assertErrorEquals ( expectedError , error ) ;
2559
- asyncTestCase . signal ( ) ;
2585
+ // Redirect results with recoverable errors should be cleared.
2586
+ manager . clearRedirectResult ( ) ;
2587
+ manager . getRedirectResult ( ) . then ( function ( result ) {
2588
+ assertNull ( result . user ) ;
2589
+ asyncTestCase . signal ( ) ;
2590
+ } ) ;
2560
2591
} ) ;
2561
2592
// Speed up timeout.
2562
2593
clock . tick ( timeoutDelay ) ;
@@ -2567,7 +2598,9 @@ function testRedirectResult_overwritePreviousRedirectResult() {
2567
2598
// Once redirect result is determined, it can still be overwritten, though
2568
2599
// in some cases like ifchandler which gets redirect result from
2569
2600
// sessionStorage, this should not happen.
2570
- asyncTestCase . waitForSignals ( 4 ) ;
2601
+ // Test also that clearRedirectResult will clear the cached result as long as
2602
+ // the operation is not pending.
2603
+ asyncTestCase . waitForSignals ( 2 ) ;
2571
2604
handler . getAuthEventHandlerFinisher = function ( mode , eventId ) {
2572
2605
return function ( requestUri , sessionId ) {
2573
2606
// Iterate through results array each call.
@@ -2595,21 +2628,32 @@ function testRedirectResult_overwritePreviousRedirectResult() {
2595
2628
assertObjectEquals ( expectedRedirectResult , result ) ;
2596
2629
asyncTestCase . signal ( ) ;
2597
2630
} ) ;
2598
- manager . redirectAuthEventProcessor_ . processAuthEvent (
2631
+ // Clear redirect result on a pending operation should have no effect.
2632
+ // Above getRedirectResult() should still resolve with expected first result.
2633
+ manager . clearRedirectResult ( ) ;
2634
+ manager . getRedirectAuthEventProcessor ( ) . processAuthEvent (
2599
2635
expectedAuthEvent , handler ) . then ( function ( ) {
2600
2636
// Popup resolve should not be called as this is not a popup event.
2601
2637
assertEquals ( 0 , handler . resolvePendingPopupEvent . getCallCount ( ) ) ;
2602
- asyncTestCase . signal ( ) ;
2638
+ // Clear redirect result after resolved operation should reset result.
2639
+ manager . clearRedirectResult ( ) ;
2640
+ return manager . getRedirectResult ( ) ;
2641
+ } ) . then ( function ( result ) {
2642
+ assertNull ( result . user ) ;
2603
2643
// Call Second time.
2604
- manager . redirectAuthEventProcessor_ . processAuthEvent (
2605
- expectedAuthEvent , handler ) . then ( function ( ) {
2606
- assertEquals ( 0 , handler . resolvePendingPopupEvent . getCallCount ( ) ) ;
2607
- asyncTestCase . signal ( ) ;
2608
- // getRedirectResult should resolve with the second expected result.
2609
- manager . getRedirectResult ( ) . then ( function ( result ) {
2610
- assertObjectEquals ( expectedRedirectResult2 , result ) ;
2611
- asyncTestCase . signal ( ) ;
2612
- } ) ;
2613
- } ) ;
2644
+ return manager . getRedirectAuthEventProcessor ( ) . processAuthEvent (
2645
+ expectedAuthEvent , handler ) ;
2646
+ } ) . then ( function ( ) {
2647
+ assertEquals ( 0 , handler . resolvePendingPopupEvent . getCallCount ( ) ) ;
2648
+ // getRedirectResult should resolve with the second expected result.
2649
+ return manager . getRedirectResult ( ) ;
2650
+ } ) . then ( function ( result ) {
2651
+ assertObjectEquals ( expectedRedirectResult2 , result ) ;
2652
+ // Clear redirect result after resolved operation should reset result.
2653
+ manager . clearRedirectResult ( ) ;
2654
+ return manager . getRedirectResult ( ) ;
2655
+ } ) . then ( function ( result ) {
2656
+ assertNull ( result . user ) ;
2657
+ asyncTestCase . signal ( ) ;
2614
2658
} ) ;
2615
2659
}
0 commit comments