Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(191)

Side by Side Diff: content/test/data/battery_status/battery_status_manual_test.html

Issue 464073003: Battery Status API: manual webpage test. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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>
48
49 <script>
50 var numberUpdates = 0;
51 var battery;
52
53 function batterySuccess(batteryManager) {
54 battery = batteryManager;
55 document.getElementById("promiseStatus").innerHTML = "success";
56 updateBatteryInformation();
57 battery.addEventListener('chargingchange', function() {
Michael van Ouwerkerk 2014/08/18 15:46:06 I think none of these addEventListener calls need
timvolodine 2014/08/20 11:28:03 that's right. Done.
58 updateBatteryInformation();
59 });
60 battery.addEventListener('chargingtimechange', function() {
61 updateBatteryInformation();
62 });
63 battery.addEventListener('dischargingtimechange', function() {
64 updateBatteryInformation();
65 });
66 battery.addEventListener('levelchange', function() {
67 updateBatteryInformation();
68 });
69 }
70
71 function batteryFailure() {
72 document.getElementById("promiseStatus").innerHTML = "failed";
73 }
74
75 function ConvertToHMS(durationInSeconds) {
76 if (!isFinite(durationInSeconds)) return "";
77 var hours = Math.floor(durationInSeconds / 3600);
78 var seconds = durationInSeconds % 60;
79 var minutes = Math.floor((durationInSeconds - hours * 3600 - seconds) / 60);
80 return " (" + hours + "h:" + minutes + "m:" + seconds + "s)";
81 }
82
83 function updateBatteryInformation() {
84 document.getElementById("charging").innerHTML = battery.charging;
85 document.getElementById("chargingTime").innerHTML = battery.chargingTime + ConvertToHMS(battery.chargingTime);
86 document.getElementById("dischargingTime").innerHTML = battery.dischargi ngTime + ConvertToHMS(battery.dischargingTime);
87 document.getElementById("level").innerHTML = battery.level;
88 numberUpdates++;
89 document.getElementById("numberUpdates").innerHTML = numberUpdates;
90 }
91
92 document.getElementById("promiseStatus").innerHTML = "pending";
93 document.getElementById("numberUpdates").innerHTML = numberUpdates;
94 navigator.getBattery().then(batterySuccess, batteryFailure);
95 </script>
96 </body>
97 </html>
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698