summaryrefslogtreecommitdiffstats
path: root/LayoutTests/fast/dom/DeviceOrientation/script-tests/multiple-frames.js
blob: f8b8fb925d1bee1dea5c701a5dea7bc928956f7c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
description('Tests using DeviceOrientation from multiple frames.');

var deviceOrientationEvent;
function checkOrientation(event) {
    deviceOrientationEvent = event;
    shouldBe('deviceOrientationEvent.alpha', 'mockEvent.alpha');
    shouldBe('deviceOrientationEvent.beta', 'mockEvent.beta');
    shouldBe('deviceOrientationEvent.gamma', 'mockEvent.gamma');
}

var hasMainFrameEventFired = false;
function mainFrameListener(event) {
    checkOrientation(event);
    hasMainFrameEventFired = true;
    maybeFinishTest();
}

var hasChildFrameEventFired = false;
function childFrameListener(event) {
    checkOrientation(event);
    hasChildFrameEventFired = true;
    maybeFinishTest();
}

function maybeFinishTest() {
    if (hasMainFrameEventFired && hasChildFrameEventFired)
        finishJSTest();
}

var mockEvent = {alpha: 1.1, beta: 2.2, gamma: 3.3};
if (window.layoutTestController)
    layoutTestController.setMockDeviceOrientation(true, mockEvent.alpha, true, mockEvent.beta, true, mockEvent.gamma);
else
    debug('This test can not be run without the LayoutTestController');

var childFrame = document.createElement('iframe');
document.body.appendChild(childFrame);
childFrame.contentWindow.addEventListener('deviceorientation', childFrameListener);

window.addEventListener('deviceorientation', mainFrameListener);

window.jsTestIsAsync = true;
window.successfullyParsed = true;