4 <title>Testing XMLHttpRequest.getReponseHeader behavior
</title>
5 <script src=
"/js-test-resources/js-test.js"></script>
6 <script type=
"text/javascript">
7 description("Test the required behavior of XMLHttpRequest.getAllResponseHeaders()");
9 window
.jsTestIsAsync
= true;
11 var xhr
= new XMLHttpRequest();
13 var savedHeaders
= null;
16 function testGetAllResponseHeaders(xhr
, expectEmpty
) {
17 shouldNotThrow("{state: " + xhr
.readyState
+ "}; headerValues = xhr.getAllResponseHeaders();");
18 if (expectEmpty
&& headerValues
!== "")
19 testFailed("Expected the empty string, got: '" + headerValues
+ "'");
21 testPassed("headerValues is " + (!expectEmpty
? "not " : "") + "the empty string");
26 xhr
.onreadystatechange = function() {
27 var rState
= this.readyState
;
28 responseHeaders
= testGetAllResponseHeaders(this, rState
<= XMLHttpRequest
.OPENED
);
29 if (responseHeaders
) {
31 shouldBe("responseHeaders", "savedHeaders");
33 if (/^Set-Cookie:|^Set-Cookie2:/im.test(responseHeaders
)) {
34 testFailed("Did not expect to find a Set-Cookie{2} header, got: '" + responseHeaders
+ "'");
36 // Do not print list for automated tests to avoid false failures.
38 testPassed("Header values appears to be conforming.");
40 testPassed("Header values appears ok: " + JSON
.stringify(headerValues
));
43 savedHeaders
= responseHeaders
;
45 if (rState
> XMLHttpRequest
.OPENED
)
46 testFailed("In ready state " + rState
+ ", unexpected empty value.");
47 else if (responseHeaders
!== "")
48 testFailed("In ready state " + rState
+ ", expected the empty string, got: " + JSON
.stringify(responseHeaders
) + ".");
50 testPassed("getAllResponseHeaders() result is empty in ready state " + rState
+ ".");
53 if (rState
== XMLHttpRequest
.DONE
)
58 // Test for readyState = 0
59 testGetAllResponseHeaders(xhr
, true);
60 shouldNotThrow('xhr.open("GET", "resources/1251.html", true);');
61 // Test for readyState = 1
62 testGetAllResponseHeaders(xhr
, true);
63 shouldNotThrow("xhr.send(null);");