Bug 843893 - Fix alarm and power tests to work with current gaia, r=gene.lian
☠☠ backed out by 2e9988148b18 ☠ ☠
authorDavid Clarke <dclarke@mozilla.com>
Thu, 07 Mar 2013 12:48:34 -0800
changeset 125482 bc8eeacc3c8a8bd02241fab8d3fe3e7ceaaf1200
parent 125481 e6ef8811bc73911539be371058d5152a30456e58
child 125483 cc9e514a38a0818e563768403c384773131de50c
push id24965
push userjgriffin@mozilla.com
push dateTue, 19 Mar 2013 20:09:23 +0000
treeherdermozilla-inbound@bc8eeacc3c8a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgene
bugs843893
milestone22.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 843893 - Fix alarm and power tests to work with current gaia, r=gene.lian
dom/alarm/test/test_alarm_non_permitted_app.html
dom/power/test/Makefile.in
dom/power/test/test_power_basics.html
dom/power/test/test_power_non_permitted_app.html
--- a/dom/alarm/test/test_alarm_non_permitted_app.html
+++ b/dom/alarm/test/test_alarm_non_permitted_app.html
@@ -1,35 +1,50 @@
 <!DOCTYPE HTML>
 <html>
 <head>
   <title>Test Non-Permitted Application for Alarm API</title>
-  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
 </head>
 <body>
 <p id="display"></p>
 <div id="content" style="display: none"></div>
 <pre id="test">
 <script type="application/javascript">
 
 "use strict";
 
-SimpleTest.waitForExplicitFinish();
+function alarmtests() {
+  SimpleTest.waitForExplicitFinish();
+
+  SpecialPowers.pushPrefEnv({"set": [["dom.mozAlarms.enabled", true]]}, function() {
 
-SpecialPowers.pushPrefEnv({"set": [["dom.mozAlarms.enabled", true]]}, function() {
-  SpecialPowers.removePermission("alarms", document);
+    // mozAlarms is intalled on all platforms except Android for the moment.
+    if (navigator.appVersion.indexOf("Android") != -1) {
+      ok(!('mozAlarms' in navigator), "navigator.mozAlarms should not exist");
+    } else {
+      ok('mozAlarms' in navigator, "navigator.mozAlarms should exist");
+      is(navigator.mozAlarms, null, "navigator.mozAlarms should return null");
+    }
+    SpecialPowers.addPermission("alarms", true, document);
+    SimpleTest.finish();
+  });
 
-  // mozAlarms is intalled on all platforms except Android for the moment.
-  if (navigator.appVersion.indexOf("Android") != -1) {
-    ok(!('mozAlarms' in navigator), "navigator.mozAlarms should not exist");
-  } else {
-    ok('mozAlarms' in navigator, "navigator.mozAlarms should exist");
-    is(navigator.mozAlarms, null, "navigator.mozAlarms should return null");
-  }
+}
 
-  SimpleTest.finish();
-});
+if(!SpecialPowers.hasPermission("alarms", document)) {
+  var head = document.getElementsByTagName('head')[0];
+  var js = document.createElement("script");
+  js.type = "application/javascript";
+  js.src = "/tests/SimpleTest/SimpleTest.js";
+  js.onload = alarmtests;
+  head.appendChild(js);
+  
+} else {
+  SpecialPowers.removePermission("alarms", document);
+  window.location = window.location; 
+}
+
 
 </script>
 </pre>
 </body>
 </html>
--- a/dom/power/test/Makefile.in
+++ b/dom/power/test/Makefile.in
@@ -8,15 +8,16 @@ srcdir           = @srcdir@
 VPATH            = @srcdir@
 
 relativesrcdir   = @relativesrcdir@
 
 include $(DEPTH)/config/autoconf.mk
 
 MOCHITEST_FILES = \
   test_power_basics.html \
+  test_power_non_permitted_app.html \
   $(NULL)
 
 MOCHITEST_BROWSER_FILES = \
   browser_bug697132.js \
   $(NULL)
 
 include $(topsrcdir)/config/rules.mk
--- a/dom/power/test/test_power_basics.html
+++ b/dom/power/test/test_power_basics.html
@@ -1,52 +1,27 @@
 <!DOCTYPE HTML>
 <html>
 <head>
   <title>Test for Power API</title>
   <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<p id="display"></p>
+<div id="content" style="display: none">
+</div>
+<pre id="test">
 <script type="application/javascript">
 
 /** Test for Power API **/
 
 ok('mozPower' in navigator, "navigator.mozPower should exist");
 
 /** Test permission **/
-// In b2g, addPermission 'power' is only working after a document reload
-// See bug 802312
-
-SimpleTest.waitForExplicitFinish();
-
-function startTest() {
-  window.frames[0].frameElement.setAttribute('onload', 'doTest2()');
-  power = window.frames[0].navigator.mozPower;
-  ok(!power, "Shouldn't be able to access power manager without permission.");
-
-  SpecialPowers.addPermission("power", true, window.frames[0].document);
-  window.frames[0].location.reload();
-}
 
-function doTest2() {
-  window.frames[0].frameElement.setAttribute('onload', 'doTest3()');
-  power = window.frames[0].navigator.mozPower;
-  ok(power, "Should be able to access power manager with permission.");
-
-  SpecialPowers.removePermission("power", window.frames[0].document);
-  window.frames[0].location.reload();
-}
+power = navigator.mozPower;
+ok(power, "Should be able to access power manager with permission.");
 
-function doTest3() {
-  power = window.frames[0].navigator.mozPower;
-  ok(!power, "Shouldn't be able to access power manager without permission.");
-  SimpleTest.finish();
-}
 </script>
-</head>
-<body>
-<p id="display"></p>
-<div id="content" style="display: none">
-</div>
-<iframe onload="startTest()"></iframe>
-<pre id="test">
 </pre>
 </body>
 </html>
new file mode 100644
--- /dev/null
+++ b/dom/power/test/test_power_non_permitted_app.html
@@ -0,0 +1,39 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>Test for Power API</title>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<p id="display"></p>
+<div id="content" style="display: none">
+</div>
+<pre id="test">
+<script type="application/javascript">
+
+/** Test for Power API **/
+
+function powertests() {
+  SimpleTest.waitForExplicitFinish();
+  power = navigator.mozPower;
+  ok(!power, "Shouldn't be able to access power manager without permission.");
+  SimpleTest.finish();
+}
+
+if(!SpecialPowers.hasPermission("power", document)) {
+  var head = document.getElementsByTagName('head')[0];
+  var js = document.createElement("script");
+  js.type = "application/javascript";
+  js.src = "/tests/SimpleTest/SimpleTest.js";
+  js.onload = powertests;
+  head.appendChild(js);
+
+} else {
+  SpecialPowers.removePermission("power", document);
+  window.location = window.location;
+}
+
+</script>
+</pre>
+</body>
+</html>