Title: [287371] trunk
Revision
287371
Author
[email protected]
Date
2021-12-22 14:23:51 -0800 (Wed, 22 Dec 2021)

Log Message

PCM tests crashing with 'unlink' errors
https://bugs.webkit.org/show_bug.cgi?id=234565
<rdar://problem/86771766>

Reviewed by Alex Christensen.

Source/WebKit:

Close PCM and ITP databases before deleting their database files in
API testing. This adds 2 new SPIs on WKWebsiteDataStore to close the
respective databases. It also addresses the renaming FIXME for
NetworkProcess::simulatePrivateClickMeasurementSessionRestart.

No new tests. This will fix existing crashing PCM API tests.

* NetworkProcess/NetworkProcess.cpp:
(WebKit::NetworkProcess::closeITPDatabase):
(WebKit::NetworkProcess::closePCMDatabase):
(WebKit::NetworkProcess::simulatePrivateClickMeasurementSessionRestart):
(WebKit::NetworkProcess::simulateResourceLoadStatisticsSessionRestart): Deleted.
* NetworkProcess/NetworkProcess.h:
* NetworkProcess/NetworkProcess.messages.in:
* NetworkProcess/NetworkSession.cpp:
(WebKit::NetworkSession::destroyPrivateClickMeasurementStore):
(WebKit::NetworkSession::setPrivateClickMeasurementAppBundleIDForTesting):
(WebKit::NetworkSession::recreatePrivateClickMeasurementStore): Renamed.
Renamed to be more accurate. This function only deletes the database,
then the call in the completion handler recreates it. This also makes
it more clear when we reuse it to close the database.

* NetworkProcess/NetworkSession.h:
* UIProcess/API/C/WKPage.cpp:
(WKPageSimulatePrivateClickMeasurementSessionRestart):
(WKPageSimulateResourceLoadStatisticsSessionRestart): Deleted.
* UIProcess/API/C/WKPagePrivate.h:
* UIProcess/API/Cocoa/WKWebsiteDataStore.mm:
(-[WKWebsiteDataStore _closeDatabases:]):
* UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h:
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::simulatePrivateClickMeasurementSessionRestart):
(WebKit::WebPageProxy::simulateResourceLoadStatisticsSessionRestart): Deleted.
* UIProcess/WebPageProxy.h:
* UIProcess/WebsiteData/WebsiteDataStore.cpp:
(WebKit::WebsiteDataStore::closeDatabases):
* UIProcess/WebsiteData/WebsiteDataStore.h:

Tools:

* TestWebKitAPI/Tests/WebKitCocoa/PrivateClickMeasurement.mm:
(cleanUp):
Close the databases before removing the files.

(TEST):
* WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl:
* WebKitTestRunner/InjectedBundle/TestRunner.cpp:
(WTR::TestRunner::simulatePrivateClickMeasurementSessionRestart):
(WTR::TestRunner::simulateResourceLoadStatisticsSessionRestart): Deleted.
* WebKitTestRunner/InjectedBundle/TestRunner.h:
* WebKitTestRunner/TestController.cpp:
(WTR::TestController::simulatePrivateClickMeasurementSessionRestart):
(WTR::TestController::simulateResourceLoadStatisticsSessionRestart): Deleted.
* WebKitTestRunner/TestController.h:
* WebKitTestRunner/TestInvocation.cpp:
(WTR::TestInvocation::didReceiveSynchronousMessageFromInjectedBundle):
Rename.

LayoutTests:

* http/tests/privateClickMeasurement/expired-ad-click-gets-removed-on-session-start.html:
* http/tests/privateClickMeasurement/expired-attribution-report-gets-sent-on-session-start.html:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (287370 => 287371)


--- trunk/LayoutTests/ChangeLog	2021-12-22 21:03:40 UTC (rev 287370)
+++ trunk/LayoutTests/ChangeLog	2021-12-22 22:23:51 UTC (rev 287371)
@@ -1,3 +1,14 @@
+2021-12-22  Kate Cheney  <[email protected]>
+
+        PCM tests crashing with 'unlink' errors
+        https://bugs.webkit.org/show_bug.cgi?id=234565
+        <rdar://problem/86771766>
+
+        Reviewed by Alex Christensen.
+
+        * http/tests/privateClickMeasurement/expired-ad-click-gets-removed-on-session-start.html:
+        * http/tests/privateClickMeasurement/expired-attribution-report-gets-sent-on-session-start.html:
+
 2021-12-22  Wenson Hsieh  <[email protected]>
 
         [iOS] Scroll view pinch zoom gesture sometimes fails to recognize in WKWebView

Modified: trunk/LayoutTests/http/tests/privateClickMeasurement/expired-ad-click-gets-removed-on-session-start.html (287370 => 287371)


