chromium/third_party/blink/web_tests/wpt_internal/prerender/resources/unload-on-prerender-remove-subframe.html

<!DOCTYPE html>
<script src="/common/get-host-info.sub.js"></script>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/speculation-rules/prerender/resources/utils.js"></script>
<script src="unload-utils.js"></script>

<body>
  <script type="module">
    const params = new URLSearchParams(location.search);
    const state = params.get('state') || 'start';
    const uid = params.get('uid');

    // Test steps:
    //   1. `start` page starts prerendering `prerendering` page.
    //   2. `prerendering` page adds `frame`.
    //   3. `prerendering` page removes `frame`.
    //   4. `pageshow`, `pagehide` and `unload` are handled in `frame`.
    if (state == 'start') {
      sendChannelMessage('load ' + state, uid);
      startPrerendering(createTestUrl('prerendering', uid));
    } else if (state === 'prerendering') {
      sendChannelMessage('load ' + state, uid);
      const frame = addFrame(createTestUrl('frame', uid));

      // Wait until the frame is loaded and requests removal.
      await waitChannelMessage('request removal', uid);

      frame.remove();
      sendChannelMessage('remove frame in prerendering', uid);
    } else if (state == 'frame') {
      // Send load state and a request to remove the frame in bulk to avoid
      // reordering. PrerenderChannel#postMessage() doesn't guarantee the message
      // order as it internally uses fetch().
      sendChannelMessage(['load ' + state, 'request removal'], uid);
    }
  </script>
</body>