Index: LayoutTests/http/tests/xmlhttprequest/getResponseHeader.html |
diff --git a/LayoutTests/http/tests/xmlhttprequest/getResponseHeader.html b/LayoutTests/http/tests/xmlhttprequest/getResponseHeader.html |
index 01b70a76dce25ba68ce091952333d2ad34ad6625..e1f312746e4317e96d7b79f260cda2f29f008814 100644 |
--- a/LayoutTests/http/tests/xmlhttprequest/getResponseHeader.html |
+++ b/LayoutTests/http/tests/xmlhttprequest/getResponseHeader.html |
@@ -1,140 +1,67 @@ |
+<!doctype html> |
<html> |
<head> |
- <title>Check exception thrown by getReponseHeader </title> |
+<title>Testing XMLHttpRequest.getReponseHeader behavior</title> |
+<script src="../resources/js-test-pre.js"></script> |
<script type="text/javascript"> |
+description("Test the required behavior of XMLHttpRequest.getResponseHeader()"); |
+ |
+window.jsTestIsAsync = true; |
var savedHeader = null; |
-var headerName="Content-Type"; |
-var nullTests = new Array("SeT-COoKie", "sEt-coOkIE2", |
- "xxx-mytest-headerabc", null, "Content-Type:"); |
+var headerName = "Content-Type"; |
+var nullTests = [ "SeT-COoKie", |
+ "sEt-coOkIE2", |
+ "xxx-mytest-headerabc", |
+ null, |
+ "Content-Type:" ]; |
-function log (msg) { |
- var paragraph = document.createElement("li"); |
- paragraph.innerHTML=msg.replace(/\n/gm,"<br>"); |
- document.getElementById("console").appendChild(paragraph); |
-} |
+var xhr = new XMLHttpRequest(); |
-function log4(status, rState, subState, msg) { |
- log(status + " " + rState + " " + subState + ": " + msg); |
-} |
+var headerValue; |
+function testGetResponseHeader(xhr, headerName, expectNull) { |
+ shouldNotThrow("{state: " + xhr.readyState + "}; headerValue = xhr.getResponseHeader('" + headerName + "');"); |
+ if (expectNull) |
+ shouldBeNull("headerValue"); |
+ else |
+ shouldBeNonNull("headerValue"); |
-function log3(status, rState, msg) { |
- log4(status, rState, headerName, msg); |
-} |
- |
-if (window.XMLHttpRequest) { |
- xhr = new XMLHttpRequest(); |
-} else { |
- try { |
- xhr = new ActiveXObject("Msxml2.XMLHTTP"); |
- } catch (ex) { |
- xhr = new ActiveXObject("Microsoft.XMLHTTP"); |
- } |
+ return headerValue; |
} |
+var result; |
xhr.onreadystatechange = function() { |
var rState = this.readyState; |
- // We expect an INVALID_STATE_ERR exception for readyState < 2 |
- // and no exception for readyState >= 2 |
- try { |
- var header = this.getResponseHeader(headerName); |
- if (rState != this.readyState) |
- log3("UNCERTAIN", rState, "readyState changed while getting the header."); |
- if (rState < 2) { |
- log3("FAILED", rState, headerName + "=" + header); |
- } else if (header) { |
- if (savedHeader) |
- if (savedHeader != header) { |
- log3("FAILED", rState,headerName + " changed after it was first returned. Previous " + headerName |
- + "=" + savedHeader + "; New " + headerName + "=" + header + "."); |
- savedHeader = header; |
- } |
- else //savedHeader == header here; no need to reprint header |
- log3("PASSED", rState, headerName); |
- else {//first header value retrieved |
- if (window.testRunner) |
-//do not print the header's value for automated tests to avoid false failures. |
- log3("PASSED", rState, "ResponseHeader(" + headerName + ") returned a value."); |
- else |
- log3("PASSED", rState, "getResponseHeader(" + headerName + ") returned: " + header + "."); |
- savedHeader = header; |
- } |
- for (var i=0;i<nullTests.length;++i) { |
- try { |
- var str = this.getResponseHeader(nullTests[i]); |
- if (str == null) |
- log4("PASSED", rState, nullTests[i], "getResponseHeader(" + nullTests[i] + |
- ") returned null."); |
- else |
- log4("FAILED", rState, nullTests[i], "getResponseHeader(" + nullTests[i] + |
- ") returned \"" + str + "\""); |
- } catch(e) { |
- log4("FAILED", rState, nullTests[i], "getResponseHeader(" + nullTests[i] + ") threw exception:" + e); |
- } |
- } |
- } |
- else //header is null |
- log3("FAILED", rState, "null " + headerName + " returned."); |
- } catch (e) { |
- if (rState < 2) |
- log3("PASSED", rState, "exception thrown"); |
+ result = testGetResponseHeader(this, headerName, rState <= XMLHttpRequest.OPENED); |
+ if (result) { |
+ if (savedHeader) |
+ shouldBe("result", "savedHeader"); |
+ |
+ savedHeader = result; |
+ |
+ for (var i = 0; i < nullTests.length; ++i) |
+ testGetResponseHeader(this, nullTests[i], true); |
+ } else { |
+ if (rState > XMLHttpRequest.OPENED) |
+ testFailed("In ready state " + rState + ", unexpected null value for '" + headerName + "'."); |
else |
- log3("FAILED", rState, "exception thrown: " + e.message + "."); |
+ testPassed("Header '" + headerName + "' is null in ready state " + rState + "."); |
} |
- if ((rState == 4) && (window.testRunner)) |
- testRunner.notifyDone(); |
-} |
-if (window.testRunner) { |
- testRunner.waitUntilDone(); |
- testRunner.dumpAsText(); |
+ if (rState == XMLHttpRequest.DONE) |
+ finishJSTest(); |
} |
-function test() { |
+function runTest() { |
// Test for readyState = 0 |
- try { |
- var header = xhr.getResponseHeader(headerName); |
- log3("FAILED", xhr.readyState, headerName + "=" + header + "."); |
- } catch (e) { |
- log3("PASSED", xhr.readyState, "exception thrown."); |
- } |
- try { |
- xhr.open("GET","resources/1251.html", true); |
- xhr.send(null); |
- } catch(e) { |
- log3("FAILED", "open/send", "exception thrown: " + e.message +"."); |
- if (window.testRunner) |
- testRunner.notifyDone(); |
- } |
+ testGetResponseHeader(xhr, headerName, true); |
+ shouldNotThrow('xhr.open("GET", "resources/1251.html", true);'); |
+ // Test for readyState = 1 |
+ testGetResponseHeader(xhr, headerName, true); |
+ shouldNotThrow("xhr.send(null);"); |
} |
+runTest(); |
</script> |
+<script src="../resources/js-test-post.js"></script> |
</head> |
-<body onload="test()"> |
- |
-<p>Test page for <a href="http://bugs.webkit.org/show_bug.cgi?id=15356">bug |
-15356</a> |
-and <a href="http://bugs.webkit.org/show_bug.cgi?id=29121">bug 29121</a></p> |
-<p>Assertion: Invoking the getResponseHeader method when readyState >= 2 |
-(HEADERS_RECEIVED) returns a header value if the header exists.</p> |
-<p>Assertion: Invoking the getResponseHeader method with the parameter |
- satisfying the following conditions causes getResponseHeader |
- to return null: |
-<li>1a. The parameter case-insensitively matches Set-Cookie;</li> |
-<li>1b. The parameter case-insensitively matches Set-Cookie2;</li> |
-<li>2. The parameter does not match any header in the response;</li> |
-<li>3a. The parameter is null (it is not a valid header name);</li> |
-<li>3b. The parameter is "Content-Type:" (it is not a valid header name).</li> |
- |
-<script> |
- if (!window.testRunner) |
- document.write("<p>If the test passes one should see \ |
-below the ruler the text \"passed\" in all capital letters, once for every ready state < 2, \ |
-followed each time by a space and the readyState number and 6 times for every ready state >= 2.</p>\n\ |
-<p>ReadyState numbers should be in ascending order 0 to 4.</p>\n\ |
-<p>ReadyState numbers should be followed by a blank, the name of the header tested, colon a space and a message.</p>\ |
-<p>The value of the " + headerName + " header should be printed for ready state 2.</p>"); |
-</script> |
- <hr> |
- <p><ol id=console></ol></p> |
-</body> |
</html> |