|
| 1 | +<!DOCTYPE html> |
| 2 | +<html> |
| 3 | +<head> |
| 4 | + <script src="/resources/testharness.js"></script> |
| 5 | + <script src="/resources/testharnessreport.js"></script> |
| 6 | + <script src="/common/get-host-info.sub.js"></script> |
| 7 | +</head> |
| 8 | +<body> |
| 9 | + <script> |
| 10 | +const host = get_host_info(); |
| 11 | +const localBaseURL = host.HTTP_ORIGIN + window.location.pathname.replace(/\/[^\/]*$/, '/') ; |
| 12 | +const sameSiteBaseURL = "http://" + host.ORIGINAL_HOST + ":" + host.HTTP_PORT2 + window.location.pathname.replace(/\/[^\/]*$/, '/') ; |
| 13 | +const notSameSiteBaseURL = host.HTTP_NOTSAMESITE_ORIGIN + window.location.pathname.replace(/\/[^\/]*$/, '/') ; |
| 14 | +const httpsBaseURL = host.HTTPS_ORIGIN + window.location.pathname.replace(/\/[^\/]*$/, '/') ; |
| 15 | + |
| 16 | +promise_test(async () => { |
| 17 | + const response = await fetch("./resources/hello.py?corp=same-origin"); |
| 18 | + assert_equals(await response.text(), "hello"); |
| 19 | +}, "Same-origin fetch with a 'Cross-Origin-Resource-Policy: same-origin' response header."); |
| 20 | + |
| 21 | +promise_test(async () => { |
| 22 | + const response = await fetch("./resources/hello.py?corp=same-site"); |
| 23 | + assert_equals(await response.text(), "hello"); |
| 24 | +}, "Same-origin fetch with a 'Cross-Origin-Resource-Policy: same-site' response header."); |
| 25 | + |
| 26 | +promise_test(async (test) => { |
| 27 | + const response = await fetch(notSameSiteBaseURL + "resources/hello.py?corp=same-origin"); |
| 28 | + assert_equals(await response.text(), "hello"); |
| 29 | +}, "Cross-origin cors fetch with a 'Cross-Origin-Resource-Policy: same-origin' response header."); |
| 30 | + |
| 31 | +promise_test(async (test) => { |
| 32 | + const response = await fetch(notSameSiteBaseURL + "resources/hello.py?corp=same-site"); |
| 33 | + assert_equals(await response.text(), "hello"); |
| 34 | +}, "Cross-origin cors fetch with a 'Cross-Origin-Resource-Policy: same-site' response header."); |
| 35 | + |
| 36 | +promise_test((test) => { |
| 37 | + const remoteURL = notSameSiteBaseURL + "resources/hello.py?corp=same-origin"; |
| 38 | + return promise_rejects(test, new TypeError, fetch(remoteURL, { mode : "no-cors" })); |
| 39 | +}, "Cross-origin no-cors fetch with a 'Cross-Origin-Resource-Policy: same-origin' response header."); |
| 40 | + |
| 41 | +promise_test((test) => { |
| 42 | + const remoteURL = notSameSiteBaseURL + "resources/hello.py?corp=same-site"; |
| 43 | + return promise_rejects(test, new TypeError, fetch(remoteURL, { mode: "no-cors" })); |
| 44 | +}, "Cross-origin no-cors fetch with a 'Cross-Origin-Resource-Policy: same-site' response header."); |
| 45 | + |
| 46 | +promise_test((test) => { |
| 47 | + const remoteURL = httpsBaseURL + "resources/hello.py?corp=same-site"; |
| 48 | + return fetch(remoteURL, { mode: "no-cors" }); |
| 49 | +}, "Cross-origin no-cors fetch to a same-site URL with a 'Cross-Origin-Resource-Policy: same-site' response header."); |
| 50 | + |
| 51 | +promise_test((test) => { |
| 52 | + const remoteURL = httpsBaseURL + "resources/hello.py?corp=same-origin"; |
| 53 | + return promise_rejects(test, new TypeError, fetch(remoteURL, { mode : "no-cors" })); |
| 54 | +}, "Cross-origin no-cors fetch to a same-site URL with a 'Cross-Origin-Resource-Policy: same-origin' response header."); |
| 55 | + |
| 56 | +promise_test(async (test) => { |
| 57 | + const remoteSameSiteURL = sameSiteBaseURL + "resources/hello.py?corp=same-site"; |
| 58 | + |
| 59 | + await fetch(remoteSameSiteURL, { mode: "no-cors" }); |
| 60 | + |
| 61 | + return promise_rejects(test, new TypeError, fetch(sameSiteBaseURL + "resources/hello.py?corp=same-origin", { mode: "no-cors" })); |
| 62 | +}, "Valid cross-origin no-cors fetch with a 'Cross-Origin-Resource-Policy: same-site' response header."); |
| 63 | + |
| 64 | +promise_test((test) => { |
| 65 | + const finalURL = notSameSiteBaseURL + "resources/hello.py?corp=same-origin"; |
| 66 | + return promise_rejects(test, new TypeError, fetch("resources/redirect.py?redirectTo=" + encodeURIComponent(finalURL), { mode: "no-cors" })); |
| 67 | +}, "Cross-origin no-cors fetch with a 'Cross-Origin-Resource-Policy: same-origin' response header after a redirection."); |
| 68 | + |
| 69 | +promise_test((test) => { |
| 70 | + const finalURL = localBaseURL + "resources/hello.py?corp=same-origin"; |
| 71 | + return fetch(notSameSiteBaseURL + "resources/redirect.py?redirectTo=" + encodeURIComponent(finalURL), { mode: "no-cors" }); |
| 72 | +}, "Cross-origin no-cors fetch with a 'Cross-Origin-Resource-Policy: same-origin' response header after a cross-origin redirection."); |
| 73 | + |
| 74 | +promise_test(async (test) => { |
| 75 | + const finalURL = localBaseURL + "resources/hello.py?corp=same-origin"; |
| 76 | + |
| 77 | + await fetch(finalURL, { mode: "no-cors" }); |
| 78 | + |
| 79 | + return promise_rejects(test, new TypeError, fetch(notSameSiteBaseURL + "resources/redirect.py?corp=same-origin&redirectTo=" + encodeURIComponent(finalURL), { mode: "no-cors" })); |
| 80 | +}, "Cross-origin no-cors fetch with a 'Cross-Origin-Resource-Policy: same-origin' redirect response header."); |
| 81 | + </script> |
| 82 | +</body> |
| 83 | +</html> |
0 commit comments