Home | History | Annotate | Download | only in script-tests
      1 description('Tests using DeviceOrientation from multiple frames.');
      2 
      3 var deviceOrientationEvent;
      4 function checkOrientation(event) {
      5     deviceOrientationEvent = event;
      6     shouldBe('deviceOrientationEvent.alpha', 'mockEvent.alpha');
      7     shouldBe('deviceOrientationEvent.beta', 'mockEvent.beta');
      8     shouldBe('deviceOrientationEvent.gamma', 'mockEvent.gamma');
      9 }
     10 
     11 var hasMainFrameEventFired = false;
     12 function mainFrameListener(event) {
     13     checkOrientation(event);
     14     hasMainFrameEventFired = true;
     15     maybeFinishTest();
     16 }
     17 
     18 var hasChildFrameEventFired = false;
     19 function childFrameListener(event) {
     20     checkOrientation(event);
     21     hasChildFrameEventFired = true;
     22     maybeFinishTest();
     23 }
     24 
     25 function maybeFinishTest() {
     26     if (hasMainFrameEventFired && hasChildFrameEventFired)
     27         finishJSTest();
     28 }
     29 
     30 var mockEvent = {alpha: 1.1, beta: 2.2, gamma: 3.3};
     31 if (window.layoutTestController)
     32     layoutTestController.setMockDeviceOrientation(true, mockEvent.alpha, true, mockEvent.beta, true, mockEvent.gamma);
     33 else
     34     debug('This test can not be run without the LayoutTestController');
     35 
     36 var childFrame = document.createElement('iframe');
     37 document.body.appendChild(childFrame);
     38 childFrame.contentWindow.addEventListener('deviceorientation', childFrameListener);
     39 
     40 window.addEventListener('deviceorientation', mainFrameListener);
     41 
     42 window.jsTestIsAsync = true;
     43 window.successfullyParsed = true;
     44