OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <html> |
| 3 <body> |
| 4 <script src="../resources/js-test.js"></script> |
| 5 <script> |
| 6 description("Test basic API definitions."); |
| 7 |
| 8 if (!window.testRunner) |
| 9 debug('This test cannot be run without the TestRunner'); |
| 10 |
| 11 jsTestIsAsync = true; |
| 12 |
| 13 var mockBatteryInfo; |
| 14 function setAndFireMockBatteryInfo(charging, chargingTime, dischargingTime, leve
l) { |
| 15 mockBatteryInfo = { charging: charging, |
| 16 chargingTime: chargingTime, |
| 17 dischargingTime: dischargingTime, |
| 18 level: level }; |
| 19 testRunner.didChangeBatteryStatus(charging, chargingTime, dischargingTime, l
evel); |
| 20 } |
| 21 |
| 22 function batteryStatusSuccess(batteryManager) { |
| 23 debug('batteryStatusSuccess invoked'); |
| 24 battery = batteryManager; |
| 25 |
| 26 shouldBeDefined("battery"); |
| 27 shouldBeNonNull("battery"); |
| 28 shouldBeDefined("battery.charging"); |
| 29 shouldBeDefined("battery.chargingTime"); |
| 30 shouldBeDefined("battery.dischargingTime"); |
| 31 shouldBeDefined("battery.level"); |
| 32 |
| 33 shouldBe('battery.charging', 'mockBatteryInfo.charging'); |
| 34 shouldBe('battery.chargingTime', 'mockBatteryInfo.chargingTime'); |
| 35 shouldBe('battery.dischargingTime', 'mockBatteryInfo.dischargingTime'); |
| 36 shouldBe('battery.level', 'mockBatteryInfo.level'); |
| 37 |
| 38 shouldBeTrue("typeof battery.onchargingchange == 'object'"); |
| 39 shouldBeTrue("typeof battery.onchargingtimechange == 'object'"); |
| 40 shouldBeTrue("typeof battery.ondischargingtimechange == 'object'"); |
| 41 shouldBeTrue("typeof battery.onlevelchange == 'object'"); |
| 42 |
| 43 shouldBeTrue("battery.hasOwnProperty('onchargingchange')"); |
| 44 shouldBeTrue("battery.hasOwnProperty('onchargingtimechange')"); |
| 45 shouldBeTrue("battery.hasOwnProperty('ondischargingtimechange')"); |
| 46 shouldBeTrue("battery.hasOwnProperty('onlevelchange')"); |
| 47 |
| 48 shouldBeTrue("'onchargingchange' in battery"); |
| 49 shouldBeTrue("'onchargingtimechange' in battery"); |
| 50 shouldBeTrue("'ondischargingtimechange' in battery"); |
| 51 shouldBeTrue("'onlevelchange' in battery"); |
| 52 |
| 53 setTimeout(cleanupAndFinish, 0); |
| 54 } |
| 55 |
| 56 function cleanupAndFinish() { |
| 57 // stops updating battery and clears current battery status. |
| 58 window.testRunner.setPageVisibility("hidden"); |
| 59 finishJSTest(); |
| 60 } |
| 61 |
| 62 function batteryStatusFailure() { |
| 63 testFailed('failed to successfully resolve the promise'); |
| 64 setTimeout(cleanupAndFinish, 0); |
| 65 } |
| 66 |
| 67 promise = navigator.getBattery(); |
| 68 shouldBeDefined("promise"); |
| 69 shouldBeDefined("promise.then"); |
| 70 promise.then(batteryStatusSuccess, batteryStatusFailure); |
| 71 setAndFireMockBatteryInfo(false, 10, 20, 0.5); |
| 72 </script> |
| 73 </body> |
| 74 </html> |
OLD | NEW |