Bug 809954 - Handle unexpected future dates; r=rnewman

This commit is contained in:
Gregory Szorc 2012-11-09 09:27:00 -08:00
parent 147e22ad30
commit 21080df09a
2 changed files with 40 additions and 2 deletions

View File

@ -640,6 +640,22 @@ HealthReportPolicy.prototype = {
let now = this.now();
let nowT = now.getTime();
let nextSubmissionDate = this.nextDataSubmissionDate;
// If the system clock were ever set to a time in the distant future,
// it's possible our next schedule date is far out as well. We know
// we shouldn't schedule for more than a day out, so we reset the next
// scheduled date appropriately. 3 days was chosen arbitrarily.
if (nextSubmissionDate.getTime() >= nowT + 3 * MILLISECONDS_PER_DAY) {
this._log.warn("Next data submission time is far away. Was the system " +
"clock recently readjusted? " + nextSubmissionDate);
// It shouldn't really matter what we set this to. 1 day in the future
// should be pretty safe.
this._moveScheduleForward24h();
// Fall through and prompt for user notification, if necessary.
}
// If the user hasn't responded to the data policy, don't do anything.
if (!this.ensureNotifyResponse(now)) {
@ -655,8 +671,6 @@ HealthReportPolicy.prototype = {
// User has responded to data policy and data submission is enabled. Now
// comes the scheduling part.
let nextSubmissionDate = this.nextDataSubmissionDate;
if (nowT < nextSubmissionDate.getTime()) {
this._log.debug("Next data submission is scheduled in the future: " +
nextSubmissionDate);

View File

@ -356,6 +356,30 @@ add_test(function test_submission_daily_scheduling() {
run_next_test();
});
add_test(function test_submission_far_future_scheduling() {
let [policy, prefs, listener] = getPolicy("submission_far_future_scheduling");
let now = new Date(Date.now() - 24 * 60 * 60 * 1000);
defineNow(policy, now);
policy.recordUserAcceptance();
now = new Date();
defineNow(policy, now);
let nextDate = policy._futureDate(3 * 24 * 60 * 60 * 1000 - 1);
policy.nextDataSubmissionDate = nextDate;
policy.checkStateAndTrigger();
do_check_eq(listener.requestDataSubmissionCount, 0);
do_check_eq(policy.nextDataSubmissionDate.getTime(), nextDate.getTime());
policy.nextDataSubmissionDate = new Date(nextDate.getTime() + 1);
policy.checkStateAndTrigger();
do_check_eq(listener.requestDataSubmissionCount, 0);
do_check_eq(policy.nextDataSubmissionDate.getTime(),
policy._futureDate(24 * 60 * 60 * 1000).getTime());
run_next_test();
});
add_test(function test_submission_backoff() {
let [policy, prefs, listener] = getPolicy("submission_backoff");