--- trunk/LayoutTests/http/tests/privateClickMeasurement/expired-ad-click-gets-removed-on-session-start.html	2021-12-22 21:03:40 UTC (rev 287370)
+++ trunk/LayoutTests/http/tests/privateClickMeasurement/expired-ad-click-gets-removed-on-session-start.html	2021-12-22 22:23:51 UTC (rev 287371)
@@ -62,7 +62,7 @@
                 activateElement("targetLink");
             } else if (window.location.search === "?stepTwo") {
                 window.testRunner.markPrivateClickMeasurementsAsExpiredForTesting();
-                window.testRunner.simulateResourceLoadStatisticsSessionRestart();
+                window.testRunner.simulatePrivateClickMeasurementSessionRestart();
                 convert(function() {
                     testRunner.dumpPrivateClickMeasurement();
                     document.body.removeChild(document.getElementById("targetLink"));

Modified: trunk/LayoutTests/http/tests/privateClickMeasurement/expired-attribution-report-gets-sent-on-session-start.html (287370 => 287371)


--- trunk/LayoutTests/http/tests/privateClickMeasurement/expired-attribution-report-gets-sent-on-session-start.html	2021-12-22 21:03:40 UTC (rev 287370)
+++ trunk/LayoutTests/http/tests/privateClickMeasurement/expired-attribution-report-gets-sent-on-session-start.html	2021-12-22 22:23:51 UTC (rev 287371)
@@ -47,7 +47,7 @@
         // Mark this attribution as past-due for reporting, and simulate a session restart to
         // make sure the attribution gets sent immediately.
         window.testRunner.markAttributedPrivateClickMeasurementsAsExpiredForTesting();
-        testRunner.simulateResourceLoadStatisticsSessionRestart();
+        testRunner.simulatePrivateClickMeasurementSessionRestart();
         testRunner.dumpPrivateClickMeasurement();
         document.body.removeChild(document.getElementById("targetLink"));
         document.body.removeChild(document.getElementById("pixel"));

Modified: trunk/Source/WebKit/ChangeLog (287370 => 287371)


--- trunk/Source/WebKit/ChangeLog	2021-12-22 21:03:40 UTC (rev 287370)
+++ trunk/Source/WebKit/ChangeLog	2021-12-22 22:23:51 UTC (rev 287371)
@@ -1,3 +1,49 @@
+2021-12-22  Kate Cheney  <[email protected]>
+
+        PCM tests crashing with 'unlink' errors
+        https://bugs.webkit.org/show_bug.cgi?id=234565
+        <rdar://problem/86771766>
+
+        Reviewed by Alex Christensen.
+
+        Close PCM and ITP databases before deleting their database files in
+        API testing. This adds 2 new SPIs on WKWebsiteDataStore to close the
+        respective databases. It also addresses the renaming FIXME for
+        NetworkProcess::simulatePrivateClickMeasurementSessionRestart.
+
+        No new tests. This will fix existing crashing PCM API tests.
+
+        * NetworkProcess/NetworkProcess.cpp:
+        (WebKit::NetworkProcess::closeITPDatabase):
+        (WebKit::NetworkProcess::closePCMDatabase):
+        (WebKit::NetworkProcess::simulatePrivateClickMeasurementSessionRestart):
+        (WebKit::NetworkProcess::simulateResourceLoadStatisticsSessionRestart): Deleted.
+        * NetworkProcess/NetworkProcess.h:
+        * NetworkProcess/NetworkProcess.messages.in:
+        * NetworkProcess/NetworkSession.cpp:
+        (WebKit::NetworkSession::destroyPrivateClickMeasurementStore):
+        (WebKit::NetworkSession::setPrivateClickMeasurementAppBundleIDForTesting):
+        (WebKit::NetworkSession::recreatePrivateClickMeasurementStore): Renamed.
+        Renamed to be more accurate. This function only deletes the database,
+        then the call in the completion handler recreates it. This also makes
+        it more clear when we reuse it to close the database.
+
+        * NetworkProcess/NetworkSession.h:
+        * UIProcess/API/C/WKPage.cpp:
+        (WKPageSimulatePrivateClickMeasurementSessionRestart):
+        (WKPageSimulateResourceLoadStatisticsSessionRestart): Deleted.
+        * UIProcess/API/C/WKPagePrivate.h:
+        * UIProcess/API/Cocoa/WKWebsiteDataStore.mm:
+        (-[WKWebsiteDataStore _closeDatabases:]):
+        * UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h:
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::simulatePrivateClickMeasurementSessionRestart):
+        (WebKit::WebPageProxy::simulateResourceLoadStatisticsSessionRestart): Deleted.
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/WebsiteData/WebsiteDataStore.cpp:
+        (WebKit::WebsiteDataStore::closeDatabases):
+        * UIProcess/WebsiteData/WebsiteDataStore.h:
+
 2021-12-22  Alex Christensen  <[email protected]>
 
         Fix compiling with pickier compiler

Modified: trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp (287370 => 287371)


--- trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp	2021-12-22 21:03:40 UTC (rev 287370)
+++ trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp	2021-12-22 22:23:51 UTC (rev 287371)
@@ -1988,6 +1988,17 @@
         });
     }
 }
+
+void NetworkProcess::closeITPDatabase(PAL::SessionID sessionID, CompletionHandler<void()>&& completionHandler)
+{
+    if (auto* session = networkSession(sessionID)) {
+        session->destroyResourceLoadStatistics(WTFMove(completionHandler));
+        return;
+    }
+
+    completionHandler();
+}
+
 #endif // ENABLE(INTELLIGENT_TRACKING_PREVENTION)
 
 void NetworkProcess::downloadRequest(PAL::SessionID sessionID, DownloadID downloadID, const ResourceRequest& request, std::optional<NavigatingToAppBoundDomain> isNavigatingToAppBoundDomain, const String& suggestedFilename)
