Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / battery-status / multiple-promises-after-resolve.html
blob2e926fd58480266c746b3bda46ae801b1be80352
1 <!DOCTYPE html>
2 <html>
3 <body>
4 <script src="../resources/js-test.js"></script>
5 <script>
6 description("Test battery status API with multiple promises after resolve.");
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 promise1;
17 var mockBatteryInfo;
18 function setAndFireMockBatteryInfo(charging, chargingTime, dischargingTime, level) {
19 mockBatteryInfo = { charging: charging,
20 chargingTime: chargingTime,
21 dischargingTime: dischargingTime,
22 level: level };
23 testRunner.didChangeBatteryStatus(charging, chargingTime, dischargingTime, level);
26 // compare obtained battery values with the mock values
27 function checkBatteryInfo(batteryManager) {
28 batteryInfo = batteryManager;
29 shouldBeDefined("batteryInfo");
30 shouldBeDefined("mockBatteryInfo");
31 shouldBe('batteryInfo.charging', 'mockBatteryInfo.charging');
32 shouldBe('batteryInfo.chargingTime', 'mockBatteryInfo.chargingTime');
33 shouldBe('batteryInfo.dischargingTime', 'mockBatteryInfo.dischargingTime');
34 shouldBe('batteryInfo.level', 'mockBatteryInfo.level');
37 function batteryStatusFailure() {
38 testFailed('failed to successfully resolve the promise');
39 setTimeout(finishJSTest, 0);
42 function batteryStatusSuccess(battery) {
43 debug('resolution number 1');
44 checkBatteryInfo(battery);
46 promise2 = navigator.getBattery();
47 promise2.then(
48 function(battery) {
49 debug('resolution number 2');
50 checkBatteryInfo(battery);
51 setTimeout(finishJSTest, 0);
52 }, batteryStatusFailure);
53 shouldBeTrue('promise1 === promise2');
56 promise1 = navigator.getBattery();
57 promise1.then(batteryStatusSuccess, batteryStatusFailure);
58 setAndFireMockBatteryInfo(false, 10, 20, 0.5);
59 </script>
60 </body>
61 </html>