Title: [205250] trunk
Revision
205250
Author
[email protected]
Date
2016-08-31 09:36:35 -0700 (Wed, 31 Aug 2016)

Log Message

[Fetch API] Blob type should be correctly set in case of empty body
https://bugs.webkit.org/show_bug.cgi?id=161431

Patch by Youenn Fablet <[email protected]> on 2016-08-31
Reviewed by Alex Christensen.

Source/WebCore:

Tests: http/tests/fetch/fetch-as-blob-worker.html
       http/tests/fetch/fetch-as-blob.html

* Modules/fetch/FetchBodyConsumer.cpp:
(WebCore::FetchBodyConsumer::takeAsBlob): Set blob type with contentType even if blob has no data.
* Modules/fetch/FetchBodyOwner.cpp:
(WebCore::FetchBodyOwner::blob): Ditto for empty bodies.

LayoutTests:

* http/tests/fetch/fetch-as-blob-expected.txt: Added.
* http/tests/fetch/fetch-as-blob-worker-expected.txt: Added.
* http/tests/fetch/fetch-as-blob-worker.html: Added.
* http/tests/fetch/fetch-as-blob.html: Added.
* http/tests/fetch/fetch-as-blob.js: Added.
(promise_test):

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (205249 => 205250)


--- trunk/LayoutTests/ChangeLog	2016-08-31 16:32:44 UTC (rev 205249)
+++ trunk/LayoutTests/ChangeLog	2016-08-31 16:36:35 UTC (rev 205250)
@@ -1,3 +1,17 @@
+2016-08-31  Youenn Fablet  <[email protected]>
+
+        [Fetch API] Blob type should be correctly set in case of empty body
+        https://bugs.webkit.org/show_bug.cgi?id=161431
+
+        Reviewed by Alex Christensen.
+
+        * http/tests/fetch/fetch-as-blob-expected.txt: Added.
+        * http/tests/fetch/fetch-as-blob-worker-expected.txt: Added.
+        * http/tests/fetch/fetch-as-blob-worker.html: Added.
+        * http/tests/fetch/fetch-as-blob.html: Added.
+        * http/tests/fetch/fetch-as-blob.js: Added.
+        (promise_test):
+
 2016-08-31  Romain Bellessort  <[email protected]>
 
         [Streams API] Align getReader() with spec

Added: trunk/LayoutTests/http/tests/fetch/fetch-as-blob-expected.txt (0 => 205250)


--- trunk/LayoutTests/http/tests/fetch/fetch-as-blob-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/fetch/fetch-as-blob-expected.txt	2016-08-31 16:36:35 UTC (rev 205250)
@@ -0,0 +1,9 @@
+
+PASS MIME type for Blob from empty body 
+PASS MIME type for Blob from empty body with Content-Type 
+PASS MIME type for Blob 
+PASS MIME type for Blob with non-empty type 
+PASS Extract a MIME type with clone 
+PASS MIME type unchanged if headers are modified after Request() constructor 
+PASS Extract a MIME type (1) 
+

Added: trunk/LayoutTests/http/tests/fetch/fetch-as-blob-worker-expected.txt (0 => 205250)


--- trunk/LayoutTests/http/tests/fetch/fetch-as-blob-worker-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/fetch/fetch-as-blob-worker-expected.txt	2016-08-31 16:36:35 UTC (rev 205250)
@@ -0,0 +1,9 @@
+
+PASS MIME type for Blob from empty body 
+PASS MIME type for Blob from empty body with Content-Type 
+PASS MIME type for Blob 
+PASS MIME type for Blob with non-empty type 
+PASS Extract a MIME type with clone 
+PASS MIME type unchanged if headers are modified after Request() constructor 
+PASS Extract a MIME type (1) 
+

Added: trunk/LayoutTests/http/tests/fetch/fetch-as-blob-worker.html (0 => 205250)


