Bug 1288584 - don't allow prefs to specify a sync interval that's less than 60 seconds. r=rnewman

MozReview-Commit-ID: CHdBsC6cdOE
This commit is contained in:
Mark Hammond 2016-07-22 15:31:21 +10:00
parent 39ed656f3a
commit ce81545035
2 changed files with 29 additions and 11 deletions

View File

@ -21,6 +21,13 @@ XPCOMUtils.defineLazyModuleGetter(this, "Status",
XPCOMUtils.defineLazyModuleGetter(this, "AddonManager",
"resource://gre/modules/AddonManager.jsm");
// Get the value for an interval that's stored in preferences. To save users
// from themselves (and us from them!) the minimum time they can specify
// is 60s.
function getThrottledIntervalPreference(prefName) {
return Math.max(Svc.Prefs.get(prefName), 60) * 1000;
}
this.SyncScheduler = function SyncScheduler(service) {
this.service = service;
this.init();
@ -48,12 +55,12 @@ SyncScheduler.prototype = {
let part = service.fxAccountsEnabled ? "fxa" : "sync11";
let prefSDInterval = "scheduler." + part + ".singleDeviceInterval";
this.singleDeviceInterval = Svc.Prefs.get(prefSDInterval) * 1000;
this.singleDeviceInterval = getThrottledIntervalPreference(prefSDInterval);
this.idleInterval = Svc.Prefs.get("scheduler.idleInterval") * 1000;
this.activeInterval = Svc.Prefs.get("scheduler.activeInterval") * 1000;
this.immediateInterval = Svc.Prefs.get("scheduler.immediateInterval") * 1000;
this.eolInterval = Svc.Prefs.get("scheduler.eolInterval") * 1000;
this.idleInterval = getThrottledIntervalPreference("scheduler.idleInterval");
this.activeInterval = getThrottledIntervalPreference("scheduler.activeInterval");
this.immediateInterval = getThrottledIntervalPreference("scheduler.immediateInterval");
this.eolInterval = getThrottledIntervalPreference("scheduler.eolInterval");
// A user is non-idle on startup by default.
this.idle = false;

View File

@ -148,16 +148,27 @@ add_test(function test_prefAttributes() {
Svc.Prefs.get("scheduler.immediateInterval") * 1000);
_("Custom values for prefs will take effect after a restart.");
Svc.Prefs.set("scheduler.sync11.singleDeviceInterval", 42);
Svc.Prefs.set("scheduler.idleInterval", 23);
Svc.Prefs.set("scheduler.activeInterval", 18);
Svc.Prefs.set("scheduler.sync11.singleDeviceInterval", 420);
Svc.Prefs.set("scheduler.idleInterval", 230);
Svc.Prefs.set("scheduler.activeInterval", 180);
Svc.Prefs.set("scheduler.immediateInterval", 31415);
scheduler.setDefaults();
do_check_eq(scheduler.idleInterval, 23000);
do_check_eq(scheduler.singleDeviceInterval, 42000);
do_check_eq(scheduler.activeInterval, 18000);
do_check_eq(scheduler.idleInterval, 230000);
do_check_eq(scheduler.singleDeviceInterval, 420000);
do_check_eq(scheduler.activeInterval, 180000);
do_check_eq(scheduler.immediateInterval, 31415000);
_("Custom values for interval prefs can't be less than 60 seconds.");
Svc.Prefs.set("scheduler.sync11.singleDeviceInterval", 42);
Svc.Prefs.set("scheduler.idleInterval", 50);
Svc.Prefs.set("scheduler.activeInterval", 50);
Svc.Prefs.set("scheduler.immediateInterval", 10);
scheduler.setDefaults();
do_check_eq(scheduler.idleInterval, 60000);
do_check_eq(scheduler.singleDeviceInterval, 60000);
do_check_eq(scheduler.activeInterval, 60000);
do_check_eq(scheduler.immediateInterval, 60000);
Svc.Prefs.resetBranch("");
scheduler.setDefaults();
run_next_test();