Bug 1211606 - Only fetch keys when Sync is enabled via 'services.sync.enabled' pref changed from Gaia. r=fabrice

This commit is contained in:
Fernando Jimenez 2015-10-15 23:36:58 +02:00
parent a33627e32b
commit fb7eb31a2a
4 changed files with 81 additions and 19 deletions

View File

@ -698,6 +698,10 @@ var settingsToObserve = {
prefName: 'dom.sms.maxReadAheadEntries',
defaultValue: 7
},
'services.sync.enabled': {
defaultValue: false,
notifyChange: true
},
'ui.touch.radius.leftmm': {
resetToPref: true
},
@ -717,6 +721,18 @@ var settingsToObserve = {
'wap.UAProf.url': ''
};
function settingObserver(setPref, prefName, setting) {
return value => {
setPref(prefName, value);
if (setting.notifyChange) {
SystemAppProxy._sendCustomEvent('mozPrefChromeEvent', {
prefName: prefName,
value: value
});
}
};
}
for (let key in settingsToObserve) {
let setting = settingsToObserve[key];
@ -766,7 +782,6 @@ for (let key in settingsToObserve) {
break;
}
SettingsListener.observe(key, defaultValue, function(value) {
setPref(prefName, value);
});
SettingsListener.observe(key, defaultValue,
settingObserver(setPref, prefName, setting));
};

View File

@ -156,7 +156,8 @@ this.FxAccountsMgmtService = {
case "signIn":
case "signUp":
case "refreshAuthentication":
FxAccountsManager[data.method](data.email, data.password).then(
FxAccountsManager[data.method](data.email, data.password,
data.fetchKeys).then(
user => {
self._onFulfill(msg.id, user);
},

View File

@ -99,7 +99,7 @@ this.FxAccountsManager = {
return this._fxAccounts.getAccountsClient();
},
_signInSignUp: function(aMethod, aEmail, aPassword) {
_signInSignUp: function(aMethod, aEmail, aPassword, aFetchKeys) {
if (Services.io.offline) {
return this._error(ERROR_OFFLINE);
}
@ -127,15 +127,7 @@ this.FxAccountsManager = {
user: this._user
});
}
let syncEnabled = false;
try {
syncEnabled = Services.prefs.getBoolPref("services.sync.enabled");
} catch(e) {
dump(e + "\n");
}
// XXX Refetch FxA credentials if services.sync.enabled preference
// changes. Bug 1183103
return client[aMethod](aEmail, aPassword, syncEnabled);
return client[aMethod](aEmail, aPassword, aFetchKeys);
}
).then(
user => {
@ -164,6 +156,15 @@ this.FxAccountsManager = {
this._activeSession = user;
log.debug("User signed in: " + JSON.stringify(this._user) +
" - Account created " + (aMethod == "signUp"));
// There is no way to obtain the key fetch token afterwards
// without login out the user and asking her to log in again.
// Also, key fetch tokens are designed to be short-lived, so
// we need to fetch kB as soon as we have the key fetch token.
if (aFetchKeys) {
this._fxAccounts.getKeys();
}
return Promise.resolve({
accountCreated: aMethod === "signUp",
user: this._user
@ -359,12 +360,12 @@ this.FxAccountsManager = {
// -- API --
signIn: function(aEmail, aPassword) {
return this._signInSignUp("signIn", aEmail, aPassword);
signIn: function(aEmail, aPassword, aFetchKeys) {
return this._signInSignUp("signIn", aEmail, aPassword, aFetchKeys);
},
signUp: function(aEmail, aPassword) {
return this._signInSignUp("signUp", aEmail, aPassword);
signUp: function(aEmail, aPassword, aFetchKeys) {
return this._signInSignUp("signUp", aEmail, aPassword, aFetchKeys);
},
signOut: function() {

View File

@ -204,9 +204,10 @@ var FakeFxAccountsClient = {
return deferred.promise;
},
signIn: function(user, password) {
signIn: function(user, password, getKeys) {
this._signInCalled = true;
this._password = password;
this._keyFetchToken = getKeys ? "token" : null;
let deferred = Promise.defer();
this._reject ? deferred.reject()
: deferred.resolve({ email: user,
@ -806,6 +807,50 @@ add_test(function(test_signIn_already_signed_user) {
);
});
add_test(function(test_signIn_getKeys_true) {
do_print("= signIn, getKeys true =");
FxAccountsManager.signOut().then(() => {
FxAccountsManager.signIn("user@domain.org", "password", true).then(
result => {
do_check_true(FakeFxAccountsClient._signInCalled);
do_check_true(FxAccountsManager._fxAccounts._getSignedInUserCalled);
do_check_eq(FxAccountsManager._fxAccounts._signedInUser.email, "user@domain.org");
do_check_eq(FakeFxAccountsClient._password, "password");
do_check_eq(FakeFxAccountsClient._keyFetchToken, "token");
do_check_eq(result.user.email, "user@domain.org");
FakeFxAccountsClient._reset();
FxAccountsManager._fxAccounts._reset();
run_next_test();
},
error => {
do_throw("Unexpected error");
}
);
});
});
add_test(function(test_signIn_getKeys_false) {
do_print("= signIn, getKeys false =");
FxAccountsManager.signOut().then(() => {
FxAccountsManager.signIn("user@domain.org", "password", false).then(
result => {
do_check_true(FakeFxAccountsClient._signInCalled);
do_check_true(FxAccountsManager._fxAccounts._getSignedInUserCalled);
do_check_eq(FxAccountsManager._fxAccounts._signedInUser.email, "user@domain.org");
do_check_eq(FakeFxAccountsClient._password, "password");
do_check_eq(FakeFxAccountsClient._keyFetchToken, null);
do_check_eq(result.user.email, "user@domain.org");
FakeFxAccountsClient._reset();
FxAccountsManager._fxAccounts._reset();
run_next_test();
},
error => {
do_throw("Unexpected error");
}
);
});
});
add_test(function(test_resendVerificationEmail_error_handling) {
do_print("= resendVerificationEmail smoke test =");
let user = FxAccountsManager._fxAccounts._signedInUser;