Title: [206632] trunk
Revision
206632
Author
[email protected]
Date
2016-09-30 01:04:52 -0700 (Fri, 30 Sep 2016)

Log Message

[Fetch API] Add support for URLSearchParams body
https://bugs.webkit.org/show_bug.cgi?id=162667

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

LayoutTests/imported/w3c:

Adding new tests to consume, stream and upload URLSearchParams bodies.

* web-platform-tests/fetch/api/basic/request-headers-expected.txt:
* web-platform-tests/fetch/api/basic/request-headers-worker-expected.txt:
* web-platform-tests/fetch/api/basic/request-headers.js:
(checkContentType):
(requestHeaders):
* web-platform-tests/fetch/api/basic/request-upload-expected.txt: Added.
* web-platform-tests/fetch/api/basic/request-upload-worker-expected.txt: Added.
* web-platform-tests/fetch/api/basic/request-upload-worker.html: Added.
* web-platform-tests/fetch/api/basic/request-upload.html: Added.
* web-platform-tests/fetch/api/basic/request-upload.js: Added.
(testUpload):
* web-platform-tests/fetch/api/request/request-consume-empty-expected.txt:
* web-platform-tests/fetch/api/request/request-consume-empty.html:
* web-platform-tests/fetch/api/request/request-init-002-expected.txt:
* web-platform-tests/fetch/api/resources/echo-content.py: Added.
(main):
* web-platform-tests/fetch/api/response/response-consume-empty-expected.txt:
* web-platform-tests/fetch/api/response/response-consume-empty.html:
* web-platform-tests/fetch/api/response/response-consume-expected.txt:
* web-platform-tests/fetch/api/response/response-consume-stream-expected.txt:
* web-platform-tests/fetch/api/response/response-consume-stream.html:
* web-platform-tests/fetch/api/response/response-consume.html:
* web-platform-tests/fetch/api/response/response-init-002-expected.txt:

Source/WebCore:

Tests: imported/w3c/web-platform-tests/fetch/api/basic/request-upload-worker.html
       imported/w3c/web-platform-tests/fetch/api/basic/request-upload.html

* Modules/fetch/FetchBody.cpp:
(WebCore::extractBytesFromText): Moving to a static function that should be moved to a String method.
(WebCore::FetchBody::FetchBody): Adding constructor for URLSearchParams.
(WebCore::FetchBody::extract): Adding URLSearchParams body initialization.
(WebCore::FetchBody::consume): Consuming URLSearchParams bodies.
(WebCore::FetchBody::consumeAsStream): Ditto.
(WebCore::FetchBody::consumeText): Updated to take a parameter to handle both text and URLSearchParams bodies.
(WebCore::FetchBody::bodyForInternalRequest): Add URLSearchParams body upload.
(WebCore::FetchBody::clone): Add URLSearchParams body cloning
* Modules/fetch/FetchBody.h:
(WebCore::FetchBody::urlSearchParamsBody):
* html/URLSearchParams.cpp:
(WebCore::URLSearchParams::toString):
* html/URLSearchParams.h:

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (206631 => 206632)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2016-09-30 06:41:08 UTC (rev 206631)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2016-09-30 08:04:52 UTC (rev 206632)
@@ -1,3 +1,36 @@
+2016-09-30  Youenn Fablet  <[email protected]>
+
+        [Fetch API] Add support for URLSearchParams body
+        https://bugs.webkit.org/show_bug.cgi?id=162667
+
+        Reviewed by Alex Christensen.
+
+        Adding new tests to consume, stream and upload URLSearchParams bodies.
+
+        * web-platform-tests/fetch/api/basic/request-headers-expected.txt:
+        * web-platform-tests/fetch/api/basic/request-headers-worker-expected.txt:
+        * web-platform-tests/fetch/api/basic/request-headers.js:
+        (checkContentType):
+        (requestHeaders):
+        * web-platform-tests/fetch/api/basic/request-upload-expected.txt: Added.
+        * web-platform-tests/fetch/api/basic/request-upload-worker-expected.txt: Added.
+        * web-platform-tests/fetch/api/basic/request-upload-worker.html: Added.
+        * web-platform-tests/fetch/api/basic/request-upload.html: Added.
+        * web-platform-tests/fetch/api/basic/request-upload.js: Added.
+        (testUpload):
+        * web-platform-tests/fetch/api/request/request-consume-empty-expected.txt:
+        * web-platform-tests/fetch/api/request/request-consume-empty.html:
+        * web-platform-tests/fetch/api/request/request-init-002-expected.txt:
+        * web-platform-tests/fetch/api/resources/echo-content.py: Added.
+        (main):
+        * web-platform-tests/fetch/api/response/response-consume-empty-expected.txt:
+        * web-platform-tests/fetch/api/response/response-consume-empty.html:
+        * web-platform-tests/fetch/api/response/response-consume-expected.txt:
+        * web-platform-tests/fetch/api/response/response-consume-stream-expected.txt:
+        * web-platform-tests/fetch/api/response/response-consume-stream.html:
+        * web-platform-tests/fetch/api/response/response-consume.html:
+        * web-platform-tests/fetch/api/response/response-init-002-expected.txt:
+
 2016-09-29  Chris Dumez  <[email protected]>
 
         Add support for download attribute on area elements

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/request-headers-expected.txt (206631 => 206632)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/request-headers-expected.txt	2016-09-30 06:41:08 UTC (rev 206631)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/request-headers-expected.txt	2016-09-30 08:04:52 UTC (rev 206632)
@@ -6,6 +6,7 @@
 PASS Fetch with POST without body 
 PASS Fetch with POST with text body 
 PASS Fetch with POST with FormData body 
