REGRESSION (r192796) WKBundlePageResourceLoadClient should be able to setHTTPBody...
authorachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 10 Dec 2015 21:26:28 +0000 (21:26 +0000)
committerachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 10 Dec 2015 21:26:28 +0000 (21:26 +0000)
https://bugs.webkit.org/show_bug.cgi?id=152022
rdar://problem/23763584

Reviewed by Darin Adler.

Source/WebKit2:

* Shared/API/c/WKURLRequest.cpp:
(WKURLRequestCopyHTTPMethod):
(WKURLRequestCopyWithHTTPBody):
(WKURLRequestSetDefaultTimeoutInterval):
* Shared/API/c/WKURLRequest.h:
Make WKURLRequestCopyWithHTTPBody SPI for testing.
* Shared/API/c/mac/WKURLRequestNS.mm:
(WKURLRequestCreateWithNSURLRequest):
Crash if someone tries to use an NSURLRequest with HTTPBodyStream, which will not work with the network process.
* WebProcess/InjectedBundle/InjectedBundlePageResourceLoadClient.cpp:
(WebKit::InjectedBundlePageResourceLoadClient::willSendRequestForFrame):
Use an HTTP body if the client's willSendRequestForFrame returned one.
This is the functional change of this patch.

Tools:

* WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl:
* WebKitTestRunner/InjectedBundle/InjectedBundlePage.cpp:
(WTR::InjectedBundlePage::willSendRequestForFrame):
* WebKitTestRunner/InjectedBundle/TestRunner.h:
(WTR::TestRunner::setWillSendRequestReturnsNull):
(WTR::TestRunner::willSendRequestReturnsNullOnRedirect):
(WTR::TestRunner::setWillSendRequestReturnsNullOnRedirect):
(WTR::TestRunner::setWillSendRequestAddsHTTPBody):
(WTR::TestRunner::willSendRequestHTTPBody):
Added setWillSendRequestAddsHTTPBody that uses new SPI for testing.

LayoutTests:

* TestExpectations:
* http/tests/misc/resources/post-echo.cgi: Copied from LayoutTests/http/tests/xmlhttprequest/resources/post-echo.cgi.
* http/tests/misc/will-send-request-with-client-provided-http-body-expected.txt: Added.
* http/tests/misc/will-send-request-with-client-provided-http-body.html: Added.
* platform/wk2/TestExpectations:
New test for WK2 only.

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

15 files changed:
LayoutTests/ChangeLog
LayoutTests/TestExpectations
LayoutTests/http/tests/misc/resources/post-echo.cgi [new file with mode: 0755]
LayoutTests/http/tests/misc/will-send-request-with-client-provided-http-body-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/misc/will-send-request-with-client-provided-http-body.html [new file with mode: 0644]
LayoutTests/platform/wk2/TestExpectations
Source/WebKit2/ChangeLog
Source/WebKit2/Shared/API/c/WKURLRequest.cpp
Source/WebKit2/Shared/API/c/WKURLRequest.h
Source/WebKit2/Shared/API/c/mac/WKURLRequestNS.mm
Source/WebKit2/WebProcess/InjectedBundle/InjectedBundlePageResourceLoadClient.cpp
Tools/ChangeLog
Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl
Tools/WebKitTestRunner/InjectedBundle/InjectedBundlePage.cpp
Tools/WebKitTestRunner/InjectedBundle/TestRunner.h

index 852e0c0..442df3a 100644 (file)
@@ -1,3 +1,18 @@
+2015-12-10  Alex Christensen  <achristensen@webkit.org>
+
+        REGRESSION (r192796) WKBundlePageResourceLoadClient should be able to setHTTPBody in willSendRequestForFrame
+        https://bugs.webkit.org/show_bug.cgi?id=152022
+        rdar://problem/23763584
+
+        Reviewed by Darin Adler.
+
+        * TestExpectations:
+        * http/tests/misc/resources/post-echo.cgi: Copied from LayoutTests/http/tests/xmlhttprequest/resources/post-echo.cgi.
+        * http/tests/misc/will-send-request-with-client-provided-http-body-expected.txt: Added.
+        * http/tests/misc/will-send-request-with-client-provided-http-body.html: Added.
+        * platform/wk2/TestExpectations:
+        New test for WK2 only.
+
 2015-12-10  Enrica Casucci  <enrica@apple.com>
 
         Change skin tone support for two emoji.