@@ -2444,14 +2455,23 @@
     completionHandler();
 }
 
-void NetworkProcess::simulateResourceLoadStatisticsSessionRestart(PAL::SessionID sessionID, CompletionHandler<void()>&& completionHandler)
+void NetworkProcess::closePCMDatabase(PAL::SessionID sessionID, CompletionHandler<void()>&& completionHandler)
 {
+    if (auto* session = networkSession(sessionID)) {
+        session->destroyPrivateClickMeasurementStore(WTFMove(completionHandler));
+        return;
+    }
+
+    completionHandler();
+}
+
+void NetworkProcess::simulatePrivateClickMeasurementSessionRestart(PAL::SessionID sessionID, CompletionHandler<void()>&& completionHandler)
+{
     if (!allowsPrivateClickMeasurementTestFunctionality())
         return completionHandler();
 
-    // FIXME: Rename this to simulatePrivateClickMeasurementSessionRestart.
     if (auto* session = networkSession(sessionID)) {
-        session->recreatePrivateClickMeasurementStore([session = WeakPtr { *session }, completionHandler = WTFMove(completionHandler)] () mutable {
+        session->destroyPrivateClickMeasurementStore([session = WeakPtr { *session }, completionHandler = WTFMove(completionHandler)] () mutable {
             if (session)
                 session->firePrivateClickMeasurementTimerImmediatelyForTesting();
             completionHandler();

Modified: trunk/Source/WebKit/NetworkProcess/NetworkProcess.h (287370 => 287371)


--- trunk/Source/WebKit/NetworkProcess/NetworkProcess.h	2021-12-22 21:03:40 UTC (rev 287370)
+++ trunk/Source/WebKit/NetworkProcess/NetworkProcess.h	2021-12-22 22:23:51 UTC (rev 287371)
@@ -260,6 +260,7 @@
     void setCrossSiteLoadWithLinkDecorationForTesting(PAL::SessionID, const RegistrableDomain& fromDomain, const RegistrableDomain& toDomain, CompletionHandler<void()>&&);
     void resetCrossSiteLoadsWithLinkDecorationForTesting(PAL::SessionID, CompletionHandler<void()>&&);
     void hasIsolatedSession(PAL::SessionID, const WebCore::RegistrableDomain&, CompletionHandler<void(bool)>&&) const;
+    void closeITPDatabase(PAL::SessionID, CompletionHandler<void()>&&);
 #if ENABLE(APP_BOUND_DOMAINS)
     void setAppBoundDomainsForResourceLoadStatistics(PAL::SessionID, HashSet<WebCore::RegistrableDomain>&&, CompletionHandler<void()>&&);
 #endif
@@ -317,7 +318,8 @@
     void setPrivateClickMeasurementOverrideTimerForTesting(PAL::SessionID, bool value, CompletionHandler<void()>&&);
     void markAttributedPrivateClickMeasurementsAsExpiredForTesting(PAL::SessionID, CompletionHandler<void()>&&);
     void setPrivateClickMeasurementEphemeralMeasurementForTesting(PAL::SessionID, bool value, CompletionHandler<void()>&&);
-    void simulateResourceLoadStatisticsSessionRestart(PAL::SessionID, CompletionHandler<void()>&&);
+    void simulatePrivateClickMeasurementSessionRestart(PAL::SessionID, CompletionHandler<void()>&&);
+    void closePCMDatabase(PAL::SessionID, CompletionHandler<void()>&&);
     void setPrivateClickMeasurementTokenPublicKeyURLForTesting(PAL::SessionID, URL&&, CompletionHandler<void()>&&);
     void setPrivateClickMeasurementTokenSignatureURLForTesting(PAL::SessionID, URL&&, CompletionHandler<void()>&&);
     void setPrivateClickMeasurementAttributionReportURLsForTesting(PAL::SessionID, URL&& sourceURL, URL&& destinationURL, CompletionHandler<void()>&&);

Modified: trunk/Source/WebKit/NetworkProcess/NetworkProcess.messages.in (287370 => 287371)


--- trunk/Source/WebKit/NetworkProcess/NetworkProcess.messages.in	2021-12-22 21:03:40 UTC (rev 287370)
+++ trunk/Source/WebKit/NetworkProcess/NetworkProcess.messages.in	2021-12-22 22:23:51 UTC (rev 287371)
@@ -135,6 +135,7 @@
     ResetCrossSiteLoadsWithLinkDecorationForTesting(PAL::SessionID sessionID) -> () Async
     DeleteCookiesForTesting(PAL::SessionID sessionID, WebCore::RegistrableDomain domain, bool includeHttpOnlyCookies) -> () Async
     HasIsolatedSession(PAL::SessionID sessionID, WebCore::RegistrableDomain domain) -> (bool hasIsolatedSession) Async
+    CloseITPDatabase(PAL::SessionID sessionID) -> () Async
 #if ENABLE(APP_BOUND_DOMAINS)
     SetAppBoundDomainsForResourceLoadStatistics(PAL::SessionID sessionID, HashSet<WebCore::RegistrableDomain> appBoundDomains) -> () Async
 #endif
@@ -164,7 +165,7 @@
     SetPrivateClickMeasurementOverrideTimerForTesting(PAL::SessionID sessionID, bool value) -> () Async
     MarkAttributedPrivateClickMeasurementsAsExpiredForTesting(PAL::SessionID sessionID) -> () Async
     SetPrivateClickMeasurementEphemeralMeasurementForTesting(PAL::SessionID sessionID, bool value) -> () Async
-    SimulateResourceLoadStatisticsSessionRestart(PAL::SessionID sessionID) -> () Async
+    SimulatePrivateClickMeasurementSessionRestart(PAL::SessionID sessionID) -> () Async
     SetPrivateClickMeasurementTokenPublicKeyURLForTesting(PAL::SessionID sessionID, URL url) -> () Async
     SetPrivateClickMeasurementTokenSignatureURLForTesting(PAL::SessionID sessionID, URL url) -> () Async
     SetPrivateClickMeasurementAttributionReportURLsForTesting(PAL::SessionID sessionID, URL sourceURL, URL destinationURL) -> () Async
@@ -171,6 +172,7 @@
     MarkPrivateClickMeasurementsAsExpiredForTesting(PAL::SessionID sessionID) -> () Async
     SetPCMFraudPreventionValuesForTesting(PAL::SessionID sessionID, String secretToken, String unlinkableToken, String signature, String keyID) -> () Async
     SetPrivateClickMeasurementAppBundleIDForTesting(PAL::SessionID sessionID, String appBundleIDForTesting) -> () Async
+    ClosePCMDatabase(PAL::SessionID sessionID) -> () Async
 
     SetServiceWorkerFetchTimeoutForTesting(Seconds seconds) -> () Synchronous
     ResetServiceWorkerFetchTimeoutForTesting() -> () Synchronous

Modified: trunk/Source/WebKit/NetworkProcess/NetworkSession.cpp (287370 => 287371)


--- trunk/Source/WebKit/NetworkProcess/NetworkSession.cpp	2021-12-22 21:03:40 UTC (rev 287370)
+++ trunk/Source/WebKit/NetworkProcess/NetworkSession.cpp	2021-12-22 22:23:51 UTC (rev 287371)
@@ -211,7 +211,7 @@
 #endif
 }
 
-void NetworkSession::recreatePrivateClickMeasurementStore(CompletionHandler<void()>&& completionHandler)
+void NetworkSession::destroyPrivateClickMeasurementStore(CompletionHandler<void()>&& completionHandler)
 {
     privateClickMeasurement().destroyStoreForTesting(WTFMove(completionHandler));
 }
@@ -467,8 +467,6 @@
 {
 #if PLATFORM(COCOA)
     auto appBundleID = WebCore::applicationBundleIdentifier();
-    if (!isRunningTest(appBundleID))
-        WTFLogAlways("isRunningTest() returned false. appBundleID is %s.", appBundleID.isEmpty() ? "empty" : appBundleID.utf8().data());
     RELEASE_ASSERT(isRunningTest(WebCore::applicationBundleIdentifier()));
 #endif
     privateClickMeasurement().setPrivateClickMeasurementAppBundleIDForTesting(WTFMove(appBundleIDForTesting));

Modified: trunk/Source/WebKit/NetworkProcess/NetworkSession.h (287370 => 287371)


--- trunk/Source/WebKit/NetworkProcess/NetworkSession.h	2021-12-22 21:03:40 UTC (rev 287370)
+++ trunk/Source/WebKit/NetworkProcess/NetworkSession.h	2021-12-22 22:23:51 UTC (rev 287371)
@@ -114,7 +114,7 @@
     void registerNetworkDataTask(NetworkDataTask&);
     void unregisterNetworkDataTask(NetworkDataTask&);
 
-    void recreatePrivateClickMeasurementStore(CompletionHandler<void()>&&);
+    void destroyPrivateClickMeasurementStore(CompletionHandler<void()>&&);
 
 #if ENABLE(INTELLIGENT_TRACKING_PREVENTION)
     WebResourceLoadStatisticsStore* resourceLoadStatistics() const { return m_resourceLoadStatistics.get(); }

Modified: trunk/Source/WebKit/UIProcess/API/C/WKPage.cpp (287370 => 287371)


--- trunk/Source/WebKit/UIProcess/API/C/WKPage.cpp	2021-12-22 21:03:40 UTC (rev 287370)
+++ trunk/Source/WebKit/UIProcess/API/C/WKPage.cpp	2021-12-22 22:23:51 UTC (rev 287371)
@@ -3068,10 +3068,10 @@
     });
 }
 
-void WKPageSimulateResourceLoadStatisticsSessionRestart(WKPageRef pageRef, WKPageSimulateResourceLoadStatisticsSessionRestartFunction callback, void* callbackContext)
+void WKPageSimulatePrivateClickMeasurementSessionRestart(WKPageRef pageRef, WKPageSimulatePrivateClickMeasurementSessionRestartFunction callback, void* callbackContext)
 {
     CRASH_IF_SUSPENDED;
-    toImpl(pageRef)->simulateResourceLoadStatisticsSessionRestart([callbackContext, callback] () {
+    toImpl(pageRef)->simulatePrivateClickMeasurementSessionRestart([callbackContext, callback] () {
         callback(callbackContext);
     });
 }

Modified: trunk/Source/WebKit/UIProcess/API/C/WKPagePrivate.h (287370 => 287371)


--- trunk/Source/WebKit/UIProcess/API/C/WKPagePrivate.h	2021-12-22 21:03:40 UTC (rev 287370)
+++ trunk/Source/WebKit/UIProcess/API/C/WKPagePrivate.h	2021-12-22 22:23:51 UTC (rev 287371)
@@ -180,8 +180,8 @@
 WK_EXPORT void WKPageMarkAttributedPrivateClickMeasurementsAsExpiredForTesting(WKPageRef page, WKPageMarkAttributedPrivateClickMeasurementsAsExpiredForTestingFunction callback, void* callbackContext);
 typedef void (*WKPageSetPrivateClickMeasurementEphemeralMeasurementForTestingFunction)(void* functionContext);
 WK_EXPORT void WKPageSetPrivateClickMeasurementEphemeralMeasurementForTesting(WKPageRef page, bool value, WKPageSetPrivateClickMeasurementEphemeralMeasurementForTestingFunction callback, void* callbackContext);
-typedef void (*WKPageSimulateResourceLoadStatisticsSessionRestartFunction)(void* functionContext);
-WK_EXPORT void WKPageSimulateResourceLoadStatisticsSessionRestart(WKPageRef page, WKPageSimulateResourceLoadStatisticsSessionRestartFunction callback, void* callbackContext);
+typedef void (*WKPageSimulatePrivateClickMeasurementSessionRestartFunction)(void* functionContext);
+WK_EXPORT void WKPageSimulatePrivateClickMeasurementSessionRestart(WKPageRef page, WKPageSimulatePrivateClickMeasurementSessionRestartFunction callback, void* callbackContext);
 typedef void (*WKPageSetPrivateClickMeasurementTokenPublicKeyURLForTestingFunction)(void* functionContext);
 WK_EXPORT void WKPageSetPrivateClickMeasurementTokenPublicKeyURLForTesting(WKPageRef page, WKURLRef urlString, WKPageSetPrivateClickMeasurementTokenPublicKeyURLForTestingFunction callback, void* callbackContext);
 typedef void (*WKPageSetPrivateClickMeasurementTokenSignatureURLForTestingFunction)(void* functionContext);

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStore.mm (287370 => 287371)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStore.mm	2021-12-22 21:03:40 UTC (rev 287370)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStore.mm	2021-12-22 22:23:51 UTC (rev 287371)
@@ -535,6 +535,13 @@
 #endif
 }
 
+- (void)_closeDatabases:(void (^)(void))completionHandler
+{
+    _websiteDataStore->closeDatabases([completionHandler = makeBlockPtr(completionHandler)]() {
+        completionHandler();
+    });
+}
+
 - (void)_getResourceLoadStatisticsDataSummary:(void (^)(NSArray<_WKResourceLoadStatisticsThirdParty *> *))completionHandler
 {
 #if ENABLE(INTELLIGENT_TRACKING_PREVENTION)

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h (287370 => 287371)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h	2021-12-22 21:03:40 UTC (rev 287370)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h	2021-12-22 22:23:51 UTC (rev 287371)
@@ -74,6 +74,7 @@
 - (void)_getResourceLoadStatisticsDataSummary:(void (^)(NSArray<_WKResourceLoadStatisticsThirdParty *> *))completionHandler WK_API_AVAILABLE(macos(10.15.4), ios(13.4));
 - (void)_clearPrevalentDomain:(NSURL *)domain completionHandler:(void (^)(void))completionHandler WK_API_AVAILABLE(macos(10.15.4), ios(13.4));
 - (void)_clearResourceLoadStatistics:(void (^)(void))completionHandler WK_API_AVAILABLE(macos(10.15.4), ios(13.4));
+- (void)_closeDatabases:(void (^)(void))completionHandler WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
 - (void)_isRelationshipOnlyInDatabaseOnce:(NSURL *)firstPartyURL thirdParty:(NSURL *)thirdPartyURL completionHandler:(void (^)(BOOL))completionHandler WK_API_AVAILABLE(macos(12.0), ios(15.0));
 - (void)_isRegisteredAsSubresourceUnderFirstParty:(NSURL *)firstPartyURL thirdParty:(NSURL *)thirdPartyURL completionHandler:(void (^)(BOOL))completionHandler WK_API_AVAILABLE(macos(10.15.4), ios(13.4));
 - (void)_setThirdPartyCookieBlockingMode:(BOOL)enabled onlyOnSitesWithoutUserInteraction:(BOOL)onlyOnSitesWithoutUserInteraction completionHandler:(void (^)(void))completionHandler WK_API_AVAILABLE(macos(11.0), ios(14.0));

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.cpp (287370 => 287371)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2021-12-22 21:03:40 UTC (rev 287370)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2021-12-22 22:23:51 UTC (rev 287371)
@@ -10493,9 +10493,9 @@
     websiteDataStore().networkProcess().sendWithAsyncReply(Messages::NetworkProcess::SetPrivateClickMeasurementEphemeralMeasurementForTesting(m_websiteDataStore->sessionID(), value), WTFMove(completionHandler));
 }
 
-void WebPageProxy::simulateResourceLoadStatisticsSessionRestart(CompletionHandler<void()>&& completionHandler)
+void WebPageProxy::simulatePrivateClickMeasurementSessionRestart(CompletionHandler<void()>&& completionHandler)
 {
-    websiteDataStore().networkProcess().sendWithAsyncReply(Messages::NetworkProcess::SimulateResourceLoadStatisticsSessionRestart(m_websiteDataStore->sessionID()), WTFMove(completionHandler));
+    websiteDataStore().networkProcess().sendWithAsyncReply(Messages::NetworkProcess::SimulatePrivateClickMeasurementSessionRestart(m_websiteDataStore->sessionID()), WTFMove(completionHandler));
 }
 
 void WebPageProxy::setPrivateClickMeasurementTokenPublicKeyURLForTesting(const URL& url, CompletionHandler<void()>&& completionHandler)

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.h (287370 => 287371)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.h	2021-12-22 21:03:40 UTC (rev 287370)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.h	2021-12-22 22:23:51 UTC (rev 287371)
@@ -1808,7 +1808,7 @@
     void setPrivateClickMeasurementOverrideTimerForTesting(bool value, CompletionHandler<void()>&&);
     void markAttributedPrivateClickMeasurementsAsExpiredForTesting(CompletionHandler<void()>&&);
     void setPrivateClickMeasurementEphemeralMeasurementForTesting(bool value, CompletionHandler<void()>&&);
-    void simulateResourceLoadStatisticsSessionRestart(CompletionHandler<void()>&&);
+    void simulatePrivateClickMeasurementSessionRestart(CompletionHandler<void()>&&);
     void setPrivateClickMeasurementTokenPublicKeyURLForTesting(const URL&, CompletionHandler<void()>&&);
     void setPrivateClickMeasurementTokenSignatureURLForTesting(const URL&, CompletionHandler<void()>&&);
     void setPrivateClickMeasurementAttributionReportURLsForTesting(const URL& sourceURL, const URL& destinationURL, CompletionHandler<void()>&&);

Modified: trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp (287370 => 287371)


--- trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp	2021-12-22 21:03:40 UTC (rev 287370)
+++ trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp	2021-12-22 22:23:51 UTC (rev 287371)
@@ -1723,7 +1723,18 @@
     networkProcess().setPrivateClickMeasurementDebugMode(sessionID(), enabled);
 }
 
+void WebsiteDataStore::closeDatabases(CompletionHandler<void()>&& completionHandler)
+{
+    auto callbackAggregator = CallbackAggregator::create(WTFMove(completionHandler));
+
+    networkProcess().sendWithAsyncReply(Messages::NetworkProcess::ClosePCMDatabase(m_sessionID), [callbackAggregator] { });
+
 #if ENABLE(INTELLIGENT_TRACKING_PREVENTION)
+    networkProcess().sendWithAsyncReply(Messages::NetworkProcess::CloseITPDatabase(m_sessionID), [callbackAggregator] { });
+#endif
+}
+
+#if ENABLE(INTELLIGENT_TRACKING_PREVENTION)
 void WebsiteDataStore::logTestingEvent(const String& event)
 {
     ASSERT(RunLoop::isMain());

Modified: trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.h (287370 => 287371)


--- trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.h	2021-12-22 21:03:40 UTC (rev 287370)
+++ trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.h	2021-12-22 22:23:51 UTC (rev 287371)
@@ -237,6 +237,7 @@
     bool isItpStateExplicitlySet() const { return m_isItpStateExplicitlySet; }
     void useExplicitITPState() { m_isItpStateExplicitlySet = true; }
 #endif
+    void closeDatabases(CompletionHandler<void()>&&);
     void syncLocalStorage(CompletionHandler<void()>&&);
     void setCacheMaxAgeCapForPrevalentResources(Seconds, CompletionHandler<void()>&&);
     void resetCacheMaxAgeCapForPrevalentResources(CompletionHandler<void()>&&);

Modified: trunk/Tools/ChangeLog (287370 => 287371)


--- trunk/Tools/ChangeLog	2021-12-22 21:03:40 UTC (rev 287370)
+++ trunk/Tools/ChangeLog	2021-12-22 22:23:51 UTC (rev 287371)
@@ -1,3 +1,29 @@
+2021-12-22  Kate Cheney  <[email protected]>
+
+        PCM tests crashing with 'unlink' errors
+        https://bugs.webkit.org/show_bug.cgi?id=234565
+        <rdar://problem/86771766>
+
+        Reviewed by Alex Christensen.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/PrivateClickMeasurement.mm:
+        (cleanUp):
+        Close the databases before removing the files.
+
+        (TEST):
+        * WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl:
+        * WebKitTestRunner/InjectedBundle/TestRunner.cpp:
+        (WTR::TestRunner::simulatePrivateClickMeasurementSessionRestart):
+        (WTR::TestRunner::simulateResourceLoadStatisticsSessionRestart): Deleted.
+        * WebKitTestRunner/InjectedBundle/TestRunner.h:
+        * WebKitTestRunner/TestController.cpp:
+        (WTR::TestController::simulatePrivateClickMeasurementSessionRestart):
+        (WTR::TestController::simulateResourceLoadStatisticsSessionRestart): Deleted.
+        * WebKitTestRunner/TestController.h:
+        * WebKitTestRunner/TestInvocation.cpp:
+        (WTR::TestInvocation::didReceiveSynchronousMessageFromInjectedBundle):
+        Rename.
+
 2021-12-22  Alex Christensen  <[email protected]>
 
         Fix compiling with pickier compiler

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/PrivateClickMeasurement.mm (287370 => 287371)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/PrivateClickMeasurement.mm	2021-12-22 21:03:40 UTC (rev 287370)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/PrivateClickMeasurement.mm	2021-12-22 22:23:51 UTC (rev 287371)
@@ -311,14 +311,18 @@
     return fileURL.path;
 }
 
-static void cleanUp()
+static void cleanUp(RetainPtr<WKWebView> webView)
 {
-    NSFileManager *defaultFileManager = NSFileManager.defaultManager;
-    NSString *itpRoot = WKWebsiteDataStore.defaultDataStore._configuration._resourceLoadStatisticsDirectory.path;
-    [defaultFileManager removeItemAtPath:itpRoot error:nil];
-    while ([defaultFileManager fileExistsAtPath:itpRoot])
-        usleep(10000);
-    EXPECT_FALSE([defaultFileManager fileExistsAtPath:itpRoot]);
+    static bool isDone = false;
+    [[webView.get() configuration].websiteDataStore _closeDatabases:^{
+        NSFileManager *defaultFileManager = NSFileManager.defaultManager;
+        NSString *itpRoot = WKWebsiteDataStore.defaultDataStore._configuration._resourceLoadStatisticsDirectory.path;
+        [defaultFileManager removeItemAtPath:itpRoot error:nil];
+        while ([defaultFileManager fileExistsAtPath:itpRoot])
+            usleep(10000);
+        isDone = true;
+    }];
+    TestWebKitAPI::Util::run(&isDone);
 }
 
 static void createAndPopulateObservedDomainTable(WebCore::SQLiteDatabase& database)
@@ -384,7 +388,7 @@
     setUpFromResourceLoadStatisticsDatabase(addUnattributedPCMv1, addAttributedPCMv1);
     auto webView = webViewWithResourceLoadStatisticsEnabledInNetworkProcess();
     pollUntilPCMIsMigrated(webView.get(), MigratingFromResourceLoadStatistics::Yes, UsingDestinationToken::No);
-    cleanUp();
+    cleanUp(webView);
 }
 
 TEST(PrivateClickMeasurement, MigrateFromResourceLoadStatistics2)
@@ -392,7 +396,7 @@
     setUpFromResourceLoadStatisticsDatabase(addUnattributedPCMv2, addAttributedPCMv2);
     auto webView = webViewWithResourceLoadStatisticsEnabledInNetworkProcess();
     pollUntilPCMIsMigrated(webView.get(), MigratingFromResourceLoadStatistics::Yes, UsingDestinationToken::No);
-    cleanUp();
+    cleanUp(webView);
 }
 
 TEST(PrivateClickMeasurement, MigrateFromResourceLoadStatistics3)
@@ -400,7 +404,7 @@
     setUpFromResourceLoadStatisticsDatabase(addUnattributedPCMv3, addAttributedPCMv3);
     auto webView = webViewWithResourceLoadStatisticsEnabledInNetworkProcess();
     pollUntilPCMIsMigrated(webView.get(), MigratingFromResourceLoadStatistics::Yes, UsingDestinationToken::No);
-    cleanUp();
+    cleanUp(webView);
 }
 
 TEST(PrivateClickMeasurement, MigrateFromPCM1)
