Bug 1655390 - handle null profileCache in FxAccountsProfile.ensureProfile; r=markh

Differential Revision: https://phabricator.services.mozilla.com/D84952
This commit is contained in:
Ryan Kelly 2020-07-28 00:20:04 +00:00
Родитель 6f07a2d9b7
Коммит af6a329b2a
2 изменённых файлов: 26 добавлений и 6 удалений

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

@ -168,7 +168,10 @@ FxAccountsProfile.prototype = {
// callers who need to await the underlying network request.
async ensureProfile() {
const profileCache = await this._getProfileCache();
if (Date.now() > this._cachedAt + this.PROFILE_FRESHNESS_THRESHOLD) {
if (
!profileCache ||
Date.now() > this._cachedAt + this.PROFILE_FRESHNESS_THRESHOLD
) {
const profile = await this._fetchAndCacheProfile().catch(err => {
log.error("Background refresh of profile failed", err);
});
@ -177,8 +180,7 @@ FxAccountsProfile.prototype = {
}
}
log.trace("not checking freshness of profile as it remains recent");
return profileCache.profile;
return profileCache ? profileCache.profile : null;
},
QueryInterface: ChromeUtils.generateQI([

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

@ -417,6 +417,20 @@ add_task(async function test_ensureProfile() {
},
fetchAndCacheProfileResolves: false,
},
// profile retrieval when we've cached a failure to fetch profile data
{
// Note: The threshold for this test case is being set to an arbitrary value that will
// be greater than Date.now() so the retrieved cached profile will be deemed recent.
threshold: Date.now() + 5000,
hasRecentCachedProfile: false,
cachedProfile: null,
fetchedProfile: {
uid: `${ACCOUNT_UID}7`,
email: `${ACCOUNT_EMAIL}7`,
avatar: "myimg7",
},
fetchAndCacheProfileResolves: true,
},
];
for (const tc of testCases) {
@ -424,9 +438,13 @@ add_task(async function test_ensureProfile() {
mockProfile
.expects("_getProfileCache")
.once()
.returns({
profile: tc.cachedProfile,
});
.returns(
tc.cachedProfile
? {
profile: tc.cachedProfile,
}
: null
);
profile.PROFILE_FRESHNESS_THRESHOLD = tc.threshold;
if (tc.hasRecentCachedProfile) {