Bug 1204714 - Open Sync Preferences from Firefox Accounts. r=markh
authorShane Tomlinson <stomlinson@mozilla.com>
Thu, 07 Jan 2016 21:41:46 +0000
changeset 281360 f1573412a4adaa48a1b955a0ecf4f2908381374c
parent 281359 819fff092e3df644b03575577fd68af89dbbdf13
child 281361 1cf358aab01b00bd6e04c492c1a604548063ea19
push id29935
push userphilringnalda@gmail.com
push dateSun, 24 Jan 2016 02:12:02 +0000
treeherdermozilla-central@a2e81822194a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmarkh
bugs1204714
milestone46.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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.
browser/app/profile/firefox.js
services/fxaccounts/FxAccountsWebChannel.jsm
services/fxaccounts/tests/xpcshell/test_web_channel.js
--- a/browser/app/profile/firefox.js
+++ b/browser/app/profile/firefox.js
@@ -1446,24 +1446,24 @@ pref("network.disable.ipc.security", tru
 
 // CustomizableUI debug logging.
 pref("browser.uiCustomization.debug", false);
 
 // CustomizableUI state of the browser's user interface
 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/");
 
 // The URL we take the user to when they opt to "manage" their Firefox Account.
 // Note that this will always need to be in the same TLD as the
 // "identity.fxaccounts.remote.signup.uri" pref.
 pref("identity.fxaccounts.settings.uri", "https://accounts.firefox.com/settings");
--- a/services/fxaccounts/FxAccountsWebChannel.jsm
+++ b/services/fxaccounts/FxAccountsWebChannel.jsm
@@ -25,16 +25,17 @@ XPCOMUtils.defineLazyModuleGetter(this, 
 XPCOMUtils.defineLazyModuleGetter(this, "Weave",
                                   "resource://services-sync/main.js");
 
 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 COMMAND_SYNC_PREFERENCES     = "fxaccounts:sync_preferences";
 
 const PREF_LAST_FXA_USER           = "identity.fxaccounts.lastSignedInUserHash";
 const PREF_SYNC_SHOW_CUSTOMIZATION = "services.sync-setup.ui.showCustomizationDialog";
 
 /**
  * Create a new FxAccountsWebChannel to listen for account updates
  *
  * @param {Object} options Options
@@ -163,16 +164,19 @@ this.FxAccountsWebChannel.prototype = {
               command: command,
               messageId: message.messageId,
               data: { ok: canLinkAccount }
             };
 
             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;
         }
       }
     };
 
     this._channelCallback = listener;
@@ -307,16 +311,32 @@ this.FxAccountsWebChannelHelpers.prototy
                    .createInstance(Ci.nsICryptoHash);
     hasher.init(hasher.SHA256);
     hasher.update(data, data.length);
 
     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
    * if they want to continue.
    *
    * @private
    */
   _needRelinkWarning(acctName) {
     let prevAcctHash = this.getPreviousAccountNameHashPref();
--- a/services/fxaccounts/tests/xpcshell/test_web_channel.js
+++ b/services/fxaccounts/tests/xpcshell/test_web_channel.js
@@ -132,16 +132,37 @@ add_test(function test_can_link_account_
         run_next_test();
       }
     }
   });
 
   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',
     data: {}
   };
 
   let channel = new FxAccountsWebChannel({
     channel_id: WEBCHANNEL_ID,
@@ -277,16 +298,32 @@ add_test(function test_helpers_login_wit
   helpers.login({
     email: 'testuser@testuser.com',
     verifiedCanLinkAccount: true,
     customizeSync: true,
     declinedSyncEngines: ['addons', 'prefs']
   });
 });
 
+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();
 }
 
 function makeObserver(aObserveTopic, aObserveFunc) {
   let callback = function (aSubject, aTopic, aData) {
     log.debug("observed " + aTopic + " " + aData);
     if (aTopic == aObserveTopic) {