-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
vt: Fire pagereveal on BFCache restore in iframe
Also add a test for pagereveal in an ordinary navigation in an iframe since this is lacking coverage. Fixed: 327187221 Change-Id: I1349cc1144f3a5d7e7d166a662606629d4c0db49 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5525858 Reviewed-by: Khushal Sagar <khushalsagar@chromium.org> Commit-Queue: David Bokan <bokan@chromium.org> Cr-Commit-Position: refs/heads/main@{#1298843}
- Loading branch information
1 parent
61d4018
commit 452afc7
Showing
3 changed files
with
135 additions
and
0 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
...owsers/browsing-the-web/history-traversal/pagereveal/order-in-bfcache-restore-iframe.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<!DOCTYPE html> | ||
<title>pagereveal event in iframe fires and in correct order on restoration from BFCache</title> | ||
<link rel="help" href="https://html.spec.whatwg.org/multipage/browsing-the-web.html#updating-the-document"> | ||
<link rel="author" href="mailto:bokan@chromium.org"> | ||
<meta name="timeout" content="long"> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="/common/utils.js"></script> | ||
<script src="/common/dispatcher/dispatcher.js"></script> | ||
<script src="/html/browsers/browsing-the-web/back-forward-cache/resources/helper.sub.js"></script> | ||
<script> | ||
|
||
// runBfcacheTest opens a popup to pageA which navigates to pageB and then | ||
// back, ensuring pageA is stored in the BFCache. | ||
runBfcacheTest({ | ||
scripts: ['/common/get-host-info.sub.js'], | ||
funcBeforeNavigation: async () => { | ||
// This function executes in pageA | ||
window.message = (data) => { | ||
return new Promise(resolve => { | ||
addEventListener('message', e => { | ||
if (data == undefined || data === e.data) | ||
resolve(e.data); | ||
}); | ||
}); | ||
} | ||
|
||
const frameLoaded = message('loaded'); | ||
const iframe = document.createElement('iframe'); | ||
iframe.src = `${get_host_info().OTHER_ORIGIN}/html/browsers/browsing-the-web/history-traversal/pagereveal/resources/iframe.html?restore`; | ||
document.body.appendChild(iframe); | ||
await frameLoaded; | ||
}, | ||
funcAfterAssertion: async (pageA, pageB, t) => { | ||
let event_log = await pageA.execute_script(async () => { | ||
const event_log = message(); | ||
document.querySelector('iframe').contentWindow.postMessage('getEventLog', '*'); | ||
return await event_log; | ||
}); | ||
|
||
// Expect that the events seen are: | ||
// pageshow.persisted, pagereveal, rAF, rAF, rAF, ... | ||
assert_equals(event_log.slice(0, 3).toString(), | ||
'pageshow.persisted,pagereveal,rAF'); | ||
for (let i = 3; i < event_log.length; ++i) { | ||
assert_equals(event_log[i], 'rAF', | ||
'All events following pagereveal should be animation frames'); | ||
} | ||
}, | ||
targetOrigin: originSameOrigin, | ||
}); | ||
</script> |
35 changes: 35 additions & 0 deletions
35
...rowsing-the-web/history-traversal/pagereveal/order-in-new-document-navigation-iframe.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<!DOCTYPE html> | ||
<title>pagereveal event fires and in correct order on new-document navigation in an iframe</title> | ||
<link rel="help" href="https://html.spec.whatwg.org/multipage/webappapis.html#update-the-rendering"> | ||
<link rel="author" href="mailto:bokan@chromium.org"> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="/common/get-host-info.sub.js"></script> | ||
<body> | ||
<script> | ||
function message(data) { | ||
return new Promise(resolve => { | ||
addEventListener('message', e => { | ||
if (data == undefined || data === e.data) | ||
resolve(e.data); | ||
}); | ||
}); | ||
} | ||
|
||
promise_test(async () => { | ||
const frameLoaded = message('loaded'); | ||
const iframe = document.createElement('iframe'); | ||
iframe.src = `${get_host_info().OTHER_ORIGIN}/html/browsers/browsing-the-web/history-traversal/pagereveal/resources/iframe.html`; | ||
document.body.appendChild(iframe); | ||
await frameLoaded; | ||
|
||
const event_log_promise = message(); | ||
iframe.contentWindow.postMessage('getEventLog', '*'); | ||
const event_log = await event_log_promise; | ||
|
||
// Expect that the events seen are: | ||
// pageshow.persisted, pagereveal, rAF, rAF, rAF, ... | ||
assert_equals(event_log.slice(0, 3).toString(),'pageshow,pagereveal,rAF'); | ||
}); | ||
</script> | ||
</body> |
48 changes: 48 additions & 0 deletions
48
html/browsers/browsing-the-web/history-traversal/pagereveal/resources/iframe.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<!DOCTYPE html> | ||
<!-- Logs rAF, pageshow, and pagereveal events. Load with '?restore' to ignore | ||
events prior to pageshow.persisted --> | ||
<script> | ||
// If the test is checking behavior after a BFCache restore, only record once | ||
// pageshow.persisted has been seen. | ||
const params = new URLSearchParams(window.location.search); | ||
let should_record = !params.has('restore'); | ||
|
||
let event_log = []; | ||
|
||
addEventListener('message', async e => { | ||
if (e.data === 'getEventLog') { | ||
// Ensure at least one animation frame is produced to ensure | ||
// pagereveal must have fired. | ||
await new Promise(requestAnimationFrame); | ||
e.source.postMessage(event_log, '*'); | ||
} | ||
}); | ||
|
||
addEventListener('load', () => { | ||
window.parent.postMessage('loaded', '*'); | ||
}) | ||
|
||
function recordRafs() { | ||
requestAnimationFrame( () => { | ||
if (should_record) | ||
event_log.push('rAF'); | ||
|
||
recordRafs(); | ||
}); | ||
} | ||
|
||
recordRafs(); | ||
|
||
addEventListener('pageshow', (e) => { | ||
if (e.persisted) | ||
should_record = true; | ||
|
||
if (should_record) | ||
event_log.push('pageshow' + (e.persisted ? '.persisted' : '')); | ||
}); | ||
|
||
addEventListener('pagereveal', () => { | ||
if (should_record) | ||
event_log.push('pagereveal'); | ||
}); | ||
</script> |