1 XPCOMUtils.defineLazyModuleGetter(this, "AlarmService",
2 "resource://gre/modules/AlarmService.jsm");
5 * Tests for Bug 867868 and related Alarm API bugs.
7 * NOTE: These tests pass the alarm time to AlarmService as a number and not as
8 * a date. See bug 810973 about Date truncating milliseconds. AlarmService does
9 * not officially allow a integer, but nor does it disallow it. Of course this
10 * test will break if AlarmService adds a type check, hence this note.
11 * FIXME: when bug 810973 is fixed.
14 function add_alarm_future(cb) {
15 let alarmId = undefined;
17 date: new Date(Date.now() + 143),
20 function onAlarmFired(aAlarm) {
21 ok(alarmId === aAlarm.id, "Future alarm fired successfully.");
24 function onSuccess(aAlarmId) {
27 function onError(error) {
28 ok(false, "Unexpected error adding future alarm " + error);
33 function add_alarm_present(cb) {
35 let alarmId = undefined;
40 function onAlarmFired(aAlarm) {
41 ok(alarmId === aAlarm.id, "Present alarm fired successfully.");
44 function onSuccess(aAlarmId) {
46 }, function onError(error) {
47 ok(false, "Unexpected error adding alarm for current time " + error);
52 function add_alarm_past(cb) {
54 let alarmId = undefined;
56 date: new Date(Date.now() - 5),
59 function onAlarmFired(aAlarm) {
60 ok(alarmId === aAlarm.id, "Past alarm fired successfully.");
63 function onSuccess(aAlarmId) {
66 function onError(error) {
67 ok(false, "Unexpected error adding alarm for time in the past " + error);
72 function trigger_all_alarms(cb) {
75 let date = new Date(Date.now() + 57);
76 function onAlarmFired() {
78 info("trigger_all_alarms count " + counter);
80 ok(true, "All " + n + " alarms set to a particular time fired.");
85 for (let i = 0; i < n; i++) {
96 function multiple_handlers(cb) {
97 let d = new Date(Date.now() + 100);
102 ok(true, "Two alarms for the same time fired.");
107 function handler1() {
112 function handler2() {
133 function same_time_alarms(cb) {
135 var delay = new Date(Date.now() + 100);
140 ok(true, "All alarms set for the same time fired.");
145 function addImmediateAlarm() {
156 }, addImmediateAlarm);
161 }, addImmediateAlarm);
175 function nextTest() {
177 if (testIndex >= tests.length)
180 waitForExplicitFinish();
181 tests[testIndex](function() {