Title: [273023] trunk
Revision
273023
Author
bfulg...@apple.com
Date
2021-02-17 13:26:08 -0800 (Wed, 17 Feb 2021)

Log Message

Expand stubs to thread actual NSURLRequest/NSURLResponse for the new simulated-request API
https://bugs.webkit.org/show_bug.cgi?id=221641
<rdar://problem/74166568>

Reviewed by Chris Dumez.

Source/WebKit:

Tested by new API Test LoadSimulatedRequestUpdatesBackForwardList.

This bug builds on the stubs created in Bug 221430 to use actual Request and
Response objects for simulated loads:

1. Thread the NSURLRequest and NSURLResponse objects to the loading layer when handling loads
   for HTML strings and data.
2. Loads via the simulated request API should cause entries to be added to the back/forward list.
3. Create a new API Test to confirm the back/forward list works as expected.

* UIProcess/API/APINavigation.cpp:
(API::SubstituteData::SubstituteData): New convenience constructor accepting a ResourceResponse.
(API::Navigation::Navigation): Ditto.
* UIProcess/API/APINavigation.h:
(API::Navigation::create): Added.
* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView loadSimulatedRequest:withResponse:responseData:]): Switch from using the plain 'loadData'
method to the new 'loadSimulatedRequest' implementation.
* UIProcess/WebNavigationState.cpp:
(WebKit::WebNavigationState::createSimulatedLoadWithDataNavigation): Added.
* UIProcess/WebNavigationState.h:
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::loadSimulatedRequest): New method to support the loadSimulatedRequest WKWebView API.
* UIProcess/WebPageProxy.h:
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::loadSimulatedRequestAndResponse): Added message handler to perform a simulated load using
ResourceRequest and ResourceResponse objects.
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in: Added LoadSimulatedRequestAndResponse IPC message.

Tools:

Add a new test to confirm that simulated loads work and are properly added to the
back-forward list.

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

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (273022 => 273023)


--- trunk/Source/WebKit/ChangeLog	2021-02-17 21:15:53 UTC (rev 273022)
+++ trunk/Source/WebKit/ChangeLog	2021-02-17 21:26:08 UTC (rev 273023)
@@ -1,3 +1,41 @@
+2021-02-17  Brent Fulgham  <bfulg...@apple.com>
+
+        Expand stubs to thread actual NSURLRequest/NSURLResponse for the new simulated-request API
+        https://bugs.webkit.org/show_bug.cgi?id=221641
+        <rdar://problem/74166568>
+
+        Reviewed by Chris Dumez.
+
+        Tested by new API Test LoadSimulatedRequestUpdatesBackForwardList.
+
+        This bug builds on the stubs created in Bug 221430 to use actual Request and
+        Response objects for simulated loads:
+
+        1. Thread the NSURLRequest and NSURLResponse objects to the loading layer when handling loads
+           for HTML strings and data.
+        2. Loads via the simulated request API should cause entries to be added to the back/forward list.
+        3. Create a new API Test to confirm the back/forward list works as expected.
+
+        * UIProcess/API/APINavigation.cpp:
+        (API::SubstituteData::SubstituteData): New convenience constructor accepting a ResourceResponse.
+        (API::Navigation::Navigation): Ditto.
+        * UIProcess/API/APINavigation.h:
+        (API::Navigation::create): Added.
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView loadSimulatedRequest:withResponse:responseData:]): Switch from using the plain 'loadData'
+        method to the new 'loadSimulatedRequest' implementation.
+        * UIProcess/WebNavigationState.cpp:
+        (WebKit::WebNavigationState::createSimulatedLoadWithDataNavigation): Added.
+        * UIProcess/WebNavigationState.h:
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::loadSimulatedRequest): New method to support the loadSimulatedRequest WKWebView API.
+        * UIProcess/WebPageProxy.h:
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::loadSimulatedRequestAndResponse): Added message handler to perform a simulated load using
+        ResourceRequest and ResourceResponse objects.
+        * WebProcess/WebPage/WebPage.h:
+        * WebProcess/WebPage/WebPage.messages.in: Added LoadSimulatedRequestAndResponse IPC message.
+
 2021-02-17  Fujii Hironori  <hironori.fu...@sony.com>
 
         [CoordinatedGraphics] The whole content is unnecessarily repainted by animations in non-AC mode pages

