summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/fetch/metadata/tools/templates/window-location.sub.html
blob: 96f3912361633f9ccabd2189fb2d513be00f4406 (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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<!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 for navigation via the HTML Location API</title>
  <script src="/resources/testharness.js"></script>
  <script src="/resources/testharnessreport.js"></script>
  {%- if subtests|selectattr('userActivated')|list %}
  <script src="/resources/testdriver.js"></script>
  <script src="/resources/testdriver-vendor.js"></script>
  {%- endif %}
  <script src="/fetch/metadata/resources/helper.sub.js"></script>
  <body>
  <script>
  'use strict';

  function induceRequest(url, navigate, userActivated) {
    const win = window.open();

    return new Promise((resolve) => {
        addEventListener('message', function(event) {
          if (event.source === win) {
            resolve();
          }
        });

        if (userActivated) {
          test_driver.bless('enable user activation', () => {
            navigate(win, url);
          });
        } else {
          navigate(win, url);
        }
      })
      .then(() => win.close());
  }

  const responseParams = {
    mime: 'text/html',
    body: `<script>opener.postMessage('done', '*')</${''}script>`
  };
  {%- for subtest in subtests %}

  promise_test(() => {
    const key = '{{uuid()}}';
    const url = makeRequestURL(key, [% subtest.origins %], responseParams);

    const navigate = (win, path) => {
      win.location = path;
    };
    return induceRequest(url, navigate, [% 'true' if subtest.userActivated else 'false' %])
      .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", " - ")%]location[% " with user activation" if subtest.userActivated%]');

  promise_test(() => {
    const key = '{{uuid()}}';
    const url = makeRequestURL(key, [% subtest.origins %], responseParams);

    const navigate = (win, path) => {
      win.location.href = path;
    };
    return induceRequest(url, navigate, [% 'true' if subtest.userActivated else 'false' %])
      .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", " - ")%]location.href[% " with user activation" if subtest.userActivated%]');

  promise_test(() => {
    const key = '{{uuid()}}';
    const url = makeRequestURL(key, [% subtest.origins %], responseParams);

    const navigate = (win, path) => {
      win.location.assign(path);
    };
    return induceRequest(url, navigate, [% 'true' if subtest.userActivated else 'false' %])
      .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", " - ")%]location.assign[% " with user activation" if subtest.userActivated%]');

  promise_test(() => {
    const key = '{{uuid()}}';
    const url = makeRequestURL(key, [% subtest.origins %], responseParams);

    const navigate = (win, path) => {
      win.location.replace(path);
    };
    return induceRequest(url, navigate, [% 'true' if subtest.userActivated else 'false' %])
      .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", " - ")%]location.replace[% " with user activation" if subtest.userActivated%]');

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