Diff
Modified: trunk/LayoutTests/ChangeLog (136892 => 136893)
--- trunk/LayoutTests/ChangeLog 2012-12-06 22:30:06 UTC (rev 136892)
+++ trunk/LayoutTests/ChangeLog 2012-12-06 22:32:46 UTC (rev 136893)
@@ -1,3 +1,15 @@
+2012-12-06 Alexander Shalamov <alexander.shala...@intel.com>
+
+ XMLHttpRequest Content-Type should be taken from Blob type
+ https://bugs.webkit.org/show_bug.cgi?id=99983
+
+ Reviewed by Alexey Proskuryakov.
+
+ 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-12-06 Joshua Bell <jsb...@chromium.org>
[Chromium] IndexedDB: storage/indexeddb/resources/cursor-advance.html flaky in content_shell after WK136782
Added: trunk/LayoutTests/http/tests/xmlhttprequest/post-blob-content-type-async-expected.txt (0 => 136893)
--- trunk/LayoutTests/http/tests/xmlhttprequest/post-blob-content-type-async-expected.txt (rev 0)
+++ trunk/LayoutTests/http/tests/xmlhttprequest/post-blob-content-type-async-expected.txt 2012-12-06 22:32:46 UTC (rev 136893)
@@ -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
+
Added: trunk/LayoutTests/http/tests/xmlhttprequest/post-blob-content-type-async.html (0 => 136893)
--- trunk/LayoutTests/http/tests/xmlhttprequest/post-blob-content-type-async.html (rev 0)
+++ trunk/LayoutTests/http/tests/xmlhttprequest/post-blob-content-type-async.html 2012-12-06 22:32:46 UTC (rev 136893)
@@ -0,0 +1,74 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <script src=""
+</head>
+<body>
+ <script src=""
+ <script type="text/_javascript_">
+ description("Test verifies that content MIME type is set correctly " +
+ "when Blob is sent using " +
+ "<a href=''>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 = "" !== 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=""
+</body>
+</html>
Added: trunk/LayoutTests/http/tests/xmlhttprequest/post-blob-content-type-sync-expected.txt (0 => 136893)
--- trunk/LayoutTests/http/tests/xmlhttprequest/post-blob-content-type-sync-expected.txt (rev 0)
+++ trunk/LayoutTests/http/tests/xmlhttprequest/post-blob-content-type-sync-expected.txt 2012-12-06 22:32:46 UTC (rev 136893)
@@ -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
+
Added: trunk/LayoutTests/http/tests/xmlhttprequest/post-blob-content-type-sync.html (0 => 136893)
--- trunk/LayoutTests/http/tests/xmlhttprequest/post-blob-content-type-sync.html (rev 0)
+++ trunk/LayoutTests/http/tests/xmlhttprequest/post-blob-content-type-sync.html 2012-12-06 22:32:46 UTC (rev 136893)
@@ -0,0 +1,58 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <script src=""
+</head>
+<body>
+ <script src=""
+ <script type="text/_javascript_">
+ description("Test verifies that content MIME type is set correctly " +
+ "when Blob is sent using " +
+ "<a href=''>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 = "" !== 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=""
+</body>
+</html>
Added: trunk/LayoutTests/http/tests/xmlhttprequest/post-blob-content-type-tests.js (0 => 136893)
--- trunk/LayoutTests/http/tests/xmlhttprequest/post-blob-content-type-tests.js (rev 0)
+++ trunk/LayoutTests/http/tests/xmlhttprequest/post-blob-content-type-tests.js 2012-12-06 22:32:46 UTC (rev 136893)
@@ -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
Modified: trunk/Source/WebCore/ChangeLog (136892 => 136893)
--- trunk/Source/WebCore/ChangeLog 2012-12-06 22:30:06 UTC (rev 136892)
+++ trunk/Source/WebCore/ChangeLog 2012-12-06 22:32:46 UTC (rev 136893)
@@ -1,3 +1,23 @@
+2012-12-06 Alexander Shalamov <alexander.shala...@intel.com>
+
+ XMLHttpRequest Content-Type should be taken from Blob type
+ https://bugs.webkit.org/show_bug.cgi?id=99983
+
+ Reviewed by Alexey Proskuryakov.
+
+ 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.
+ * WebCore.vcproj/WebCore.vcproj:
+ Added ParsedContentType to project file.
+
2012-12-06 Min Qin <qin...@chromium.org>
Make LazyDecodingPixelRef inherit from skia::LazyPixelRef so that cc thread can access it
Modified: trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj (136892 => 136893)
--- trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj 2012-12-06 22:30:06 UTC (rev 136892)
+++ trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj 2012-12-06 22:32:46 UTC (rev 136893)
@@ -32665,6 +32665,14 @@
>
</File>
<File
+ RelativePath="..\platform\network\ParsedContentType.h"
+ >
+ </File>
+ <File
+ RelativePath="..\platform\network\ParsedContentType.cpp"
+ >
+ </File>
+ <File
RelativePath="..\platform\network\PlatformCookieJar.h"
>
</File>
Modified: trunk/Source/WebCore/xml/XMLHttpRequest.cpp (136892 => 136893)
--- trunk/Source/WebCore/xml/XMLHttpRequest.cpp 2012-12-06 22:30:06 UTC (rev 136892)
+++ trunk/Source/WebCore/xml/XMLHttpRequest.cpp 2012-12-06 22:32:46 UTC (rev 136893)
@@ -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,17 @@
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())