Bug 876936 - Alarms set to a past time fire immediately instead of error. r=gene
--- a/dom/alarm/AlarmService.jsm
+++ b/dom/alarm/AlarmService.jsm
@@ -389,23 +389,16 @@ this.AlarmService = {
aErrorCb = aErrorCb || function() {};
if (!aNewAlarm) {
aErrorCb("alarm is null");
return;
}
aNewAlarm['timezoneOffset'] = this._currentTimezoneOffset;
- let aNewAlarmTime = this._getAlarmTime(aNewAlarm);
- if (aNewAlarmTime <= Date.now()) {
- debug("Adding a alarm that has past time.");
- this._debugCurrentAlarm();
- aErrorCb("InvalidStateError");
- return;
- }
this._db.add(
aNewAlarm,
function addSuccessCb(aNewId) {
debug("Callback after adding alarm in database.");
aNewAlarm['id'] = aNewId;
@@ -419,16 +412,17 @@ this.AlarmService = {
this._debugCurrentAlarm();
aSuccessCb(aNewId);
return;
}
// If the new alarm is earlier than the current alarm, swap them and
// push the previous alarm back to queue.
let alarmQueue = this._alarmQueue;
+ let aNewAlarmTime = this._getAlarmTime(aNewAlarm);
let currentAlarmTime = this._getAlarmTime(this._currentAlarm);
if (aNewAlarmTime < currentAlarmTime) {
alarmQueue.unshift(this._currentAlarm);
this._currentAlarm = aNewAlarm;
this._debugCurrentAlarm();
aSuccessCb(aNewId);
return;
}
--- a/dom/alarm/test/test_alarm_add_date.html
+++ b/dom/alarm/test/test_alarm_add_date.html
@@ -52,21 +52,21 @@
} catch (e) {
ok(false,
"Unexpected exception trying to add alarm for yesterday.");
return testNull();
}
domRequest.onsuccess = function(e) {
navigator.mozAlarms.remove(e.target.result);
- ok(false, "Should not be able to add alarm for already past date.");
+ ok(true, "Should be able to add alarm for already past date, which should fire immediately.");
testNull();
};
domRequest.onerror = function(e) {
- ok(true, "Can't use past date when adding new alarm.");
+ ok(false, "Unable to add alarm for yesterday.");
// Errors as it should, on to the next test
testNull();
}
}
// Verify passing null does indeed fail
function testNull() {