-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Expand file tree
/
Copy pathelement-scroll-promise-interruption.html
More file actions
194 lines (157 loc) · 7.22 KB
/
Copy pathelement-scroll-promise-interruption.html
File metadata and controls
194 lines (157 loc) · 7.22 KB
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
<!DOCTYPE html>
<title>Element scroll promises are interrupted correctly</title>
<meta name="timeout" content="long">
<meta name="viewport" content="width=device-width,initial-scale=1">
<link rel="author" title="Mustaq Ahmed" href="mailto:mustaq@chromium.org">
<link rel="help" href="https://drafts.csswg.org/cssom-view/#scrolling">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/dom/events/scrolling/scroll_support.js"></script>
<style>
.filler { height: 5000px }
.scroller {
overflow: scroll;
height: 100px;
}
</style>
<div id="scroller" class="scroller">
<div class="filler"></div>
<div class="filler"></div>
<div id="inner_scroller" class="scroller">
<div class="filler"></div>
<div class="filler"></div>
</div>
</div>
<div id="other_scroller" class="scroller">
<div class="filler"></div>
</div>
<script>
"use strict";
const scroller = document.getElementById("scroller");
const inner_scroller = document.getElementById("inner_scroller");
const other_scroller = document.getElementById("other_scroller");
const target_at_5000px = scroller.firstElementChild.nextElementSibling;
const innertarget_at_5000px = inner_scroller.lastElementChild;
function resetScrollPositions() {
scroller.scrollTop = 0;
inner_scroller.scrollTop = 0;
other_scroller.scrollTop = 0;
assert_true(!scroller.scrollTop && !inner_scroller.scrollTop
&& !other_scroller.scrollTop, "Sanity check initial position");
}
promise_setup(async () => {
await waitForCompositorReady();
});
for (const scroll_method of ["scrollTo", "scrollBy", "scrollIntoView"]) {
promise_test(async () => {
resetScrollPositions();
let promise1 = scroll_method != "scrollIntoView"
? scroller[scroll_method]({ top: 5000, behavior: "smooth" })
: target_at_5000px.scrollIntoView({ behavior: "smooth" });
const pos2 = 7000;
scroller.scrollTop = pos2;
assert_equals(scroller.scrollTop, pos2, "Position before promise wait");
const result1 = await promise1;
assert_true(result1.interrupted, "Interruption bit in promise");
assert_equals(scroller.scrollTop, pos2, "Position after promise wait");
}, `Element.${scroll_method} interrupted by a non-promise scroll`);
promise_test(async () => {
resetScrollPositions();
const pos1 = 5000;
let promise1 = scroll_method != "scrollIntoView"
? scroller[scroll_method]({ top: pos1, behavior: "smooth" })
: target_at_5000px.scrollIntoView({ behavior: "smooth" });
other_scroller.scrollTop = 100;
assert_not_equals(scroller.scrollTop, pos1,
"Position before promise wait");
const result1 = await promise1;
assert_false(result1.interrupted, "Interruption bit in promise");
assert_equals(scroller.scrollTop, pos1, "Position after promise wait");
}, `Element.${scroll_method} uninterrupted by an unrelated non-promise scroll`);
}
for (const interrupt_behavior of ["auto", "smooth"]) {
promise_test(async () => {
resetScrollPositions();
const pos1 = 5000;
let promise1 = scroller.scrollTo({ top: pos1, behavior: "smooth" });
const pos2 = 7000;
let promise2 =
scroller.scrollTo({ top: pos2, behavior: interrupt_behavior });
assert_not_equals(scroller.scrollTop, pos1,
"Position before first promise wait");
const result1 = await promise1;
assert_true(result1.interrupted, "Interruption bit in first promise");
assert_not_equals(scroller.scrollTop, pos1,
"Position after first promise wait");
const result2 = await promise2;
assert_false(result2.interrupted, "Interruption bit in second promise");
assert_equals(scroller.scrollTop, pos2,
"Position after interrupting promise wait");
}, `Element.scrollTo: interrupted by ${interrupt_behavior} scroll`);
promise_test(async () => {
resetScrollPositions();
const pos1 = 5000;
let promise1 = scroller.scrollBy({ top: pos1, behavior: "smooth" });
const pos2 = 2000;
let promise2 =
scroller.scrollBy({ top: pos2, behavior: interrupt_behavior });
assert_not_equals(scroller.scrollTop, pos1,
"Position before first promise wait");
const result1 = await promise1;
assert_true(result1.interrupted, "Interruption bit in first promise");
assert_not_equals(scroller.scrollTop, pos1,
"Position after first promise wait");
const result2 = await promise2;
assert_false(result2.interrupted, "Interruption bit in second promise");
assert_equals(scroller.scrollTop, pos2,
"Position after interrupting promise wait");
}, `Element.scrollBy: interrupted by ${interrupt_behavior} scroll`);
promise_test(async () => {
resetScrollPositions();
const pos1 = 5000;
let promise1 = target_at_5000px.scrollIntoView({ behavior: "smooth" });
const pos2 = 7000;
let promise2 =
scroller.scrollTo({ top: pos2, behavior: interrupt_behavior });
assert_not_equals(scroller.scrollTop, pos1,
"Position before first promise wait");
const result1 = await promise1;
assert_true(result1.interrupted, "Interruption bit in first promise");
assert_not_equals(scroller.scrollTop, pos1,
"Position after first promise wait");
const result2 = await promise2;
assert_false(result2.interrupted, "Interruption bit in second promise");
assert_equals(scroller.scrollTop, pos2,
"Position after interrupting promise wait");
}, `Element.scrollIntoView: interrupted by ${interrupt_behavior} scroll`);
}
// Below are scrollIntoView tests involving nested scrollers.
promise_test(async () => {
resetScrollPositions();
let promise1 = target_at_5000px.scrollIntoView({ behavior: "smooth" });
let promise2 = innertarget_at_5000px.scrollIntoView({ behavior: "smooth" });
const result1 = await promise1;
assert_true(result1.interrupted, "Interruption bit in first promise");
assert_not_equals(scroller.scrollTop, 5000,
"Position after first promise wait");
const result2 = await promise2;
assert_false(result2.interrupted, "Interruption bit in second promise");
assert_equals(scroller.scrollTop, 10000,
"Position after interrupting promise wait");
assert_equals(inner_scroller.scrollTop, 5000,
"Inner-position after interrupting promise wait");
}, `Element.scrollIntoView: interrupted by inner scroll`);
promise_test(async () => {
resetScrollPositions();
let promise1 = innertarget_at_5000px.scrollIntoView({ behavior: "smooth" });
let promise2 = target_at_5000px.scrollIntoView({ behavior: "smooth" });
const result1 = await promise1;
assert_true(result1.interrupted, "Interruption bit in first promise");
assert_not_equals(scroller.scrollTop, 10000,
"Position after first promise wait");
const result2 = await promise2;
assert_false(result2.interrupted, "Interruption bit in second promise");
assert_equals(scroller.scrollTop, 5000,
"Position after interrupting promise wait");
}, `Element.scrollIntoView: interrupted by outer scroll`);
</script>