<!DOCTYPE html>
<!--
This file cannot be upstreamed to WPT until:
* The test changes to use a method to trigger cancellation of prerendering that
is guaranteed by the specification. Currently the test cancels prerendering
by performing a main frame navigation after the initial prerendering
navigation.
* `unload` event handling matches what the specification expects. The current
specification expects that the unload event handler is never fired, and the
test passes whether or not it is fired.
* `pageshow` and `pagehide` behaviors during prerendering is clearly defined
in the specification. This test just checks current behaviors.
(https://crbug.com/1222551)
-->
<title>unload event handlers</title>
<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="/speculation-rules/prerender/resources/utils.js"></script>
<script src="resources/unload-utils.js"></script>
<script>
promise_test(async t => {
const uid = token();
const gotMessages = waitChannelMessage('load another-page in prerendering', uid);
const url = `resources/unload-on-prerender-main-frame-navigation.html?uid=${uid}`;
window.open(url, '_blank', 'noopener');
const result = await gotMessages;
// TODO(https://crbug.com/1520703): This test doesn't have a suitable name
// any more as now the main frame navigation is permitted for the same
// origin, and it would not result in the unload, or prerender cancellation.
// Rename the test, and have a cross-origin variant to cover different
// scenarios.
const expected = [
'load start',
'load prerendering in prerendering',
'request fallback',
'load another-page in prerendering',
];
assert_array_equals(result, expected, 'gotMessages');
}, 'unload on main frame navigation to cancel prerendering');
</script>