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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
|
<!doctype html>
<html>
<head>
<title>Viewport: Scroll Event</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_timeout: true, explicit_done: true})
</script>
<style>
html {
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<h1>Viewport: Scroll Event</h1>
<h4>
Test Description: This test checks that a scroll event is fired against
the window.visualViewport object when the viewport is scrolled.
</h4>
<h2 style="color: red">THIS IS A MANUAL TEST</h2>
<p id="skip">
<button id="skipbtn" onclick="skipManualTest();">Skip Test</button>
</p>
<h4>Instruction</h4>
<p id="instruction"></p>
<button id="continue">Start Test</button>
<div id="log"></div>
</body>
<script>
var continueBtn = document.getElementById("continue");
function continueTest() {
nextStep(function(instructionText) {
var instruction = document.getElementById("instruction");
continueBtn.innerText = "Continue";
instruction.innerText = instructionText;
});
}
continueBtn.addEventListener('click', continueTest);
var didGetScrollEvent = false;
var cancelable = undefined;
var bubbles = undefined;
function resetValues() {
didGetScrollEvent = false;
cancelable = undefined;
bubbles = undefined;
}
addManualTestStep(
function() {
window.visualViewport.addEventListener('scroll', function(e) {
didGetScrollEvent = true;
cancelable = e.cancelable;
bubbles = e.bubbles;
});
document.documentElement.style.overflow = "hidden";
},
null,
'1. Pinch-zoom a little near the "Continue" button but don\'t ' +
'perform any scrolling.');
addManualTestStep(
function() {
requestAnimationFrame(continueTest);
assert_true(didGetScrollEvent, "Got event");
assert_false(cancelable, "Event is not cancelable");
assert_false(bubbles, "Event does not bubble");
},
'Got scroll event while pinch-zooming',
'');
addManualTestStep(
resetValues,
null,
'2. Scroll in any direction.');
addManualTestStep(
function() {
requestAnimationFrame(continueTest);
assert_true(didGetScrollEvent, "Got event");
assert_false(cancelable, "Event is not cancelable");
assert_false(bubbles, "Event does not bubble");
},
'Panning viewport fires a scroll event',
'');
addManualTestStep(
function() {
continueBtn.style.position = "absolute";
continueBtn.style.right = "10px";
continueBtn.style.bottom = "10px";
},
null,
'3. Scroll fully to the bottom right and click the continue ' +
'button.');
var offsetLeft;
var offsetTop;
addManualTestStep(
function() {
resetValues();
document.documentElement.style.overflow = "";
document.body.style.width = "500%";
document.body.style.height = "500%";
continueBtn.style.position = "";
continueBtn.style.left = "";
continueBtn.style.top = "";
offsetLeft = window.visualViewport.offsetLeft;
offsetTop = window.visualViewport.offsetTop;
// The visual viewport should be fully scrolled so even if
// scrollTo does normally "push" the layout viewport with the
// visual, there should be no change to either offsetValue
window.scrollTo(10000, 10000);
requestAnimationFrame(continueTest);
assert_equals(window.visualViewport.offsetLeft, offsetLeft,
"OffsetLeft Unchanged");
assert_equals(window.visualViewport.offsetTop, offsetTop,
"OffsetTop Unchanged");
assert_false(didGetScrollEvent,
"Should not get view scroll event");
},
'scrollTo down and right on a fully scrolled visual viewport ' +
'shouldn\'t change offsets',
'');
addManualTestStep(
function() {
requestAnimationFrame(continueTest);
assert_false(didGetScrollEvent,
"Should not get view scroll event");
resetValues();
},
'scrollTo without changing offsets shouldn\'t fire scroll event ' +
'on view',
'');
addManualTestStep(
function() {
requestAnimationFrame(continueTest);
resetValues();
window.scrollTo(0, 0);
},
null,
'');
addManualTestStep(
function() {
// How scrollTo behaves in this case isn't fully spec'd but
// make sure it's at least rational if it does change the
// offset values.
var scrollChangedOffset =
offsetLeft != window.visualViewport.offsetLeft ||
offsetTop != window.visualViewport.offsetTop;
document.body.style.width = "";
document.body.style.height = "";
assert_equals(didGetScrollEvent, scrollChangedOffset,
'If the scrollTo changed offsets it must have fired a ' +
'scroll event');
},
'scrollTo must fire scroll event if it changes visualViewport.offsetLeft|Top',
'6. Pinch-zoom out fully');
addManualTestStep(
function() { continueBtn.remove(); },
null,
'Test Complete');
</script>
</html>
|