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.getResponseHeader()");
9 window
.jsTestIsAsync
= true;
11 var savedHeader
= null;
12 var headerName
= "Content-Type";
13 var nullTests
= [ "SeT-COoKie",
15 "xxx-mytest-headerabc",
19 var xhr
= new XMLHttpRequest();
22 function testGetResponseHeader(xhr
, headerName
, expectNull
) {
23 shouldNotThrow("{state: " + xhr
.readyState
+ "}; headerValue = xhr.getResponseHeader('" + headerName
+ "');");
25 shouldBeNull("headerValue");
27 shouldBeNonNull("headerValue");
33 xhr
.onreadystatechange = function() {
34 var rState
= this.readyState
;
35 result
= testGetResponseHeader(this, headerName
, rState
<= XMLHttpRequest
.OPENED
);
38 shouldBe("result", "savedHeader");
42 for (var i
= 0; i
< nullTests
.length
; ++i
)
43 testGetResponseHeader(this, nullTests
[i
], true);
45 if (rState
> XMLHttpRequest
.OPENED
)
46 testFailed("In ready state " + rState
+ ", unexpected null value for '" + headerName
+ "'.");
47 else if (result
!== null)
48 testFailed("In ready state " + rState
+ ", expected null for '" + headerName
+ ", got: " + JSON
.stringify(result
) + ".");
50 testPassed("Header '" + headerName
+ "' is null in ready state " + rState
+ ".");
53 if (rState
== XMLHttpRequest
.DONE
)
58 // Test for readyState = 0
59 testGetResponseHeader(xhr
, headerName
, true);
60 shouldNotThrow('xhr.open("GET", "resources/1251.html", true);');
61 // Test for readyState = 1
62 testGetResponseHeader(xhr
, headerName
, true);
63 shouldNotThrow("xhr.send(null);");