Bug 993732 - Add test case. r=fabrice
authorHenry Chang <hchang@mozilla.com>
Thu, 10 Apr 2014 19:00:24 +0800
changeset 179535 3d749ffa6003a3a08e87c272652828b1bd167460
parent 179534 1388fb71fc64afb67c3d4be449bfcc7dbdc97ae5
child 179536 1d1235d457b466a7af305852bf0bbda08f921865
push id272
push userpvanderbeken@mozilla.com
push dateMon, 05 May 2014 16:31:18 +0000
reviewersfabrice
bugs993732
milestone31.0a1
Bug 993732 - Add test case. r=fabrice
dom/messages/moz.build
dom/messages/test/mochitest.ini
dom/messages/test/moz.build
dom/messages/test/test_bug_993732.html
--- a/dom/messages/moz.build
+++ b/dom/messages/moz.build
@@ -1,14 +1,16 @@
 # -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
 # vim: set filetype=python:
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
+TEST_DIRS += ['test']
+
 PARALLEL_DIRS += ['interfaces']
 
 EXTRA_COMPONENTS += [
     'SystemMessageInternal.js',
     'SystemMessageManager.js',
     'SystemMessageManager.manifest',
 ]
 
new file mode 100644
--- /dev/null
+++ b/dom/messages/test/mochitest.ini
@@ -0,0 +1,5 @@
+[DEFAULT]
+skip-if = e10s
+
+[test_bug_993732.html]
+skip-if = (buildapp == 'b2g' && toolkit != 'gonk') #Bug 931116, b2g desktop specific, initial triage
new file mode 100644
--- /dev/null
+++ b/dom/messages/test/moz.build
@@ -0,0 +1,8 @@
+# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
+# vim: set filetype=python:
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+MOCHITEST_MANIFESTS += ['mochitest.ini']
+
new file mode 100644
--- /dev/null
+++ b/dom/messages/test/test_bug_993732.html
@@ -0,0 +1,70 @@
+<!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 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 for tomorrow`.");
+      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)
+      {
+        testAlarm(10000);
+      } 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>