blob: b78d6da649383a3b7eadb8f3b4ccad4e3ed1a49e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set sts=2 sw=2 et tw=80: */
/* eslint-disable mozilla/no-arbitrary-setTimeout */
"use strict";
add_task(async function test_periodic_alarm_fires() {
function backgroundScript() {
const ALARM_NAME = "test_ext_alarms";
let count = 0;
let timer;
browser.alarms.onAlarm.addListener(alarm => {
browser.test.assertEq(
alarm.name,
ALARM_NAME,
"alarm has the expected name"
);
if (count++ === 3) {
clearTimeout(timer);
browser.alarms.clear(ALARM_NAME).then(wasCleared => {
browser.test.assertTrue(wasCleared, "alarm was cleared");
browser.test.notifyPass("alarm-periodic");
});
}
});
browser.alarms.create(ALARM_NAME, { periodInMinutes: 0.02 });
timer = setTimeout(async () => {
browser.test.fail("alarm fired expected number of times");
let wasCleared = await browser.alarms.clear(ALARM_NAME);
browser.test.assertTrue(wasCleared, "alarm was cleared");
browser.test.notifyFail("alarm-periodic");
}, 30000);
}
let extension = ExtensionTestUtils.loadExtension({
background: `(${backgroundScript})()`,
manifest: {
permissions: ["alarms"],
},
});
await extension.startup();
await extension.awaitFinish("alarm-periodic");
await extension.unload();
});
|