summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/battery-status/restricted-level-precision.html
blob: 8561b46732184abcfa767798b0baefe0f13f12a4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<!DOCTYPE html>
<html>
<body>
<script src="../resources/js-test.js"></script>
<script>
description("Test to ensure level is reported with restricted precision.");

if (!window.testRunner)
    debug('This test cannot be run without the TestRunner');
if (!window.internals)
    debug('This test cannot be run without the window.internals');

// Clean-up any unused battery manager objects from previous tests.
gc();
jsTestIsAsync = true;
testRunner.waitUntilDone();

var levelFullPrecision = 0.556789;
var levelRounded = 0.56;

function setAndFireMockBatteryInfo(charging, chargingTime, dischargingTime, level) {
    window.internals.updateBatteryStatus(charging, chargingTime, dischargingTime, level);
}

var battery;
function batteryStatusSuccess(batteryManager) {
    debug('batteryStatusSuccess invoked');
    battery = batteryManager;
    shouldBe('battery.level', 'levelRounded');
    setTimeout(finishJSTest, 0);
}

function batteryStatusFailure() {
    testFailed('failed to successfully resolve the promise');
    setTimeout(finishJSTest, 0);
}

navigator.getBattery().then(batteryStatusSuccess, batteryStatusFailure);
setAndFireMockBatteryInfo(false, 10, 20, levelFullPrecision);
</script>
</body>
</html>