@@ -408,7 +412,7 @@
     setUpFromPCMDatabase(addUnattributedPCMv4, addAttributedPCMv4);
     auto webView = webViewWithResourceLoadStatisticsEnabledInNetworkProcess();
     pollUntilPCMIsMigrated(webView.get(), MigratingFromResourceLoadStatistics::No, UsingDestinationToken::No);
-    cleanUp();
+    cleanUp(webView);
 }
 
 TEST(PrivateClickMeasurement, MigrateWithDestinationToken)
@@ -416,5 +420,5 @@
     setUpFromPCMDatabase(addUnattributedPCMv4, addAttributedPCMv5);
     auto webView = webViewWithResourceLoadStatisticsEnabledInNetworkProcess();
     pollUntilPCMIsMigrated(webView.get(), MigratingFromResourceLoadStatistics::No, UsingDestinationToken::Yes);
-    cleanUp();
+    cleanUp(webView);
 }

Modified: trunk/Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl (287370 => 287371)


--- trunk/Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl	2021-12-22 21:03:40 UTC (rev 287370)
+++ trunk/Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl	2021-12-22 22:23:51 UTC (rev 287371)
@@ -412,7 +412,7 @@
     undefined setPrivateClickMeasurementOverrideTimerForTesting(boolean value);
     undefined markAttributedPrivateClickMeasurementsAsExpiredForTesting();
     undefined setPrivateClickMeasurementEphemeralMeasurementForTesting(boolean value);
