blob: dcf7d62467adcb9a90b60a2ed18f3bb6654354a9 [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>
Ms2ger91fef142014-11-01 09:24:377 <link rel="help" href="https://xhr.spec.whatwg.org/#the-status-attribute" data-tested-assertations="following::ol/li[1] following::ol/li[3]" />
8 <link rel="help" href="https://xhr.spec.whatwg.org/#the-statustext-attribute" data-tested-assertations="following::ol/li[1] following::ol/li[3]" />
9 <link rel="help" href="https://xhr.spec.whatwg.org/#the-getresponseheader()-method" data-tested-assertations="following::ol/li[5]" />
10 <link rel="help" href="https://xhr.spec.whatwg.org/#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 Reiar M. Steen4e96dac2013-07-03 12:42:1015 var counter=0
Hallvord R. M. Steen6bb53052012-11-09 10:47:4916 function statusRequest(method, code, text, content, type) {
Hallvord Reiar M. Steen4e96dac2013-07-03 12:42:1017 counter++
Hallvord R. M. Steenbbb96102013-05-06 21:32:0018 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 }
Hallvord Reiar M. Steen4048a182013-05-08 13:39:0736 }else{
37 assert_equals(client.status, 0)
38 assert_equals(client.statusText, "")
Hallvord R. M. Steen6bb53052012-11-09 10:47:4939 }
40 }, this)
41 }
James Graham234a6722013-09-17 17:54:3842 client.open(method, "resources/status.py?code=" + encodeURIComponent(code) + "&text=" + text + "&content=" + encodeURIComponent(content) + "&type=" + encodeURIComponent(type))
Hallvord R. M. Steen6bb53052012-11-09 10:47:4943 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>