<!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>[281990] trunk/Tools</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/281990">281990</a></dd>
<dt>Author</dt> <dd>cdumez@apple.com</dd>
<dt>Date</dt> <dd>2021-09-03 07:46:56 -0700 (Fri, 03 Sep 2021)</dd>
</dl>

<h3>Log Message</h3>
<pre>WebKitTestRunner does not correctly close all auxiliary WebViews between tests
https://bugs.webkit.org/show_bug.cgi?id=229838

Reviewed by Alex Christensen.

I noticed when running imported/w3c/web-platform-tests/html/cross-origin-opener-policy/coop-csp-sandbox-navigate.https.html
in a loop that the number of WebContent processes would grow until we crash. The reason for that is that the
test opens a popup window and that popup wouldn't get closed between runs.

There was some logic in InjectedBundle::done() to close auxiliary pages but this relied on the injected
bundle API and thus only knows about pages that are in the same WebProcess. Nowadays, with process swapping,
it is common for auxiliary pages to end up in other WebProcesses. For this reason, I dropped the logic to
close auxiliary pages from InjectedBundle::done() and instead added similar logic in the UIProcess,
inside TestController::resetStateToConsistentValues().

Finally, I dropped most of the code related to testRunner.setCloseRemainingWindowsWhenComplete() while keeping
the method as a no-op for now so that I don't have to update all the layout tests in this patch (I'll follow
up). For WebKitTestRunner, testRunner.setCloseRemainingWindowsWhenComplete() was already a no-op as the data
member getting set was never queried. For DumpRenderTree, I just made this behavior the default as I don't see
any reason why we wouldn't want to close auxiliary pages between tests.