+PASS Fetch with POST with URLSearchParams body 
 FAIL Fetch with POST with Blob body assert_equals: Request should have header content-type: null expected (object) null but got (string) "application/x-www-form-urlencoded"
 FAIL Fetch with POST with ArrayBuffer body assert_equals: Request should have header content-type: null expected (object) null but got (string) "application/x-www-form-urlencoded"
 FAIL Fetch with POST with Uint8Array body assert_equals: Request should have header content-type: null expected (object) null but got (string) "application/x-www-form-urlencoded"

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/request-headers-worker-expected.txt (206631 => 206632)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/request-headers-worker-expected.txt	2016-09-30 06:41:08 UTC (rev 206631)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/request-headers-worker-expected.txt	2016-09-30 08:04:52 UTC (rev 206632)
@@ -6,6 +6,7 @@
 PASS Fetch with POST without body 
 PASS Fetch with POST with text body 
 FAIL Fetch with POST with FormData body Can't find variable: FormData
+PASS Fetch with POST with URLSearchParams body 
 FAIL Fetch with POST with Blob body assert_equals: Request should have header content-type: null expected (object) null but got (string) "application/x-www-form-urlencoded"
 FAIL Fetch with POST with ArrayBuffer body assert_equals: Request should have header content-type: null expected (object) null but got (string) "application/x-www-form-urlencoded"
 FAIL Fetch with POST with Uint8Array body assert_equals: Request should have header content-type: null expected (object) null but got (string) "application/x-www-form-urlencoded"

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/request-headers.js (206631 => 206632)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/request-headers.js	2016-09-30 06:41:08 UTC (rev 206631)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/request-headers.js	2016-09-30 08:04:52 UTC (rev 206632)
@@ -15,6 +15,8 @@
         expectedContentType = null;
     else if (body instanceof Blob)
         expectedContentType = body.type ? body.type : null;
+    else if (body instanceof URLSearchParams)
+        expectedContentType = "application/x-www-form-urlencoded;charset=UTF-8";
 
     assert_equals(contentType , expectedContentType, "Request should have header content-type: " + expectedContentType);
 }
@@ -49,6 +51,7 @@
 requestHeaders("Fetch with POST without body", url, "POST", null, location.origin, "0");
 requestHeaders("Fetch with POST with text body", url, "POST", "Request's body", location.origin, "14");
 requestHeaders("Fetch with POST with FormData body", url, "POST", function() { return new FormData(); }, location.origin);
