Permalink
Browse files

Back out bc8eeacc3c8a (bug 843893) for (at least) desktop bustage in …

…test_power_basics.html
  • Loading branch information...
1 parent ae39bce commit 08571ca4de5a585f3f21159615c70ee6d91e52e0 @philor philor committed Mar 19, 2013
@@ -2,6 +2,7 @@
<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>
@@ -12,37 +13,21 @@
"use strict";
-function alarmtests() {
- SimpleTest.waitForExplicitFinish();
+SimpleTest.waitForExplicitFinish();
- SpecialPowers.pushPrefEnv({"set": [["dom.mozAlarms.enabled", true]]}, function() {
-
- // 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();
- });
-
-}
-
-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.pushPrefEnv({"set": [["dom.mozAlarms.enabled", true]]}, function() {
SpecialPowers.removePermission("alarms", document);
- window.location = window.location;
-}
+ // 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();
+});
</script>
</pre>
@@ -13,7 +13,6 @@ include $(DEPTH)/config/autoconf.mk
MOCHITEST_FILES = \
test_power_basics.html \
- test_power_non_permitted_app.html \
$(NULL)
MOCHITEST_BROWSER_FILES = \
@@ -4,24 +4,49 @@
<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.");
-power = navigator.mozPower;
-ok(power, "Should be able to access power manager with 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();
+}
+
+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>
@@ -1,39 +0,0 @@
-<!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>

0 comments on commit 08571ca

Please sign in to comment.