<html>
<head>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/service-workers/service-worker/resources/test-helpers.sub.js"></script>
</head>
<body>
<script>
var scope = "resources";
var activeWorker;

promise_test(async (test) => {
    var registration = await navigator.serviceWorker.register("fetch-worker-terminate-worker.js", { scope : scope });
    activeWorker = registration.active;
    if (activeWorker)
        return;
    activeWorker = registration.installing;
    return new Promise(resolve => {
        activeWorker.addEventListener('statechange', () => {
            if (activeWorker.state === "activated")
                resolve();
        });
    });
}, "Setup worker");

promise_test(async (test) => {
    const iframe = await with_iframe(scope);

    const response = await iframe.contentWindow.fetch("/terminate-while-fetching");
    assert_equals(response.status, 404);
}, "Make sure a load goes to the network when worker terminates while load is not yet responded");
</script>
</body>
</html>
