function keepaliveCorsInUnloadTest(description, origin, method) {
  const evt = 'unload';
  for (const mode of ['no-cors', 'cors']) {
    for (const disallowCrossOrigin of [false, true]) {
      const desc = `${description} ${method} request in ${evt} [${mode} mode` +
          (disallowCrossOrigin ? ']' : ', server forbid CORS]');
      const expectTokenExist = !disallowCrossOrigin || mode === 'no-cors';
      promise_test(async (test) => {
        const token1 = token();
        const iframe = document.createElement('iframe');
        iframe.src = getKeepAliveIframeUrl(token1, method, {
          frameOrigin: '',
          requestOrigin: origin,
          sendOn: evt,
          mode: mode,
          disallowCrossOrigin
        });
        document.body.appendChild(iframe);
        await iframeLoaded(iframe);
        iframe.remove();
        assert_equals(await getTokenFromMessage(), token1);

        assertStashedTokenAsync(desc, token1, {expectTokenExist});
      }, `${desc}; setting up`);
    }
  }
}
In a same-site iframe, and in `unload` event handler, test to fetch
a keepalive URL that involves in different cors modes.