Improve error messages in case FetchEvent.respondWith has a rejected promise
authoryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 12 Jun 2018 02:37:17 +0000 (02:37 +0000)
committeryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 12 Jun 2018 02:37:17 +0000 (02:37 +0000)
https://bugs.webkit.org/show_bug.cgi?id=186368

Reviewed by Chris Dumez.

LayoutTests/imported/w3c:

* web-platform-tests/service-workers/service-worker/fetch-event-network-error.https-expected.txt:
* web-platform-tests/service-workers/service-worker/fetch-event-redirect.https-expected.txt:
* web-platform-tests/service-workers/service-worker/fetch-event-respond-with-argument.https-expected.txt:
* web-platform-tests/service-workers/service-worker/fetch-event-respond-with-response-body-with-invalid-chunk.https-expected.txt:
* web-platform-tests/service-workers/service-worker/fetch-frame-resource.https-expected.txt:
* web-platform-tests/service-workers/service-worker/fetch-mixed-content-to-inscope.https-expected.txt:
* web-platform-tests/service-workers/service-worker/fetch-mixed-content-to-outscope.https-expected.txt:
* web-platform-tests/service-workers/service-worker/fetch-request-css-images.https-expected.txt:
* web-platform-tests/service-workers/service-worker/fetch-request-resources.https-expected.txt:
* web-platform-tests/service-workers/service-worker/invalid-header.https-expected.txt:
* web-platform-tests/service-workers/service-worker/update-recovery.https-expected.txt:

Source/WebCore:

Covered by rebased tests.

Introduce a new error domain for service worker ResourceError.
Used this domain to log in the console any such error.

Update FetchEvent implementation to get meaningful error messages for respondWith error cases.
In particular, convert the rejected promise JS value as a string to populate the error message.

* loader/SubresourceLoader.cpp:
(WebCore::SubresourceLoader::didFail):
* platform/network/ResourceErrorBase.cpp:
* platform/network/ResourceErrorBase.h:
* testing/ServiceWorkerInternals.cpp:
(WebCore::ServiceWorkerInternals::waitForFetchEventToFinish):
* workers/service/FetchEvent.cpp:
(WebCore::FetchEvent::~FetchEvent):
(WebCore::FetchEvent::createResponseError):
(WebCore::FetchEvent::onResponse):
(WebCore::FetchEvent::respondWithError):
(WebCore::FetchEvent::processResponse):
(WebCore::FetchEvent::promiseIsSettled):
* workers/service/FetchEvent.h:
* workers/service/context/ServiceWorkerFetch.cpp:
(WebCore::ServiceWorkerFetch::processResponse):
(WebCore::ServiceWorkerFetch::dispatchFetchEvent):

Source/WebKit:

Log in JS console in case of failures.
Rely on ThreadableLoader to log which client actually failed.

* WebProcess/Storage/ServiceWorkerClientFetch.cpp:
(WebKit::ServiceWorkerClientFetch::didFail):

LayoutTests:

* TestExpectations:
* http/tests/workers/service/basic-fetch.https-expected.txt:

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

23 files changed:
LayoutTests/ChangeLog
LayoutTests/TestExpectations
LayoutTests/http/tests/workers/service/basic-fetch.https-expected.txt
LayoutTests/imported/w3c/ChangeLog
LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/fetch-event-network-error.https-expected.txt
LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/fetch-event-redirect.https-expected.txt
LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/fetch-event-respond-with-argument.https-expected.txt
LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/fetch-event-respond-with-response-body-with-invalid-chunk.https-expected.txt
LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/fetch-frame-resource.https-expected.txt
LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/fetch-mixed-content-to-inscope.https-expected.txt
LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/fetch-mixed-content-to-outscope.https-expected.txt
LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/invalid-header.https-expected.txt
LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/update-recovery.https-expected.txt
Source/WebCore/ChangeLog
Source/WebCore/loader/ThreadableLoader.cpp
Source/WebCore/platform/network/ResourceErrorBase.cpp
Source/WebCore/platform/network/ResourceErrorBase.h
Source/WebCore/testing/ServiceWorkerInternals.cpp
Source/WebCore/workers/service/FetchEvent.cpp
Source/WebCore/workers/service/FetchEvent.h
Source/WebCore/workers/service/context/ServiceWorkerFetch.cpp
Source/WebKit/ChangeLog
Source/WebKit/WebProcess/Storage/ServiceWorkerClientFetch.cpp

index b9bfe15..96f771d 100644 (file)
@@ -1,3 +1,13 @@
+2018-06-11  Youenn Fablet  <youenn@apple.com>
+
+        Improve error messages in case FetchEvent.respondWith has a rejected promise
+        https://bugs.webkit.org/show_bug.cgi?id=186368
+
+        Reviewed by Chris Dumez.
+
+        * TestExpectations:
+        * http/tests/workers/service/basic-fetch.https-expected.txt:
+
 2018-06-11  Chris Dumez  <cdumez@apple.com>
 
         http/tests/security/xss-DENIED-script-inject-into-inactive-window2.html times out with PSON enabled
