Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / http / tests / xmlhttprequest / getResponseHeader.html
blob1a609b2a30f2a7fd56011ef7fb4d33ef1f1e70ed
1 <!doctype html>
2 <html>
3 <head>
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",
14 "sEt-coOkIE2",
15 "xxx-mytest-headerabc",
16 null,
17 "Content-Type:" ];
19 var xhr = new XMLHttpRequest();
21 var headerValue;
22 function testGetResponseHeader(xhr, headerName, expectNull) {
23 shouldNotThrow("{state: " + xhr.readyState + "}; headerValue = xhr.getResponseHeader('" + headerName + "');");
24 if (expectNull)
25 shouldBeNull("headerValue");
26 else
27 shouldBeNonNull("headerValue");
29 return headerValue;
32 var result;
33 xhr.onreadystatechange = function() {
34 var rState = this.readyState;
35 result = testGetResponseHeader(this, headerName, rState <= XMLHttpRequest.OPENED);
36 if (result) {
37 if (savedHeader)
38 shouldBe("result", "savedHeader");
40 savedHeader = result;
42 for (var i = 0; i < nullTests.length; ++i)
43 testGetResponseHeader(this, nullTests[i], true);
44 } else {
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) + ".");
49 else
50 testPassed("Header '" + headerName + "' is null in ready state " + rState + ".");
53 if (rState == XMLHttpRequest.DONE)
54 finishJSTest();
57 function runTest() {
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);");
65 runTest();
66 </script>
67 </head>
68 </html>