Modified: trunk/Source/WebKit/UIProcess/API/APINavigation.cpp (273022 => 273023)


--- trunk/Source/WebKit/UIProcess/API/APINavigation.cpp	2021-02-17 21:15:53 UTC (rev 273022)
+++ trunk/Source/WebKit/UIProcess/API/APINavigation.cpp	2021-02-17 21:26:08 UTC (rev 273023)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2015 Apple Inc. All rights reserved.
+ * Copyright (C) 2015-2021 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -28,6 +28,7 @@
 
 #include "WebBackForwardListItem.h"
 #include "WebNavigationState.h"
+#include <WebCore/ResourceRequest.h>
 #include <wtf/DebugUtilities.h>
 #include <wtf/HexNumber.h>
 
@@ -37,6 +38,11 @@
 
 static constexpr Seconds navigationActivityTimeout { 30_s };
 
+SubstituteData::SubstituteData(Vector<uint8_t>&& content, const ResourceResponse& response, API::Object* userData)
+    : SubstituteData(WTFMove(content), response.mimeType(), response.textEncodingName(), response.url().string(), userData)
+{
+}
+
 Navigation::Navigation(WebNavigationState& state)
     : m_navigationID(state.generateNavigationID())
     , m_clientNavigationActivity(navigationActivityTimeout)
@@ -78,6 +84,13 @@
     m_substituteData = WTFMove(substituteData);
 }
 
+Navigation::Navigation(WebKit::WebNavigationState& state, WebCore::ResourceRequest&& simulatedRequest, std::unique_ptr<SubstituteData>&& substituteData, WebKit::WebBackForwardListItem* fromItem)
+    : Navigation(state, WTFMove(simulatedRequest), fromItem)
+{
+    ASSERT(substituteData);
+    m_substituteData = WTFMove(substituteData);
+}
+
 Navigation::~Navigation()
 {
 }

Modified: trunk/Source/WebKit/UIProcess/API/APINavigation.h (273022 => 273023)


--- trunk/Source/WebKit/UIProcess/API/APINavigation.h	2021-02-17 21:15:53 UTC (rev 273022)
+++ trunk/Source/WebKit/UIProcess/API/APINavigation.h	2021-02-17 21:26:08 UTC (rev 273023)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2015 Apple Inc. All rights reserved.
+ * Copyright (C) 2015-2021 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -41,6 +41,7 @@
 
 namespace WebCore {
 enum class FrameLoadType : uint8_t;
+class ResourceResponse;
 }
 
 namespace WebKit {
@@ -60,6 +61,8 @@
         , userData(userData)
     { }
 
+    SubstituteData(Vector<uint8_t>&& content, const WebCore::ResourceResponse&, API::Object* userData);
+
     Vector<uint8_t> content;
     WTF::String MIMEType;
     WTF::String encoding;
@@ -90,6 +93,11 @@
         return adoptRef(*new Navigation(state, WTFMove(substituteData)));
     }
 
+    static Ref<Navigation> create(WebKit::WebNavigationState& state, WebCore::ResourceRequest&& simulatedRequest, std::unique_ptr<SubstituteData>&& substituteData, WebKit::WebBackForwardListItem* fromItem)
+    {
+        return adoptRef(*new Navigation(state, WTFMove(simulatedRequest), WTFMove(substituteData), fromItem));
+    }
+
     virtual ~Navigation();
 
     uint64_t navigationID() const { return m_navigationID; }
@@ -166,6 +174,7 @@
     Navigation(WebKit::WebNavigationState&, WebCore::ResourceRequest&&, WebKit::WebBackForwardListItem* fromItem);
     Navigation(WebKit::WebNavigationState&, WebKit::WebBackForwardListItem& targetItem, WebKit::WebBackForwardListItem* fromItem, WebCore::FrameLoadType);
     Navigation(WebKit::WebNavigationState&, std::unique_ptr<SubstituteData>&&);
