OLD | NEW |
(Empty) | |
| 1 if (this.document === undefined) { |
| 2 importScripts("/resources/testharness.js"); |
| 3 importScripts("/common/utils.js"); |
| 4 importScripts("../resources/utils.js"); |
| 5 importScripts("/common/get-host-info.sub.js"); |
| 6 } |
| 7 |
| 8 function corsRedirect(desc, redirectUrl, redirectLocation, redirectStatus, expec
tedOrigin) { |
| 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 var requestInit = {"mode": "cors", "redirect": "follow"}; |
| 16 |
| 17 return promise_test(function(test) { |
| 18 return fetch(RESOURCES_DIR + "clean-stash.py?token=" + uuid_token).then(func
tion(resp) { |
| 19 return fetch(url + urlParameters, requestInit).then(function(resp) { |
| 20 assert_equals(resp.status, 200, "Response's status is 200"); |
| 21 assert_equals(resp.headers.get("x-did-preflight"), "0", "No preflight re
quest has been made"); |
| 22 assert_equals(resp.headers.get("x-origin"), expectedOrigin, "Origin is c
orrectly set after redirect"); |
| 23 }); |
| 24 }); |
| 25 }, desc); |
| 26 } |
| 27 |
| 28 var redirPath = dirname(location.pathname) + RESOURCES_DIR + "redirect.py"; |
| 29 var preflightPath = dirname(location.pathname) + RESOURCES_DIR + "preflight.py"; |
| 30 |
| 31 var host_info = get_host_info(); |
| 32 |
| 33 var localRedirect = host_info.HTTP_ORIGIN + redirPath; |
| 34 var remoteRedirect = host_info.HTTP_REMOTE_ORIGIN + redirPath; |
| 35 |
| 36 var localLocation = host_info.HTTP_ORIGIN + preflightPath; |
| 37 var remoteLocation = host_info.HTTP_REMOTE_ORIGIN + preflightPath; |
| 38 var remoteLocation2 = host_info.HTTP_ORIGIN_WITH_DIFFERENT_PORT + preflightPath; |
| 39 |
| 40 for (var code of [301, 302, 303, 307, 308]) { |
| 41 corsRedirect("Redirect " + code + ": cors to same cors", remoteRedirect, remot
eLocation, code, location.origin); |
| 42 corsRedirect("Redirect " + code + ": cors to another cors", remoteRedirect, re
moteLocation2, code, "null"); |
| 43 corsRedirect("Redirect " + code + ": same origin to cors", localRedirect, remo
teLocation, code, location.origin); |
| 44 corsRedirect("Redirect " + code + ": cors to same origin", remoteRedirect, loc
alLocation, code, "null"); |
| 45 } |
| 46 |
| 47 done(); |
OLD | NEW |