| Hallvord R. M. Steen | 6bb5305 | 2012-11-09 10:47:49 | [diff] [blame] | 1 | <!doctype html> |
| 2 | <html> |
| 3 | <head> |
| 4 | <title>XMLHttpRequest: status/statusText - various responses</title> |
| 5 | <script src="/resources/testharness.js"></script> |
| 6 | <script src="/resources/testharnessreport.js"></script> |
| Hallvord Reiar M. Steen | 4048a18 | 2013-05-08 13:39:07 | [diff] [blame^] | 7 | <link rel="help" href="http://dvcs.w3.org/hg/xhr/raw-file/tip/Overview.html#the-status-attribute" data-tested-assertations="following::ol/li[1] following::ol/li[3]" /> |
| 8 | <link rel="help" href="http://dvcs.w3.org/hg/xhr/raw-file/tip/Overview.html#the-statustext-attribute" data-tested-assertations="following::ol/li[1] following::ol/li[3]" /> |
| Hallvord Reiar M. Steen | 3789336 | 2013-05-08 11:14:33 | [diff] [blame] | 9 | <link rel="help" href="http://dvcs.w3.org/hg/xhr/raw-file/tip/Overview.html#the-getresponseheader()-method" data-tested-assertations="following::ol/li[5]" /> |
| 10 | <link rel="help" href="http://dvcs.w3.org/hg/xhr/raw-file/tip/Overview.html#the-responsetext-attribute" data-tested-assertations="following::ol/li[4]" /> |
| Hallvord R. M. Steen | 6bb5305 | 2012-11-09 10:47:49 | [diff] [blame] | 11 | </head> |
| 12 | <body> |
| 13 | <div id="log"></div> |
| 14 | <script> |
| Hallvord R. M. Steen | bbb9610 | 2013-05-06 21:32:00 | [diff] [blame] | 15 | var counter=0; |
| Hallvord R. M. Steen | 6bb5305 | 2012-11-09 10:47:49 | [diff] [blame] | 16 | function statusRequest(method, code, text, content, type) { |
| Hallvord R. M. Steen | bbb9610 | 2013-05-06 21:32:00 | [diff] [blame] | 17 | counter++; |
| 18 | var test = async_test(document.title +' '+ counter+" (" + method + " " + code + ")") |
| Hallvord R. M. Steen | 6bb5305 | 2012-11-09 10:47:49 | [diff] [blame] | 19 | test.step(function() { |
| 20 | var client = new XMLHttpRequest() |
| 21 | client.onreadystatechange = function(e) { |
| 22 | test.step(function() { |
| 23 | if(client.readyState > 1) { |
| 24 | assert_equals(client.status, code) |
| 25 | assert_equals(client.statusText, text) |
| 26 | assert_equals(client.getResponseHeader("X-Request-Method"), method) |
| 27 | if(client.readyState == 4) { |
| 28 | if(method != "HEAD") { |
| 29 | if(type == "text/xml") { |
| 30 | assert_equals(client.responseXML.documentElement.localName, "x") |
| 31 | } |
| 32 | assert_equals(client.responseText, content) |
| 33 | } |
| 34 | test.done() |
| 35 | } |
| Hallvord Reiar M. Steen | 4048a18 | 2013-05-08 13:39:07 | [diff] [blame^] | 36 | }else{ |
| 37 | assert_equals(client.status, 0) |
| 38 | assert_equals(client.statusText, "") |
| Hallvord R. M. Steen | 6bb5305 | 2012-11-09 10:47:49 | [diff] [blame] | 39 | } |
| 40 | }, this) |
| 41 | } |
| Hallvord R. M. Steen | bbb9610 | 2013-05-06 21:32:00 | [diff] [blame] | 42 | client.open(method, "resources/status.php?code=" + encodeURIComponent(code) + "&text=" + text + "&content=" + encodeURIComponent(content) + "&type=" + encodeURIComponent(type)) |
| Hallvord R. M. Steen | 6bb5305 | 2012-11-09 10:47:49 | [diff] [blame] | 43 | client.send(null) |
| 44 | }) |
| 45 | } |
| 46 | function status(code, text, content, type) { |
| 47 | statusRequest("GET", code, text, content, type) |
| 48 | statusRequest("HEAD", code, text, content, type) |
| 49 | statusRequest("CHICKEN", code, text, content, type) |
| 50 | } |
| 51 | status(204, "UNICORNSWIN", "", "") |
| 52 | status(401, "OH HELLO", "Not today.", "") |
| 53 | status(402, "FIVE BUCKS", "<x>402<\/x>", "text/xml") |
| 54 | status(402, "FREE", "Nice!", "text/doesnotmatter") |
| 55 | status(402, "402 TEH AWESOME", "", "") |
| 56 | status(502, "YO", "", "") |
| 57 | status(502, "lowercase", "SWEET POTATO", "text/plain") |
| 58 | status(503, "HOUSTON WE HAVE A", "503", "text/plain") |
| 59 | status(699, "WAY OUTTA RANGE", "699", "text/plain") |
| 60 | </script> |
| 61 | </body> |
| 62 | </html> |