+    Navigation(WebKit::WebNavigationState&, WebCore::ResourceRequest&&, std::unique_ptr<SubstituteData>&&, WebKit::WebBackForwardListItem* fromItem);
 
     uint64_t m_navigationID;
     WebCore::ResourceRequest m_originalRequest;

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm (273022 => 273023)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm	2021-02-17 21:15:53 UTC (rev 273022)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm	2021-02-17 21:26:08 UTC (rev 273023)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2014-2020 Apple Inc. All rights reserved.
+ * Copyright (C) 2014-2021 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -2105,7 +2105,7 @@
 
 - (WKNavigation *)loadSimulatedRequest:(NSURLRequest *)request withResponse:(NSURLResponse *)response responseData:(NSData *)data
 {
-    return wrapper(_page->loadData({ static_cast<const uint8_t*>(data.bytes), data.length }, response.MIMEType, response.textEncodingName, request.URL.absoluteString));
+    return wrapper(_page->loadSimulatedRequest(request, response, { static_cast<const uint8_t*>(data.bytes), data.length }));
 }
 
 - (WKNavigation *)loadSimulatedRequest:(NSURLRequest *)request withResponseHTMLString:(NSString *)string

Modified: trunk/Source/WebKit/UIProcess/WebNavigationState.cpp (273022 => 273023)


--- trunk/Source/WebKit/UIProcess/WebNavigationState.cpp	2021-02-17 21:15:53 UTC (rev 273022)
+++ trunk/Source/WebKit/UIProcess/WebNavigationState.cpp	2021-02-17 21:26:08 UTC (rev 273023)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2015 Apple Inc. All rights reserved.
+ * Copyright (C) 2015-2021 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -77,6 +77,15 @@
     return navigation;
 }
 
+Ref<API::Navigation> WebNavigationState::createSimulatedLoadWithDataNavigation(WebCore::ResourceRequest&& request, std::unique_ptr<API::SubstituteData>&& substituteData, WebBackForwardListItem* currentItem)
+{
+    auto navigation = API::Navigation::create(*this, WTFMove(request), WTFMove(substituteData), currentItem);
+
+    m_navigations.set(navigation->navigationID(), navigation.ptr());
+
+    return navigation;
+}
+
 API::Navigation* WebNavigationState::navigation(uint64_t navigationID)
 {
     ASSERT(navigationID);

Modified: trunk/Source/WebKit/UIProcess/WebNavigationState.h (273022 => 273023)


--- trunk/Source/WebKit/UIProcess/WebNavigationState.h	2021-02-17 21:15:53 UTC (rev 273022)
+++ trunk/Source/WebKit/UIProcess/WebNavigationState.h	2021-02-17 21:26:08 UTC (rev 273023)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2015 Apple Inc. All rights reserved.
+ * Copyright (C) 2015-2021 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -54,6 +54,7 @@
     Ref<API::Navigation> createLoadRequestNavigation(WebCore::ResourceRequest&&, WebBackForwardListItem* currentItem);
     Ref<API::Navigation> createReloadNavigation(WebBackForwardListItem* currentAndTargetItem);
     Ref<API::Navigation> createLoadDataNavigation(std::unique_ptr<API::SubstituteData>&&);
+    Ref<API::Navigation> createSimulatedLoadWithDataNavigation(WebCore::ResourceRequest&&, std::unique_ptr<API::SubstituteData>&&, WebBackForwardListItem* currentItem);
 
     bool hasNavigation(uint64_t navigationID) const { return m_navigations.contains(navigationID); }
     API::Navigation* navigation(uint64_t navigationID);

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.cpp (273022 => 273023)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2021-02-17 21:15:53 UTC (rev 273022)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2021-02-17 21:26:08 UTC (rev 273023)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010-2020 Apple Inc. All rights reserved.
+ * Copyright (C) 2010-2021 Apple Inc. All rights reserved.
  * Copyright (C) 2012 Intel Corporation. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -1472,6 +1472,59 @@
     process->startResponsivenessTimer();
 }
 
