dom/messages/test/test_bug_993732.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/messages/test/test_bug_993732.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,70 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<head>
     1.7 +  <meta charset="utf-8">
     1.8 +  <title>Test Bug 993732</title>
     1.9 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    1.10 +  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.11 +</head>
    1.12 +<body>
    1.13 +<p id="display"></p>
    1.14 +<div id="content" style="display: none"></div>
    1.15 +<pre id="test">
    1.16 +  <script type="application/javascript">
    1.17 +
    1.18 +  "use strict";
    1.19 +
    1.20 +  // The syndrome of Bug 993732 is that the running app (either foreground or background)
    1.21 +  // is not able to receive system messages. Even worse, the app will be killed when the
    1.22 +  // listening system message is broadcast. So this test case uses the alarm message
    1.23 +  // to test if a running app can receive the system message.
    1.24 +
    1.25 +  function testAlarm(aMillisecondsFromNow) {
    1.26 +    var at = new Date();
    1.27 +    at.setTime(at.getTime() + aMillisecondsFromNow);
    1.28 +
    1.29 +    navigator.mozSetMessageHandler('alarm', function(message) {
    1.30 +      ok(true, "We got alarm message!");
    1.31 +      SimpleTest.finish();
    1.32 +    });
    1.33 +
    1.34 +    var domRequest;
    1.35 +    try {
    1.36 +      domRequest = navigator.mozAlarms.add(at, "honorTimezone", {});
    1.37 +    } catch (e) {
    1.38 +      ok(false,
    1.39 +         "Unexpected exception while adding alarm " + aMillisecondsFromNow + " ms from now.");
    1.40 +      SimpleTest.finish();
    1.41 +    }
    1.42 +    domRequest.onsuccess = function(e) {
    1.43 +      // Waiting for alarm message.
    1.44 +    };
    1.45 +    domRequest.onerror = function(e) {
    1.46 +      ok(false, "Unable to add alarm for tomorrow`.");
    1.47 +      SimpleTest.finish();
    1.48 +    };
    1.49 +  }
    1.50 +
    1.51 +  function startTests() {
    1.52 +
    1.53 +    SpecialPowers.pushPrefEnv({"set": [["dom.mozAlarms.enabled", true]]}, function() {
    1.54 +      // Currently applicable only on FxOS
    1.55 +      if (navigator.userAgent.indexOf("Mobile") != -1 &&
    1.56 +          navigator.appVersion.indexOf("Android") == -1)
    1.57 +      {
    1.58 +        testAlarm(10000);
    1.59 +      } else {
    1.60 +        ok(true, "mozAlarms on Firefox OS only.");
    1.61 +        SimpleTest.finish();
    1.62 +      }
    1.63 +    });
    1.64 +  }
    1.65 +
    1.66 +  SimpleTest.expectAssertions(0, 9);
    1.67 +  SimpleTest.waitForExplicitFinish();
    1.68 +  SpecialPowers.pushPermissions([{'type': 'alarms', 'allow': true, 'context': document}], startTests);
    1.69 +
    1.70 +  </script>
    1.71 +</pre>
    1.72 +</body>
    1.73 +</html>

mercurial