3 <title>Test XMLHttpRequest zero-length response handling (async)
</title>
4 <meta http-equiv=
"content-type" content=
"text/html;charset=utf-8">
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>
10 if (window
.testRunner
) {
11 testRunner
.dumpAsText();
12 testRunner
.waitUntilDone();
15 var console_messages
= document
.createElement("ul");
16 document
.body
.appendChild(console_messages
);
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();
31 req
= new ActiveXObject("Msxml2.XMLHTTP");
33 req
= new ActiveXObject("Microsoft.XMLHTTP");
37 log("after creation: " + stateName(req
.readyState
));
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
));
51 req
.overrideMimeType('text/xml');
52 log("after overrideMimeType(): " + stateName(req
.readyState
));
54 log("overrideMimeType(): " + ex
);
58 log("after send(): " + stateName(req
.readyState
));
60 if (!async
&& req
.status
!= 200)
61 throw ("HTTP request failed, status: " + req
.status
);
66 function stateName(val
) {
67 if (req
.readyState
== 0)
68 return "Uninitialized";
69 else if (req
.readyState
== 1)
71 else if (req
.readyState
== 2)
73 else if (req
.readyState
== 3)
75 else if (req
.readyState
== 4)
81 function prettyPrintText(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
));
99 if (req
.readyState
== 4) {
100 if (window
.testRunner
)
101 testRunner
.notifyDone();
106 get('resources/zero-length.xml', true);