DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (fddffdeab170)

VCS Links

Line Code
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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
<!DOCTYPE HTML>
<html>
<head>
  <meta charset="utf-8">
  <title>Test Bug 993732</title>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
</head>
<body>
<p id="display"></p>
<div id="content" style="display: none"></div>
<pre id="test">
  <script type="application/javascript">

  "use strict";

  // The syndrome of Bug 993732 is that the running app (either foreground or background)
  // is not able to receive system messages. Even worse, the app will be killed when the
  // listening system message is broadcast. So this test case uses the alarm message
  // to test if a running app can receive the system message.

  function registerPage() {
    var gScript = SpecialPowers.loadChromeScript(SimpleTest.getTestFileURL('system_message_chrome_script.js'));
    gScript.addMessageListener("page-registered", function pageRegisteredHandler() {
      gScript.removeMessageListener("page-registered", pageRegisteredHandler);
      gScript.destroy();
      testAlarm(10000);
    });

    gScript.sendAsyncMessage("trigger-register-page",
                             { type: "alarm",
                               manifestURL: window.location.origin + "/manifest.webapp",
                               pageURL: window.location.href });
  }

  function testAlarm(aMillisecondsFromNow) {
    var at = new Date();
    at.setTime(at.getTime() + aMillisecondsFromNow);

    navigator.mozSetMessageHandler('alarm', function(message) {
      ok(true, "We got alarm message!");
      SimpleTest.finish();
    });

    var domRequest;
    try {
      domRequest = navigator.mozAlarms.add(at, "honorTimezone", {});
    } catch (e) {
      ok(false,
         "Unexpected exception while adding alarm " + aMillisecondsFromNow + " ms from now.");
      SimpleTest.finish();
    }
    domRequest.onsuccess = function(e) {
      // Waiting for alarm message.
    };
    domRequest.onerror = function(e) {
      ok(false, "Unable to add alarm.");
      SimpleTest.finish();
    };
  }

  function startTests() {

    SpecialPowers.pushPrefEnv({"set": [["dom.mozAlarms.enabled", true]]}, function() {
      // Currently applicable only on FxOS
      if (navigator.userAgent.indexOf("Mobile") != -1 &&
          navigator.appVersion.indexOf("Android") == -1)
      {
        registerPage();
      } else {
        ok(true, "mozAlarms on Firefox OS only.");
        SimpleTest.finish();
      }
    });
  }

  SimpleTest.expectAssertions(0, 9);
  SimpleTest.waitForExplicitFinish();
  SpecialPowers.pushPermissions([{'type': 'alarms', 'allow': true, 'context': document}], startTests);

  </script>
</pre>
</body>
</html>