File: fetch-via-serviceworker.https.sub.html

package info (click to toggle)
firefox 149.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,767,760 kB
  • sloc: cpp: 7,416,064; javascript: 6,752,859; ansic: 3,774,850; python: 1,250,473; xml: 641,578; asm: 439,191; java: 186,617; sh: 56,634; makefile: 18,856; objc: 13,092; perl: 12,763; pascal: 5,960; yacc: 4,583; cs: 3,846; lex: 1,720; ruby: 1,002; php: 436; lisp: 258; awk: 105; sql: 66; sed: 53; csh: 10; exp: 6
file content (88 lines) | stat: -rw-r--r-- 2,898 bytes parent folder | download | duplicates (19)
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<!DOCTYPE html>
<!--
[%provenance%]
-->
<html lang="en">
  <meta charset="utf-8">
  {%- if subtests|length > 10 %}
  <meta name="timeout" content="long">
  {%- endif %}
  <title>HTTP headers on request using the "fetch" API and passing through a Serive Worker</title>
  <script src="/resources/testharness.js"></script>
  <script src="/resources/testharnessreport.js"></script>
  <script src="/service-workers/service-worker/resources/test-helpers.sub.js"></script>
  <script src="/fetch/metadata/resources/helper.sub.js"></script>
  <body>
  <script>
  'use strict';

  const scripts = {
    fallback: '/fetch/metadata/resources/fetch-via-serviceworker--fallback--sw.js',
    respondWith: '/fetch/metadata/resources/fetch-via-serviceworker--respondWith--sw.js'
  };

  function induceRequest(t, url, init, script) {
    const SCOPE = '/fetch/metadata/resources/fetch-via-serviceworker-frame.html';
    const SCRIPT = scripts[script];

    return service_worker_unregister_and_register(t, SCRIPT, SCOPE)
      .then((registration) => {
        t.add_cleanup(() => registration.unregister());

        return wait_for_state(t, registration.installing, 'activated');
      })
      .then(() => with_iframe(SCOPE))
      .then((frame) => {
        t.add_cleanup(() => frame.remove());

        return frame.contentWindow.fetch(url, init);
      });
  }

  {%- for subtest in subtests %}

  promise_test((t) => {
    const key = '{{uuid()}}';

    return induceRequest(
        t,
        makeRequestURL(key, [% subtest.origins %]),
        [%subtest.init | default({}) | tojson%],
        'respondWith'
      )
      .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.init | collection("init")%] - respondWith');

  promise_test((t) => {
    const key = '{{uuid()}}';

    return induceRequest(
        t,
        makeRequestURL(key, [% subtest.origins %]),
        [%subtest.init | default({}) | tojson%],
        'fallback'
      )
      .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.init | collection("init")%] - fallback');

  {%- endfor %}

  </script>
  </body>
</html>