| OLD | NEW |
| (Empty) |
| 1 <html> | |
| 2 <head> | |
| 3 <script src="../../../resources/js-test.js"></script> | |
| 4 </head> | |
| 5 <body> | |
| 6 <script> | |
| 7 | |
| 8 description('Tests using multiple event handlers for the Device Orientation API.
'); | |
| 9 | |
| 10 var mockEvent; | |
| 11 var expectedEvent; | |
| 12 function setMockOrientation(alpha, beta, gamma, absolute) { | |
| 13 mockEvent = {alpha: alpha, beta: beta, gamma: gamma, absolute: absolute}; | |
| 14 if (window.testRunner) | |
| 15 testRunner.setMockDeviceOrientation( | |
| 16 true, mockEvent.alpha, true, mockEvent.beta, true, mockEvent.gamma,
mockEvent.absolute); | |
| 17 else | |
| 18 debug('This test can not be run without the TestRunner'); | |
| 19 } | |
| 20 | |
| 21 var deviceOrientationEvent; | |
| 22 function checkOrientation(event) { | |
| 23 deviceOrientationEvent = event; | |
| 24 shouldBe('deviceOrientationEvent.alpha', 'expectedEvent.alpha'); | |
| 25 shouldBe('deviceOrientationEvent.beta', 'expectedEvent.beta'); | |
| 26 shouldBe('deviceOrientationEvent.gamma', 'expectedEvent.gamma'); | |
| 27 shouldBe('deviceOrientationEvent.absolute', 'expectedEvent.absolute'); | |
| 28 } | |
| 29 | |
| 30 var counter = 0; | |
| 31 function firstListener(event) { | |
| 32 checkOrientation(event); | |
| 33 counter++; | |
| 34 proceedIfNecessary(); | |
| 35 } | |
| 36 | |
| 37 function secondListener(event) { | |
| 38 checkOrientation(event); | |
| 39 counter++; | |
| 40 proceedIfNecessary(); | |
| 41 } | |
| 42 | |
| 43 function proceedIfNecessary() { | |
| 44 if (counter == 2) { | |
| 45 setMockOrientation(11, 12, 13, true); | |
| 46 // Note: this should not stop Device Orientation updates, | |
| 47 // because there is still one listener active. | |
| 48 window.removeEventListener('deviceorientation', secondListener); | |
| 49 setTimeout(function(){initThirdListener();}, 0); | |
| 50 } | |
| 51 } | |
| 52 | |
| 53 var childFrame; | |
| 54 function initThirdListener() { | |
| 55 childFrame = document.createElement('iframe'); | |
| 56 document.body.appendChild(childFrame); | |
| 57 childFrame.contentWindow.addEventListener('deviceorientation', thirdListener
); | |
| 58 } | |
| 59 | |
| 60 function thirdListener(event) { | |
| 61 // Expect the cached event because Device Orientation was already active | |
| 62 // when third listener was added. | |
| 63 checkOrientation(event); | |
| 64 window.removeEventListener('deviceorientation', firstListener); | |
| 65 childFrame.contentWindow.removeEventListener('deviceorientation', thirdListe
ner); | |
| 66 setTimeout(function(){initFourthListener();}, 0); | |
| 67 } | |
| 68 | |
| 69 function initFourthListener() { | |
| 70 expectedEvent = mockEvent; | |
| 71 window.addEventListener('deviceorientation', fourthListener); | |
| 72 } | |
| 73 | |
| 74 function fourthListener(event) { | |
| 75 checkOrientation(event); | |
| 76 finishJSTest(); | |
| 77 } | |
| 78 | |
| 79 setMockOrientation(1, 2, 3, true); | |
| 80 expectedEvent = mockEvent; | |
| 81 window.addEventListener('deviceorientation', firstListener); | |
| 82 window.addEventListener('deviceorientation', secondListener); | |
| 83 | |
| 84 window.jsTestIsAsync = true; | |
| 85 | |
| 86 </script> | |
| 87 </body> | |
| 88 </html> | |
| OLD | NEW |