зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1374501 - Allow extra sync engines to be activited using FxA Web Channels. r=markh,stomlinson
MozReview-Commit-ID: HykDad81Ifh --HG-- extra : rebase_source : d07f048b5f96e7fa9b1fc7130b4f518ac5527075
This commit is contained in:
Родитель
eaddafd020
Коммит
58f16ee440
|
@ -38,6 +38,11 @@ const COMMAND_FXA_STATUS = "fxaccounts:fxa_status";
|
|||
|
||||
const PREF_LAST_FXA_USER = "identity.fxaccounts.lastSignedInUserHash";
|
||||
|
||||
// These engines were added years after Sync had been introduced, they need
|
||||
// special handling since they are system add-ons and are un-available on
|
||||
// older versions of Firefox.
|
||||
const EXTRA_ENGINES = ["addresses", "creditcards"];
|
||||
|
||||
/**
|
||||
* A helper function that extracts the message and stack from an error object.
|
||||
* Returns a `{ message, stack }` tuple. `stack` will be null if the error
|
||||
|
@ -280,6 +285,17 @@ this.FxAccountsWebChannelHelpers.prototype = {
|
|||
// the browser to selecte the engines to sync but we do it on the web now.
|
||||
delete accountData.customizeSync;
|
||||
|
||||
if (accountData.offeredSyncEngines) {
|
||||
EXTRA_ENGINES.forEach(engine => {
|
||||
if (accountData.offeredSyncEngines.includes(engine) &&
|
||||
!accountData.declinedSyncEngines.includes(engine)) {
|
||||
// These extra engines are disabled by default.
|
||||
Services.prefs.setBoolPref(`services.sync.engine.${engine}`, true);
|
||||
}
|
||||
});
|
||||
delete accountData.offeredSyncEngines;
|
||||
}
|
||||
|
||||
if (accountData.declinedSyncEngines) {
|
||||
let declinedSyncEngines = accountData.declinedSyncEngines;
|
||||
log.debug("Received declined engines", declinedSyncEngines);
|
||||
|
@ -384,10 +400,23 @@ this.FxAccountsWebChannelHelpers.prototype = {
|
|||
}
|
||||
|
||||
return {
|
||||
signedInUser
|
||||
signedInUser,
|
||||
capabilities: {
|
||||
engines: this._getAvailableExtraEngines()
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
_getAvailableExtraEngines() {
|
||||
return EXTRA_ENGINES.filter(engineName => {
|
||||
try {
|
||||
return Services.prefs.getBoolPref(`services.sync.engine.${engineName}.available`);
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
changePassword(credentials) {
|
||||
// If |credentials| has fields that aren't handled by accounts storage,
|
||||
// updateUserAccountData will throw - mainly to prevent errors in code
|
||||
|
|
|
@ -259,6 +259,9 @@ add_test(function test_fxa_status_message() {
|
|||
sessionToken: "session-token",
|
||||
uid: "uid",
|
||||
verified: true
|
||||
},
|
||||
capabilities: {
|
||||
engines: ["creditcards", "addresses"]
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -277,6 +280,8 @@ add_test(function test_fxa_status_message() {
|
|||
do_check_eq(signedInUser.uid, "uid");
|
||||
do_check_eq(signedInUser.verified, true);
|
||||
|
||||
deepEqual(response.data.capabilities.engines, ["creditcards", "addresses"]);
|
||||
|
||||
run_next_test();
|
||||
}
|
||||
};
|
||||
|
@ -417,6 +422,42 @@ add_task(async function test_helpers_login_with_customize_sync_and_declined_engi
|
|||
});
|
||||
});
|
||||
|
||||
add_task(async function test_helpers_login_with_offered_sync_engines() {
|
||||
let helpers;
|
||||
const setSignedInUserCalled = new Promise(resolve => {
|
||||
helpers = new FxAccountsWebChannelHelpers({
|
||||
fxAccounts: {
|
||||
async setSignedInUser(accountData) {
|
||||
resolve(accountData);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Services.prefs.setBoolPref("services.sync.engine.creditcards", false);
|
||||
Services.prefs.setBoolPref("services.sync.engine.addresses", false);
|
||||
|
||||
await helpers.login({
|
||||
email: "testuser@testuser.com",
|
||||
verifiedCanLinkAccount: true,
|
||||
customizeSync: true,
|
||||
declinedSyncEngines: ["addresses"],
|
||||
offeredSyncEngines: ["creditcards", "addresses"]
|
||||
});
|
||||
|
||||
const accountData = await setSignedInUserCalled;
|
||||
|
||||
// ensure fxAccounts is informed of the new user being signed in.
|
||||
equal(accountData.email, "testuser@testuser.com");
|
||||
|
||||
// offeredSyncEngines should be stripped in the data.
|
||||
ok(!("offeredSyncEngines" in accountData));
|
||||
// credit cards was offered but not declined.
|
||||
equal(Services.prefs.getBoolPref("services.sync.engine.creditcards"), true);
|
||||
// addresses was offered and explicitely declined.
|
||||
equal(Services.prefs.getBoolPref("services.sync.engine.addresses"), false);
|
||||
});
|
||||
|
||||
add_test(function test_helpers_open_sync_preferences() {
|
||||
let helpers = new FxAccountsWebChannelHelpers({
|
||||
fxAccounts: {
|
||||
|
@ -433,6 +474,31 @@ add_test(function test_helpers_open_sync_preferences() {
|
|||
helpers.openSyncPreferences(mockBrowser, "fxa:verification_complete");
|
||||
});
|
||||
|
||||
add_task(async function test_helpers_getFxAStatus_extra_engines() {
|
||||
let helpers = new FxAccountsWebChannelHelpers({
|
||||
fxAccounts: {
|
||||
getSignedInUser() {
|
||||
return Promise.resolve({
|
||||
email: "testuser@testuser.com",
|
||||
kA: "kA",
|
||||
kb: "kB",
|
||||
sessionToken: "sessionToken",
|
||||
uid: "uid",
|
||||
verified: true
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Services.prefs.setBoolPref("services.sync.engine.creditcards.available", true);
|
||||
// Not defining "services.sync.engine.addresses.available" on purpose.
|
||||
|
||||
let fxaStatus = await helpers.getFxaStatus("sync", mockSendingContext);
|
||||
ok(!!fxaStatus);
|
||||
ok(!!fxaStatus.signedInUser);
|
||||
deepEqual(fxaStatus.capabilities.engines, ["creditcards"]);
|
||||
});
|
||||
|
||||
|
||||
add_task(async function test_helpers_getFxaStatus_allowed_signedInUser() {
|
||||
let wasCalled = {
|
||||
|
|
Загрузка…
Ссылка в новой задаче