|
| 1 | +// META: global=window,worker |
| 2 | +// META: script=/common/get-host-info.sub.js |
| 3 | + |
| 4 | +const BASE = location.href; |
| 5 | +const IS_HTTPS = new URL(BASE).protocol === 'https:'; |
| 6 | +const REMOTE_HOST = get_host_info()['REMOTE_HOST']; |
| 7 | +const REMOTE_PORT = |
| 8 | + IS_HTTPS ? get_host_info()['HTTPS_PORT'] : get_host_info()['HTTP_PORT']; |
| 9 | + |
| 10 | +const REMOTE_ORIGIN = |
| 11 | + new URL(`//${REMOTE_HOST}:${REMOTE_PORT}`, BASE).origin; |
| 12 | +const DESTINATION = new URL('../resources/cors-top.txt', BASE); |
| 13 | + |
| 14 | +function CreateURL(url, BASE, params) { |
| 15 | + const u = new URL(url, BASE); |
| 16 | + for (const {name, value} of params) { |
| 17 | + u.searchParams.append(name, value); |
| 18 | + } |
| 19 | + return u; |
| 20 | +} |
| 21 | + |
| 22 | +const redirect = |
| 23 | + CreateURL('/fetch/api/resources/redirect.py', REMOTE_ORIGIN, |
| 24 | + [{name: 'redirect_status', value: 303}, |
| 25 | + {name: 'location', value: DESTINATION.href}]); |
| 26 | + |
| 27 | +promise_test(async (test) => { |
| 28 | + const res = await fetch(redirect.href, {mode: 'no-cors'}); |
| 29 | + // This is discussed at https://github.com/whatwg/fetch/issues/737. |
| 30 | + assert_equals(res.type, 'opaque'); |
| 31 | +}, 'original => remote => original with mode: "no-cors"'); |
| 32 | + |
| 33 | +promise_test(async (test) => { |
| 34 | + const res = await fetch(redirect.href, {mode: 'cors'}); |
| 35 | + assert_equals(res.type, 'cors'); |
| 36 | +}, 'original => remote => original with mode: "cors"'); |
| 37 | + |
| 38 | +done(); |
0 commit comments