diff --git a/services/fxaccounts/FxAccountsManager.jsm b/services/fxaccounts/FxAccountsManager.jsm index a293b412e111..b3b69896cb66 100644 --- a/services/fxaccounts/FxAccountsManager.jsm +++ b/services/fxaccounts/FxAccountsManager.jsm @@ -249,11 +249,11 @@ this.FxAccountsManager = { getAccount: function() { // We check first if we have session details cached. if (this._activeSession) { - // If our cache says that the account is not yet verified, we check that - // this information is correct, and update the cached data if not. + // If our cache says that the account is not yet verified, + // we kick off verification before returning what we have. if (this._activeSession && !this._activeSession.verified && !Services.io.offline) { - return this.verificationStatus(this._activeSession); + this.verificationStatus(this._activeSession); } log.debug("Account " + JSON.stringify(this._user)); @@ -270,11 +270,10 @@ this.FxAccountsManager = { this._activeSession = user; // If we get a stored information of a not yet verified account, - // we check this information with the server, update the stored - // data if needed and finally return the account details. + // we kick off verification before returning what we have. if (!user.verified && !Services.io.offline) { log.debug("Unverified account"); - return this.verificationStatus(user); + this.verificationStatus(user); } log.debug("Account " + JSON.stringify(this._user)); @@ -315,44 +314,35 @@ this.FxAccountsManager = { verificationStatus: function() { log.debug("verificationStatus"); if (!this._activeSession || !this._activeSession.sessionToken) { - return this._error(ERROR_NO_TOKEN_SESSION); + this._error(ERROR_NO_TOKEN_SESSION); } // There is no way to unverify an already verified account, so we just // return the account details of a verified account if (this._activeSession.verified) { log.debug("Account already verified"); - return Promise.resolve(this._user); + return; } if (Services.io.offline) { - return this._error(ERROR_OFFLINE); + this._error(ERROR_OFFLINE); } let client = this._getFxAccountsClient(); - return client.recoveryEmailStatus(this._activeSession.sessionToken).then( + client.recoveryEmailStatus(this._activeSession.sessionToken).then( data => { let error = this._getError(data); if (error) { - return this._error(error, data); + this._error(error, data); } - - // If the verification status is different from the one that we have - // stored, we update it and return the session data. If not, we simply - // return the session data. + // If the verification status has changed, update state. if (this._activeSession.verified != data.verified) { this._activeSession.verified = data.verified; - return this._fxAccounts.setSignedInUser(this._activeSession).then( - () => { - log.debug(JSON.stringify(this._user)); - return Promise.resolve(this._user); - } - ); + this._fxAccounts.setSignedInUser(this._activeSession); } log.debug(JSON.stringify(this._user)); - return Promise.resolve(this._user); }, - reason => { return this._serverError(reason); } + reason => { this._serverError(reason); } ); }, @@ -415,7 +405,7 @@ this.FxAccountsManager = { log.debug("No signed in user"); - if (aOptions.silent) { + if (aOptions && aOptions.silent) { return Promise.resolve(null); } diff --git a/services/fxaccounts/tests/xpcshell/test_manager.js b/services/fxaccounts/tests/xpcshell/test_manager.js index 77a83ba8d7a8..22b7ff6db914 100644 --- a/services/fxaccounts/tests/xpcshell/test_manager.js +++ b/services/fxaccounts/tests/xpcshell/test_manager.js @@ -445,18 +445,17 @@ add_test(function(test_getAccount_existing_unverified_session_verified_user) { FxAccountsManager._activeSession.verified = false; FxAccountsManager._fxAccounts._signedInUser.verified = false; FakeFxAccountsClient._verified = true; - FxAccountsManager.getAccount().then( - result => { - do_check_true(FakeFxAccountsClient._recoveryEmailStatusCalled); - do_check_true(result.verified); - do_check_eq(result.accountId, FxAccountsManager._user.accountId); - FakeFxAccountsClient._reset(); - run_next_test(); - }, - error => { - do_throw("Unexpected error: " + error); - } - ); + FxAccountsManager.getAccount(); + do_execute_soon(function() { + do_check_true(FakeFxAccountsClient._recoveryEmailStatusCalled); + FxAccountsManager.getAccount().then( + result => { + do_check_true(result.verified); + do_check_eq(result.accountId, FxAccountsManager._user.accountId); + FakeFxAccountsClient._reset(); + run_next_test(); + }); + }); }); add_test(function(test_signOut) { @@ -475,20 +474,6 @@ add_test(function(test_signOut) { ); }); -add_test(function(test_verificationStatus_no_token_session) { - do_print("= verificationStatus, no token session ="); - do_check_null(FxAccountsManager._activeSession); - FxAccountsManager.verificationStatus().then( - () => { - do_throw("Unexpected success"); - }, - error => { - do_check_eq(error.error, ERROR_NO_TOKEN_SESSION); - run_next_test(); - } - ); -}); - add_test(function(test_signUp_no_accountId) { do_print("= signUp, no accountId="); FxAccountsManager.signUp().then( @@ -598,33 +583,27 @@ add_test(function(test_signIn_already_signed_user) { add_test(function(test_verificationStatus_unverified_session_unverified_user) { do_print("= verificationStatus unverified session and user ="); FakeFxAccountsClient._verified = false; - FxAccountsManager.verificationStatus().then( - user => { - do_check_false(user.verified); - do_check_true(FakeFxAccountsClient._recoveryEmailStatusCalled); - do_check_false(FxAccountsManager._fxAccounts._setSignedInUserCalled); - run_next_test(); - }, - error => { - do_throw("Unexpected error: " + error); - } - ); + FxAccountsManager.verificationStatus(); + do_execute_soon(function() { + let user = FxAccountsManager._user; + do_check_false(user.verified); + do_check_true(FakeFxAccountsClient._recoveryEmailStatusCalled); + do_check_false(FxAccountsManager._fxAccounts._setSignedInUserCalled); + run_next_test(); + }); }); add_test(function(test_verificationStatus_unverified_session_verified_user) { do_print("= verificationStatus unverified session, verified user ="); FakeFxAccountsClient._verified = true; - FxAccountsManager.verificationStatus().then( - user => { - do_check_true(user.verified); - do_check_true(FakeFxAccountsClient._recoveryEmailStatusCalled); - do_check_true(FxAccountsManager._fxAccounts._setSignedInUserCalled); - run_next_test(); - }, - error => { - do_throw("Unexpected error: " + error); - } - ); + FxAccountsManager.verificationStatus(); + do_execute_soon(function() { + let user = FxAccountsManager._user; + do_check_true(user.verified); + do_check_true(FakeFxAccountsClient._recoveryEmailStatusCalled); + do_check_true(FxAccountsManager._fxAccounts._setSignedInUserCalled); + run_next_test(); + }); }); add_test(function(test_queryAccount_no_exists) {