-    undefined simulateResourceLoadStatisticsSessionRestart();
+    undefined simulatePrivateClickMeasurementSessionRestart();
     undefined setPrivateClickMeasurementTokenPublicKeyURLForTesting(DOMString url);
     undefined setPrivateClickMeasurementTokenSignatureURLForTesting(DOMString url);
     undefined setPrivateClickMeasurementAttributionReportURLsForTesting(DOMString sourceURLString, DOMString destinationURLString);

Modified: trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp (287370 => 287371)


--- trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp	2021-12-22 21:03:40 UTC (rev 287370)
+++ trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp	2021-12-22 22:23:51 UTC (rev 287371)
@@ -2086,9 +2086,9 @@
     postSynchronousPageMessage("SetPrivateClickMeasurementEphemeralMeasurementForTesting", value);
 }
 
-void TestRunner::simulateResourceLoadStatisticsSessionRestart()
+void TestRunner::simulatePrivateClickMeasurementSessionRestart()
 {
-    postSynchronousPageMessage("SimulateResourceLoadStatisticsSessionRestart");
+    postSynchronousPageMessage("SimulatePrivateClickMeasurementSessionRestart");
 }
 
 void TestRunner::setPrivateClickMeasurementTokenPublicKeyURLForTesting(JSStringRef urlString)