index dc409b6..f871549 100644 (file)
@@ -218,7 +218,9 @@ webkit.org/b/181900 imported/w3c/web-platform-tests/service-workers/service-work
 imported/w3c/web-platform-tests/service-workers/service-worker/fetch-response-taint.https.html [ DumpJSConsoleLogInStdErr ]
 imported/w3c/web-platform-tests/service-workers/service-worker/register-closed-window.https.html [ DumpJSConsoleLogInStdErr ]
 imported/w3c/web-platform-tests/service-workers/service-worker/registration-security-error.https.html [ DumpJSConsoleLogInStdErr ]
+imported/w3c/web-platform-tests/service-workers/service-worker/fetch-request-css-images.https.html [ DumpJSConsoleLogInStdErr ]
 imported/w3c/web-platform-tests/service-workers/service-worker/fetch-request-redirect.https.html [ DumpJSConsoleLogInStdErr Slow ]
+imported/w3c/web-platform-tests/service-workers/service-worker/fetch-request-resources.https.html [ DumpJSConsoleLogInStdErr ]
 [ Debug ] imported/w3c/web-platform-tests/service-workers/service-worker/clients-matchall-order.https.html [ Slow ]
 [ Debug ] imported/w3c/web-platform-tests/service-workers/service-worker/getregistrations.https.html [ Slow ]
 [ Debug ] imported/w3c/web-platform-tests/service-workers/service-worker/interfaces-sw.https.html [ Slow ]
index d7e9471..1e41258 100644 (file)
@@ -1,3 +1,4 @@
+CONSOLE MESSAGE: Fetch event was canceled
 CONSOLE MESSAGE: Fetch API cannot load https://127.0.0.1:8443/workers/service/resources/test5.
 
 test1 url: https://127.0.0.1:8443/workers/service/resources/test1
index e7d6847..ce2b95b 100644 (file)
@@ -1,3 +1,22 @@
+2018-06-11  Youenn Fablet  <youenn@apple.com>
+
+        Improve error messages in case FetchEvent.respondWith has a rejected promise
+        https://bugs.webkit.org/show_bug.cgi?id=186368
+
+        Reviewed by Chris Dumez.
+
+        * web-platform-tests/service-workers/service-worker/fetch-event-network-error.https-expected.txt:
+        * web-platform-tests/service-workers/service-worker/fetch-event-redirect.https-expected.txt:
+        * web-platform-tests/service-workers/service-worker/fetch-event-respond-with-argument.https-expected.txt:
+        * web-platform-tests/service-workers/service-worker/fetch-event-respond-with-response-body-with-invalid-chunk.https-expected.txt:
+        * web-platform-tests/service-workers/service-worker/fetch-frame-resource.https-expected.txt:
+        * web-platform-tests/service-workers/service-worker/fetch-mixed-content-to-inscope.https-expected.txt:
+        * web-platform-tests/service-workers/service-worker/fetch-mixed-content-to-outscope.https-expected.txt:
+        * web-platform-tests/service-workers/service-worker/fetch-request-css-images.https-expected.txt:
+        * web-platform-tests/service-workers/service-worker/fetch-request-resources.https-expected.txt:
+        * web-platform-tests/service-workers/service-worker/invalid-header.https-expected.txt:
+        * web-platform-tests/service-workers/service-worker/update-recovery.https-expected.txt:
+
 2018-06-08  Brendan McLoughlin  <brendan@bocoup.com>
 
         Sync web-platform-tests repo to 197cdad
index a8b8aa2..7658bbc 100644 (file)
@@ -1,4 +1,11 @@
+CONSOLE MESSAGE: Fetch event was canceled
 CONSOLE MESSAGE: XMLHttpRequest cannot load https://localhost:9443/service-workers/service-worker/resources/fetch-event-network-error-controllee-iframe.html?prevent-default.
+CONSOLE MESSAGE: FetchEvent.respondWith received an error: undefined
+CONSOLE MESSAGE: XMLHttpRequest cannot load https://localhost:9443/service-workers/service-worker/resources/fetch-event-network-error-controllee-iframe.html?reject.
+CONSOLE MESSAGE: FetchEvent.respondWith received an error: Response is disturbed or locked.
+CONSOLE MESSAGE: XMLHttpRequest cannot load https://localhost:9443/service-workers/service-worker/resources/fetch-event-network-error-controllee-iframe.html?used-body.
+CONSOLE MESSAGE: FetchEvent.respondWith received an error: Response is disturbed or locked.
+CONSOLE MESSAGE: XMLHttpRequest cannot load https://localhost:9443/service-workers/service-worker/resources/fetch-event-network-error-controllee-iframe.html?used-fetched-body.
 
 PASS Rejecting the fetch event or using preventDefault() causes a network error 
 
index a97cea3..1dbc085 100644 (file)
@@ -1,9 +1,49 @@
 CONSOLE MESSAGE: line 51: No-Cors mode requires follow redirect mode
 CONSOLE MESSAGE: line 51: Not allowed to request resource
 CONSOLE MESSAGE: line 51: Fetch API cannot load https://localhost:9443/nonav-manual-nocors-redirects-to-sameorigin-nocreds?url=redirect.py%3FRedirect%3Dhttps%253A%252F%252Flocalhost%253A9443%252Fservice-workers%252Fservice-worker%252Fresources%252Fsuccess.py&expected_type=opaqueredirect due to access control checks.