+RefPtr<API::Navigation> WebPageProxy::loadSimulatedRequest(WebCore::ResourceRequest&& simulatedRequest, WebCore::ResourceResponse&& simulatedResponse, const IPC::DataReference& data)
+{
+    RELEASE_LOG_IF_ALLOWED(Loading, "loadSimulatedRequest:");
+
+#if ENABLE(APP_BOUND_DOMAINS)
+    if (simulatedResponse.mimeType() == "text/html"_s && !isFullWebBrowser())
+        m_limitsNavigationsToAppBoundDomains = true;
+#endif
+
+    if (m_isClosed) {
+        RELEASE_LOG_IF_ALLOWED(Loading, "loadSimulatedRequest: page is closed");
+        return nullptr;
+    }
+
+    if (!hasRunningProcess())
+        launchProcess(RegistrableDomain { simulatedRequest.url() }, ProcessLaunchReason::InitialProcess);
+
+    auto navigation = m_navigationState->createSimulatedLoadWithDataNavigation(ResourceRequest(simulatedRequest), makeUnique<API::SubstituteData>(data.vector(), ResourceResponse(simulatedResponse), nullptr), m_backForwardList->currentItem());
+
+    if (shouldForceForegroundPriorityForClientNavigation())
+        navigation->setClientNavigationActivity(process().throttler().foregroundActivity("Client navigation"_s));
+
+    auto transaction = m_pageLoadState.transaction();
+
+    auto baseURL = simulatedRequest.url().string();
+    simulatedResponse.setURL(simulatedRequest.url()); // These should always match for simulated load
+
+    m_pageLoadState.setPendingAPIRequest(transaction, { navigation->navigationID(), !baseURL.isEmpty() ? baseURL : aboutBlankURL().string() });
+
+    LoadParameters loadParameters;
+    loadParameters.navigationID = navigation->navigationID();
+    loadParameters.request = WTFMove(simulatedRequest);
+    loadParameters.data = ""
+    loadParameters.MIMEType = simulatedResponse.mimeType();
+    loadParameters.encodingName = simulatedResponse.textEncodingName();
+    loadParameters.baseURLString = baseURL;
+    loadParameters.shouldOpenExternalURLsPolicy = WebCore::ShouldOpenExternalURLsPolicy::ShouldNotAllow;
+    loadParameters.shouldTreatAsContinuingLoad = false;
+    loadParameters.lockHistory = navigation->lockHistory();
+    loadParameters.lockBackForwardList = navigation->lockBackForwardList();
+    loadParameters.clientRedirectSourceForHistory = navigation->clientRedirectSourceForHistory();
+    loadParameters.isNavigatingToAppBoundDomain = isNavigatingToAppBoundDomain();
+
+    simulatedResponse.setExpectedContentLength(data.size());
+
+    addPlatformLoadParameters(m_process, loadParameters);
+
+    m_process->assumeReadAccessToBaseURL(*this, baseURL);
+    m_process->send(Messages::WebPage::LoadSimulatedRequestAndResponse(loadParameters, simulatedResponse), m_webPageID);
+    m_process->startResponsivenessTimer();
+    return navigation;
+}
+
 void WebPageProxy::loadAlternateHTML(const IPC::DataReference& htmlData, const String& encoding, const URL& baseURL, const URL& unreachableURL, API::Object* userData)
 {
     RELEASE_LOG_IF_ALLOWED(Loading, "loadAlternateHTML");

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.h (273022 => 273023)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.h	2021-02-17 21:15:53 UTC (rev 273022)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.h	2021-02-17 21:26:08 UTC (rev 273023)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010-2020 Apple Inc. All rights reserved.
+ * Copyright (C) 2010-2021 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -593,6 +593,7 @@
     RefPtr<API::Navigation> loadRequest(WebCore::ResourceRequest&&, WebCore::ShouldOpenExternalURLsPolicy = WebCore::ShouldOpenExternalURLsPolicy::ShouldAllowExternalSchemesButNotAppLinks, API::Object* userData = nullptr);
     RefPtr<API::Navigation> loadFile(const String& fileURL, const String& resourceDirectoryURL, API::Object* userData = nullptr);
     RefPtr<API::Navigation> loadData(const IPC::DataReference&, const String& MIMEType, const String& encoding, const String& baseURL, API::Object* userData = nullptr, WebCore::ShouldOpenExternalURLsPolicy = WebCore::ShouldOpenExternalURLsPolicy::ShouldNotAllow);
+    RefPtr<API::Navigation> loadSimulatedRequest(WebCore::ResourceRequest&&, WebCore::ResourceResponse&&, const IPC::DataReference&);
     void loadAlternateHTML(const IPC::DataReference&, const String& encoding, const URL& baseURL, const URL& unreachableURL, API::Object* userData = nullptr);
     void loadWebArchiveData(API::Data*, API::Object* userData = nullptr);
     void navigateToPDFLinkWithSimulatedClick(const String& url, WebCore::IntPoint documentPoint, WebCore::IntPoint screenPoint);

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp (273022 => 273023)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp	2021-02-17 21:15:53 UTC (rev 273022)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp	2021-02-17 21:26:08 UTC (rev 273023)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010-2020 Apple Inc. All rights reserved.
+ * Copyright (C) 2010-2021 Apple Inc. All rights reserved.
  * Copyright (C) 2012 Intel Corporation. All rights reserved.
  * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
  *
@@ -1721,6 +1721,45 @@
     m_mainFrame->coreFrame()->loader().setProvisionalLoadErrorBeingHandledURL({ });
 }
 
