<!DOCTYPE html>
<html>
<script src="../../resources/js-test.js"></script>
<body>
<script type="text/javascript">
description("Test Battery Status API callback in WebView");
window.jsTestIsAsync = true;
var battery;
function batteryStatusSuccess(batteryManager) {
debug('batteryStatusSuccess invoked');
battery = batteryManager;
// Validate values
shouldBeGreaterThanOrEqual('battery.level', '0');
shouldBeLessThanOrEqual('battery.level', '1');
// Check that level has at most 2 significant digits
shouldBeTrue('battery.level.toPrecision(2) == battery.level');
shouldBeTrue('!battery.charging || battery.dischargingTime === Infinity');
shouldBeTrue('battery.charging || battery.chargingTime === Infinity');
finishJSTest();
}
function batteryStatusFailure() {
testFailed("failed to successfully resolve the promise");
finishJSTest();
}
navigator.getBattery().then(batteryStatusSuccess, batteryStatusFailure);
</script>
</body>
</html>