Bug 999190 - Part 2 - Listen to logout commands from fxa remote server. r=markh

This commit is contained in:
Edouard Oger 2015-09-01 11:42:00 +02:00
parent 8a2fe56063
commit d673507ada
4 changed files with 155 additions and 0 deletions

View File

@ -21,6 +21,12 @@
case "can_link_account":
test_can_link_account();
break;
case "logout":
test_logout();
break;
case "delete":
test_delete();
break;
}
};
@ -93,6 +99,40 @@
window.dispatchEvent(event);
}
function test_logout() {
var event = new window.CustomEvent("WebChannelMessageToChrome", {
detail: {
id: webChannelId,
message: {
command: "fxaccounts:logout",
data: {
uid: 'uid'
},
messageId: 3,
},
},
});
window.dispatchEvent(event);
}
function test_delete() {
var event = new window.CustomEvent("WebChannelMessageToChrome", {
detail: {
id: webChannelId,
message: {
command: "fxaccounts:delete",
data: {
uid: 'uid'
},
messageId: 4,
},
},
});
window.dispatchEvent(event);
}
</script>
</body>
</html>

View File

@ -120,6 +120,62 @@ let gTests = [
yield promiseEcho;
});
}
},
{
desc: "fxa web channel - logout messages should notify the fxAccounts object",
run: function* () {
let promiseLogout = new Promise((resolve, reject) => {
let logout = (uid) => {
Assert.equal(uid, 'uid');
client.tearDown();
resolve();
};
let client = new FxAccountsWebChannel({
content_uri: TEST_HTTP_PATH,
channel_id: TEST_CHANNEL_ID,
helpers: {
logout: logout
}
});
});
yield BrowserTestUtils.withNewTab({
gBrowser: gBrowser,
url: TEST_BASE_URL + "?logout"
}, function* () {
yield promiseLogout;
});
}
},
{
desc: "fxa web channel - delete messages should notify the fxAccounts object",
run: function* () {
let promiseDelete = new Promise((resolve, reject) => {
let logout = (uid) => {
Assert.equal(uid, 'uid');
client.tearDown();
resolve();
};
let client = new FxAccountsWebChannel({
content_uri: TEST_HTTP_PATH,
channel_id: TEST_CHANNEL_ID,
helpers: {
logout: logout
}
});
});
yield BrowserTestUtils.withNewTab({
gBrowser: gBrowser,
url: TEST_BASE_URL + "?delete"
}, function* () {
yield promiseDelete;
});
}
}
]; // gTests

View File

@ -26,6 +26,8 @@ XPCOMUtils.defineLazyModuleGetter(this, "fxAccounts",
const COMMAND_PROFILE_CHANGE = "profile:change";
const COMMAND_CAN_LINK_ACCOUNT = "fxaccounts:can_link_account";
const COMMAND_LOGIN = "fxaccounts:login";
const COMMAND_LOGOUT = "fxaccounts:logout";
const COMMAND_DELETE = "fxaccounts:delete";
const PREF_LAST_FXA_USER = "identity.fxaccounts.lastSignedInUserHash";
const PREF_SYNC_SHOW_CUSTOMIZATION = "services.sync-setup.ui.showCustomizationDialog";
@ -145,6 +147,10 @@ this.FxAccountsWebChannel.prototype = {
case COMMAND_LOGIN:
this._helpers.login(data);
break;
case COMMAND_LOGOUT:
case COMMAND_DELETE:
this._helpers.logout(data.uid);
break;
case COMMAND_CAN_LINK_ACCOUNT:
let canLinkAccount = this._helpers.shouldAllowRelink(data.email);
@ -232,6 +238,19 @@ this.FxAccountsWebChannelHelpers.prototype = {
});
},
/**
* logoust the fxaccounts service
*
* @param the uid of the account which have been logged out
*/
logout(uid) {
return fxAccounts.getSignedInUser().then(userData => {
if (userData.uid === uid) {
return fxAccounts.signOut();
}
});
},
/**
* Get the hash of account name of the previously signed in account
*/

View File

@ -77,6 +77,46 @@ add_test(function test_login_message() {
channel._channelCallback(WEBCHANNEL_ID, mockMessage, mockSendingContext);
});
add_test(function test_logout_message() {
let mockMessage = {
command: 'fxaccounts:logout',
data: { uid: "foo" }
};
let channel = new FxAccountsWebChannel({
channel_id: WEBCHANNEL_ID,
content_uri: URL_STRING,
helpers: {
logout: function (uid) {
do_check_eq(uid, 'foo');
run_next_test();
}
}
});
channel._channelCallback(WEBCHANNEL_ID, mockMessage, mockSendingContext);
});
add_test(function test_delete_message() {
let mockMessage = {
command: 'fxaccounts:delete',
data: { uid: "foo" }
};
let channel = new FxAccountsWebChannel({
channel_id: WEBCHANNEL_ID,
content_uri: URL_STRING,
helpers: {
logout: function (uid) {
do_check_eq(uid, 'foo');
run_next_test();
}
}
});
channel._channelCallback(WEBCHANNEL_ID, mockMessage, mockSendingContext);
});
add_test(function test_can_link_account_message() {
let mockMessage = {
command: 'fxaccounts:can_link_account',