--- trunk/LayoutTests/http/tests/fetch/fetch-as-blob-worker.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/fetch/fetch-as-blob-worker.html	2016-08-31 16:36:35 UTC (rev 205250)
@@ -0,0 +1,17 @@
+<!doctype html>
+<html>
+    <head>
+        <meta charset="utf-8">
+        <title>Response body used tests</title>
+        <meta name="help" href=""
+        <meta name="help" href=""
+        <script src=""
+        <script src=""
+    </head>
+    <body>
+        <script>
+            fetch_tests_from_worker(new Worker("fetch-as-blob.js"));
+        </script>
+    </body>
+</html>
+

Added: trunk/LayoutTests/http/tests/fetch/fetch-as-blob.html (0 => 205250)


--- trunk/LayoutTests/http/tests/fetch/fetch-as-blob.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/fetch/fetch-as-blob.html	2016-08-31 16:36:35 UTC (rev 205250)
@@ -0,0 +1,14 @@
+<!doctype html>
+<html>
+    <head>
+        <meta charset="utf-8">
+        <title>Response body used tests</title>
+        <meta name="help" href=""
+        <meta name="help" href=""
+        <script src=""
+        <script src=""
+    </head>
+    <body>
+        <script src=""
+    </body>
+</html>

Added: trunk/LayoutTests/http/tests/fetch/fetch-as-blob.js (0 => 205250)


--- trunk/LayoutTests/http/tests/fetch/fetch-as-blob.js	                        (rev 0)
+++ trunk/LayoutTests/http/tests/fetch/fetch-as-blob.js	2016-08-31 16:36:35 UTC (rev 205250)
@@ -0,0 +1,87 @@
+if (self.importScripts) {
+  importScripts('/resources/testharness.js');
+}
+
+promise_test(function(t) {
+    var req = new Request('http://localhost/',
+                          {method: 'POST'});
+    return req.blob()
+      .then(function(blob) {
+          assert_equals(blob.type, '');
+        });
+  }, 'MIME type for Blob from empty body');
+
+promise_test(function(t) {
+    var req = new Request('http://localhost/',
+                          {method: 'POST', headers: [['Content-Type', 'Mytext/Plain']]});
+    return req.blob()
+      .then(function(blob) {
+          assert_equals(blob.type, 'mytext/plain');
+        });
+  }, 'MIME type for Blob from empty body with Content-Type');
+
+// The 5 following tests are coming from Chromium see fetch/script-tests/request.js
+
+// Tests for MIME types.
+promise_test(function(t) {
+    var req = new Request('http://localhost/',
+                          {method: 'POST', body: new Blob([''])});
+    return req.blob()
+      .then(function(blob) {
+          assert_equals(blob.type, '');
+          assert_equals(req.headers.get('Content-Type'), null);
+        });
+  }, 'MIME type for Blob');
+
+promise_test(function(t) {
+    var req = new Request('http://localhost/',
+                          {method: 'POST',
+                           body: new Blob([''], {type: 'Text/Plain'})});
+    return req.blob()
+      .then(function(blob) {
+          assert_equals(blob.type, 'text/plain');
+          assert_equals(req.headers.get('Content-Type'), 'text/plain');
+        });
+  }, 'MIME type for Blob with non-empty type');
+
+promise_test(function(t) {
+    var req = new Request('http://localhost/',
+                          {method: 'POST',
+                           body: new Blob([''], {type: 'Text/Plain'}),
+                           headers: [['Content-Type', 'Text/Html']]});
+    var clone = req.clone();
+    return Promise.all([req.blob(), clone.blob()])
+      .then(function(blobs) {
+          assert_equals(blobs[0].type, 'text/html');
+          assert_equals(blobs[1].type, 'text/html');
+          assert_equals(req.headers.get('Content-Type'), 'Text/Html');
+          assert_equals(clone.headers.get('Content-Type'), 'Text/Html');
+        });
+  }, 'Extract a MIME type with clone');
+
+promise_test(function(t) {
+    var req = new Request('http://localhost/',
+                          {method: 'POST',
+                           body: new Blob([''], {type: 'Text/Plain'})});
+    req.headers.set('Content-Type', 'Text/Html');
+    return req.blob()
+      .then(function(blob) {
+          assert_equals(blob.type, 'text/plain');
+          assert_equals(req.headers.get('Content-Type'), 'Text/Html');
+        });
+  },
+  'MIME type unchanged if headers are modified after Request() constructor');
+
+promise_test(function(t) {
+    var req = new Request('http://localhost/',
+                          {method: 'POST',
+                           body: new Blob([''], {type: 'Text/Plain'}),
+                           headers: [['Content-Type', 'Text/Html']]});
+    return req.blob()
+      .then(function(blob) {
+          assert_equals(blob.type, 'text/html');
+          assert_equals(req.headers.get('Content-Type'), 'Text/Html');
+        });
+  }, 'Extract a MIME type (1)');
+
+done();

