OLD | NEW |
(Empty) | |
| 1 if (this.document === undefined) { |
| 2 importScripts("/resources/testharness.js"); |
| 3 importScripts("../resources/utils.js"); |
| 4 } |
| 5 |
| 6 function redirectLocation(desc, redirectUrl, redirectLocation, redirectStatus, r
edirectMode, shouldPass) { |
| 7 var url = redirectUrl; |
| 8 var urlParameters = "?redirect_status=" + redirectStatus; |
| 9 if (redirectLocation) |
| 10 urlParameters += "&location=" + encodeURIComponent(redirectLocation); |
| 11 |
| 12 var requestInit = {"redirect": redirectMode}; |
| 13 |
| 14 promise_test(function(test) { |
| 15 if (redirectMode === "error" || !shouldPass) |
| 16 return promise_rejects(test, new TypeError(), fetch(url + urlParameters, r
equestInit)); |
| 17 if (redirectLocation && redirectMode === "manual") |
| 18 return fetch(url + urlParameters, requestInit).then(function(resp) { |
| 19 assert_equals(resp.status, 0, "Response's status is 0"); |
| 20 assert_equals(resp.type, "opaqueredirect", "Response's type is opaquered
irect"); |
| 21 assert_equals(resp.statusText, "", "Response's statusText is \"\""); |
| 22 assert_true(resp.headers.entries().next().done, "Headers should be empty
"); |
| 23 }); |
| 24 |
| 25 if (redirectMode === "manual" || redirectMode === "follow") |
| 26 return fetch(url + urlParameters, requestInit).then(function(resp) { |
| 27 assert_equals(resp.status, redirectStatus, "Response's status is " + red
irectStatus); |
| 28 }); |
| 29 assert_unreached(redirectMode + " is not a valid redirect mode"); |
| 30 }, desc); |
| 31 } |
| 32 |
| 33 var redirUrl = RESOURCES_DIR + "redirect.py"; |
| 34 var locationUrl = "top.txt"; |
| 35 var invalidLocationUrl = "#invalidurl:"; |
| 36 var dataLocationUrl = "data:,data%20url"; |
| 37 // FIXME: We may want to mix redirect-mode and cors-mode. |
| 38 // FIXME: Add tests for "error" redirect-mode. |
| 39 for (var statusCode of [301, 302, 303, 307, 308]) { |
| 40 redirectLocation("Redirect " + statusCode + " in \"follow\" mode without locat
ion", redirUrl, undefined, statusCode, "follow", true); |
| 41 redirectLocation("Redirect " + statusCode + " in \"manual\" mode without locat
ion", redirUrl, undefined, statusCode, "manual", true); |
| 42 |
| 43 redirectLocation("Redirect " + statusCode + " in \"follow\" mode with invalid
location", redirUrl, invalidLocationUrl, statusCode, "follow", false); |
| 44 redirectLocation("Redirect " + statusCode + " in \"manual\" mode with invalid
location", redirUrl, invalidLocationUrl, statusCode, "manual", true); |
| 45 |
| 46 redirectLocation("Redirect " + statusCode + " in \"follow\" mode with data loc
ation", redirUrl, dataLocationUrl, statusCode, "follow", false); |
| 47 redirectLocation("Redirect " + statusCode + " in \"manual\" mode with data loc
ation", redirUrl, dataLocationUrl, statusCode, "manual", true); |
| 48 } |
| 49 |
| 50 done(); |
OLD | NEW |