Modified: trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.h (287370 => 287371)


--- trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.h	2021-12-22 21:03:40 UTC (rev 287370)
+++ trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.h	2021-12-22 22:23:51 UTC (rev 287371)
@@ -535,7 +535,7 @@
     void setPrivateClickMeasurementEphemeralMeasurementForTesting(bool value);
     void setPrivateClickMeasurementFraudPreventionValuesForTesting(JSStringRef unlinkableToken, JSStringRef secretToken, JSStringRef signature, JSStringRef keyID);
     void setPrivateClickMeasurementAppBundleIDForTesting(JSStringRef);
-    void simulateResourceLoadStatisticsSessionRestart();
+    void simulatePrivateClickMeasurementSessionRestart();
 
     void setIsSpeechRecognitionPermissionGranted(bool);
 

Modified: trunk/Tools/WebKitTestRunner/TestController.cpp (287370 => 287371)


--- trunk/Tools/WebKitTestRunner/TestController.cpp	2021-12-22 21:03:40 UTC (rev 287370)
+++ trunk/Tools/WebKitTestRunner/TestController.cpp	2021-12-22 22:23:51 UTC (rev 287371)
@@ -3780,10 +3780,10 @@
     runUntil(callbackContext.done, noTimeout);
 }
 
-void TestController::simulateResourceLoadStatisticsSessionRestart()
+void TestController::simulatePrivateClickMeasurementSessionRestart()
 {
     PrivateClickMeasurementVoidCallbackContext callbackContext(*this);
-    WKPageSimulateResourceLoadStatisticsSessionRestart(m_mainWebView->page(), privateClickMeasurementVoidCallback, &callbackContext);
+    WKPageSimulatePrivateClickMeasurementSessionRestart(m_mainWebView->page(), privateClickMeasurementVoidCallback, &callbackContext);
     runUntil(callbackContext.done, noTimeout);
 }
 

