@@ -6959,6 +6959,155 @@ function testAuth_getRedirectResult_unsupportedEnvironment() {
6959
6959
}
6960
6960
6961
6961
6962
+ function testAuth_signOut_clearSuccessRedirectResult ( ) {
6963
+ // Tests getRedirectResult with success event after signOut being called.
6964
+ fireauth . AuthEventManager . ENABLED = true ;
6965
+ const expectedCred = fireauth . GoogleAuthProvider . credential (
6966
+ null , 'ACCESS_TOKEN' ) ;
6967
+ // Expected sign in via redirect successful Auth event.
6968
+ const expectedAuthEvent = new fireauth . AuthEvent (
6969
+ fireauth . AuthEvent . Type . SIGN_IN_VIA_REDIRECT ,
6970
+ null ,
6971
+ 'http://www.example.com/#response' ,
6972
+ 'SESSION_ID' ) ;
6973
+ // Stub instantiateOAuthSignInHandler.
6974
+ stubs . replace (
6975
+ fireauth . AuthEventManager , 'instantiateOAuthSignInHandler' ,
6976
+ function ( authDomain , apiKey , appName ) {
6977
+ return {
6978
+ 'addAuthEventListener' : function ( handler ) {
6979
+ // auth1 should be subscribed.
6980
+ const manager = fireauth . AuthEventManager . getManager (
6981
+ config3 [ 'authDomain' ] , config3 [ 'apiKey' ] , app1 . name ) ;
6982
+ assertTrue ( manager . isSubscribed ( auth1 ) ) ;
6983
+ // In this case run immediately with expected redirect event.
6984
+ handler ( expectedAuthEvent ) ;
6985
+ asyncTestCase . signal ( ) ;
6986
+ } ,
6987
+ 'initializeAndWait' : function ( ) { return goog . Promise . resolve ( ) ; } ,
6988
+ 'shouldBeInitializedEarly' : function ( ) { return false ; } ,
6989
+ 'hasVolatileStorage' : function ( ) { return false ; }
6990
+ } ;
6991
+ } ) ;
6992
+ // Simulate successful finishPopupAndRedirectSignIn.
6993
+ stubs . replace (
6994
+ fireauth . Auth . prototype ,
6995
+ 'finishPopupAndRedirectSignIn' ,
6996
+ function ( requestUri , sessionId , postBody ) {
6997
+ assertEquals ( 'http://www.example.com/#response' , requestUri ) ;
6998
+ assertEquals ( 'SESSION_ID' , sessionId ) ;
6999
+ assertNull ( postBody ) ;
7000
+ user1 = new fireauth . AuthUser (
7001
+ config3 , expectedTokenResponse , accountInfo ) ;
7002
+ expectedPopupResult = {
7003
+ 'user' : user1 ,
7004
+ 'credential' : expectedCred ,
7005
+ 'additionalUserInfo' : expectedAdditionalUserInfo ,
7006
+ 'operationType' : fireauth . constants . OperationType . SIGN_IN
7007
+ } ;
7008
+ // User 1 should be set here and saved to storage.
7009
+ auth1 . setCurrentUser_ ( user1 ) ;
7010
+ asyncTestCase . signal ( ) ;
7011
+ return currentUserStorageManager . setCurrentUser ( user1 ) . then ( ( ) => {
7012
+ return expectedPopupResult ;
7013
+ } ) ;
7014
+ } ) ;
7015
+ let user1 , expectedPopupResult ;
7016
+ asyncTestCase . waitForSignals ( 3 ) ;
7017
+ const pendingRedirectManager = new fireauth . storage . PendingRedirectManager (
7018
+ config3 [ 'apiKey' ] + ':' + appId1 ) ;
7019
+ currentUserStorageManager = new fireauth . storage . UserManager (
7020
+ config3 [ 'apiKey' ] + ':' + appId1 ) ;
7021
+ app1 = firebase . initializeApp ( config3 , appId1 ) ;
7022
+ auth1 = app1 . auth ( ) ;
7023
+ pendingRedirectManager . setPendingStatus ( ) . then ( ( ) => {
7024
+ // Verify that the redirect result is resolved before signing out.
7025
+ const manager = fireauth . AuthEventManager . getManager (
7026
+ config3 [ 'authDomain' ] , config3 [ 'apiKey' ] , app1 . name ) ;
7027
+ return manager . getRedirectResult ( ) . then ( ( result ) => {
7028
+ // Expected result returned.
7029
+ assertObjectEquals ( expectedPopupResult , result ) ;
7030
+ return auth1 . signOut ( ) ;
7031
+ } ) . then ( ( ) => {
7032
+ // signOut should clear the cached redirect result.
7033
+ return auth1 . getRedirectResult ( ) ;
7034
+ } ) . then ( ( resultAfterClearing ) => {
7035
+ fireauth . common . testHelper . assertUserCredentialResponse (
7036
+ null , null , null , undefined , resultAfterClearing ) ;
7037
+ asyncTestCase . signal ( ) ;
7038
+ } ) ;
7039
+ } ) ;
7040
+ }
7041
+
7042
+
7043
+ function testAuth_signOut_clearErrorRedirectResult ( ) {
7044
+ // Tests getRedirectResult with error event after signOut being called.
7045
+ fireauth . AuthEventManager . ENABLED = true ;
7046
+ // The expected error.
7047
+ const expectedError =
7048
+ new fireauth . AuthError ( fireauth . authenum . Error . INTERNAL_ERROR ) ;
7049
+ // Expected sign in via redirect error Auth event.
7050
+ const expectedAuthEvent = new fireauth . AuthEvent (
7051
+ fireauth . AuthEvent . Type . SIGN_IN_VIA_REDIRECT ,
7052
+ null ,
7053
+ null ,
7054
+ null ,
7055
+ expectedError ) ;
7056
+ // Stub instantiateOAuthSignInHandler.
7057
+ stubs . replace (
7058
+ fireauth . AuthEventManager , 'instantiateOAuthSignInHandler' ,
7059
+ function ( authDomain , apiKey , appName ) {
7060
+ return {
7061
+ 'addAuthEventListener' : function ( handler ) {
7062
+ // auth1 should be subscribed.
7063
+ const manager = fireauth . AuthEventManager . getManager (
7064
+ config3 [ 'authDomain' ] , config3 [ 'apiKey' ] , app1 . name ) ;
7065
+ assertTrue ( manager . isSubscribed ( auth1 ) ) ;
7066
+ // In this case run immediately with expected redirect event.
7067
+ handler ( expectedAuthEvent ) ;
7068
+ asyncTestCase . signal ( ) ;
7069
+ } ,
7070
+ 'initializeAndWait' : function ( ) { return goog . Promise . resolve ( ) ; } ,
7071
+ 'shouldBeInitializedEarly' : function ( ) { return false ; } ,
7072
+ 'hasVolatileStorage' : function ( ) { return false ; }
7073
+ } ;
7074
+ } ) ;
7075
+ stubs . replace (
7076
+ fireauth . Auth . prototype ,
7077
+ 'finishPopupAndRedirectSignIn' ,
7078
+ function ( requestUri , sessionId , postBody ) {
7079
+ fail ( 'finishPopupAndRedirectSignIn should not run on event error!' ) ;
7080
+ } ) ;
7081
+ asyncTestCase . waitForSignals ( 2 ) ;
7082
+ const pendingRedirectManager = new fireauth . storage . PendingRedirectManager (
7083
+ config3 [ 'apiKey' ] + ':' + appId1 ) ;
7084
+ currentUserStorageManager = new fireauth . storage . UserManager (
7085
+ config3 [ 'apiKey' ] + ':' + appId1 ) ;
7086
+ app1 = firebase . initializeApp ( config3 , appId1 ) ;
7087
+ auth1 = app1 . auth ( ) ;
7088
+ pendingRedirectManager . setPendingStatus ( ) . then ( ( ) => {
7089
+ // Verify that the redirect result is rejected with error before
7090
+ // signing out.
7091
+ const manager = fireauth . AuthEventManager . getManager (
7092
+ config3 [ 'authDomain' ] , config3 [ 'apiKey' ] , app1 . name ) ;
7093
+ return manager . getRedirectResult ( ) . thenCatch ( ( error ) => {
7094
+ // Expected error returned.
7095
+ fireauth . common . testHelper . assertErrorEquals ( expectedError , error ) ;
7096
+ return auth1 . signOut ( ) ;
7097
+ } ) . then ( ( ) => {
7098
+ // signOut should clear the error in cached redirect result.
7099
+ return auth1 . getRedirectResult ( ) ;
7100
+ } ) . then ( ( resultAfterClearing ) => {
7101
+ fireauth . common . testHelper . assertUserCredentialResponse (
7102
+ null , null , null , undefined , resultAfterClearing ) ;
7103
+ asyncTestCase . signal ( ) ;
7104
+ } ) ;
7105
+ } ) . thenCatch ( ( error ) => {
7106
+ fail ( 'Redirect result should be cleared by signOut.' ) ;
7107
+ } ) ;
7108
+ }
7109
+
7110
+
6962
7111
function testAuth_returnFromSignInWithRedirect_success_withoutPostBody ( ) {
6963
7112
// Tests the return from a successful sign in with redirect.
6964
7113
fireauth . AuthEventManager . ENABLED = true ;
@@ -7025,6 +7174,11 @@ function testAuth_returnFromSignInWithRedirect_success_withoutPostBody() {
7025
7174
auth1 . getRedirectResult ( ) . then ( function ( result ) {
7026
7175
// Expected result returned.
7027
7176
assertObjectEquals ( expectedPopupResult , result ) ;
7177
+ // Redirect result should be cleared after being returned once.
7178
+ return auth1 . getRedirectResult ( ) ;
7179
+ } ) . then ( function ( resultAfterClearing ) {
7180
+ fireauth . common . testHelper . assertUserCredentialResponse (
7181
+ null , null , null , undefined , resultAfterClearing ) ;
7028
7182
asyncTestCase . signal ( ) ;
7029
7183
} ) ;
7030
7184
} ) ;
@@ -7114,6 +7268,11 @@ function testAuth_returnFromSignInWithRedirect_success_withPostBody() {
7114
7268
auth1 . getRedirectResult ( ) . then ( function ( result ) {
7115
7269
// Expected result returned.
7116
7270
assertObjectEquals ( expectedPopupResult , result ) ;
7271
+ // Redirect result should be cleared after being returned once.
7272
+ return auth1 . getRedirectResult ( ) ;
7273
+ } ) . then ( function ( resultAfterClearing ) {
7274
+ fireauth . common . testHelper . assertUserCredentialResponse (
7275
+ null , null , null , undefined , resultAfterClearing ) ;
7117
7276
asyncTestCase . signal ( ) ;
7118
7277
} ) ;
7119
7278
} ) ;
@@ -7226,6 +7385,11 @@ function testAuth_returnFromSignInWithRedirect_withExistingUser() {
7226
7385
// Newly signed in user.
7227
7386
assertEquals ( user1 , auth1 [ 'currentUser' ] ) ;
7228
7387
assertObjectEquals ( expectedPopupResult , result ) ;
7388
+ // Redirect result should be cleared after being returned once.
7389
+ return auth1 . getRedirectResult ( ) ;
7390
+ } ) . then ( function ( resultAfterClearing ) {
7391
+ fireauth . common . testHelper . assertUserCredentialResponse (
7392
+ null , null , null , undefined , resultAfterClearing ) ;
7229
7393
asyncTestCase . signal ( ) ;
7230
7394
} ) ;
7231
7395
// State listener should fire once only with the final redirected user.
@@ -7296,7 +7460,14 @@ function testAuth_returnFromSignInWithRedirect_error() {
7296
7460
// Get redirect result should return the expected error.
7297
7461
auth1 . getRedirectResult ( ) . thenCatch ( function ( error ) {
7298
7462
fireauth . common . testHelper . assertErrorEquals ( expectedError , error ) ;
7463
+ // Error in redirect result should be cleared after being returned once.
7464
+ return auth1 . getRedirectResult ( ) ;
7465
+ } ) . then ( function ( resultAfterClearing ) {
7466
+ fireauth . common . testHelper . assertUserCredentialResponse (
7467
+ null , null , null , undefined , resultAfterClearing ) ;
7299
7468
asyncTestCase . signal ( ) ;
7469
+ } ) . thenCatch ( function ( error ) {
7470
+ fail ( 'Error in event should only be thrown once.' ) ;
7300
7471
} ) ;
7301
7472
} ) ;
7302
7473
// State listener should fire once only with null user.
@@ -7365,6 +7536,12 @@ function testAuth_returnFromSignInWithRedirect_error_webStorageNotSupported() {
7365
7536
pendingRedirectManager . setPendingStatus ( ) . then ( function ( ) {
7366
7537
// Get redirect result should return the expected error.
7367
7538
auth1 . getRedirectResult ( ) . thenCatch ( function ( error ) {
7539
+ fireauth . common . testHelper . assertErrorEquals ( expectedError , error ) ;
7540
+ // Errors not being tied to a sign-in session should not be cleared.
7541
+ return auth1 . getRedirectResult ( ) ;
7542
+ } ) . then ( function ( result ) {
7543
+ fail ( 'Errors not being tied to a sign-in session should not be cleared.' ) ;
7544
+ } ) . thenCatch ( function ( error ) {
7368
7545
fireauth . common . testHelper . assertErrorEquals ( expectedError , error ) ;
7369
7546
asyncTestCase . signal ( ) ;
7370
7547
} ) ;
@@ -7535,6 +7712,11 @@ function testAuth_returnFromLinkWithRedirect_success_withoutPostBody() {
7535
7712
// Get redirect result should resolve with expected user and credential.
7536
7713
auth1 . getRedirectResult ( ) . then ( function ( result ) {
7537
7714
assertObjectEquals ( expectedPopupResult , result ) ;
7715
+ // Redirect result should be cleared after being returned once.
7716
+ return auth1 . getRedirectResult ( ) ;
7717
+ } ) . then ( function ( resultAfterClearing ) {
7718
+ fireauth . common . testHelper . assertUserCredentialResponse (
7719
+ null , null , null , undefined , resultAfterClearing ) ;
7538
7720
asyncTestCase . signal ( ) ;
7539
7721
} ) ;
7540
7722
// Should fire once only with the final redirected user.
@@ -7636,6 +7818,11 @@ function testAuth_returnFromLinkWithRedirect_success_withPostBody() {
7636
7818
// Get redirect result should resolve with expected user and credential.
7637
7819
auth1 . getRedirectResult ( ) . then ( function ( result ) {
7638
7820
assertObjectEquals ( expectedPopupResult , result ) ;
7821
+ // Redirect result should be cleared after being returned once.
7822
+ return auth1 . getRedirectResult ( ) ;
7823
+ } ) . then ( function ( resultAfterClearing ) {
7824
+ fireauth . common . testHelper . assertUserCredentialResponse (
7825
+ null , null , null , undefined , resultAfterClearing ) ;
7639
7826
asyncTestCase . signal ( ) ;
7640
7827
} ) ;
7641
7828
// Should fire once only with the final redirected user.
@@ -7779,6 +7966,11 @@ function testAuth_returnFromLinkWithRedirect_redirectedLoggedOutUser_success() {
7779
7966
assertEquals ( 'fr' , result . user . getLanguageCode ( ) ) ;
7780
7967
auth1 . languageCode = 'de' ;
7781
7968
assertEquals ( 'de' , result . user . getLanguageCode ( ) ) ;
7969
+ // Redirect result should be cleared after being returned once.
7970
+ return auth1 . getRedirectResult ( ) ;
7971
+ } ) . then ( function ( resultAfterClearing ) {
7972
+ fireauth . common . testHelper . assertUserCredentialResponse (
7973
+ null , null , null , undefined , resultAfterClearing ) ;
7782
7974
asyncTestCase . signal ( ) ;
7783
7975
} ) ;
7784
7976
// Should fire once only with the original user.
@@ -7889,6 +8081,11 @@ function testAuth_redirectedLoggedOutUser_differentAuthDomain() {
7889
8081
assertEquals ( 'fr' , result . user . getLanguageCode ( ) ) ;
7890
8082
auth1 . languageCode = 'de' ;
7891
8083
assertEquals ( 'de' , result . user . getLanguageCode ( ) ) ;
8084
+ // Redirect result should be cleared after being returned once.
8085
+ return auth1 . getRedirectResult ( ) ;
8086
+ } ) . then ( function ( resultAfterClearing ) {
8087
+ fireauth . common . testHelper . assertUserCredentialResponse (
8088
+ null , null , null , undefined , resultAfterClearing ) ;
7892
8089
asyncTestCase . signal ( ) ;
7893
8090
} ) ;
7894
8091
// Should fire once only with null user.
@@ -8014,6 +8211,11 @@ function testAuth_returnFromLinkWithRedirect_noCurrentUser_redirectUser() {
8014
8211
assertEquals ( 'fr' , result . user . getLanguageCode ( ) ) ;
8015
8212
auth1 . languageCode = 'de' ;
8016
8213
assertEquals ( 'de' , result . user . getLanguageCode ( ) ) ;
8214
+ // Redirect result should be cleared after being returned once.
8215
+ return auth1 . getRedirectResult ( ) ;
8216
+ } ) . then ( function ( resultAfterClearing ) {
8217
+ fireauth . common . testHelper . assertUserCredentialResponse (
8218
+ null , null , null , undefined , resultAfterClearing ) ;
8017
8219
asyncTestCase . signal ( ) ;
8018
8220
} ) ;
8019
8221
// Should fire once only with null user.
@@ -8217,6 +8419,11 @@ function testAuth_returnFromLinkWithRedirect_redirectedLoggedInUser_success() {
8217
8419
// operationType not implemented yet.
8218
8420
fireauth . constants . OperationType . SIGN_IN ,
8219
8421
result ) ;
8422
+ // Redirect result should be cleared after being returned once.
8423
+ return auth1 . getRedirectResult ( ) ;
8424
+ } ) . then ( function ( resultAfterClearing ) {
8425
+ fireauth . common . testHelper . assertUserCredentialResponse (
8426
+ null , null , null , undefined , resultAfterClearing ) ;
8220
8427
asyncTestCase . signal ( ) ;
8221
8428
} ) ;
8222
8429
// Should fire once only with redirected user.
@@ -8402,7 +8609,14 @@ function testAuth_returnFromLinkWithRedirect_error() {
8402
8609
// Get redirect result should contain an error.
8403
8610
auth1 . getRedirectResult ( ) . thenCatch ( function ( error ) {
8404
8611
fireauth . common . testHelper . assertErrorEquals ( expectedError , error ) ;
8612
+ // Error in redirect result should be cleared after being returned once.
8613
+ return auth1 . getRedirectResult ( ) ;
8614
+ } ) . then ( function ( resultAfterClearing ) {
8615
+ fireauth . common . testHelper . assertUserCredentialResponse (
8616
+ null , null , null , undefined , resultAfterClearing ) ;
8405
8617
asyncTestCase . signal ( ) ;
8618
+ } ) . thenCatch ( function ( error ) {
8619
+ fail ( 'Error in event should only be thrown once.' ) ;
8406
8620
} ) ;
8407
8621
// Should fire once only with original user1.
8408
8622
var idTokenChangeCounter = 0 ;
0 commit comments