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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
|
<!DOCTYPE html>
<title>Testing scrollOptions' behavior for Element.scroll* and scroll-behavior on the root of the main frame</title>
<meta name="timeout" content="long"/>
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
<link rel="author" title="Frédéric Wang" href="mailto:fwang@igalia.com">
<link rel="help" href="https://drafts.csswg.org/cssom-view/#propdef-scroll-behavior">
<link rel="help" href="https://drafts.csswg.org/cssom-view/#scrolling-box">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/dom/events/scrolling/scroll_support.js"></script>
<script src="support/scroll-behavior.js"></script>
<style>
body {
margin: 0;
}
.autoBehavior {
scroll-behavior: auto;
}
.smoothBehavior {
scroll-behavior: smooth;
}
</style>
<div id="log">
</div>
<div id="pageContent" style="position: absolute; left: 0; top: 0;">
<div id="elementToReveal" style="position: absolute; display: inline-block; width: 10px; height: 15px; background: black;"></div>
</div>
<script>
var pageLoaded = async_test("Page loaded");
var scrollingElement, styledElement, elementToRevealLeft, elementToRevealTop;
window.addEventListener("load", pageLoaded.step_func_done(function() {
scrollingElement = document.scrollingElement;
styledElement = document.documentElement;
pageContent.style.width = (10 + window.innerWidth) * 5 + "px";
pageContent.style.height = (20 + window.innerHeight) * 6 + "px";
elementToRevealLeft = (10 + window.innerWidth) * 3;
elementToRevealTop = (20 + window.innerHeight) * 4;
elementToReveal.style.left = elementToRevealLeft + "px";
elementToReveal.style.top = elementToRevealTop + "px";
add_completion_callback(() => { resetScroll(scrollingElement); });
promise_test(async () => {
await waitForCompositorReady();
}, "Make sure the page is ready for animation.");
["scroll", "scrollTo", "scrollBy", "scrollIntoView"].forEach((scrollFunction) => {
promise_test(() => {
resetScroll(scrollingElement);
setScrollBehavior(styledElement, "autoBehavior");
assert_equals(scrollingElement.scrollLeft, 0);
assert_equals(scrollingElement.scrollTop, 0);
scrollNode(scrollingElement, scrollFunction, null, elementToRevealLeft, elementToRevealTop);
assert_equals(scrollingElement.scrollLeft, elementToRevealLeft, "Should set scrollLeft immediately");
assert_equals(scrollingElement.scrollTop, elementToRevealTop, "Should set scrollTop immediately");
return new Promise((resolve) => { resolve(); });
}, `Main frame with auto scroll-behavior ; ${scrollFunction}() with default behavior`);
promise_test(() => {
resetScroll(scrollingElement);
setScrollBehavior(styledElement, "autoBehavior");
assert_equals(scrollingElement.scrollLeft, 0);
assert_equals(scrollingElement.scrollTop, 0);
scrollNode(scrollingElement, scrollFunction, "auto", elementToRevealLeft, elementToRevealTop);
assert_equals(scrollingElement.scrollLeft, elementToRevealLeft, "Should set scrollLeft immediately");
assert_equals(scrollingElement.scrollTop, elementToRevealTop, "Should set scrollTop immediately");
return new Promise((resolve) => { resolve(); });
}, `Main frame with auto scroll-behavior ; ${scrollFunction}() with auto behavior`);
promise_test(() => {
resetScroll(scrollingElement);
setScrollBehavior(styledElement, "autoBehavior");
assert_equals(scrollingElement.scrollLeft, 0);
assert_equals(scrollingElement.scrollTop, 0);
scrollNode(scrollingElement, scrollFunction, "instant", elementToRevealLeft, elementToRevealTop);
assert_equals(scrollingElement.scrollLeft, elementToRevealLeft, "Should set scrollLeft immediately");
assert_equals(scrollingElement.scrollTop, elementToRevealTop, "Should set scrollTop immediately");
return new Promise((resolve) => { resolve(); });
}, `Main frame with auto scroll-behavior ; ${scrollFunction}() with instant behavior`);
promise_test(() => {
resetScroll(scrollingElement);
setScrollBehavior(styledElement, "autoBehavior");
assert_equals(scrollingElement.scrollLeft, 0);
assert_equals(scrollingElement.scrollTop, 0);
scrollNode(scrollingElement, scrollFunction, "smooth", elementToRevealLeft, elementToRevealTop);
assert_less_than(scrollingElement.scrollLeft, elementToRevealLeft, "Should not set scrollLeft immediately");
assert_less_than(scrollingElement.scrollTop, elementToRevealTop, "Should not set scrollTop immediately");
return waitForScrollEnd(scrollingElement).then(() => {
assert_equals(scrollingElement.scrollLeft, elementToRevealLeft, "Final value of scrollLeft");
assert_equals(scrollingElement.scrollTop, elementToRevealTop, "Final value of scrollTop");
});
}, `Main frame with auto scroll-behavior ; ${scrollFunction}() with smooth behavior`);
promise_test(() => {
resetScroll(scrollingElement);
setScrollBehavior(styledElement, "smoothBehavior");
assert_equals(scrollingElement.scrollLeft, 0);
assert_equals(scrollingElement.scrollTop, 0);
scrollNode(scrollingElement, scrollFunction, null, elementToRevealLeft, elementToRevealTop);
assert_less_than(scrollingElement.scrollLeft, elementToRevealLeft, "Should not set scrollLeft immediately");
assert_less_than(scrollingElement.scrollTop, elementToRevealTop, "Should not set scrollTop immediately");
return waitForScrollEnd(scrollingElement).then(() => {
assert_equals(scrollingElement.scrollLeft, elementToRevealLeft, "Final value of scrollLeft");
assert_equals(scrollingElement.scrollTop, elementToRevealTop, "Final value of scrollTop");
});
}, `Main frame with smooth scroll-behavior ; ${scrollFunction}() with default behavior`);
promise_test(() => {
resetScroll(scrollingElement);
setScrollBehavior(styledElement, "smoothBehavior");
assert_equals(scrollingElement.scrollLeft, 0);
assert_equals(scrollingElement.scrollTop, 0);
scrollNode(scrollingElement, scrollFunction, "auto", elementToRevealLeft, elementToRevealTop);
assert_less_than(scrollingElement.scrollLeft, elementToRevealLeft, "Should not set scrollLeft immediately");
assert_less_than(scrollingElement.scrollTop, elementToRevealTop, "Should not set scrollTop immediately");
return waitForScrollEnd(scrollingElement).then(() => {
assert_equals(scrollingElement.scrollLeft, elementToRevealLeft, "Final value of scrollLeft");
assert_equals(scrollingElement.scrollTop, elementToRevealTop, "Final value of scrollTop");
});
}, `Main frame with smooth scroll-behavior ; ${scrollFunction}() with auto behavior`);
promise_test(() => {
resetScroll(scrollingElement);
setScrollBehavior(styledElement, "smoothBehavior");
assert_equals(scrollingElement.scrollLeft, 0);
assert_equals(scrollingElement.scrollTop, 0);
scrollNode(scrollingElement, scrollFunction, "instant", elementToRevealLeft, elementToRevealTop);
assert_equals(scrollingElement.scrollLeft, elementToRevealLeft, "Should set scrollLeft immediately");
assert_equals(scrollingElement.scrollTop, elementToRevealTop, "Should set scrollTop immediately");
return new Promise((resolve) => { resolve(); });
}, `Main frame with smooth scroll-behavior ; ${scrollFunction}() with instant behavior`);
promise_test(() => {
resetScroll(scrollingElement);
setScrollBehavior(styledElement, "smoothBehavior");
assert_equals(scrollingElement.scrollLeft, 0);
assert_equals(scrollingElement.scrollTop, 0);
scrollNode(scrollingElement, scrollFunction, "smooth", elementToRevealLeft, elementToRevealTop);
assert_less_than(scrollingElement.scrollLeft, elementToRevealLeft, "Should not set scrollLeft immediately");
assert_less_than(scrollingElement.scrollTop, elementToRevealTop, "Should not set scrollTop immediately");
return waitForScrollEnd(scrollingElement).then(() => {
assert_equals(scrollingElement.scrollLeft, elementToRevealLeft, "Final value of scrollLeft");
assert_equals(scrollingElement.scrollTop, elementToRevealTop, "Final value of scrollTop");
});
}, `Main frame with smooth scroll-behavior ; ${scrollFunction}() with smooth behavior`);
});
[{scrollAttribute: "scrollLeft", scrollValue: elementToRevealLeft}, {scrollAttribute: "scrollTop", scrollValue: elementToRevealTop}].forEach((attributeTest) => {
promise_test(() => {
resetScroll(scrollingElement);
setScrollBehavior(styledElement, "autoBehavior");
assert_equals(scrollingElement.scrollLeft, 0);
assert_equals(scrollingElement.scrollTop, 0);
var expectedValue = Number(attributeTest.scrollValue);
scrollingElement[attributeTest.scrollAttribute] = expectedValue;
assert_equals( scrollingElement[attributeTest.scrollAttribute], expectedValue, "Should set scroll attribute immediately");
return new Promise((resolve) => { resolve(); });
}, `Set ${attributeTest.scrollAttribute} to frame with auto scroll-behavior`);
promise_test(() => {
resetScroll(scrollingElement);
setScrollBehavior(styledElement, "smoothBehavior");
assert_equals(scrollingElement.scrollLeft, 0);
assert_equals(scrollingElement.scrollTop, 0);
var expectedValue = Number(attributeTest.scrollValue);
scrollingElement[attributeTest.scrollAttribute] = expectedValue;
assert_less_than(scrollingElement[attributeTest.scrollAttribute], expectedValue, "Shouldn't set scroll attribute immediately");
return waitForScrollEnd(scrollingElement).then(() => {
assert_equals(scrollingElement[attributeTest.scrollAttribute], expectedValue, "Final value of scroll attribute");
});
}, `Set ${attributeTest.scrollAttribute} to frame with smooth scroll-behavior`);
});
promise_test(() => {
resetScroll(scrollingElement);
setScrollBehavior(styledElement, "smoothBehavior");
assert_equals(scrollingElement.scrollLeft, 0);
assert_equals(scrollingElement.scrollTop, 0);
scrollNode(scrollingElement, "scroll", "smooth", elementToRevealLeft, elementToRevealTop);
scrollNode(scrollingElement, "scroll", "smooth", elementToRevealLeft / 2, elementToRevealTop / 2);
return waitForScrollEnd(scrollingElement).then(() => {
assert_equals(scrollingElement.scrollLeft, elementToRevealLeft / 2, "Final value of scrollLeft");
assert_equals(scrollingElement.scrollTop, elementToRevealTop / 2, "Final value of scrollTop");
});
}, "Aborting an ongoing smooth scrolling on the main frame with another smooth scrolling");
promise_test(() => {
resetScroll(scrollingElement);
setScrollBehavior(styledElement, "smoothBehavior");
assert_equals(scrollingElement.scrollLeft, 0);
assert_equals(scrollingElement.scrollTop, 0);
scrollNode(scrollingElement, "scroll", "smooth", elementToRevealLeft, elementToRevealTop);
scrollNode(scrollingElement, "scroll", "instant", 0, 0);
return waitForScrollEnd(scrollingElement).then(() => {
assert_equals(scrollingElement.scrollLeft, 0, "Final value of scrollLeft");
assert_equals(scrollingElement.scrollTop, 0, "Final value of scrollTop");
});
}, "Aborting an ongoing smooth scrolling on the main frame with an instant scrolling");
}));
</script>
|