зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1332993 - Do not write logs on FxA profile 304 response. r=markh
MozReview-Commit-ID: Hf5d6rz8HNQ --HG-- extra : rebase_source : f51a3a9b1fb0c4f5e6c56114e289f67ee99b315f
This commit is contained in:
Родитель
f0d74608eb
Коммит
d22c7ab8ed
|
@ -72,7 +72,6 @@ this.FxAccountsProfile.prototype = {
|
|||
|
||||
// Cache fetched data and send out a notification so that UI can update.
|
||||
_cacheProfile(response) {
|
||||
this._cachedAt = Date.now();
|
||||
let profileCache = {
|
||||
profile: response.body,
|
||||
etag: response.etag
|
||||
|
@ -90,6 +89,10 @@ this.FxAccountsProfile.prototype = {
|
|||
},
|
||||
|
||||
_fetchAndCacheProfileInternal() {
|
||||
let onFinally = () => {
|
||||
this._cachedAt = Date.now();
|
||||
this._currentFetchPromise = null;
|
||||
}
|
||||
return this.fxa.getProfileCache()
|
||||
.then(profileCache => {
|
||||
const etag = profileCache ? profileCache.etag : null;
|
||||
|
@ -99,11 +102,13 @@ this.FxAccountsProfile.prototype = {
|
|||
return this._cacheProfile(response);
|
||||
})
|
||||
.then(body => { // finally block
|
||||
this._currentFetchPromise = null;
|
||||
onFinally();
|
||||
return body;
|
||||
}, e => {
|
||||
this._currentFetchPromise = null;
|
||||
throw e;
|
||||
}, err => {
|
||||
onFinally();
|
||||
if (err.code != 304) { // fetchProfile() throws when the profile wasn't modified
|
||||
throw err;
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
|
@ -125,8 +130,7 @@ this.FxAccountsProfile.prototype = {
|
|||
// Note that _fetchAndCacheProfile isn't returned, so continues
|
||||
// in the background.
|
||||
this._fetchAndCacheProfile().catch(err => {
|
||||
log.error("Background refresh of profile failed, bumping _cachedAt", err);
|
||||
this._cachedAt = Date.now();
|
||||
log.error("Background refresh of profile failed", err);
|
||||
});
|
||||
} else {
|
||||
log.trace("not checking freshness of profile as it remains recent");
|
||||
|
|
|
@ -116,11 +116,9 @@ add_test(function cacheProfile_change() {
|
|||
return Promise.resolve();
|
||||
}
|
||||
let profile = CreateFxAccountsProfile(fxa);
|
||||
profile._cachedAt = 12345;
|
||||
|
||||
makeObserver(ON_PROFILE_CHANGE_NOTIFICATION, function(subject, topic, data) {
|
||||
do_check_eq(data, ACCOUNT_DATA.uid);
|
||||
do_check_neq(profile._cachedAt, 12345, "cachedAt has been bumped");
|
||||
do_check_true(setProfileCacheCalled);
|
||||
run_next_test();
|
||||
});
|
||||
|
@ -134,6 +132,7 @@ add_test(function fetchAndCacheProfile_ok() {
|
|||
return Promise.resolve({ body: { avatar: "myimg"} });
|
||||
};
|
||||
let profile = CreateFxAccountsProfile(null, client);
|
||||
profile._cachedAt = 12345;
|
||||
|
||||
profile._cacheProfile = function(toCache) {
|
||||
do_check_eq(toCache.body.avatar, "myimg");
|
||||
|
@ -143,6 +142,24 @@ add_test(function fetchAndCacheProfile_ok() {
|
|||
return profile._fetchAndCacheProfile()
|
||||
.then(result => {
|
||||
do_check_eq(result.avatar, "myimg");
|
||||
do_check_neq(profile._cachedAt, 12345, "cachedAt has been bumped");
|
||||
run_next_test();
|
||||
});
|
||||
});
|
||||
|
||||
add_test(function fetchAndCacheProfile_always_bumps_cachedAt() {
|
||||
let client = mockClient(mockFxa());
|
||||
client.fetchProfile = function() {
|
||||
return Promise.reject(new Error("oops"));
|
||||
};
|
||||
let profile = CreateFxAccountsProfile(null, client);
|
||||
profile._cachedAt = 12345;
|
||||
|
||||
return profile._fetchAndCacheProfile()
|
||||
.then(result => {
|
||||
do_throw("Should not succeed");
|
||||
}, err => {
|
||||
do_check_neq(profile._cachedAt, 12345, "cachedAt has been bumped");
|
||||
run_next_test();
|
||||
});
|
||||
});
|
||||
|
@ -406,12 +423,10 @@ add_test(function getProfile_fetchAndCacheProfile_throws() {
|
|||
fxa.profileCache = { profile: { avatar: "myimg" } };
|
||||
let profile = CreateFxAccountsProfile(fxa);
|
||||
|
||||
profile._cachedAt = 12345;
|
||||
profile._fetchAndCacheProfile = () => Promise.reject(new Error());
|
||||
|
||||
return profile.getProfile()
|
||||
.then(result => {
|
||||
do_check_neq(profile._cachedAt, 12345);
|
||||
do_check_eq(result.avatar, "myimg");
|
||||
run_next_test();
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче