summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/fetch/api/request/destination/fetch-destination-worker.https.html
blob: 5935c1ff31ec4bf84b65fc2a92ff7276f4e79fed (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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<!DOCTYPE html>
<title>Fetch destination tests for resources with no load event</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="/service-workers/service-worker/resources/test-helpers.sub.js"></script>
<script>
let frame;

// Set up the service worker and the frame.
promise_test(t => {
    const kScope = 'resources/dummy.html';
    const kScript = 'resources/fetch-destination-worker-no-load-event.js';
    return service_worker_unregister_and_register(t, kScript, kScope)
      .then(registration => {
          add_completion_callback(() => {
              registration.unregister();
            });

          return wait_for_state(t, registration.installing, 'activated');
        })
      .then(() => {
          return with_iframe(kScope);
        })
      .then(f => {
          frame = f;
          add_completion_callback(() => { f.remove(); });
        });
  }, 'Initialize global state');

var waitOnMessageFromSW = async t => {
    await new Promise((resolve, reject) => {
        frame.contentWindow.navigator.serviceWorker.onmessage = t.step_func(event => {
            if (event.data == "PASS") {
                resolve();
            } else {
                reject();
            }
        });
    }).catch(() => {;
        assert_unreached("Wrong destination.");
    });
    t.add_cleanup(() => { frame.contentWindow.navigator.serviceWorker.onmessage = null; });
}

// worker destination
/////////////////////
promise_test(async t => {
    // We can use an html file as we don't really care about the dedicated worker successfully loading.
    let worker = new frame.contentWindow.Worker("dummy.html?t=worker&dest=worker");
    await waitOnMessageFromSW(t);
}, 'DedicatedWorker fetches with a "worker" Request.destination');

promise_test(async t => {
    // We can use an html file as we don't really care about the shared worker successfully loading.
    let worker = new frame.contentWindow.SharedWorker("dummy.html?t=sharedworker&dest=sharedworker");
    await waitOnMessageFromSW(t);
}, 'SharedWorker fetches with a "sharedworker" Request.destination');

</script>