+requestHeaders("Fetch with POST with URLSearchParams body", url, "POST", function() { return new URLSearchParams("name=value"); }, location.origin, "10");
 requestHeaders("Fetch with POST with Blob body", url, "POST", new Blob(["Test"]), location.origin, "4");
 requestHeaders("Fetch with POST with ArrayBuffer body", url, "POST", new ArrayBuffer(4), location.origin, "4");
 requestHeaders("Fetch with POST with Uint8Array body", url, "POST", new Uint8Array(4), location.origin, "4");

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/request-upload-expected.txt (0 => 206632)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/request-upload-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/request-upload-expected.txt	2016-09-30 08:04:52 UTC (rev 206632)
@@ -0,0 +1,13 @@
+
+PASS Fetch with PUT with body 
+PASS Fetch with POST with text body 
+PASS Fetch with POST with URLSearchParams body 
+PASS Fetch with POST with Blob body 
+PASS Fetch with POST with ArrayBuffer body 
+PASS Fetch with POST with Uint8Array body 
+PASS Fetch with POST with Int8Array body 
+PASS Fetch with POST with Float32Array body 
+PASS Fetch with POST with Float64Array body 
+PASS Fetch with POST with DataView body 
+PASS Fetch with POST with Blob body with mime type 
+

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/request-upload-worker-expected.txt (0 => 206632)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/request-upload-worker-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/request-upload-worker-expected.txt	2016-09-30 08:04:52 UTC (rev 206632)
@@ -0,0 +1,13 @@
+
+PASS Fetch with PUT with body 
+PASS Fetch with POST with text body 
+PASS Fetch with POST with URLSearchParams body 
+PASS Fetch with POST with Blob body 
+PASS Fetch with POST with ArrayBuffer body 
+PASS Fetch with POST with Uint8Array body 
+PASS Fetch with POST with Int8Array body 
+PASS Fetch with POST with Float32Array body 
+PASS Fetch with POST with Float64Array body 
+PASS Fetch with POST with DataView body 
+PASS Fetch with POST with Blob body with mime type 
+

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/request-upload-worker.html (0 => 206632)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/request-upload-worker.html	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/request-upload-worker.html	2016-09-30 08:04:52 UTC (rev 206632)
@@ -0,0 +1,14 @@
+<!doctype html>
+<html>
+  <head>
+    <meta charset="utf-8">
+    <title>Fetch in worker: Upload</title>
+    <script src=""
+    <script src=""
+  </head>
+  <body>
+    <script>
+      fetch_tests_from_worker(new Worker("request-upload.js"));
+    </script>
+  </body>
+</html>

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/request-upload.html (0 => 206632)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/request-upload.html	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/request-upload.html	2016-09-30 08:04:52 UTC (rev 206632)
@@ -0,0 +1,13 @@
+<!doctype html>
+<html>
+  <head>
+    <meta charset="utf-8">
+    <title>Fetch: Uploading content</title>
+    <script src=""
+    <script src=""
+    <script src=""
+  </head>
+  <body>
+    <script src=""
+  </body>
+</html>

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/request-upload.js (0 => 206632)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/request-upload.js	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/request-upload.js	2016-09-30 08:04:52 UTC (rev 206632)
@@ -0,0 +1,35 @@
+if (this.document === undefined) {
+  importScripts("/resources/testharness.js");
+  importScripts("../resources/utils.js");
+}
+
+function testUpload(desc, url, method, body, expectedBody) {
+  var requestInit = {"method": method}
+  promise_test(function(test){
+    if (typeof body === "function")
+      body = body();
+    if (body)
+      requestInit["body"] = body;
+    return fetch(url, requestInit).then(function(resp) {
+      return resp.text().then((text)=> {
+        assert_equals(text, expectedBody);
+      });
+    });
+  }, desc);
+}
+
+var url = "" + "echo-content.py"
+
+testUpload("Fetch with PUT with body", url, "PUT", "Request's body", "Request's body");
+testUpload("Fetch with POST with text body", url, "POST", "Request's body", "Request's body");
+testUpload("Fetch with POST with URLSearchParams body", url, "POST", function() { return new URLSearchParams("name=value"); }, "name=value");
+testUpload("Fetch with POST with Blob body", url, "POST", new Blob(["Test"]), "Test");
+testUpload("Fetch with POST with ArrayBuffer body", url, "POST", new ArrayBuffer(4), "\0\0\0\0");
+testUpload("Fetch with POST with Uint8Array body", url, "POST", new Uint8Array(4), "\0\0\0\0");
+testUpload("Fetch with POST with Int8Array body", url, "POST", new Int8Array(4), "\0\0\0\0");
+testUpload("Fetch with POST with Float32Array body", url, "POST", new Float32Array(1), "\0\0\0\0");
+testUpload("Fetch with POST with Float64Array body", url, "POST", new Float64Array(1), "\0\0\0\0\0\0\0\0");
+testUpload("Fetch with POST with DataView body", url, "POST", new DataView(new ArrayBuffer(8), 0, 4), "\0\0\0\0");
+testUpload("Fetch with POST with Blob body with mime type", url, "POST", new Blob(["Test"], { type: "text/maybe" }), "Test");
+
+done();

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-consume-empty-expected.txt (206631 => 206632)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-consume-empty-expected.txt	2016-09-30 06:41:08 UTC (rev 206631)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-consume-empty-expected.txt	2016-09-30 08:04:52 UTC (rev 206632)
@@ -8,4 +8,7 @@
 PASS Consume empty text request body as arrayBuffer 
 PASS Consume empty blob request body as text 
 PASS Consume empty text request body as text 
