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

Side by Side Diff: LayoutTests/fast/dom/DeviceMotion/fire-last-event.html

Issue 21256002: Fire null Device Motion events only once. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: fixed comments Created 7 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
OLDNEW
(Empty)
1 <html>
2 <head>
3 <script src="../../js/resources/js-test-pre.js"></script>
4 </head>
5 <body>
6 <script>
7
8 description('Tests to see if the last available event is fired.');
9
10 var mockEvent;
11 function setMockMotion(accelerationX, accelerationY, accelerationZ,
12 accelerationIncludingGravityX, accelerationIncludingGravi tyY, accelerationIncludingGravityZ,
13 rotationRateAlpha, rotationRateBeta, rotationRateGamma,
14 interval) {
15
16 mockEvent = {accelerationX: accelerationX, accelerationY: accelerationY, acc elerationZ: accelerationZ,
17 accelerationIncludingGravityX: accelerationIncludingGravityX, a ccelerationIncludingGravityY: accelerationIncludingGravityY, accelerationIncludi ngGravityZ: accelerationIncludingGravityZ,
18 rotationRateAlpha: rotationRateAlpha, rotationRateBeta: rotatio nRateBeta, rotationRateGamma: rotationRateGamma,
19 interval: interval};
20
21 if (window.testRunner)
22 testRunner.setMockDeviceMotion(null != mockEvent.accelerationX, null == mockEvent.accelerationX ? 0 : mockEvent.accelerationX,
23 null != mockEvent.accelerationY, null == mockEvent.accelerationY ? 0 : mockEvent.accelerationY,
24 null != mockEvent.accelerationZ, null == mockEvent.accelerationZ ? 0 : mockEvent.accelerationZ,
25 null != mockEvent.accelerationIncludingGr avityX, null == mockEvent.accelerationIncludingGravityX ? 0 : mockEvent.accelera tionIncludingGravityX,
26 null != mockEvent.accelerationIncludingGr avityY, null == mockEvent.accelerationIncludingGravityY ? 0 : mockEvent.accelera tionIncludingGravityY,
27 null != mockEvent.accelerationIncludingGr avityZ, null == mockEvent.accelerationIncludingGravityZ ? 0 : mockEvent.accelera tionIncludingGravityZ,
28 null != mockEvent.rotationRateAlpha, null == mockEvent.rotationRateAlpha ? 0 : mockEvent.rotationRateAlpha,
29 null != mockEvent.rotationRateBeta, null == mockEvent.rotationRateBeta ? 0 : mockEvent.rotationRateBeta,
30 null != mockEvent.rotationRateGamma, null == mockEvent.rotationRateGamma ? 0 : mockEvent.rotationRateGamma,
31 interval);
32 else
33 debug('This test can not be run without the TestRunner');
34 }
35
36
37 var deviceMotionEvent;
38 function checkMotion(event) {
39 deviceMotionEvent = event;
40 shouldBe('deviceMotionEvent.acceleration.x', 'mockEvent.accelerationX');
41 shouldBe('deviceMotionEvent.acceleration.y', 'mockEvent.accelerationY');
42 shouldBe('deviceMotionEvent.acceleration.z', 'mockEvent.accelerationZ');
43
44 shouldBe('deviceMotionEvent.accelerationIncludingGravity.x', 'mockEvent.acce lerationIncludingGravityX');
45 shouldBe('deviceMotionEvent.accelerationIncludingGravity.y', 'mockEvent.acce lerationIncludingGravityY');
46 shouldBe('deviceMotionEvent.accelerationIncludingGravity.z', 'mockEvent.acce lerationIncludingGravityZ');
47
48 shouldBe('deviceMotionEvent.rotationRate.alpha', 'mockEvent.rotationRateAlph a');
49 shouldBe('deviceMotionEvent.rotationRate.beta', 'mockEvent.rotationRateBeta' );
50 shouldBe('deviceMotionEvent.rotationRate.gamma', 'mockEvent.rotationRateGamm a');
51
52 shouldBe('deviceMotionEvent.interval', 'mockEvent.interval');
53 }
54
55
56 function mainFrameListener(event) {
57 checkMotion(event);
58 var childFrame = document.createElement('iframe');
59 document.body.appendChild(childFrame);
60 window.removeEventListener('devicemotion', mainFrameListener);
61 testRunner.setMockDeviceMotion(true, 0, true, 0, true, 0,
62 true, 0, true, 0, true, 0,
63 true, 0, true, 0, true, 0,
64 0);
65 childFrame.contentWindow.addEventListener('devicemotion', childFrameListener );
66 }
67
68 function childFrameListener(event) {
69 checkMotion(event);
70 finishJSTest();
71 }
72
73 setMockMotion(1, 2, 3,
74 4, 5, 6,
75 7, 8, 9,
76 10);
77
78 window.addEventListener('devicemotion', mainFrameListener);
79
80 window.jsTestIsAsync = true;
81
82 </script>
83 <script src="../../js/resources/js-test-post.js"></script>
84 </body>
85 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698