OLD | NEW |
1 <html> | 1 <html> |
2 <head> | 2 <head> |
3 <title>DeviceMotion test</title> | 3 <title>DeviceMotion test</title> |
4 <script type="text/javascript"> | 4 <script type="text/javascript"> |
| 5 let expectedInterval = Math.floor(1000 / 60); |
5 function checkMotionEvent(event) { | 6 function checkMotionEvent(event) { |
6 return event.acceleration.x == 1 && | 7 return event.acceleration.x == 1 && |
7 event.acceleration.y == 2 && | 8 event.acceleration.y == 2 && |
8 event.acceleration.z == 3 && | 9 event.acceleration.z == 3 && |
9 event.accelerationIncludingGravity.x == 4 && | 10 event.accelerationIncludingGravity.x == 4 && |
10 event.accelerationIncludingGravity.y == 5 && | 11 event.accelerationIncludingGravity.y == 5 && |
11 event.accelerationIncludingGravity.z == 6 && | 12 event.accelerationIncludingGravity.z == 6 && |
12 event.rotationRate.alpha == 7 && | 13 event.rotationRate.alpha == 7 && |
13 event.rotationRate.beta == 8 && | 14 event.rotationRate.beta == 8 && |
14 event.rotationRate.gamma == 9 && | 15 event.rotationRate.gamma == 9 && |
15 event.interval == 100; | 16 event.interval == expectedInterval; |
16 } | 17 } |
17 | 18 |
18 function onMotion(event) { | 19 function onMotion(event) { |
19 if (checkMotionEvent(event)) { | 20 if (checkMotionEvent(event)) { |
20 window.removeEventListener('devicemotion', onMotion); | 21 window.removeEventListener('devicemotion', onMotion); |
21 pass(); | 22 pass(); |
22 } else { | 23 } else { |
23 fail(); | 24 fail(); |
24 } | 25 } |
25 } | 26 } |
26 | 27 |
27 function pass() { | 28 function pass() { |
28 document.getElementById('status').innerHTML = 'PASS'; | 29 document.getElementById('status').innerHTML = 'PASS'; |
29 document.location = '#pass'; | 30 document.location = '#pass'; |
30 } | 31 } |
31 | 32 |
32 function fail() { | 33 function fail() { |
33 document.location = '#fail'; | 34 document.location = '#fail'; |
34 } | 35 } |
35 </script> | 36 </script> |
36 </head> | 37 </head> |
37 <body onLoad="window.addEventListener('devicemotion', onMotion)"> | 38 <body onLoad="window.addEventListener('devicemotion', onMotion)"> |
38 <div id="status">FAIL</div> | 39 <div id="status">FAIL</div> |
39 </body> | 40 </body> |
40 </html> | 41 </html> |
OLD | NEW |