+CONSOLE MESSAGE: FetchEvent.respondWith received an error: TypeError: Origin https://localhost:9443 is not allowed by Access-Control-Allow-Origin.
+CONSOLE MESSAGE: Fetch API cannot load https://localhost:9443/nonav-follow-cors-redirects-to-nocors-nocreds?url=redirect.py%3FRedirect%3Dhttps%253A%252F%252F127.0.0.1%253A9443%252Fservice-workers%252Fservice-worker%252Fresources%252Fsuccess.py.
+CONSOLE MESSAGE: FetchEvent.respondWith received an error: TypeError: Unsafe attempt to load URL https://127.0.0.1:9443/service-workers/service-worker/resources/success.py from origin https://localhost:9443. Domains, protocols and ports must match.
+
+CONSOLE MESSAGE: Fetch API cannot load https://localhost:9443/nonav-follow-sameorigin-redirects-to-nocors-nocreds?url=redirect.py%3FRedirect%3Dhttps%253A%252F%252F127.0.0.1%253A9443%252Fservice-workers%252Fservice-worker%252Fresources%252Fsuccess.py.
+CONSOLE MESSAGE: FetchEvent.respondWith received an error: TypeError: Unsafe attempt to load URL https://127.0.0.1:9443/service-workers/service-worker/resources/success.py?ACAOrigin=https%3A%2F%2Flocalhost%3A9443 from origin https://localhost:9443. Domains, protocols and ports must match.
+
+CONSOLE MESSAGE: Fetch API cannot load https://localhost:9443/nonav-follow-sameorigin-redirects-to-cors-nocreds?url=redirect.py%3FRedirect%3Dhttps%253A%252F%252F127.0.0.1%253A9443%252Fservice-workers%252Fservice-worker%252Fresources%252Fsuccess.py%253FACAOrigin%253Dhttps%25253A%25252F%25252Flocalhost%25253A9443.
+CONSOLE MESSAGE: FetchEvent.respondWith received an error: TypeError: Origin https://localhost:9443 is not allowed by Access-Control-Allow-Origin.
+CONSOLE MESSAGE: Fetch API cannot load https://localhost:9443/nonav-follow-cors-redirects-to-nocors-creds?url=redirect.py%3FRedirect%3Dhttps%253A%252F%252Ffoo%253Abar%2540127.0.0.1%253A9443%252Fservice-workers%252Fservice-worker%252Fresources%252Fsuccess.py.
+CONSOLE MESSAGE: FetchEvent.respondWith received an error: TypeError: Unsafe attempt to load URL https://127.0.0.1:9443/service-workers/service-worker/resources/success.py from origin https://localhost:9443. Domains, protocols and ports must match.
+
+CONSOLE MESSAGE: Fetch API cannot load https://localhost:9443/nonav-follow-sameorigin-redirects-to-nocors-creds?url=redirect.py%3FRedirect%3Dhttps%253A%252F%252Ffoo%253Abar%2540127.0.0.1%253A9443%252Fservice-workers%252Fservice-worker%252Fresources%252Fsuccess.py.
+CONSOLE MESSAGE: FetchEvent.respondWith received an error: TypeError: Unsafe attempt to load URL https://127.0.0.1:9443/service-workers/service-worker/resources/success.py?ACAOrigin=https%3A%2F%2Flocalhost%3A9443 from origin https://localhost:9443. Domains, protocols and ports must match.
+
+CONSOLE MESSAGE: Fetch API cannot load https://localhost:9443/nonav-follow-sameorigin-redirects-to-cors-creds?url=redirect.py%3FRedirect%3Dhttps%253A%252F%252Ffoo%253Abar%2540127.0.0.1%253A9443%252Fservice-workers%252Fservice-worker%252Fresources%252Fsuccess.py%253FACAOrigin%253Dhttps%25253A%25252F%25252Flocalhost%25253A9443.
+CONSOLE MESSAGE: FetchEvent.respondWith received an error: TypeError: Not allowed to follow a redirection while loading https://localhost:9443/service-workers/service-worker/resources/redirect.py?Redirect=https%3A%2F%2Flocalhost%3A9443%2Fservice-workers%2Fservice-worker%2Fresources%2Fsuccess.py
+CONSOLE MESSAGE: Fetch API cannot load https://localhost:9443/nonav-error-cors-redirects-to-sameorigin-nocreds?url=redirect.py%3FRedirect%3Dhttps%253A%252F%252Flocalhost%253A9443%252Fservice-workers%252Fservice-worker%252Fresources%252Fsuccess.py.
+CONSOLE MESSAGE: FetchEvent.respondWith received an error: TypeError: Not allowed to follow a redirection while loading https://localhost:9443/service-workers/service-worker/resources/redirect.py?Redirect=https%3A%2F%2F127.0.0.1%3A9443%2Fservice-workers%2Fservice-worker%2Fresources%2Fsuccess.py
+CONSOLE MESSAGE: Fetch API cannot load https://localhost:9443/nonav-error-cors-redirects-to-nocors-nocreds?url=redirect.py%3FRedirect%3Dhttps%253A%252F%252F127.0.0.1%253A9443%252Fservice-workers%252Fservice-worker%252Fresources%252Fsuccess.py.
+CONSOLE MESSAGE: FetchEvent.respondWith received an error: TypeError: Not allowed to follow a redirection while loading https://localhost:9443/service-workers/service-worker/resources/redirect.py?Redirect=https%3A%2F%2F127.0.0.1%3A9443%2Fservice-workers%2Fservice-worker%2Fresources%2Fsuccess.py%3FACAOrigin%3Dhttps%253A%252F%252Flocalhost%253A9443
+CONSOLE MESSAGE: Fetch API cannot load https://localhost:9443/nonav-error-cors-redirects-to-cors-nocreds?url=redirect.py%3FRedirect%3Dhttps%253A%252F%252F127.0.0.1%253A9443%252Fservice-workers%252Fservice-worker%252Fresources%252Fsuccess.py%253FACAOrigin%253Dhttps%25253A%25252F%25252Flocalhost%25253A9443.
+CONSOLE MESSAGE: FetchEvent.respondWith received an error: TypeError: Not allowed to follow a redirection while loading https://localhost:9443/service-workers/service-worker/resources/redirect.py?Redirect=https%3A%2F%2Flocalhost%3A9443%2Fservice-workers%2Fservice-worker%2Fresources%2Fsuccess.py
+CONSOLE MESSAGE: Fetch API cannot load https://localhost:9443/nonav-error-sameorigin-redirects-to-sameorigin-nocreds?url=redirect.py%3FRedirect%3Dhttps%253A%252F%252Flocalhost%253A9443%252Fservice-workers%252Fservice-worker%252Fresources%252Fsuccess.py.
+CONSOLE MESSAGE: FetchEvent.respondWith received an error: TypeError: Not allowed to follow a redirection while loading https://localhost:9443/service-workers/service-worker/resources/redirect.py?Redirect=https%3A%2F%2F127.0.0.1%3A9443%2Fservice-workers%2Fservice-worker%2Fresources%2Fsuccess.py
+CONSOLE MESSAGE: Fetch API cannot load https://localhost:9443/nonav-error-sameorigin-redirects-to-nocors-nocreds?url=redirect.py%3FRedirect%3Dhttps%253A%252F%252F127.0.0.1%253A9443%252Fservice-workers%252Fservice-worker%252Fresources%252Fsuccess.py.
+CONSOLE MESSAGE: FetchEvent.respondWith received an error: TypeError: Not allowed to follow a redirection while loading https://localhost:9443/service-workers/service-worker/resources/redirect.py?Redirect=https%3A%2F%2F127.0.0.1%3A9443%2Fservice-workers%2Fservice-worker%2Fresources%2Fsuccess.py%3FACAOrigin%3Dhttps%253A%252F%252Flocalhost%253A9443
+CONSOLE MESSAGE: Fetch API cannot load https://localhost:9443/nonav-error-sameorigin-redirects-to-cors-nocreds?url=redirect.py%3FRedirect%3Dhttps%253A%252F%252F127.0.0.1%253A9443%252Fservice-workers%252Fservice-worker%252Fresources%252Fsuccess.py%253FACAOrigin%253Dhttps%25253A%25252F%25252Flocalhost%25253A9443.
 CONSOLE MESSAGE: line 51: No-Cors mode requires follow redirect mode
 CONSOLE MESSAGE: line 51: Not allowed to request resource
 CONSOLE MESSAGE: line 51: Fetch API cannot load https://localhost:9443/nonav-error-nocors-redirects-to-sameorigin-nocreds?url=redirect.py%3FRedirect%3Dhttps%253A%252F%252Flocalhost%253A9443%252Fservice-workers%252Fservice-worker%252Fresources%252Fsuccess.py due to access control checks.