* DumpRenderTree/TestRunner.cpp:
(setCloseRemainingWindowsWhenCompleteCallback):
(TestRunner::staticFunctions):
* DumpRenderTree/TestRunner.h:
(TestRunner::setCanOpenWindows):
* DumpRenderTree/mac/DumpRenderTree.mm:
(runTest):
* DumpRenderTree/win/DumpRenderTree.cpp:
(runTest):
* WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl:
* WebKitTestRunner/InjectedBundle/InjectedBundle.cpp:
(WTR::InjectedBundle::done):
* WebKitTestRunner/InjectedBundle/InjectedBundle.h:
(WTR::InjectedBundle::pageCount const):
* WebKitTestRunner/InjectedBundle/TestRunner.h:
(WTR::TestRunner::setCloseRemainingWindowsWhenComplete):
* WebKitTestRunner/TestController.cpp:
(WTR::TestController::closeOtherPage):
(WTR::TestController::createOtherPage):
(WTR::TestController::resetStateToConsistentValues):
(WTR::TestController::platformCreateOtherPage):
* WebKitTestRunner/TestController.h:
* WebKitTestRunner/cocoa/TestControllerCocoa.mm:
(WTR::TestController::platformCreateOtherPage):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsDumpRenderTreeTestRunnercpp">trunk/Tools/DumpRenderTree/TestRunner.cpp</a></li>
<li><a href="#trunkToolsDumpRenderTreeTestRunnerh">trunk/Tools/DumpRenderTree/TestRunner.h</a></li>
<li><a href="#trunkToolsDumpRenderTreemacDumpRenderTreemm">trunk/Tools/DumpRenderTree/mac/DumpRenderTree.mm</a></li>
<li><a href="#trunkToolsDumpRenderTreewinDumpRenderTreecpp">trunk/Tools/DumpRenderTree/win/DumpRenderTree.cpp</a></li>
<li><a href="#trunkToolsWebKitTestRunnerInjectedBundleBindingsTestRunneridl">trunk/Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl</a></li>
<li><a href="#trunkToolsWebKitTestRunnerInjectedBundleInjectedBundlecpp">trunk/Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.cpp</a></li>
<li><a href="#trunkToolsWebKitTestRunnerInjectedBundleInjectedBundleh">trunk/Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.h</a></li>
<li><a href="#trunkToolsWebKitTestRunnerInjectedBundleTestRunnerh">trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.h</a></li>
<li><a href="#trunkToolsWebKitTestRunnerTestControllercpp">trunk/Tools/WebKitTestRunner/TestController.cpp</a></li>
<li><a href="#trunkToolsWebKitTestRunnerTestControllerh">trunk/Tools/WebKitTestRunner/TestController.h</a></li>
<li><a href="#trunkToolsWebKitTestRunnercocoaTestControllerCocoamm">trunk/Tools/WebKitTestRunner/cocoa/TestControllerCocoa.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (281989 => 281990)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog    2021-09-03 13:55:11 UTC (rev 281989)
+++ trunk/Tools/ChangeLog       2021-09-03 14:46:56 UTC (rev 281990)
</span><span class="lines">@@ -1,3 +1,51 @@
</span><ins>+2021-09-03  Chris Dumez  <cdumez@apple.com>
+
+        WebKitTestRunner does not correctly close all auxiliary WebViews between tests
+        https://bugs.webkit.org/show_bug.cgi?id=229838
+
+        Reviewed by Alex Christensen.
+
+        I noticed when running imported/w3c/web-platform-tests/html/cross-origin-opener-policy/coop-csp-sandbox-navigate.https.html
+        in a loop that the number of WebContent processes would grow until we crash. The reason for that is that the
+        test opens a popup window and that popup wouldn't get closed between runs.
+
+        There was some logic in InjectedBundle::done() to close auxiliary pages but this relied on the injected
+        bundle API and thus only knows about pages that are in the same WebProcess. Nowadays, with process swapping,
+        it is common for auxiliary pages to end up in other WebProcesses. For this reason, I dropped the logic to
+        close auxiliary pages from InjectedBundle::done() and instead added similar logic in the UIProcess,
+        inside TestController::resetStateToConsistentValues().
+
+        Finally, I dropped most of the code related to testRunner.setCloseRemainingWindowsWhenComplete() while keeping
+        the method as a no-op for now so that I don't have to update all the layout tests in this patch (I'll follow
+        up). For WebKitTestRunner, testRunner.setCloseRemainingWindowsWhenComplete() was already a no-op as the data
+        member getting set was never queried. For DumpRenderTree, I just made this behavior the default as I don't see
+        any reason why we wouldn't want to close auxiliary pages between tests.
+
+        * DumpRenderTree/TestRunner.cpp:
+        (setCloseRemainingWindowsWhenCompleteCallback):
+        (TestRunner::staticFunctions):
+        * DumpRenderTree/TestRunner.h:
+        (TestRunner::setCanOpenWindows):
+        * DumpRenderTree/mac/DumpRenderTree.mm:
+        (runTest):
+        * DumpRenderTree/win/DumpRenderTree.cpp:
+        (runTest):
+        * WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl:
+        * WebKitTestRunner/InjectedBundle/InjectedBundle.cpp:
+        (WTR::InjectedBundle::done):
+        * WebKitTestRunner/InjectedBundle/InjectedBundle.h:
+        (WTR::InjectedBundle::pageCount const):
+        * WebKitTestRunner/InjectedBundle/TestRunner.h:
+        (WTR::TestRunner::setCloseRemainingWindowsWhenComplete):
+        * WebKitTestRunner/TestController.cpp:
+        (WTR::TestController::closeOtherPage):
+        (WTR::TestController::createOtherPage):
+        (WTR::TestController::resetStateToConsistentValues):
+        (WTR::TestController::platformCreateOtherPage):
+        * WebKitTestRunner/TestController.h:
+        * WebKitTestRunner/cocoa/TestControllerCocoa.mm:
+        (WTR::TestController::platformCreateOtherPage):
+
</ins><span class="cx"> 2021-09-03  Wenson Hsieh  <wenson_hsieh@apple.com>
</span><span class="cx"> 
</span><span class="cx">         [iOS 15] editing/caret/ios/caret-in-overflow-area.html is failing
</span></span></pre></div>
<a id="trunkToolsDumpRenderTreeTestRunnercpp"></a>
<div class="modfile"><h4>Modified: trunk/Tools/DumpRenderTree/TestRunner.cpp (281989 => 281990)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/DumpRenderTree/TestRunner.cpp        2021-09-03 13:55:11 UTC (rev 281989)
+++ trunk/Tools/DumpRenderTree/TestRunner.cpp   2021-09-03 14:46:56 UTC (rev 281990)
</span><span class="lines">@@ -292,11 +292,6 @@
</span><span class="cx"> 
</span><span class="cx"> static JSValueRef setCloseRemainingWindowsWhenCompleteCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
</span><span class="cx"> {
</span><del>-    if (argumentCount < 1)
-        return JSValueMakeUndefined(context);
-
-    TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
-    controller->setCloseRemainingWindowsWhenComplete(JSValueToBoolean(context, arguments[0]));
</del><span class="cx">     return JSValueMakeUndefined(context);
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -2055,7 +2050,7 @@
</span><span class="cx">         { "setCacheModel", setCacheModelCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
</span><span class="cx">         { "setCallCloseOnWebViews", setCallCloseOnWebViewsCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
</span><span class="cx">         { "setCanOpenWindows", setCanOpenWindowsCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
</span><del>-        { "setCloseRemainingWindowsWhenComplete", setCloseRemainingWindowsWhenCompleteCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
</del><ins>+        { "setCloseRemainingWindowsWhenComplete", setCloseRemainingWindowsWhenCompleteCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, // This is a no-op: We should update the layout tests and remove it.
</ins><span class="cx">         { "setCustomPolicyDelegate", setCustomPolicyDelegateCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
</span><span class="cx">         { "setDatabaseQuota", setDatabaseQuotaCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, 
</span><span class="cx">         { "setDefersLoading", setDefersLoadingCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
</span></span></pre></div>
<a id="trunkToolsDumpRenderTreeTestRunnerh"></a>
<div class="modfile"><h4>Modified: trunk/Tools/DumpRenderTree/TestRunner.h (281989 => 281990)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/DumpRenderTree/TestRunner.h  2021-09-03 13:55:11 UTC (rev 281989)
+++ trunk/Tools/DumpRenderTree/TestRunner.h     2021-09-03 14:46:56 UTC (rev 281990)
</span><span class="lines">@@ -229,9 +229,6 @@
</span><span class="cx"> 
</span><span class="cx">     bool canOpenWindows() const { return m_canOpenWindows; }
</span><span class="cx">     void setCanOpenWindows(bool canOpenWindows) { m_canOpenWindows = canOpenWindows; }
</span><del>-
-    bool closeRemainingWindowsWhenComplete() const { return m_closeRemainingWindowsWhenComplete; }
-    void setCloseRemainingWindowsWhenComplete(bool closeRemainingWindowsWhenComplete) { m_closeRemainingWindowsWhenComplete = closeRemainingWindowsWhenComplete; }
</del><span class="cx">     
</span><span class="cx">     bool newWindowsCopyBackForwardList() const { return m_newWindowsCopyBackForwardList; }
</span><span class="cx">     void setNewWindowsCopyBackForwardList(bool newWindowsCopyBackForwardList) { m_newWindowsCopyBackForwardList = newWindowsCopyBackForwardList; }
</span><span class="lines">@@ -429,7 +426,6 @@
</span><span class="cx">     bool m_generatePixelResults { true };
</span><span class="cx">     bool m_callCloseOnWebViews { true };
</span><span class="cx">     bool m_canOpenWindows { false };
</span><del>-    bool m_closeRemainingWindowsWhenComplete { true };
</del><span class="cx">     bool m_newWindowsCopyBackForwardList { false };
</span><span class="cx">     bool m_stopProvisionalFrameLoads { false };
</span><span class="cx">     bool m_testOnscreen { false };
</span></span></pre></div>
<a id="trunkToolsDumpRenderTreemacDumpRenderTreemm"></a>
<div class="modfile"><h4>Modified: trunk/Tools/DumpRenderTree/mac/DumpRenderTree.mm (281989 => 281990)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/DumpRenderTree/mac/DumpRenderTree.mm 2021-09-03 13:55:11 UTC (rev 281989)
+++ trunk/Tools/DumpRenderTree/mac/DumpRenderTree.mm    2021-09-03 14:46:56 UTC (rev 281990)
</span><span class="lines">@@ -1986,27 +1986,20 @@
</span><span class="cx">             [[mainWindow contentView] addSubview:webView];
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><del>-        if (gTestRunner->closeRemainingWindowsWhenComplete()) {
-            NSArray* array = [DumpRenderTreeWindow openWindows];
</del><ins>+        for (NSWindow *window in DumpRenderTreeWindow.openWindows) {
+            // Don't try to close the main window
+            if (window == mainFrame.webView.window)
+                continue;
</ins><span class="cx"> 
</span><del>-            unsigned count = [array count];
-            for (unsigned i = 0; i < count; i++) {
-                NSWindow *window = [array objectAtIndex:i];
-
-                // Don't try to close the main window
-                if (window == [[mainFrame webView] window])
-                    continue;
-
</del><span class="cx"> #if !PLATFORM(IOS_FAMILY)
</span><del>-                WebView *webView = [[[window contentView] subviews] objectAtIndex:0];
</del><ins>+            WebView *webView = [window.contentView.subviews objectAtIndex:0];
</ins><span class="cx"> #else
</span><del>-                ASSERT([[window contentView] isKindOfClass:[WebView class]]);
-                WebView *webView = (WebView *)[window contentView];
</del><ins>+            ASSERT([window.contentView] isKindOfClass:WebView.class]);
+            WebView *webView = (WebView *)window.contentView;
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><del>-                [webView close];
-                [window close];
-            }
</del><ins>+            [webView close];
+            [window close];
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         resetWebViewToConsistentState(options, ResetTime::AfterTest);
</span></span></pre></div>
<a id="trunkToolsDumpRenderTreewinDumpRenderTreecpp"></a>
<div class="modfile"><h4>Modified: trunk/Tools/DumpRenderTree/win/DumpRenderTree.cpp (281989 => 281990)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/DumpRenderTree/win/DumpRenderTree.cpp        2021-09-03 13:55:11 UTC (rev 281989)
+++ trunk/Tools/DumpRenderTree/win/DumpRenderTree.cpp   2021-09-03 14:46:56 UTC (rev 281990)
</span><span class="lines">@@ -1327,18 +1327,13 @@
</span><span class="cx">     // then try to close it in case it was accidentally left open.
</span><span class="cx">     ::gTestRunner->closeWebInspector();
</span><span class="cx"> 
</span><del>-    if (::gTestRunner->closeRemainingWindowsWhenComplete()) {
-        Vector<HWND> windows = openWindows();
-        unsigned size = windows.size();
-        for (unsigned i = 0; i < size; i++) {
-            HWND window = windows[i];
</del><span class="cx"> 
</span><del>-            // Don't try to close the main window
-            if (window == hostWindow)
-                continue;
</del><ins>+    for (HWND window : openWindows()) {
+        // Don't try to close the main window
+        if (window == hostWindow)
+            continue;
</ins><span class="cx"> 
</span><del>-            ::DestroyWindow(window);
-        }
</del><ins>+        ::DestroyWindow(window);
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     resetWebViewToConsistentStateBeforeTesting(options);
</span></span></pre></div>
<a id="trunkToolsWebKitTestRunnerInjectedBundleBindingsTestRunneridl"></a>
<div class="modfile"><h4>Modified: trunk/Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl (281989 => 281990)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl      2021-09-03 13:55:11 UTC (rev 281989)
+++ trunk/Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl 2021-09-03 14:46:56 UTC (rev 281990)
</span><span class="lines">@@ -78,7 +78,7 @@
</span><span class="cx">     undefined keepWebHistory();
</span><span class="cx">     undefined setAcceptsEditing(boolean value);
</span><span class="cx">     undefined setCanOpenWindows();
</span><del>-    undefined setCloseRemainingWindowsWhenComplete(boolean value);
</del><ins>+    undefined setCloseRemainingWindowsWhenComplete(boolean value); // FIXME: This is a no-op, we should update the tests and remove it.
</ins><span class="cx">     undefined setCustomPolicyDelegate(boolean enabled, boolean permissive);
</span><span class="cx">     undefined addOriginAccessAllowListEntry(DOMString sourceOrigin, DOMString destinationProtocol, DOMString destinationHost, boolean allowDestinationSubdomains);
</span><span class="cx">     undefined removeOriginAccessAllowListEntry(DOMString sourceOrigin, DOMString destinationProtocol, DOMString destinationHost, boolean allowDestinationSubdomains);
</span></span></pre></div>
<a id="trunkToolsWebKitTestRunnerInjectedBundleInjectedBundlecpp"></a>
<div class="modfile"><h4>Modified: trunk/Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.cpp (281989 => 281990)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.cpp   2021-09-03 13:55:11 UTC (rev 281989)
+++ trunk/Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.cpp      2021-09-03 14:46:56 UTC (rev 281990)
</span><span class="lines">@@ -561,21 +561,9 @@
</span><span class="cx"> 
</span><span class="cx">     WKBundlePagePostMessageIgnoringFullySynchronousMode(page()->page(), toWK("Done").get(), body.get());
</span><span class="cx"> 
</span><del>-    closeOtherPages();
-
</del><span class="cx">     m_state = Idle;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void InjectedBundle::closeOtherPages()
-{
-    Vector<WKBundlePageRef> pagesToClose;
-    size_t size = m_pages.size();
-    for (size_t i = 1; i < size; ++i)
-        pagesToClose.append(m_pages[i]->page());
-    for (auto& page : pagesToClose)
-        WKBundlePageClose(page);
-}
-
</del><span class="cx"> void InjectedBundle::dumpBackForwardListsForAllPages(StringBuilder& stringBuilder)
</span><span class="cx"> {
</span><span class="cx">     size_t size = m_pages.size();
</span></span></pre></div>
<a id="trunkToolsWebKitTestRunnerInjectedBundleInjectedBundleh"></a>
<div class="modfile"><h4>Modified: trunk/Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.h (281989 => 281990)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.h     2021-09-03 13:55:11 UTC (rev 281989)
+++ trunk/Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.h        2021-09-03 14:46:56 UTC (rev 281990)
</span><span class="lines">@@ -64,7 +64,6 @@
</span><span class="cx">     InjectedBundlePage* page() const;
</span><span class="cx">     WKBundlePageRef pageRef() const;
</span><span class="cx">     size_t pageCount() const { return m_pages.size(); }
</span><del>-    void closeOtherPages();
</del><span class="cx"> 
</span><span class="cx">     void dumpBackForwardListsForAllPages(StringBuilder&);
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkToolsWebKitTestRunnerInjectedBundleTestRunnerh"></a>
<div class="modfile"><h4>Modified: trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.h (281989 => 281990)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.h 2021-09-03 13:55:11 UTC (rev 281989)
+++ trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.h    2021-09-03 14:46:56 UTC (rev 281990)
</span><span class="lines">@@ -100,7 +100,7 @@
</span><span class="cx">     void keepWebHistory();
</span><span class="cx">     void setAcceptsEditing(bool value) { m_shouldAllowEditing = value; }
</span><span class="cx">     void setCanOpenWindows();
</span><del>-    void setCloseRemainingWindowsWhenComplete(bool value) { m_shouldCloseExtraWindows = value; }
</del><ins>+    void setCloseRemainingWindowsWhenComplete(bool) { }
</ins><span class="cx"> 
</span><span class="cx">     void setCustomPolicyDelegate(bool enabled, bool permissive = false);
</span><span class="cx">     void addOriginAccessAllowListEntry(JSStringRef sourceOrigin, JSStringRef destinationProtocol, JSStringRef destinationHost, bool allowDestinationSubdomains);
</span><span class="lines">@@ -219,8 +219,6 @@
</span><span class="cx"> 
</span><span class="cx">     bool shouldAllowEditing() const { return m_shouldAllowEditing; }
</span><span class="cx"> 
</span><del>-    bool shouldCloseExtraWindowsAfterRunningTest() const { return m_shouldCloseExtraWindows; }
-
</del><span class="cx">     void evaluateScriptInIsolatedWorld(JSContextRef, unsigned worldID, JSStringRef script);
</span><span class="cx">     static unsigned worldIDForWorld(WKBundleScriptWorldRef);
</span><span class="cx"> 
</span><span class="lines">@@ -566,7 +564,6 @@
</span><span class="cx">     bool m_shouldDumpAllFrameScrollPositions { false };
</span><span class="cx">     bool m_shouldDumpBackForwardListsForAllWindows { false };
</span><span class="cx">     bool m_shouldAllowEditing { true };
</span><del>-    bool m_shouldCloseExtraWindows { false };
</del><span class="cx"> 
</span><span class="cx">     bool m_dumpEditingCallbacks { false };
</span><span class="cx">     bool m_dumpStatusCallbacks { false };
</span></span></pre></div>
<a id="trunkToolsWebKitTestRunnerTestControllercpp"></a>
<div class="modfile"><h4>Modified: trunk/Tools/WebKitTestRunner/TestController.cpp (281989 => 281990)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/WebKitTestRunner/TestController.cpp  2021-09-03 13:55:11 UTC (rev 281989)
+++ trunk/Tools/WebKitTestRunner/TestController.cpp     2021-09-03 14:46:56 UTC (rev 281990)
</span><span class="lines">@@ -91,6 +91,7 @@
</span><span class="cx"> #include <wtf/SetForScope.h>
</span><span class="cx"> #include <wtf/UUID.h>
</span><span class="cx"> #include <wtf/UniqueArray.h>
</span><ins>+#include <wtf/UniqueRef.h>
</ins><span class="cx"> #include <wtf/text/CString.h>
</span><span class="cx"> #include <wtf/text/StringConcatenateNumbers.h>
</span><span class="cx"> 
</span><span class="lines">@@ -268,11 +269,10 @@
</span><span class="cx">     TestController::singleton().mainWebView()->setWindowIsKey(true);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static void closeOtherPage(WKPageRef page, const void* clientInfo)
</del><ins>+void TestController::closeOtherPage(WKPageRef page, const void* clientInfo)
</ins><span class="cx"> {
</span><del>-    WKPageClose(page);
</del><span class="cx">     PlatformWebView* view = static_cast<PlatformWebView*>(const_cast<void*>(clientInfo));
</span><del>-    delete view;
</del><ins>+    TestController::singleton().closeOtherPage(page, view);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> static void focus(WKPageRef page, const void* clientInfo)
</span><span class="lines">@@ -359,6 +359,14 @@
</span><span class="cx">     m_isMediaKeySystemPermissionGranted = granted;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void TestController::closeOtherPage(WKPageRef page, PlatformWebView* view)
+{
+    WKPageClose(page);
+    auto index = m_auxiliaryWebViews.findMatching([view](auto& auxiliaryWebView) { return auxiliaryWebView.ptr() == view; });
+    if (index != notFound)
+        m_auxiliaryWebViews.remove(index);
+}
+
</ins><span class="cx"> WKPageRef TestController::createOtherPage(WKPageRef, WKPageConfigurationRef configuration, WKNavigationActionRef navigationAction, WKWindowFeaturesRef windowFeatures, const void *clientInfo)
</span><span class="cx"> {
</span><span class="cx">     PlatformWebView* parentView = static_cast<PlatformWebView*>(const_cast<void*>(clientInfo));
</span><span class="lines">@@ -375,13 +383,13 @@
</span><span class="cx"> 
</span><span class="cx">     m_createdOtherPage = true;
</span><span class="cx"> 
</span><del>-    PlatformWebView* view = platformCreateOtherPage(parentView, configuration, parentView->options());
</del><ins>+    auto view = platformCreateOtherPage(parentView, configuration, parentView->options());
</ins><span class="cx">     WKPageRef newPage = view->page();
</span><span class="cx"> 
</span><span class="cx">     view->resizeTo(800, 600);
</span><span class="cx"> 
</span><span class="cx">     WKPageUIClientV8 otherPageUIClient = {
</span><del>-        { 8, view },
</del><ins>+        { 8, view.ptr() },
</ins><span class="cx">         nullptr, // createNewPage_deprecatedForUseWithV0
</span><span class="cx">         nullptr, // showPage
</span><span class="cx">         closeOtherPage,
</span><span class="lines">@@ -485,8 +493,9 @@
</span><span class="cx"> 
</span><span class="cx">     view->didInitializeClients();
</span><span class="cx"> 
</span><del>-    TestController::singleton().updateWindowScaleForTest(view, *TestController::singleton().m_currentInvocation);
</del><ins>+    TestController::singleton().updateWindowScaleForTest(view.ptr(), *TestController::singleton().m_currentInvocation);
</ins><span class="cx"> 
</span><ins>+    m_auxiliaryWebViews.append(WTFMove(view));
</ins><span class="cx">     WKRetain(newPage);
</span><span class="cx">     return newPage;
</span><span class="cx"> }
</span><span class="lines">@@ -911,6 +920,9 @@
</span><span class="cx">     SetForScope<State> changeState(m_state, Resetting);
</span><span class="cx">     m_beforeUnloadReturnValue = true;
</span><span class="cx"> 
</span><ins>+    for (auto& auxiliaryWebView : std::exchange(m_auxiliaryWebViews, { }))
+        WKPageClose(auxiliaryWebView->page());
+
</ins><span class="cx">     // This setting differs between the antique and modern Mac WebKit2 API.
</span><span class="cx">     // For now, maintain the antique behavior, because some tests depend on it!
</span><span class="cx">     // FIXME: We should be testing the default.
</span><span class="lines">@@ -2721,9 +2733,9 @@
</span><span class="cx">     m_mainWebView = makeUnique<PlatformWebView>(configuration, options);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-PlatformWebView* TestController::platformCreateOtherPage(PlatformWebView* parentView, WKPageConfigurationRef configuration, const TestOptions& options)
</del><ins>+UniqueRef<PlatformWebView> TestController::platformCreateOtherPage(PlatformWebView* parentView, WKPageConfigurationRef configuration, const TestOptions& options)
</ins><span class="cx"> {
</span><del>-    return new PlatformWebView(configuration, options);
</del><ins>+    return makeUniqueRef<PlatformWebView>(configuration, options);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> WKContextRef TestController::platformAdjustContext(WKContextRef context, WKContextConfigurationRef)
</span></span></pre></div>
<a id="trunkToolsWebKitTestRunnerTestControllerh"></a>
<div class="modfile"><h4>Modified: trunk/Tools/WebKitTestRunner/TestController.h (281989 => 281990)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/WebKitTestRunner/TestController.h    2021-09-03 13:55:11 UTC (rev 281989)
+++ trunk/Tools/WebKitTestRunner/TestController.h       2021-09-03 14:46:56 UTC (rev 281990)
</span><span class="lines">@@ -384,7 +384,7 @@
</span><span class="cx">     WKContextRef platformAdjustContext(WKContextRef, WKContextConfigurationRef);
</span><span class="cx">     void platformInitializeContext();
</span><span class="cx">     void platformCreateWebView(WKPageConfigurationRef, const TestOptions&);
</span><del>-    static PlatformWebView* platformCreateOtherPage(PlatformWebView* parentView, WKPageConfigurationRef, const TestOptions&);
</del><ins>+    static UniqueRef<PlatformWebView> platformCreateOtherPage(PlatformWebView* parentView, WKPageConfigurationRef, const TestOptions&);
</ins><span class="cx"> 
</span><span class="cx">     // Returns false if the reset timed out.
</span><span class="cx">     bool platformResetStateToConsistentValues(const TestOptions&);
</span><span class="lines">@@ -519,6 +519,9 @@
</span><span class="cx">     static WKPageRef createOtherPage(WKPageRef, WKPageConfigurationRef, WKNavigationActionRef, WKWindowFeaturesRef, const void*);
</span><span class="cx">     WKPageRef createOtherPage(PlatformWebView* parentView, WKPageConfigurationRef, WKNavigationActionRef, WKWindowFeaturesRef);
</span><span class="cx"> 
</span><ins>+    static void closeOtherPage(WKPageRef, const void*);
+    void closeOtherPage(WKPageRef, PlatformWebView*);
+
</ins><span class="cx">     static void runModal(WKPageRef, const void* clientInfo);
</span><span class="cx">     static void runModal(PlatformWebView*);
</span><span class="cx"> 
</span><span class="lines">@@ -552,6 +555,7 @@
</span><span class="cx">     WebNotificationProvider m_webNotificationProvider;
</span><span class="cx"> 
</span><span class="cx">     std::unique_ptr<PlatformWebView> m_mainWebView;
</span><ins>+    Vector<UniqueRef<PlatformWebView>> m_auxiliaryWebViews;
</ins><span class="cx">     WKRetainPtr<WKContextRef> m_context;
</span><span class="cx">     WKRetainPtr<WKPageGroupRef> m_pageGroup;
</span><span class="cx">     WKRetainPtr<WKUserContentControllerRef> m_userContentController;
</span></span></pre></div>
<a id="trunkToolsWebKitTestRunnercocoaTestControllerCocoamm"></a>
<div class="modfile"><h4>Modified: trunk/Tools/WebKitTestRunner/cocoa/TestControllerCocoa.mm (281989 => 281990)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/WebKitTestRunner/cocoa/TestControllerCocoa.mm        2021-09-03 13:55:11 UTC (rev 281989)
+++ trunk/Tools/WebKitTestRunner/cocoa/TestControllerCocoa.mm   2021-09-03 14:46:56 UTC (rev 281990)
</span><span class="lines">@@ -54,6 +54,7 @@
</span><span class="cx"> #import <WebKit/_WKUserContentExtensionStorePrivate.h>
</span><span class="cx"> #import <WebKit/_WKWebsiteDataStoreConfiguration.h>
</span><span class="cx"> #import <wtf/MainThread.h>
</span><ins>+#import <wtf/UniqueRef.h>
</ins><span class="cx"> #import <wtf/cocoa/VectorCocoa.h>
</span><span class="cx"> #import <wtf/spi/cocoa/SecuritySPI.h>
</span><span class="cx"> 
</span><span class="lines">@@ -202,14 +203,14 @@
</span><span class="cx">     [m_mainWebView->platformView() _setShareSheetCompletesImmediatelyWithResolutionForTesting:YES];
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-PlatformWebView* TestController::platformCreateOtherPage(PlatformWebView* parentView, WKPageConfigurationRef, const TestOptions& options)
</del><ins>+UniqueRef<PlatformWebView> TestController::platformCreateOtherPage(PlatformWebView* parentView, WKPageConfigurationRef, const TestOptions& options)
</ins><span class="cx"> {
</span><span class="cx">     auto newConfiguration = adoptNS([globalWebViewConfiguration() copy]);
</span><span class="cx">     [newConfiguration _setRelatedWebView:static_cast<WKWebView*>(parentView->platformView())];
</span><span class="cx">     if ([newConfiguration _relatedWebView])
</span><span class="cx">         [newConfiguration setWebsiteDataStore:[newConfiguration _relatedWebView].configuration.websiteDataStore];
</span><del>-    PlatformWebView* view = new PlatformWebView(newConfiguration.get(), options);
-    finishCreatingPlatformWebView(view, options);
</del><ins>+    auto view = makeUniqueRef<PlatformWebView>(newConfiguration.get(), options);
+    finishCreatingPlatformWebView(view.ptr(), options);
</ins><span class="cx">     return view;
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>