<html>
<head>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<script>
if (window.testRunner)
    testRunner.setUseSeparateServiceWorkerProcess(true);

promise_test(async (t) => {
    const worker1 = new SharedWorker('connect-event-ordering-sharedworker.js');
    const worker2 = new SharedWorker('connect-event-ordering-sharedworker.js');

    let promise1 = new Promise(resolve => { worker1.port.onmessage = (event) => resolve(event.data) });
    let promise2 = new Promise(resolve => { worker2.port.onmessage = (event) => resolve(event.data) });

    assert_equals(await promise1, "worker1");
    assert_equals(await promise2, "worker2");
}, "connect event should fire following SharedWorker creation order");
</script>
</body>
</html>