+CONSOLE MESSAGE: FetchEvent.respondWith received an error: TypeError: Not allowed to follow a redirection while loading https://localhost:9443/service-workers/service-worker/resources/redirect.py?Redirect=https%3A%2F%2Ffoo%3Abar%40localhost%3A9443%2Fservice-workers%2Fservice-worker%2Fresources%2Fsuccess.py
+CONSOLE MESSAGE: Fetch API cannot load https://localhost:9443/nonav-error-cors-redirects-to-sameorigin-creds?url=redirect.py%3FRedirect%3Dhttps%253A%252F%252Ffoo%253Abar%2540localhost%253A9443%252Fservice-workers%252Fservice-worker%252Fresources%252Fsuccess.py.
+CONSOLE MESSAGE: FetchEvent.respondWith received an error: TypeError: Not allowed to follow a redirection while loading https://localhost:9443/service-workers/service-worker/resources/redirect.py?Redirect=https%3A%2F%2Ffoo%3Abar%40127.0.0.1%3A9443%2Fservice-workers%2Fservice-worker%2Fresources%2Fsuccess.py
+CONSOLE MESSAGE: Fetch API cannot load https://localhost:9443/nonav-error-cors-redirects-to-nocors-creds?url=redirect.py%3FRedirect%3Dhttps%253A%252F%252Ffoo%253Abar%2540127.0.0.1%253A9443%252Fservice-workers%252Fservice-worker%252Fresources%252Fsuccess.py.
+CONSOLE MESSAGE: FetchEvent.respondWith received an error: TypeError: Not allowed to follow a redirection while loading https://localhost:9443/service-workers/service-worker/resources/redirect.py?Redirect=https%3A%2F%2Ffoo%3Abar%40127.0.0.1%3A9443%2Fservice-workers%2Fservice-worker%2Fresources%2Fsuccess.py%3FACAOrigin%3Dhttps%253A%252F%252Flocalhost%253A9443
+CONSOLE MESSAGE: Fetch API cannot load https://localhost:9443/nonav-error-cors-redirects-to-cors-creds?url=redirect.py%3FRedirect%3Dhttps%253A%252F%252Ffoo%253Abar%2540127.0.0.1%253A9443%252Fservice-workers%252Fservice-worker%252Fresources%252Fsuccess.py%253FACAOrigin%253Dhttps%25253A%25252F%25252Flocalhost%25253A9443.
+CONSOLE MESSAGE: FetchEvent.respondWith received an error: TypeError: Not allowed to follow a redirection while loading https://localhost:9443/service-workers/service-worker/resources/redirect.py?Redirect=https%3A%2F%2Ffoo%3Abar%40localhost%3A9443%2Fservice-workers%2Fservice-worker%2Fresources%2Fsuccess.py
+CONSOLE MESSAGE: Fetch API cannot load https://localhost:9443/nonav-error-sameorigin-redirects-to-sameorigin-creds?url=redirect.py%3FRedirect%3Dhttps%253A%252F%252Ffoo%253Abar%2540localhost%253A9443%252Fservice-workers%252Fservice-worker%252Fresources%252Fsuccess.py.
+CONSOLE MESSAGE: FetchEvent.respondWith received an error: TypeError: Not allowed to follow a redirection while loading https://localhost:9443/service-workers/service-worker/resources/redirect.py?Redirect=https%3A%2F%2Ffoo%3Abar%40127.0.0.1%3A9443%2Fservice-workers%2Fservice-worker%2Fresources%2Fsuccess.py
+CONSOLE MESSAGE: Fetch API cannot load https://localhost:9443/nonav-error-sameorigin-redirects-to-nocors-creds?url=redirect.py%3FRedirect%3Dhttps%253A%252F%252Ffoo%253Abar%2540127.0.0.1%253A9443%252Fservice-workers%252Fservice-worker%252Fresources%252Fsuccess.py.
+CONSOLE MESSAGE: FetchEvent.respondWith received an error: TypeError: Not allowed to follow a redirection while loading https://localhost:9443/service-workers/service-worker/resources/redirect.py?Redirect=https%3A%2F%2Ffoo%3Abar%40127.0.0.1%3A9443%2Fservice-workers%2Fservice-worker%2Fresources%2Fsuccess.py%3FACAOrigin%3Dhttps%253A%252F%252Flocalhost%253A9443
+CONSOLE MESSAGE: Fetch API cannot load https://localhost:9443/nonav-error-sameorigin-redirects-to-cors-creds?url=redirect.py%3FRedirect%3Dhttps%253A%252F%252Ffoo%253Abar%2540127.0.0.1%253A9443%252Fservice-workers%252Fservice-worker%252Fresources%252Fsuccess.py%253FACAOrigin%253Dhttps%25253A%25252F%25252Flocalhost%25253A9443.
 
 PASS initialize global state 
 PASS Non-navigation, manual redirect, cors mode Request redirected to same-origin without credentials should succeed opaqueredirect interception and response should not be redirected 
