Bug 1344068 - Use alarmLastAck from parent item in the alarm service. r=Decathlon
authorPhilipp Kewisch <mozilla@kewis.ch>
Tue, 04 Apr 2017 23:07:24 +0200
changeset 21649 693678f602cfbdf0ff0f1f3f9214f142816bd61b
parent 21648 316de32a421766cd3481da2915a4ecb90730cb86
child 21650 4bafb6c2ddaf96fce9afed6ad76793224927207e
push id13196
push usermozilla@jorgk.com
push dateFri, 09 Jun 2017 15:32:08 +0000
treeherdercomm-central@291cefb09dff [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersDecathlon
bugs1344068
Bug 1344068 - Use alarmLastAck from parent item in the alarm service. r=Decathlon MozReview-Commit-ID: FoNi3nzX5TA
calendar/base/src/calAlarmService.js
calendar/test/unit/.eslintrc.js
calendar/test/unit/test_alarmservice.js
--- a/calendar/base/src/calAlarmService.js
+++ b/calendar/base/src/calAlarmService.js
@@ -366,17 +366,17 @@ calAlarmService.prototype = {
                 let timeUntilRefresh = this.mRangeEnd.subtractDate(now).inSeconds * 1000;
                 if (timeUntilRefresh < timeout) {
                     continue;
                 }
 
                 this.addTimer(aItem, alarm, timeout);
             } else if (showMissed) {
                 // This alarm is in the past.  See if it has been previously ack'd.
-                let lastAck = aItem.alarmLastAck || aItem.parentItem.alarmLastAck;
+                let lastAck = aItem.parentItem.alarmLastAck;
                 if (lastAck && lastAck.compare(alarmDate) >= 0) {
                     // The alarm was previously dismissed or snoozed, no further
                     // action required.
                     continue;
                 } else {
                     // The alarm was not snoozed or dismissed, fire it now.
                     this.alarmFired(aItem, alarm);
                 }
--- a/calendar/test/unit/.eslintrc.js
+++ b/calendar/test/unit/.eslintrc.js
@@ -1,13 +1,13 @@
 "use strict";
 
 module.exports = {
     "extends": [
-        "../../../mozilla/testing/xpcshell/xpcshell.eslintrc.js"
+        "plugin:mozilla/xpcshell-test"
     ],
     "rules": {
         // Allow non-camelcase so that run_test doesn't produce a warning.
         "camelcase": 0,
         // Allow using undefined variables so that tests can refer to functions
         // and variables defined in head.js files, without having to maintain a
         // list of globals in each .eslintrc file.
         // Note that bug 1168340 will eventually help auto-registering globals
--- a/calendar/test/unit/test_alarmservice.js
+++ b/calendar/test/unit/test_alarmservice.js
@@ -219,22 +219,43 @@ function addTestItems(aCalendar) {
 
     firedOffsets.forEach(([offset, expected]) => {
         alarm = createAlarmFromDuration(offset);
         item.addAlarm(alarm);
         alarmObserver.expectResult(aCalendar, item, alarm, expected);
     });
     aCalendar.addItem(item, null);
 
+    // Bug 1344068 - Alarm with lastAck on exception, should take parent lastAck.
+    // Alarm 15 minutes ago should fire.
+    date = cal.now();
+    [item, alarm] = createEventWithAlarm(aCalendar, date, date, "-PT15M", "RRULE:FREQ=DAILY;COUNT=1");
+    item.title="addTestItems Test 6";
+
+    // Parent item is acknowledged before alarm, so it should fire.
+    let lastAck = item.startDate.clone();
+    lastAck.hour -= 1;
+    item.alarmLastAck = lastAck;
+
+    // Occurrence is acknowledged after alarm (start date), so if the alarm
+    // service wrongly uses the exception occurrence then we catch it.
+    let occ = item.recurrenceInfo.getOccurrenceFor(item.startDate);
+    occ.alarmLastAck = item.startDate.clone();
+    item.recurrenceInfo.modifyException(occ, true);
+
+    alarmObserver.expectOccurrences(aCalendar, item, alarm, [EXPECT_FIRED]);
+    aCalendar.addItem(item, null);
+
+
     // daily repeating event starting almost 2 full days ago. The alarms on the first 2 occurrences
     // should fire, and a timer should be set for the next occurrence only
     date = cal.now();
     date.hour -= 47;
     [item, alarm] = createEventWithAlarm(aCalendar, date, date, "-PT15M", "RRULE:FREQ=DAILY");
-    item.title="addTestItems Test 6";
+    item.title="addTestItems Test 7";
     alarmObserver.expectOccurrences(aCalendar, item, alarm,
                                    [EXPECT_FIRED, EXPECT_FIRED, EXPECT_TIMER,
                                     EXPECT_NONE, EXPECT_NONE]);
     aCalendar.addItem(item, null);
 
     // monthly repeating event starting 2 months and a day ago. The alarms on the first 2 occurrences
     // should be ignored, the alarm on the next occurrence only should fire.
     // Missing recurrences of the event in particular days of the year generate exceptions to the
@@ -260,17 +281,17 @@ function addTestItems(aCalendar) {
         expected = statusAlarmSequences.excep1;
     } else {
         // Regular sequence of alarms expected for all the others days.
         expected = statusAlarmSequences.reg;
     }
     date.month -= 2;
     date.day -= 1;
     [item, alarm] = createEventWithAlarm(aCalendar, date, date, "-PT15M", "RRULE:FREQ=MONTHLY");
-    item.title="addTestItems Test 7";
+    item.title="addTestItems Test 8";
     alarmObserver.expectOccurrences(aCalendar, item, alarm, expected);
     aCalendar.addItem(item, null);
 }
 
 function doModifyItemTest(aCalendar) {
     let item, alarm;
 
     // begin with item starting before the alarm date range