[Fetch API] ReadableStream should be errored with TypeError values
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 4 Oct 2016 15:17:34 +0000 (15:17 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 4 Oct 2016 15:17:34 +0000 (15:17 +0000)
https://bugs.webkit.org/show_bug.cgi?id=162895

Patch by Youenn Fablet <youenn@apple.com> on 2016-10-04
Reviewed by Alex Christensen.

LayoutTests/imported/w3c:

* web-platform-tests/fetch/api/basic/error-after-response-expected.txt: Added.
* web-platform-tests/fetch/api/basic/error-after-response.html: Added.
* web-platform-tests/fetch/api/resources/bad-chunk-encoding.py: Added.
(main):
* web-platform-tests/fetch/api/response/response-consume-stream-expected.txt:

Source/WebCore:

Test: imported/w3c/web-platform-tests/fetch/api/basic/error-after-response.html

* Modules/fetch/FetchResponse.cpp:
(WebCore::FetchResponse::BodyLoader::didFail): Removing FIXME.
* bindings/js/ReadableStreamDefaultController.h:
(WebCore::ReadableStreamDefaultController::error<String>): Erroring with TypeError values.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@206770 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/imported/w3c/ChangeLog
LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/error-after-response-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/error-after-response.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/fetch/api/resources/bad-chunk-encoding.py [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-consume-stream-expected.txt
Source/WebCore/ChangeLog
Source/WebCore/Modules/fetch/FetchResponse.cpp
Source/WebCore/bindings/js/ReadableStreamDefaultController.h

index 5be906b..0c39dd4 100644 (file)
@@ -1,3 +1,16 @@
+2016-10-04  Youenn Fablet  <youenn@apple.com>
+
+        [Fetch API] ReadableStream should be errored with TypeError values
+        https://bugs.webkit.org/show_bug.cgi?id=162895
+
+        Reviewed by Alex Christensen.
+
+        * web-platform-tests/fetch/api/basic/error-after-response-expected.txt: Added.
+        * web-platform-tests/fetch/api/basic/error-after-response.html: Added.
+        * web-platform-tests/fetch/api/resources/bad-chunk-encoding.py: Added.
+        (main):
+        * web-platform-tests/fetch/api/response/response-consume-stream-expected.txt:
+
 2016-10-03  Chris Dumez  <cdumez@apple.com>
 
         Add support for KeyboardEvent.key attribute
diff --git a/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/error-after-response-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/error-after-response-expected.txt
new file mode 100644 (file)
index 0000000..a6eb10a
--- /dev/null
@@ -0,0 +1,4 @@
+
+PASS Response reader read() promise should reject after a network error happening after resolving fetch promise 
+PASS Response reader closed promise should reject after a network error happening after resolving fetch promise 
+
diff --git a/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/error-after-response.html b/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/error-after-response.html
new file mode 100644 (file)
index 0000000..c42d55e
--- /dev/null
@@ -0,0 +1,34 @@
+<!doctype html>
+<html>
+  <head>
+    <title>Fetch: network timeout after receiving the HTTP response headers</title>
+    <script src="/resources/testharness.js"></script>
+    <script src="/resources/testharnessreport.js"></script>
+    <script src="../resources/utils.js"></script>
+  </head>
+  <body>
+    <div id="log"></div>
+    <script>
+function checkReader(test, reader, checkRead)
+{
+    return reader.read().then((value) => {
+        validateBufferFromString(value.value, "TEST_CHUNK", "Should receive first chunk");
+        return promise_rejects(test, new TypeError(), checkRead ? reader.read() : reader.closed);
+    });
+}
+
+promise_test((test) => {
+    return fetch("../resources/bad-chunk-encoding.py?count=1").then((response) => {
+        return checkReader(test, response.body.getReader(), true);
+    });
+}, "Response reader read() promise should reject after a network error happening after resolving fetch promise");
+
+promise_test((test) => {
+    return fetch("../resources/bad-chunk-encoding.py?count=1").then((response) => {
+        return checkReader(test, response.body.getReader(), false);
+    });
+}, "Response reader closed promise should reject after a network error happening after resolving fetch promise");
+    </script>
+  </body>
+</html>
+
diff --git a/LayoutTests/imported/w3c/web-platform-tests/fetch/api/resources/bad-chunk-encoding.py b/LayoutTests/imported/w3c/web-platform-tests/fetch/api/resources/bad-chunk-encoding.py
new file mode 100644 (file)
index 0000000..d7a7503
--- /dev/null
@@ -0,0 +1,14 @@
+import time
+
+def main(request, response):
+    delay = float(request.GET.first("ms", 1000)) / 1E3
+    count = int(request.GET.first("count", 50))
+    time.sleep(delay)
+    response.headers.set("Transfer-Encoding", "chunked")
+    response.write_status_headers()
+    time.sleep(delay);
+    for i in xrange(count):
+        response.writer.write_content("a\r\nTEST_CHUNK\r\n")
+        time.sleep(delay)
+    response.writer.write_content("garbage")
+
index f9d7ab2..124cdcc 100644 (file)
@@ -5,7 +5,7 @@ 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"
+FAIL Read form data response's body as readableStream promise_test: Unhandled rejection with value: object "TypeError: not implemented"
 PASS Getting an error Response stream 
 PASS Getting a redirect Response stream 
 
index f6fd647..15933bd 100644 (file)
@@ -1,3 +1,17 @@
+2016-10-04  Youenn Fablet  <youenn@apple.com>
+
+        [Fetch API] ReadableStream should be errored with TypeError values
+        https://bugs.webkit.org/show_bug.cgi?id=162895
+
+        Reviewed by Alex Christensen.
+
+        Test: imported/w3c/web-platform-tests/fetch/api/basic/error-after-response.html
+
+        * Modules/fetch/FetchResponse.cpp:
+        (WebCore::FetchResponse::BodyLoader::didFail): Removing FIXME.
+        * bindings/js/ReadableStreamDefaultController.h:
+        (WebCore::ReadableStreamDefaultController::error<String>): Erroring with TypeError values.
+
 2016-10-03  Chris Dumez  <cdumez@apple.com>
 
         Bindings do not throw a TypeError if a required dictionary member is missing
index 333ede1..83a98fd 100644 (file)
@@ -159,8 +159,6 @@ void FetchResponse::BodyLoader::didFail()
     if (m_loader->isStarted())
         m_response.m_bodyLoader = Nullopt;
 
-    // FIXME: Handle the case of failing after didReceiveResponse is called.
-
     m_response.unsetPendingActivity(&m_response);
 }
 
index 5a0b6b8..aa8e316 100644 (file)
@@ -108,11 +108,11 @@ inline bool ReadableStreamDefaultController::enqueue(RefPtr<JSC::ArrayBuffer>&&
 }
 
 template<>
-inline void ReadableStreamDefaultController::error<String>(const String& result)
+inline void ReadableStreamDefaultController::error<String>(const String& errorMessage)
 {
     JSC::ExecState& state = globalExec();
     JSC::JSLockHolder locker(&state);
-    error(state, jsString(&state, result));
+    error(state, JSC::createTypeError(&state, errorMessage));
 }
 
 } // namespace WebCore