OLD | NEW |
(Empty) | |
| 1 description('Tests that adding a new devicemotion event listener from a callback
works as expected.'); |
| 2 |
| 3 var mockAccelerationX = 1.1; |
| 4 var mockAccelerationY = 2.1; |
| 5 var mockAccelerationZ = 3.1; |
| 6 |
| 7 var mockAccelerationIncludingGravityX = 1.2; |
| 8 var mockAccelerationIncludingGravityY = 2.2; |
| 9 var mockAccelerationIncludingGravityZ = 3.2; |
| 10 |
| 11 var mockRotationRateAlpha = 1.3; |
| 12 var mockRotationRateBeta = 2.3; |
| 13 var mockRotationRateGamma = 3.3; |
| 14 |
| 15 var mockInterval = 100; |
| 16 |
| 17 if (window.testRunner) { |
| 18 testRunner.setMockDeviceMotion(true, mockAccelerationX, true, mockAccelerati
onY, true, mockAccelerationZ, |
| 19 true, mockAccelerationIncludingGravityX, true
, mockAccelerationIncludingGravityY, true, mockAccelerationIncludingGravityZ, |
| 20 true, mockRotationRateAlpha, true, mockRotati
onRateBeta, true, mockRotationRateGamma, |
| 21 mockInterval); |
| 22 debug('TEST MODE enabled'); |
| 23 } else |
| 24 debug('This test can not be run without the TestRunner'); |
| 25 |
| 26 var deviceMotionEvent; |
| 27 function checkMotion(event) { |
| 28 deviceMotionEvent = event; |
| 29 shouldBe('deviceMotionEvent.acceleration.x', 'mockAccelerationX'); |
| 30 shouldBe('deviceMotionEvent.acceleration.y', 'mockAccelerationY'); |
| 31 shouldBe('deviceMotionEvent.acceleration.z', 'mockAccelerationZ'); |
| 32 |
| 33 shouldBe('deviceMotionEvent.accelerationIncludingGravity.x', 'mockAccelerati
onIncludingGravityX'); |
| 34 shouldBe('deviceMotionEvent.accelerationIncludingGravity.y', 'mockAccelerati
onIncludingGravityY'); |
| 35 shouldBe('deviceMotionEvent.accelerationIncludingGravity.z', 'mockAccelerati
onIncludingGravityZ'); |
| 36 |
| 37 shouldBe('deviceMotionEvent.rotationRate.alpha', 'mockRotationRateAlpha'); |
| 38 shouldBe('deviceMotionEvent.rotationRate.beta', 'mockRotationRateBeta'); |
| 39 shouldBe('deviceMotionEvent.rotationRate.gamma', 'mockRotationRateGamma'); |
| 40 |
| 41 shouldBe('deviceMotionEvent.interval', 'mockInterval'); |
| 42 } |
| 43 |
| 44 function listener(event) { |
| 45 checkMotion(event); |
| 46 finishJSTest(); |
| 47 } |
| 48 |
| 49 window.addEventListener('devicemotion', listener); |
| 50 window.jsTestIsAsync = true; |
OLD | NEW |