Bug 876936 - Alarms set to a past time fire immediately instead of error. r=gene
☠☠ backed out by e460f5af4311 ☠ ☠
authorNikhil Marathe <nsm.nikhil@gmail.com>
Mon, 03 Jun 2013 21:35:39 -0700
changeset 145356 0cd289fcea166731e947883d303dae45778bc88e
parent 145355 2c19b63b23d9dbb397784292722f116ef45852df
child 145357 83b67d255bf35784893f6e114a51403ddf96e86f
push id2697
push userbbajaj@mozilla.com
push dateMon, 05 Aug 2013 18:49:53 +0000
treeherdermozilla-beta@dfec938c7b63 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgene
bugs876936
milestone24.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 876936 - Alarms set to a past time fire immediately instead of error. r=gene
dom/alarm/AlarmService.jsm
dom/alarm/test/test_alarm_add_date.html
--- 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() {