Bug 1385191 - Prefer email address from the FxA profile over that from the account. r?eoger draft
authorMark Hammond <mhammond@skippinet.com.au>
Fri, 28 Jul 2017 16:35:40 +1000
changeset 617225 f7d813fa992b360d547600e99385652b3f7439a2
parent 617159 556f19ef392ac2d9aac579864e2179d6c1d464e8
child 639758 a1345d719462cdc1947ae95904074bc049b48f2a
push id70991
push userbmo:markh@mozilla.com
push dateFri, 28 Jul 2017 06:37:04 +0000
reviewerseoger
bugs1385191
milestone56.0a1
Bug 1385191 - Prefer email address from the FxA profile over that from the account. r?eoger MozReview-Commit-ID: 78U2RZQ5xfB
browser/components/preferences/in-content-new/sync.js
browser/components/preferences/in-content/sync.js
services/sync/modules/UIState.jsm
services/sync/tests/unit/test_uistate.js
--- a/browser/components/preferences/in-content-new/sync.js
+++ b/browser/components/preferences/in-content-new/sync.js
@@ -314,16 +314,23 @@ var gSyncPane = {
     }).then(isVerified => {
       if (isVerified) {
         return fxAccounts.getSignedInUserProfile();
       }
       return null;
     }).then(data => {
       let fxaLoginStatus = document.getElementById("fxaLoginStatus");
       if (data) {
+        if (data.email) {
+          // A hack to handle that the user's email address may have changed.
+          // This can probably be removed as part of bug 1383663.
+          fxaEmailAddress1Label.textContent = data.email;
+          document.getElementById("fxaEmailAddress2").textContent = data.email;
+          document.getElementById("fxaEmailAddress3").textContent = data.email;
+        }
         if (data.displayName) {
           fxaLoginStatus.setAttribute("hasName", true);
           displayNameLabel.hidden = false;
           displayNameLabel.textContent = data.displayName;
         } else {
           fxaLoginStatus.removeAttribute("hasName");
         }
         if (data.avatar) {
--- a/browser/components/preferences/in-content/sync.js
+++ b/browser/components/preferences/in-content/sync.js
@@ -309,16 +309,23 @@ var gSyncPane = {
     }).then(isVerified => {
       if (isVerified) {
         return fxAccounts.getSignedInUserProfile();
       }
       return null;
     }).then(data => {
       let fxaLoginStatus = document.getElementById("fxaLoginStatus");
       if (data) {
+        if (data.email) {
+          // A hack to handle that the user's email address may have changed.
+          // This can probably be removed as part of bug 1383663.
+          fxaEmailAddress1Label.textContent = data.email;
+          document.getElementById("fxaEmailAddress2").textContent = data.email;
+          document.getElementById("fxaEmailAddress3").textContent = data.email;
+        }
         if (data.displayName) {
           fxaLoginStatus.setAttribute("hasName", true);
           displayNameLabel.hidden = false;
           displayNameLabel.textContent = data.displayName;
         } else {
           fxaLoginStatus.removeAttribute("hasName");
         }
         if (data.avatar) {
--- a/services/sync/modules/UIState.jsm
+++ b/services/sync/modules/UIState.jsm
@@ -156,16 +156,19 @@ const UIStateInternal = {
       state.email = userData.email;
     }
     state.status = status;
   },
 
   _populateWithProfile(state, profile) {
     state.displayName = profile.displayName;
     state.avatarURL = profile.avatar;
+    // A hack to handle that the user's email address may have changed.
+    // This can probably be removed as part of bug 1383663.
+    state.email = profile.email;
   },
 
   async _getUserData() {
     try {
       return await this.fxAccounts.getSignedInUser();
     } catch (e) {
       // This is most likely in tests, where we quickly log users in and out.
       // The most likely scenario is a user logged out, so reflect that.
--- a/services/sync/tests/unit/test_uistate.js
+++ b/services/sync/tests/unit/test_uistate.js
@@ -48,31 +48,56 @@ add_task(async function test_refreshStat
   const fxAccountsOrig = UIStateInternal.fxAccounts;
 
   const now = new Date().toString();
   Services.prefs.setCharPref("services.sync.lastSync", now);
   UIStateInternal.syncing = false;
 
   UIStateInternal.fxAccounts = {
     getSignedInUser: () => Promise.resolve({ verified: true, email: "foo@bar.com" }),
-    getSignedInUserProfile: () => Promise.resolve({ displayName: "Foo Bar", avatar: "https://foo/bar" })
+    getSignedInUserProfile: () => Promise.resolve({ displayName: "Foo Bar", avatar: "https://foo/bar", email: "foo@bar.com" })
   }
 
   let state = await UIState.refresh();
 
   equal(state.status, UIState.STATUS_SIGNED_IN);
   equal(state.email, "foo@bar.com");
   equal(state.displayName, "Foo Bar");
   equal(state.avatarURL, "https://foo/bar");
   equal(state.lastSync, now);
   equal(state.syncing, false);
 
   UIStateInternal.fxAccounts = fxAccountsOrig;
 });
 
+add_task(async function test_refreshState_preferProfileEmail() {
+  UIState.reset();
+  const fxAccountsOrig = UIStateInternal.fxAccounts;
+
+  const now = new Date().toString();
+  Services.prefs.setCharPref("services.sync.lastSync", now);
+  UIStateInternal.syncing = false;
+
+  UIStateInternal.fxAccounts = {
+    getSignedInUser: () => Promise.resolve({ verified: true, email: "foo@bar.com" }),
+    getSignedInUserProfile: () => Promise.resolve({ displayName: "Foo Bar", avatar: "https://foo/bar", email: "bar@foo.com" })
+  }
+
+  let state = await UIState.refresh();
+
+  equal(state.status, UIState.STATUS_SIGNED_IN);
+  equal(state.email, "bar@foo.com");
+  equal(state.displayName, "Foo Bar");
+  equal(state.avatarURL, "https://foo/bar");
+  equal(state.lastSync, now);
+  equal(state.syncing, false);
+
+  UIStateInternal.fxAccounts = fxAccountsOrig;
+});
+
 add_task(async function test_refreshState_signedin_profile_unavailable() {
   UIState.reset();
   const fxAccountsOrig = UIStateInternal.fxAccounts;
 
   const now = new Date().toString();
   Services.prefs.setCharPref("services.sync.lastSync", now);
   UIStateInternal.syncing = false;