<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[286505] trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/286505">286505</a></dd>
<dt>Author</dt> <dd>cdumez@apple.com</dd>
<dt>Date</dt> <dd>2021-12-03 11:39:02 -0800 (Fri, 03 Dec 2021)</dd>
</dl>

<h3>Log Message</h3>
<pre>Follow-up to <a href="http://trac.webkit.org/projects/webkit/changeset/286479">r286479</a> to add API test and address issues found by the test
https://bugs.webkit.org/show_bug.cgi?id=233798

Reviewed by Darin Adler.

Source/WebKit:

Add functionality needed for API testing and fix issues found by the API test.

* UIProcess/API/Cocoa/WKWebViewPrivateForTesting.h:
* UIProcess/API/Cocoa/WKWebViewTesting.mm:
(-[WKWebView _isLayerTreeFrozenForTesting:]):
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::destroyProvisionalPage):
(WebKit::WebPageProxy::isLayerTreeFrozen):
* UIProcess/WebPageProxy.h:
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::isLayerTreeFrozen):
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in:
Add new SPI to check if the layer tree is frozen in the WebProcess so that I could
write an API test for this.

* UIProcess/ProvisionalPageProxy.cpp:
(WebKit::ProvisionalPageProxy::ProvisionalPageProxy):
Make sure m_provisionalLoadURL gets initialized when the ProvisionalPageProxy gets
constructed *after* the provisional load has already started (which is the case
when the process swap is triggered by COOP).

(WebKit::ProvisionalPageProxy::didFailProvisionalLoadForFrame):
If the provisional load load fails in the provisional process, and the ProvisionalPageProxy
was constructed on resource response (COOP case), then no longer forward the
didFailProvisionalLoadForFrame() to the WebPageProxy. Instead, we destroy the
ProvisionalPageProxy. This is to avoid duplicate calls to didFailProvisionalLoadForFrame().
In this case, there is still a provisional load ongoing in the committed process and the
ProvisionalPageProxy destructor will take care of stopping that provisional load (due to
<a href="http://trac.webkit.org/projects/webkit/changeset/286479">r286479</a>), which will cause the committed process to send its own
didFailProvisionalLoadForFrame IPC.

Tools:

Add API test coverage.

* TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebKitChangeLog">trunk/Source/WebKit/ChangeLog</a></li>
<li><a href="#trunkSourceWebKitUIProcessAPICocoaWKWebViewPrivateForTestingh">trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivateForTesting.h</a></li>
<li><a href="#trunkSourceWebKitUIProcessAPICocoaWKWebViewTestingmm">trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewTesting.mm</a></li>
<li><a href="#trunkSourceWebKitUIProcessProvisionalPageProxycpp">trunk/Source/WebKit/UIProcess/ProvisionalPageProxy.cpp</a></li>
<li><a href="#trunkSourceWebKitUIProcessWebPageProxycpp">trunk/Source/WebKit/UIProcess/WebPageProxy.cpp</a></li>
<li><a href="#trunkSourceWebKitUIProcessWebPageProxyh">trunk/Source/WebKit/UIProcess/WebPageProxy.h</a></li>
<li><a href="#trunkSourceWebKitWebProcessWebPageWebPagecpp">trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp</a></li>
<li><a href="#trunkSourceWebKitWebProcessWebPageWebPageh">trunk/Source/WebKit/WebProcess/WebPage/WebPage.h</a></li>
<li><a href="#trunkSourceWebKitWebProcessWebPageWebPagemessagesin">trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in</a></li>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsTestWebKitAPITestsWebKitCocoaProcessSwapOnNavigationmm">trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebKitChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/ChangeLog (286504 => 286505)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/ChangeLog    2021-12-03 19:21:51 UTC (rev 286504)
+++ trunk/Source/WebKit/ChangeLog       2021-12-03 19:39:02 UTC (rev 286505)
</span><span class="lines">@@ -1,3 +1,42 @@
</span><ins>+2021-12-03  Chris Dumez  <cdumez@apple.com>
+
+        Follow-up to r286479 to add API test and address issues found by the test
+        https://bugs.webkit.org/show_bug.cgi?id=233798
+
+        Reviewed by Darin Adler.
+
+        Add functionality needed for API testing and fix issues found by the API test.
+
+        * UIProcess/API/Cocoa/WKWebViewPrivateForTesting.h:
+        * UIProcess/API/Cocoa/WKWebViewTesting.mm:
+        (-[WKWebView _isLayerTreeFrozenForTesting:]):
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::destroyProvisionalPage):
+        (WebKit::WebPageProxy::isLayerTreeFrozen):
+        * UIProcess/WebPageProxy.h:
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::isLayerTreeFrozen):
+        * WebProcess/WebPage/WebPage.h:
+        * WebProcess/WebPage/WebPage.messages.in:
+        Add new SPI to check if the layer tree is frozen in the WebProcess so that I could
+        write an API test for this.
+
+        * UIProcess/ProvisionalPageProxy.cpp:
+        (WebKit::ProvisionalPageProxy::ProvisionalPageProxy):
+        Make sure m_provisionalLoadURL gets initialized when the ProvisionalPageProxy gets
+        constructed *after* the provisional load has already started (which is the case
+        when the process swap is triggered by COOP).
+
+        (WebKit::ProvisionalPageProxy::didFailProvisionalLoadForFrame):
+        If the provisional load load fails in the provisional process, and the ProvisionalPageProxy
+        was constructed on resource response (COOP case), then no longer forward the
+        didFailProvisionalLoadForFrame() to the WebPageProxy. Instead, we destroy the
+        ProvisionalPageProxy. This is to avoid duplicate calls to didFailProvisionalLoadForFrame().
+        In this case, there is still a provisional load ongoing in the committed process and the
+        ProvisionalPageProxy destructor will take care of stopping that provisional load (due to
+        r286479), which will cause the committed process to send its own
+        didFailProvisionalLoadForFrame IPC.
+
</ins><span class="cx"> 2021-12-03  Wenson Hsieh  <wenson_hsieh@apple.com>
</span><span class="cx"> 
</span><span class="cx">         [ Monterey wk2 ] http/tests/media/video-webm-stall.html (layout-test) is a constant text failure
</span></span></pre></div>
<a id="trunkSourceWebKitUIProcessAPICocoaWKWebViewPrivateForTestingh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivateForTesting.h (286504 => 286505)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivateForTesting.h     2021-12-03 19:21:51 UTC (rev 286504)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivateForTesting.h        2021-12-03 19:39:02 UTC (rev 286505)
</span><span class="lines">@@ -116,6 +116,8 @@
</span><span class="cx"> - (void)_createMediaSessionCoordinatorForTesting:(id <_WKMediaSessionCoordinator>)privateCoordinator completionHandler:(void(^)(BOOL))completionHandler;
</span><span class="cx"> - (void)_gpuToWebProcessConnectionCountForTesting:(void(^)(NSUInteger))completionHandler WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
</span><span class="cx"> 
</span><ins>+- (void)_isLayerTreeFrozenForTesting:(void (^)(BOOL frozen))completionHandler WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
+
</ins><span class="cx"> @end
</span><span class="cx"> 
</span><span class="cx"> typedef NS_ENUM(NSInteger, _WKMediaSessionReadyState) {
</span></span></pre></div>
<a id="trunkSourceWebKitUIProcessAPICocoaWKWebViewTestingmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewTesting.mm (286504 => 286505)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewTesting.mm      2021-12-03 19:21:51 UTC (rev 286504)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewTesting.mm 2021-12-03 19:39:02 UTC (rev 286505)
</span><span class="lines">@@ -424,6 +424,13 @@
</span><span class="cx">     });
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+- (void)_isLayerTreeFrozenForTesting:(void (^)(BOOL frozen))completionHandler
+{
+    _page->isLayerTreeFrozen([completionHandler = makeBlockPtr(completionHandler)](bool isFrozen) {
+        completionHandler(isFrozen);
+    });
+}
+
</ins><span class="cx"> - (void)_gpuToWebProcessConnectionCountForTesting:(void(^)(NSUInteger))completionHandler
</span><span class="cx"> {
</span><span class="cx">     RefPtr gpuProcess = _page->process().processPool().gpuProcess();
</span></span></pre></div>
<a id="trunkSourceWebKitUIProcessProvisionalPageProxycpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/ProvisionalPageProxy.cpp (286504 => 286505)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/UIProcess/ProvisionalPageProxy.cpp   2021-12-03 19:21:51 UTC (rev 286504)
+++ trunk/Source/WebKit/UIProcess/ProvisionalPageProxy.cpp      2021-12-03 19:39:02 UTC (rev 286505)
</span><span class="lines">@@ -67,6 +67,7 @@
</span><span class="cx">     , m_request(request)
</span><span class="cx">     , m_processSwapRequestedByClient(processSwapRequestedByClient)
</span><span class="cx">     , m_isProcessSwappingOnNavigationResponse(isProcessSwappingOnNavigationResponse)
</span><ins>+    , m_provisionalLoadURL(isProcessSwappingOnNavigationResponse ? request.url() : URL())
</ins><span class="cx"> #if PLATFORM(IOS_FAMILY)
</span><span class="cx">     , m_provisionalLoadActivity(m_process->throttler().foregroundActivity("Provisional Load"_s))
</span><span class="cx"> #endif
</span><span class="lines">@@ -296,6 +297,15 @@
</span><span class="cx">     ASSERT(!m_provisionalLoadURL.isNull());
</span><span class="cx">     m_provisionalLoadURL = { };
</span><span class="cx"> 
</span><ins>+    if (m_isProcessSwappingOnNavigationResponse) {
+        // If the provisional load fails and we were process-swapping on navigation response, then we simply destroy ourselves.
+        // In this case, the provisional load is still ongoing in the committed process and the ProvisionalPageProxy destructor
+        // will stop it and cause the committed process to send its own DidFailProvisionalLoadForFrame IPC.
+        ASSERT(m_page.provisionalPageProxy() == this);
+        m_page.destroyProvisionalPage();
+        return;
+    }
+
</ins><span class="cx">     // Make sure the Page's main frame's expectedURL gets cleared since we updated it in didStartProvisionalLoad.
</span><span class="cx">     if (auto* pageMainFrame = m_page.mainFrame())
</span><span class="cx">         pageMainFrame->didFailProvisionalLoad();
</span></span></pre></div>
<a id="trunkSourceWebKitUIProcessWebPageProxycpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.cpp (286504 => 286505)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/UIProcess/WebPageProxy.cpp   2021-12-03 19:21:51 UTC (rev 286504)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.cpp      2021-12-03 19:39:02 UTC (rev 286505)
</span><span class="lines">@@ -3587,6 +3587,11 @@
</span><span class="cx">     m_inspectorController->didCommitProvisionalPage(oldWebPageID, m_webPageID);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void WebPageProxy::destroyProvisionalPage()
+{
+    m_provisionalPage = nullptr;
+}
+
</ins><span class="cx"> void WebPageProxy::continueNavigationInNewProcess(API::Navigation& navigation, std::unique_ptr<SuspendedPageProxy>&& suspendedPage, Ref<WebProcessProxy>&& newProcess, ProcessSwapRequestedByClient processSwapRequestedByClient, ShouldTreatAsContinuingLoad shouldTreatAsContinuingLoad, RefPtr<API::WebsitePolicies>&& websitePolicies, std::optional<NetworkResourceLoadIdentifier> existingNetworkResourceLoadIdentifierToResume)
</span><span class="cx"> {
</span><span class="cx">     WEBPAGEPROXY_RELEASE_LOG(Loading, "continueNavigationInNewProcess: newProcessPID=%i, hasSuspendedPage=%i", newProcess->processIdentifier(), !!suspendedPage);
</span><span class="lines">@@ -10800,6 +10805,11 @@
</span><span class="cx">     });
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void WebPageProxy::isLayerTreeFrozen(CompletionHandler<void(bool)>&& completionHandler)
+{
+    sendWithAsyncReply(Messages::WebPage::IsLayerTreeFrozen(), WTFMove(completionHandler));
+}
+
</ins><span class="cx"> void WebPageProxy::requestSpeechRecognitionPermission(WebCore::SpeechRecognitionRequest& request, CompletionHandler<void(std::optional<SpeechRecognitionError>&&)>&& completionHandler)
</span><span class="cx"> {
</span><span class="cx">     if (!m_speechRecognitionPermissionManager)
</span></span></pre></div>
<a id="trunkSourceWebKitUIProcessWebPageProxyh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.h (286504 => 286505)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/UIProcess/WebPageProxy.h     2021-12-03 19:21:51 UTC (rev 286504)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.h        2021-12-03 19:39:02 UTC (rev 286505)
</span><span class="lines">@@ -1502,6 +1502,8 @@
</span><span class="cx">     void setOverlayScrollbarStyle(std::optional<WebCore::ScrollbarOverlayStyle>);
</span><span class="cx">     std::optional<WebCore::ScrollbarOverlayStyle> overlayScrollbarStyle() const { return m_scrollbarOverlayStyle; }
</span><span class="cx"> 
</span><ins>+    void isLayerTreeFrozen(CompletionHandler<void(bool)>&&);
+
</ins><span class="cx">     // When the state of the window changes such that the WebPage needs immediate update, the UIProcess sends a new
</span><span class="cx">     // ActivityStateChangeID to the WebProcess through the SetActivityState message. The UIProcess will wait till it
</span><span class="cx">     // receives a CommitLayerTree which has an ActivityStateChangeID equal to or greater than the one it sent.
</span><span class="lines">@@ -1770,6 +1772,7 @@
</span><span class="cx"> 
</span><span class="cx">     ProvisionalPageProxy* provisionalPageProxy() const { return m_provisionalPage.get(); }
</span><span class="cx">     void commitProvisionalPage(WebCore::FrameIdentifier, FrameInfoData&&, WebCore::ResourceRequest&&, uint64_t navigationID, const String& mimeType, bool frameHasCustomContentProvider, WebCore::FrameLoadType, const WebCore::CertificateInfo&, bool usedLegacyTLS, bool containsPluginDocument, std::optional<WebCore::HasInsecureContent> forcedHasInsecureContent, WebCore::MouseEventPolicy, const UserData&);
</span><ins>+    void destroyProvisionalPage();
</ins><span class="cx"> 
</span><span class="cx">     // Logic shared between the WebPageProxy and the ProvisionalPageProxy.
</span><span class="cx">     void didStartProvisionalLoadForFrameShared(Ref<WebProcessProxy>&&, WebCore::FrameIdentifier, FrameInfoData&&, WebCore::ResourceRequest&&, uint64_t navigationID, URL&&, URL&& unreachableURL, const UserData&);
</span></span></pre></div>
<a id="trunkSourceWebKitWebProcessWebPageWebPagecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp (286504 => 286505)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp       2021-12-03 19:21:51 UTC (rev 286504)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp  2021-12-03 19:39:02 UTC (rev 286505)
</span><span class="lines">@@ -2787,6 +2787,11 @@
</span><span class="cx">     updateDrawingAreaLayerTreeFreezeState();
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void WebPage::isLayerTreeFrozen(CompletionHandler<void(bool)>&& completionHandler)
+{
+    completionHandler(!!m_layerTreeFreezeReasons);
+}
+
</ins><span class="cx"> void WebPage::updateDrawingAreaLayerTreeFreezeState()
</span><span class="cx"> {
</span><span class="cx">     if (!m_drawingArea)
</span></span></pre></div>
<a id="trunkSourceWebKitWebProcessWebPageWebPageh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.h (286504 => 286505)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.h 2021-12-03 19:21:51 UTC (rev 286504)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.h    2021-12-03 19:39:02 UTC (rev 286505)
</span><span class="lines">@@ -859,6 +859,8 @@
</span><span class="cx">     void freezeLayerTree(LayerTreeFreezeReason);
</span><span class="cx">     void unfreezeLayerTree(LayerTreeFreezeReason);
</span><span class="cx"> 
</span><ins>+    void isLayerTreeFrozen(CompletionHandler<void(bool)>&&);
+
</ins><span class="cx">     void markLayersVolatile(CompletionHandler<void(bool)>&& completionHandler = { });
</span><span class="cx">     void cancelMarkLayersVolatile();
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKitWebProcessWebPageWebPagemessagesin"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in (286504 => 286505)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in       2021-12-03 19:21:51 UTC (rev 286504)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in  2021-12-03 19:39:02 UTC (rev 286505)
</span><span class="lines">@@ -402,6 +402,7 @@
</span><span class="cx"> 
</span><span class="cx">     FreezeLayerTreeDueToSwipeAnimation()
</span><span class="cx">     UnfreezeLayerTreeDueToSwipeAnimation()
</span><ins>+    IsLayerTreeFrozen() -> (bool isFrozen) Async
</ins><span class="cx"> 
</span><span class="cx">     # Printing.
</span><span class="cx">     BeginPrinting(WebCore::FrameIdentifier frameID, struct WebKit::PrintInfo printInfo)
</span></span></pre></div>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (286504 => 286505)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog    2021-12-03 19:21:51 UTC (rev 286504)
+++ trunk/Tools/ChangeLog       2021-12-03 19:39:02 UTC (rev 286505)
</span><span class="lines">@@ -1,3 +1,14 @@
</span><ins>+2021-12-03  Chris Dumez  <cdumez@apple.com>
+
+        Follow-up to r286479 to add API test and address issues found by the test
+        https://bugs.webkit.org/show_bug.cgi?id=233798
+
+        Reviewed by Darin Adler.
+
+        Add API test coverage.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm:
+
</ins><span class="cx"> 2021-12-03  Alex Christensen  <achristensen@webkit.org>
</span><span class="cx"> 
</span><span class="cx">         Add room for more bytecode in WKContentRuleList file format
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestsWebKitCocoaProcessSwapOnNavigationmm"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm (286504 => 286505)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm   2021-12-03 19:21:51 UTC (rev 286504)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm      2021-12-03 19:39:02 UTC (rev 286505)
</span><span class="lines">@@ -7266,6 +7266,64 @@
</span><span class="cx">     [processPool _clearWebProcessCache];
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+TEST(ProcessSwap, ResponsePolicyDownloadAfterCOOPProcessSwap)
+{
+    using namespace TestWebKitAPI;
+
+    HTTPServer server({
+        { "/source.html", { "foo" } },
+        { "/destination.html", { { { "Content-Type", "text/html" }, { "Cross-Origin-Opener-Policy", "same-origin" } }, "bar" } },
+    }, HTTPServer::Protocol::Https);
+
+    auto processPoolConfiguration = psonProcessPoolConfiguration();
+    auto processPool = adoptNS([[WKProcessPool alloc] _initWithConfiguration:processPoolConfiguration.get()]);
+
+    auto webViewConfiguration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    [webViewConfiguration setProcessPool:processPool.get()];
+    for (_WKExperimentalFeature *feature in [WKPreferences _experimentalFeatures]) {
+        if ([feature.key isEqualToString:@"CrossOriginOpenerPolicyEnabled"])
+            [[webViewConfiguration preferences] _setEnabled:YES forExperimentalFeature:feature];
+        else if ([feature.key isEqualToString:@"CrossOriginEmbedderPolicyEnabled"])
+            [[webViewConfiguration preferences] _setEnabled:YES forExperimentalFeature:feature];
+    }
+
+    auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:webViewConfiguration.get()]);
+    auto navigationDelegate = adoptNS([[PSONNavigationDelegate alloc] init]);
+    [webView setNavigationDelegate:navigationDelegate.get()];
+
+    done = false;
+    [webView loadRequest:server.request("/source.html")];
+    Util::run(&done);
+    done = false;
+
+    auto pid1 = [webView _webProcessIdentifier];
+
+    // The next navigation will get converted into a download via decidePolicyForNavigationResponse.
+    shouldConvertToDownload = true;
+
+    done = false;
+    failed = false;
+    [webView loadRequest:server.request("/destination.html")];
+    Util::run(&failed);
+    failed = false;
+    shouldConvertToDownload = false;
+
+    auto pid2 = [webView _webProcessIdentifier];
+    EXPECT_EQ(pid1, pid2);
+
+    // The layer tree should no longer be frozen since the navigation didn't happen.
+    __block bool isFrozen = true;
+    do {
+        Util::sleep(0.1);
+        done = false;
+        [webView _isLayerTreeFrozenForTesting:^(BOOL frozen) {
+            isFrozen = frozen;
+            done = true;
+        }];
+        Util::run(&done);
+    } while (isFrozen);
+}
+
</ins><span class="cx"> enum class IsSameOrigin : bool { No, Yes };
</span><span class="cx"> enum class DoServerSideRedirect : bool { No, Yes };
</span><span class="cx"> static void runCOOPProcessSwapTest(const char* sourceCOOP, const char* sourceCOEP, const char* destinationCOOP, const char* destinationCOEP, IsSameOrigin isSameOrigin, DoServerSideRedirect doServerSideRedirect, ExpectSwap expectSwap)
</span></span></pre>
</div>
</div>

</body>
</html>