| 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 promises after resolve."); | 6 description("Test battery status API with multiple promises after resolve."); |
| 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'); | |
| 12 | 10 |
| 13 // Clean-up any unused battery manager objects from previous tests. | 11 // Clean-up any unused battery manager objects from previous tests. |
| 14 gc(); | 12 gc(); |
| 15 jsTestIsAsync = true; | 13 jsTestIsAsync = true; |
| 16 testRunner.waitUntilDone(); | 14 testRunner.waitUntilDone(); |
| 17 | 15 |
| 18 var promise1; | 16 var promise1; |
| 19 var mockBatteryInfo; | 17 var mockBatteryInfo; |
| 20 function setAndFireMockBatteryInfo(charging, chargingTime, dischargingTime, leve
l) { | 18 function setAndFireMockBatteryInfo(charging, chargingTime, dischargingTime, leve
l) { |
| 21 mockBatteryInfo = { charging: charging, | 19 mockBatteryInfo = { charging: charging, |
| 22 chargingTime: chargingTime, | 20 chargingTime: chargingTime, |
| 23 dischargingTime: dischargingTime, | 21 dischargingTime: dischargingTime, |
| 24 level: level }; | 22 level: level }; |
| 25 window.internals.updateBatteryStatus(charging, chargingTime, dischargingTime
, level); | 23 testRunner.didChangeBatteryStatus(charging, chargingTime, dischargingTime, l
evel); |
| 26 } | 24 } |
| 27 | 25 |
| 28 // compare obtained battery values with the mock values | 26 // compare obtained battery values with the mock values |
| 29 function checkBatteryInfo(batteryManager) { | 27 function checkBatteryInfo(batteryManager) { |
| 30 batteryInfo = batteryManager; | 28 batteryInfo = batteryManager; |
| 31 shouldBeDefined("batteryInfo"); | 29 shouldBeDefined("batteryInfo"); |
| 32 shouldBeDefined("mockBatteryInfo"); | 30 shouldBeDefined("mockBatteryInfo"); |
| 33 shouldBe('batteryInfo.charging', 'mockBatteryInfo.charging'); | 31 shouldBe('batteryInfo.charging', 'mockBatteryInfo.charging'); |
| 34 shouldBe('batteryInfo.chargingTime', 'mockBatteryInfo.chargingTime'); | 32 shouldBe('batteryInfo.chargingTime', 'mockBatteryInfo.chargingTime'); |
| 35 shouldBe('batteryInfo.dischargingTime', 'mockBatteryInfo.dischargingTime'); | 33 shouldBe('batteryInfo.dischargingTime', 'mockBatteryInfo.dischargingTime'); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 54 }, batteryStatusFailure); | 52 }, batteryStatusFailure); |
| 55 shouldBeTrue('promise1 === promise2'); | 53 shouldBeTrue('promise1 === promise2'); |
| 56 } | 54 } |
| 57 | 55 |
| 58 promise1 = navigator.getBattery(); | 56 promise1 = navigator.getBattery(); |
| 59 promise1.then(batteryStatusSuccess, batteryStatusFailure); | 57 promise1.then(batteryStatusSuccess, batteryStatusFailure); |
| 60 setAndFireMockBatteryInfo(false, 10, 20, 0.5); | 58 setAndFireMockBatteryInfo(false, 10, 20, 0.5); |
| 61 </script> | 59 </script> |
| 62 </body> | 60 </body> |
| 63 </html> | 61 </html> |
| OLD | NEW |