+PASS Consume empty URLSearchParams request body as text 
+FAIL Consume empty FormData request body as text promise_test: Unhandled rejection with value: undefined
+PASS Consume empty ArrayBuffer request body as text 
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-consume-empty.html (206631 => 206632)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-consume-empty.html	2016-09-30 06:41:08 UTC (rev 206631)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-consume-empty.html	2016-09-30 08:04:52 UTC (rev 206632)
@@ -98,6 +98,9 @@
     checkRequestWithEmptyBody("text", "", false);
     checkRequestWithEmptyBody("blob", new Blob([], { "type" : "text/plain" }), true);
     checkRequestWithEmptyBody("text", "", true);
+    checkRequestWithEmptyBody("URLSearchParams", new URLSearchParams(""), true);
+    checkRequestWithEmptyBody("FormData", new FormData(), true);
+    checkRequestWithEmptyBody("ArrayBuffer", new ArrayBuffer(), true);
     </script>
   </body>
 </html>

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-init-002-expected.txt (206631 => 206632)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-init-002-expected.txt	2016-09-30 06:41:08 UTC (rev 206631)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-init-002-expected.txt	2016-09-30 08:04:52 UTC (rev 206632)
@@ -5,5 +5,5 @@
 PASS Initialize Request's body with application/octet-binary 
 FAIL Initialize Request's body with multipart/form-data promise_test: Unhandled rejection with value: undefined
 PASS Initialize Request's body with text/plain;charset=UTF-8 
-FAIL Initialize Request's body with application/x-www-form-urlencoded;charset=UTF-8 Type error
+PASS Initialize Request's body with application/x-www-form-urlencoded;charset=UTF-8 
 

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/resources/echo-content.py (0 => 206632)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/resources/echo-content.py	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/resources/echo-content.py	2016-09-30 08:04:52 UTC (rev 206632)
@@ -0,0 +1,9 @@
+def main(request, response):
+
+    headers = [("X-Request-Method", request.method),
+               ("X-Request-Content-Length", request.headers.get("Content-Length", "NO")),
+               ("X-Request-Content-Type", request.headers.get("Content-Type", "NO"))]
+
+    content = request.body
+
+    return headers, content

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-consume-empty-expected.txt (206631 => 206632)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-consume-empty-expected.txt	2016-09-30 06:41:08 UTC (rev 206631)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-consume-empty-expected.txt	2016-09-30 08:04:52 UTC (rev 206632)
@@ -8,4 +8,7 @@
 PASS Consume empty text response body as arrayBuffer 
 PASS Consume empty blob response body as text 
 PASS Consume empty text response body as text 
+PASS Consume empty URLSearchParams response body as text 
+FAIL Consume empty FormData response body as text promise_test: Unhandled rejection with value: undefined
+PASS Consume empty ArrayBuffer response body as text 
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-consume-empty.html (206631 => 206632)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-consume-empty.html	2016-09-30 06:41:08 UTC (rev 206631)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-consume-empty.html	2016-09-30 08:04:52 UTC (rev 206632)
@@ -93,11 +93,13 @@
       }, "Consume empty " + bodyType + " response body as " + (asText ? "text" : "arrayBuffer"));
     }
 
-    // FIXME: Add BufferSource, FormData and URLSearchParams.
     checkResponseWithEmptyBody("blob", new Blob([], { "type" : "text/plain" }), false);
     checkResponseWithEmptyBody("text", "", false);
     checkResponseWithEmptyBody("blob", new Blob([], { "type" : "text/plain" }), true);
     checkResponseWithEmptyBody("text", "", true);
+    checkResponseWithEmptyBody("URLSearchParams", new URLSearchParams(""), true);
+    checkResponseWithEmptyBody("FormData", new FormData(), true);
+    checkResponseWithEmptyBody("ArrayBuffer", new ArrayBuffer(), true);
     </script>
   </body>
 </html>

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-consume-expected.txt (206631 => 206632)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-consume-expected.txt	2016-09-30 06:41:08 UTC (rev 206631)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-consume-expected.txt	2016-09-30 08:04:52 UTC (rev 206632)
@@ -1,9 +1,12 @@
 
