WebKit Bugzilla
New
Browse
Search+
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
[patch]
Patch 3
webcore_xhr_mime_blob_3.patch (text/plain), 12.22 KB, created by
Alexander Shalamov
on 2012-11-29 05:35:12 PST
(
hide
)
Description:
Patch 3
Filename:
MIME Type:
Creator:
Alexander Shalamov
Created:
2012-11-29 05:35:12 PST
Size:
12.22 KB
patch
obsolete
>diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog >index 57ae35d..8daf45b 100644 >--- a/LayoutTests/ChangeLog >+++ b/LayoutTests/ChangeLog >@@ -1,3 +1,15 @@ >+2012-10-26 Alexander Shalamov <alexander.shalamov@intel.com> >+ >+ XMLHttpRequest Content-Type should be taken from Blob type >+ https://bugs.webkit.org/show_bug.cgi?id=99983 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Added tests that check if content type is set correctly when blob object is sent. >+ >+ * http/tests/xmlhttprequest/post-blob-content-type-expected.txt: Added. >+ * http/tests/xmlhttprequest/post-blob-content-type.html: Added. >+ > 2012-11-29 Mike West <mkwst@chromium.org> > > Layout Test http/tests/inspector/network/script-as-text-loading-long-url.html is failing >diff --git a/LayoutTests/http/tests/xmlhttprequest/post-blob-content-type-async-expected.txt b/LayoutTests/http/tests/xmlhttprequest/post-blob-content-type-async-expected.txt >new file mode 100644 >index 0000000..0684fe4 >--- /dev/null >+++ b/LayoutTests/http/tests/xmlhttprequest/post-blob-content-type-async-expected.txt >@@ -0,0 +1,23 @@ >+CONSOLE MESSAGE: XMLHttpRequest cannot load http://localhost:8000/xmlhttprequest/resources/access-control-allow-lists.php. Origin http://127.0.0.1:8000 is not allowed by Access-Control-Allow-Origin. >+Test verifies that content MIME type is set correctly when Blob is sent using XMLHttpRequest asynchronously. >+ >+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". >+ >+ >+PASS expectedMimeType is "text/plain;charset=utf-8" >+PASS expectedMimeType is "" >+PASS expectedMimeType is "" >+PASS expectedMimeType is "" >+PASS expectedMimeType is "" >+PASS expectedMimeType is "" >+PASS expectedMimeType is "" >+PASS expectedMimeType is "" >+PASS expectedMimeType is "multipart/mixed;boundary=\"--blob-boundary\"" >+PASS expectedMimeType is "" >+PASS Exception should be thrown. >+PASS Cross-origin request without CORS headers should fail. >+PASS expectedMimeType is "text/plain;charset=utf-8" >+PASS successfullyParsed is true >+ >+TEST COMPLETE >+ >diff --git a/LayoutTests/http/tests/xmlhttprequest/post-blob-content-type-async.html b/LayoutTests/http/tests/xmlhttprequest/post-blob-content-type-async.html >new file mode 100644 >index 0000000..ef0b87d >--- /dev/null >+++ b/LayoutTests/http/tests/xmlhttprequest/post-blob-content-type-async.html >@@ -0,0 +1,74 @@ >+<!DOCTYPE html> >+<html> >+<head> >+ <script src="/js-test-resources/js-test-pre.js"></script> >+</head> >+<body> >+ <script src="post-blob-content-type-tests.js"></script> >+ <script type="text/javascript"> >+ description("Test verifies that content MIME type is set correctly " + >+ "when Blob is sent using " + >+ "<a href='http://www.w3.org/TR/XMLHttpRequest/#the-send-method'>XMLHttpRequest asynchronously.</a>"); >+ >+ var xhr; >+ var expectedMimeType; >+ window.jsTestIsAsync = true; >+ var asyncTestCase = 0; >+ >+ function runNextAsyncTest() { >+ asyncTestCase++; >+ runAsyncTests(); >+ } >+ >+ function reportResult(e) { >+ if (xhr.status === 200) { >+ expectedMimeType = JSON.parse(xhr.response)['content-type'] || ""; >+ shouldBeEqualToString("expectedMimeType", xhrBlobTestCases[asyncTestCase].expectedMime); >+ } else if (xhr.status === 0 && xhrBlobTestCases[asyncTestCase].shouldThrow){ >+ testPassed("Cross-origin request without CORS headers should fail."); >+ } else { >+ testFailed("Unknown error"); >+ } >+ >+ runNextAsyncTest(); >+ } >+ >+ function runAsyncTests() { >+ if (asyncTestCase >= xhrBlobTestCases.length) { >+ finishJSTest(); >+ return; >+ } else { >+ var mime = xhrBlobTestCases[asyncTestCase].mime; >+ var url = xhrBlobTestCases[asyncTestCase].url !== undefined ? xhrBlobTestCases[asyncTestCase].url + xhrBlobTestUrl : xhrBlobTestUrl; >+ url += xhrBlobTestCases[asyncTestCase].allowOrigin || ""; >+ if (xhrBlobTestCases[asyncTestCase].shouldThrow !== undefined) { >+ try { >+ testBlobContentTypeAsync(url, mime); >+ } catch (e) { >+ testPassed("Exception should be thrown.") >+ runNextAsyncTest(); >+ } >+ } else >+ testBlobContentTypeAsync(url, mime); >+ } >+ } >+ >+ function testBlobContentTypeAsync(url, mimeType) { >+ var blob; >+ if (mimeType !== "") >+ blob = new Blob(["Test content"], {type: mimeType}); >+ else >+ blob = new Blob(["Test content"]); >+ >+ xhr = new XMLHttpRequest(); >+ xhr.onloadend = reportResult; >+ xhr.open("POST", url, true); >+ xhr.send(blob); >+ } >+ >+ runAsyncTests(); >+ >+ </script> >+ <script src="/js-test-resources/js-test-post.js"></script> >+</body> >+</html> >diff --git a/LayoutTests/http/tests/xmlhttprequest/post-blob-content-type-sync-expected.txt b/LayoutTests/http/tests/xmlhttprequest/post-blob-content-type-sync-expected.txt >new file mode 100644 >index 0000000..2e33345 >--- /dev/null >+++ b/LayoutTests/http/tests/xmlhttprequest/post-blob-content-type-sync-expected.txt >@@ -0,0 +1,23 @@ >+CONSOLE MESSAGE: XMLHttpRequest cannot load http://localhost:8000/xmlhttprequest/resources/access-control-allow-lists.php. Origin http://127.0.0.1:8000 is not allowed by Access-Control-Allow-Origin. >+Test verifies that content MIME type is set correctly when Blob is sent using XMLHttpRequest synchronously. >+ >+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". >+ >+ >+PASS expectedMimeType is "text/plain;charset=utf-8" >+PASS expectedMimeType is "" >+PASS expectedMimeType is "" >+PASS expectedMimeType is "" >+PASS expectedMimeType is "" >+PASS expectedMimeType is "" >+PASS expectedMimeType is "" >+PASS expectedMimeType is "" >+PASS expectedMimeType is "multipart/mixed;boundary=\"--blob-boundary\"" >+PASS expectedMimeType is "" >+PASS Exception should be thrown. >+PASS Exception should be thrown. >+PASS expectedMimeType is "text/plain;charset=utf-8" >+PASS successfullyParsed is true >+ >+TEST COMPLETE >+ >diff --git a/LayoutTests/http/tests/xmlhttprequest/post-blob-content-type-sync.html b/LayoutTests/http/tests/xmlhttprequest/post-blob-content-type-sync.html >new file mode 100644 >index 0000000..ca9929d >--- /dev/null >+++ b/LayoutTests/http/tests/xmlhttprequest/post-blob-content-type-sync.html >@@ -0,0 +1,58 @@ >+<!DOCTYPE html> >+<html> >+<head> >+ <script src="/js-test-resources/js-test-pre.js"></script> >+</head> >+<body> >+ <script src="post-blob-content-type-tests.js"></script> >+ <script type="text/javascript"> >+ description("Test verifies that content MIME type is set correctly " + >+ "when Blob is sent using " + >+ "<a href='http://www.w3.org/TR/XMLHttpRequest/#the-send-method'>XMLHttpRequest synchronously.</a>"); >+ >+ var xhr; >+ var expectedMimeType; >+ >+ function runSyncTests() { >+ var testCount = xhrBlobTestCases.length; >+ for (var i = 0; i < testCount; i++) { >+ var mime = xhrBlobTestCases[i].mime; >+ var expectedMime = xhrBlobTestCases[i].expectedMime; >+ var url = xhrBlobTestCases[i].url !== undefined ? xhrBlobTestCases[i].url + xhrBlobTestUrl : xhrBlobTestUrl; >+ url += xhrBlobTestCases[i].allowOrigin || ""; >+ if (xhrBlobTestCases[i].shouldThrow !== undefined) { >+ try { >+ testBlobContentTypeSync(url, mime, expectedMime); >+ } catch (e) { >+ testPassed("Exception should be thrown.") >+ } >+ } else { >+ testBlobContentTypeSync(url, mime, expectedMime); >+ } >+ } >+ } >+ >+ function testBlobContentTypeSync(url, mimeType, expectedMime) { >+ var blob; >+ if (mimeType !== "") >+ blob = new Blob(["Test content"], {type: mimeType}); >+ else >+ blob = new Blob(["Test content"]); >+ >+ xhr = new XMLHttpRequest(); >+ xhr.open("POST", url, false); >+ xhr.send(blob); >+ if (xhr.status === 200) { >+ expectedMimeType = JSON.parse(xhr.response)['content-type'] || ""; >+ shouldBeEqualToString("expectedMimeType", expectedMime); >+ } else >+ testFailed("Unknown error"); >+ >+ } >+ >+ runSyncTests(); >+ >+ </script> >+ <script src="/js-test-resources/js-test-post.js"></script> >+</body> >+</html> >diff --git a/LayoutTests/http/tests/xmlhttprequest/post-blob-content-type-tests.js b/LayoutTests/http/tests/xmlhttprequest/post-blob-content-type-tests.js >new file mode 100644 >index 0000000..b2f29bc >--- /dev/null >+++ b/LayoutTests/http/tests/xmlhttprequest/post-blob-content-type-tests.js >@@ -0,0 +1,48 @@ >+var xhrBlobTestUrl = '/xmlhttprequest/resources/access-control-allow-lists.php'; >+ >+var xhrBlobTestCases = [{ >+ mime: 'text/plain;charset=utf-8', >+ expectedMime: 'text/plain;charset=utf-8' >+}, { >+ mime: 'Invalid/Type\r\n;charset=koi8-r', >+ expectedMime: '' >+}, { >+ mime: 'ASCII/CR\r;charset=invalid', >+ expectedMime: '' >+}, { >+ mime: 'ASCII/LF\n;charset=UTF-16BE', >+ expectedMime: '' >+}, { >+ mime: 'Unicode/CRLF\u000D\u000A;charset=Ventura-US', >+ expectedMime: '' >+}, { >+ mime: 'Unicode/CR\u000Dcharset=windows-1251', >+ expectedMime: '' >+}, { >+ mime: 'Unicode/LF\u000Acharset=windows-1252', >+ expectedMime: '' >+}, { >+ mime: 'multipart/mixed;boundary="--blob-boundary', >+ expectedMime: '' >+}, { >+ mime: 'multipart/mixed;boundary="--blob-boundary"', >+ expectedMime: 'multipart/mixed;boundary="--blob-boundary"' >+}, { >+ mime: '', >+ expectedMime: '' >+}, { >+ mime: '\u0422\u0435\u0441\u0442', >+ expectedMime: '', >+ shouldThrow: true >+}, { >+ mime: 'text/plain;charset=utf-8', >+ expectedMime: 'text/plain;charset=utf-8', >+ shouldThrow: true, >+ url: 'http://localhost:8000', >+ allowOrigin: '' >+}, { >+ mime: 'text/plain;charset=utf-8', >+ expectedMime: 'text/plain;charset=utf-8', >+ url: 'http://localhost:8000', >+ allowOrigin: '?origin=http://127.0.0.1:8000' >+}]; >\ No newline at end of file >diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index c8b1b68..fa5d41b 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,21 @@ >+2012-10-26 Alexander Shalamov <alexander.shalamov@intel.com> >+ >+ XMLHttpRequest Content-Type should be taken from Blob type >+ https://bugs.webkit.org/show_bug.cgi?id=99983 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Fix XMLHttpRequest::send(Blob*) method, so that the Content-Type is set according to W3C specification. >+ http://www.w3.org/TR/XMLHttpRequest/#the-send-method >+ >+ Added test that check if content type is set correctly when blob object is sent. >+ >+ Test: http/tests/xmlhttprequest/post-blob-content-type.html >+ >+ * xml/XMLHttpRequest.cpp: >+ (WebCore::XMLHttpRequest::send): >+ Set correct MIME type for Blob objects. >+ > 2012-11-29 Sheriff Bot <webkit.review.bot@gmail.com> > > Unreviewed, rolling out r136111. >diff --git a/Source/WebCore/xml/XMLHttpRequest.cpp b/Source/WebCore/xml/XMLHttpRequest.cpp >index 29536da..edacbbd 100644 >--- a/Source/WebCore/xml/XMLHttpRequest.cpp >+++ b/Source/WebCore/xml/XMLHttpRequest.cpp >@@ -42,6 +42,7 @@ > #include "HistogramSupport.h" > #include "InspectorInstrumentation.h" > #include "MemoryCache.h" >+#include "ParsedContentType.h" > #include "ResourceError.h" > #include "ResourceRequest.h" > #include "ScriptCallStack.h" >@@ -643,7 +644,16 @@ void XMLHttpRequest::send(Blob* body, ExceptionCode& ec) > return; > > if (m_method != "GET" && m_method != "HEAD" && m_url.protocolIsInHTTPFamily()) { >- // FIXME: Should we set a Content-Type if one is not set. >+ const String& contentType = getRequestHeader("Content-Type"); >+ if (contentType.isEmpty()) { >+ const String& blobType = body->type(); >+ if (!blobType.isEmpty() && isValidContentType(blobType)) >+ setRequestHeaderInternal("Content-Type", blobType); >+ else >+ // From FileAPI spec, whenever media type cannot be determined, empty string must be returned. >+ setRequestHeaderInternal("Content-Type", ""); >+ } >+ > // FIXME: add support for uploading bundles. > m_requestEntityBody = FormData::create(); > if (body->isFile())
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 99983
:
169890
|
170880
|
176711
|
176712
|
177242
|
177736