|
1 <!DOCTYPE HTML> |
|
2 <html> |
|
3 <!-- |
|
4 https://bugzilla.mozilla.org/show_bug.cgi?id=662678 |
|
5 --> |
|
6 <head> |
|
7 <title>Test for Bug 662678</title> |
|
8 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
|
9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> |
|
10 </head> |
|
11 <body> |
|
12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=662678">Mozilla Bug 662678</a> |
|
13 <p id="display"></p> |
|
14 <div id="content" style="display: none"> |
|
15 |
|
16 </div> |
|
17 <pre id="test"> |
|
18 <script type="application/javascript"> |
|
19 |
|
20 /** Test for Bug 662678 **/ |
|
21 SimpleTest.waitForExplicitFinish(); |
|
22 |
|
23 var checkMotion = function(event) { |
|
24 window.removeEventListener("devicemotion", checkMotion, true); |
|
25 |
|
26 is(event.acceleration.x, 1.5, "acceleration.x"); |
|
27 is(event.acceleration.y, 2.5, "acceleration.y"); |
|
28 is(event.acceleration.z, 3.5, "acceleration.z"); |
|
29 is(event.accelerationIncludingGravity.x, 4.5, "accelerationIncludingGravity.x"); |
|
30 is(event.accelerationIncludingGravity.y, 5.5, "accelerationIncludingGravity.y"); |
|
31 is(event.accelerationIncludingGravity.z, 6.5, "accelerationIncludingGravity.z"); |
|
32 is(event.rotationRate.alpha, 7.5, "rotationRate.alpha"); |
|
33 is(event.rotationRate.beta, 8.5, "rotationRate.beta"); |
|
34 is(event.rotationRate.gamma, 9.5, "rotationRate.gamma"); |
|
35 is(event.interval, 0.5, "interval"); |
|
36 |
|
37 var e = document.createEvent("DeviceMotionEvent"); |
|
38 e.initDeviceMotionEvent('devicemotion', true, true, |
|
39 null, null, null, null); |
|
40 is(e.acceleration.x, null, "acceleration.x"); |
|
41 is(e.acceleration.y, null, "acceleration.y"); |
|
42 is(e.acceleration.z, null, "acceleration.z"); |
|
43 is(e.accelerationIncludingGravity.x, null, "accelerationIncludingGravity.x"); |
|
44 is(e.accelerationIncludingGravity.y, null, "accelerationIncludingGravity.y"); |
|
45 is(e.accelerationIncludingGravity.z, null, "accelerationIncludingGravity.z"); |
|
46 is(e.rotationRate.alpha, null, "rotationRate.alpha"); |
|
47 is(e.rotationRate.beta, null, "rotationRate.beta"); |
|
48 is(e.rotationRate.gamma, null, "rotationRate.gamma"); |
|
49 is(e.interval, null, "interval"); |
|
50 |
|
51 e.initDeviceMotionEvent('devicemotion', true, true, |
|
52 {}, {}, {}, 0); |
|
53 is(e.acceleration.x, null, "acceleration.x"); |
|
54 is(e.acceleration.y, null, "acceleration.y"); |
|
55 is(e.acceleration.z, null, "acceleration.z"); |
|
56 is(e.accelerationIncludingGravity.x, null, "accelerationIncludingGravity.x"); |
|
57 is(e.accelerationIncludingGravity.y, null, "accelerationIncludingGravity.y"); |
|
58 is(e.accelerationIncludingGravity.z, null, "accelerationIncludingGravity.z"); |
|
59 is(e.rotationRate.alpha, null, "rotationRate.alpha"); |
|
60 is(e.rotationRate.beta, null, "rotationRate.beta"); |
|
61 is(e.rotationRate.gamma, null, "rotationRate.gamma"); |
|
62 is(e.interval, 0, "interval"); |
|
63 |
|
64 window.addEventListener("devicemotion", checkMotionCtor, true); |
|
65 |
|
66 event = new DeviceMotionEvent('devicemotion', { |
|
67 bubbles: true, cancelable: true, |
|
68 acceleration: {x:1.5,y:2.5,z:3.5}, |
|
69 accelerationIncludingGravity: {x:4.5,y:5.5,z:6.5}, |
|
70 rotationRate: {alpha:7.5,beta:8.5,gamma:9.5}, |
|
71 interval: 0.5 |
|
72 }); |
|
73 window.dispatchEvent(event); |
|
74 }; |
|
75 |
|
76 var checkMotionCtor = function(event) { |
|
77 window.removeEventListener("devicemotion", checkMotionCtor, true); |
|
78 |
|
79 is(event.acceleration.x, 1.5, "acceleration.x"); |
|
80 is(event.acceleration.y, 2.5, "acceleration.y"); |
|
81 is(event.acceleration.z, 3.5, "acceleration.z"); |
|
82 is(event.accelerationIncludingGravity.x, 4.5, "accelerationIncludingGravity.x"); |
|
83 is(event.accelerationIncludingGravity.y, 5.5, "accelerationIncludingGravity.y"); |
|
84 is(event.accelerationIncludingGravity.z, 6.5, "accelerationIncludingGravity.z"); |
|
85 is(event.rotationRate.alpha, 7.5, "rotationRate.alpha"); |
|
86 is(event.rotationRate.beta, 8.5, "rotationRate.beta"); |
|
87 is(event.rotationRate.gamma, 9.5, "rotationRate.gamma"); |
|
88 is(event.interval, 0.5, "interval"); |
|
89 |
|
90 var e = new DeviceMotionEvent('devicemotion'); |
|
91 is(e.acceleration.x, null, "acceleration.x"); |
|
92 is(e.acceleration.y, null, "acceleration.y"); |
|
93 is(e.acceleration.z, null, "acceleration.z"); |
|
94 is(e.accelerationIncludingGravity.x, null, "accelerationIncludingGravity.x"); |
|
95 is(e.accelerationIncludingGravity.y, null, "accelerationIncludingGravity.y"); |
|
96 is(e.accelerationIncludingGravity.z, null, "accelerationIncludingGravity.z"); |
|
97 is(e.rotationRate.alpha, null, "rotationRate.alpha"); |
|
98 is(e.rotationRate.beta, null, "rotationRate.beta"); |
|
99 is(e.rotationRate.gamma, null, "rotationRate.gamma"); |
|
100 is(e.interval, null, "interval"); |
|
101 |
|
102 e = new DeviceMotionEvent('devicemotion', { |
|
103 bubbles: true, cancelable: true, |
|
104 acceleration: null, accelerationIncludingGravity: null, |
|
105 rotationRate: null, interval: null |
|
106 }); |
|
107 is(e.acceleration.x, null, "acceleration.x"); |
|
108 is(e.acceleration.y, null, "acceleration.y"); |
|
109 is(e.acceleration.z, null, "acceleration.z"); |
|
110 is(e.accelerationIncludingGravity.x, null, "accelerationIncludingGravity.x"); |
|
111 is(e.accelerationIncludingGravity.y, null, "accelerationIncludingGravity.y"); |
|
112 is(e.accelerationIncludingGravity.z, null, "accelerationIncludingGravity.z"); |
|
113 is(e.rotationRate.alpha, null, "rotationRate.alpha"); |
|
114 is(e.rotationRate.beta, null, "rotationRate.beta"); |
|
115 is(e.rotationRate.gamma, null, "rotationRate.gamma"); |
|
116 is(e.interval, null, "interval"); |
|
117 |
|
118 e = new DeviceMotionEvent('devicemotion', { |
|
119 bubbles: true, cancelable: true, |
|
120 acceleration: {}, accelerationIncludingGravity: {}, |
|
121 rotationRate: {}, interval: 0 |
|
122 }); |
|
123 is(e.acceleration.x, null, "acceleration.x"); |
|
124 is(e.acceleration.y, null, "acceleration.y"); |
|
125 is(e.acceleration.z, null, "acceleration.z"); |
|
126 is(e.accelerationIncludingGravity.x, null, "accelerationIncludingGravity.x"); |
|
127 is(e.accelerationIncludingGravity.y, null, "accelerationIncludingGravity.y"); |
|
128 is(e.accelerationIncludingGravity.z, null, "accelerationIncludingGravity.z"); |
|
129 is(e.rotationRate.alpha, null, "rotationRate.alpha"); |
|
130 is(e.rotationRate.beta, null, "rotationRate.beta"); |
|
131 is(e.rotationRate.gamma, null, "rotationRate.gamma"); |
|
132 is(e.interval, 0, "interval"); |
|
133 |
|
134 SimpleTest.finish(); |
|
135 }; |
|
136 |
|
137 window.addEventListener("devicemotion", checkMotion, true); |
|
138 |
|
139 var event = DeviceMotionEvent; |
|
140 ok(!!event, "Should have seen DeviceMotionEvent!"); |
|
141 |
|
142 event = document.createEvent("DeviceMotionEvent"); |
|
143 event.initDeviceMotionEvent('devicemotion', true, true, |
|
144 {x:1.5,y:2.5,z:3.5}, |
|
145 {x:4.5,y:5.5,z:6.5}, |
|
146 {alpha:7.5,beta:8.5,gamma:9.5}, |
|
147 0.5); |
|
148 window.dispatchEvent(event); |
|
149 |
|
150 </script> |
|
151 </pre> |
|
152 </body> |
|
153 </html> |