Get foreground tab on Android
[chromium-blink-merge.git] / content / test / data / device_orientation / device_inertial_sensor_diagnostics.html
blob796357d2bb269595861aed3f9d5650a257fddb94
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <title>Device Motion/Orientation diagnostic measurements</title>
5 </head>
6 <body>
7 <table>
8 <tr>
9 <td colspan="2">
10 <hr>
11 </td>
12 </tr>
13 <tr>
14 <td>Motion Supported</td>
15 <td width="250px" id="motionSupported"></td>
16 </tr>
17 <tr>
18 <td>motion acceleration (x, y, z)</td>
19 <td id="motionAccel"></td>
20 </tr>
21 <tr>
22 <td>motion acceleration incl. gravity (x, y, z)</td>
23 <td id="motionAccelG"></td>
24 </tr>
25 <tr>
26 <td>motion rotation rate (&alpha;, &beta;, &gamma;)</td>
27 <td id="motionRotation"></td>
28 </tr>
29 <tr>
30 <td>real-time motion frequency (Hz)</td>
31 <td id="motionFreq"></td>
32 </tr>
33 <tr>
34 <td>motion max frequency (Hz)</td>
35 <td id="motionMaxFreq"></td>
36 </tr>
37 <tr>
38 <td>motion stated interval</td>
39 <td id="motionInterval"></td>
40 </tr>
41 <tr>
42 <td colspan="2">
43 <hr>
44 </td>
45 </tr>
46 <tr>
47 <td>Orientation Supported</td>
48 <td id="orientationSupported"></td>
49 </tr>
50 <tr>
51 <td>orientation values (&alpha;, &beta;, &gamma;)</td>
52 <td id="orientationValues"></td>
53 </tr>
54 <tr>
55 <td>orientation absolute</td>
56 <td id="orientationAbsolute"></td>
57 </tr>
58 <tr>
59 <td>orientation frequency (Hz)</td>
60 <td id="orientationFreq"></td>
61 </tr>
62 <tr>
63 <td>orientation max frequency (Hz)</td>
64 <td id="orientationMaxFreq"></td>
65 </tr>
66 </table>
68 <script type="text/javascript">
69 var numberMotionEvents = 0;
70 var numberOrientationEvents = 0;
71 var motionMaxFreq = 0;
72 var orientationMaxFreq = 0;
73 var updateIntervalDelaySec = 2;
75 function onMotion(event) {
76 document.getElementById('motionAccel').innerHTML =
77 roundToFixedArray([event.acceleration.x,
78 event.acceleration.y,
79 event.acceleration.z]);
81 document.getElementById("motionAccelG").innerHTML =
82 roundToFixedArray([event.accelerationIncludingGravity.x,
83 event.accelerationIncludingGravity.y,
84 event.accelerationIncludingGravity.z]);
86 document.getElementById("motionRotation").innerHTML =
87 roundToFixedArray([event.rotationRate.alpha,
88 event.rotationRate.beta,
89 event.rotationRate.gamma]);
91 document.getElementById("motionInterval").innerHTML = event.interval;
92 ++numberMotionEvents;
95 function roundToFixed(value) {
96 return value==null ? value : value.toFixed(4);
99 function roundToFixedArray(values) {
100 return '[' + values.map(function(value) {
101 return roundToFixed(value);
102 }).join(',') + ']';
105 function onOrientation(event) {
106 document.getElementById("orientationValues").innerHTML =
107 roundToFixedArray([event.alpha, event.beta, event.gamma]);
108 document.getElementById("orientationAbsolute").innerHTML = event.absolute;
109 ++numberOrientationEvents;
112 function updateMeasurements() {
113 var motionFreq = numberMotionEvents/updateIntervalDelaySec;
114 var orientationFreq = numberOrientationEvents/updateIntervalDelaySec;
115 motionMaxFreq = Math.max(motionMaxFreq, motionFreq);
116 orientationMaxFreq = Math.max(orientationMaxFreq, orientationFreq);
118 document.getElementById("motionFreq").innerHTML = motionFreq;
119 document.getElementById("motionMaxFreq").innerHTML = motionMaxFreq;
120 document.getElementById("orientationFreq").innerHTML = orientationFreq;
121 document.getElementById("orientationMaxFreq").innerHTML = orientationMaxFreq;
123 numberMotionEvents = 0;
124 numberOrientationEvents = 0;
127 var motionSupported="not supported";
128 var orientationSupported="not supported";
130 if (window.DeviceMotionEvent) {
131 window.addEventListener('devicemotion', onMotion)
132 motionSupported="supported";
134 document.getElementById("motionSupported").innerHTML = motionSupported;
136 if (window.DeviceOrientationEvent) {
137 window.addEventListener('deviceorientation', onOrientation);
138 orientationSupported = "supported";
140 document.getElementById("orientationSupported").innerHTML = orientationSupported;
142 setInterval(function(){updateMeasurements()}, updateIntervalDelaySec*1000);
144 </script>
146 </body>
147 </html>