| OLD | NEW |
| (Empty) |
| 1 <!DOCTYPE html> | |
| 2 <html> | |
| 3 <body> | |
| 4 <script src="../../../resources/js-test.js"></script> | |
| 5 <script> | |
| 6 description('Test no fire listeners added during event dispatch.'); | |
| 7 | |
| 8 var mockEvent; | |
| 9 function setMockMotion(accelerationX, accelerationY, accelerationZ, | |
| 10 accelerationIncludingGravityX, accelerationIncludingGravi
tyY, accelerationIncludingGravityZ, | |
| 11 rotationRateAlpha, rotationRateBeta, rotationRateGamma, | |
| 12 interval) { | |
| 13 | |
| 14 mockEvent = {accelerationX: accelerationX, accelerationY: accelerationY, acc
elerationZ: accelerationZ, | |
| 15 accelerationIncludingGravityX: accelerationIncludingGravityX, a
ccelerationIncludingGravityY: accelerationIncludingGravityY, accelerationIncludi
ngGravityZ: accelerationIncludingGravityZ, | |
| 16 rotationRateAlpha: rotationRateAlpha, rotationRateBeta: rotatio
nRateBeta, rotationRateGamma: rotationRateGamma, | |
| 17 interval: interval}; | |
| 18 | |
| 19 if (window.testRunner) | |
| 20 testRunner.setMockDeviceMotion(null != mockEvent.accelerationX, null ==
mockEvent.accelerationX ? 0 : mockEvent.accelerationX, | |
| 21 null != mockEvent.accelerationY, null ==
mockEvent.accelerationY ? 0 : mockEvent.accelerationY, | |
| 22 null != mockEvent.accelerationZ, null ==
mockEvent.accelerationZ ? 0 : mockEvent.accelerationZ, | |
| 23 null != mockEvent.accelerationIncludingGr
avityX, null == mockEvent.accelerationIncludingGravityX ? 0 : mockEvent.accelera
tionIncludingGravityX, | |
| 24 null != mockEvent.accelerationIncludingGr
avityY, null == mockEvent.accelerationIncludingGravityY ? 0 : mockEvent.accelera
tionIncludingGravityY, | |
| 25 null != mockEvent.accelerationIncludingGr
avityZ, null == mockEvent.accelerationIncludingGravityZ ? 0 : mockEvent.accelera
tionIncludingGravityZ, | |
| 26 null != mockEvent.rotationRateAlpha, null
== mockEvent.rotationRateAlpha ? 0 : mockEvent.rotationRateAlpha, | |
| 27 null != mockEvent.rotationRateBeta, null
== mockEvent.rotationRateBeta ? 0 : mockEvent.rotationRateBeta, | |
| 28 null != mockEvent.rotationRateGamma, null
== mockEvent.rotationRateGamma ? 0 : mockEvent.rotationRateGamma, | |
| 29 interval); | |
| 30 else | |
| 31 debug('This test can not be run without the TestRunner'); | |
| 32 } | |
| 33 | |
| 34 | |
| 35 var deviceMotionEvent; | |
| 36 function checkMotion(event) { | |
| 37 deviceMotionEvent = event; | |
| 38 shouldBe('deviceMotionEvent.acceleration.x', 'mockEvent.accelerationX'); | |
| 39 shouldBe('deviceMotionEvent.acceleration.y', 'mockEvent.accelerationY'); | |
| 40 shouldBe('deviceMotionEvent.acceleration.z', 'mockEvent.accelerationZ'); | |
| 41 | |
| 42 shouldBe('deviceMotionEvent.accelerationIncludingGravity.x', 'mockEvent.acce
lerationIncludingGravityX'); | |
| 43 shouldBe('deviceMotionEvent.accelerationIncludingGravity.y', 'mockEvent.acce
lerationIncludingGravityY'); | |
| 44 shouldBe('deviceMotionEvent.accelerationIncludingGravity.z', 'mockEvent.acce
lerationIncludingGravityZ'); | |
| 45 | |
| 46 shouldBe('deviceMotionEvent.rotationRate.alpha', 'mockEvent.rotationRateAlph
a'); | |
| 47 shouldBe('deviceMotionEvent.rotationRate.beta', 'mockEvent.rotationRateBeta'
); | |
| 48 shouldBe('deviceMotionEvent.rotationRate.gamma', 'mockEvent.rotationRateGamm
a'); | |
| 49 | |
| 50 shouldBe('deviceMotionEvent.interval', 'mockEvent.interval'); | |
| 51 } | |
| 52 | |
| 53 function firstListener(event) { | |
| 54 checkMotion(event); | |
| 55 window.removeEventListener('devicemotion', firstListener); | |
| 56 window.addEventListener('devicemotion', secondListener); | |
| 57 setTimeout(function(){finish();}, 100); | |
| 58 } | |
| 59 | |
| 60 var numSecondListenerCalls = 0; | |
| 61 function secondListener(event) { | |
| 62 ++numSecondListenerCalls; | |
| 63 } | |
| 64 | |
| 65 function finish() { | |
| 66 shouldBe('numSecondListenerCalls', '1'); | |
| 67 finishJSTest(); | |
| 68 } | |
| 69 | |
| 70 setMockMotion(1, 2, 3, | |
| 71 4, 5, 6, | |
| 72 7, 8, 9, | |
| 73 10); | |
| 74 window.addEventListener('devicemotion', firstListener); | |
| 75 | |
| 76 window.jsTestIsAsync = true; | |
| 77 </script> | |
| 78 </body> | |
| 79 </html> | |
| OLD | NEW |