blob: 10800c38ca071f13b03c5b9aa923bdc38695be9a [file] [log] [blame]
Hallvord R. M. Steen6bb53052012-11-09 10:47:491<!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. Steen37893362013-05-08 11:14:337 <link rel="help" href="http://dvcs.w3.org/hg/xhr/raw-file/tip/Overview.html#the-status-attribute" data-tested-assertations="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[3]" />
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. Steen6bb53052012-11-09 10:47:4911 </head>
12 <body>
13 <div id="log"></div>
14 <script>
Hallvord R. M. Steenbbb96102013-05-06 21:32:0015 var counter=0;
Hallvord R. M. Steen6bb53052012-11-09 10:47:4916 function statusRequest(method, code, text, content, type) {
Hallvord R. M. Steenbbb96102013-05-06 21:32:0017 counter++;
18 var test = async_test(document.title +' '+ counter+" (" + method + " " + code + ")")
Hallvord R. M. Steen6bb53052012-11-09 10:47:4919 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 }
36 }
37 }, this)
38 }
Hallvord R. M. Steenbbb96102013-05-06 21:32:0039 client.open(method, "resources/status.php?code=" + encodeURIComponent(code) + "&text=" + text + "&content=" + encodeURIComponent(content) + "&type=" + encodeURIComponent(type))
Hallvord R. M. Steen6bb53052012-11-09 10:47:4940 client.send(null)
41 })
42 }
43 function status(code, text, content, type) {
44 statusRequest("GET", code, text, content, type)
45 statusRequest("HEAD", code, text, content, type)
46 statusRequest("CHICKEN", code, text, content, type)
47 }
48 status(204, "UNICORNSWIN", "", "")
49 status(401, "OH HELLO", "Not today.", "")
50 status(402, "FIVE BUCKS", "<x>402<\/x>", "text/xml")
51 status(402, "FREE", "Nice!", "text/doesnotmatter")
52 status(402, "402 TEH AWESOME", "", "")
53 status(502, "YO", "", "")
54 status(502, "lowercase", "SWEET POTATO", "text/plain")
55 status(503, "HOUSTON WE HAVE A", "503", "text/plain")
56 status(699, "WAY OUTTA RANGE", "699", "text/plain")
57 </script>
58 </body>
59</html>