fune/testing/web-platform/tests/navigation-api/scroll-behavior/after-transition-explicit-scroll.html
Nate Chapin 4d0f3819e1 Bug 1817345 [wpt PR 38562] - Refactor NavigateEvent state checks, a=testonly
Automatic update from web-platform-tests
Refactor NavigateEvent state checks

* Add a PerformSharedChecks() helper for entry point checks that
  apply to all functions on NavigateEvent (e.g., checking for
  detached window, whether the event is trusted, etc.)
* Add a state machine for tracking interception state in
  NavigateEvent. Current states are None, Intercepted, Committed,
  Scrolled, Finished, and transitions must increase. This is hopefully
  easy to follow than the several independent booleans we are
  currently using.
* Adding the state machine shows that it's possible to scroll before
  commit by calling scroll() during navigate event dispatch (and in
  fact, several tests do so). Fix that.

Change-Id: I48095b97a3463d6bc145114639dbfc5711822b27
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4262131
Commit-Queue: Nate Chapin <japhet@chromium.org>
Reviewed-by: Domenic Denicola <domenic@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1109657}

--

wpt-commits: 4ec997cb455c429be5b26681b0515428e086cac1
wpt-pr: 38562
2023-03-07 00:23:49 +00:00

29 lines
963 B
HTML

<!doctype html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<body>
<div style="height: 1000px; width: 1000px;"></div>
<div id="frag"></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;
assert_not_equals(window.scrollY, 0);
navigation.onnavigate = t.step_func(e => {
e.intercept({
scroll: "after-transition",
handler: t.step_func(() => {
assert_not_equals(window.scrollY, 0);
e.scroll();
assert_equals(window.scrollY, 0);
})
});
});
await navigation.back().finished;
assert_equals(window.scrollY, 0);
}, "scroll: scroll() should preempt after-transition");
</script>
</body>