summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/service-workers/service-worker/websocket-in-service-worker.https.html
blob: cda9d6fe67e233e8b36dbfe12ddec2fa054de425 (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
<!DOCTYPE html>
<title>Service Worker: WebSockets can be created in a Service Worker</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/test-helpers.sub.js"></script>
<script>
promise_test(t => {
    const SCRIPT = 'resources/websocket-worker.js?pipe=sub';
    const SCOPE = 'resources/blank.html';
    let registration;
    return service_worker_unregister_and_register(t, SCRIPT, SCOPE)
      .then(r => {
          add_completion_callback(() => { r.unregister(); });
          registration = r;
          return wait_for_state(t, r.installing, 'activated');
        })
      .then(() => {
          return new Promise(resolve => {
              navigator.serviceWorker.onmessage = t.step_func(msg => {
                  assert_equals(msg.data, 'PASS');
                  resolve();
              });
              registration.active.postMessage({});
          });
        });
  }, 'Verify WebSockets can be created in a Service Worker');
</script>