summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/fetch/metadata/tools/templates/serviceworker.https.sub.html
blob: 82843255469e9c3e3ac6367ee5a8a059a33e86d4 (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
61
62
63
64
65
66
67
68
69
70
71
72
<!DOCTYPE html>
<!--
[%provenance%]
-->
<!DOCTYPE html>
<html lang="en">
  <meta charset="utf-8">
  <title>HTTP headers on request for Service Workers</title>
  <script src="/resources/testharness.js"></script>
  <script src="/resources/testharnessreport.js"></script>
  <script src="/fetch/metadata/resources/helper.sub.js"></script>
  <body>
  <script>
  'use strict';

  function induceRequest(t, url, options, event, clear) {
    // Register a service worker and check the request header.
    return navigator.serviceWorker.register(url, options)
      .then((registration) => {
        t.add_cleanup(() => registration.unregister());
        if (event === 'register') {
          return;
        }
        return clear().then(() => registration.update());
      });
  }

  {%- for subtest in subtests %}
  {%- set origin = subtest.origins[0]|default('httpsOrigin') %}
  {%- if origin == 'httpsOrigin' or not origin %}

  promise_test((t) => {
    const key = '{{uuid()}}';
    const url = makeRequestURL(
      key, [% subtest.origins %], { mime: 'application/javascript' }
    );

    return induceRequest(t, url, [%subtest.options | default({}) | tojson%], 'register')
      .then(() => retrieve(key))
      .then((headers) => {
        {%- if subtest.expected == none %}
          assert_not_own_property(headers, '[%subtest.headerName%]');
        {%- else %}
          assert_own_property(headers, '[%subtest.headerName%]');
          assert_array_equals(headers['[%subtest.headerName%]'], ['[%subtest.expected%]']);
        {%- endif %}
        });
  }, '[%subtest.headerName%] - [%subtest.description | pad("end", ", ")%][%subtest.options | collection("options")%] - registration');

  promise_test((t) => {
    const key = '{{uuid()}}';
    const url = makeRequestURL(
      key, [% subtest.origins %], { mime: 'application/javascript' }
    );

    return induceRequest(t, url, [%subtest.options | default({}) | tojson%], 'update', () => retrieve(key))
      .then(() => retrieve(key))
      .then((headers) => {
        {%- if subtest.expected == none %}
          assert_not_own_property(headers, '[%subtest.headerName%]');
        {%- else %}
          assert_own_property(headers, '[%subtest.headerName%]');
          assert_array_equals(headers['[%subtest.headerName%]'], ['[%subtest.expected%]']);
        {%- endif %}
        });
  }, '[%subtest.headerName%] - [%subtest.description | pad("end", ", ")%][%subtest.options | collection("options")%] - updating');

  {%- endif %}
  {%- endfor %}
  </script>
</body>
</html>