OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <html> | 2 <html> |
3 <body> | 3 <body> |
4 <script src="../resources/js-test.js"></script> | 4 <script src="../resources/js-test.js"></script> |
5 <script> | 5 <script> |
6 description("Test battery status API with multiple windows."); | 6 description("Test battery status API with multiple windows."); |
7 | 7 |
8 if (!window.testRunner) | 8 if (!window.testRunner) |
9 debug('This test cannot be run without the TestRunner'); | 9 debug('This test cannot be run without the TestRunner'); |
| 10 if (!window.internals) |
| 11 debug('This test cannot be run without the window.internals'); |
10 | 12 |
11 // Clean-up any unused battery manager objects from previous tests. | 13 // Clean-up any unused battery manager objects from previous tests. |
12 gc(); | 14 gc(); |
13 jsTestIsAsync = true; | 15 jsTestIsAsync = true; |
14 testRunner.waitUntilDone(); | 16 testRunner.waitUntilDone(); |
15 testRunner.setCanOpenWindows(); | 17 testRunner.setCanOpenWindows(); |
16 testRunner.setCloseRemainingWindowsWhenComplete(true); | 18 testRunner.setCloseRemainingWindowsWhenComplete(true); |
17 | 19 |
18 var mockBatteryInfo; | 20 var mockBatteryInfo; |
19 function setAndFireMockBatteryInfo(charging, chargingTime, dischargingTime, leve
l) { | 21 function setAndFireMockBatteryInfo(charging, chargingTime, dischargingTime, leve
l) { |
20 mockBatteryInfo = { charging: charging, | 22 mockBatteryInfo = { charging: charging, |
21 chargingTime: chargingTime, | 23 chargingTime: chargingTime, |
22 dischargingTime: dischargingTime, | 24 dischargingTime: dischargingTime, |
23 level: level }; | 25 level: level }; |
24 testRunner.didChangeBatteryStatus(charging, chargingTime, dischargingTime, l
evel); | 26 window.internals.updateBatteryStatus(charging, chargingTime, dischargingTime
, level); |
25 } | 27 } |
26 | 28 |
27 // compare obtained battery values with the mock values | 29 // compare obtained battery values with the mock values |
28 function checkBatteryInfo(batteryManager) { | 30 function checkBatteryInfo(batteryManager) { |
29 batteryInfo = batteryManager; | 31 batteryInfo = batteryManager; |
30 shouldBeDefined("batteryInfo"); | 32 shouldBeDefined("batteryInfo"); |
31 shouldBeDefined("mockBatteryInfo"); | 33 shouldBeDefined("mockBatteryInfo"); |
32 shouldBe('batteryInfo.charging', 'mockBatteryInfo.charging'); | 34 shouldBe('batteryInfo.charging', 'mockBatteryInfo.charging'); |
33 shouldBe('batteryInfo.chargingTime', 'mockBatteryInfo.chargingTime'); | 35 shouldBe('batteryInfo.chargingTime', 'mockBatteryInfo.chargingTime'); |
34 shouldBe('batteryInfo.dischargingTime', 'mockBatteryInfo.dischargingTime'); | 36 shouldBe('batteryInfo.dischargingTime', 'mockBatteryInfo.dischargingTime'); |
(...skipping 16 matching lines...) Expand all Loading... |
51 checkBatteryInfo(battery2); | 53 checkBatteryInfo(battery2); |
52 setTimeout(finishJSTest, 0); | 54 setTimeout(finishJSTest, 0); |
53 }, batteryStatusFailure); | 55 }, batteryStatusFailure); |
54 } | 56 } |
55 | 57 |
56 navigator.getBattery().then(batteryStatusSuccess, batteryStatusFailure); | 58 navigator.getBattery().then(batteryStatusSuccess, batteryStatusFailure); |
57 setAndFireMockBatteryInfo(false, 10, 20, 0.5); | 59 setAndFireMockBatteryInfo(false, 10, 20, 0.5); |
58 </script> | 60 </script> |
59 </body> | 61 </body> |
60 </html> | 62 </html> |
OLD | NEW |