OLD | NEW |
(Empty) | |
| 1 if (this.document === undefined) { |
| 2 importScripts("/resources/testharness.js"); |
| 3 importScripts("../resources/utils.js"); |
| 4 importScripts("/common/get-host-info.sub.js"); |
| 5 } |
| 6 |
| 7 const url = get_host_info().HTTP_REMOTE_ORIGIN + dirname(location.pathname) + RE
SOURCES_DIR + "preflight.py", |
| 8 origin = location.origin // assuming an ASCII origin |
| 9 |
| 10 function preflightTest(succeeds, withCredentials, allowMethod, allowHeader, useM
ethod, useHeader) { |
| 11 return promise_test(t => { |
| 12 let testURL = url + "?", |
| 13 requestInit = {} |
| 14 if (withCredentials) { |
| 15 testURL += "origin=" + origin + "&" |
| 16 testURL += "credentials&" |
| 17 requestInit.credentials = "include" |
| 18 } |
| 19 if (useMethod) { |
| 20 requestInit.method = useMethod |
| 21 } |
| 22 if (useHeader) { |
| 23 requestInit.headers = [useHeader] |
| 24 } |
| 25 testURL += "allow_methods=" + allowMethod + "&" |
| 26 testURL += "allow_headers=" + allowHeader + "&" |
| 27 |
| 28 if (succeeds) { |
| 29 return fetch(testURL, requestInit).then(resp => { |
| 30 assert_equals(resp.headers.get("x-origin"), origin) |
| 31 }) |
| 32 } else { |
| 33 return promise_rejects(t, new TypeError(), fetch(testURL, requestInit)) |
| 34 } |
| 35 }, "CORS that " + (succeeds ? "succeeds" : "fails") + " with credentials: " +
withCredentials + "; method: " + useMethod + " (allowed: " + allowMethod + "); h
eader: " + useHeader + " (allowed: " + allowHeader + ")") |
| 36 } |
| 37 |
| 38 preflightTest(true, false, "get", "x-test", "GET", ["X-Test", "1"]) |
| 39 preflightTest(true, false, "*", "x-test", "SUPER", ["X-Test", "1"]) |
| 40 preflightTest(true, false, "*", "*", "OK", ["X-Test", "1"]) |
| 41 preflightTest(false, true, "*", "*", "OK", ["X-Test", "1"]) |
| 42 preflightTest(false, true, "*", "", "PUT", undefined) |
| 43 preflightTest(false, true, "put", "*", "PUT", undefined) |
| 44 preflightTest(false, true, "get", "*", "GET", ["X-Test", "1"]) |
| 45 preflightTest(false, true, "*", "*", "GET", ["X-Test", "1"]) |
| 46 |
| 47 done(); |
OLD | NEW |