blob: db12df0d289be971cc26cd35dcbffc2f98d489e7 [file] [log] [blame]
<!DOCTYPE html>
<meta charset="utf-8">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/utils.js"></script>
// This controller must be on the window so it is visible to the iframe.
window.sharedController = new AbortController();
async function fetchJson(url) {
const response = await fetch(url);
assert_true(response.ok, 'response should be ok');
return response.json();
promise_test(async () => {
const stateKey = token();
const controller = new AbortController();
await fetch(`../resources/${stateKey}`,
signal: controller.signal,
keepalive: true
const before = await fetchJson(`../resources/${stateKey}`);
assert_equals(before, 'open', 'connection should be open');
// Spin until the abort completes.
while (true) {
const after = await fetchJson(`../resources/${stateKey}`);
if (after) {
// stateKey='open' was removed from the dictionary by the first fetch of
//, so we should only ever see the value 'closed' here.
assert_equals(after, 'closed', 'connection should have closed');
}, 'aborting a keepalive fetch should work');
promise_test(async t => {
const key = token();
const iframeEl = document.querySelector('iframe');
// Tell the iframe to start the fetch, and wait until it says it has.
await new Promise(resolve => {
onmessage = t.step_func(event => {
assert_equals(, 'started', 'event data should be "started"');
iframeEl.contentWindow.postMessage(key, '*');
// Detach the context of the fetch.
// The abort should not do anything. The connection should stay open. Wait 1
// second to give time for the fetch to complete.
await new Promise(resolve => t.step_timeout(resolve, 1000));
const after = await fetchJson(`../resources/${key}`);
assert_equals(after, 'on', 'fetch should have completed');
}, 'aborting a detached keepalive fetch should not do anything');
<iframe srcdoc="
<!DOCTYPE html>
<meta charset=utf-8>
onmessage = async event => {
const key =;
await fetch(
`../resources/;location=` +
signal: parent.sharedController.signal,
keepalive: true
parent.postMessage('started', '*');