Bug 1348743 - avoid running a bookmark validation on every sync. r=tcsc

MozReview-Commit-ID: 49sWR56kfrj

--HG--
extra : rebase_source : f13d7ef61b343820347579b76352cd65a322c8eb
This commit is contained in:
Mark Hammond 2017-03-20 19:13:42 +11:00
Родитель e7b03d35b1
Коммит dfa642bc63
2 изменённых файлов: 48 добавлений и 1 удалений

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

@ -106,7 +106,7 @@ this.Doctor = {
// Update the time now, even if we decline to actually perform a
// validation. We don't want to check the rest of these more frequently
// than once a day.
Svc.Prefs.set("validation.lastTime", Math.floor(nowSeconds));
Svc.Prefs.set(prefPrefix + "validation.lastTime", Math.floor(nowSeconds));
// Validation only occurs a certain percentage of the time.
let validationProbability = Svc.Prefs.get(prefPrefix + "validation.percentageChance", 0) / 100.0;

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

@ -2,6 +2,7 @@
http://creativecommons.org/publicdomain/zero/1.0/ */
const { Doctor, REPAIR_ADVANCE_PERIOD } = Cu.import("resource://services-sync/doctor.js", {});
Cu.import("resource://gre/modules/Services.jsm");
initTestLogging("Trace");
@ -10,6 +11,52 @@ function mockDoctor(mocks) {
return Object.assign({}, Doctor, mocks);
}
add_task(async function test_validation_interval() {
let now = 1000;
let doctor = mockDoctor({
_now() {
// note that the function being mocked actually returns seconds.
return now;
},
});
let engine = {
name: "test-engine",
getValidator() {
return {
validate(e) {
return {};
}
}
},
}
// setup prefs which enable test-engine validation.
Services.prefs.setBoolPref("services.sync.engine.test-engine.validation.enabled", true);
Services.prefs.setIntPref("services.sync.engine.test-engine.validation.percentageChance", 100);
Services.prefs.setIntPref("services.sync.engine.test-engine.validation.maxRecords", 1);
// And say we should validate every 10 seconds.
Services.prefs.setIntPref("services.sync.engine.test-engine.validation.interval", 10);
deepEqual(doctor._getEnginesToValidate([engine]), {
"test-engine": {
engine,
maxRecords: 1,
}
});
// We haven't advanced the timestamp, so we should not validate again.
deepEqual(doctor._getEnginesToValidate([engine]), {});
// Advance our clock by 11 seconds.
now += 11;
// We should validate again.
deepEqual(doctor._getEnginesToValidate([engine]), {
"test-engine": {
engine,
maxRecords: 1,
}
});
});
add_task(async function test_repairs_start() {
let repairStarted = false;
let problems = {