summaryrefslogtreecommitdiffstats
path: root/LayoutTests/fast/dom/DeviceOrientation/script-tests/null-values.js
blob: ccde66aa9df52923eeae4bfd8747e8acf7418dd6 (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
44
45
46
47
48
49
50
51
52
53
54
55
56
description('Tests using null values for some of the event properties.');

var mockEvent;
function setMockOrientation(alpha, beta, gamma) {
    mockEvent = {alpha: alpha, beta: beta, gamma: gamma};
    if (window.layoutTestController)
        layoutTestController.setMockDeviceOrientation(
            null != mockEvent.alpha, null == mockEvent.alpha ? 0 : mockEvent.alpha,
            null != mockEvent.beta, null == mockEvent.beta ? 0 : mockEvent.beta,
            null != mockEvent.gamma, null == mockEvent.gamma ? 0 : mockEvent.gamma);
    else
        debug('This test can not be run without the LayoutTestController');
}

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

function firstListener(event) {
    checkOrientation(event);
    window.removeEventListener('deviceorientation', firstListener);

    setMockOrientation(1.1, null, null);
    window.addEventListener('deviceorientation', secondListener);
}

function secondListener(event) {
    checkOrientation(event);
    window.removeEventListener('deviceorientation', secondListener);

    setMockOrientation(null, 2.2, null);
    window.addEventListener('deviceorientation', thirdListener);
}

function thirdListener(event) {
    checkOrientation(event);
    window.removeEventListener('deviceorientation', thirdListener);

    setMockOrientation(null, null, 3.3);
    window.addEventListener('deviceorientation', fourthListener);
}

function fourthListener(event) {
    checkOrientation(event);
    finishJSTest();
}

setMockOrientation(null, null, null);
window.addEventListener('deviceorientation', firstListener);

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