summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/workers/shared-worker-name-via-options.html
blob: 1914d66db7489f6306c4365a4d7b7b9fb59fe00e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<!DOCTYPE html>
<meta charset="utf-8">
<title>Test the name property of shared workers mixing constructor options and constructor strings</title>
<link rel="help" href="https://html.spec.whatwg.org/multipage/#concept-workerglobalscope-name">
<link rel="help" href="https://html.spec.whatwg.org/multipage/#dom-sharedworker">
<link rel="help" href="https://html.spec.whatwg.org/multipage/#dom-sharedworkerglobalscope-name">
<link rel="author" title="Domenic Denicola" href="mailto:d@domenic.me">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<script>
"use strict";
setup({ single_test: true });

const name = "my name";

const worker1 = new SharedWorker("support/shared-name.js", { name });
worker1.port.onmessage = receiveMessage;

const worker2 = new SharedWorker("support/shared-name.js", { name });
worker2.port.onmessage = receiveMessage;

const worker3 = new SharedWorker("support/shared-name.js", name);
worker3.port.onmessage = receiveMessage;

let nextCounterExpected = 1;
function receiveMessage(e) {
  const { counter, name: receivedName } = e.data;

  assert_equals(receivedName, name);
  assert_equals(counter, nextCounterExpected);

  ++nextCounterExpected;
  if (nextCounterExpected === 4) {
    done();
  }
}
</script>