LayoutTest imported/w3c/web-platform-tests/xhr/event-upload-progress-crossorigin...
authoryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 3 May 2019 17:32:25 +0000 (17:32 +0000)
committeryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 3 May 2019 17:32:25 +0000 (17:32 +0000)
https://bugs.webkit.org/show_bug.cgi?id=182849
<rdar://problem/50353372>

Reviewed by Alex Christensen.

LayoutTests/imported/w3c:

Modernize the test and add an assertion that the body is transmitted after a redirection.

* web-platform-tests/xhr/event-upload-progress-crossorigin.htm:

Source/WebKit:

In case of restarting the load after a redirection, which now happens in case
of following cross origin redirections with same-origin credentials, make sure to
update the request as would do NetworkLoad.
This is in particular important to preserve the request body.

Covered by WPT updated test.

* NetworkProcess/NetworkLoad.cpp:
(WebKit::updateRequest):
(WebKit::NetworkLoad::updateRequestAfterRedirection const):
(WebKit::NetworkLoad::continueWillSendRequest):
* NetworkProcess/NetworkLoad.h:
* NetworkProcess/NetworkResourceLoader.cpp:
(WebKit::NetworkResourceLoader::continueWillSendRequest):

LayoutTests:

* platform/mac-wk2/TestExpectations:

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

LayoutTests/ChangeLog
LayoutTests/imported/w3c/ChangeLog
LayoutTests/imported/w3c/web-platform-tests/xhr/event-upload-progress-crossorigin.htm
LayoutTests/platform/mac-wk2/TestExpectations
Source/WebKit/ChangeLog
Source/WebKit/NetworkProcess/NetworkLoad.cpp
Source/WebKit/NetworkProcess/NetworkLoad.h
Source/WebKit/NetworkProcess/NetworkResourceLoader.cpp

index b0b34d5..8e089d5 100644 (file)
@@ -1,3 +1,13 @@
+2019-05-03  Youenn Fablet  <youenn@apple.com>
+
+        LayoutTest imported/w3c/web-platform-tests/xhr/event-upload-progress-crossorigin.htm is a flaky failure
+        https://bugs.webkit.org/show_bug.cgi?id=182849
+        <rdar://problem/50353372>
+
+        Reviewed by Alex Christensen.
+
+        * platform/mac-wk2/TestExpectations:
+
 2019-05-03  Devin Rousso  <drousso@apple.com>
 
         Web Inspector: Record actions performed on WebGL2RenderingContext
index 4a22b6d..e000a4b 100644 (file)
@@ -1,3 +1,15 @@
+2019-05-03  Youenn Fablet  <youenn@apple.com>
+
+        LayoutTest imported/w3c/web-platform-tests/xhr/event-upload-progress-crossorigin.htm is a flaky failure
+        https://bugs.webkit.org/show_bug.cgi?id=182849
+        <rdar://problem/50353372>
+
+        Reviewed by Alex Christensen.
+
+        Modernize the test and add an assertion that the body is transmitted after a redirection.
+
+        * web-platform-tests/xhr/event-upload-progress-crossorigin.htm:
+
 2019-05-03  Joonghun Park  <jh718.park@samsung.com>
 
         Resolve the percentage values of inset properties against proper box.
