Title: [279494] trunk
Revision
279494
Author
commit-qu...@webkit.org
Date
2021-07-01 18:45:31 -0700 (Thu, 01 Jul 2021)

Log Message

loadSimulatedRequest: should do same delegate callbacks as loadHTMLString and loadData
https://bugs.webkit.org/show_bug.cgi?id=227599

Patch by Alex Christensen <achristen...@webkit.org> on 2021-07-01
Reviewed by Chris Dumez.

Source/WebKit:

* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::loadSimulatedRequestAndResponse):

Tools:

* TestWebKitAPI/Tests/WebKitCocoa/WKWebViewLoadAPIs.mm:
(TEST):

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (279493 => 279494)


--- trunk/Source/WebKit/ChangeLog	2021-07-02 01:36:04 UTC (rev 279493)
+++ trunk/Source/WebKit/ChangeLog	2021-07-02 01:45:31 UTC (rev 279494)
@@ -1,3 +1,13 @@
+2021-07-01  Alex Christensen  <achristen...@webkit.org>
+
+        loadSimulatedRequest: should do same delegate callbacks as loadHTMLString and loadData
+        https://bugs.webkit.org/show_bug.cgi?id=227599
+
+        Reviewed by Chris Dumez.
+
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::loadSimulatedRequestAndResponse):
+
 2021-07-01  Youenn Fablet  <you...@apple.com>
 
         Disable relay for UDP sockets when not needed

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp (279493 => 279494)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp	2021-07-02 01:36:04 UTC (rev 279493)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp	2021-07-02 01:45:31 UTC (rev 279494)
@@ -1793,7 +1793,8 @@
     m_pendingNavigationID = loadParameters.navigationID;
     m_pendingWebsitePolicies = WTFMove(loadParameters.websitePolicies);
 
-    SubstituteData substituteData(WTFMove(sharedBuffer), loadParameters.request.url(), simulatedResponse, SubstituteData::SessionHistoryVisibility::Visible);
+    auto unreachableURL = loadParameters.unreachableURLString.isEmpty() ? URL() : URL(URL(), loadParameters.unreachableURLString);
+    SubstituteData substituteData(WTFMove(sharedBuffer), unreachableURL, simulatedResponse, SubstituteData::SessionHistoryVisibility::Visible);
 
     // Let the InjectedBundle know we are about to start the load, passing the user data from the UIProcess
     // to all the client to set up any needed state.

Modified: trunk/Tools/ChangeLog (279493 => 279494)


--- trunk/Tools/ChangeLog	2021-07-02 01:36:04 UTC (rev 279493)
+++ trunk/Tools/ChangeLog	2021-07-02 01:45:31 UTC (rev 279494)
@@ -1,3 +1,13 @@
+2021-07-01  Alex Christensen  <achristen...@webkit.org>
+
+        loadSimulatedRequest: should do same delegate callbacks as loadHTMLString and loadData
+        https://bugs.webkit.org/show_bug.cgi?id=227599
+
+        Reviewed by Chris Dumez.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/WKWebViewLoadAPIs.mm:
+        (TEST):
+
 2021-07-01  Jonathan Bedard  <jbed...@apple.com>
 
         [webkitscmpy] Cache identifiers in Git checkouts (Follow-up fix)

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebViewLoadAPIs.mm (279493 => 279494)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebViewLoadAPIs.mm	2021-07-02 01:36:04 UTC (rev 279493)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebViewLoadAPIs.mm	2021-07-02 01:45:31 UTC (rev 279494)
@@ -32,6 +32,7 @@
 #import <WebKit/WKFoundation.h>
 #import <WebKit/WKWebView.h>
 #import <wtf/RetainPtr.h>
+#import <wtf/Vector.h>
 #import <wtf/cocoa/NSURLExtras.h>
 
 static NSString *exampleURLString = @"https://example.com/";
@@ -82,6 +83,61 @@
     [delegate waitForDidFinishNavigation];
 }
 
+TEST(WKWebView, LoadSimulatedRequestDelegateCallbacks)
+{
+    enum class Callback : uint8_t {
+        NavigationAction,
+        NavigationResponse,
+        StartProvisional,
+        Commit,
+        Finish
+    };
+
+    auto checkCallbacks = [] (const Vector<Callback> vector) {
+        ASSERT_EQ(vector.size(), 4u);
+        EXPECT_EQ(vector[0], Callback::NavigationAction);
+        EXPECT_EQ(vector[1], Callback::StartProvisional);
+        EXPECT_EQ(vector[2], Callback::Commit);
+        EXPECT_EQ(vector[3], Callback::Finish);
+    };
+
+    __block Vector<Callback> callbacks;
+    __block bool finished = false;
+    auto delegate = adoptNS([TestNavigationDelegate new]);
+    delegate.get().decidePolicyForNavigationAction = ^(WKNavigationAction *, void (^completionHandler)(WKNavigationActionPolicy)) {
+        callbacks.append(Callback::NavigationAction);
+        completionHandler(WKNavigationActionPolicyAllow);
+    };
+    delegate.get().decidePolicyForNavigationResponse = ^(WKNavigationResponse *, void (^completionHandler)(WKNavigationResponsePolicy)) {
+        callbacks.append(Callback::NavigationResponse);
+        completionHandler(WKNavigationResponsePolicyAllow);
+    };
+    delegate.get().didStartProvisionalNavigation = ^(WKWebView *, WKNavigation *) {
+        callbacks.append(Callback::StartProvisional);
+    };
+    delegate.get().didCommitNavigation = ^(WKWebView *, WKNavigation *) {
+        callbacks.append(Callback::Commit);
+    };
+    delegate.get().didFinishNavigation = ^(WKWebView *, WKNavigation *) {
+        callbacks.append(Callback::Finish);
+        finished = true;
+    };
+
+    auto webView = adoptNS([WKWebView new]);
+    webView.get().navigationDelegate = delegate.get();
+    NSURL *url = "" URLWithString:@"https://webkit.org/"];
+    [webView loadHTMLString:@"hi!" baseURL:url];
+    TestWebKitAPI::Util::run(&finished);
+
+    checkCallbacks(callbacks);
+    callbacks = { };
+    finished = false;
+
+    [webView loadSimulatedRequest:[NSURLRequest requestWithURL:url] response:adoptNS([[NSURLResponse alloc] initWithURL:url MIMEType:@"text/html" expectedContentLength:3 textEncodingName:nil]).get() responseData:[NSData dataWithBytes:"hi!" length:3]];
+    TestWebKitAPI::Util::run(&finished);
+    checkCallbacks(callbacks);
+}
+
 TEST(WKWebView, LoadFileRequest)
 {
     auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to