dom/battery/test/test_battery_basics.html
author Paul Adenot <paul@paul.cx>
Fri, 02 Mar 2018 19:27:57 +0100
changeset 409026 dfabe184b3677d87c55eb9e92f04a6a49f6dbc29
parent 320010 6069dc9afe31c75b809df062af362df76faf25cc
child 451420 b15b5b6dbce20140369dbe829b26f7fdbb0bf93a
permissions -rw-r--r--
Bug 1437366 - Add a way to force the sample-rate used for a MediaStreamGraph. r=pehrsons MozReview-Commit-ID: 4ICQiNKbUpJ

<!DOCTYPE HTML>
<html>
<head>
  <title>Test for Battery API</title>
  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/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();

/** Test for Battery API **/
ok("getBattery" in navigator, "navigator.getBattery should exist");
ok(!("battery" in navigator), "navigator.battery should not exist");

navigator.getBattery().then(function (battery) {
  ok(battery.level >= 0.0 && battery.level <= 1.0, "Battery level " + battery.level + " should be in the range [0.0, 1.0]");

  SpecialPowers.pushPrefEnv({"set": [["dom.battery.test.default", true]]}, function () {
    ok(battery.charging, "Battery should be charging by default");
    is(battery.chargingTime, 0, "Battery chargingTime " + battery.chargingTime + " should be zero by default");
    is(battery.dischargingTime, Infinity, "Battery dischargingTime should be Infinity by default");
    is(battery.level, 1.0, "Battery level " + battery.level + " should be 1.0 by default");

    SimpleTest.finish();
  });
});

</script>
</pre>
</body>
</html>