Skip to content

Commit

Permalink
NavigateEvent.restoreScroll() should throw if repeated or called afte…
Browse files Browse the repository at this point in the history
…r transition completes

Fixed: 1310014
Change-Id: I7bd395d69b39117b981a24fb2da0e4f8d1045f86
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3564998
Auto-Submit: Nate Chapin <japhet@chromium.org>
Reviewed-by: Domenic Denicola <domenic@chromium.org>
Commit-Queue: Domenic Denicola <domenic@chromium.org>
Cr-Commit-Position: refs/heads/main@{#987951}
  • Loading branch information
natechapin authored and chromium-wpt-export-bot committed Apr 1, 2022
1 parent 80bb197 commit 360fe71
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
};
await navigation.back().finished;
assert_not_equals(window.scrollY, 0);
navigate_event.restoreScroll();
assert_throws_dom("InvalidStateError", () => navigate_event.restoreScroll());
assert_not_equals(window.scrollY, 0);
}, "scrollRestoration: restoreScroll() should not work after a navigation finished promise fulfills");
}, "scrollRestoration: restoreScroll() should throw after a navigation finished promise fulfills");
</script>
</body>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!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.transitionWhile(Promise.resolve(), { scrollRestoration: "manual" });
e.restoreScroll();
assert_equals(window.scrollY, 0);
assert_throws_dom("InvalidStateError", () => e.restoreScroll());
});
await navigation.back().finished;
assert_equals(window.scrollY, 0);
}, "scrollRestoration: restoreScroll() should throw if called a second time");
</script>
</body>

0 comments on commit 360fe71

Please sign in to comment.