Skip to content

Commit

Permalink
vt: Fire pagereveal on BFCache restore in iframe
Browse files Browse the repository at this point in the history
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
bokand authored and chromium-wpt-export-bot committed May 9, 2024
1 parent 61d4018 commit 452afc7
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 0 deletions.
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>
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>
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>

0 comments on commit 452afc7

Please sign in to comment.