[refactor] More post-NSS WebCrypto cleanups (utility functions).
[chromium-blink-merge.git] / content / test / data / battery_status / battery_status_manual_test.html
blob0c64ec57baae81ccf2663fc88578fc5d7cfdba27
1 <html>
2 <body>
3 <head>
4 <meta name="description" content="Test for Battery Status API"/>
5 <title>Battery Status API</title>
6 </head>
7 <body>
8 <table>
9 <tr>
10 <td>Battery Status API</td>
11 <td width="250px"></td>
12 </tr>
13 <tr>
14 <td colspan="2">
15 <hr>
16 </td>
17 </tr>
18 <tr>
19 <td>charging</td>
20 <td id="charging"></td>
21 </tr>
22 <tr>
23 <td>chargingTime</td>
24 <td id="chargingTime"></td>
25 </tr>
26 <tr>
27 <td>dischargingTime</td>
28 <td id="dischargingTime"></td>
29 </tr>
30 <tr>
31 <td>battery level</td>
32 <td id="level"></td>
33 </tr>
34 <tr>
35 <td colspan="2">
36 <hr>
37 </td>
38 </tr>
39 <tr>
40 <td>promise status</td>
41 <td id="promiseStatus"></td>
42 </tr>
43 <tr>
44 <td>number of updates</td>
45 <td id="numberUpdates"></td>
46 </tr>
47 </table>
49 <script>
50 var numberUpdates = 0;
51 var battery;
53 function batterySuccess(batteryManager) {
54 battery = batteryManager;
55 document.getElementById("promiseStatus").innerHTML = "success";
56 updateBatteryInformation();
57 battery.addEventListener('chargingchange', updateBatteryInformation);
58 battery.addEventListener('chargingtimechange', updateBatteryInformation);
59 battery.addEventListener('dischargingtimechange', updateBatteryInformation);
60 battery.addEventListener('levelchange', updateBatteryInformation);
63 function batteryFailure() {
64 document.getElementById("promiseStatus").innerHTML = "failed";
67 function ConvertToHMS(durationInSeconds) {
68 if (!isFinite(durationInSeconds)) return "";
69 var hours = Math.floor(durationInSeconds / 3600);
70 var seconds = durationInSeconds % 60;
71 var minutes = Math.floor((durationInSeconds - hours * 3600 - seconds) / 60);
72 return " (" + hours + "h:" + minutes + "m:" + seconds + "s)";
75 function updateBatteryInformation() {
76 document.getElementById("charging").innerHTML = battery.charging;
77 document.getElementById("chargingTime").innerHTML = battery.chargingTime + ConvertToHMS(battery.chargingTime);
78 document.getElementById("dischargingTime").innerHTML = battery.dischargingTime + ConvertToHMS(battery.dischargingTime);
79 document.getElementById("level").innerHTML = battery.level;
80 numberUpdates++;
81 document.getElementById("numberUpdates").innerHTML = numberUpdates;
84 document.getElementById("promiseStatus").innerHTML = "pending";
85 document.getElementById("numberUpdates").innerHTML = numberUpdates;
86 navigator.getBattery().then(batterySuccess, batteryFailure);
87 </script>
88 </body>
89 </html>