Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / battery-status / api-defined.html
blobea2a985e5fd7460c0fd4f98b096699499ab4e7ea
1 <!DOCTYPE html>
2 <html>
3 <body>
4 <script src="../resources/js-test.js"></script>
5 <script>
6 description("Test basic API definitions.");
8 if (!window.testRunner)
9 debug('This test cannot be run without the TestRunner');
11 // Clean-up any unused battery manager objects from previous tests.
12 gc();
13 jsTestIsAsync = true;
14 testRunner.waitUntilDone();
16 var mockBatteryInfo;
17 function setAndFireMockBatteryInfo(charging, chargingTime, dischargingTime, level) {
18 mockBatteryInfo = { charging: charging,
19 chargingTime: chargingTime,
20 dischargingTime: dischargingTime,
21 level: level };
22 testRunner.didChangeBatteryStatus(charging, chargingTime, dischargingTime, level);
25 var battery;
26 function batteryStatusSuccess(batteryManager) {
27 debug('batteryStatusSuccess invoked');
28 battery = batteryManager;
30 shouldBeDefined("battery");
31 shouldBeNonNull("battery");
32 shouldBeDefined("battery.charging");
33 shouldBeDefined("battery.chargingTime");
34 shouldBeDefined("battery.dischargingTime");
35 shouldBeDefined("battery.level");
37 shouldBe('battery.charging', 'mockBatteryInfo.charging');
38 shouldBe('battery.chargingTime', 'mockBatteryInfo.chargingTime');
39 shouldBe('battery.dischargingTime', 'mockBatteryInfo.dischargingTime');
40 shouldBe('battery.level', 'mockBatteryInfo.level');
42 shouldBeTrue("typeof battery.onchargingchange == 'object'");
43 shouldBeTrue("typeof battery.onchargingtimechange == 'object'");
44 shouldBeTrue("typeof battery.ondischargingtimechange == 'object'");
45 shouldBeTrue("typeof battery.onlevelchange == 'object'");
47 shouldBeTrue("'onchargingchange' in battery");
48 shouldBeTrue("'onchargingtimechange' in battery");
49 shouldBeTrue("'ondischargingtimechange' in battery");
50 shouldBeTrue("'onlevelchange' in battery");
52 setTimeout(finishJSTest, 0);
55 function batteryStatusFailure() {
56 testFailed('failed to successfully resolve the promise');
57 setTimeout(finishJSTest, 0);
60 promise = navigator.getBattery();
61 shouldBeDefined("promise");
62 shouldBeDefined("promise.then");
63 promise.then(batteryStatusSuccess, batteryStatusFailure);
64 setAndFireMockBatteryInfo(false, 10, 20, 0.5);
65 </script>
66 </body>
67 </html>