Bug 1385191 - Prefer email address from the FxA profile over that from the account. r=eoger

MozReview-Commit-ID: 78U2RZQ5xfB

--HG--
extra : rebase_source : b79b18ea8c545003998692cd97c7ad5d6606c7f7
This commit is contained in:
Mark Hammond 2017-07-28 16:35:40 +10:00
Родитель 1914870141
Коммит 8d2320d13f
4 изменённых файлов: 43 добавлений и 1 удалений

Просмотреть файл

@ -319,6 +319,13 @@ var gSyncPane = {
}).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;

Просмотреть файл

@ -314,6 +314,13 @@ var gSyncPane = {
}).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;

Просмотреть файл

@ -161,6 +161,9 @@ const UIStateInternal = {
_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() {

Просмотреть файл

@ -53,7 +53,7 @@ add_task(async function test_refreshState_signedin() {
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();
@ -68,6 +68,31 @@ add_task(async function test_refreshState_signedin() {
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;