-PASS Consume response's body as text 
-PASS Consume response's body as blob 
-PASS Consume response's body as arrayBuffer 
-PASS Consume response's body as json 
-FAIL Consume response's body as formData promise_test: Unhandled rejection with value: "Not implemented"
+PASS Consume text response's body as text 
+PASS Consume text response's body as blob 
+PASS Consume text response's body as arrayBuffer 
+PASS Consume text response's body as json 
+FAIL Consume formdata response's body as formData promise_test: Unhandled rejection with value: "Not implemented"
+PASS Consume URLSearchParams response's body as text 
+PASS Consume URLSearchParams response's body as blob 
+PASS Consume URLSearchParams response's body as arrayBuffer 
 PASS Consume blob response's body as blob 
 PASS Consume blob response's body as text 
 PASS Consume blob response's body as json 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-consume-stream-expected.txt (206631 => 206632)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-consume-stream-expected.txt	2016-09-30 06:41:08 UTC (rev 206631)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-consume-stream-expected.txt	2016-09-30 08:04:52 UTC (rev 206632)
@@ -3,6 +3,7 @@
 PASS Read empty blob response's body as readableStream 
 PASS Read blob response's body as readableStream 
 PASS Read text response's body as readableStream 
+PASS Read text response's body as readableStream 
 PASS Read array buffer response's body as readableStream 
 FAIL Read form data response's body as readableStream promise_test: Unhandled rejection with value: "not implemented"
 PASS Getting an error Response stream 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-consume-stream.html (206631 => 206632)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-consume-stream.html	2016-09-30 06:41:08 UTC (rev 206631)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-consume-stream.html	2016-09-30 08:04:52 UTC (rev 206632)
@@ -28,6 +28,8 @@
 formData.append("name", "value");
 var textData = JSON.stringify("This is response's body");
 var blob = new Blob([textData], { "type" : "text/plain" });
+var urlSearchParamsData = "name=value";
+var urlSearchParams = new URLSearchParams(urlSearchParamsData);
 
 promise_test(function(test) {
     var response = new Response(blob);
@@ -40,6 +42,11 @@
 }, "Read text response's body as readableStream");
 
 promise_test(function(test) {
+    var response = new Response(urlSearchParams);
+    return validateStreamFromString(response.body.getReader(), urlSearchParamsData);
+}, "Read text response's body as readableStream");
+
+promise_test(function(test) {
     var arrayBuffer = new ArrayBuffer(textData.length);
     var int8Array = new Int8Array(arrayBuffer);
     for (var cptr = 0; cptr < textData.length; cptr++)

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-consume.html (206631 => 206632)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-consume.html	2016-09-30 06:41:08 UTC (rev 206631)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-consume.html	2016-09-30 08:04:52 UTC (rev 206632)
@@ -63,12 +63,12 @@
      });
     }
 
-    function checkResponseBody(body, bodyType, checkFunction) {
+    function checkResponseBody(body, bodyType, bodyConsumingType, checkFunction) {
       promise_test(function(test) {
         var response = new Response(body, { "headers": [["Content-Type", "text/PLAIN"]] });
         assert_false(response.bodyUsed, "bodyUsed is false at init");
         return checkFunction(response, body);
-      }, "Consume response's body as " + bodyType);
+      }, "Consume " + bodyType + " response's body as " + bodyConsumingType);
     }
 
     var formData = new FormData();
@@ -75,12 +75,17 @@
     formData.append("name", "value");
     var textData = JSON.stringify("This is response's body");
     var blob = new Blob([textData], { "type" : "text/plain" });
+    var urlSearchParamsData = "name=value";
+    var urlSearchParams = new URLSearchParams(urlSearchParamsData);
 
