| OLD | NEW |
| (Empty) |
| 1 <!DOCTYPE html> | |
| 2 <html> | |
| 3 <body> | |
| 4 <script src="../../../resources/js-test.js"></script> | |
| 5 <script> | |
| 6 description('Tests that adding a new event listener from a callback works as exp
ected.'); | |
| 7 | |
| 8 var mockAlpha = 1.1; | |
| 9 var mockBeta = 2.2; | |
| 10 var mockGamma = 3.3; | |
| 11 var mockAbsolute = true; | |
| 12 | |
| 13 if (window.testRunner) | |
| 14 testRunner.setMockDeviceOrientation(true, mockAlpha, true, mockBeta, true, m
ockGamma, mockAbsolute); | |
| 15 else | |
| 16 debug('This test can not be run without the TestRunner'); | |
| 17 | |
| 18 var deviceOrientationEvent; | |
| 19 function checkOrientation(event) { | |
| 20 deviceOrientationEvent = event; | |
| 21 shouldBe('deviceOrientationEvent.alpha', 'mockAlpha'); | |
| 22 shouldBe('deviceOrientationEvent.beta', 'mockBeta'); | |
| 23 shouldBe('deviceOrientationEvent.gamma', 'mockGamma'); | |
| 24 shouldBe('deviceOrientationEvent.absolute', 'mockAbsolute'); | |
| 25 } | |
| 26 | |
| 27 var firstListenerEvents = 0; | |
| 28 function firstListener(event) { | |
| 29 checkOrientation(event); | |
| 30 window.removeEventListener('deviceorientation', firstListener); | |
| 31 if (++firstListenerEvents == 1) | |
| 32 window.addEventListener('deviceorientation', secondListener); | |
| 33 } | |
| 34 | |
| 35 var secondListenerEvents = 0; | |
| 36 function secondListener(event) { | |
| 37 checkOrientation(event); | |
| 38 ++secondListenerEvents; | |
| 39 if (firstListenerEvents != 1 || secondListenerEvents != 1) | |
| 40 testFailed('Too many events fired for first or second listener'); | |
| 41 finishJSTest(); | |
| 42 } | |
| 43 | |
| 44 window.addEventListener('deviceorientation', firstListener); | |
| 45 | |
| 46 window.jsTestIsAsync = true; | |
| 47 </script> | |
| 48 </body> | |
| 49 </html> | |
| OLD | NEW |