summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/fast/dom/Window/window-scaled-viewport-properties.html
blob: 790c0bfbb22286ea447e149c71c4098e7f569773 (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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<script src="../../../resources/js-test.js"></script>
<style>
  body {
    padding: 0px;
    margin: 0px;
  }

  .spacer {
    position: absolute;
    left: 0px;
    top: 0px;
    margin: 0px;
    padding: 0px;
    width: 2000px;
    height: 1500px;
  }
</style>
<script language="JavaScript" type="text/javascript">
    if (window.testRunner && window.internals) {
        window.internals.setPageScaleFactorLimits(0.5, 4.0);
        window.jsTestIsAsync = true;
        testRunner.dumpAsText();
        testRunner.waitUntilDone();
    }

    description("This test makes sure the window properties related to the\
        viewport remain correct under pinch-to-zoom.");

    debug('===Unscaled===');
    debug('');
    shouldBe('window.innerWidth', '800');
    shouldBe('window.innerHeight', '600');

    function testPinchedIn() {
        debug('');
        debug('===Pinch Zoom in to 2X===');
        debug('');
        window.internals.setPageScaleFactor(2.0);
        shouldBe('window.innerWidth', '400');
        shouldBe('window.innerHeight', '300');
        shouldBe('window.scrollX', '0');
        shouldBe('window.scrollY', '0');

        window.scrollBy(10, 20);
        shouldBe('window.scrollX', '10');
        shouldBe('window.scrollY', '20');
        window.scrollBy(1590, 1180);
        shouldBe('window.scrollX', '1600');
        shouldBe('window.scrollY', '1200');
        window.scrollBy(-1600, -1200);
        shouldBe('window.scrollX', '0');
        shouldBe('window.scrollY', '0');
        window.scrollTo(1600, 1200);
        shouldBe('window.scrollX', '1600');
        shouldBe('window.scrollY', '1200');
        window.scrollTo(0, 0);
        shouldBe('window.scrollX', '0');
        shouldBe('window.scrollY', '0');
    }

    function testMaximallyPinchedOut() {
        debug('');
        debug('===Pinch Out to 0.5X===');
        debug('');
        window.internals.setPageScaleFactor(0.5);
        shouldBe('window.innerWidth', '1600');
        shouldBe('window.innerHeight', '1200');
        shouldBe('window.scrollX', '0');
        shouldBe('window.scrollY', '0');

        window.scrollBy(10, 20);
        shouldBe('window.scrollX', '10');
        shouldBe('window.scrollY', '20');
        window.scrollBy(390, 280);
        shouldBe('window.scrollX', '400');
        shouldBe('window.scrollY', '300');
        window.scrollBy(-400, -300);
        shouldBe('window.scrollX', '0');
        shouldBe('window.scrollY', '0');
        window.scrollTo(400, 300);
        shouldBe('window.scrollX', '400');
        shouldBe('window.scrollY', '300');
        window.scrollTo(0, 0);
        shouldBe('window.scrollX', '0');
        shouldBe('window.scrollY', '0');
    }

    function testOnScroll() {
        debug('');
        debug('===Test OnScroll===');
        debug('');
        window.internals.setPageScaleFactor(1.0);
        shouldBe('window.innerWidth', '800');
        shouldBe('window.innerHeight', '600');
        shouldBe('window.scrollX', '0');
        shouldBe('window.scrollY', '0');

        // First scroll scrolls only the outer viewport.
        // Second scrolls the outer and the inner.
        // Third scrolls only the inner.
        var scrolls = [100, 400, 100];
        var numScrollsReceived = 0;
        var numRAFCalls = 0;

        document.onscroll = function() {
            if (numRAFCalls == 0)
                return;

            ++numScrollsReceived;
            debug('PASS OnScroll called for scroll #' + numScrollsReceived);
            if (numScrollsReceived < scrolls.length) {
                var scrollAmount = scrolls[numScrollsReceived];
                window.scrollBy(scrollAmount, 0);
            } else if (numScrollsReceived == scrolls.length) {
                // Make sure scrollTo that moves only the inner viewport also
                // triggers a scroll event.
                window.scrollTo(1200, 0);
            } else {
                debug('');
                finishJSTest();
            }
        }

        // Scroll events are fired right before RAF so this is a good place to
        // make sure event was handled.
        var failureSentinel = function() {
            if (numRAFCalls == 0) {
                window.scrollBy(scrolls[0], 0);
            }else if (numRAFCalls > numScrollsReceived) {
                testFailed("Failed to receive scroll event #" + (numScrollsReceived+1));
                finishJSTest();
            }
            ++numRAFCalls;
            window.requestAnimationFrame(failureSentinel);
        }

        window.requestAnimationFrame(failureSentinel);
    }

    function forceLayout() {
        window.scrollTo(0, 0);
    }

    function runTests() {
        if (window.testRunner && window.internals) {
            forceLayout();
            testPinchedIn();
            testMaximallyPinchedOut();
            testOnScroll();
        }
    }

    onload = runTests;
</script>
<div class="spacer"></div>