fetch.sub.window.js (1967B)
1 // META: script=/common/get-host-info.sub.js 2 // 3 // The following tests assume the policy `Connection-Allowlist: (response-origin)` has been set. 4 5 const port = get_host_info().HTTP_PORT_ELIDED; 6 const SUCCESS = true; 7 const FAILURE = false; 8 9 function fetch_test(origin, expectation) { 10 if (expectation === FAILURE) { 11 return promise_test(async t => { 12 const fetcher = fetch(`${origin}/common/blank-with-cors.html`, { mode: "cors", credential: "omit" }); 13 return promise_rejects_js(t, TypeError, fetcher); 14 }, `Fetch to ${origin} fails.`); 15 } 16 17 promise_test(async t => { 18 const r = await fetch(`${origin}/common/blank-with-cors.html`, { mode: "cors", credential: "omit" }); 19 assert_equals(r.status, 200); 20 }, `Fetch to ${origin} succeeds.`); 21 } 22 23 const test_cases = [ 24 // We're loading this page from `http://hosts[][]`, so that origin should 25 // succeed, while its subdomains should fail: 26 { origin: "http://{{hosts[][]}}" + port, expectation: SUCCESS }, 27 { origin: "http://{{hosts[][www]}}" + port, expectation: FAILURE }, 28 { origin: "http://{{hosts[][www1]}}" + port, expectation: FAILURE }, 29 { origin: "http://{{hosts[][www2]}}" + port, expectation: FAILURE }, 30 { origin: "http://{{hosts[][天気の良い日]}}" + port, expectation: FAILURE }, 31 { origin: "http://{{hosts[][élève]}}" + port, expectation: FAILURE }, 32 33 // Cross-site origins should fail as well: 34 { origin: "http://{{hosts[alt][]}}" + port, expectation: FAILURE }, 35 { origin: "http://{{hosts[alt][www]}}" + port, expectation: FAILURE }, 36 { origin: "http://{{hosts[alt][www1]}}" + port, expectation: FAILURE }, 37 { origin: "http://{{hosts[alt][www2]}}" + port, expectation: FAILURE }, 38 { origin: "http://{{hosts[alt][天気の良い日]}}" + port, expectation: FAILURE }, 39 { origin: "http://{{hosts[alt][élève]}}" + port, expectation: FAILURE }, 40 ]; 41 42 for (let i = 0; i < test_cases.length; i++) { 43 fetch_test(test_cases[i].origin, test_cases[i].expectation); 44 }