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