index f63160f..1c0446d 100644 (file)
@@ -42,8 +42,9 @@ fast/events/mouse-force-up.html [ Skip ]
 quicklook [ Skip ]
 http/tests/quicklook [ Skip ]
 
-# This test is WebKit2-only
+# These tests are WebKit2-only
 http/tests/appcache/decide-navigation-policy-after-delay.html [ Skip ]
+http/tests/misc/will-send-request-with-client-provided-http-body.html [ Skip ]
 
 # Only Mac and iOS have an implementation of UIScriptController::doAsyncTask().
 fast/harness/ui-side-scripts.html [ Skip ]
diff --git a/LayoutTests/http/tests/misc/resources/post-echo.cgi b/LayoutTests/http/tests/misc/resources/post-echo.cgi
new file mode 100755 (executable)
index 0000000..bbf6d16
--- /dev/null
@@ -0,0 +1,10 @@
+#!/usr/bin/perl -w
+
+print "Content-type: text/plain\n\n"; 
+
+if ($ENV{'REQUEST_METHOD'} eq "POST") {
+    read(STDIN, $request, $ENV{'CONTENT_LENGTH'}) || die "Could not get query\n";
+    print $request;
+} else {
+    print "Wrong method: " . $ENV{'REQUEST_METHOD'} . "\n";
+} 
diff --git a/LayoutTests/http/tests/misc/will-send-request-with-client-provided-http-body-expected.txt b/LayoutTests/http/tests/misc/will-send-request-with-client-provided-http-body-expected.txt
new file mode 100644 (file)
index 0000000..e840dbe
--- /dev/null
@@ -0,0 +1,5 @@
+This tests that the http body set by willSendRequestForFrame is sent.
+
+Request body before setWillSendRequestAddsHTTPBody: This body should be sent
+Request body after setWillSendRequestAddsHTTPBody: This body should also be sent
+
diff --git a/LayoutTests/http/tests/misc/will-send-request-with-client-provided-http-body.html b/LayoutTests/http/tests/misc/will-send-request-with-client-provided-http-body.html
new file mode 100644 (file)
index 0000000..5f9d453
--- /dev/null
@@ -0,0 +1,34 @@
+<p>This tests that the http body set by willSendRequestForFrame is sent.</p>
+<pre id="console"></pre>
+<script>
+    if (window.testRunner) {
+        testRunner.dumpAsText();
+        testRunner.waitUntilDone();
+    }
+
+    function log(msg)
+    {
+        document.getElementById('console').appendChild(document.createTextNode(msg + "\n"));
+    }
+
+    var xhr1 = new XMLHttpRequest();
+    xhr1.onreadystatechange = function () {
+        if (xhr1.readyState == 4){
+            log("Request body before setWillSendRequestAddsHTTPBody: " + xhr1.responseText);
+            testRunner.setWillSendRequestAddsHTTPBody("This body should also be sent");
+            
+            var xhr2 = new XMLHttpRequest();
+            xhr2.onreadystatechange = function () {
+                if (xhr2.readyState == 4){
+                    log("Request body after setWillSendRequestAddsHTTPBody: " + xhr2.responseText);
+                    if (window.testRunner)
+                        testRunner.notifyDone();
+                }            
+            }
+            xhr2.open("POST", "resources/post-echo.cgi");
+            xhr2.send("This body should not be sent because of setWillSendRequestHTTPBody");
+        }
+    };
+    xhr1.open("POST", "resources/post-echo.cgi");
+    xhr1.send("This body should be sent");
+</script>
index 8662fd9..d73e22a 100644 (file)
@@ -729,6 +729,9 @@ webkit.org/b/115274 http/tests/security/contentSecurityPolicy/report-same-origin
 fast/images/animated-gif-no-layout.html [ Pass ]
 fast/images/gif-loop-count.html [ Pass ]
 
+# DumpRenderTree does not implement setWillSendRequestHTTPBody
+http/tests/misc/will-send-request-with-client-provided-http-body.html [ Pass ]
+
 ### END OF (5) Progressions, expected successes that are expected failures in WebKit1.
 ########################################
 
