OLD | NEW |
(Empty) | |
| 1 if (this.document === undefined) { |
| 2 importScripts("/resources/testharness.js"); |
| 3 importScripts("../resources/utils.js"); |
| 4 } |
| 5 |
| 6 function redirectMethod(desc, redirectUrl, redirectLocation, redirectStatus, met
hod, expectedMethod) { |
| 7 var url = redirectUrl; |
| 8 var urlParameters = "?redirect_status=" + redirectStatus; |
| 9 urlParameters += "&location=" + encodeURIComponent(redirectLocation); |
| 10 |
| 11 var requestInit = {"method": method, "redirect": "follow"}; |
| 12 if (method != "GET" && method != "HEAD") |
| 13 requestInit.body = "this is my body"; |
| 14 |
| 15 promise_test(function(test) { |
| 16 return fetch(url + urlParameters, requestInit).then(function(resp) { |
| 17 assert_equals(resp.status, 200, "Response's status is 200"); |
| 18 assert_equals(resp.type, "basic", "Response's type basic"); |
| 19 assert_equals(resp.headers.get("x-request-method"), expectedMethod, "Reque
st method after redirection is " + expectedMethod); |
| 20 assert_true(resp.redirected); |
| 21 return resp.text().then(function(text) { |
| 22 assert_equals(text, expectedMethod == "POST" ? requestInit.body : ""); |
| 23 }); |
| 24 }); |
| 25 }, desc); |
| 26 } |
| 27 |
| 28 promise_test(function(test) { |
| 29 assert_false(new Response().redirected); |
| 30 return fetch(RESOURCES_DIR + "method.py").then(function(resp) { |
| 31 assert_equals(resp.status, 200, "Response's status is 200"); |
| 32 assert_false(resp.redirected); |
| 33 }); |
| 34 }, "Response.redirected should be false on not-redirected responses"); |
| 35 |
| 36 var redirUrl = RESOURCES_DIR + "redirect.py"; |
| 37 var locationUrl = "method.py"; |
| 38 |
| 39 redirectMethod("Redirect 301 with GET", redirUrl, locationUrl, 301, "GET", "GET"
); |
| 40 redirectMethod("Redirect 301 with POST", redirUrl, locationUrl, 301, "POST", "GE
T"); |
| 41 redirectMethod("Redirect 301 with HEAD", redirUrl, locationUrl, 301, "HEAD", "HE
AD"); |
| 42 |
| 43 redirectMethod("Redirect 302 with GET", redirUrl, locationUrl, 302, "GET", "GET"
); |
| 44 redirectMethod("Redirect 302 with POST", redirUrl, locationUrl, 302, "POST", "GE
T"); |
| 45 redirectMethod("Redirect 302 with HEAD", redirUrl, locationUrl, 302, "HEAD", "HE
AD"); |
| 46 |
| 47 redirectMethod("Redirect 303 with GET", redirUrl, locationUrl, 303, "GET", "GET"
); |
| 48 redirectMethod("Redirect 303 with POST", redirUrl, locationUrl, 303, "POST", "GE
T"); |
| 49 redirectMethod("Redirect 303 with HEAD", redirUrl, locationUrl, 303, "HEAD", "HE
AD"); |
| 50 |
| 51 redirectMethod("Redirect 307 with GET", redirUrl, locationUrl, 307, "GET", "GET"
); |
| 52 redirectMethod("Redirect 307 with POST", redirUrl, locationUrl, 307, "POST", "PO
ST"); |
| 53 redirectMethod("Redirect 307 with HEAD", redirUrl, locationUrl, 307, "HEAD", "HE
AD"); |
| 54 |
| 55 done(); |
OLD | NEW |