[Fetch API] Fetch promises should not reject or resolve when ActiveDOMObjects are...
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 2 Aug 2016 08:07:28 +0000 (08:07 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 2 Aug 2016 08:07:28 +0000 (08:07 +0000)
https://bugs.webkit.org/show_bug.cgi?id=160420

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

LayoutTests/imported/w3c:

* web-platform-tests/fetch/api/cors/cors-preflight-redirect-worker-expected.txt: Added.
* web-platform-tests/fetch/nosniff/worker-expected.txt: Added.

Source/WebCore:

Test: http/tests/fetch/fetch-in-worker-crash.html

Promises should not be rejected when FetchResponse/FetchRequest are stopped as ActiveDOMObject.

* Modules/fetch/FetchBody.h:
(WebCore::FetchBody::cleanConsumePromise): Allowing to nullify the promise used to consume body.
* Modules/fetch/FetchBodyOwner.cpp:
(WebCore::FetchBodyOwner::stop): Nullifying the body consume promise if any.
* Modules/fetch/FetchResponse.cpp:
(WebCore::FetchResponse::BodyLoader::stop): Nullifying the fetch promise if any.

LayoutTests:

* TestExpectations:
* http/tests/fetch/fetch-in-worker-crash-expected.txt: Added.
* http/tests/fetch/fetch-in-worker-crash.html: Added.
* http/tests/fetch/fetch-in-worker.js: Added.
(onmessage):
* platform/ios-simulator-wk2/imported/w3c/web-platform-tests/fetch/api/cors/cors-basic-worker-expected.txt:

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

13 files changed:
LayoutTests/ChangeLog
LayoutTests/TestExpectations
LayoutTests/http/tests/fetch/fetch-in-worker-crash-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/fetch/fetch-in-worker-crash.html [new file with mode: 0644]
LayoutTests/http/tests/fetch/fetch-in-worker.js [new file with mode: 0644]
LayoutTests/imported/w3c/ChangeLog
LayoutTests/imported/w3c/web-platform-tests/fetch/api/cors/cors-preflight-redirect-worker-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/fetch/nosniff/worker-expected.txt [new file with mode: 0644]
LayoutTests/platform/ios-simulator-wk2/imported/w3c/web-platform-tests/fetch/api/cors/cors-basic-worker-expected.txt
Source/WebCore/ChangeLog
Source/WebCore/Modules/fetch/FetchBody.h
Source/WebCore/Modules/fetch/FetchBodyOwner.cpp
Source/WebCore/Modules/fetch/FetchResponse.cpp

index 0566513..6780de5 100644 (file)
@@ -1,3 +1,17 @@
+2016-08-02  Youenn Fablet  <youenn@apple.com>
+
+        [Fetch API] Fetch promises should not reject or resolve when ActiveDOMObjects are being stopped
+        https://bugs.webkit.org/show_bug.cgi?id=160420
+
+        Reviewed by Alex Christensen.
+
+        * TestExpectations:
+        * http/tests/fetch/fetch-in-worker-crash-expected.txt: Added.
+        * http/tests/fetch/fetch-in-worker-crash.html: Added.
+        * http/tests/fetch/fetch-in-worker.js: Added.
+        (onmessage):
+        * platform/ios-simulator-wk2/imported/w3c/web-platform-tests/fetch/api/cors/cors-basic-worker-expected.txt:
+
 2016-08-01  Tim Horton  <timothy_horton@apple.com>
 
         <attachment> action label doesn't wrap, but needs to for some localizations
index 79773ec..c8cf2d1 100644 (file)
@@ -337,30 +337,10 @@ imported/w3c/web-platform-tests/XMLHttpRequest/send-redirect-to-cors.htm [ Skip
 imported/w3c/web-platform-tests/XMLHttpRequest/send-redirect-to-non-cors.htm [ Skip ]
 # Failing assertion with dynamic message
 imported/w3c/web-platform-tests/XMLHttpRequest/responsexml-document-properties.htm [ Failure ]
-# Fetch Worker tests skipped until bug 156737 is resolved
-imported/w3c/web-platform-tests/fetch/api/cors/cors-basic-worker.html [ Skip ]
-imported/w3c/web-platform-tests/fetch/api/cors/cors-cookies-worker.html [ Skip ]
-imported/w3c/web-platform-tests/fetch/api/cors/cors-filtering-worker.html [ Skip ]
-imported/w3c/web-platform-tests/fetch/api/cors/cors-multiple-origins-worker.html [ Skip ]
-imported/w3c/web-platform-tests/fetch/api/cors/cors-no-preflight-worker.html [ Skip ]
-imported/w3c/web-platform-tests/fetch/api/cors/cors-origin-worker.html [ Skip ]
-imported/w3c/web-platform-tests/fetch/api/cors/cors-preflight-redirect-worker.html [ Skip ]
-imported/w3c/web-platform-tests/fetch/api/cors/cors-preflight-referrer-worker.html [ Skip ]
-imported/w3c/web-platform-tests/fetch/api/cors/cors-preflight-status-worker.html [ Skip ]
-imported/w3c/web-platform-tests/fetch/api/cors/cors-preflight-worker.html [ Skip ]
-imported/w3c/web-platform-tests/fetch/api/cors/cors-redirect-credentials-worker.html [ Skip ]
-imported/w3c/web-platform-tests/fetch/api/cors/cors-redirect-worker.html [ Skip ]
-imported/w3c/web-platform-tests/fetch/api/credentials/authentication-basic-worker.html [ Skip ]
-imported/w3c/web-platform-tests/fetch/api/credentials/cookies-worker.html [ Skip ]
-imported/w3c/web-platform-tests/fetch/api/policies/csp-blocked-worker.html [ Skip ]
-imported/w3c/web-platform-tests/fetch/api/policies/referrer-no-referrer-worker.html [ Skip ]
-imported/w3c/web-platform-tests/fetch/api/policies/referrer-origin-worker.html [ Skip ]
-imported/w3c/web-platform-tests/fetch/api/policies/referrer-unsafe-url-worker.html [ Skip ]
-imported/w3c/web-platform-tests/fetch/api/redirect/redirect-count-worker.html [ Skip ]
-imported/w3c/web-platform-tests/fetch/api/redirect/redirect-location-worker.html [ Skip ]
-imported/w3c/web-platform-tests/fetch/api/redirect/redirect-method-worker.html [ Skip ]
-imported/w3c/web-platform-tests/fetch/api/redirect/redirect-mode-worker.html [ Skip ]
-imported/w3c/web-platform-tests/fetch/nosniff/worker.html [ Skip ]
+
+imported/w3c/web-platform-tests/fetch/api/cors/cors-cookies-worker.html [ Crash Failure Pass ]
+[ Debug ] imported/w3c/web-platform-tests/fetch/api/redirect/redirect-count-worker.html [ Crash Pass ]
+imported/w3c/web-platform-tests/fetch/api/request/request-cache.html [ Skip ]
 
 webkit.org/b/157068 imported/w3c/web-platform-tests/fetch/nosniff/importscripts.html [ Skip ]
 webkit.org/b/157145 imported/w3c/web-platform-tests/fetch/nosniff/stylesheet.html [ Failure Pass ]
diff --git a/LayoutTests/http/tests/fetch/fetch-in-worker-crash-expected.txt b/LayoutTests/http/tests/fetch/fetch-in-worker-crash-expected.txt
new file mode 100644 (file)
index 0000000..34480c1
--- /dev/null
@@ -0,0 +1,5 @@
+CONSOLE MESSAGE: line 11: 0
+CONSOLE MESSAGE: line 11: 1
+Test that terminating an ongoing fetch in a worker does not cause a crash.
+
+PASS: No crash.
diff --git a/LayoutTests/http/tests/fetch/fetch-in-worker-crash.html b/LayoutTests/http/tests/fetch/fetch-in-worker-crash.html
new file mode 100644 (file)
index 0000000..0f60e1e
--- /dev/null
@@ -0,0 +1,25 @@
+<body>
+<p>Test that terminating an ongoing fetch in a worker does not cause a crash.</p> <script>
+    if (testRunner) {
+        testRunner.dumpAsText();
+        testRunner.waitUntilDone();
+    }
+
+    worker = new Worker("fetch-in-worker.js");
+
+    worker.onmessage = function(e) {
+        console.log(e.data);
+        if (e.data == 0) {
+            worker.postMessage("start");
+        } else {
+            worker.terminate();
+            setTimeout(() => {
+                document.body.innerHTML += "<p>PASS: No crash.</p>";
+                if (testRunner)
+                    testRunner.notifyDone();
+            }, 100);
+        }
+    };
+    worker.postMessage("start");
+</script>
+</body>
diff --git a/LayoutTests/http/tests/fetch/fetch-in-worker.js b/LayoutTests/http/tests/fetch/fetch-in-worker.js
new file mode 100644 (file)
index 0000000..17db6e7
--- /dev/null
@@ -0,0 +1,19 @@
+var counter = 0;
+onmessage = function(e) {
+    if (e.data !== "start")
+        return;
+
+    var promise1 = fetch("detached-frame.html").then(() => {
+        postMessage("FAIL: promise 1 resolved");
+    }, () => {
+        postMessage("FAIL: promise 1 rejected");
+    });
+
+    var promise2 = new Request("test", {method: "POST", body: new Blob(["ab"])}).text().then(() => {
+        postMessage("FAIL: promise 2 resolved");
+    }, () => {
+        postMessage("FAIL: promise 2 rejected");
+    });
+
+    postMessage(counter++);
+}
index e87867d..51f6e73 100644 (file)
@@ -1,5 +1,15 @@
 2016-08-02  Youenn Fablet  <youenn@apple.com>
 
+        [Fetch API] Fetch promises should not reject or resolve when ActiveDOMObjects are being stopped
+        https://bugs.webkit.org/show_bug.cgi?id=160420
+
+        Reviewed by Alex Christensen.
+
+        * web-platform-tests/fetch/api/cors/cors-preflight-redirect-worker-expected.txt: Added.
+        * web-platform-tests/fetch/nosniff/worker-expected.txt: Added.
+
+2016-08-02  Youenn Fablet  <youenn@apple.com>
+
         [Fetch API] Add support to ReferrerPolicy
         https://bugs.webkit.org/show_bug.cgi?id=160404
 
diff --git a/LayoutTests/imported/w3c/web-platform-tests/fetch/api/cors/cors-preflight-redirect-worker-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/fetch/api/cors/cors-preflight-redirect-worker-expected.txt
new file mode 100644 (file)
index 0000000..bee76bb
--- /dev/null
@@ -0,0 +1,12 @@
+
+PASS Redirection 301 on preflight failed 
+PASS Redirection 301 after preflight failed 
+PASS Redirection 302 on preflight failed 
+PASS Redirection 302 after preflight failed 
+PASS Redirection 303 on preflight failed 
+PASS Redirection 303 after preflight failed 
+PASS Redirection 307 on preflight failed 
+PASS Redirection 307 after preflight failed 
+PASS Redirection 308 on preflight failed 
+PASS Redirection 308 after preflight failed 
+
diff --git a/LayoutTests/imported/w3c/web-platform-tests/fetch/nosniff/worker-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/fetch/nosniff/worker-expected.txt
new file mode 100644 (file)
index 0000000..8c8b3bc
--- /dev/null
@@ -0,0 +1,9 @@
+
+FAIL URL query:  assert_unreached: Unexpected message event Reached unreachable code
+FAIL URL query: ?type= assert_unreached: Unexpected message event Reached unreachable code
+FAIL URL query: ?type=x assert_unreached: Unexpected message event Reached unreachable code
+FAIL URL query: ?type=x/x assert_unreached: Unexpected message event Reached unreachable code
+PASS URL query: ?type=text/javascript 
+PASS URL query: ?type=text/ecmascript 
+PASS URL query: ?type=text/ecmascript;yay 
+
index a8a822a..3e46cf6 100644 (file)
@@ -1,16 +1,16 @@
 
-FAIL Same domain different port [no-cors mode] assert_equals: Opaque filter: status is 0 expected 0 but got 200
+PASS Same domain different port [no-cors mode] 
 PASS Same domain different port [server forbid CORS] 
-FAIL Same domain different port [cors mode] assert_equals: CORS response's type is cors expected "cors" but got "basic"
+PASS Same domain different port [cors mode] 
 FAIL Same domain different protocol different port [no-cors mode] promise_test: Unhandled rejection with value: object "TypeError: Type error"
 PASS Same domain different protocol different port [server forbid CORS] 
 FAIL Same domain different protocol different port [cors mode] promise_test: Unhandled rejection with value: object "TypeError: Type error"
-FAIL Cross domain basic usage [no-cors mode] assert_equals: Opaque filter: status is 0 expected 0 but got 200
+PASS Cross domain basic usage [no-cors mode] 
 PASS Cross domain basic usage [server forbid CORS] 
-FAIL Cross domain basic usage [cors mode] assert_equals: CORS response's type is cors expected "cors" but got "basic"
-FAIL Cross domain different port [no-cors mode] assert_equals: Opaque filter: status is 0 expected 0 but got 200
+PASS Cross domain basic usage [cors mode] 
+PASS Cross domain different port [no-cors mode] 
 PASS Cross domain different port [server forbid CORS] 
-FAIL Cross domain different port [cors mode] assert_equals: CORS response's type is cors expected "cors" but got "basic"
+PASS Cross domain different port [cors mode] 
 FAIL Cross domain different protocol [no-cors mode] promise_test: Unhandled rejection with value: object "TypeError: Type error"
 PASS Cross domain different protocol [server forbid CORS] 
 FAIL Cross domain different protocol [cors mode] promise_test: Unhandled rejection with value: object "TypeError: Type error"
index a5ef5bb..dd865d6 100644 (file)
@@ -1,5 +1,23 @@
 2016-08-02  Youenn Fablet  <youenn@apple.com>
 
+        [Fetch API] Fetch promises should not reject or resolve when ActiveDOMObjects are being stopped
+        https://bugs.webkit.org/show_bug.cgi?id=160420
+
+        Reviewed by Alex Christensen.
+
+        Test: http/tests/fetch/fetch-in-worker-crash.html
+
+        Promises should not be rejected when FetchResponse/FetchRequest are stopped as ActiveDOMObject.
+
+        * Modules/fetch/FetchBody.h:
+        (WebCore::FetchBody::cleanConsumePromise): Allowing to nullify the promise used to consume body.
+        * Modules/fetch/FetchBodyOwner.cpp:
+        (WebCore::FetchBodyOwner::stop): Nullifying the body consume promise if any.
+        * Modules/fetch/FetchResponse.cpp:
+        (WebCore::FetchResponse::BodyLoader::stop): Nullifying the fetch promise if any.
+
+2016-08-02  Youenn Fablet  <youenn@apple.com>
+
         [Fetch API] Add support to ReferrerPolicy
         https://bugs.webkit.org/show_bug.cgi?id=160404
 
index 62d9e5a..4cab391 100644 (file)
@@ -80,6 +80,8 @@ public:
 
     FetchBodyConsumer& consumer() { return m_consumer; }
 
+    void cleanConsumePromise() { m_consumePromise = Nullopt; }
+
 private:
     FetchBody(Ref<Blob>&&);
     FetchBody(Ref<DOMFormData>&&);
index 964be77..c6b7175 100644 (file)
@@ -48,6 +48,8 @@ FetchBodyOwner::FetchBodyOwner(ScriptExecutionContext& context, FetchBody&& body
 
 void FetchBodyOwner::stop()
 {
+    m_body.cleanConsumePromise();
+
     if (m_blobLoader) {
         if (m_blobLoader->loader)
             m_blobLoader->loader->stop();
index 6738fa3..3cc78be 100644 (file)
@@ -197,6 +197,7 @@ bool FetchResponse::BodyLoader::start(ScriptExecutionContext& context, const Fet
 
 void FetchResponse::BodyLoader::stop()
 {
+    m_promise = Nullopt;
     if (m_loader)
         m_loader->stop();
 }