index 5e558a2..5acfc05 100644 (file)
@@ -11,23 +11,42 @@ const remote = get_host_info().HTTP_REMOTE_ORIGIN + "/xhr/resources/corsenabled.
       redirect = "resources/redirect.py?code=307&location=" + remote;
 
 [remote, redirect].forEach(url => {
-  async_test(test => {
+  promise_test(async test => {
     const client = new XMLHttpRequest();
-    client.upload.onprogress = test.step_func_done()
-    client.onload = test.unreached_func()
-    client.open("POST", url)
-    client.send("On time: " + url)
+
+    const loadFinished = new Promise(resolve => client.onloadend = resolve);
+    const progressReceived = new Promise(resolve => client.upload.onprogress = resolve);
+    const loadReceived = new Promise((resolve, reject) => client.onload = () => { reject("load event received") });
+
+    const body = "On time: " + url;
+    client.open("POST", url);
+    client.send(body);
+
+    await Promise.race([progressReceived, loadReceived]);
+
+    await loadFinished;
+    assert_equals(client.getResponseHeader("X-Request-Data"), body, "test body");
   }, "Upload events registered on time (" + url + ")");
 });
 
 [remote, redirect].forEach(url => {
-  async_test(test => {
+  promise_test(async test => {
     const client = new XMLHttpRequest();
-    client.onload = test.step_func_done();
+
+    const loadFinished = new Promise(resolve => client.onloadend = resolve);
+    const loadReceived = new Promise(resolve => client.onload = resolve);
+
+    const body = "Too late: " + url;
     client.open("POST", url);
-    client.send("Too late: " + url);
-    client.upload.onloadstart = test.unreached_func(); // registered too late
-    client.upload.onprogress = test.unreached_func(); // registered too late
+    client.send(body);
+
+    const loadstartReceived = new Promise((resolve, reject) => client.upload.onloadstart = () => { reject("loadstart event received") });
+    const progressReceived = new Promise((resolve, reject) => client.upload.onprogress = () => { reject("progress event received") });
+
+    await Promise.race([loadReceived, progressReceived, loadstartReceived]);
+
+    await loadFinished;
+    assert_equals(client.getResponseHeader("X-Request-Data"), body);
   }, "Upload events registered too late (" + url + ")");
 });
 </script>
index acf978b..f4c190d 100644 (file)
@@ -832,8 +832,6 @@ webkit.org/b/182341 imported/w3c/web-platform-tests/service-workers/service-work
 
 webkit.org/b/179352 imported/w3c/web-platform-tests/service-workers/service-worker/windowclient-navigate.https.html [ Pass Failure Slow ]
 
-webkit.org/b/182849 imported/w3c/web-platform-tests/xhr/event-upload-progress-crossorigin.htm [ Pass Failure ]
-
 webkit.org/b/183164 fast/dom/Window/window-focus-self.html [ Pass Failure ]
 
 webkit.org/b/180982 [ Debug ] imported/w3c/web-platform-tests/service-workers/service-worker/registration-updateviacache.https.html [ Slow ]
index 16fe326..e2b557d 100644 (file)
@@ -1,3 +1,26 @@
+2019-05-03  Youenn Fablet  <youenn@apple.com>
+
+        LayoutTest imported/w3c/web-platform-tests/xhr/event-upload-progress-crossorigin.htm is a flaky failure
+        https://bugs.webkit.org/show_bug.cgi?id=182849
+        <rdar://problem/50353372>
+
+        Reviewed by Alex Christensen.
+
+        In case of restarting the load after a redirection, which now happens in case
+        of following cross origin redirections with same-origin credentials, make sure to
+        update the request as would do NetworkLoad.
+        This is in particular important to preserve the request body.
+
+        Covered by WPT updated test.
+
+        * NetworkProcess/NetworkLoad.cpp:
+        (WebKit::updateRequest):
+        (WebKit::NetworkLoad::updateRequestAfterRedirection const):
+        (WebKit::NetworkLoad::continueWillSendRequest):
+        * NetworkProcess/NetworkLoad.h:
+        * NetworkProcess/NetworkResourceLoader.cpp:
+        (WebKit::NetworkResourceLoader::continueWillSendRequest):
+
 2019-05-03  Commit Queue  <commit-queue@webkit.org>
 
         Unreviewed, rolling out r244881.
index 3a6fa10..735f369 100644 (file)
@@ -90,14 +90,26 @@ void NetworkLoad::cancel()
         m_task->cancel();
 }
 
-void NetworkLoad::continueWillSendRequest(WebCore::ResourceRequest&& newRequest)
+static inline void updateRequest(ResourceRequest& currentRequest, const ResourceRequest& newRequest)
 {
 #if PLATFORM(COCOA)
-    m_currentRequest.updateFromDelegatePreservingOldProperties(newRequest.nsURLRequest(HTTPBodyUpdatePolicy::DoNotUpdateHTTPBody));
+    currentRequest.updateFromDelegatePreservingOldProperties(newRequest.nsURLRequest(HTTPBodyUpdatePolicy::DoNotUpdateHTTPBody));
 #else
     // FIXME: Implement ResourceRequest::updateFromDelegatePreservingOldProperties. See https://bugs.webkit.org/show_bug.cgi?id=126127.
-    m_currentRequest.updateFromDelegatePreservingOldProperties(newRequest);
+    currentRequest.updateFromDelegatePreservingOldProperties(newRequest);
 #endif
+}
+
+void NetworkLoad::updateRequestAfterRedirection(WebCore::ResourceRequest& newRequest) const
+{
+    ResourceRequest updatedRequest = m_currentRequest;
+    updateRequest(updatedRequest, newRequest);
+    newRequest = WTFMove(updatedRequest);
+}
+
+void NetworkLoad::continueWillSendRequest(WebCore::ResourceRequest&& newRequest)
+{
+    updateRequest(m_currentRequest, newRequest);
 
     auto redirectCompletionHandler = std::exchange(m_redirectCompletionHandler, nullptr);
     ASSERT(redirectCompletionHandler);
index 5a51b29..a5ebab6 100644 (file)
@@ -52,6 +52,7 @@ public:
     bool isAllowedToAskUserForCredentials() const;
 
     const WebCore::ResourceRequest& currentRequest() const { return m_currentRequest; }
+    void updateRequestAfterRedirection(WebCore::ResourceRequest&) const;
 
     const NetworkLoadParameters& parameters() const { return m_parameters; }
 
index 7ba63cb..8ab0466 100644 (file)
@@ -701,6 +701,10 @@ void NetworkResourceLoader::continueWillSendRequest(ResourceRequest&& newRequest
 {
     if (m_shouldRestartLoad) {
         m_shouldRestartLoad = false;
+
+        if (m_networkLoad)
+            m_networkLoad->updateRequestAfterRedirection(newRequest);
+
         restartNetworkLoad(WTFMove(newRequest));
         return;
     }