| OLD | NEW |
| (Empty) | |
| 1 description('Test no fire listeners added during event dispatch.'); |
| 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 window.addEventListener('devicemotion', secondListener); |
| 52 setTimeout(function(){finish();}, 100); |
| 53 } |
| 54 |
| 55 var numSecondListenerCalls = 0; |
| 56 function secondListener(event) { |
| 57 ++numSecondListenerCalls; |
| 58 } |
| 59 |
| 60 function finish() { |
| 61 shouldBe('numSecondListenerCalls', '1'); |
| 62 finishJSTest(); |
| 63 } |
| 64 |
| 65 setMockMotion(1, 2, 3, |
| 66 4, 5, 6, |
| 67 7, 8, 9, |
| 68 10); |
| 69 window.addEventListener('devicemotion', firstListener); |
| 70 |
| 71 window.jsTestIsAsync = true; |
| OLD | NEW |