Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
1 <!DOCTYPE HTML>
2 <html>
3 <head>
4 <meta charset="utf-8">
5 <title>Test Bug 993732</title>
6 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
7 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
8 </head>
9 <body>
10 <p id="display"></p>
11 <div id="content" style="display: none"></div>
12 <pre id="test">
13 <script type="application/javascript">
15 "use strict";
17 // The syndrome of Bug 993732 is that the running app (either foreground or background)
18 // is not able to receive system messages. Even worse, the app will be killed when the
19 // listening system message is broadcast. So this test case uses the alarm message
20 // to test if a running app can receive the system message.
22 function testAlarm(aMillisecondsFromNow) {
23 var at = new Date();
24 at.setTime(at.getTime() + aMillisecondsFromNow);
26 navigator.mozSetMessageHandler('alarm', function(message) {
27 ok(true, "We got alarm message!");
28 SimpleTest.finish();
29 });
31 var domRequest;
32 try {
33 domRequest = navigator.mozAlarms.add(at, "honorTimezone", {});
34 } catch (e) {
35 ok(false,
36 "Unexpected exception while adding alarm " + aMillisecondsFromNow + " ms from now.");
37 SimpleTest.finish();
38 }
39 domRequest.onsuccess = function(e) {
40 // Waiting for alarm message.
41 };
42 domRequest.onerror = function(e) {
43 ok(false, "Unable to add alarm for tomorrow`.");
44 SimpleTest.finish();
45 };
46 }
48 function startTests() {
50 SpecialPowers.pushPrefEnv({"set": [["dom.mozAlarms.enabled", true]]}, function() {
51 // Currently applicable only on FxOS
52 if (navigator.userAgent.indexOf("Mobile") != -1 &&
53 navigator.appVersion.indexOf("Android") == -1)
54 {
55 testAlarm(10000);
56 } else {
57 ok(true, "mozAlarms on Firefox OS only.");
58 SimpleTest.finish();
59 }
60 });
61 }
63 SimpleTest.expectAssertions(0, 9);
64 SimpleTest.waitForExplicitFinish();
65 SpecialPowers.pushPermissions([{'type': 'alarms', 'allow': true, 'context': document}], startTests);
67 </script>
68 </pre>
69 </body>
70 </html>