OLD | NEW |
1 <html> | 1 <html> |
2 <head> | 2 <head> |
3 <title>Battery Status API test : promise resolution</title> | 3 <title>Battery Status API test : promise resolution</title> |
4 <script type="text/javascript"> | 4 <script type="text/javascript"> |
5 | 5 |
6 function checkBatteryInfo(battery) { | 6 function checkBatteryInfo(battery) { |
7 return battery.charging && | 7 return battery.charging && |
8 battery.chargingTime == 100 && | 8 battery.chargingTime == 100 && |
9 battery.dischargingTime == Infinity && | 9 battery.dischargingTime == Infinity && |
10 battery.level == 0.5; | 10 battery.level == 0.5; |
11 } | 11 } |
12 | 12 |
13 function testBattery() { | 13 function testBattery() { |
14 navigator.getBattery().then( | 14 navigator.getBattery().then( |
15 function(battery) { | 15 function(battery) { |
16 if (checkBatteryInfo(battery)) | 16 if (checkBatteryInfo(battery)) |
17 pass(); | 17 pass(); |
18 else | 18 else |
19 fail(); | 19 fail(); |
20 }, fail()); | 20 }, fail()); |
21 } | 21 } |
22 | 22 |
23 function pass() { | 23 function pass() { |
24 document.getElementById('status').innerHTML = 'PASS'; | 24 document.getElementById('status').innerHTML = 'PASS'; |
25 document.location = '#pass'; | 25 document.location = '#pass'; |
26 } | 26 } |
27 | 27 |
28 function fail() { | 28 function fail() { |
29 document.location = '#fail'; | 29 document.location = '#fail'; |
30 } | 30 } |
31 </script> | 31 </script> |
32 </head> | 32 </head> |
33 <body onLoad="testBattery()"> | 33 <body onLoad="testBattery()"> |
34 <div id="status">FAIL</div> | 34 <div id="status">FAIL</div> |
35 </body> | 35 </body> |
36 </html> | 36 </html> |
OLD | NEW |