<!DOCTYPE html>
<html>
<head>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<script>
var activeWorker;

promise_test(async (test) => {
    if (window.testRunner) {
        testRunner.setUseSeparateServiceWorkerProcess(true);
        await fetch("").then(() => { }, () => { });
    }

    var registration = await navigator.serviceWorker.register("service-worker-process-worker.js", { 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) => {
    let resolve;
    const promise = new Promise(r => resolve = r);
    navigator.serviceWorker.addEventListener("message", (e) => resolve(e.data), {once: true}); 
    activeWorker.postMessage("PID");
    assert_not_equals(await promise, window.internals.processIdentifier);
}, "Test that service worker is in a different process");

</script>
</body>
</html>
