Bug 1204714 - Open Sync Preferences from Firefox Accounts. r=markh

Listen for an |fxaccounts:sync_preferences| WebChannel message. Open
about:preferences#sync in the tab that sent the message.
This commit is contained in:
Shane Tomlinson 2016-01-07 21:41:46 +00:00
parent bf9d5fa2da
commit 56bf427a72
3 changed files with 60 additions and 3 deletions

View File

@ -1451,14 +1451,14 @@ pref("browser.uiCustomization.debug", false);
pref("browser.uiCustomization.state", "");
// The remote content URL shown for FxA signup. Must use HTTPS.
pref("identity.fxaccounts.remote.signup.uri", "https://accounts.firefox.com/signup?service=sync&context=fx_desktop_v2");
pref("identity.fxaccounts.remote.signup.uri", "https://accounts.firefox.com/signup?service=sync&context=fx_desktop_v3");
// The URL where remote content that forces re-authentication for Firefox Accounts
// should be fetched. Must use HTTPS.
pref("identity.fxaccounts.remote.force_auth.uri", "https://accounts.firefox.com/force_auth?service=sync&context=fx_desktop_v2");
pref("identity.fxaccounts.remote.force_auth.uri", "https://accounts.firefox.com/force_auth?service=sync&context=fx_desktop_v3");
// The remote content URL shown for signin in. Must use HTTPS.
pref("identity.fxaccounts.remote.signin.uri", "https://accounts.firefox.com/signin?service=sync&context=fx_desktop_v2");
pref("identity.fxaccounts.remote.signin.uri", "https://accounts.firefox.com/signin?service=sync&context=fx_desktop_v3");
// The remote content URL where FxAccountsWebChannel messages originate.
pref("identity.fxaccounts.remote.webchannel.uri", "https://accounts.firefox.com/");

View File

@ -30,6 +30,7 @@ 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 COMMAND_SYNC_PREFERENCES = "fxaccounts:sync_preferences";
const PREF_LAST_FXA_USER = "identity.fxaccounts.lastSignedInUserHash";
const PREF_SYNC_SHOW_CUSTOMIZATION = "services.sync-setup.ui.showCustomizationDialog";
@ -168,6 +169,9 @@ this.FxAccountsWebChannel.prototype = {
log.debug("FxAccountsWebChannel response", response);
this._channel.send(response, sendingContext);
break;
case COMMAND_SYNC_PREFERENCES:
this._helpers.openSyncPreferences(sendingContext.browser, data.entryPoint);
break;
default:
log.warn("Unrecognized FxAccountsWebChannel command", command);
break;
@ -311,6 +315,22 @@ this.FxAccountsWebChannelHelpers.prototype = {
return hasher.finish(true);
},
/**
* Open Sync Preferences in the current tab of the browser
*
* @param {Object} browser the browser in which to open preferences
* @param {String} [entryPoint] entryPoint to use for logging
*/
openSyncPreferences(browser, entryPoint) {
let uri = "about:preferences";
if (entryPoint) {
uri += "?entrypoint=" + encodeURIComponent(entryPoint);
}
uri += "#sync";
browser.loadURI(uri);
},
/**
* If a user signs in using a different account, the data from the
* previous account and the new account will be merged. Ask the user

View File

@ -137,6 +137,27 @@ add_test(function test_can_link_account_message() {
channel._channelCallback(WEBCHANNEL_ID, mockMessage, mockSendingContext);
});
add_test(function test_sync_preferences_message() {
let mockMessage = {
command: 'fxaccounts:sync_preferences',
data: { entryPoint: 'fxa:verification_complete' }
};
let channel = new FxAccountsWebChannel({
channel_id: WEBCHANNEL_ID,
content_uri: URL_STRING,
helpers: {
openSyncPreferences: function (browser, entryPoint) {
do_check_eq(entryPoint, 'fxa:verification_complete');
do_check_eq(browser, mockSendingContext.browser);
run_next_test();
}
}
});
channel._channelCallback(WEBCHANNEL_ID, mockMessage, mockSendingContext);
});
add_test(function test_unrecognized_message() {
let mockMessage = {
command: 'fxaccounts:unrecognized',
@ -282,6 +303,22 @@ add_test(function test_helpers_login_with_customize_sync_and_declined_engines()
});
});
add_test(function test_helpers_open_sync_preferences() {
let helpers = new FxAccountsWebChannelHelpers({
fxAccounts: {
}
});
let mockBrowser = {
loadURI(uri) {
do_check_eq(uri, "about:preferences?entrypoint=fxa%3Averification_complete#sync");
run_next_test();
}
};
helpers.openSyncPreferences(mockBrowser, "fxa:verification_complete");
});
function run_test() {
run_next_test();
}