Skip to content

Commit f15c0b5

Browse files
natechapinchromium-wpt-export-bot
authored andcommitted
AppHistory bfcache support
Currently, with appHistory and bfcache both enabled, appHistory's entries() arrays are not updated when a navigation is served from bfcache. It keeps the same appHistory.entries() that it had when the document was put into bfcache, but the entries() almost certainly have changed in the meantime. This CL ensures that when blink is notified of the restore from bfcache, it also receives updated appHistory.entries(). Any entries that evicted from appHistory.entries() as a result of the restore will have dispose events fired. Fixed: 1241655 Change-Id: I9c49312ccbbec714f751f3b59c8d1f05edb024fd Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3277336 Reviewed-by: Charles Reis <[email protected]> Reviewed-by: Mason Freed <[email protected]> Reviewed-by: Rakina Zata Amni <[email protected]> Reviewed-by: Domenic Denicola <[email protected]> Reviewed-by: Daniel Cheng <[email protected]> Commit-Queue: Nate Chapin <[email protected]> Cr-Commit-Position: refs/heads/main@{#972761}
1 parent 114cb3e commit f15c0b5

File tree

5 files changed

+133
-0
lines changed

5 files changed

+133
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<!doctype html>
2+
<script src="/resources/testharness.js"></script>
3+
<script src="/resources/testharnessreport.js"></script>
4+
<script src="/common/utils.js"></script>
5+
<script src="/common/dispatcher/dispatcher.js"></script>
6+
<script src="/html/browsers/browsing-the-web/back-forward-cache/resources/helper.sub.js"></script>
7+
<script src="resources/is_uuid.js"></script>
8+
9+
<script>
10+
// This test ensures that appHistory.entries() in an iframe is properly updated
11+
// when a page is restored from bfcache.
12+
// First, create an iframe and do a fragment navigation in it, so that its
13+
// appHistory.entries().length == 2. Then go back, so that entries()[0] is
14+
// current. Finally, navigate the main window (which should clobber the
15+
// the iframe's entries()[1]), and come back via bfcache. If the iframe's
16+
// entries() were updated, then its entries().length should have been reduced
17+
// to 1.
18+
runBfcacheTest({
19+
targetOrigin: originSameOrigin,
20+
funcBeforeNavigation: async () => {
21+
window.events = [];
22+
let i = document.createElement("iframe");
23+
i.src = "/common/blank.html";
24+
document.body.appendChild(i);
25+
await new Promise(resolve => i.onload = () => setTimeout(resolve, 0));
26+
await i.contentWindow.appHistory.navigate("#foo");
27+
await i.contentWindow.appHistory.back();
28+
window.frames[0].appHistory.entries()[1].ondispose = () => events.push("dispose");
29+
window.frames[0].onpageshow = () => events.push("pageshow");
30+
},
31+
async funcAfterAssertion(pageA, pageB) {
32+
assert_equals(await pageA.execute_script(() => window.frames[0].appHistory.entries().length), 1);
33+
assert_array_equals(await pageA.execute_script(() => window.events), ["pageshow", "dispose"]);
34+
}
35+
}, "entries() in an iframe must be updated after navigating back to a bfcached page");
36+
</script>
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<!doctype html>
2+
<script src="/resources/testharness.js"></script>
3+
<script src="/resources/testharnessreport.js"></script>
4+
<script src="/common/utils.js"></script>
5+
<script src="/common/dispatcher/dispatcher.js"></script>
6+
<script src="/html/browsers/browsing-the-web/back-forward-cache/resources/helper.sub.js"></script>
7+
<script src="resources/is_uuid.js"></script>
8+
9+
<script>
10+
// This test ensures that appHistory.entries() is properly updated when a page
11+
// is restored from bfcache. Before navigating away and back, entries() contains
12+
// a single entry representing this document. When restored from bfcache,
13+
// entries() should now have two entries: [0] should still be this document, but
14+
// [1] should represent the document that we navigated to and back from
15+
// (assuming that document is same-origin to this one).
16+
runBfcacheTest({
17+
targetOrigin: originSameOrigin,
18+
funcBeforeNavigation: () => {
19+
window.originalEntry0 = appHistory.entries()[0];
20+
},
21+
async funcAfterAssertion(pageA, pageB) {
22+
const entryData = await pageA.execute_script(() => {
23+
return appHistory.entries().map(e => ({
24+
url: e.url,
25+
key: e.key,
26+
id: e.id,
27+
index: e.index,
28+
sameDocument: e.sameDocument
29+
}));
30+
});
31+
32+
assert_equals(entryData.length, 2);
33+
34+
// Ensure that [1] has the proper url, and otherwise is initialized as
35+
// a cross-document AppHistoryEntry ought to be.
36+
assert_equals(entryData[0].url, pageA.url);
37+
assert_equals(entryData[1].url, pageB.url);
38+
39+
assert_true(isUUID(entryData[0].key));
40+
assert_true(isUUID(entryData[1].key));
41+
assert_not_equals(entryData[0].key, entryData[1].key);
42+
43+
assert_true(isUUID(entryData[0].id));
44+
assert_true(isUUID(entryData[1].id));
45+
assert_not_equals(entryData[0].id, entryData[1].id);
46+
47+
assert_equals(entryData[0].index, 0);
48+
assert_equals(entryData[1].index, 1);
49+
50+
assert_true(entryData[0].sameDocument);
51+
assert_false(entryData[1].sameDocument);
52+
53+
const currentIsZero = await pageA.execute_script(() => appHistory.current === appHistory.entries()[0]);
54+
assert_true(currentIsZero);
55+
56+
const zeroIsSameAsOriginal = await pageA.execute_script(() => appHistory.current === window.originalEntry0);
57+
assert_true(zeroIsSameAsOriginal);
58+
}
59+
}, "entries() must contain the forward-history page after navigating back to a bfcached page");
60+
</script>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<!doctype html>
2+
<script src="/resources/testharness.js"></script>
3+
<script src="/resources/testharnessreport.js"></script>
4+
<script src="/common/utils.js"></script>
5+
<script src="/common/dispatcher/dispatcher.js"></script>
6+
<script src="/html/browsers/browsing-the-web/back-forward-cache/resources/helper.sub.js"></script>
7+
<script src="resources/is_uuid.js"></script>
8+
9+
<script>
10+
// This test:
11+
// * Does a fragment navigation, then goes back (same-document).
12+
// * Navigates away, then back via bfcache.
13+
// When navigating away, appHistory.entries()[1] will be overwritten.
14+
// When returning after bfcache restore, appHistory.entries()[1] should represent
15+
// pageB, and the original appHistory.entries()[1] should have been disposed.
16+
runBfcacheTest({
17+
targetOrigin: originSameOrigin,
18+
funcBeforeNavigation: async () => {
19+
window.events = [];
20+
await appHistory.navigate("#1");
21+
await appHistory.back();
22+
window.originalEntry1 = appHistory.entries()[1];
23+
window.originalEntry1.ondispose = () => events.push("dispose");
24+
window.onpageshow = () => events.push("pageshow");
25+
},
26+
async funcAfterAssertion(pageA, pageB) {
27+
assert_equals(await pageA.execute_script(() => appHistory.entries().length), 2);
28+
assert_false(await pageA.execute_script(() => window.originalEntry1 === appHistory.entries[1]));
29+
assert_array_equals(await pageA.execute_script(() => window.events), ["pageshow", "dispose"]);
30+
}
31+
}, "entries() must contain the forward-history page after navigating back to a bfcached page");
32+
</script>

html/browsers/browsing-the-web/back-forward-cache/resources/helper.sub.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@ function runBfcacheTest(params, description) {
153153
const urlA = executorPath + pageA.context_id;
154154
const urlB = params.targetOrigin + executorPath + pageB.context_id;
155155

156+
// So that tests can refer to these URLs for assertions if necessary.
157+
pageA.url = originSameOrigin + urlA;
158+
pageB.url = urlB;
159+
156160
params.openFunc(urlA);
157161

158162
await pageA.execute_script(waitForPageShow);

lint.ignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ PARSE-FAILED: custom-elements/xhtml-crash.xhtml
138138
SET TIMEOUT: *-manual.*
139139
SET TIMEOUT: annotation-model/scripts/ajv.min.js
140140
SET TIMEOUT: apng/animated-png-timeout.html
141+
SET TIMEOUT: app-history/app-history-entry/entries-after-bfcache-in-iframe.html
141142
SET TIMEOUT: cookies/resources/testharness-helpers.js
142143
SET TIMEOUT: common/reftest-wait.js
143144
SET TIMEOUT: conformance-checkers/*

0 commit comments

Comments
 (0)