-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Expand file tree
/
Copy pathwindow-scroll-promises.html
More file actions
60 lines (51 loc) · 2.08 KB
/
window-scroll-promises.html
File metadata and controls
60 lines (51 loc) · 2.08 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
<!DOCTYPE html>
<title>Window.scroll* methods returning promises</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/#extensions-to-the-window-interface">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/dom/events/scrolling/scroll_support.js"></script>
<style>
.filler { height: 10000px }
</style>
<div class="filler"></div>
<script>
"use strict";
const scroll_methods = ["scroll", "scrollTo", "scrollBy"];
function reset() {
window.scrollTo({ top: 0 });
assert_equals(window.scrollY, 0, "Sanity check starting position");
}
promise_setup(async () => {
await waitForCompositorReady();
});
for (const scroll_method of scroll_methods) {
for (const behavior of ["auto", "instant", "smooth"]) {
const test_label = `Window.${scroll_method}(${behavior})`;
promise_test(async () => {
let result = window[scroll_method]({ behavior: behavior });
assert_true(result instanceof Promise);
const result_value = await result;
assert_equals(typeof result_value, "object");
assert_equals(typeof result_value.interrupted, "boolean");
}, `${test_label}: return type`);
promise_test(async () => {
reset();
const offset = 5000;
let promise = window[scroll_method]({ top: offset, behavior: behavior });
if (behavior != "smooth") {
assert_equals(window.scrollY, offset, "Position before await");
} else {
assert_true(0 <= window.scrollY && window.scrollY < offset,
"Position before await");
}
const result_value = await promise;
assert_equals(window.scrollY, offset, "Position after await");
assert_equals(typeof result_value, "object");
assert_equals(typeof result_value.interrupted, "boolean");
}, `${test_label}: promise behavior`);
}
}
</script>