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

Side by Side Diff: LayoutTests/fast/dom/DeviceMotion/script-tests/fire-last-event.js

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

Powered by Google App Engine
This is Rietveld 408576698