index 6bd887d..972c71f 100644 (file)
@@ -1,3 +1,25 @@
+2015-12-10  Alex Christensen  <achristensen@webkit.org>
+
+        REGRESSION (r192796) WKBundlePageResourceLoadClient should be able to setHTTPBody in willSendRequestForFrame
+        https://bugs.webkit.org/show_bug.cgi?id=152022
+        rdar://problem/23763584
+
+        Reviewed by Darin Adler.
+
+        * Shared/API/c/WKURLRequest.cpp:
+        (WKURLRequestCopyHTTPMethod):
+        (WKURLRequestCopyWithHTTPBody):
+        (WKURLRequestSetDefaultTimeoutInterval):
+        * Shared/API/c/WKURLRequest.h:
+        Make WKURLRequestCopyWithHTTPBody SPI for testing.
+        * Shared/API/c/mac/WKURLRequestNS.mm:
+        (WKURLRequestCreateWithNSURLRequest):
+        Crash if someone tries to use an NSURLRequest with HTTPBodyStream, which will not work with the network process.
+        * WebProcess/InjectedBundle/InjectedBundlePageResourceLoadClient.cpp:
+        (WebKit::InjectedBundlePageResourceLoadClient::willSendRequestForFrame):
+        Use an HTTP body if the client's willSendRequestForFrame returned one.
+        This is the functional change of this patch.
+
 2015-12-10  Zan Dobersek  <zdobersek@igalia.com>
 
         [CoordinatedGraphics] Reserve capacity for the children vector in CoordinatedGraphicsScene::setLayerChildrenIfNeeded()
index 1a337b2..736e1f3 100644 (file)
@@ -28,6 +28,7 @@
 
 #include "APIURLRequest.h"
 #include "WKAPICast.h"
+#include "WKData.h"
 #include <WebCore/URL.h>
 
 using namespace WebCore;
@@ -58,6 +59,13 @@ WKStringRef WKURLRequestCopyHTTPMethod(WKURLRequestRef requestRef)
     return toCopiedAPI(toImpl(requestRef)->resourceRequest().httpMethod());
 }
 
