fune/testing/web-platform/tests/navigation-api/scroll-behavior/manual-scroll-reload.html
Nate Chapin 87192c6c70 Bug 1780442 [wpt PR 34919] - Navigation API: Revamp intercepted-navigation scroll handling, a=testonly
Automatic update from web-platform-tests
Navigation API: Revamp intercepted-navigation scroll handling

Follows https://github.com/WICG/navigation-api/pull/239

Intent to Ship: https://groups.google.com/a/chromium.org/g/blink-dev/c/DKeklNbLG5s

Bug: 1345507
Change-Id: Id5c1b9d77953388dbe287f6403b0a49c8359d51b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3758902
Reviewed-by: Chris Harrelson <chrishtr@chromium.org>
Reviewed-by: Domenic Denicola <domenic@chromium.org>
Commit-Queue: Nate Chapin <japhet@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1026382}

--

wpt-commits: 5fb15e04adca47cc972a2e4c665853aca6a1a5b9
wpt-pr: 34919
2022-07-22 02:09:17 +00:00

45 lines
1.6 KiB
HTML

<!doctype html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<body>
<div id="buffer" style="height: 1000px; width: 1000px;"></div>
<div id="frag"></div>
<div style="height: 1000px; width: 1000px;"></div>
<script>
promise_test(async t => {
// Wait for after the load event so that the navigation doesn't get converted
// into a replace navigation.
await new Promise(resolve => window.onload = () => t.step_timeout(resolve, 0));
assert_equals(window.scrollY, 0);
await navigation.navigate("#frag").finished;
// Scroll down 10px from #frag
window.scrollBy(0, 10);
let scrollY_frag_plus_10 = window.scrollY;
let intercept_resolve;
let navigate_event;
navigation.onnavigate = e => {
navigate_event = e;
e.intercept({ handler: () => new Promise(r => intercept_resolve = r),
scroll: "manual" });
};
let reload_promises = navigation.reload();
await reload_promises.committed;
// removing the <div id="buffer"> should scroll up 1000px.
assert_equals(window.scrollY, scrollY_frag_plus_10);
buffer.remove();
let scrollY_after_buffer_remove = window.scrollY;
assert_equals(scrollY_after_buffer_remove, scrollY_frag_plus_10 - 1000);
// scroll() should scroll to #frag, which is 10px up from the current location
navigate_event.scroll();
assert_equals(window.scrollY, scrollY_after_buffer_remove - 10);
// Finishing should not scroll.
intercept_resolve();
await reload_promises.finished;
assert_equals(window.scrollY, scrollY_after_buffer_remove - 10);
}, "scroll: scroll() should work on a reload navigation");
</script>
</body>