| OLD | NEW |
| (Empty) | |
| 1 description('Tests using null values for some or all of the event properties.'); |
| 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 function firstListener(event) { |
| 49 checkMotion(event); |
| 50 window.removeEventListener('devicemotion', firstListener); |
| 51 setTimeout(function(){initSecondListener();}, 0); |
| 52 } |
| 53 |
| 54 function initSecondListener() { |
| 55 setMockMotion(1, 2, 3, |
| 56 null, null, null, |
| 57 null, null, null, |
| 58 100); |
| 59 window.addEventListener('devicemotion', secondListener); |
| 60 } |
| 61 |
| 62 function secondListener(event) { |
| 63 checkMotion(event); |
| 64 window.removeEventListener('devicemotion', secondListener); |
| 65 setTimeout(function(){initThirdListener();}, 0); |
| 66 } |
| 67 |
| 68 function initThirdListener() { |
| 69 setMockMotion(null, null, null, |
| 70 1, 2, 3, |
| 71 null, null, null, |
| 72 100); |
| 73 window.addEventListener('devicemotion', thirdListener); |
| 74 } |
| 75 |
| 76 function thirdListener(event) { |
| 77 checkMotion(event); |
| 78 window.removeEventListener('devicemotion', thirdListener); |
| 79 setTimeout(function(){initFourthListener();}, 0); |
| 80 } |
| 81 |
| 82 function initFourthListener() { |
| 83 setMockMotion(null, null, null, |
| 84 null, null, null, |
| 85 1, 2, 3, |
| 86 100); |
| 87 window.addEventListener('devicemotion', fourthListener); |
| 88 } |
| 89 |
| 90 function fourthListener(event) { |
| 91 checkMotion(event); |
| 92 finishJSTest(); |
| 93 } |
| 94 |
| 95 setMockMotion(null, null, null, |
| 96 null, null, null, |
| 97 null, null, null, |
| 98 0); |
| 99 window.addEventListener('devicemotion', firstListener); |
| 100 |
| 101 window.jsTestIsAsync = true; |
| OLD | NEW |