Files
firefox/testing/web-platform/tests/css/cssom-view/scrollIntoView-smooth.html
François Doray 465890247d Bug 1918753 [wpt PR 48163] - [blink] Fix smooth-scroll-in-load-event.html., a=testonly
Automatic update from web-platform-tests
[blink] Fix smooth-scroll-in-load-event.html.

The test fails with this error on most platforms:

[FAIL] Smooth scroll in load event handler
  assert_equals: Final value of scrollLeft expected 800 but got 0

This is because observeScrolling() completes after 20 rAF without
change to the scroll position, which is not enough for the scroll
animation to start on most platforms. This CL fixes the test by
replacing observeScrolling() with a function that waits for the
"scrollend" event.

This CL also moves the function to wait to a "scrollend" event from
css/css-scroll-snap/support/common.js to
dom/events/scrolling/scroll_support.js for better reusability, and
renames it to waitForScrollEndFallbackToDelayWithoutScrollEvent() to
convey that it has a different behavior when the "scrollend" event is
not available.

Fixed: 327468395
Change-Id: I63d89cd1d0bf0973543aa769765eac00b62ba87c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5823436
Commit-Queue: Francois Pierre Doray <[email protected]>
Reviewed-by: Robert Flack <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1355320}

--

wpt-commits: 922a7fe9a4f5bffd0161e11b38bac8f76ef03efd
wpt-pr: 48163
2024-09-16 05:58:28 +00:00

81 lines
3.9 KiB
HTML

<!DOCTYPE HTML>
<!-- meta name="viewport" content="width=device-width,initial-scale=1" -->
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/dom/events/scrolling/scroll_support.js"></script>
<title>Check End Position of smooth scrollIntoView</title>
<div id="container" style="height: 2500px; width: 2500px;">
<div id="content" style="height: 500px; width: 500px;margin-left: 1000px; margin-right: 1000px; margin-top: 1000px;margin-bottom: 1000px;background-color: red">
</div>
<div id="shadow"></div>
</div>
<script>
var content_height = 500;
var content_width = 500;
var window_height = document.documentElement.clientHeight;
var window_width = document.documentElement.clientWidth;
var content = document.getElementById("content");
add_completion_callback(() => document.getElementById("container").remove());
// When testing manually, we need an additional frame at beginning
// to trigger the effect.
requestAnimationFrame(() => {
promise_test(async (t) => {
await waitForScrollReset(t, document.scrollingElement);
var expected_x = content.offsetLeft + content_width - window_width;
var expected_y = content.offsetTop + content_height - window_height;
assert_not_equals(window.scrollX, expected_x, "scrollX");
assert_not_equals(window.scrollY, expected_y, "scrollY");
const scrollend_promise = waitForScrollEndFallbackToDelayWithoutScrollEvent(document);
content.scrollIntoView({behavior: "smooth", block: "nearest", inline:
"nearest"});
await scrollend_promise;
assert_approx_equals(window.scrollX, expected_x, 1, "scrollX");
assert_approx_equals(window.scrollY, expected_y, 1, "scrollY");
}, "Smooth scrollIntoView should scroll the element to the 'nearest' position");
promise_test(async (t) => {
await waitForScrollReset(t, document.scrollingElement);
var expected_x = content.offsetLeft;
var expected_y = content.offsetTop;
assert_not_equals(window.scrollX, expected_x, "scrollX");
assert_not_equals(window.scrollY, expected_y, "scrollY");
const scrollend_promise = waitForScrollEndFallbackToDelayWithoutScrollEvent(document);
content.scrollIntoView({behavior: "smooth", block: "start", inline:
"start"});
await scrollend_promise;
assert_approx_equals(window.scrollX, expected_x, 1, "scrollX");
assert_approx_equals(window.scrollY, expected_y, 1, "scrollY");
}, "Smooth scrollIntoView should scroll the element to the 'start' position");
promise_test(async (t) => {
await waitForScrollReset(t, document.scrollingElement);
var expected_x = content.offsetLeft + (content_width - window_width) / 2;
var expected_y = content.offsetTop + (content_height - window_height) / 2;
assert_not_equals(window.scrollX, expected_x, "scrollX");
assert_not_equals(window.scrollY, expected_y, "scrollY");
const scrollend_promise = waitForScrollEndFallbackToDelayWithoutScrollEvent(document);
content.scrollIntoView({behavior: "smooth", block: "center", inline:
"center"});
await scrollend_promise;
assert_approx_equals(window.scrollX, expected_x, 1, "scrollX");
assert_approx_equals(window.scrollY, expected_y, 1, "scrollY");
}, "Smooth scrollIntoView should scroll the element to the 'center' position");
promise_test(async (t) => {
await waitForScrollReset(t, document.scrollingElement);
var expected_x = content.offsetLeft + content_width - window_width;
var expected_y = content.offsetTop + content_height - window_height;
assert_not_equals(window.scrollX, expected_x, "scrollX");
assert_not_equals(window.scrollY, expected_y, "scrollY");
const scrollend_promise = waitForScrollEndFallbackToDelayWithoutScrollEvent(document);
content.scrollIntoView({behavior: "smooth", block: "end", inline:
"end"});
await scrollend_promise;
assert_approx_equals(window.scrollX, expected_x, 1, "scrollX");
assert_approx_equals(window.scrollY, expected_y, 1, "scrollY");
}, "Smooth scrollIntoView should scroll the element to the 'end' position");
});
</script>