1 description('Tests that adding a new event listener from a callback works as expected.'); 2 3 var mockAlpha = 1.1; 4 var mockBeta = 2.2; 5 var mockGamma = 3.3; 6 7 if (window.layoutTestController) 8 layoutTestController.setMockDeviceOrientation(true, mockAlpha, true, mockBeta, true, mockGamma); 9 else 10 debug('This test can not be run without the LayoutTestController'); 11 12 var deviceOrientationEvent; 13 function checkOrientation(event) { 14 deviceOrientationEvent = event; 15 shouldBe('deviceOrientationEvent.alpha', 'mockAlpha'); 16 shouldBe('deviceOrientationEvent.beta', 'mockBeta'); 17 shouldBe('deviceOrientationEvent.gamma', 'mockGamma'); 18 } 19 20 var firstListenerEvents = 0; 21 function firstListener(event) { 22 checkOrientation(event); 23 if (++firstListenerEvents == 1) 24 window.addEventListener('deviceorientation', secondListener); 25 else if (firstListenerEvents > 2) 26 testFailed('Too many events for first listener.'); 27 maybeFinishTest(); 28 } 29 30 var secondListenerEvents = 0; 31 function secondListener(event) { 32 checkOrientation(event); 33 if (++secondListenerEvents > 1) 34 testFailed('Too many events for second listener.'); 35 maybeFinishTest(); 36 } 37 38 function maybeFinishTest() { 39 if (firstListenerEvents == 2 && secondListenerEvents == 1) 40 finishJSTest(); 41 } 42 43 window.addEventListener('deviceorientation', firstListener); 44 45 window.jsTestIsAsync = true; 46 window.successfullyParsed = true; 47