Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / http / tests / xmlhttprequest / zero-length-response.html
blob39ae0077b4b01d66def5e3e7a9aad81525db2ec1
1 <html>
2 <head>
3 <title>Test XMLHttpRequest zero-length response handling (async)</title>
4 <meta http-equiv="content-type" content="text/html;charset=utf-8">
5 <body>
6 <p>Test for <a href="https://bugs.webkit.org/show_bug.cgi?id=5924">bug 5924</a>
7 - zero-length responses to XMLHTTPRequest mishandled.</p>
8 <script>
10 if (window.testRunner) {
11 testRunner.dumpAsText();
12 testRunner.waitUntilDone();
15 var console_messages = document.createElement("ul");
16 document.body.appendChild(console_messages);
18 function log(message)
20 var item = document.createElement("li");
21 item.appendChild(document.createTextNode(message));
22 console_messages.appendChild(item);
25 function get(url, async)
27 if (window.XMLHttpRequest) {
28 req = new XMLHttpRequest();
29 } else {
30 try {
31 req = new ActiveXObject("Msxml2.XMLHTTP");
32 } catch (ex) {
33 req = new ActiveXObject("Microsoft.XMLHTTP");
37 log("after creation: " + stateName(req.readyState));
39 dumpResponse();
41 if (async)
42 req.onreadystatechange = processStateChange;
44 log("after setting onreadystatechange: " + stateName(req.readyState));
46 req.open('GET', url, async);
47 log("after open(): " + stateName(req.readyState));
48 dumpResponse();
50 try {
51 req.overrideMimeType('text/xml');
52 log("after overrideMimeType(): " + stateName(req.readyState));
53 } catch (ex) {
54 log("overrideMimeType(): " + ex);
57 req.send(null);
58 log("after send(): " + stateName(req.readyState));
60 if (!async && req.status != 200)
61 throw ("HTTP request failed, status: " + req.status);
63 return req;
66 function stateName(val) {
67 if (req.readyState == 0)
68 return "Uninitialized";
69 else if (req.readyState == 1)
70 return "Open";
71 else if (req.readyState == 2)
72 return "Sent";
73 else if (req.readyState == 3)
74 return "Receiving";
75 else if (req.readyState == 4)
76 return "Loaded";
77 else
78 return "???";
81 function prettyPrintText(text) {
82 if (text == null)
83 return text;
84 return '"' + text + '"';
87 function dumpResponse() {
89 try { log ("  Status: " + req.status); } catch (ex) { log("  Exception getting status: " + ex.message); }
90 try { log ("  StatusText: " + prettyPrintText(req.statusText)); } catch (ex) { log("  Exception getting StatusText: " + ex.message); }
91 try { log ("  ResponseText: " + prettyPrintText(req.responseText)); } catch (ex) { log("  Exception getting ResponseText: " + ex.message); }
92 try { log ("  ResponseXML: " + req.responseXML); } catch (ex) { log("  Exception getting ResponseXML: " + ex.message); }
93 try { log ("  ResponseXML serialized: " + (req.responseXML ? prettyPrintText(window.XMLSerializer ? (new XMLSerializer()).serializeToString(req.responseXML) : req.responseXML.xml) : "n/a")); } catch (ex) { log("  Exception serializing ResponseXML: " + ex.message); }
96 function processStateChange() {
97 log("onreadystatechange: " + stateName(req.readyState));
98 dumpResponse();
99 if (req.readyState == 4) {
100 if (window.testRunner)
101 testRunner.notifyDone();
105 // start async steps
106 get('resources/zero-length.xml', true);
108 </script>
109 </body>
110 </html>