Modified: trunk/Source/WebCore/ChangeLog (205249 => 205250)


--- trunk/Source/WebCore/ChangeLog	2016-08-31 16:32:44 UTC (rev 205249)
+++ trunk/Source/WebCore/ChangeLog	2016-08-31 16:36:35 UTC (rev 205250)
@@ -1,3 +1,18 @@
+2016-08-31  Youenn Fablet  <[email protected]>
+
+        [Fetch API] Blob type should be correctly set in case of empty body
+        https://bugs.webkit.org/show_bug.cgi?id=161431
+
+        Reviewed by Alex Christensen.
+
+        Tests: http/tests/fetch/fetch-as-blob-worker.html
+               http/tests/fetch/fetch-as-blob.html
+
+        * Modules/fetch/FetchBodyConsumer.cpp:
+        (WebCore::FetchBodyConsumer::takeAsBlob): Set blob type with contentType even if blob has no data.
+        * Modules/fetch/FetchBodyOwner.cpp:
+        (WebCore::FetchBodyOwner::blob): Ditto for empty bodies.
+
 2016-08-31  Andreas Kling  <[email protected]>
 
         DOM event handling should pass Event around by reference.

Modified: trunk/Source/WebCore/Modules/fetch/FetchBodyConsumer.cpp (205249 => 205250)


--- trunk/Source/WebCore/Modules/fetch/FetchBodyConsumer.cpp	2016-08-31 16:32:44 UTC (rev 205249)
+++ trunk/Source/WebCore/Modules/fetch/FetchBodyConsumer.cpp	2016-08-31 16:36:35 UTC (rev 205250)
@@ -134,7 +134,7 @@
 Ref<Blob> FetchBodyConsumer::takeAsBlob()
 {
     if (!m_buffer)
-        return Blob::create();
+        return Blob::create(Vector<uint8_t>(), m_contentType);
 
     // FIXME: We should try to move m_buffer to Blob without doing extra copy.
     return blobFromData(reinterpret_cast<const unsigned char*>(m_buffer->data()), m_buffer->size(), m_contentType);

Modified: trunk/Source/WebCore/Modules/fetch/FetchBodyOwner.cpp (205249 => 205250)


--- trunk/Source/WebCore/Modules/fetch/FetchBodyOwner.cpp	2016-08-31 16:32:44 UTC (rev 205249)
+++ trunk/Source/WebCore/Modules/fetch/FetchBodyOwner.cpp	2016-08-31 16:36:35 UTC (rev 205250)
@@ -34,6 +34,7 @@
 #include "ExceptionCode.h"
 #include "FetchLoader.h"
 #include "FetchResponseSource.h"
+#include "HTTPParsers.h"
 #include "JSBlob.h"
 #include "ResourceResponse.h"
 
@@ -87,7 +88,7 @@
 void FetchBodyOwner::blob(DeferredWrapper&& promise)
 {
     if (m_body.isEmpty()) {
-        promise.resolve(Blob::create());
+        promise.resolve(Blob::create(Vector<uint8_t>(), Blob::normalizedContentType(extractMIMETypeFromMediaType(m_body.contentType()))));
         return;
     }
     if (isDisturbed()) {
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to