tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

fetch-via-serviceworker.https.sub.html (2898B)


      1 <!DOCTYPE html>
      2 <!--
      3 [%provenance%]
      4 -->
      5 <html lang="en">
      6  <meta charset="utf-8">
      7  {%- if subtests|length > 10 %}
      8  <meta name="timeout" content="long">
      9  {%- endif %}
     10  <title>HTTP headers on request using the "fetch" API and passing through a Serive Worker</title>
     11  <script src="/resources/testharness.js"></script>
     12  <script src="/resources/testharnessreport.js"></script>
     13  <script src="/service-workers/service-worker/resources/test-helpers.sub.js"></script>
     14  <script src="/fetch/metadata/resources/helper.sub.js"></script>
     15  <body>
     16  <script>
     17  'use strict';
     18 
     19  const scripts = {
     20    fallback: '/fetch/metadata/resources/fetch-via-serviceworker--fallback--sw.js',
     21    respondWith: '/fetch/metadata/resources/fetch-via-serviceworker--respondWith--sw.js'
     22  };
     23 
     24  function induceRequest(t, url, init, script) {
     25    const SCOPE = '/fetch/metadata/resources/fetch-via-serviceworker-frame.html';
     26    const SCRIPT = scripts[script];
     27 
     28    return service_worker_unregister_and_register(t, SCRIPT, SCOPE)
     29      .then((registration) => {
     30        t.add_cleanup(() => registration.unregister());
     31 
     32        return wait_for_state(t, registration.installing, 'activated');
     33      })
     34      .then(() => with_iframe(SCOPE))
     35      .then((frame) => {
     36        t.add_cleanup(() => frame.remove());
     37 
     38        return frame.contentWindow.fetch(url, init);
     39      });
     40  }
     41 
     42  {%- for subtest in subtests %}
     43 
     44  promise_test((t) => {
     45    const key = '{{uuid()}}';
     46 
     47    return induceRequest(
     48        t,
     49        makeRequestURL(key, [% subtest.origins %]),
     50        [%subtest.init | default({}) | tojson%],
     51        'respondWith'
     52      )
     53      .then(() => retrieve(key))
     54      .then((headers) => {
     55        {%- if subtest.expected == none %}
     56          assert_not_own_property(headers, '[%subtest.headerName%]');
     57        {%- else %}
     58          assert_own_property(headers, '[%subtest.headerName%]');
     59          assert_array_equals(headers['[%subtest.headerName%]'], ['[%subtest.expected%]']);
     60        {%- endif %}
     61        });
     62  }, '[%subtest.headerName%] - [%subtest.description | pad("end", ", ")%][%subtest.init | collection("init")%] - respondWith');
     63 
     64  promise_test((t) => {
     65    const key = '{{uuid()}}';
     66 
     67    return induceRequest(
     68        t,
     69        makeRequestURL(key, [% subtest.origins %]),
     70        [%subtest.init | default({}) | tojson%],
     71        'fallback'
     72      )
     73      .then(() => retrieve(key))
     74      .then((headers) => {
     75        {%- if subtest.expected == none %}
     76          assert_not_own_property(headers, '[%subtest.headerName%]');
     77        {%- else %}
     78          assert_own_property(headers, '[%subtest.headerName%]');
     79          assert_array_equals(headers['[%subtest.headerName%]'], ['[%subtest.expected%]']);
     80        {%- endif %}
     81        });
     82  }, '[%subtest.headerName%] - [%subtest.description | pad("end", ", ")%][%subtest.init | collection("init")%] - fallback');
     83 
     84  {%- endfor %}
     85 
     86  </script>
     87  </body>
     88 </html>