+void WebPage::loadSimulatedRequestAndResponse(LoadParameters&& loadParameters, ResourceResponse&& simulatedResponse)
+{
+    ASSERT(simulatedResponse.url() == loadParameters.request.url());
+    ASSERT(simulatedResponse.mimeType() == loadParameters.MIMEType);
+    ASSERT(simulatedResponse.textEncodingName() == loadParameters.encodingName);
+    ASSERT(static_cast<size_t>(simulatedResponse.expectedContentLength()) == loadParameters.data.size());
+
+    platformDidReceiveLoadParameters(loadParameters);
+
+    auto sharedBuffer = SharedBuffer::create(reinterpret_cast<const char*>(loadParameters.data.data()), loadParameters.data.size());
+
+#if ENABLE(APP_BOUND_DOMAINS)
+    setIsNavigatingToAppBoundDomain(loadParameters.isNavigatingToAppBoundDomain, &m_mainFrame.get());
+#endif
+
+    SendStopResponsivenessTimer stopper;
+
+    m_pendingNavigationID = loadParameters.navigationID;
+    m_pendingWebsitePolicies = WTFMove(loadParameters.websitePolicies);
+
+    SubstituteData substituteData(WTFMove(sharedBuffer), loadParameters.request.url(), 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.
+    m_loaderClient->willLoadDataRequest(*this, loadParameters.request, const_cast<SharedBuffer*>(substituteData.content()), substituteData.mimeType(), substituteData.textEncoding(), substituteData.failingURL(), WebProcess::singleton().transformHandlesToObjects(loadParameters.userData.object()).get());
+
+    // Initate the load in WebCore.
+    FrameLoadRequest frameLoadRequest(*m_mainFrame->coreFrame(), loadParameters.request, substituteData);
+    frameLoadRequest.setShouldOpenExternalURLsPolicy(loadParameters.shouldOpenExternalURLsPolicy);
+    frameLoadRequest.setShouldTreatAsContinuingLoad(loadParameters.shouldTreatAsContinuingLoad);
+    frameLoadRequest.setLockHistory(loadParameters.lockHistory);
+    frameLoadRequest.setLockBackForwardList(loadParameters.lockBackForwardList);
+    frameLoadRequest.setClientRedirectSourceForHistory(loadParameters.clientRedirectSourceForHistory);
+    frameLoadRequest.setIsRequestFromClientOrUserInput();
+
+    // FIXME: Should this be "corePage()->userInputBridge().loadRequest(WTFMove(frameLoadRequest));"?
+    m_mainFrame->coreFrame()->loader().load(WTFMove(frameLoadRequest));
+}
+
 void WebPage::navigateToPDFLinkWithSimulatedClick(const String& url, IntPoint documentPoint, IntPoint screenPoint)
 {
     Frame* mainFrame = m_mainFrame->coreFrame();

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.h (273022 => 273023)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.h	2021-02-17 21:15:53 UTC (rev 273022)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.h	2021-02-17 21:26:08 UTC (rev 273023)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010-2020 Apple Inc. All rights reserved.
+ * Copyright (C) 2010-2021 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -1506,6 +1506,7 @@
     NO_RETURN void loadRequestWaitingForProcessLaunch(LoadParameters&&, URL&&, WebPageProxyIdentifier, bool);
     void loadData(LoadParameters&&);
     void loadAlternateHTML(LoadParameters&&);
+    void loadSimulatedRequestAndResponse(LoadParameters&&, WebCore::ResourceResponse&&);
     void navigateToPDFLinkWithSimulatedClick(const String& url, WebCore::IntPoint documentPoint, WebCore::IntPoint screenPoint);
     void reload(uint64_t navigationID, uint32_t reloadOptions, SandboxExtension::Handle&&);
     void goToBackForwardItem(uint64_t navigationID, const WebCore::BackForwardItemIdentifier&, WebCore::FrameLoadType, WebCore::ShouldTreatAsContinuingLoad, Optional<WebsitePoliciesData>&&);

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in (273022 => 273023)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in	2021-02-17 21:15:53 UTC (rev 273022)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in	2021-02-17 21:26:08 UTC (rev 273023)
@@ -1,4 +1,4 @@
-# Copyright (C) 2010-2020 Apple Inc. All rights reserved.
+# Copyright (C) 2010-2021 Apple Inc. All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
 # modification, are permitted provided that the following conditions
@@ -179,6 +179,7 @@
     LoadRequest(struct WebKit::LoadParameters loadParameters)
     LoadRequestWaitingForProcessLaunch(struct WebKit::LoadParameters loadParameters, URL resourceDirectoryURL, WebKit::WebPageProxyIdentifier pageID, bool checkAssumedReadAccessToResourceURL)
     LoadData(struct WebKit::LoadParameters loadParameters)
+    LoadSimulatedRequestAndResponse(struct WebKit::LoadParameters loadParameters, WebCore::ResourceResponse simulatedResponse)
     LoadAlternateHTML(struct WebKit::LoadParameters loadParameters)
 
     NavigateToPDFLinkWithSimulatedClick(String url, WebCore::IntPoint documentPoint, WebCore::IntPoint screenPoint)

Modified: trunk/Tools/ChangeLog (273022 => 273023)


--- trunk/Tools/ChangeLog	2021-02-17 21:15:53 UTC (rev 273022)
+++ trunk/Tools/ChangeLog	2021-02-17 21:26:08 UTC (rev 273023)
@@ -1,3 +1,17 @@
+2021-02-17  Brent Fulgham  <bfulg...@apple.com>
+
+        Expand stubs to thread actual NSURLRequest/NSURLResponse for the new simulated-request API
+        https://bugs.webkit.org/show_bug.cgi?id=221641
+        <rdar://problem/74166568>
+
+        Reviewed by Chris Dumez.
+
+        Add a new test to confirm that simulated loads work and are properly added to the
+        back-forward list.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/WKWebViewLoadAPIs.mm:
+        (TEST):
+
 2021-02-17  Chris Dumez  <cdu...@apple.com>
 
         Use smart pointer for WebView ownership in DumpRenderTree

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebViewLoadAPIs.mm (273022 => 273023)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebViewLoadAPIs.mm	2021-02-17 21:15:53 UTC (rev 273022)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebViewLoadAPIs.mm	2021-02-17 21:26:08 UTC (rev 273023)
@@ -24,17 +24,22 @@
  */
 
 #import "config.h"
-#import <WebKit/WKFoundation.h>
 
 #import "PlatformUtilities.h"
 #import "Test.h"
 #import "TestNavigationDelegate.h"
+#import "TestWKWebView.h"
+#import <WebKit/WKFoundation.h>
 #import <WebKit/WKWebViewPrivate.h>
 #import <wtf/RetainPtr.h>
 #import <wtf/cocoa/NSURLExtras.h>
 
-static NSURL *exampleURL = [NSURL URLWithString:@"https://example.com"];
+static NSString *exampleURLString = @"https://example.com";
+static NSURL *exampleURL = [NSURL URLWithString:exampleURLString];
 static NSString *htmlString = @"<html><body><h1>Hello, world!</h1></body></html>";
+static NSString *exampleURLString2 = @"https://example.org";
+static NSURL *exampleURL2 = [NSURL URLWithString:exampleURLString2];
+static NSString *htmlString2 = @"<html><body><h1>Hello, new world!</h1></body></html>";
 
 TEST(WKWebView, LoadSimulatedRequestUsingResponseHTMLString)
 {
@@ -78,3 +83,52 @@
     [delegate waitForDidFinishNavigation];
     EXPECT_WK_STREQ(webView.get()._resourceDirectoryURL.path, file.URLByDeletingLastPathComponent.path);
 }
+
+TEST(WKWebView, LoadSimulatedRequestUpdatesBackForwardList)
+{
+    auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
+
+    auto delegate = adoptNS([[TestNavigationDelegate alloc] init]);
+    [webView setNavigationDelegate:delegate.get()];
+
+    NSURLRequest *loadRequest = [NSURLRequest requestWithURL:exampleURL];
+    [webView loadSimulatedRequest:loadRequest withResponseHTMLString:htmlString];
+    [delegate waitForDidFinishNavigation];
+
+    NSURLRequest *loadRequest2 = [NSURLRequest requestWithURL:exampleURL2];
+    [webView loadSimulatedRequest:loadRequest2 withResponseHTMLString:htmlString2];
+    [delegate waitForDidFinishNavigation];
+    
+    WKBackForwardList *list = [webView backForwardList];
+    EXPECT_WK_STREQ(exampleURLString2, [list.currentItem.URL absoluteString]);
+    EXPECT_EQ((NSUInteger)1, list.backList.count);
+    EXPECT_EQ((NSUInteger)0, list.forwardList.count);
+    EXPECT_TRUE(!list.forwardItem);
+    EXPECT_WK_STREQ(exampleURLString, [list.backItem.URL absoluteString]);
+    
+    EXPECT_TRUE([webView canGoBack]);
+    if (![webView canGoBack])
+        return;
+
+    [webView goBack];
+    [delegate waitForDidFinishNavigation];
+
+    EXPECT_WK_STREQ(exampleURLString, [list.currentItem.URL absoluteString]);
+    EXPECT_EQ((NSUInteger)0, list.backList.count);
+    EXPECT_EQ((NSUInteger)1, list.forwardList.count);
+    EXPECT_TRUE(!list.backItem);
+    EXPECT_WK_STREQ(exampleURLString2, [list.forwardItem.URL absoluteString]);
+
+    EXPECT_TRUE([webView canGoForward]);
+    if (![webView canGoForward])
+        return;
+
+    [webView goForward];
+    [delegate waitForDidFinishNavigation];
+
+    EXPECT_WK_STREQ(exampleURLString2, [list.currentItem.URL absoluteString]);
+    EXPECT_EQ((NSUInteger)1, list.backList.count);
+    EXPECT_EQ((NSUInteger)0, list.forwardList.count);
+    EXPECT_TRUE(!list.forwardItem);
+    EXPECT_WK_STREQ(exampleURLString, [list.backItem.URL absoluteString]);
+}
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to