OLD | NEW |
(Empty) | |
| 1 if (this.document === undefined) { |
| 2 importScripts("/resources/testharness.js"); |
| 3 importScripts("/common/utils.js"); |
| 4 importScripts("/common/get-host-info.sub.js"); |
| 5 importScripts("../resources/utils.js"); |
| 6 } |
| 7 |
| 8 function corsRedirect(desc, redirectUrl, redirectLocation, redirectStatus, expec
tSuccess) { |
| 9 var urlBaseParameters = "&redirect_status=" + redirectStatus; |
| 10 var urlParametersSuccess = urlBaseParameters + "&allow_headers=x-w3c&location=
" + encodeURIComponent(redirectLocation + "?allow_headers=x-w3c"); |
| 11 var urlParametersFailure = urlBaseParameters + "&location=" + encodeURICompone
nt(redirectLocation); |
| 12 |
| 13 var requestInit = {"mode": "cors", "redirect": "follow", "headers" : [["x-w3c"
, "test"]]}; |
| 14 |
| 15 promise_test(function(test) { |
| 16 var uuid_token = token(); |
| 17 return fetch(RESOURCES_DIR + "clean-stash.py?token=" + uuid_token).then(func
tion(resp) { |
| 18 return fetch(redirectUrl + "?token=" + uuid_token + "&max_age=0" + urlPara
metersSuccess, requestInit).then(function(resp) { |
| 19 assert_equals(resp.status, 200, "Response's status is 200"); |
| 20 assert_equals(resp.headers.get("x-did-preflight"), "1", "Preflight reque
st has been made"); |
| 21 }); |
| 22 }); |
| 23 }, desc + " (preflight after redirection success case)"); |
| 24 promise_test(function(test) { |
| 25 var uuid_token = token(); |
| 26 return fetch(RESOURCES_DIR + "clean-stash.py?token=" + uuid_token).then(func
tion(resp) { |
| 27 return promise_rejects(test, new TypeError(), fetch(redirectUrl + "?token=
" + uuid_token + "&max_age=0" + urlParametersFailure, requestInit)); |
| 28 }); |
| 29 }, desc + " (preflight after redirection failure case)"); |
| 30 } |
| 31 |
| 32 var redirPath = dirname(location.pathname) + RESOURCES_DIR + "redirect.py"; |
| 33 var preflightPath = dirname(location.pathname) + RESOURCES_DIR + "preflight.py"; |
| 34 |
| 35 var host_info = get_host_info(); |
| 36 |
| 37 var localRedirect = host_info.HTTP_ORIGIN + redirPath; |
| 38 var remoteRedirect = host_info.HTTP_REMOTE_ORIGIN + redirPath; |
| 39 |
| 40 var localLocation = host_info.HTTP_ORIGIN + preflightPath; |
| 41 var remoteLocation = host_info.HTTP_REMOTE_ORIGIN + preflightPath; |
| 42 var remoteLocation2 = host_info.HTTP_ORIGIN_WITH_DIFFERENT_PORT + preflightPath; |
| 43 |
| 44 for (var code of [301, 302, 303, 307, 308]) { |
| 45 corsRedirect("Redirect " + code + ": same origin to cors", localRedirect, remo
teLocation, code); |
| 46 corsRedirect("Redirect " + code + ": cors to same origin", remoteRedirect, loc
alLocation, code); |
| 47 corsRedirect("Redirect " + code + ": cors to another cors", remoteRedirect, re
moteLocation2, code); |
| 48 } |
| 49 |
| 50 done(); |
OLD | NEW |