| 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 src="../resources/mojo-helpers.js"></script> | |
| 6 <script src="resources/mock-battery-monitor.js"></script> | |
| 7 <script> | 5 <script> |
| 8 description("Test basic API definitions."); | 6 description("Test basic API definitions."); |
| 9 | 7 |
| 10 if (!window.testRunner) | 8 if (!window.testRunner) |
| 11 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 | 12 |
| 13 // Clean-up any unused battery manager objects from previous tests. | 13 // Clean-up any unused battery manager objects from previous tests. |
| 14 gc(); | 14 gc(); |
| 15 jsTestIsAsync = true; | 15 jsTestIsAsync = true; |
| 16 testRunner.waitUntilDone(); | 16 testRunner.waitUntilDone(); |
| 17 | 17 |
| 18 var mockBatteryInfo; |
| 19 function setAndFireMockBatteryInfo(charging, chargingTime, dischargingTime, leve
l) { |
| 20 mockBatteryInfo = { charging: charging, |
| 21 chargingTime: chargingTime, |
| 22 dischargingTime: dischargingTime, |
| 23 level: level }; |
| 24 window.internals.updateBatteryStatus(charging, chargingTime, dischargingTime
, level); |
| 25 } |
| 26 |
| 18 var battery; | 27 var battery; |
| 19 function batteryStatusSuccess(batteryManager) { | 28 function batteryStatusSuccess(batteryManager) { |
| 20 debug('batteryStatusSuccess invoked'); | 29 debug('batteryStatusSuccess invoked'); |
| 21 battery = batteryManager; | 30 battery = batteryManager; |
| 22 | 31 |
| 23 shouldBeDefined("battery"); | 32 shouldBeDefined("battery"); |
| 24 shouldBeNonNull("battery"); | 33 shouldBeNonNull("battery"); |
| 25 shouldBeDefined("battery.charging"); | 34 shouldBeDefined("battery.charging"); |
| 26 shouldBeDefined("battery.chargingTime"); | 35 shouldBeDefined("battery.chargingTime"); |
| 27 shouldBeDefined("battery.dischargingTime"); | 36 shouldBeDefined("battery.dischargingTime"); |
| 28 shouldBeDefined("battery.level"); | 37 shouldBeDefined("battery.level"); |
| 29 | 38 |
| 30 testIfBatteryStatusIsUpToDate(batteryManager); | 39 shouldBe('battery.charging', 'mockBatteryInfo.charging'); |
| 40 shouldBe('battery.chargingTime', 'mockBatteryInfo.chargingTime'); |
| 41 shouldBe('battery.dischargingTime', 'mockBatteryInfo.dischargingTime'); |
| 42 shouldBe('battery.level', 'mockBatteryInfo.level'); |
| 31 | 43 |
| 32 shouldBeTrue("typeof battery.onchargingchange == 'object'"); | 44 shouldBeTrue("typeof battery.onchargingchange == 'object'"); |
| 33 shouldBeTrue("typeof battery.onchargingtimechange == 'object'"); | 45 shouldBeTrue("typeof battery.onchargingtimechange == 'object'"); |
| 34 shouldBeTrue("typeof battery.ondischargingtimechange == 'object'"); | 46 shouldBeTrue("typeof battery.ondischargingtimechange == 'object'"); |
| 35 shouldBeTrue("typeof battery.onlevelchange == 'object'"); | 47 shouldBeTrue("typeof battery.onlevelchange == 'object'"); |
| 36 | 48 |
| 37 shouldBeTrue("'onchargingchange' in battery"); | 49 shouldBeTrue("'onchargingchange' in battery"); |
| 38 shouldBeTrue("'onchargingtimechange' in battery"); | 50 shouldBeTrue("'onchargingtimechange' in battery"); |
| 39 shouldBeTrue("'ondischargingtimechange' in battery"); | 51 shouldBeTrue("'ondischargingtimechange' in battery"); |
| 40 shouldBeTrue("'onlevelchange' in battery"); | 52 shouldBeTrue("'onlevelchange' in battery"); |
| 41 | 53 |
| 42 setTimeout(finishJSTest, 0); | 54 setTimeout(finishJSTest, 0); |
| 43 } | 55 } |
| 44 | 56 |
| 45 var promise; | 57 function batteryStatusFailure() { |
| 46 mockBatteryMonitorReady.then(() => { | 58 testFailed('failed to successfully resolve the promise'); |
| 47 promise = navigator.getBattery(); | 59 setTimeout(finishJSTest, 0); |
| 48 shouldBeDefined("promise"); | 60 } |
| 49 shouldBeDefined("promise.then"); | 61 |
| 50 promise.then(batteryStatusSuccess, batteryStatusFailure); | 62 promise = navigator.getBattery(); |
| 51 setAndFireMockBatteryInfo(false, 10, 20, 0.5); | 63 shouldBeDefined("promise"); |
| 52 }); | 64 shouldBeDefined("promise.then"); |
| 65 promise.then(batteryStatusSuccess, batteryStatusFailure); |
| 66 setAndFireMockBatteryInfo(false, 10, 20, 0.5); |
| 53 </script> | 67 </script> |
| 54 </body> | 68 </body> |
| 55 </html> | 69 </html> |
| OLD | NEW |