test_battery_basics.html (1314B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <title>Test for Battery API</title> 5 <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 6 <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/> 7 </head> 8 <body> 9 <p id="display"></p> 10 <div id="content" style="display: none"> 11 </div> 12 <pre id="test"> 13 <script type="application/javascript"> 14 15 "use strict"; 16 17 SimpleTest.waitForExplicitFinish(); 18 19 /** Test for Battery API */ 20 ok("getBattery" in navigator, "navigator.getBattery should exist"); 21 ok(!("battery" in navigator), "navigator.battery should not exist"); 22 23 navigator.getBattery().then(function(battery) { 24 ok(battery.level >= 0.0 && battery.level <= 1.0, "Battery level " + battery.level + " should be in the range [0.0, 1.0]"); 25 26 SpecialPowers.pushPrefEnv({"set": [["dom.battery.test.default", true]]}, function() { 27 ok(battery.charging, "Battery should be charging by default"); 28 is(battery.chargingTime, 0, "Battery chargingTime " + battery.chargingTime + " should be zero by default"); 29 is(battery.dischargingTime, Infinity, "Battery dischargingTime should be Infinity by default"); 30 is(battery.level, 1.0, "Battery level " + battery.level + " should be 1.0 by default"); 31 32 SimpleTest.finish(); 33 }); 34 }); 35 36 </script> 37 </pre> 38 </body> 39 </html>