Bug 1215201 - Iterate through the elements of the alarmCallbacksMap. r=billm

This commit is contained in:
Blake Winton 2015-10-15 13:36:38 -04:00
parent a46404a35b
commit a7cc76647e
3 changed files with 50 additions and 1 deletions

View File

@ -47,7 +47,7 @@ Alarm.prototype = {
},
observe(subject, topic, data) {
for (let callback in alarmCallbacksMap.get(this.extension)) {
for (let callback of alarmCallbacksMap.get(this.extension)) {
callback(this);
}
if (this.canceled) {

View File

@ -31,3 +31,4 @@ support-files =
[test_ext_background_runtime_connect_params.html]
[test_ext_cookies.html]
[test_ext_bookmarks.html]
[test_ext_alarms.html]

View File

@ -0,0 +1,48 @@
<!DOCTYPE HTML>
<html>
<head>
<title>WebExtension test</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SpawnTask.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/ExtensionTestUtils.js"></script>
<script type="text/javascript" src="head.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<script type="application/javascript;version=1.8">
add_task(function* test_alarm_fires() {
function backgroundScript() {
browser.test.log("running alarm script");
chrome.alarms.onAlarm.addListener(function (alarm) {
browser.test.assertEq(alarm.name, "test_ext_alarms");
browser.test.notifyPass("alarms");
});
chrome.alarms.create("test_ext_alarms", {delayInMinutes: 0.02});
setTimeout(() => {
browser.test.notifyFail("alarms test failed, took too long");
}, 10000);
}
let extensionData = {
background: "(" + backgroundScript.toString() + ")()",
manifest: {
permissions: ["alarms"]
},
};
let extension = ExtensionTestUtils.loadExtension(extensionData);
yield extension.startup();
info("extension loaded");
yield extension.awaitFinish("alarms");
yield extension.unload();
info("extension unloaded");
});
</script>
</body>
</html>