Commit e1a8da7e authored by Rob Buis's avatar Rob Buis Committed by Commit Bot

Improve xhr/setrequestheader-content-type.htm result

Improve xhr/setrequestheader-content-type.htm result by doing two fixes:
- Apply Content-Type processing steps for Documents, just like for Strings [1].
- Apply Content-Type processing steps also for empty Content-Type value [2].

This matches Firefox and WebKit.

[1] https://xhr.spec.whatwg.org/#the-send()-method 4.4.1
[2] https://xhr.spec.whatwg.org/#the-send()-method 4.4

Bug: 626703

Change-Id: Ie09df6e711b04a30b6181914f3b59bb8cf4e6a49
Reviewed-on: https://chromium-review.googlesource.com/1189602Reviewed-by: default avatarYutaka Hirano <yhirano@chromium.org>
Commit-Queue: Rob Buis <rbuis@igalia.com>
Cr-Commit-Position: refs/heads/master@{#587059}
parent 6ee348c4
This is a testharness.js-based test. This is a testharness.js-based test.
FAIL header with invalid MIME type is not changed assert_equals: expected "text; charset=ascii" but got "text; charset=UTF-8" FAIL header with invalid MIME type is not changed assert_equals: expected "text; charset=ascii" but got "text; charset=UTF-8"
FAIL header with invalid MIME type (empty string) is not changed assert_equals: expected "" but got "text/plain;charset=UTF-8" PASS header with invalid MIME type (empty string) is not changed
PASS known charset but bogus header - missing MIME type PASS known charset but bogus header - missing MIME type
PASS bogus charset and bogus header - missing MIME type PASS bogus charset and bogus header - missing MIME type
PASS Correct text/plain MIME with charset PASS Correct text/plain MIME with charset
......
This is a testharness.js-based test. This is a testharness.js-based test.
FAIL setRequestHeader("") sends a blank string assert_equals: expected "Content-Type: \n" but got "Content-Type: , text/plain;charset=UTF-8\n" PASS setRequestHeader("") sends a blank string
FAIL setRequestHeader(" ") sends the string " " assert_equals: expected "Content-Type: \n" but got "Content-Type: , text/plain;charset=UTF-8\n" PASS setRequestHeader(" ") sends the string " "
PASS setRequestHeader(null) sends the string "null" PASS setRequestHeader(null) sends the string "null"
PASS setRequestHeader(undefined) sends the string "undefined" PASS setRequestHeader(undefined) sends the string "undefined"
PASS String request has correct default Content-Type of "text/plain;charset=UTF-8" PASS String request has correct default Content-Type of "text/plain;charset=UTF-8"
PASS String request keeps setRequestHeader() Content-Type, with charset adjusted to UTF-8 PASS String request keeps setRequestHeader() Content-Type, with charset adjusted to UTF-8
PASS XML Document request respects setRequestHeader("") PASS XML Document request respects setRequestHeader("")
PASS XML Document request has correct default Content-Type of "application/xml;charset=UTF-8" PASS XML Document request has correct default Content-Type of "application/xml;charset=UTF-8"
FAIL XML Document request keeps setRequestHeader() Content-Type, with charset adjusted to UTF-8 assert_equals: expected "Content-Type: application/xhtml+xml;charset=UTF-8\n" but got "Content-Type: application/xhtml+xml;charset=ASCII\n" PASS XML Document request keeps setRequestHeader() Content-Type, with charset adjusted to UTF-8
PASS HTML Document request respects setRequestHeader("") PASS HTML Document request respects setRequestHeader("")
FAIL HTML Document request has correct default Content-Type of "text/html;charset=UTF-8" assert_equals: expected "Content-Type: text/html;charset=UTF-8\n" but got "Content-Type: application/xml;charset=UTF-8\n" PASS HTML Document request has correct default Content-Type of "text/html;charset=UTF-8"
FAIL HTML Document request keeps setRequestHeader() Content-Type, with charset adjusted to UTF-8 assert_equals: expected "Content-Type: text/html+junk;charset=UTF-8\n" but got "Content-Type: text/html+junk;charset=ASCII\n" PASS HTML Document request keeps setRequestHeader() Content-Type, with charset adjusted to UTF-8
PASS Blob request respects setRequestHeader("") to be specified PASS Blob request respects setRequestHeader("") to be specified
PASS Blob request with unset type sends no Content-Type without setRequestHeader() call PASS Blob request with unset type sends no Content-Type without setRequestHeader() call
PASS Blob request with unset type keeps setRequestHeader() Content-Type and charset PASS Blob request with unset type keeps setRequestHeader() Content-Type and charset
...@@ -26,10 +26,10 @@ PASS ArrayBufferView request keeps setRequestHeader() Content-Type and charset ...@@ -26,10 +26,10 @@ PASS ArrayBufferView request keeps setRequestHeader() Content-Type and charset
PASS FormData request respects setRequestHeader("") PASS FormData request respects setRequestHeader("")
PASS FormData request has correct default Content-Type of "multipart/form-data; boundary=_" PASS FormData request has correct default Content-Type of "multipart/form-data; boundary=_"
PASS FormData request keeps setRequestHeader() Content-Type and charset PASS FormData request keeps setRequestHeader() Content-Type and charset
FAIL URLSearchParams respects setRequestHeader("") assert_equals: expected "Content-Type: \n" but got "Content-Type: , application/x-www-form-urlencoded;charset=UTF-8\n" PASS URLSearchParams respects setRequestHeader("")
PASS URLSearchParams request has correct default Content-Type of "application/x-www-form-urlencoded;charset=UTF-8" PASS URLSearchParams request has correct default Content-Type of "application/x-www-form-urlencoded;charset=UTF-8"
PASS URLSearchParams request keeps setRequestHeader() Content-Type, with charset adjusted to UTF-8 PASS URLSearchParams request keeps setRequestHeader() Content-Type, with charset adjusted to UTF-8
FAIL ReadableStream request respects setRequestHeader("") assert_equals: expected "Content-Type: \n" but got "Content-Type: , text/plain;charset=UTF-8\n" PASS ReadableStream request respects setRequestHeader("")
FAIL ReadableStream request with under type sends no Content-Type without setRequestHeader() call assert_equals: expected "" but got "Content-Type: text/plain;charset=UTF-8\n" FAIL ReadableStream request with under type sends no Content-Type without setRequestHeader() call assert_equals: expected "" but got "Content-Type: text/plain;charset=UTF-8\n"
FAIL ReadableStream request keeps setRequestHeader() Content-Type and charset assert_equals: expected "Content-Type: application/xml;charset=ASCII\n" but got "Content-Type: application/xml;charset=UTF-8\n" FAIL ReadableStream request keeps setRequestHeader() Content-Type and charset assert_equals: expected "Content-Type: application/xml;charset=ASCII\n" but got "Content-Type: application/xml;charset=UTF-8\n"
Harness: the test ran to completion. Harness: the test ran to completion.
......
...@@ -14,7 +14,7 @@ async_test(function(t) { ...@@ -14,7 +14,7 @@ async_test(function(t) {
xhr.open("POST", "print-content-type.cgi"); xhr.open("POST", "print-content-type.cgi");
xhr.send(document); xhr.send(document);
xhr.onloadend = t.step_func_done(function() { xhr.onloadend = t.step_func_done(function() {
assert_equals(xhr.responseText, "application/xml;charset=UTF-8\n"); assert_equals(xhr.responseText, "text/html;charset=UTF-8\n");
}); });
}); });
</script> </script>
......
...@@ -827,12 +827,10 @@ void XMLHttpRequest::send(Document* document, ExceptionState& exception_state) { ...@@ -827,12 +827,10 @@ void XMLHttpRequest::send(Document* document, ExceptionState& exception_state) {
scoped_refptr<EncodedFormData> http_body; scoped_refptr<EncodedFormData> http_body;
if (AreMethodAndURLValidForSend()) { if (AreMethodAndURLValidForSend()) {
// FIXME: Per https://xhr.spec.whatwg.org/#dom-xmlhttprequest-send the if (document->IsHTMLDocument())
// Content-Type header and whether to serialize as HTML or XML should UpdateContentTypeAndCharset("text/html;charset=UTF-8", "UTF-8");
// depend on |document->isHTMLDocument()|. else if (document->IsXMLDocument())
if (!HasContentTypeRequestHeader()) UpdateContentTypeAndCharset("application/xml;charset=UTF-8", "UTF-8");
SetRequestHeaderInternal(HTTPNames::Content_Type,
"application/xml;charset=UTF-8");
String body = CreateMarkup(document); String body = CreateMarkup(document);
...@@ -1542,7 +1540,7 @@ void XMLHttpRequest::UpdateContentTypeAndCharset( ...@@ -1542,7 +1540,7 @@ void XMLHttpRequest::UpdateContentTypeAndCharset(
// http://xhr.spec.whatwg.org/#the-send()-method step 4's concilliation of // http://xhr.spec.whatwg.org/#the-send()-method step 4's concilliation of
// "charset=" in any author-provided Content-Type: request header. // "charset=" in any author-provided Content-Type: request header.
String content_type = request_headers_.Get(HTTPNames::Content_Type); String content_type = request_headers_.Get(HTTPNames::Content_Type);
if (content_type.IsEmpty()) { if (content_type.IsNull()) {
SetRequestHeaderInternal(HTTPNames::Content_Type, default_content_type); SetRequestHeaderInternal(HTTPNames::Content_Type, default_content_type);
return; return;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment