summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/visual-viewport/viewport-dimensions-scrollbars-manual.html
blob: 493de254dc09dbcb5e6be8e671f90954be77310d (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
<!doctype html>
<html>
    <head>
        <title>Viewport: Dimensions with scrollbars</title>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, minimum-scale=1">
        <script src="/resources/testharness.js"></script>
        <script src="/resources/testharnessreport.js"></script>
        <script src="viewport_support.js"></script>
        <script>
           setup({explicit_done: true, explicit_timeout: true});
        </script>
        <style>
          #spacer {
            width: 10000px;
            height: 10000px;
            position: absolute;
            visibility: hidden;
          }
        </style>
    </head>
    <body>
    <h1>Viewport: Dimensions with scrollbars</h1>
    <h4>
        Test Description: Tests the viewport dimensions correctly account for
        scrollbars
    </h4>
    <h2 style="color: red">THIS IS A MANUAL TEST</h2>
    <p id="skip">
        <button id="skipbtn" onclick="skipManualTest();">Skip Test</button>
        <p>
            If your browser doesn't support browser-zoom (Ctrl+/-, e.g. Mobile
            Browsers) please skip.
        </p>
    </p>
    <p id="instruction"></p>
    <button id="continue">Start Test</button>
    <div id="log"></div>
    <div id="spacer"></div>
    </body>
    <script>
        var continueBtn = document.getElementById("continue");
        var scrollbarThickness = calculateScrollbarThickness();

        function continueTest() {
          nextStep(function(instructionText) {
            var instruction = document.getElementById("instruction");
            continueBtn.innerText = "Continue";
            instruction.innerText = instructionText;
          });
        }

        continueBtn.addEventListener('click', continueTest);

        var originalWidth = 0;
        var originalHeight = 0;
        var originalInnerWidth = 0;
        var originalVisualViewportWidthExpectation = 0;
        var originalVisualViewportHeightExpectation = 0;

        addManualTestStep(
            function() {},
            null,
            '1. Ensure the browser is at the default pinch and browser zoom ' +
            'levels (100%). Most browsers: ctrl+0');

        addManualTestStep(
            function() {
                originalWidth = window.visualViewport.width;
                originalHeight = window.visualViewport.height;
                originalInnerWidth = window.innerWidth;
                // Remember the visualViewport size here for the next test to
                // address an edge case where originalInnerWidth is an odd
                // number of pixels. The test expects that at 2x browser-zoom,
                // visualViewport.width = innerWidth - scrollbarThickness / 2.0
                // The equality only holds if originalInnerWidth / innerWidth is
                // exactly 2, which is not the case in the aforementioned
                // scenario because innerWidth always has to be an integer
                // number of CSS pixels. Ditto for the height computation.
                originalVisualViewportWidthExpectation =
                    window.innerWidth - scrollbarThickness;
                originalVisualViewportHeightExpectation =
                    window.innerHeight - scrollbarThickness;

                assert_equals(
                    window.visualViewport.width,
                    originalVisualViewportWidthExpectation,
                    "Scrollbar width subtracted from viewport.");
                assert_equals(
                    window.visualViewport.height,
                    originalVisualViewportHeightExpectation,
                    "Scrollbar height subtracted from viewport.");
            },
            'No zoom or scale applied',
            '2. Browser-zoom into 200% (ctrl +)');

        addManualTestStep(
            function() {
                assert_approx_equals(
                    originalInnerWidth / window.innerWidth,
                    2.0,
                    0.1,
                    "Browser zoom to correct level");

                // Scrollbars on the window don't grow with browser-zoom so
                // they'll be fewer CSS pixels as the user zooms in.
                assert_equals(
                    window.visualViewport.width,
                    originalVisualViewportWidthExpectation / 2,
                    "Scrollbar width subtracted from viewport.");
                assert_equals(
                    window.visualViewport.height,
                    originalVisualViewportHeightExpectation / 2,
                    "Scrollbar height subtracted from viewport.");
            },
            'With 200% browser zoom',
            '3. Reset browser zoom (ctrl+0).');

        addManualTestStep(
            showPinchWidget.bind(null, 2.0, 0, 0, continueTest),
            null,
            'Pinch-zoom dialog in progress');

        addManualTestStep(
            function() {
                assert_approx_equals(
                    window.visualViewport.scale, 2, 0.2, "Pinch zoom to correct scale");

                assert_approx_equals(window.visualViewport.width,
                              originalWidth / window.visualViewport.scale,
                              1,
                              "Scrollbar width subtracted from viewport.");
                assert_approx_equals(window.visualViewport.height,
                              originalHeight / window.visualViewport.scale,
                              1,
                              "Scrollbar width subtracted from viewport.");
            },
            'With ~200% pinch zoom',
            '4. Pinch-zoom out.');

        addManualTestStep(
            function() { continueBtn.remove(); },
            null,
            'Test Complete');
    </script>
</html>