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