|
| 1 | +<!DOCTYPE html> |
| 2 | +<!-- |
| 3 | +This test was procedurally generated. Please do not modify it directly. |
| 4 | +Sources: |
| 5 | +- fetch/metadata/tools/fetch-metadata.conf.yml |
| 6 | +- fetch/metadata/tools/templates/serviceworker.https.sub.html |
| 7 | +--> |
| 8 | +<!DOCTYPE html> |
| 9 | +<html lang="en"> |
| 10 | + <meta charset="utf-8"> |
| 11 | + <title>HTTP headers on request for Service Workers</title> |
| 12 | + <script src="/resources/testharness.js"></script> |
| 13 | + <script src="/resources/testharnessreport.js"></script> |
| 14 | + <script src="/fetch/metadata/resources/helper.sub.js"></script> |
| 15 | + <body> |
| 16 | + <script> |
| 17 | + 'use strict'; |
| 18 | + |
| 19 | + function induceRequest(t, url, options, event, clear) { |
| 20 | + // Register a service worker and check the request header. |
| 21 | + return navigator.serviceWorker.register(url, options) |
| 22 | + .then((registration) => { |
| 23 | + t.add_cleanup(() => registration.unregister()); |
| 24 | + if (event === 'register') { |
| 25 | + return; |
| 26 | + } |
| 27 | + return clear().then(() => registration.update()); |
| 28 | + }); |
| 29 | + } |
| 30 | + |
| 31 | + promise_test((t) => { |
| 32 | + const key = '{{uuid()}}'; |
| 33 | + const url = makeRequestURL( |
| 34 | + key, ['httpsOrigin'], { mime: 'application/javascript' } |
| 35 | + ); |
| 36 | + |
| 37 | + return induceRequest(t, url, {}, 'register') |
| 38 | + .then(() => retrieve(key)) |
| 39 | + .then((headers) => { |
| 40 | + assert_own_property(headers, 'sec-fetch-site'); |
| 41 | + assert_equals(headers['sec-fetch-site'], 'same-origin'); |
| 42 | + }); |
| 43 | + }, 'sec-fetch-site - Same origin, no options - registration'); |
| 44 | + |
| 45 | + promise_test((t) => { |
| 46 | + const key = '{{uuid()}}'; |
| 47 | + const url = makeRequestURL( |
| 48 | + key, ['httpsOrigin'], { mime: 'application/javascript' } |
| 49 | + ); |
| 50 | + |
| 51 | + return induceRequest(t, url, {}, 'update', () => retrieve(key)) |
| 52 | + .then(() => retrieve(key)) |
| 53 | + .then((headers) => { |
| 54 | + assert_own_property(headers, 'sec-fetch-site'); |
| 55 | + assert_equals(headers['sec-fetch-site'], 'same-origin'); |
| 56 | + }); |
| 57 | + }, 'sec-fetch-site - Same origin, no options - updating'); |
| 58 | + |
| 59 | + promise_test((t) => { |
| 60 | + const key = '{{uuid()}}'; |
| 61 | + const url = makeRequestURL( |
| 62 | + key, [], { mime: 'application/javascript' } |
| 63 | + ); |
| 64 | + |
| 65 | + return induceRequest(t, url, {"type": "classic"}, 'register') |
| 66 | + .then(() => retrieve(key)) |
| 67 | + .then((headers) => { |
| 68 | + assert_own_property(headers, 'sec-fetch-mode'); |
| 69 | + assert_equals(headers['sec-fetch-mode'], 'same-origin'); |
| 70 | + }); |
| 71 | + }, 'sec-fetch-mode - options: type=classic - registration'); |
| 72 | + |
| 73 | + promise_test((t) => { |
| 74 | + const key = '{{uuid()}}'; |
| 75 | + const url = makeRequestURL( |
| 76 | + key, [], { mime: 'application/javascript' } |
| 77 | + ); |
| 78 | + |
| 79 | + return induceRequest(t, url, {"type": "classic"}, 'update', () => retrieve(key)) |
| 80 | + .then(() => retrieve(key)) |
| 81 | + .then((headers) => { |
| 82 | + assert_own_property(headers, 'sec-fetch-mode'); |
| 83 | + assert_equals(headers['sec-fetch-mode'], 'same-origin'); |
| 84 | + }); |
| 85 | + }, 'sec-fetch-mode - options: type=classic - updating'); |
| 86 | + |
| 87 | + promise_test((t) => { |
| 88 | + const key = '{{uuid()}}'; |
| 89 | + const url = makeRequestURL( |
| 90 | + key, [], { mime: 'application/javascript' } |
| 91 | + ); |
| 92 | + |
| 93 | + return induceRequest(t, url, {}, 'register') |
| 94 | + .then(() => retrieve(key)) |
| 95 | + .then((headers) => { |
| 96 | + assert_own_property(headers, 'sec-fetch-mode'); |
| 97 | + assert_equals(headers['sec-fetch-mode'], 'same-origin'); |
| 98 | + }); |
| 99 | + }, 'sec-fetch-mode - no options - registration'); |
| 100 | + |
| 101 | + promise_test((t) => { |
| 102 | + const key = '{{uuid()}}'; |
| 103 | + const url = makeRequestURL( |
| 104 | + key, [], { mime: 'application/javascript' } |
| 105 | + ); |
| 106 | + |
| 107 | + return induceRequest(t, url, {}, 'update', () => retrieve(key)) |
| 108 | + .then(() => retrieve(key)) |
| 109 | + .then((headers) => { |
| 110 | + assert_own_property(headers, 'sec-fetch-mode'); |
| 111 | + assert_equals(headers['sec-fetch-mode'], 'same-origin'); |
| 112 | + }); |
| 113 | + }, 'sec-fetch-mode - no options - updating'); |
| 114 | + |
| 115 | + promise_test((t) => { |
| 116 | + const key = '{{uuid()}}'; |
| 117 | + const url = makeRequestURL( |
| 118 | + key, [], { mime: 'application/javascript' } |
| 119 | + ); |
| 120 | + |
| 121 | + return induceRequest(t, url, {}, 'register') |
| 122 | + .then(() => retrieve(key)) |
| 123 | + .then((headers) => { |
| 124 | + assert_own_property(headers, 'sec-fetch-dest'); |
| 125 | + assert_equals(headers['sec-fetch-dest'], 'serviceworker'); |
| 126 | + }); |
| 127 | + }, 'sec-fetch-dest - no options - registration'); |
| 128 | + |
| 129 | + promise_test((t) => { |
| 130 | + const key = '{{uuid()}}'; |
| 131 | + const url = makeRequestURL( |
| 132 | + key, [], { mime: 'application/javascript' } |
| 133 | + ); |
| 134 | + |
| 135 | + return induceRequest(t, url, {}, 'update', () => retrieve(key)) |
| 136 | + .then(() => retrieve(key)) |
| 137 | + .then((headers) => { |
| 138 | + assert_own_property(headers, 'sec-fetch-dest'); |
| 139 | + assert_equals(headers['sec-fetch-dest'], 'serviceworker'); |
| 140 | + }); |
| 141 | + }, 'sec-fetch-dest - no options - updating'); |
| 142 | + |
| 143 | + promise_test((t) => { |
| 144 | + const key = '{{uuid()}}'; |
| 145 | + const url = makeRequestURL( |
| 146 | + key, [], { mime: 'application/javascript' } |
| 147 | + ); |
| 148 | + |
| 149 | + return induceRequest(t, url, {}, 'register') |
| 150 | + .then(() => retrieve(key)) |
| 151 | + .then((headers) => { |
| 152 | + assert_not_own_property(headers, 'sec-fetch-user'); |
| 153 | + }); |
| 154 | + }, 'sec-fetch-user - no options - registration'); |
| 155 | + |
| 156 | + promise_test((t) => { |
| 157 | + const key = '{{uuid()}}'; |
| 158 | + const url = makeRequestURL( |
| 159 | + key, [], { mime: 'application/javascript' } |
| 160 | + ); |
| 161 | + |
| 162 | + return induceRequest(t, url, {}, 'update', () => retrieve(key)) |
| 163 | + .then(() => retrieve(key)) |
| 164 | + .then((headers) => { |
| 165 | + assert_not_own_property(headers, 'sec-fetch-user'); |
| 166 | + }); |
| 167 | + }, 'sec-fetch-user - no options - updating'); |
| 168 | + </script> |
| 169 | +</body> |
| 170 | +</html> |
0 commit comments