OLD | NEW |
(Empty) | |
| 1 <!doctype html> |
| 2 <html> |
| 3 <head> |
| 4 <meta charset="utf-8"> |
| 5 <title>Response: redirect static method</title> |
| 6 <meta name="help" href="https://fetch.spec.whatwg.org/#response"> |
| 7 <meta name="help" href="https://fetch.spec.whatwg.org/#redirect-status"> |
| 8 <meta name="author" title="Canon Research France" href="https://www.crf.cano
n.fr"> |
| 9 <script src="/resources/testharness.js"></script> |
| 10 <script src="/resources/testharnessreport.js"></script> |
| 11 </head> |
| 12 <body> |
| 13 <script> |
| 14 var url = "http://test.url:1234/"; |
| 15 test(function() { |
| 16 redirectResponse = Response.redirect(url); |
| 17 assert_equals(redirectResponse.status, 302, "Default redirect status is
302"); |
| 18 assert_equals(redirectResponse.headers.get("Location"), url, |
| 19 "redirected response has Location header with the correct url"); |
| 20 }, "Check default redirect response"); |
| 21 |
| 22 var redirectStatus = [301, 302, 303, 307, 308]; |
| 23 redirectStatus.forEach(function(status) { |
| 24 test(function() { |
| 25 redirectResponse = Response.redirect(url, status); |
| 26 assert_equals(redirectResponse.status, status, "Redirect status is " +
status); |
| 27 }, "Check response returned by static method redirect(), status = " + st
atus); |
| 28 }); |
| 29 |
| 30 test(function() { |
| 31 var invalidUrl = "http://:This is not an url"; |
| 32 assert_throws(new TypeError(), function() { Response.redirect(invalidUrl
); }, |
| 33 "Expect TypeError exception"); |
| 34 }, "Check error returned when giving invalid url to redirect()"); |
| 35 |
| 36 var invalidRedirectStatus = [200, 309, 400, 500]; |
| 37 invalidRedirectStatus.forEach(function(invalidStatus) { |
| 38 test(function() { |
| 39 assert_throws(new RangeError() , function() { Response.redirect(url, i
nvalidStatus); }, |
| 40 "Expect RangeError exception"); |
| 41 }, "Check error returned when giving invalid status to redirect(), statu
s = " + invalidStatus); |
| 42 }); |
| 43 </script> |
| 44 </body> |
| 45 </html> |
OLD | NEW |