3 <script src="../../../resources/js-test.js"></script>
8 description('Tests using multiple event handlers for the Device Orientation API.');
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, true, mockEvent.absolute);
18 debug('This test can not be run without the TestRunner');
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');
31 function firstListener(event) {
32 checkOrientation(event);
37 function secondListener(event) {
38 checkOrientation(event);
43 function proceedIfNecessary() {
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);
54 function initThirdListener() {
55 childFrame = document.createElement('iframe');
56 document.body.appendChild(childFrame);
57 childFrame.contentWindow.addEventListener('deviceorientation', thirdListener);
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', thirdListener);
66 setTimeout(function(){initFourthListener();}, 0);
69 function initFourthListener() {
70 expectedEvent = mockEvent;
71 window.addEventListener('deviceorientation', fourthListener);
74 function fourthListener(event) {
75 checkOrientation(event);
79 setMockOrientation(1, 2, 3, true);
80 expectedEvent = mockEvent;
81 window.addEventListener('deviceorientation', firstListener);
82 window.addEventListener('deviceorientation', secondListener);
84 window.jsTestIsAsync = true;