OLD | NEW |
(Empty) | |
| 1 if (this.document === undefined) { |
| 2 importScripts("/resources/testharness.js"); |
| 3 importScripts("../resources/utils.js"); |
| 4 importScripts("/common/utils.js"); |
| 5 importScripts("/common/get-host-info.sub.js"); |
| 6 } |
| 7 |
| 8 function corsPreflightRedirect(desc, redirectUrl, redirectLocation, redirectStat
us, redirectPreflight) { |
| 9 var uuid_token = token(); |
| 10 var url = redirectUrl; |
| 11 var urlParameters = "?token=" + uuid_token + "&max_age=0"; |
| 12 urlParameters += "&redirect_status=" + redirectStatus; |
| 13 urlParameters += "&location=" + encodeURIComponent(redirectLocation); |
| 14 |
| 15 if (redirectPreflight) |
| 16 urlParameters += "&redirect_preflight"; |
| 17 var requestInit = {"mode": "cors", "redirect": "follow"}; |
| 18 |
| 19 /* Force preflight */ |
| 20 requestInit["headers"] = {"x-force-preflight": ""}; |
| 21 urlParameters += "&allow_headers=x-force-preflight"; |
| 22 |
| 23 promise_test(function(test) { |
| 24 fetch(RESOURCES_DIR + "clean-stash.py?token=" + uuid_token).then(function(re
sp) { |
| 25 assert_equals(resp.status, 200, "Clean stash response's status is 200"); |
| 26 return promise_rejects(test, new TypeError(), fetch(url + urlParameters, r
equestInit)); |
| 27 }); |
| 28 }, desc); |
| 29 } |
| 30 |
| 31 var redirectUrl = get_host_info().HTTP_REMOTE_ORIGIN + dirname(location.pathname
) + RESOURCES_DIR + "redirect.py"; |
| 32 var locationUrl = get_host_info().HTTP_REMOTE_ORIGIN + dirname(location.pathnam
e) + RESOURCES_DIR + "preflight.py"; |
| 33 |
| 34 for (var code of [301, 302, 303, 307, 308]) { |
| 35 /* preflight should not follow the redirection */ |
| 36 corsPreflightRedirect("Redirection " + code + " on preflight failed", redirect
Url, locationUrl, code, true); |
| 37 /* preflight is done before redirection: preflight force redirect to error */ |
| 38 corsPreflightRedirect("Redirection " + code + " after preflight failed", redir
ectUrl, locationUrl, code, false); |
| 39 } |
| 40 |
| 41 done(); |
OLD | NEW |