| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <html> | 2 <html> |
| 3 <script src="../../resources/js-test.js"></script> | 3 <script src="../../resources/js-test.js"></script> |
| 4 <body> | 4 <body> |
| 5 <script type="text/javascript"> | 5 <script type="text/javascript"> |
| 6 description("Test Battery Status API callback in WebView"); | 6 description("Test Battery Status API callback in WebView"); |
| 7 window.jsTestIsAsync = true; | 7 window.jsTestIsAsync = true; |
| 8 | 8 |
| 9 function isInteger(value) { |
| 10 if ((undefined === value) || (null === value)) { |
| 11 return false; |
| 12 } |
| 13 return value % 1 == 0; |
| 14 } |
| 15 |
| 9 var battery; | 16 var battery; |
| 10 function batteryStatusSuccess(batteryManager) { | 17 function batteryStatusSuccess(batteryManager) { |
| 11 debug('batteryStatusSuccess invoked'); | 18 debug('batteryStatusSuccess invoked'); |
| 12 battery = batteryManager; | 19 battery = batteryManager; |
| 13 | 20 |
| 14 // Validate values | 21 // Validate values |
| 15 shouldBeGreaterThanOrEqual('battery.level', '0'); | 22 shouldBeGreaterThanOrEqual('battery.level', '0'); |
| 16 shouldBeLessThanOrEqual('battery.level', '1'); | 23 shouldBeLessThanOrEqual('battery.level', '1'); |
| 17 // Check that level has at most 2 significant digits | 24 // Check that level has at most 2 significant digits |
| 18 shouldBeTrue('battery.level.toPrecision(2) === battery.level.toString()'
); | 25 shouldBeTrue('isInteger(battery.level * 100)'); |
| 19 shouldBeTrue('!battery.charging || battery.dischargingTime === Infinity'
); | 26 shouldBeTrue('!battery.charging || battery.dischargingTime === Infinity'
); |
| 20 shouldBeTrue('battery.charging || battery.chargingTime === Infinity'); | 27 shouldBeTrue('battery.charging || battery.chargingTime === Infinity'); |
| 21 finishJSTest(); | 28 finishJSTest(); |
| 22 } | 29 } |
| 23 | 30 |
| 24 function batteryStatusFailure() { | 31 function batteryStatusFailure() { |
| 25 testFailed("failed to successfully resolve the promise"); | 32 testFailed("failed to successfully resolve the promise"); |
| 26 finishJSTest(); | 33 finishJSTest(); |
| 27 } | 34 } |
| 28 | 35 |
| 29 navigator.getBattery().then(batteryStatusSuccess, batteryStatusFailure); | 36 navigator.getBattery().then(batteryStatusSuccess, batteryStatusFailure); |
| 30 </script> | 37 </script> |
| 31 </body> | 38 </body> |
| 32 </html> | 39 </html> |
| OLD | NEW |