+WKURLRequestRef WKURLRequestCopySettingHTTPBody(WKURLRequestRef requestRef, WKDataRef body)
+{
+    WebCore::ResourceRequest requestCopy(toImpl(requestRef)->resourceRequest());
+    requestCopy.setHTTPBody(FormData::create(WKDataGetBytes(body), WKDataGetSize(body)));
+    return toAPI(&API::URLRequest::create(requestCopy).leakRef());
+}
+
 void WKURLRequestSetDefaultTimeoutInterval(double timeoutInterval)
 {
     API::URLRequest::setDefaultTimeoutInterval(timeoutInterval);
index c7418c3..1741804 100644 (file)
@@ -42,6 +42,8 @@ WK_EXPORT WKURLRef WKURLRequestCopyFirstPartyForCookies(WKURLRequestRef);
 
 WK_EXPORT WKStringRef WKURLRequestCopyHTTPMethod(WKURLRequestRef);
 
+WK_EXPORT WKURLRequestRef WKURLRequestCopySettingHTTPBody(WKURLRequestRef, WKDataRef);
+
 WK_EXPORT void WKURLRequestSetDefaultTimeoutInterval(double);
 
 #ifdef __cplusplus
index aadddd1..611ded6 100644 (file)
@@ -34,6 +34,8 @@ using namespace WebKit;
 
 WKURLRequestRef WKURLRequestCreateWithNSURLRequest(NSURLRequest* urlRequest)
 {
+    if ([urlRequest HTTPBodyStream])
+        return nullptr;
     RetainPtr<NSURLRequest> copiedURLRequest = adoptNS([urlRequest copy]);
     return toAPI(&API::URLRequest::create(copiedURLRequest.get()).leakRef());
 }
index b4910a6..b92df47 100644 (file)
@@ -49,10 +49,15 @@ void InjectedBundlePageResourceLoadClient::willSendRequestForFrame(WebPage* page
         return;
 
     RefPtr<API::URLRequest> returnedRequest = adoptRef(toImpl(m_client.willSendRequestForFrame(toAPI(page), toAPI(frame), identifier, toAPI(request), toAPI(redirectResponse), m_client.base.clientInfo)));
-    if (returnedRequest)
-        request.updateFromDelegatePreservingOldProperties(returnedRequest->resourceRequest());
-    else
-        request = ResourceRequest();
+    if (returnedRequest) {
+        // If the client returned an HTTP body, we want to use that http body. This is needed to fix <rdar://problem/23763584>
+        auto& returnedResourceRequest = returnedRequest->resourceRequest();
+        RefPtr<FormData> returnedHTTPBody = returnedResourceRequest.httpBody();
+        request.updateFromDelegatePreservingOldProperties(returnedResourceRequest);
+        if (returnedHTTPBody)
+            request.setHTTPBody(WTF::move(returnedHTTPBody));
+    } else
+        request = { };
 }
 
 void InjectedBundlePageResourceLoadClient::didReceiveResponseForResource(WebPage* page, WebFrame* frame, uint64_t identifier, const WebCore::ResourceResponse& response)
index 8dfaa70..51e4407 100644 (file)
@@ -1,3 +1,22 @@
+2015-12-10  Alex Christensen  <achristensen@webkit.org>
+
+        REGRESSION (r192796) WKBundlePageResourceLoadClient should be able to setHTTPBody in willSendRequestForFrame
+        https://bugs.webkit.org/show_bug.cgi?id=152022
+        rdar://problem/23763584
+
+        Reviewed by Darin Adler.
+
+        * WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl:
+        * WebKitTestRunner/InjectedBundle/InjectedBundlePage.cpp:
+        (WTR::InjectedBundlePage::willSendRequestForFrame):
+        * WebKitTestRunner/InjectedBundle/TestRunner.h:
+        (WTR::TestRunner::setWillSendRequestReturnsNull):
+        (WTR::TestRunner::willSendRequestReturnsNullOnRedirect):
+        (WTR::TestRunner::setWillSendRequestReturnsNullOnRedirect):
+        (WTR::TestRunner::setWillSendRequestAddsHTTPBody):
+        (WTR::TestRunner::willSendRequestHTTPBody):
+        Added setWillSendRequestAddsHTTPBody that uses new SPI for testing.
+
 2015-12-10  Aakash Jain  <aakash_jain@apple.com>
 
         Remove additional simulator checks before running layout-tests
index 52eae35..19f180e 100644 (file)
@@ -135,6 +135,7 @@ interface TestRunner {
 
     void setWillSendRequestReturnsNull(boolean flag);
     void setWillSendRequestReturnsNullOnRedirect(boolean flag);
+    void setWillSendRequestAddsHTTPBody(DOMString body);
     
     void setShouldStayOnPageAfterHandlingBeforeUnload(boolean flag);
 
index 16361bd..d3a3638 100644 (file)
@@ -1166,6 +1166,14 @@ WKURLRequestRef InjectedBundlePage::willSendRequestForFrame(WKBundlePageRef page
             return nullptr;
         }
     }
+    
+    if (injectedBundle.isTestRunning()) {
+        String body = injectedBundle.testRunner()->willSendRequestHTTPBody();
+        if (!body.isEmpty()) {
+            CString cBody = body.utf8();
+            return WKURLRequestCopySettingHTTPBody(request, WKDataCreate(reinterpret_cast<const unsigned char*>(cBody.data()), cBody.length()));
+        }
+    }
 
     WKRetain(request);
     return request;
index e5a9642..29632f4 100644 (file)
 #define TestRunner_h
 
 #include "JSWrappable.h"
+#include "StringFunctions.h"
 #include <JavaScriptCore/JSRetainPtr.h>
 #include <WebKit/WKBundleScriptWorld.h>
 #include <WebKit/WKRetainPtr.h>
 #include <string>
 #include <wtf/PassRefPtr.h>
+#include <wtf/text/WTFString.h>
 
 #if PLATFORM(COCOA)
 #include <wtf/RetainPtr.h>
@@ -210,6 +212,8 @@ public:
     void setWillSendRequestReturnsNull(bool f) { m_willSendRequestReturnsNull = f; }
     bool willSendRequestReturnsNullOnRedirect() const { return m_willSendRequestReturnsNullOnRedirect; }
     void setWillSendRequestReturnsNullOnRedirect(bool f) { m_willSendRequestReturnsNullOnRedirect = f; }
+    void setWillSendRequestAddsHTTPBody(JSStringRef body) { m_willSendRequestHTTPBody = toWTFString(toWK(body)); }
+    String willSendRequestHTTPBody() const { return m_willSendRequestHTTPBody; }
 
     void setTextDirection(JSStringRef);
 
@@ -343,6 +347,7 @@ private:
     bool m_willSendRequestReturnsNull;
     bool m_willSendRequestReturnsNullOnRedirect;
     bool m_shouldStopProvisionalFrameLoads;
+    String m_willSendRequestHTTPBody;
 
     bool m_policyDelegateEnabled;
     bool m_policyDelegatePermissive;