| 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'); |
| 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 | 17 |
| 16 var promise1; | 18 var promise1; |
| 17 var mockBatteryInfo; | 19 var mockBatteryInfo; |
| 18 function setAndFireMockBatteryInfo(charging, chargingTime, dischargingTime, leve
l) { | 20 function setAndFireMockBatteryInfo(charging, chargingTime, dischargingTime, leve
l) { |
| 19 mockBatteryInfo = { charging: charging, | 21 mockBatteryInfo = { charging: charging, |
| 20 chargingTime: chargingTime, | 22 chargingTime: chargingTime, |
| 21 dischargingTime: dischargingTime, | 23 dischargingTime: dischargingTime, |
| 22 level: level }; | 24 level: level }; |
| 23 testRunner.didChangeBatteryStatus(charging, chargingTime, dischargingTime, l
evel); | 25 window.internals.updateBatteryStatus(charging, chargingTime, dischargingTime
, level); |
| 24 } | 26 } |
| 25 | 27 |
| 26 // compare obtained battery values with the mock values | 28 // compare obtained battery values with the mock values |
| 27 function checkBatteryInfo(batteryManager) { | 29 function checkBatteryInfo(batteryManager) { |
| 28 batteryInfo = batteryManager; | 30 batteryInfo = batteryManager; |
| 29 shouldBeDefined("batteryInfo"); | 31 shouldBeDefined("batteryInfo"); |
| 30 shouldBeDefined("mockBatteryInfo"); | 32 shouldBeDefined("mockBatteryInfo"); |
| 31 shouldBe('batteryInfo.charging', 'mockBatteryInfo.charging'); | 33 shouldBe('batteryInfo.charging', 'mockBatteryInfo.charging'); |
| 32 shouldBe('batteryInfo.chargingTime', 'mockBatteryInfo.chargingTime'); | 34 shouldBe('batteryInfo.chargingTime', 'mockBatteryInfo.chargingTime'); |
| 33 shouldBe('batteryInfo.dischargingTime', 'mockBatteryInfo.dischargingTime'); | 35 shouldBe('batteryInfo.dischargingTime', 'mockBatteryInfo.dischargingTime'); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 52 }, batteryStatusFailure); | 54 }, batteryStatusFailure); |
| 53 shouldBeTrue('promise1 === promise2'); | 55 shouldBeTrue('promise1 === promise2'); |
| 54 } | 56 } |
| 55 | 57 |
| 56 promise1 = navigator.getBattery(); | 58 promise1 = navigator.getBattery(); |
| 57 promise1.then(batteryStatusSuccess, batteryStatusFailure); | 59 promise1.then(batteryStatusSuccess, batteryStatusFailure); |
| 58 setAndFireMockBatteryInfo(false, 10, 20, 0.5); | 60 setAndFireMockBatteryInfo(false, 10, 20, 0.5); |
| 59 </script> | 61 </script> |
| 60 </body> | 62 </body> |
| 61 </html> | 63 </html> |
| OLD | NEW |