-    checkResponseBody(textData, "text", checkBodyText);
-    checkResponseBody(textData, "blob", function(response, body) { checkBodyBlob(response, body, true); });
-    checkResponseBody(textData, "arrayBuffer", checkBodyArrayBuffer);
-    checkResponseBody(textData, "json", checkBodyJSON);
-    checkResponseBody(formData, "formData", checkBodyFormData);
+    checkResponseBody(textData, "text", "text", checkBodyText);
+    checkResponseBody(textData, "text", "blob", function(response, body) { checkBodyBlob(response, body, true); });
+    checkResponseBody(textData, "text", "arrayBuffer", checkBodyArrayBuffer);
+    checkResponseBody(textData, "text", "json", checkBodyJSON);
+    checkResponseBody(formData, "formdata", "formData", checkBodyFormData);
+    checkResponseBody(urlSearchParams, "URLSearchParams", "text", function(response) { checkBodyText(response, urlSearchParams); });
+    checkResponseBody(urlSearchParams, "URLSearchParams", "blob", function(response, body) { checkBodyBlob(response, urlSearchParamsData, false); });
+    checkResponseBody(urlSearchParams, "URLSearchParams", "arrayBuffer", function(response) { checkBodyArrayBuffer(response, urlSearchParamsData); });
 
     function checkBlobResponseBody(blobBody, blobData, bodyType, checkFunction) {
       promise_test(function(test) {

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-init-002-expected.txt (206631 => 206632)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-init-002-expected.txt	2016-09-30 06:41:08 UTC (rev 206631)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-init-002-expected.txt	2016-09-30 08:04:52 UTC (rev 206632)
@@ -2,7 +2,7 @@
 PASS Initialize Response with headers values 
 PASS Initialize Response's body with application/octet-binary 
 FAIL Initialize Response's body with multipart/form-data promise_test: Unhandled rejection with value: undefined
-FAIL Initialize Response's body with application/x-www-form-urlencoded;charset=UTF-8 assert_true: Content-Type header should be "application/x-www-form-urlencoded;charset=UTF-8"  expected true got null
+PASS Initialize Response's body with application/x-www-form-urlencoded;charset=UTF-8 
 PASS Initialize Response's body with text/plain;charset=UTF-8 
 PASS Read Response's body as readableStream 
 PASS Testing empty Response Content-Type header 

Modified: trunk/Source/WebCore/ChangeLog (206631 => 206632)


--- trunk/Source/WebCore/ChangeLog	2016-09-30 06:41:08 UTC (rev 206631)
+++ trunk/Source/WebCore/ChangeLog	2016-09-30 08:04:52 UTC (rev 206632)
@@ -1,3 +1,28 @@
+2016-09-30  Youenn Fablet  <[email protected]>
+
+        [Fetch API] Add support for URLSearchParams body
+        https://bugs.webkit.org/show_bug.cgi?id=162667
+
+        Reviewed by Alex Christensen.
+
+        Tests: imported/w3c/web-platform-tests/fetch/api/basic/request-upload-worker.html
+               imported/w3c/web-platform-tests/fetch/api/basic/request-upload.html
+
+        * Modules/fetch/FetchBody.cpp:
+        (WebCore::extractBytesFromText): Moving to a static function that should be moved to a String method.
+        (WebCore::FetchBody::FetchBody): Adding constructor for URLSearchParams.
+        (WebCore::FetchBody::extract): Adding URLSearchParams body initialization.
+        (WebCore::FetchBody::consume): Consuming URLSearchParams bodies.
+        (WebCore::FetchBody::consumeAsStream): Ditto.
+        (WebCore::FetchBody::consumeText): Updated to take a parameter to handle both text and URLSearchParams bodies.
+        (WebCore::FetchBody::bodyForInternalRequest): Add URLSearchParams body upload.
+        (WebCore::FetchBody::clone): Add URLSearchParams body cloning
+        * Modules/fetch/FetchBody.h:
+        (WebCore::FetchBody::urlSearchParamsBody):
+        * html/URLSearchParams.cpp:
+        (WebCore::URLSearchParams::toString):
+        * html/URLSearchParams.h:
+
 2016-09-29  Simon Fraser  <[email protected]>
 
         Re-order the arguments to drawPattern() functions

Modified: trunk/Source/WebCore/Modules/fetch/FetchBody.cpp (206631 => 206632)


--- trunk/Source/WebCore/Modules/fetch/FetchBody.cpp	2016-09-30 06:41:08 UTC (rev 206631)
+++ trunk/Source/WebCore/Modules/fetch/FetchBody.cpp	2016-09-30 08:04:52 UTC (rev 206632)
@@ -41,11 +41,21 @@
 #include "JSBlob.h"
 #include "JSDOMFormData.h"
 #include "JSReadableStream.h"
+#include "JSURLSearchParams.h"
 #include "ReadableStreamSource.h"
 #include <runtime/ArrayBufferView.h>
 
 namespace WebCore {
 
+// FIXME: This implementation is not efficient and we should probably use UTF8Encoding().
+static Vector<uint8_t> extractBytesFromText(const String& text)
+{
+    CString data = ""
+    Vector<uint8_t> value(data.length());
+    memcpy(value.data(), data.data(), data.length());
+    return value;
+}
+
 FetchBody::FetchBody(Ref<const Blob>&& blob)
     : m_type(Type::Blob)
     , m_data(WTFMove(blob))
@@ -79,6 +89,13 @@
 {
 }
 
+FetchBody::FetchBody(Ref<const URLSearchParams>&& url)
+    : m_type(Type::URLSeachParams)
+    , m_data(WTFMove(url))
+    , m_contentType(ASCIILiteral("application/x-www-form-urlencoded;charset=UTF-8"))
+{
+}
+
 FetchBody::FetchBody(Type type, const String& contentType, const FetchBodyConsumer& consumer)
     : m_type(type)
     , m_contentType(contentType)
@@ -96,6 +113,8 @@
     }
     if (value.isString())
         return FetchBody(value.toWTFString(&state));
+    if (value.inherits(JSURLSearchParams::info()))
+        return FetchBody(*JSURLSearchParams::toWrapped(value));
     if (value.inherits(JSReadableStream::info()))
         return { Type::ReadableStream };
     if (value.inherits(JSC::JSArrayBuffer::info())) {
@@ -185,8 +204,11 @@
         consumeArrayBufferView(WTFMove(promise));
         return;
     case Type::Text:
-        consumeText(WTFMove(promise));
+        consumeText(WTFMove(promise), textBody());
         return;
+    case Type::URLSeachParams:
+        consumeText(WTFMove(promise), urlSearchParamsBody().toString());
+        return;
     case Type::Blob:
         consumeBlob(owner, WTFMove(promise));
         return;
@@ -225,11 +247,17 @@
         break;
     }
     case Type::Text: {
-        Vector<uint8_t> data = ""
+        Vector<uint8_t> data = ""
         closeStream = source.enqueue(ArrayBuffer::tryCreate(data.data(), data.size()));
         m_data = nullptr;
         break;
     }
+    case Type::URLSeachParams: {
+        Vector<uint8_t> data = ""
+        closeStream = source.enqueue(ArrayBuffer::tryCreate(data.data(), data.size()));
+        m_data = nullptr;
+        break;
+    }
     case Type::Blob:
         owner.loadBlob(blobBody(), nullptr);
         m_data = nullptr;
@@ -262,9 +290,9 @@
     m_data = nullptr;
 }
 
-void FetchBody::consumeText(Ref<DeferredPromise>&& promise)
+void FetchBody::consumeText(Ref<DeferredPromise>&& promise, const String& text)
 {
-    Vector<uint8_t> data = ""
+    Vector<uint8_t> data = ""
     m_consumer.resolveWithData(WTFMove(promise), data.data(), data.size());
     m_data = nullptr;
 }
@@ -276,16 +304,6 @@
     m_data = nullptr;
 }
 
-Vector<uint8_t> FetchBody::extractFromText() const
-{
-    ASSERT(m_type == Type::Text);
-    // FIXME: This double allocation is not efficient. Might want to fix that at WTFString level.
-    CString data = ""
-    Vector<uint8_t> value(data.length());
-    memcpy(value.data(), data.data(), data.length());
-    return value;
-}
-
 void FetchBody::loadingFailed()
 {
     if (m_consumePromise) {
@@ -308,6 +326,8 @@
         return nullptr;
     case Type::Text:
         return FormData::create(UTF8Encoding().encode(textBody(), EntitiesForUnencodables));
+    case Type::URLSeachParams:
+        return FormData::create(UTF8Encoding().encode(urlSearchParamsBody().toString(), EntitiesForUnencodables));
     case Type::Blob: {
         RefPtr<FormData> body = FormData::create();
         body->appendBlob(blobBody().url());
@@ -350,6 +370,9 @@
     case Type::Text:
         clone.m_data = textBody();
         break;
+    case Type::URLSeachParams:
+        clone.m_data = urlSearchParamsBody();
+        break;
     case Type::Loaded:
     case Type::None:
     case Type::Loading:

Modified: trunk/Source/WebCore/Modules/fetch/FetchBody.h (206631 => 206632)


--- trunk/Source/WebCore/Modules/fetch/FetchBody.h	2016-09-30 06:41:08 UTC (rev 206631)
+++ trunk/Source/WebCore/Modules/fetch/FetchBody.h	2016-09-30 08:04:52 UTC (rev 206632)
@@ -36,6 +36,7 @@
 #include "FetchLoader.h"
 #include "FormData.h"
 #include "JSDOMPromise.h"
+#include "URLSearchParams.h"
 #include <wtf/Variant.h>
 
 namespace JSC {
@@ -79,7 +80,7 @@
 
     RefPtr<FormData> bodyForInternalRequest(ScriptExecutionContext&) const;
 
-    enum class Type { None, ArrayBuffer, ArrayBufferView, Blob, FormData, Text, Loading, Loaded, ReadableStream };
+    enum class Type { None, ArrayBuffer, ArrayBufferView, Blob, FormData, Text, URLSeachParams, Loading, Loaded, ReadableStream };
     Type type() const { return m_type; }
 
     FetchBodyConsumer& consumer() { return m_consumer; }
@@ -94,15 +95,15 @@
     FetchBody(Ref<const ArrayBufferView>&&);
     FetchBody(DOMFormData&, Document&);
     FetchBody(String&&);
+    FetchBody(Ref<const URLSearchParams>&&);
     FetchBody(Type, const String&, const FetchBodyConsumer&);
     FetchBody(Type type) : m_type(type) { }
 
     void consume(FetchBodyOwner&, Ref<DeferredPromise>&&);
 
-    Vector<uint8_t> extractFromText() const;
     void consumeArrayBuffer(Ref<DeferredPromise>&&);
     void consumeArrayBufferView(Ref<DeferredPromise>&&);
-    void consumeText(Ref<DeferredPromise>&&);
+    void consumeText(Ref<DeferredPromise>&&, const String&);
     void consumeBlob(FetchBodyOwner&, Ref<DeferredPromise>&&);
 
     const Blob& blobBody() const { return std::experimental::get<Ref<const Blob>>(m_data).get(); }
@@ -112,11 +113,11 @@
     const ArrayBufferView& arrayBufferViewBody() const { return std::experimental::get<Ref<const ArrayBufferView>>(m_data).get(); }
     String& textBody() { return std::experimental::get<String>(m_data); }
     const String& textBody() const { return std::experimental::get<String>(m_data); }
+    const URLSearchParams& urlSearchParamsBody() const { return std::experimental::get<Ref<const URLSearchParams>>(m_data).get(); }
 
     Type m_type { Type::None };
 
-    // FIXME: Add support for URLSearchParams.
-    std::experimental::variant<std::nullptr_t, Ref<const Blob>, Ref<FormData>, Ref<const ArrayBuffer>, Ref<const ArrayBufferView>, String> m_data;
+    std::experimental::variant<std::nullptr_t, Ref<const Blob>, Ref<FormData>, Ref<const ArrayBuffer>, Ref<const ArrayBufferView>, Ref<const URLSearchParams>, String> m_data;
     String m_contentType;
 
     FetchBodyConsumer m_consumer { FetchBodyConsumer::Type::None };

Modified: trunk/Source/WebCore/html/URLSearchParams.cpp (206631 => 206632)


--- trunk/Source/WebCore/html/URLSearchParams.cpp	2016-09-30 06:41:08 UTC (rev 206631)
+++ trunk/Source/WebCore/html/URLSearchParams.cpp	2016-09-30 08:04:52 UTC (rev 206632)
@@ -106,7 +106,7 @@
         updateURL();
 }
 
-String URLSearchParams::toString()
+String URLSearchParams::toString() const
 {
     return URLParser::serialize(m_pairs);
 }

Modified: trunk/Source/WebCore/html/URLSearchParams.h (206631 => 206632)


--- trunk/Source/WebCore/html/URLSearchParams.h	2016-09-30 06:41:08 UTC (rev 206631)
+++ trunk/Source/WebCore/html/URLSearchParams.h	2016-09-30 08:04:52 UTC (rev 206632)
@@ -42,7 +42,7 @@
     Vector<String> getAll(const String& name) const;
     bool has(const String& name) const;
     void set(const String& name, const String& value);
-    String toString();
+    String toString() const;
     operator const Vector<std::pair<String, String>>&() { return m_pairs; }
     void updateFromAssociatedURL();
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to