Source code
Revision control
Copy as Markdown
Other Tools
Test Info:
- This WPT test may be referenced by the following Test IDs:
- /css/css-view-transitions/navigation/prerender-removed-during-navigation.html - WPT Dashboard Interop Dashboard
<!DOCTYPE html>
<title>View transitions: cross-document navigation to a prerender cancelled before commit</title>
<link rel="help" href="https://drafts.csswg.org/css-view-transitions-2/">
<link rel="author" href="mailto:bokan@chromium.org">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/utils.js"></script>
<script src="/speculation-rules/resources/utils.js"></script>
<script src="/speculation-rules/prerender/resources/utils.js"></script>
<style>
@view-transition {
navigation: auto;
}
html {
background-color: red;
}
html.outgoing {
background-color: cornflowerblue;
}
html.incoming {
background-color: hotpink;
}
::view-transition {
background-color: limegreen;
}
::view-transition-new(root) {
transform: translateY(55vh);
animation: none;
opacity: 1;
}
::view-transition-old(root) {
transform: translateY(-55vh);
animation: none;
opacity: 1;
}
::view-transition-group(root) {
animation-duration: 300s;
}
</style>
<script>
const params = new URLSearchParams(location.search);
const uid = params.has('uid') ? params.get('uid') : token();
const mode = params.get("mode") || "test";
if (mode === "test") {
promise_test(async t => {
const result = await new Promise(resolve => {
window.did_reveal = msg => { resolve(msg) };
// Speculation rules are not supported in popups in some environments,
// but let's try.
if (!implementsSpeculationRules()) {
resolve("skip: speculation rules not supported");
return;
}
const popup = window.open(`?mode=old&uid=${uid}`);
t.add_cleanup(() => popup.close());
});
if (result.startsWith("skip:")) {
return; // Skip if not supported
}
assert_equals(result, "pass");
});
} else if (mode === "old") {
const ready_channel = new PrerenderChannel('ready-to-activate', uid);
onload = async () => {
document.documentElement.classList.add('outgoing');
const next_url =
new URL(`?mode=new&uid=${uid}`, window.location).href;
const ready_to_activate = new Promise(resolve => {
ready_channel.addEventListener('message', resolve, {once: true});
});
let prerender_script = startPrerendering(next_url);
await ready_to_activate;
onpageswap = () => {
prerender_script.remove();
}
window.location.replace(new URL(next_url, window.location));
};
} else if (mode === "new") {
const ready_channel = new PrerenderChannel('ready-to-activate', uid);
if (document.prerendering) {
ready_channel.postMessage('readyToActivateMessage');
ready_channel.close();
} else {
document.documentElement.classList.add('incoming');
// Since the prerender was cancelled/removed, we expect a normal navigation?
// Or wait, the test says "cancelled before commit".
// If we are here, we are on the new page.
// The reftest expected "incomingPage" visual state.
// We can just signal success.
if (window.opener) window.opener.did_reveal("pass");
}
}
function implementsSpeculationRules() {
return ('supports' in HTMLScriptElement) &&
HTMLScriptElement.supports('speculationrules');
}
</script>