Bug 802312 - Fix test_power_basics.html to work on b2g. r=kchen
☠☠ backed out by b9892a0403e4 ☠ ☠
authorMartijn Wargers <martijn.martijn@gmail.com>
Thu, 18 Oct 2012 21:44:15 -0400
changeset 110872 fe90dfc8a30a1fce0cc2cf8078ac871a3f300399
parent 110871 811bf58c47f2d8ac629a1b805fa97670e4c626fb
child 110873 4a4acb36e6701b595910f179d2930e5d006e17a5
push id93
push usernmatsakis@mozilla.com
push dateWed, 31 Oct 2012 21:26:57 +0000
reviewerskchen
bugs802312
milestone19.0a1
Bug 802312 - Fix test_power_basics.html to work on b2g. r=kchen
dom/power/test/test_power_basics.html
--- a/dom/power/test/test_power_basics.html
+++ b/dom/power/test/test_power_basics.html
@@ -4,31 +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>
+<iframe onload="startTest()"></iframe>
 <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
 
-SpecialPowers.removePermission("power", document);
+SimpleTest.waitForExplicitFinish();
 
-power = navigator.mozPower;
-ok(!power, "Shouldn't be able to access power manager without permission.");
+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();
+}
 
-SpecialPowers.addPermission("power", true, document);
+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.");
 
-power = navigator.mozPower;
-ok(power, "Shouldn 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>
 </pre>
 </body>
 </html>