Bug 1459243 - Always store last check pref in RemoteSettings r=mgoodwin
MozReview-Commit-ID: 2CvYBKoOOaE
--- a/services/common/remote-settings.js
+++ b/services/common/remote-settings.js
@@ -119,21 +119,21 @@ async function fetchLatestChanges(url, l
}
return {changes, currentEtag, serverTimeMillis, backoffSeconds};
}
class RemoteSettingsClient {
- constructor(collectionName, { lastCheckTimePref, bucketName, signerName }) {
+ constructor(collectionName, { bucketName, signerName, lastCheckTimePref }) {
this.collectionName = collectionName;
- this.lastCheckTimePref = lastCheckTimePref;
this.bucketName = bucketName;
this.signerName = signerName;
+ this._lastCheckTimePref = lastCheckTimePref;
this._callbacks = new Map();
this._callbacks.set("sync", []);
this._kinto = null;
}
get identifier() {
@@ -141,16 +141,20 @@ class RemoteSettingsClient {
}
get filename() {
// Replace slash by OS specific path separator (eg. Windows)
const identifier = OS.Path.join(...this.identifier.split("/"));
return `${identifier}.json`;
}
+ get lastCheckTimePref() {
+ return this._lastCheckTimePref || `services.settings.${this.bucketName}.${this.collectionName}.last_check`;
+ }
+
on(event, callback) {
if (!this._callbacks.has(event)) {
throw new Error(`Unknown event type ${event}`);
}
this._callbacks.get(event).push(callback);
}
/**
@@ -403,22 +407,16 @@ class RemoteSettingsClient {
}
/**
* Save last time server was checked in users prefs.
*
* @param {Date} serverTime the current date return by server.
*/
_updateLastCheck(serverTime) {
- if (!this.lastCheckTimePref) {
- // If not set (default), it is not necessary to store the last check timestamp.
- return;
- }
- // Storing the last check time is mainly a matter of retro-compatibility with
- // the blocklists clients.
const checkedServerTimeInSeconds = Math.round(serverTime / 1000);
Services.prefs.setIntPref(this.lastCheckTimePref, checkedServerTimeInSeconds);
}
}
function remoteSettingsFunction() {
const _clients = new Map();
--- a/services/common/tests/unit/test_blocklist_clients.js
+++ b/services/common/tests/unit/test_blocklist_clients.js
@@ -122,16 +122,19 @@ add_task(async function test_list_is_wri
const content = await readJSON(profFile.path);
equal(content.data[0].blockID, testData[testData.length - 1]);
}
});
add_task(clear_state);
add_task(async function test_current_server_time_is_saved_in_pref() {
for (let {client} of gBlocklistClients) {
+ // The lastCheckTimePref was customized:
+ ok(/services\.blocklist\.(\w+)\.checked/.test(client.lastCheckTimePref), client.lastCheckTimePref);
+
const serverTime = Date.now();
await client.maybeSync(2000, serverTime);
const after = Services.prefs.getIntPref(client.lastCheckTimePref);
equal(after, Math.round(serverTime / 1000));
}
});
add_task(clear_state);
--- a/services/common/tests/unit/test_remote_settings.js
+++ b/services/common/tests/unit/test_remote_settings.js
@@ -74,16 +74,25 @@ add_task(async function test_records_obt
// Open the collection, verify it's been populated:
// Our test data has a single record; it should be in the local collection
const list = await client.get();
equal(list.length, 1);
});
add_task(clear_state);
+add_task(async function test_current_server_time_is_saved_in_pref() {
+ const serverTime = Date.now();
+ await client.maybeSync(2000, serverTime);
+ equal(client.lastCheckTimePref, "services.settings.main.password-fields.last_check");
+ const after = Services.prefs.getIntPref(client.lastCheckTimePref);
+ equal(after, Math.round(serverTime / 1000));
+});
+add_task(clear_state);
+
add_task(async function test_records_changes_are_overwritten_by_server_changes() {
// Create some local conflicting data, and make sure it syncs without error.
const collection = await client.openCollection();
await collection.create({
"website": "",
"id": "9d500963-d80e-3a91-6e74-66f3811b99cc"
}, { useRecordId: true });