Skip to content

Commit bbf5ec1

Browse files
natechapinchromium-wpt-export-bot
authored andcommitted
Don't proceed with same-document history traversals if the destination entry is no longer in the back/forward list
This fix will apply only if AppHistory is enabled, but will apply to *all* preempted same-document history traversals, even if AppHistory hasn't been used at all by the page. AppHistory has the requisite state to detect this case, but the rest of the renderer navigation logic does not. Bug: 1256622 Change-Id: I481067e6e02b61468d604dafcce962a62439a3f8 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3206547 Reviewed-by: Domenic Denicola <[email protected]> Commit-Queue: Nate Chapin <[email protected]> Cr-Commit-Position: refs/heads/main@{#934575}
1 parent 96ca25f commit bbf5ec1

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<!doctype html>
2+
<script src="/resources/testharness.js"></script>
3+
<script src="/resources/testharnessreport.js"></script>
4+
<script>
5+
promise_test(async t => {
6+
// Wait for after the load event so that the navigation doesn't get converted
7+
// into a replace navigation.
8+
await new Promise(resolve => window.onload = () => t.step_timeout(resolve, 0));
9+
await appHistory.navigate("#foo").finished;
10+
assert_equals(appHistory.entries().length, 2);
11+
await appHistory.back().finished;
12+
assert_equals(appHistory.current.index, 0);
13+
14+
// Traverse forward then immediately do a same-document push. This will
15+
// truncate the back forward list, and by the time the traverse commits, the
16+
// destination key will no longer be present in appHistory.entries(). The
17+
// traverse should abort.
18+
let forward_value = appHistory.forward();
19+
await appHistory.navigate("#clobber").finished;
20+
assert_equals(appHistory.current.index, 1);
21+
await promise_rejects_dom(t, "AbortError", forward_value.committed);
22+
await promise_rejects_dom(t, "AbortError", forward_value.finished);
23+
24+
// This leaves appHistory.entries() in a consistent state where traversing
25+
// back and forward still works.
26+
await appHistory.back().finished;
27+
assert_equals(appHistory.current.index, 0);
28+
await appHistory.forward().finished;
29+
assert_equals(appHistory.current.index, 1);
30+
}, "If forward pruning clobbers the target of a traverse, abort");
31+
</script>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<!doctype html>
2+
<script src="/resources/testharness.js"></script>
3+
<script src="/resources/testharnessreport.js"></script>
4+
<script>
5+
promise_test(async t => {
6+
// Wait for after the load event so that the navigation doesn't get converted
7+
// into a replace navigation.
8+
await new Promise(resolve => window.onload = () => t.step_timeout(resolve, 0));
9+
location.hash = "#1";
10+
location.hash = "#2";
11+
history.go(-2);
12+
await new Promise(r => window.onpopstate = r);
13+
14+
// Traverse forward then immediately do a same-document push. This will
15+
// truncate the back forward list.
16+
history.forward();
17+
location.hash = "#clobber";
18+
19+
// history.forward() should be aborted.
20+
window.onpopstate = t.unreached_func("history.forward() should have been cancelled");
21+
await new Promise(r => t.step_timeout(r, 20));
22+
assert_equals(location.hash, "#clobber");
23+
}, "If forward pruning clobbers the target of a traverse, abort");
24+
25+
</script>

0 commit comments

Comments
 (0)