summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/screen_orientation/page-visibility.html
blob: f9bdff9572f251ab0c47cc0937f2f2a8ec590fe9 (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
57
58
<!DOCTYPE html>
<html>
<body>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<iframe src='about:blank'></iframe>
<script>
var orientationChangeEventListenerCalls = 0;
var orientationChangeEventListenerCallsForFrame = 0;

screen.orientation.addEventListener('change', function() {
    orientationChangeEventListenerCalls++;
});

window.frames[0].screen.orientation.addEventListener('change', function() {
    orientationChangeEventListenerCallsForFrame++;
});

test(function() {
    assert_false(document.hidden);
    if (window.testRunner)
        window.testRunner.setMockScreenOrientation("landscape-primary");
    assert_equals(orientationChangeEventListenerCalls, 1);
    assert_equals(screen.orientation.type, "landscape-primary");
}, "Test that a change event is fired when the page is visible");

if (window.testRunner)
    testRunner.setPageVisibility("hidden");

test(function() {
    assert_true(document.hidden);
    if (window.testRunner)
        window.testRunner.setMockScreenOrientation("portrait-primary");
    assert_equals(orientationChangeEventListenerCalls, 1);
}, "Test that change event is not fired when the page is not visible");

test(function() {
    assert_equals(screen.orientation.type, "landscape-primary");
}, "Test that screen.orientation keeps returning the same orientation when the page is not visible");

if (window.testRunner)
    testRunner.setPageVisibility("visible");

test(function() {
    assert_false(document.hidden);
    // A change event should have been fired.
    assert_equals(orientationChangeEventListenerCalls, 2);
    // Should keep returning the start returning the orientation value.
    assert_equals(screen.orientation.type, "portrait-primary");
}, "Test that screen.orientation is updated once the page is visible again");

test(function() {
    assert_equals(orientationChangeEventListenerCallsForFrame, orientationChangeEventListenerCalls);
}, "Test that the iframe got as many events as the main frame.")

</script>
</body>
</html>