Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Warnings
- This test has a WPT meta file that expects 6 subtest issues.
- This WPT test may be referenced by the following Test IDs:
- /connection-allowlist/tentative/fetch-wildcard.sub.window.html - WPT Dashboard Interop Dashboard
// META: script=/common/get-host-info.sub.js
//
// The following tests assume the policy `Connection-Allowlist: (response-origin "*://*.hosts[alt]:*")` has been set.
const port = get_host_info().HTTP_PORT_ELIDED;
const SUCCESS = true;
const FAILURE = false;
function fetch_test(origin, expectation) {
if (expectation === FAILURE) {
return promise_test(async t => {
const fetcher = fetch(`${origin}/common/blank-with-cors.html`, { mode: "cors", credential: "omit" });
return promise_rejects_js(t, TypeError, fetcher);
}, `Fetch to ${origin} fails.`);
}
promise_test(async t => {
const r = await fetch(`${origin}/common/blank-with-cors.html`, { mode: "cors", credential: "omit" });
assert_equals(r.status, 200);
}, `Fetch to ${origin} succeeds.`);
}
const test_cases = [
// succeed, while its subdomains should fail.
// The pattern we've specified in the header ("*://*.hosts[alt]:*/") will
// match any subdomain of `hosts[alt]` (though not, as it turns out,
// `hosts[alt]` itself.
];
for (let i = 0; i < test_cases.length; i++) {
fetch_test(test_cases[i].origin, test_cases[i].expectation);
}