index efaac5b..f450d7b 100644 (file)
@@ -1,3 +1,5 @@
+CONSOLE MESSAGE: FetchEvent.respondWith received an error: Returned response is null.
+CONSOLE MESSAGE: XMLHttpRequest cannot load https://localhost:9443/service-workers/service-worker/resources/fetch-event-respond-with-argument-iframe.html?other-value.
 
 PASS respondWith() takes either a Response or a promise that resolves with a Response. Other values should raise a network error. 
 
index 9418bd3..fd27309 100644 (file)
@@ -1,3 +1,7 @@
+CONSOLE MESSAGE: FetchEvent.respondWith received an error: TypeError: Not allowed to request resource
+CONSOLE MESSAGE: Cannot load https://localhost:9443/service-workers/service-worker/resources/fetch-frame-resource/frame-opaque?mode=no-cors&url=https%3A%2F%2F127.0.0.1%3A9443%2Fservice-workers%2Fservice-worker%2Fresources%2Ffetch-access-control.py.
+CONSOLE MESSAGE: FetchEvent.respondWith received an error: TypeError: Not allowed to request resource
+CONSOLE MESSAGE: Cannot load https://localhost:9443/service-workers/service-worker/resources/fetch-frame-resource/window-opaque?mode=no-cors&url=https%3A%2F%2F127.0.0.1%3A9443%2Fservice-workers%2Fservice-worker%2Fresources%2Ffetch-access-control.py.
 
 PASS Basic type response could be loaded in the iframe. 
 PASS CORS type response could be loaded in the iframe. 
