Chromium Code Reviews| Index: LayoutTests/http/tests/xmlhttprequest/getAllResponseHeaders.html |
| diff --git a/LayoutTests/http/tests/xmlhttprequest/getAllResponseHeaders.html b/LayoutTests/http/tests/xmlhttprequest/getAllResponseHeaders.html |
| index f371f0a4918185528d777fa2d94b6d81b4e09047..1eff2dfd5707c6a6d8f019b1f5864d8c7448266d 100644 |
| --- a/LayoutTests/http/tests/xmlhttprequest/getAllResponseHeaders.html |
| +++ b/LayoutTests/http/tests/xmlhttprequest/getAllResponseHeaders.html |
| @@ -1,118 +1,67 @@ |
| +<!doctype html> |
| <html> |
| <head> |
| - <title>Check exception thrown by getAllResponseHeaders and some |
| - characteristics of the return value</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.getAllResponseHeaders()"); |
| -function log (msg) { |
| - var paragraph = document.createElement("li"); |
| - paragraph.innerHTML=msg.replace(/\n/gm,"<br>"); |
| - document.getElementById("console").appendChild(paragraph); |
| -} |
| +window.jsTestIsAsync = true; |
| -var xhr; |
| +var xhr = new XMLHttpRequest(); |
| -if (window.XMLHttpRequest) { |
| - xhr = new XMLHttpRequest(); |
| -} else { |
| - try { |
| - xhr = new ActiveXObject("Msxml2.XMLHTTP"); |
| - } catch (ex) { |
| - xhr = new ActiveXObject("Microsoft.XMLHTTP"); |
| - } |
| +var savedHeaders = null; |
| + |
| +var headerValues; |
| +function testGetAllResponseHeaders(xhr, expectEmpty) { |
| + shouldNotThrow("{state: " + xhr.readyState + "}; headerValues = xhr.getAllResponseHeaders();"); |
| + if (expectEmpty && headerValues !== "") |
| + testFailed("Expected the empty string, got: '" + headerValues + "'"); |
| + else |
| + testPassed("headerValues is " + (!expectEmpty ? "not " : "") + "the empty string"); |
| + return headerValues; |
| } |
| -var savedHeader = null; |
| 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.getAllResponseHeaders(); |
| - if (rState != this.readyState) |
| - log("UNCERTAIN " + rState + ": readyState changed while getting headers."); |
| - if (rState < 2) { |
| - log("FAILED " + rState + ": headerlist=" + header); |
| - } else if (header) |
| - if (savedHeader) |
| - if (savedHeader != header) { |
| - log("FAILED " + rState + |
| -": headerlist changed after it was first returned. Previous header list:\n" |
| -+ savedHeader + "\n New headerlist:\n" + header); |
| - savedHeader = header; |
| - } |
| - else //savedHeader == header here; no need to reprint header |
| - log("PASSED " + rState); |
| - else {//first header list retrieved |
| - if (/^Set-Cookie:|^Set-Cookie2:/im.test(header)) |
| - log("FAILED " + rState + |
| -": /^Set-Cookie:|^Set-Cookie2:/ matches. getAllResponseHeaders returned:\n" + header); |
| - else if (window.testRunner) |
| -//do not print list for automated tests to avoid false failures. |
| - log("PASSED " + rState + |
| -": getAllResponseHeaders returned what looks like a conforming headerlist."); |
| + var result = testGetAllResponseHeaders(this, rState <= XMLHttpRequest.OPENED); |
| + if (result) { |
| + if (savedHeaders) { |
| + if (result !== savedHeaders) |
| + testFailed("Expected '" + savedHeaders + "', got: '" + result + "'"); |
| + else |
| + testPassed("header values are unchanged."); |
| + } else { |
| + if (/^Set-Cookie:|^Set-Cookie2:/im.test(result)) { |
| + testFailed("Did not expect to find a Set-Cookie{2} header, got: '" + result + "'"); |
| + } |
| + else { |
|
tyoshino (SeeGerritForStatus)
2013/10/26 19:05:13
join l37 and l38 please
|
| + // Do not print list for automated tests to avoid false failures. |
| + if (self.testRunner) |
| + testPassed("Header values appears to be conforming."); |
| else |
| - log("PASSED " + rState + |
| -": getAllResponseHeaders returned:\n" + header); |
| - savedHeader = header; |
| + testPassed("Header values appears ok: " + JSON.stringify(headerValues)); |
| } |
| - else //header is null |
| - log("FAILED " + rState + ": null header list returned"); |
| - } catch (e) { |
| - if (rState < 2) { |
| - log("PASSED " + rState); |
| - } else { |
| - log("FAILED " + rState + ": EXCEPTION THROWN: " + e.message + "."); |
| } |
| + savedHeaders = result; |
| + } else { |
| + shouldBeGreaterThanOrEqual("XMLHttpRequest.OPENED", "xhr.readyState"); |
|
tyoshino (SeeGerritForStatus)
2013/10/26 19:05:13
seems it's recommended to pass actual value as the
sof
2013/10/26 20:02:26
Yes, but there's no *LessThanOrEqual predicate :)
tyoshino (SeeGerritForStatus)
2013/10/26 20:22:46
Oh... I see.
|
| } |
| - if ((rState == 4) && (window.testRunner)) |
| - testRunner.notifyDone(); |
| + |
| + if (rState == 4) |
| + finishJSTest(); |
| } |
| -function test() { |
| - if (window.testRunner) { |
| - testRunner.waitUntilDone(); |
| - testRunner.dumpAsText(); |
| - } |
| +function runTest() { |
| // Test for readyState = 0 |
| - try { |
| - var header = xhr.getAllResponseHeaders(); |
| - log("FAILED " + xhr.readyState + ": header=" + header); |
| - } catch (e) { |
| - log("PASSED " + xhr.readyState); |
| - } |
| - try { |
| - xhr.open("GET","resources/1251.html", true); |
| - xhr.send(null); |
| - } catch(e) { |
| - log("FAILED open/send: EXCEPTION THROWN: " + e.message +"."); |
| - if (window.testRunner) |
| - testRunner.notifyDone(); |
| - } |
| + testGetAllResponseHeaders(xhr, true); |
| + shouldNotThrow('xhr.open("GET","resources/1251.html", true);'); |
|
tyoshino (SeeGerritForStatus)
2013/10/26 19:05:13
space. i.e.
"GET", "
|
| + // Test for readyState = 1 |
| + testGetAllResponseHeaders(xhr, true); |
| + shouldNotThrow("xhr.send(null);"); |
| } |
| +runTest(); |
| </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 getAllResponseHeaders method when readyState >= 2 |
| -(HEADERS_RECEIVED) should return a conforming list of headers.</p> |
| -<script> |
| - if (!window.testRunner) |
| - document.write("<p>If the test passes one should see \ |
| -below the ruler the text \"passed\" in all capital letters, 5 times, \ |
| -followed each time by a space and the readyState number.</p>\n\ |
| -<p>ReadyStatenumbers should be in ascending order 0 to 4.</p>\n\ |
| -<p>A conforming list of response headers should also be printed.</p>\n\ |
| -<p>A conforming list of headers:</p> \ |
| - <li> contains one header per line.</li> \ |
| - <li> has header names and header values separated by a COLON and \ |
| -a SPACE.</li>\ |
| - <li> does not contain any headers that match (case-insensitively) \ |
| -Set-Cookie or Set-Cookie2</li>"); |
| - </script> |
| - <hr> |
| - <p><ol id=console></ol></p> |
| -</body> |
| +<script src="../resources/js-test-post.js"></script> |
| </html> |