Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(245)

Side by Side Diff: LayoutTests/http/tests/xmlhttprequest/getAllResponseHeaders.html

Issue 46913002: Have XHR.getResponseHeader() return null in initial ready states. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Improve test code quality in places Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | LayoutTests/http/tests/xmlhttprequest/getAllResponseHeaders-expected.txt » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 <!doctype html>
1 <html> 2 <html>
2 <head> 3 <head>
3 <title>Check exception thrown by getAllResponseHeaders and some 4 <title>Testing XMLHttpRequest.getReponseHeader behavior</title>
4 characteristics of the return value</title> 5 <script src="../resources/js-test-pre.js"></script>
5 <script type="text/javascript"> 6 <script type="text/javascript">
7 description("Test the required behavior of XMLHttpRequest.getAllResponseHeaders( )");
6 8
7 function log (msg) { 9 window.jsTestIsAsync = true;
8 var paragraph = document.createElement("li"); 10
9 paragraph.innerHTML=msg.replace(/\n/gm,"<br>"); 11 var xhr = new XMLHttpRequest();
10 document.getElementById("console").appendChild(paragraph); 12
13 var savedHeaders = null;
14
15 var headerValues;
16 function testGetAllResponseHeaders(xhr, expectEmpty) {
17 shouldNotThrow("{state: " + xhr.readyState + "}; headerValues = xhr.getAllRe sponseHeaders();");
18 if (expectEmpty && headerValues !== "")
19 testFailed("Expected the empty string, got: '" + headerValues + "'");
20 else
21 testPassed("headerValues is " + (!expectEmpty ? "not " : "") + "the empt y string");
22 return headerValues;
11 } 23 }
12 24
13 var xhr; 25 xhr.onreadystatechange = function() {
26 var rState = this.readyState;
27 var result = testGetAllResponseHeaders(this, rState <= XMLHttpRequest.OPENED );
28 if (result) {
29 if (savedHeaders) {
30 if (result !== savedHeaders)
31 testFailed("Expected '" + savedHeaders + "', got: '" + result + "'");
32 else
33 testPassed("header values are unchanged.");
tyoshino (SeeGerritForStatus) 2013/10/26 20:22:46 do the same as getResponseHeaders.html for consist
34 } else {
35 if (/^Set-Cookie:|^Set-Cookie2:/im.test(result)) {
36 testFailed("Did not expect to find a Set-Cookie{2} header, got: '" + result + "'");
37 } else {
38 // Do not print list for automated tests to avoid false failures .
39 if (self.testRunner)
40 testPassed("Header values appears to be conforming.");
41 else
42 testPassed("Header values appears ok: " + JSON.stringify(hea derValues));
43 }
44 }
45 savedHeaders = result;
46 } else {
47 shouldBeGreaterThanOrEqual("XMLHttpRequest.OPENED", "xhr.readyState");
48 }
14 49
15 if (window.XMLHttpRequest) { 50 if (rState == XMLHttpRequest.DONE)
16 xhr = new XMLHttpRequest(); 51 finishJSTest();
17 } else {
18 try {
19 xhr = new ActiveXObject("Msxml2.XMLHTTP");
20 } catch (ex) {
21 xhr = new ActiveXObject("Microsoft.XMLHTTP");
22 }
23 } 52 }
24 53
25 var savedHeader = null; 54 function runTest() {
26 xhr.onreadystatechange = function() { 55 // Test for readyState = 0
27 var rState = this.readyState; 56 testGetAllResponseHeaders(xhr, true);
28 // We expect an INVALID_STATE_ERR exception for readyState < 2 57 shouldNotThrow('xhr.open("GET", "resources/1251.html", true);');
29 // and no exception for readyState >= 2 58 // Test for readyState = 1
30 try { 59 testGetAllResponseHeaders(xhr, true);
31 var header = this.getAllResponseHeaders(); 60 shouldNotThrow("xhr.send(null);");
32 if (rState != this.readyState)
33 log("UNCERTAIN " + rState + ": readyState changed while getting head ers.");
34 if (rState < 2) {
35 log("FAILED " + rState + ": headerlist=" + header);
36 } else if (header)
37 if (savedHeader)
38 if (savedHeader != header) {
39 log("FAILED " + rState +
40 ": headerlist changed after it was first returned. Previous header list:\n"
41 + savedHeader + "\n New headerlist:\n" + header);
42 savedHeader = header;
43 }
44 else //savedHeader == header here; no need to reprint header
45 log("PASSED " + rState);
46 else {//first header list retrieved
47 if (/^Set-Cookie:|^Set-Cookie2:/im.test(header))
48 log("FAILED " + rState +
49 ": /^Set-Cookie:|^Set-Cookie2:/ matches. getAllResponseHeaders returned:\n" + he ader);
50 else if (window.testRunner)
51 //do not print list for automated tests to avoid false failures.
52 log("PASSED " + rState +
53 ": getAllResponseHeaders returned what looks like a conforming headerlist.");
54 else
55 log("PASSED " + rState +
56 ": getAllResponseHeaders returned:\n" + header);
57 savedHeader = header;
58 }
59 else //header is null
60 log("FAILED " + rState + ": null header list returned");
61 } catch (e) {
62 if (rState < 2) {
63 log("PASSED " + rState);
64 } else {
65 log("FAILED " + rState + ": EXCEPTION THROWN: " + e.message + ".");
66 }
67 }
68 if ((rState == 4) && (window.testRunner))
69 testRunner.notifyDone();
70 } 61 }
71 62 runTest();
72 function test() {
73 if (window.testRunner) {
74 testRunner.waitUntilDone();
75 testRunner.dumpAsText();
76 }
77 // Test for readyState = 0
78 try {
79 var header = xhr.getAllResponseHeaders();
80 log("FAILED " + xhr.readyState + ": header=" + header);
81 } catch (e) {
82 log("PASSED " + xhr.readyState);
83 }
84 try {
85 xhr.open("GET","resources/1251.html", true);
86 xhr.send(null);
87 } catch(e) {
88 log("FAILED open/send: EXCEPTION THROWN: " + e.message +".");
89 if (window.testRunner)
90 testRunner.notifyDone();
91 }
92 }
93 </script> 63 </script>
94 </head> 64 </head>
95 <body onload="test()"> 65 <script src="../resources/js-test-post.js"></script>
tyoshino (SeeGerritForStatus) 2013/10/26 20:22:46 inside </head>
96
97 <p>Test page for <a href="http://bugs.webkit.org/show_bug.cgi?id=15356">bug 1535 6</a>
98 and <a href="http://bugs.webkit.org/show_bug.cgi?id=29121">bug 29121</a></p>
99 <p>Assertion: Invoking getAllResponseHeaders method when readyState >= 2
100 (HEADERS_RECEIVED) should return a conforming list of headers.</p>
101 <script>
102 if (!window.testRunner)
103 document.write("<p>If the test passes one should see \
104 below the ruler the text \"passed\" in all capital letters, 5 times, \
105 followed each time by a space and the readyState number.</p>\n\
106 <p>ReadyStatenumbers should be in ascending order 0 to 4.</p>\n\
107 <p>A conforming list of response headers should also be printed.</p>\n\
108 <p>A conforming list of headers:</p> \
109 <li> contains one header per line.</li> \
110 <li> has header names and header values separated by a COLON and \
111 a SPACE.</li>\
112 <li> does not contain any headers that match (case-insensitively) \
113 Set-Cookie or Set-Cookie2</li>");
114 </script>
115 <hr>
116 <p><ol id=console></ol></p>
117 </body>
118 </html> 66 </html>
OLDNEW
« no previous file with comments | « no previous file | LayoutTests/http/tests/xmlhttprequest/getAllResponseHeaders-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698