index 11cf6a0..ede8ce0 100644 (file)
@@ -1,3 +1,7 @@
+CONSOLE MESSAGE: FetchEvent.respondWith received an error: TypeError: Not allowed to request resource
+CONSOLE MESSAGE: Cannot load https://localhost:9443/service-workers/service-worker/resources/dummy?mode=no-cors&url=http%3A%2F%2Flocalhost%3A8800%2Fservice-workers%2Fservice-worker%2Fresources%2Ffetch-access-control.py%3FPNGIMAGE.
+CONSOLE MESSAGE: FetchEvent.respondWith received an error: TypeError: Not allowed to request resource
+CONSOLE MESSAGE: Cannot load https://localhost:9443/service-workers/service-worker/resources/dummy?mode=no-cors&url=http%3A%2F%2F127.0.0.1%3A8800%2Fservice-workers%2Fservice-worker%2Fresources%2Ffetch-access-control.py%3FPNGIMAGE.
 
 
 PASS Verify Mixed content of fetch() in a Service Worker 
index ae6efe5..ba27fed 100644 (file)
@@ -1,7 +1,11 @@
 CONSOLE MESSAGE: line 25: The page at https://localhost:9443/service-workers/service-worker/fetch-mixed-content-to-outscope.https.html was allowed to display insecure content from http://localhost:8800/service-workers/service-worker/resources/fetch-access-control.py?PNGIMAGE.
 
+CONSOLE MESSAGE: FetchEvent.respondWith received an error: TypeError: Not allowed to request resource
+CONSOLE MESSAGE: Cannot load http://localhost:8800/service-workers/service-worker/resources/fetch-access-control.py?PNGIMAGE.
 CONSOLE MESSAGE: line 42: The page at https://localhost:9443/service-workers/service-worker/fetch-mixed-content-to-outscope.https.html was allowed to display insecure content from http://127.0.0.1:8800/service-workers/service-worker/resources/fetch-access-control.py?PNGIMAGE.
 
+CONSOLE MESSAGE: FetchEvent.respondWith received an error: TypeError: Not allowed to request resource
+CONSOLE MESSAGE: Cannot load http://127.0.0.1:8800/service-workers/service-worker/resources/fetch-access-control.py?PNGIMAGE.
 
 
 PASS Verify Mixed content of fetch() in a Service Worker 
index 92ae213..c2b68e1 100644 (file)
@@ -1,3 +1,5 @@
+CONSOLE MESSAGE: FetchEvent.respondWith received an error: TypeError: Header 'foo' has invalid value: 'b
+CONSOLE MESSAGE: XMLHttpRequest cannot load https://localhost:9443/service-workers/service-worker/resources/dummy?test.
 
 PASS Verify the response of FetchEvent using XMLHttpRequest 
 
index ffbd739..7cbac1c 100644 (file)
@@ -1,3 +1,5 @@
+CONSOLE MESSAGE: FetchEvent.respondWith received an error: undefined
+CONSOLE MESSAGE: Cannot load https://localhost:9443/service-workers/service-worker/resources/simple.txt.
 
 PASS Recover from a bad service worker by updating after a failed navigation. 
 
index 028d7d7..9ceef4f 100644 (file)
@@ -1,3 +1,36 @@
+2018-06-11  Youenn Fablet  <youenn@apple.com>
+
+        Improve error messages in case FetchEvent.respondWith has a rejected promise
+        https://bugs.webkit.org/show_bug.cgi?id=186368
+
+        Reviewed by Chris Dumez.
+
+        Covered by rebased tests.
+
+        Introduce a new error domain for service worker ResourceError.
+        Used this domain to log in the console any such error.
+
+        Update FetchEvent implementation to get meaningful error messages for respondWith error cases.
+        In particular, convert the rejected promise JS value as a string to populate the error message.
+
+        * loader/SubresourceLoader.cpp:
+        (WebCore::SubresourceLoader::didFail):
+        * platform/network/ResourceErrorBase.cpp:
+        * platform/network/ResourceErrorBase.h:
+        * testing/ServiceWorkerInternals.cpp:
+        (WebCore::ServiceWorkerInternals::waitForFetchEventToFinish):
+        * workers/service/FetchEvent.cpp:
+        (WebCore::FetchEvent::~FetchEvent):
+        (WebCore::FetchEvent::createResponseError):
+        (WebCore::FetchEvent::onResponse):
+        (WebCore::FetchEvent::respondWithError):
+        (WebCore::FetchEvent::processResponse):
+        (WebCore::FetchEvent::promiseIsSettled):
+        * workers/service/FetchEvent.h:
+        * workers/service/context/ServiceWorkerFetch.cpp:
+        (WebCore::ServiceWorkerFetch::processResponse):
+        (WebCore::ServiceWorkerFetch::dispatchFetchEvent):
+
 2018-06-11  Chris Dumez  <cdumez@apple.com>
 
         http/tests/security/xss-DENIED-script-inject-into-inactive-window2.html times out with PSON enabled
