Bug 989549 - Call signOut() in FxAccountsClient.jsm from signOut() in FxAccounts.jsm. r=markh

This commit is contained in:
Chris Karlof 2014-04-09 16:14:19 -07:00
parent 2d3dc71207
commit 9bc6ab6d2a
2 changed files with 61 additions and 3 deletions

View File

@ -460,9 +460,26 @@ FxAccountsInternal.prototype = {
},
signOut: function signOut() {
this.abortExistingFlow();
this.currentAccountState.signedInUser = null; // clear in-memory cache
return this.signedInUserStorage.set(null).then(() => {
let currentState = this.currentAccountState;
let fxAccountsClient = this.fxAccountsClient;
let sessionToken;
return currentState.getUserAccountData().then(data => {
// Save the session token for use in the call to signOut below.
sessionToken = data && data.sessionToken;
this.abortExistingFlow();
this.currentAccountState.signedInUser = null; // clear in-memory cache
return this.signedInUserStorage.set(null);
}).then(() => {
// Wrap this in a promise so *any* errors in signOut won't
// block the local sign out. This is *not* returned.
Promise.resolve().then(() => {
// This can happen in the background and shouldn't block
// the user from signing out. The server must tolerate
// clients just disappearing, so this call should be best effort.
return fxAccountsClient.signOut(sessionToken);
}).then(null, err => {
log.error("Error during remote sign out of Firefox Accounts: " + err);
});
this.notifyObservers(ONLOGOUT_NOTIFICATION);
});
},

View File

@ -77,6 +77,8 @@ function MockFxAccountsClient() {
this.signCertificate = function() { throw "no" };
this.signOut = function() { return Promise.resolve(); };
FxAccountsClient.apply(this);
}
MockFxAccountsClient.prototype = {
@ -537,6 +539,45 @@ add_test(function test_resend_email() {
});
});
add_test(function test_sign_out() {
do_test_pending();
let fxa = new MockFxAccounts();
let remoteSignOutCalled = false;
let client = fxa.internal.fxAccountsClient;
client.signOut = function() { remoteSignOutCalled = true; return Promise.resolve(); };
makeObserver(ONLOGOUT_NOTIFICATION, function() {
log.debug("test_sign_out_with_remote_error observed onlogout");
// user should be undefined after sign out
fxa.internal.getUserAccountData().then(user => {
do_check_eq(user, null);
do_check_true(remoteSignOutCalled);
do_test_finished();
run_next_test();
});
});
fxa.signOut();
});
add_test(function test_sign_out_with_remote_error() {
do_test_pending();
let fxa = new MockFxAccounts();
let client = fxa.internal.fxAccountsClient;
let remoteSignOutCalled = false;
// Force remote sign out to trigger an error
client.signOut = function() { remoteSignOutCalled = true; throw "Remote sign out error"; };
makeObserver(ONLOGOUT_NOTIFICATION, function() {
log.debug("test_sign_out_with_remote_error observed onlogout");
// user should be undefined after sign out
fxa.internal.getUserAccountData().then(user => {
do_check_eq(user, null);
do_check_true(remoteSignOutCalled);
do_test_finished();
run_next_test();
});
});
fxa.signOut();
});
/*
* End of tests.
* Utility functions follow.