| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <script src="../resources/testharness.js"></script> | 2 <script src="../resources/testharness.js"></script> |
| 3 <script src="../resources/testharnessreport.js"></script> | 3 <script src="../resources/testharnessreport.js"></script> |
| 4 <script src="../resources/get-host-info.js"></script> | 4 <script src="../resources/get-host-info.js"></script> |
| 5 <script src="resources/test-helpers.js"></script> | 5 <script src="resources/test-helpers.js"></script> |
| 6 <script src="resources/foreign-fetch-helpers.js"></script> |
| 6 <body> | 7 <body> |
| 7 <script> | 8 <script> |
| 8 var host_info = get_host_info(); | 9 var host_info = get_host_info(); |
| 9 | 10 |
| 10 function worker_for_origins(origins) { | 11 function worker_for_origins(origins) { |
| 11 var worker = 'foreign-fetch-worker.js?'; | 12 var worker = 'foreign-fetch-worker.js?'; |
| 12 var params = {origins: origins, relscopes: ['/intercept']}; | 13 var params = {origins: origins, relscopes: ['/intercept']}; |
| 13 return worker + encodeURIComponent(JSON.stringify(params)); | 14 return worker + encodeURIComponent(JSON.stringify(params)); |
| 14 } | 15 } |
| 15 | 16 |
| 16 function worker_for_scopes(relative_scopes) { | 17 function worker_for_scopes(relative_scopes) { |
| 17 var worker = 'foreign-fetch-worker.js?'; | 18 var worker = 'foreign-fetch-worker.js?'; |
| 18 var params = {relscopes: relative_scopes}; | 19 var params = {relscopes: relative_scopes}; |
| 19 return worker + encodeURIComponent(JSON.stringify(params)); | 20 return worker + encodeURIComponent(JSON.stringify(params)); |
| 20 } | 21 } |
| 21 | 22 |
| 22 function install_cross_origin_worker(t, worker, scope) { | |
| 23 return with_iframe(host_info.HTTPS_REMOTE_ORIGIN + | |
| 24 '/serviceworker/resources/install-worker-helper.html') | |
| 25 .then(frame => new Promise((resolve, reject) => { | |
| 26 var channel = new MessageChannel(); | |
| 27 frame.contentWindow.postMessage({worker: worker, | |
| 28 options: {scope: scope}, | |
| 29 port: channel.port1}, | |
| 30 '*', [channel.port1]); | |
| 31 channel.port2.onmessage = reply => { | |
| 32 if (reply.data == 'success') resolve(); | |
| 33 else reject(reply.data); | |
| 34 }; | |
| 35 })); | |
| 36 } | |
| 37 | |
| 38 function intercepted_url(scope) { | 23 function intercepted_url(scope) { |
| 39 return host_info.HTTPS_REMOTE_ORIGIN + '/serviceworker/resources/' + | 24 return host_info.HTTPS_REMOTE_ORIGIN + '/serviceworker/resources/' + |
| 40 scope + '/intercept/foo?basic'; | 25 scope + '/intercept/foo?basic'; |
| 41 } | 26 } |
| 42 | 27 |
| 43 function non_intercepted_url(scope) { | 28 function non_intercepted_url(scope) { |
| 44 return host_info.HTTPS_REMOTE_ORIGIN + '/serviceworker/resources/' + | 29 return host_info.HTTPS_REMOTE_ORIGIN + '/serviceworker/resources/' + |
| 45 scope + '/foo?basic'; | 30 scope + '/foo?basic'; |
| 46 } | 31 } |
| 47 | 32 |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 return wait_for_state(t, r.installing, 'activated'); | 124 return wait_for_state(t, r.installing, 'activated'); |
| 140 }) | 125 }) |
| 141 .then(() => with_iframe(scope)) | 126 .then(() => with_iframe(scope)) |
| 142 .then(frame => frame.contentWindow.fetch(remote_url)) | 127 .then(frame => frame.contentWindow.fetch(remote_url)) |
| 143 .then(response => response.text()) | 128 .then(response => response.text()) |
| 144 .then(response_text => { | 129 .then(response_text => { |
| 145 assert_equals(response_text, 'Foreign Fetch'); | 130 assert_equals(response_text, 'Foreign Fetch'); |
| 146 }); | 131 }); |
| 147 }, 'Foreign fetch can intercept requests from SW controlled pages.'); | 132 }, 'Foreign fetch can intercept requests from SW controlled pages.'); |
| 148 | 133 |
| 134 promise_test(t => { |
| 135 var scope = 'simple.txt?meta'; |
| 136 var remote_url = |
| 137 host_info.HTTPS_REMOTE_ORIGIN + '/serviceworker/resources/' + scope; |
| 138 return install_cross_origin_worker(t, worker_for_scopes(['']), scope) |
| 139 .then(() => fetch(remote_url, {mode: 'no-cors'})) |
| 140 .then(response => response.json()) |
| 141 .then(response_data => { |
| 142 assert_equals(self.location.href, response_data.referrer); |
| 143 assert_equals(self.location.origin, response_data.origin); |
| 144 }) |
| 145 .then(() => with_iframe('resources/blank.html')) |
| 146 .then(frame => { |
| 147 var meta = frame.contentDocument.createElement('meta'); |
| 148 meta.setAttribute('name', 'referrer'); |
| 149 meta.setAttribute('content', 'no-referrer'); |
| 150 frame.contentDocument.head.appendChild(meta); |
| 151 return frame.contentWindow.fetch(remote_url, {mode: 'no-cors'}); |
| 152 }) |
| 153 .then(response => response.json()) |
| 154 .then(response_data => { |
| 155 assert_equals('', response_data.referrer); |
| 156 assert_equals('null', response_data.origin); |
| 157 }); |
| 158 }, 'Referrer and origin are set correctly in ForeignFetchEvent.'); |
| 159 |
| 149 </script> | 160 </script> |
| 150 </body> | 161 </body> |
| OLD | NEW |