index ceab6fe..68b7e9b 100644 (file)
@@ -131,7 +131,7 @@ void ThreadableLoader::logError(ScriptExecutionContext& context, const ResourceE
 
     // We further reduce logging to some errors.
     // FIXME: Log more errors when making so do not make some layout tests flaky.
-    if (error.domain() != errorDomainWebKitInternal && !error.isAccessControl())
+    if (error.domain() != errorDomainWebKitInternal && error.domain() != errorDomainWebKitServiceWorker && !error.isAccessControl())
         return;
 
     const char* messageStart;
index 84a7c51..48a810e 100644 (file)
@@ -30,6 +30,7 @@
 namespace WebCore {
 
 const char* const errorDomainWebKitInternal = "WebKitInternal";
+const char* const errorDomainWebKitServiceWorker = "WebKitServiceWorker";
 
 inline const ResourceError& ResourceErrorBase::asResourceError() const
 {
index 073cacb..a1bc601 100644 (file)
@@ -34,6 +34,7 @@ namespace WebCore {
 class ResourceError;
 
 WEBCORE_EXPORT extern const char* const errorDomainWebKitInternal; // Used for errors that won't be exposed to clients.
+WEBCORE_EXPORT extern const char* const errorDomainWebKitServiceWorker; // Used for errors that happen when loading a resource from a service worker.
 
 class ResourceErrorBase {
 public:
index da1c4fb..887894e 100644 (file)
@@ -51,11 +51,11 @@ void ServiceWorkerInternals::setOnline(bool isOnline)
 
 void ServiceWorkerInternals::waitForFetchEventToFinish(FetchEvent& event, DOMPromiseDeferred<IDLInterface<FetchResponse>>&& promise)
 {
-    event.onResponse([promise = WTFMove(promise), event = makeRef(event)] (FetchResponse* response) mutable {
-        if (response)
-            promise.resolve(*response);
+    event.onResponse([promise = WTFMove(promise), event = makeRef(event)] (auto&& result) mutable {
+        if (result.has_value())
+            promise.resolve(WTFMove(result.value()));
         else
-            promise.reject(TypeError, ASCIILiteral("fetch event responded with error"));
+            promise.reject(TypeError, result.error().localizedDescription());
     });
 }
 
index a054e84..18eff9e 100644 (file)
@@ -52,7 +52,13 @@ FetchEvent::FetchEvent(const AtomicString& type, Init&& initializer, IsTrusted i
 FetchEvent::~FetchEvent()
 {
     if (auto callback = WTFMove(m_onResponse))
-        callback(nullptr);
+        callback(makeUnexpected(ResourceError { errorDomainWebKitServiceWorker, 0, m_request->url(), ASCIILiteral("Fetch event is destroyed."), ResourceError::Type::Cancellation }));
+}
+
+ResourceError FetchEvent::createResponseError(const URL& url, const String& errorMessage)
+{
+    return ResourceError { errorDomainWebKitServiceWorker, 0, url, makeString("FetchEvent.respondWith received an error: ", errorMessage), ResourceError::Type::General };
+
 }
 
 ExceptionOr<void> FetchEvent::respondWith(Ref<DOMPromise>&& promise)
@@ -81,46 +87,47 @@ ExceptionOr<void> FetchEvent::respondWith(Ref<DOMPromise>&& promise)
     return { };
 }
 
-void FetchEvent::onResponse(CompletionHandler<void(FetchResponse*)>&& callback)
+void FetchEvent::onResponse(ResponseCallback&& callback)
 {
     ASSERT(!m_onResponse);
     m_onResponse = WTFMove(callback);
 }
 
-void FetchEvent::respondWithError()
+void FetchEvent::respondWithError(ResourceError&& error)
 {
     m_respondWithError = true;
-    processResponse(nullptr);
+    processResponse(makeUnexpected(WTFMove(error)));
 }
 
-void FetchEvent::processResponse(FetchResponse* response)
+void FetchEvent::processResponse(Expected<Ref<FetchResponse>, ResourceError>&& result)
 {
     m_respondPromise = nullptr;
     m_waitToRespond = false;
     if (auto callback = WTFMove(m_onResponse))
-        callback(response);
+        callback(WTFMove(result));
 }
 
 void FetchEvent::promiseIsSettled()
 {
     if (m_respondPromise->status() == DOMPromise::Status::Rejected) {
-        respondWithError();
+        auto reason = m_respondPromise->result().toWTFString(m_respondPromise->globalObject()->globalExec());
+        respondWithError(createResponseError(m_request->url(), reason));
         return;
     }
 
     ASSERT(m_respondPromise->status() == DOMPromise::Status::Fulfilled);
     auto response = JSFetchResponse::toWrapped(m_respondPromise->globalObject()->globalExec()->vm(), m_respondPromise->result());
     if (!response) {
-        respondWithError();
+        respondWithError(createResponseError(m_request->url(), ASCIILiteral("Returned response is null.")));
         return;
     }
 
     if (response->isDisturbedOrLocked()) {
-        respondWithError();
+        respondWithError(createResponseError(m_request->url(), ASCIILiteral("Response is disturbed or locked.")));
         return;
     }
 
-    processResponse(response);
+    processResponse(makeRef(*response));
 }
 
 } // namespace WebCore
index 5786f94..f570b8a 100644 (file)
 #include "ExtendableEvent.h"
 #include "FetchRequest.h"
 #include <wtf/CompletionHandler.h>
+#include <wtf/Expected.h>
 
 namespace WebCore {
 
 class FetchResponse;
+class ResourceError;
 
 class FetchEvent final : public ExtendableEvent {
 public:
@@ -56,7 +58,8 @@ public:
 
     ExceptionOr<void> respondWith(Ref<DOMPromise>&&);
 
-    WEBCORE_EXPORT void onResponse(CompletionHandler<void(FetchResponse*)>&&);
+    using ResponseCallback = CompletionHandler<void(Expected<Ref<FetchResponse>, ResourceError>&&)>;
+    WEBCORE_EXPORT void onResponse(ResponseCallback&&);
 
     FetchRequest& request() { return m_request.get(); }
     const String& clientId() const { return m_clientId; }
@@ -65,12 +68,14 @@ public:
 
     bool respondWithEntered() const { return m_respondWithEntered; }
 
+    static ResourceError createResponseError(const URL&, const String&);
+
 private:
     WEBCORE_EXPORT FetchEvent(const AtomicString&, Init&&, IsTrusted);
 
     void promiseIsSettled();
-    void processResponse(FetchResponse*);
-    void respondWithError();
+    void processResponse(Expected<Ref<FetchResponse>, ResourceError>&&);
+    void respondWithError(ResourceError&&);
 
     Ref<FetchRequest> m_request;
     String m_clientId;
@@ -82,7 +87,7 @@ private:
     bool m_respondWithError { false };
     RefPtr<DOMPromise> m_respondPromise;
 
-    CompletionHandler<void(FetchResponse*)> m_onResponse;
+    ResponseCallback m_onResponse;
 };
 
 } // namespace WebCore
index 63be95c..ea6e023 100644 (file)
@@ -43,13 +43,13 @@ namespace WebCore {
 
 namespace ServiceWorkerFetch {
 
-static void processResponse(Ref<Client>&& client, FetchResponse* response)
+static void processResponse(Ref<Client>&& client, Expected<Ref<FetchResponse>, ResourceError>&& result)
 {
-    if (!response) {
-        client->didFail(ResourceError { errorDomainWebKitInternal, 0, URL(), ASCIILiteral("Response is null") });
+    if (!result.has_value()) {
+        client->didFail(result.error());
         return;
     }
-    auto protectedResponse = makeRef(*response);
+    auto response = WTFMove(result.value());
 
     client->didReceiveResponse(response->resourceResponse());
 
@@ -61,7 +61,7 @@ static void processResponse(Ref<Client>&& client, FetchResponse* response)
     if (response->isBodyReceivedByChunk()) {
         response->consumeBodyReceivedByChunk([client = WTFMove(client)] (auto&& result) mutable {
             if (result.hasException()) {
-                client->didFail(ResourceError { errorDomainWebKitInternal, 0, URL(), result.exception().message() });
+                client->didFail(FetchEvent::createResponseError(URL { }, result.exception().message()));
                 return;
             }
 
@@ -122,8 +122,8 @@ void dispatchFetchEvent(Ref<Client>&& client, ServiceWorkerGlobalScope& globalSc
     init.cancelable = true;
     auto event = FetchEvent::create(eventNames().fetchEvent, WTFMove(init), Event::IsTrusted::Yes);
 
-    event->onResponse([client = client.copyRef()] (FetchResponse* response) mutable {
-        processResponse(WTFMove(client), response);
+    event->onResponse([client = client.copyRef()] (auto&& result) mutable {
+        processResponse(WTFMove(client), WTFMove(result));
     });
 
     globalScope.dispatchEvent(event);
index d157101..026b113 100644 (file)
@@ -1,3 +1,16 @@
+2018-06-11  Youenn Fablet  <youenn@apple.com>
+
+        Improve error messages in case FetchEvent.respondWith has a rejected promise
+        https://bugs.webkit.org/show_bug.cgi?id=186368
+
+        Reviewed by Chris Dumez.
+
+        Log in JS console in case of failures.
+        Rely on ThreadableLoader to log which client actually failed.
+
+        * WebProcess/Storage/ServiceWorkerClientFetch.cpp:
+        (WebKit::ServiceWorkerClientFetch::didFail):
+
 2018-06-11  Chris Dumez  <cdumez@apple.com>
 
         http/tests/security/xss-DENIED-script-inject-into-inactive-window2.html times out with PSON enabled
index a80a880..5518fa2 100644 (file)
@@ -32,6 +32,8 @@
 #include "WebSWClientConnection.h"
 #include "WebServiceWorkerProvider.h"
 #include <WebCore/CrossOriginAccessControl.h>
+#include <WebCore/Document.h>
+#include <WebCore/Frame.h>
 #include <WebCore/MIMETypeRegistry.h>
 #include <WebCore/NotImplemented.h>
 #include <WebCore/ResourceError.h>
@@ -233,6 +235,13 @@ void ServiceWorkerClientFetch::didFail(ResourceError&& error)
         if (!m_loader)
             return;
 
+        auto* document = m_loader->frame() ? m_loader->frame()->document() : nullptr;
+        if (document) {
+            document->addConsoleMessage(MessageSource::JS, MessageLevel::Error, m_error.localizedDescription());
+            if (m_loader->options().destination != FetchOptions::Destination::EmptyString)
+                document->addConsoleMessage(MessageSource::JS, MessageLevel::Error, makeString("Cannot load ", m_error.failingURL().string(), "."));
+        }
+
         m_loader->didFail(m_error);
 
         if (auto callback = WTFMove(m_callback))