Modified: trunk/Tools/WebKitTestRunner/TestController.h (287370 => 287371)


--- trunk/Tools/WebKitTestRunner/TestController.h	2021-12-22 21:03:40 UTC (rev 287370)
+++ trunk/Tools/WebKitTestRunner/TestController.h	2021-12-22 22:23:51 UTC (rev 287371)
@@ -351,7 +351,7 @@
     void setPrivateClickMeasurementOverrideTimerForTesting(bool value);
     void markAttributedPrivateClickMeasurementsAsExpiredForTesting();
     void setPrivateClickMeasurementEphemeralMeasurementForTesting(bool value);
-    void simulateResourceLoadStatisticsSessionRestart();
+    void simulatePrivateClickMeasurementSessionRestart();
     void setPrivateClickMeasurementTokenPublicKeyURLForTesting(WKURLRef);
     void setPrivateClickMeasurementTokenSignatureURLForTesting(WKURLRef);
     void setPrivateClickMeasurementAttributionReportURLsForTesting(WKURLRef sourceURL, WKURLRef destinationURL);

Modified: trunk/Tools/WebKitTestRunner/TestInvocation.cpp (287370 => 287371)


--- trunk/Tools/WebKitTestRunner/TestInvocation.cpp	2021-12-22 21:03:40 UTC (rev 287370)
+++ trunk/Tools/WebKitTestRunner/TestInvocation.cpp	2021-12-22 22:23:51 UTC (rev 287371)
@@ -1387,8 +1387,8 @@
         return nullptr;
     }
     
-    if (WKStringIsEqualToUTF8CString(messageName, "SimulateResourceLoadStatisticsSessionRestart")) {
-        TestController::singleton().simulateResourceLoadStatisticsSessionRestart();
+    if (WKStringIsEqualToUTF8CString(messageName, "SimulatePrivateClickMeasurementSessionRestart")) {
+        TestController::singleton().simulatePrivateClickMeasurementSessionRestart();
         return nullptr;
     }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to