summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/fast/dom/DeviceOrientation/page-visibility.html
blob: c61adc7ed116fd402378f6133db269caab86e68d (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
<!DOCTYPE html>
<html>
<body>
<script src="../../../resources/js-test.js"></script>
<script>
description('Tests to check that deviceorientation events are not fired when the page is not visible.');
window.jsTestIsAsync = true;

function succeedAndFinish()
{
    testPassed("Received a deviceorientation event");
    finishJSTest();
}

function testWithPageVisible()
{
    testPassed("Did not receive a deviceorientation event");
    window.removeEventListener('deviceorientation', failAndFinish);
    if (window.testRunner)
        testRunner.setPageVisibility("visible");
    debug("* Page is visible");
    window.addEventListener('deviceorientation', succeedAndFinish);
}

function failAndFinish()
{
    testFailed('Should not have received a deviceorientation event while the page was hidden');
    finishJSTest();
}

function testWithPageHidden()
{
    testPassed("Received a deviceorientation event");
    window.removeEventListener('deviceorientation', deviceOrientationListener);
    if (window.testRunner)
        testRunner.setPageVisibility("hidden");
    debug("* Page is hidden");
    window.addEventListener('deviceorientation', failAndFinish);

    setTimeout(testWithPageVisible, 100);
}

function deviceOrientationListener(event) {
    setTimeout(testWithPageHidden, 0);
}

if (window.testRunner)
   testRunner.setMockDeviceOrientation(true, 1, true, 2, true, 3, true);

debug("* Page is visible");
window.addEventListener('deviceorientation', deviceOrientationListener);
</script>
</body>
</html>