Title: [291851] trunk
Revision
291851
Author
[email protected]
Date
2022-03-25 01:54:16 -0700 (Fri, 25 Mar 2022)

Log Message

Introduce an SPI to get website data directory for origin and use it in API tests
https://bugs.webkit.org/show_bug.cgi?id=238269

Reviewed by Alex Christensen.

Source/WebKit:

There are a few tests using hardcoded website data paths to check if files are correcly modified by API.
Everytime we migrate website data (for example, if we start using general storage directory for IndexedDB
storage), we need to update these tests with new paths, otherwise the tests will check the wrong paths. Let's
just add an SPI so these tests can get the paths in use dynamically, which would avoid test breakage when
we do website data migration.

* NetworkProcess/NetworkProcess.cpp:
(WebKit::NetworkProcess::websiteDataOriginDirectoryForTesting):
* NetworkProcess/NetworkProcess.h:
* NetworkProcess/NetworkProcess.messages.in:
* NetworkProcess/storage/NetworkStorageManager.cpp:
(WebKit::NetworkStorageManager::moveData):
(WebKit::NetworkStorageManager::getOriginDirectory):
* NetworkProcess/storage/NetworkStorageManager.h:
* NetworkProcess/storage/OriginStorageManager.cpp:
(WebKit::OriginStorageManager::StorageBucket::toStorageType const):
(WebKit::OriginStorageManager::StorageBucket::resolvedLocalStoragePath):
(WebKit::OriginStorageManager::StorageBucket::resolvedIDBStoragePath):
(WebKit::OriginStorageManager::StorageBucket::resolvedPath):
(WebKit::OriginStorageManager::resolvedPath):
(WebKit::OriginStorageManager::resolvedLocalStoragePath): Deleted.
(WebKit::OriginStorageManager::resolvedIDBStoragePath): Deleted.
* NetworkProcess/storage/OriginStorageManager.h:
* UIProcess/API/Cocoa/WKWebsiteDataStore.mm:
(-[WKWebsiteDataStore _originDirectoryForTesting:topOrigin:type:completionHandler:]):
* UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h:
* UIProcess/Network/NetworkProcessProxy.cpp:
(WebKit::NetworkProcessProxy::websiteDataOriginDirectoryForTesting):
* UIProcess/Network/NetworkProcessProxy.h:
* UIProcess/WebsiteData/WebsiteDataStore.cpp:
(WebKit::WebsiteDataStore::originDirectoryForTesting):
* UIProcess/WebsiteData/WebsiteDataStore.h:

Tools:

* TestWebKitAPI/Tests/WebKitCocoa/IDBCheckpointWAL.mm:
(TEST):
* TestWebKitAPI/Tests/WebKitCocoa/IDBIndexUpgradeToV2.mm:
(runMultipleIndicesTestWithDatabase):
* TestWebKitAPI/Tests/WebKitCocoa/IndexedDBFileName.mm:
(runTest):
(TEST):
* TestWebKitAPI/Tests/WebKitCocoa/IndexedDBPersistence.mm:
* TestWebKitAPI/Tests/WebKitCocoa/IndexedDBTempFileSize.mm:
(TEST):
* TestWebKitAPI/Tests/WebKitCocoa/StoreBlobThenDelete.mm:
(TEST):
* TestWebKitAPI/Tests/WebKitCocoa/WebsiteDataStoreCustomPaths.mm:
(runWebsiteDataStoreCustomPaths):

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (291850 => 291851)


--- trunk/Source/WebKit/ChangeLog	2022-03-25 07:43:36 UTC (rev 291850)
+++ trunk/Source/WebKit/ChangeLog	2022-03-25 08:54:16 UTC (rev 291851)
@@ -1,3 +1,43 @@
+2022-03-25  Sihui Liu  <[email protected]>
+
+        Introduce an SPI to get website data directory for origin and use it in API tests
+        https://bugs.webkit.org/show_bug.cgi?id=238269
+
+        Reviewed by Alex Christensen.
+
+        There are a few tests using hardcoded website data paths to check if files are correcly modified by API.
+        Everytime we migrate website data (for example, if we start using general storage directory for IndexedDB 
+        storage), we need to update these tests with new paths, otherwise the tests will check the wrong paths. Let's 
+        just add an SPI so these tests can get the paths in use dynamically, which would avoid test breakage when
+        we do website data migration.
+
+        * NetworkProcess/NetworkProcess.cpp:
+        (WebKit::NetworkProcess::websiteDataOriginDirectoryForTesting):
+        * NetworkProcess/NetworkProcess.h:
+        * NetworkProcess/NetworkProcess.messages.in:
+        * NetworkProcess/storage/NetworkStorageManager.cpp:
+        (WebKit::NetworkStorageManager::moveData):
+        (WebKit::NetworkStorageManager::getOriginDirectory):
+        * NetworkProcess/storage/NetworkStorageManager.h:
+        * NetworkProcess/storage/OriginStorageManager.cpp:
+        (WebKit::OriginStorageManager::StorageBucket::toStorageType const):
+        (WebKit::OriginStorageManager::StorageBucket::resolvedLocalStoragePath):
+        (WebKit::OriginStorageManager::StorageBucket::resolvedIDBStoragePath):
+        (WebKit::OriginStorageManager::StorageBucket::resolvedPath):
+        (WebKit::OriginStorageManager::resolvedPath):
+        (WebKit::OriginStorageManager::resolvedLocalStoragePath): Deleted.
+        (WebKit::OriginStorageManager::resolvedIDBStoragePath): Deleted.
+        * NetworkProcess/storage/OriginStorageManager.h:
+        * UIProcess/API/Cocoa/WKWebsiteDataStore.mm:
+        (-[WKWebsiteDataStore _originDirectoryForTesting:topOrigin:type:completionHandler:]):
+        * UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h:
+        * UIProcess/Network/NetworkProcessProxy.cpp:
+        (WebKit::NetworkProcessProxy::websiteDataOriginDirectoryForTesting):
+        * UIProcess/Network/NetworkProcessProxy.h:
+        * UIProcess/WebsiteData/WebsiteDataStore.cpp:
+        (WebKit::WebsiteDataStore::originDirectoryForTesting):
+        * UIProcess/WebsiteData/WebsiteDataStore.h:
+
 2022-03-24  Don Olmstead  <[email protected]>
 
         Non-unified build fixes, late March 2022 edition

Modified: trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp (291850 => 291851)


--- trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp	2022-03-25 07:43:36 UTC (rev 291850)
+++ trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp	2022-03-25 08:54:16 UTC (rev 291851)
@@ -2259,6 +2259,16 @@
         session->storageManager().moveData(dataTypes, WTFMove(oldOrigin), WTFMove(newOrigin), [aggregator] { });
 }
 
+void NetworkProcess::websiteDataOriginDirectoryForTesting(PAL::SessionID sessionID, const URL& origin, const URL& topOrigin, WebsiteDataType dataType, CompletionHandler<void(const String&)>&& completionHandler)
+{
+    auto* session = networkSession(sessionID);
+    if (!session)
+        return completionHandler({ });
+
+    auto clientOrigin = WebCore::ClientOrigin { WebCore::SecurityOriginData::fromURL(topOrigin), WebCore::SecurityOriginData::fromURL(origin) };
+    session->storageManager().getOriginDirectory(WTFMove(clientOrigin), dataType, WTFMove(completionHandler));
+}
+
 #if ENABLE(SERVICE_WORKER)
 #if ENABLE(BUILT_IN_NOTIFICATIONS)
 

Modified: trunk/Source/WebKit/NetworkProcess/NetworkProcess.h (291850 => 291851)


--- trunk/Source/WebKit/NetworkProcess/NetworkProcess.h	2022-03-25 07:43:36 UTC (rev 291850)
+++ trunk/Source/WebKit/NetworkProcess/NetworkProcess.h	2022-03-25 08:54:16 UTC (rev 291851)
@@ -292,6 +292,7 @@
     void clearStorage(PAL::SessionID, CompletionHandler<void()>&&);
     void didIncreaseQuota(PAL::SessionID, WebCore::ClientOrigin&&, QuotaIncreaseRequestIdentifier, std::optional<uint64_t> newQuota);
     void renameOriginInWebsiteData(PAL::SessionID, const URL&, const URL&, OptionSet<WebsiteDataType>, CompletionHandler<void()>&&);
+    void websiteDataOriginDirectoryForTesting(PAL::SessionID, const URL&, const URL&, WebsiteDataType, CompletionHandler<void(const String&)>&&);
 
 #if PLATFORM(IOS_FAMILY)
     bool parentProcessHasServiceWorkerEntitlement() const;

Modified: trunk/Source/WebKit/NetworkProcess/NetworkProcess.messages.in (291850 => 291851)


--- trunk/Source/WebKit/NetworkProcess/NetworkProcess.messages.in	2022-03-25 07:43:36 UTC (rev 291850)
+++ trunk/Source/WebKit/NetworkProcess/NetworkProcess.messages.in	2022-03-25 08:54:16 UTC (rev 291851)
@@ -46,6 +46,7 @@
     DeleteWebsiteData(PAL::SessionID sessionID, OptionSet<WebKit::WebsiteDataType> websiteDataTypes, WallTime modifiedSince) -> ()
     DeleteWebsiteDataForOrigins(PAL::SessionID sessionID, OptionSet<WebKit::WebsiteDataType> websiteDataTypes, Vector<WebCore::SecurityOriginData> origins, Vector<String> cookieHostNames, Vector<String> HSTSCacheHostNames, Vector<WebCore::RegistrableDomain> registrableDomains) -> ()
     RenameOriginInWebsiteData(PAL::SessionID sessionID, URL oldDomain, URL newDomain, OptionSet<WebKit::WebsiteDataType> websiteDataTypes) -> ()
+    WebsiteDataOriginDirectoryForTesting(PAL::SessionID sessionID, URL origin, URL topOrigin, enum:uint32_t WebKit::WebsiteDataType websiteDataType) -> (String directory)
 
     DownloadRequest(PAL::SessionID sessionID, WebKit::DownloadID downloadID, WebCore::ResourceRequest request, enum:bool std::optional<WebKit::NavigatingToAppBoundDomain> isNavigatingToAppBoundDomain, String suggestedFilename)
     ResumeDownload(PAL::SessionID sessionID, WebKit::DownloadID downloadID, IPC::DataReference resumeData, String path, WebKit::SandboxExtension::Handle sandboxExtensionHandle, enum:bool WebKit::CallDownloadDidStart callDownloadDidStart)

Modified: trunk/Source/WebKit/NetworkProcess/storage/NetworkStorageManager.cpp (291850 => 291851)


--- trunk/Source/WebKit/NetworkProcess/storage/NetworkStorageManager.cpp	2022-03-25 07:43:36 UTC (rev 291850)
+++ trunk/Source/WebKit/NetworkProcess/storage/NetworkStorageManager.cpp	2022-03-25 08:54:16 UTC (rev 291851)
@@ -632,7 +632,7 @@
         localOriginStorageManager(targetOrigin).deleteData(types, -WallTime::infinity());
 
         // Move data from source origin to target origin.
-        localOriginStorageManager(sourceOrigin).moveData(types, localOriginStorageManager(targetOrigin).resolvedLocalStoragePath(), localOriginStorageManager(targetOrigin).resolvedIDBStoragePath());
+        localOriginStorageManager(sourceOrigin).moveData(types, localOriginStorageManager(targetOrigin).resolvedPath(WebsiteDataType::LocalStorage), localOriginStorageManager(targetOrigin).resolvedPath(WebsiteDataType::IndexedDBDatabases));
 
         removeOriginStorageManagerIfPossible(targetOrigin);
         removeOriginStorageManagerIfPossible(sourceOrigin);
@@ -641,6 +641,19 @@
     });
 }
 
+void NetworkStorageManager::getOriginDirectory(WebCore::ClientOrigin&& origin, WebsiteDataType type, CompletionHandler<void(const String&)>&& completionHandler)
+{
+    ASSERT(RunLoop::isMain());
+    ASSERT(!m_closed);
+
+    m_queue->dispatch([this, protectedThis = Ref { *this }, type, origin = crossThreadCopy(WTFMove(origin)), completionHandler = WTFMove(completionHandler)]() mutable {
+        RunLoop::main().dispatch([completionHandler = WTFMove(completionHandler), directory = crossThreadCopy(localOriginStorageManager(origin).resolvedPath(type))]() mutable {
+            completionHandler(WTFMove(directory));
+        });
+        removeOriginStorageManagerIfPossible(origin);
+    });
+}
+
 void NetworkStorageManager::suspend(CompletionHandler<void()>&& completionHandler)
 {
     ASSERT(RunLoop::isMain());

Modified: trunk/Source/WebKit/NetworkProcess/storage/NetworkStorageManager.h (291850 => 291851)


--- trunk/Source/WebKit/NetworkProcess/storage/NetworkStorageManager.h	2022-03-25 07:43:36 UTC (rev 291850)
+++ trunk/Source/WebKit/NetworkProcess/storage/NetworkStorageManager.h	2022-03-25 08:54:16 UTC (rev 291851)
@@ -86,6 +86,7 @@
     void deleteDataModifiedSince(OptionSet<WebsiteDataType>, WallTime, CompletionHandler<void()>&&);
     void deleteDataForRegistrableDomains(OptionSet<WebsiteDataType>, const Vector<WebCore::RegistrableDomain>&, CompletionHandler<void(HashSet<WebCore::RegistrableDomain>&&)>&&);
     void moveData(OptionSet<WebsiteDataType>, WebCore::SecurityOriginData&& source, WebCore::SecurityOriginData&& target, CompletionHandler<void()>&&);
+    void getOriginDirectory(WebCore::ClientOrigin&&, WebsiteDataType, CompletionHandler<void(const String&)>&&);
     void suspend(CompletionHandler<void()>&&);
     void resume();
     void handleLowMemoryWarning();

Modified: trunk/Source/WebKit/NetworkProcess/storage/OriginStorageManager.cpp (291850 => 291851)


--- trunk/Source/WebKit/NetworkProcess/storage/OriginStorageManager.cpp	2022-03-25 07:43:36 UTC (rev 291850)
+++ trunk/Source/WebKit/NetworkProcess/storage/OriginStorageManager.cpp	2022-03-25 08:54:16 UTC (rev 291851)
@@ -54,6 +54,7 @@
         SessionStorage,
         IndexedDB,
     };
+    std::optional<StorageType> toStorageType(WebsiteDataType) const;
     String toStorageIdentifier(StorageType) const;
     StorageBucket(const String& rootPath, const String& identifier, const String& localStoragePath, const String& idbStoragePath, bool shouldUseCustomPaths);
     StorageBucketMode mode() const { return m_mode; }
@@ -74,6 +75,7 @@
     void moveData(OptionSet<WebsiteDataType>, const String& localStoragePath, const String& idbStoragePath);
     String resolvedLocalStoragePath();
     String resolvedIDBStoragePath();
+    String resolvedPath(WebsiteDataType);
 
 private:
     OptionSet<WebsiteDataType> fetchDataTypesInListFromMemory(OptionSet<WebsiteDataType>);
@@ -118,6 +120,25 @@
         m_sessionStorageManager->connectionClosed(connection);
 }
 
+std::optional<OriginStorageManager::StorageBucket::StorageType> OriginStorageManager::StorageBucket::toStorageType(WebsiteDataType websiteDataType) const
+{
+    switch (websiteDataType) {
+    case WebsiteDataType::FileSystem:
+        return StorageType::FileSystem;
+    case WebsiteDataType::LocalStorage:
+        return StorageType::LocalStorage;
+    case WebsiteDataType::SessionStorage:
+        return StorageType::SessionStorage;
+    case WebsiteDataType::IndexedDBDatabases:
+        return StorageType::IndexedDB;
+    default:
+        break;
+    }
+
+    ASSERT_NOT_REACHED();
+    return std::nullopt;
+}
+
 String OriginStorageManager::StorageBucket::toStorageIdentifier(StorageType type) const
 {
     switch (type) {
@@ -352,10 +373,10 @@
         m_resolvedLocalStoragePath = m_customLocalStoragePath;
     } else if (!m_rootPath.isEmpty()) {
         auto localStorageDirectory = typeStoragePath(StorageType::LocalStorage);
-        FileSystem::makeAllDirectories(localStorageDirectory);
         auto localStoragePath = LocalStorageManager::localStorageFilePath(localStorageDirectory);
         if (!m_customLocalStoragePath.isEmpty() && !FileSystem::fileExists(localStoragePath) && FileSystem::fileExists(m_customLocalStoragePath)) {
             RELEASE_LOG(Storage, "%p - StorageBucket::resolvedLocalStoragePath New path '%{public}s'", this, localStoragePath.utf8().data());
+            FileSystem::makeAllDirectories(localStorageDirectory);
             auto moved = WebCore::SQLiteFileSystem::moveDatabaseFile(m_customLocalStoragePath, localStoragePath);
             if (!moved && !FileSystem::fileExists(localStoragePath))
                 RELEASE_LOG_ERROR(Storage, "%p - StorageBucket::resolvedLocalStoragePath Fails to migrate file to new path", this);
@@ -395,11 +416,27 @@
         }
         m_resolvedIDBStoragePath = idbStoragePath;
     }
-    
     ASSERT(!m_resolvedIDBStoragePath.isNull());
     return m_resolvedIDBStoragePath;
 }
 
+String OriginStorageManager::StorageBucket::resolvedPath(WebsiteDataType webisteDataType)
+{
+    auto type = toStorageType(webisteDataType);
+    if (!type)
+        return { };
+
+    switch (*type) {
+    case StorageType::LocalStorage:
+        return resolvedLocalStoragePath();
+    case StorageType::IndexedDB:
+        return resolvedIDBStoragePath();
+    case StorageType::SessionStorage:
+    case StorageType::FileSystem:
+        return typeStoragePath(*type);
+    }
+}
+
 String OriginStorageManager::originFileIdentifier()
 {
     return originFileName;
@@ -493,16 +530,11 @@
     return defaultBucket().existingIDBStorageManager();
 }
 
-String OriginStorageManager::resolvedLocalStoragePath()
+String OriginStorageManager::resolvedPath(WebsiteDataType type)
 {
-    return defaultBucket().resolvedLocalStoragePath();
+    return defaultBucket().resolvedPath(type);
 }
 
-String OriginStorageManager::resolvedIDBStoragePath()
-{
-    return defaultBucket().resolvedIDBStoragePath();
-}
-
 bool OriginStorageManager::isActive()
 {
     return defaultBucket().isActive();

Modified: trunk/Source/WebKit/NetworkProcess/storage/OriginStorageManager.h (291850 => 291851)


--- trunk/Source/WebKit/NetworkProcess/storage/OriginStorageManager.h	2022-03-25 07:43:36 UTC (rev 291850)
+++ trunk/Source/WebKit/NetworkProcess/storage/OriginStorageManager.h	2022-03-25 08:54:16 UTC (rev 291851)
@@ -59,8 +59,7 @@
     SessionStorageManager* existingSessionStorageManager();
     IDBStorageManager& idbStorageManager(IDBStorageRegistry&);
     IDBStorageManager* existingIDBStorageManager();
-    String resolvedLocalStoragePath();
-    String resolvedIDBStoragePath();
+    String resolvedPath(WebsiteDataType);
     bool isActive();
     bool isEmpty();
     OptionSet<WebsiteDataType> fetchDataTypesInList(OptionSet<WebsiteDataType>);

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


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStore.mm	2022-03-25 07:43:36 UTC (rev 291850)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStore.mm	2022-03-25 08:54:16 UTC (rev 291851)
@@ -844,4 +844,16 @@
         });
 }
 
+-(void)_originDirectoryForTesting:(NSURL *)origin topOrigin:(NSURL *)topOrigin type:(NSString *)dataType completionHandler:(void(^)(NSString *))completionHandler
+{
+    auto websiteDataType = WebKit::toWebsiteDataType(dataType);
+    if (!websiteDataType)
+        return completionHandler(nil);
+
+    auto completionHandlerCopy = makeBlockPtr(completionHandler);
+    _websiteDataStore->originDirectoryForTesting(origin, topOrigin, *websiteDataType, [completionHandlerCopy = WTFMove(completionHandlerCopy)](auto result) {
+        completionHandlerCopy(result);
+    });
+}
+
 @end

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


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h	2022-03-25 07:43:36 UTC (rev 291850)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h	2022-03-25 08:54:16 UTC (rev 291851)
@@ -59,7 +59,6 @@
 @property (nonatomic, setter=_setAllowsTLSFallback:) BOOL _allowsTLSFallback WK_API_AVAILABLE(macos(10.15), ios(13.0));
 @property (nonatomic, readonly) NSURL *_indexedDBDatabaseDirectory WK_API_DEPRECATED_WITH_REPLACEMENT("_WKWebsiteDataStoreConfiguration._indexedDBDatabaseDirectory", macos(10.11, 11.0), ios(9.0, 14.0));
 
-
 - (void)_setResourceLoadStatisticsTestingCallback:(nullable void (^)(WKWebsiteDataStore *, NSString *))callback WK_API_AVAILABLE(macos(10.13), ios(11.0));
 - (void)_getAllStorageAccessEntriesFor:(WKWebView *)webView completionHandler:(void (^)(NSArray<NSString *> *domains))completionHandler WK_API_AVAILABLE(macos(10.14), ios(12.0));
 - (void)_loadedSubresourceDomainsFor:(WKWebView *)webView completionHandler:(void (^)(NSArray<NSString *> *domains))completionHandler WK_API_AVAILABLE(macos(12.0), ios(15.0));
@@ -116,6 +115,7 @@
 -(void)_deletePushAndNotificationRegistration:(WKSecurityOrigin *)securityOrigin completionHandler:(void(^)(NSError *))completionHandler WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
 -(void)_getOriginsWithPushAndNotificationPermissions:(void(^)(NSSet<WKSecurityOrigin *> *))completionHandler WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
 -(void)_scopeURL:(NSURL *)scopeURL hasPushSubscriptionForTesting:(void(^)(BOOL))completionHandler WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
+-(void)_originDirectoryForTesting:(NSURL *)origin topOrigin:(NSURL *)topOrigin type:(NSString *)dataType completionHandler:(void(^)(NSString *))completionHandler WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
 @end
 
 NS_ASSUME_NONNULL_END

Modified: trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp (291850 => 291851)


--- trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp	2022-03-25 07:43:36 UTC (rev 291850)
+++ trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp	2022-03-25 08:54:16 UTC (rev 291851)
@@ -427,6 +427,11 @@
     sendWithAsyncReply(Messages::NetworkProcess::RenameOriginInWebsiteData(sessionID, oldName, newName, dataTypes), WTFMove(completionHandler));
 }
 
+void NetworkProcessProxy::websiteDataOriginDirectoryForTesting(PAL::SessionID sessionID, URL&& origin, URL&& topOrigin, WebsiteDataType type, CompletionHandler<void(const String&)>&& completionHandler)
+{
+    sendWithAsyncReply(Messages::NetworkProcess::WebsiteDataOriginDirectoryForTesting(sessionID, WTFMove(origin), WTFMove(topOrigin), type), WTFMove(completionHandler));
+}
+
 void NetworkProcessProxy::networkProcessDidTerminate(TerminationReason reason)
 {
     Ref protectedThis { *this };

Modified: trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.h (291850 => 291851)


--- trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.h	2022-03-25 07:43:36 UTC (rev 291850)
+++ trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.h	2022-03-25 08:54:16 UTC (rev 291851)
@@ -135,6 +135,7 @@
     void deleteWebsiteData(PAL::SessionID, OptionSet<WebsiteDataType>, WallTime modifiedSince, CompletionHandler<void()>&& completionHandler);
     void deleteWebsiteDataForOrigins(PAL::SessionID, OptionSet<WebKit::WebsiteDataType>, const Vector<WebCore::SecurityOriginData>& origins, const Vector<String>& cookieHostNames, const Vector<String>& HSTSCacheHostNames, const Vector<RegistrableDomain>&, CompletionHandler<void()>&&);
     void renameOriginInWebsiteData(PAL::SessionID, const URL&, const URL&, OptionSet<WebsiteDataType>, CompletionHandler<void()>&&);
+    void websiteDataOriginDirectoryForTesting(PAL::SessionID, URL&&, URL&&, WebsiteDataType, CompletionHandler<void(const String&)>&&);
 
     void getLocalStorageDetails(PAL::SessionID, CompletionHandler<void(Vector<LocalStorageDatabaseTracker::OriginDetails>&&)>&&);
 

Modified: trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp (291850 => 291851)


--- trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp	2022-03-25 07:43:36 UTC (rev 291850)
+++ trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp	2022-03-25 08:54:16 UTC (rev 291851)
@@ -1988,6 +1988,11 @@
     networkProcess().renameOriginInWebsiteData(m_sessionID, oldName, newName, dataTypes, WTFMove(completionHandler));
 }
 
+void WebsiteDataStore::originDirectoryForTesting(URL&& origin, URL&& topOrigin, WebsiteDataType type, CompletionHandler<void(const String&)>&& completionHandler)
+{
+    networkProcess().websiteDataOriginDirectoryForTesting(m_sessionID, WTFMove(origin), WTFMove(topOrigin), type, WTFMove(completionHandler));
+}
+
 #if ENABLE(APP_BOUND_DOMAINS)
 void WebsiteDataStore::hasAppBoundSession(CompletionHandler<void(bool)>&& completionHandler) const
 {

Modified: trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.h (291850 => 291851)


--- trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.h	2022-03-25 07:43:36 UTC (rev 291850)
+++ trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.h	2022-03-25 08:54:16 UTC (rev 291851)
@@ -320,6 +320,7 @@
     WebCore::LocalWebLockRegistry& webLockRegistry() { return m_webLockRegistry.get(); }
 
     void renameOriginInWebsiteData(URL&&, URL&&, OptionSet<WebsiteDataType>, CompletionHandler<void()>&&);
+    void originDirectoryForTesting(URL&&, URL&&, WebsiteDataType, CompletionHandler<void(const String&)>&&);
 
     bool networkProcessHasEntitlementForTesting(const String&);
 

Modified: trunk/Tools/ChangeLog (291850 => 291851)


--- trunk/Tools/ChangeLog	2022-03-25 07:43:36 UTC (rev 291850)
+++ trunk/Tools/ChangeLog	2022-03-25 08:54:16 UTC (rev 291851)
@@ -1,3 +1,25 @@
+2022-03-25  Sihui Liu  <[email protected]>
+
+        Introduce an SPI to get website data directory for origin and use it in API tests
+        https://bugs.webkit.org/show_bug.cgi?id=238269
+
+        Reviewed by Alex Christensen.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/IDBCheckpointWAL.mm:
+        (TEST):
+        * TestWebKitAPI/Tests/WebKitCocoa/IDBIndexUpgradeToV2.mm:
+        (runMultipleIndicesTestWithDatabase):
+        * TestWebKitAPI/Tests/WebKitCocoa/IndexedDBFileName.mm:
+        (runTest):
+        (TEST):
+        * TestWebKitAPI/Tests/WebKitCocoa/IndexedDBPersistence.mm:
+        * TestWebKitAPI/Tests/WebKitCocoa/IndexedDBTempFileSize.mm:
+        (TEST):
+        * TestWebKitAPI/Tests/WebKitCocoa/StoreBlobThenDelete.mm:
+        (TEST):
+        * TestWebKitAPI/Tests/WebKitCocoa/WebsiteDataStoreCustomPaths.mm:
+        (runWebsiteDataStoreCustomPaths):
+
 2022-03-24  Chris Dumez  <[email protected]>
 
         FileSystem::pathByAppendingComponent() should take in StringViews instead of Strings

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/IDBCheckpointWAL.mm (291850 => 291851)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/IDBCheckpointWAL.mm	2022-03-25 07:43:36 UTC (rev 291850)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/IDBCheckpointWAL.mm	2022-03-25 08:54:16 UTC (rev 291851)
@@ -25,6 +25,7 @@
 
 #import "config.h"
 
+#import "DeprecatedGlobalValues.h"
 #import "PlatformUtilities.h"
 #import "Test.h"
 #import <WebCore/SQLiteFileSystem.h>
@@ -74,36 +75,40 @@
 
 TEST(IndexedDB, CheckpointsWALAutomatically)
 {
-    NSString *hash = WebCore::SQLiteFileSystem::computeHashForFileName("test-wal-checkpoint");
-    NSString *basePath = [@"~/Library/WebKit/com.apple.WebKit.TestWebKitAPI/WebsiteData/IndexedDB/v1/file__0" stringByExpandingTildeInPath];
-    basePath = [basePath stringByAppendingPathComponent:hash];
-
-    if ([[NSFileManager defaultManager] fileExistsAtPath:basePath]) {
-        BOOL success = [[NSFileManager defaultManager] removeItemAtPath:basePath error:nil];
-        EXPECT_TRUE(success);
-    }
-
-    RetainPtr<IDBCheckpointWALMessageHandler> handler = adoptNS([[IDBCheckpointWALMessageHandler alloc] init]);
-    RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    auto handler = adoptNS([[IDBCheckpointWALMessageHandler alloc] init]);
+    auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
     [[configuration userContentController] addScriptMessageHandler:handler.get() name:@"testHandler"];
+    [configuration.get().websiteDataStore removeDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:^() {
+        done = true;
+    }];
+    TestWebKitAPI::Util::run(&done);
+    done = false;
 
     [configuration.get().websiteDataStore _terminateNetworkProcess];
 
-    RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
-
+    auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
     NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"IDBCheckpointWAL" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
     [webView loadRequest:request];
-
     TestWebKitAPI::Util::run([handler receivedScriptMessagePointer]);
-
     EXPECT_STREQ([[[handler lastScriptMessage] body] UTF8String], "Success");
 
+    NSURL *originURL = [NSURL URLWithString:@"file://"];
+    __block NSString *indexedDBDirectoryString = nil;
+    [configuration.get().websiteDataStore _originDirectoryForTesting:originURL topOrigin:originURL type:WKWebsiteDataTypeIndexedDBDatabases completionHandler:^(NSString *result) {
+        indexedDBDirectoryString = result;
+        done = true;
+    }];
+    TestWebKitAPI::Util::run(&done);
+    NSURL *indexedDBDirectory = [NSURL fileURLWithPath:indexedDBDirectoryString isDirectory:YES];
+    NSString *databaseHash = WebCore::SQLiteFileSystem::computeHashForFileName("test-wal-checkpoint");
+    NSURL *indexedDBDatabaseDirectory = [indexedDBDirectory URLByAppendingPathComponent:databaseHash];
+    NSURL *indexedDBDatabaseFile = [indexedDBDatabaseDirectory URLByAppendingPathComponent:@"IndexedDB.sqlite3"];
+    NSURL *indexedDBDatabaseWAL = [indexedDBDatabaseDirectory URLByAppendingPathComponent:@"IndexedDB.sqlite3-wal"];
+
     // We inserted a single 5 MB row, which is greater than the WAL auto-checkpoint
     // threshold of 4MB, so the WAL should be of minimal size now.
-    NSString *walPath = [basePath stringByAppendingPathComponent:@"IndexedDB.sqlite3-wal"];
-    EXPECT_LT(fileSizeAtPath(walPath), 128 * 1024);
+    EXPECT_LT(fileSizeAtPath(indexedDBDatabaseWAL.path), 128 * 1024);
 
     // Since the single 5 MB row was checkpointed to the main DB file, it should be at least that large.
-    NSString *dbPath = [basePath stringByAppendingPathComponent:@"IndexedDB.sqlite3"];
-    EXPECT_GT(fileSizeAtPath(dbPath), 5 * 1024 * 1024);
+    EXPECT_GT(fileSizeAtPath(indexedDBDatabaseFile.path), 5 * 1024 * 1024);
 }

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/IDBIndexUpgradeToV2.mm (291850 => 291851)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/IDBIndexUpgradeToV2.mm	2022-03-25 07:43:36 UTC (rev 291850)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/IDBIndexUpgradeToV2.mm	2022-03-25 08:54:16 UTC (rev 291851)
@@ -85,28 +85,28 @@
 
 static void runMultipleIndicesTestWithDatabase(NSString* databaseName)
 {
-    RetainPtr<IDBIndexUpgradeToV2MessageHandler> handler = adoptNS([[IDBIndexUpgradeToV2MessageHandler alloc] init]);
-    RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    auto handler = adoptNS([[IDBIndexUpgradeToV2MessageHandler alloc] init]);
+    auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
     [[configuration userContentController] addScriptMessageHandler:handler.get() name:@"testHandler"];
-
     [configuration.get().websiteDataStore _terminateNetworkProcess];
 
     NSURL *url = "" mainBundle] URLForResource:databaseName withExtension:@"sqlite3" subdirectory:@"TestWebKitAPI.resources"];
-
     NSString *hash = WebCore::SQLiteFileSystem::computeHashForFileName("index-upgrade-test");
-    NSString *originDirectory = @"~/Library/WebKit/com.apple.WebKit.TestWebKitAPI/WebsiteData/IndexedDB/v1/file__0/";
-    NSString *databaseDirectory = [[originDirectory stringByAppendingString:hash] stringByExpandingTildeInPath];
-    NSURL *targetURL = [NSURL fileURLWithPath:databaseDirectory];
-    [[NSFileManager defaultManager] removeItemAtURL:targetURL error:nil];
-    [[NSFileManager defaultManager] createDirectoryAtURL:targetURL withIntermediateDirectories:YES attributes:nil error:nil];
+    NSURL *originURL = [NSURL URLWithString:@"file://"];
+    __block NSString *originDirectoryString = nil;
+    [configuration.get().websiteDataStore _originDirectoryForTesting:originURL topOrigin:originURL type:WKWebsiteDataTypeIndexedDBDatabases completionHandler:^(NSString *result) {
+        originDirectoryString = result;
+        done = true;
+    }];
+    TestWebKitAPI::Util::run(&done);
+    NSURL *databaseDirectory = [[NSURL fileURLWithPath:originDirectoryString isDirectory:YES] URLByAppendingPathComponent:hash];
+    [[NSFileManager defaultManager] removeItemAtURL:databaseDirectory error:nil];
+    [[NSFileManager defaultManager] createDirectoryAtURL:databaseDirectory withIntermediateDirectories:YES attributes:nil error:nil];
+    [[NSFileManager defaultManager] copyItemAtURL:url toURL:[databaseDirectory URLByAppendingPathComponent:@"IndexedDB.sqlite3"] error:nil];
 
-    [[NSFileManager defaultManager] copyItemAtURL:url toURL:[targetURL URLByAppendingPathComponent:@"IndexedDB.sqlite3"] error:nil];
-
-    RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
-
+    auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
     NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"IDBIndexUpgradeToV2WithMultipleIndices" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
     [webView loadRequest:request];
-
     TestWebKitAPI::Util::run(&receivedScriptMessage);
 
     EXPECT_WK_STREQ(@"Get object: {\"name\":\"apple\",\"color\":\"red\"}", [lastScriptMessage body]);

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/IndexedDBFileName.mm (291850 => 291851)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/IndexedDBFileName.mm	2022-03-25 07:43:36 UTC (rev 291850)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/IndexedDBFileName.mm	2022-03-25 08:54:16 UTC (rev 291851)
@@ -31,6 +31,7 @@
 #import <WebCore/SQLiteFileSystem.h>
 #import <WebKit/WKWebsiteDataStorePrivate.h>
 #import <WebKit/WebKit.h>
+#import <WebKit/_WKWebsiteDataStoreConfiguration.h>
 #import <wtf/RetainPtr.h>
 
 @interface IndexedDBFileNameMessageHandler : NSObject <WKScriptMessageHandler>
@@ -50,6 +51,12 @@
 {
     auto handler = adoptNS([[IndexedDBFileNameMessageHandler alloc] init]);
     auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    // We need to create custom WebsiteDataStore that uses custom IndexedDB paths to test old migration code.
+    auto websiteDataStoreConfiguration = adoptNS([[_WKWebsiteDataStoreConfiguration alloc] init]);
+    websiteDataStoreConfiguration.get().shouldUseCustomStoragePaths = true;
+    // Custom WebsiteDataStore must have a different general storage directory than default WebsiteDataStore.
+    websiteDataStoreConfiguration.get().generalStorageDirectory = [NSURL fileURLWithPath:[@"~/Library/WebKit/com.apple.WebKit.TestWebKitAPI/CustomWebsiteData/Default" stringByExpandingTildeInPath] isDirectory:YES];
+    [configuration setWebsiteDataStore:adoptNS([[WKWebsiteDataStore alloc] _initWithConfiguration:websiteDataStoreConfiguration.get()]).get()];
     [[configuration userContentController] addScriptMessageHandler:handler.get() name:@"testHandler"];
     auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
     
@@ -79,7 +86,7 @@
     NSString *existingDatbaseHash = WebCore::SQLiteFileSystem::computeHashForFileName(existingDatabaseName);
     NSString *createdDatabaseHash = WebCore::SQLiteFileSystem::computeHashForFileName(createdDatabaseName);
     NSString *unusedDatabaseHash = WebCore::SQLiteFileSystem::computeHashForFileName(createdDatabaseName);
-    NSURL *idbRootURL = [[WKWebsiteDataStore defaultDataStore] _indexedDBDatabaseDirectory];
+    NSURL *idbRootURL = [websiteDataStoreConfiguration.get() _indexedDBDatabaseDirectory];
     NSURL *oldVersionDirectoryURL = [idbRootURL URLByAppendingPathComponent:@"v0"];
     NSURL *newVersionDirectoryURL = [idbRootURL URLByAppendingPathComponent:@"v1"];
     NSURL *oldVersionOriginDirectoryURL = [oldVersionDirectoryURL URLByAppendingPathComponent: @"file__0"];
@@ -173,8 +180,13 @@
 {
     createDirectories("API");
     
-    RetainPtr<NSSet> types = adoptNS([[NSSet alloc] initWithObjects:WKWebsiteDataTypeIndexedDBDatabases, nil]);
-    [[WKWebsiteDataStore defaultDataStore] fetchDataRecordsOfTypes:types.get() completionHandler:^(NSArray<WKWebsiteDataRecord *> * records) {
+    auto types = adoptNS([[NSSet alloc] initWithObjects:WKWebsiteDataTypeIndexedDBDatabases, nil]);
+    auto websiteDataStoreConfiguration = adoptNS([[_WKWebsiteDataStoreConfiguration alloc] init]);
+    websiteDataStoreConfiguration.get().shouldUseCustomStoragePaths = true;
+    websiteDataStoreConfiguration.get().generalStorageDirectory = [NSURL fileURLWithPath:[@"~/Library/WebKit/com.apple.WebKit.TestWebKitAPI/CustomWebsiteData/Default" stringByExpandingTildeInPath] isDirectory:YES];
+    auto dataStore = adoptNS([[WKWebsiteDataStore alloc] _initWithConfiguration:websiteDataStoreConfiguration.get()]);
+
+    [dataStore fetchDataRecordsOfTypes:types.get() completionHandler:^(NSArray<WKWebsiteDataRecord *> * records) {
         EXPECT_EQ(3U, [records count]);
         readyToContinue = true;
     }];
@@ -181,7 +193,7 @@
     readyToContinue = false;
     TestWebKitAPI::Util::run(&readyToContinue);
 
-    [[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:[NSSet setWithObjects:WKWebsiteDataTypeIndexedDBDatabases, nil] modifiedSince:[NSDate distantPast] completionHandler:^() {
+    [dataStore removeDataOfTypes:[NSSet setWithObjects:WKWebsiteDataTypeIndexedDBDatabases, nil] modifiedSince:[NSDate distantPast] completionHandler:^() {
         readyToContinue = true;
     }];
     readyToContinue = false;

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/IndexedDBPersistence.mm (291850 => 291851)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/IndexedDBPersistence.mm	2022-03-25 07:43:36 UTC (rev 291850)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/IndexedDBPersistence.mm	2022-03-25 08:54:16 UTC (rev 291851)
@@ -326,25 +326,33 @@
 
 TEST(IndexedDB, IndexedDBThirdPartyStorageLayout)
 {
-    NSURL *resourceSalt = [[NSBundle mainBundle] URLForResource:@"general-storage-directory" withExtension:@"salt" subdirectory:@"TestWebKitAPI.resources"];
-    NSURL *generalStorageDirectory = [NSURL fileURLWithPath:[@"~/Library/WebKit/com.apple.WebKit.TestWebKitAPI/CustomWebsiteData/Default" stringByExpandingTildeInPath] isDirectory:YES];
-    NSURL *webkitOriginFile = [generalStorageDirectory URLByAppendingPathComponent:@"EAO66s8JvCWNn4D3YQut5pXfiGF_UXNZGvMGN6aKILg/EAO66s8JvCWNn4D3YQut5pXfiGF_UXNZGvMGN6aKILg/origin"];
-    NSURL *webkitIframeOriginFile = [generalStorageDirectory URLByAppendingPathComponent:@"EAO66s8JvCWNn4D3YQut5pXfiGF_UXNZGvMGN6aKILg/vudvbMlKXj1m6RibnVvc8PdAdcXZsNE6ON_Al7yqOsg/origin"];
-    NSURL *iframeWebKitOriginFile = [generalStorageDirectory URLByAppendingPathComponent:@"vudvbMlKXj1m6RibnVvc8PdAdcXZsNE6ON_Al7yqOsg/EAO66s8JvCWNn4D3YQut5pXfiGF_UXNZGvMGN6aKILg/origin"];
-    NSURL *idbDirectory = [NSURL fileURLWithPath:[@"~/Library/WebKit/com.apple.WebKit.TestWebKitAPI/CustomWebsiteData/IndexedDB" stringByExpandingTildeInPath] isDirectory:YES];
-    NSString *hashedDatabaseName = WebCore::SQLiteFileSystem::computeHashForFileName("IndexedDBThirdPartyFrameHasAccess");
-    NSURL *webkitIframeDatabaseFile = [NSURL fileURLWithPath:[NSString pathWithComponents:@[idbDirectory.path, @"v1/http_webkit.org_0/iframe__0/", hashedDatabaseName, @"IndexedDB.sqlite3"]]];
+    auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    NSString *databaseHash = WebCore::SQLiteFileSystem::computeHashForFileName("IndexedDBThirdPartyFrameHasAccess");
+    NSURL *webkitURL = [NSURL URLWithString:@"http://webkit.org"];
+    NSURL *iframeURL = [NSURL URLWithString:@"iframe://"];
+    __block NSString *directoryString = nil;
+    done = false;
+    [configuration.get().websiteDataStore _originDirectoryForTesting:iframeURL topOrigin:webkitURL type:WKWebsiteDataTypeIndexedDBDatabases completionHandler:^(NSString *result) {
+        directoryString = result;
+        done = true;
+    }];
+    TestWebKitAPI::Util::run(&done);
+    NSURL *webkitIframeRootDirectory = [NSURL fileURLWithPath:directoryString isDirectory:YES];
+    NSURL *webkitIframeDatabaseDirectory = [webkitIframeRootDirectory URLByAppendingPathComponent:databaseHash];
+    NSURL *webkitIframeDatabaseFile = [webkitIframeDatabaseDirectory URLByAppendingPathComponent:@"IndexedDB.sqlite3"];
+
+    done = false;
+    [configuration.get().websiteDataStore _originDirectoryForTesting:webkitURL topOrigin:iframeURL type:WKWebsiteDataTypeIndexedDBDatabases completionHandler:^(NSString *result) {
+        directoryString = result;
+        done = true;
+    }];
+    TestWebKitAPI::Util::run(&done);
+    NSURL *iframeWebKitRootDirectory = [NSURL fileURLWithPath:directoryString isDirectory:YES];
+
     NSFileManager *fileManager = [NSFileManager defaultManager];
-    [fileManager removeItemAtURL:generalStorageDirectory error:nil];
-    [fileManager createDirectoryAtURL:generalStorageDirectory withIntermediateDirectories:YES attributes:nil error:nil];
-    [fileManager copyItemAtURL:resourceSalt toURL:[generalStorageDirectory URLByAppendingPathComponent:@"salt"] error:nil];
-    [fileManager removeItemAtURL:idbDirectory error:nil];
+    [fileManager removeItemAtURL:webkitIframeRootDirectory error:nil];
+    [fileManager removeItemAtURL:iframeWebKitRootDirectory error:nil];
 
-    auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
-    auto websiteDataStoreConfiguration = adoptNS([[_WKWebsiteDataStoreConfiguration alloc] init]);
-    websiteDataStoreConfiguration.get()._indexedDBDatabaseDirectory = idbDirectory;
-    websiteDataStoreConfiguration.get().generalStorageDirectory = generalStorageDirectory;
-    [configuration setWebsiteDataStore:adoptNS([[WKWebsiteDataStore alloc] _initWithConfiguration:websiteDataStoreConfiguration.get()]).get()];
     auto handler = adoptNS([[IndexedDBMessageHandler alloc] init]);
     [[configuration userContentController] addScriptMessageHandler:handler.get() name:@"testHandler"];
     auto schemeHandler = adoptNS([[TestURLSchemeHandler alloc] init]);
@@ -360,10 +368,9 @@
 
     auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
     loadThirdPartyPageInWebView(webView.get(), @"database is created - put item success");
-    EXPECT_TRUE([fileManager fileExistsAtPath:webkitOriginFile.path]);
-    EXPECT_TRUE([fileManager fileExistsAtPath:webkitIframeOriginFile.path]);
-    EXPECT_FALSE([fileManager fileExistsAtPath:iframeWebKitOriginFile.path]);
+    EXPECT_TRUE([fileManager fileExistsAtPath:webkitIframeRootDirectory.path]);
     EXPECT_TRUE([fileManager fileExistsAtPath:webkitIframeDatabaseFile.path]);
+    EXPECT_FALSE([fileManager fileExistsAtPath:iframeWebKitRootDirectory.path]);
 }
 
 TEST(IndexedDB, MigrateThirdPartyDataToGeneralStorageDirectory)
@@ -584,11 +591,35 @@
     EXPECT_WK_STREQ(@"main frame databases: []", [getNextMessage() body]);
 
     // Getting databases should not create files on disk.
-    NSURL *idbDirectoryURL = [[WKWebsiteDataStore defaultDataStore] _indexedDBDatabaseDirectory];
-    NSURL *versionDirectoryURL = [idbDirectoryURL URLByAppendingPathComponent:@"v1"];
-    NSURL *appleDirectoryURL = [versionDirectoryURL URLByAppendingPathComponent: @"http_apple.com_0"];
-    NSURL *appleWebkitDirectoryURL = [appleDirectoryURL URLByAppendingPathComponent: @"webkit__0"];
-    NSURL *webkitDirectoryURL = [versionDirectoryURL URLByAppendingPathComponent: @"webkit__0"];
+    NSURL *appleURL = [NSURL URLWithString:@"http://apple.com"];
+    NSURL *webkitURL = [NSURL URLWithString:@"webkit://"];
+    __block NSString *appleDirectoryString = nil;
+    readyToContinue = false;
+    [[WKWebsiteDataStore defaultDataStore] _originDirectoryForTesting:appleURL topOrigin:appleURL type:WKWebsiteDataTypeIndexedDBDatabases completionHandler:^(NSString *result) {
+        appleDirectoryString = result;
+        readyToContinue = true;
+    }];
+    TestWebKitAPI::Util::run(&readyToContinue);
+    NSURL *appleDirectoryURL = [NSURL fileURLWithPath:appleDirectoryString isDirectory:YES];
+
+    readyToContinue = false;
+    __block NSString *webkitDirectoryString = nil;
+    [[WKWebsiteDataStore defaultDataStore] _originDirectoryForTesting:webkitURL topOrigin:webkitURL type:WKWebsiteDataTypeIndexedDBDatabases completionHandler:^(NSString *result) {
+        webkitDirectoryString = result;
+        readyToContinue = true;
+    }];
+    TestWebKitAPI::Util::run(&readyToContinue);
+    NSURL *webkitDirectoryURL = [NSURL fileURLWithPath:webkitDirectoryString isDirectory:YES];
+
+    __block NSString *appleWebkitDirectoryString = nil;
+    readyToContinue = false;
+    [[WKWebsiteDataStore defaultDataStore] _originDirectoryForTesting:webkitURL topOrigin:appleURL type:WKWebsiteDataTypeIndexedDBDatabases completionHandler:^(NSString *result) {
+        appleWebkitDirectoryString = result;
+        readyToContinue = true;
+    }];
+    TestWebKitAPI::Util::run(&readyToContinue);
+    NSURL *appleWebkitDirectoryURL = [NSURL fileURLWithPath:appleWebkitDirectoryString isDirectory:YES];
+
     auto defaultFileManager = [NSFileManager defaultManager];
     EXPECT_TRUE([defaultFileManager fileExistsAtPath:appleDirectoryURL.path]);
     EXPECT_FALSE([defaultFileManager fileExistsAtPath:appleWebkitDirectoryURL.path]);

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/IndexedDBTempFileSize.mm (291850 => 291851)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/IndexedDBTempFileSize.mm	2022-03-25 07:43:36 UTC (rev 291850)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/IndexedDBTempFileSize.mm	2022-03-25 08:54:16 UTC (rev 291851)
@@ -59,18 +59,20 @@
     auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
     [[configuration userContentController] addScriptMessageHandler:handler.get() name:@"testHandler"];
 
+    NSURL *originURL = [NSURL URLWithString:@"file://"];
+    __block NSString *databaseRootDirectoryString = nil;
+    readyToContinue = false;
+    [configuration.get().websiteDataStore _originDirectoryForTesting:originURL topOrigin:originURL type:WKWebsiteDataTypeIndexedDBDatabases completionHandler:^(NSString *result) {
+        databaseRootDirectoryString = result;
+        readyToContinue = true;
+    }];
+    TestWebKitAPI::Util::run(&readyToContinue);
+    NSURL *databaseRootDirectory = [NSURL fileURLWithPath:databaseRootDirectoryString isDirectory:YES];
     NSString *hash = WebCore::SQLiteFileSystem::computeHashForFileName("IndexedDBTempFileSize");
-    NSString *databaseRootDirectory = [@"~/Library/WebKit/com.apple.WebKit.TestWebKitAPI/CustomWebsiteData/IndexedDB/" stringByExpandingTildeInPath];
-    NSString *databaseDirectory = [[[databaseRootDirectory stringByAppendingPathComponent:@"v1"] stringByAppendingPathComponent:@"file__0"] stringByAppendingPathComponent:hash];
-    RetainPtr<NSURL> idbPath = [NSURL fileURLWithPath:databaseRootDirectory isDirectory:YES];
-    RetainPtr<NSURL> walFilePath = [NSURL fileURLWithPath:[databaseDirectory stringByAppendingPathComponent:@"IndexedDB.sqlite3-wal"] isDirectory:NO];
+    NSURL *databaseDirectory = [databaseRootDirectory URLByAppendingPathComponent:hash];
+    NSURL *walFilePath = [databaseDirectory URLByAppendingPathComponent:@"IndexedDB.sqlite3-wal"];
 
-    auto websiteDataStoreConfiguration = adoptNS([[_WKWebsiteDataStoreConfiguration alloc] init]);
-    websiteDataStoreConfiguration.get()._indexedDBDatabaseDirectory = idbPath.get();
-
-    configuration.get().websiteDataStore = adoptNS([[WKWebsiteDataStore alloc] _initWithConfiguration:websiteDataStoreConfiguration.get()]).get();
     auto types = adoptNS([[NSSet alloc] initWithObjects:WKWebsiteDataTypeIndexedDBDatabases, nil]);
-
     [configuration.get().websiteDataStore removeDataOfTypes:types.get() modifiedSince:[NSDate distantPast] completionHandler:^() {
         readyToContinue = true;
     }];
@@ -94,8 +96,8 @@
     webView = nil;
     [configuration.get().websiteDataStore _terminateNetworkProcess];
 
-    EXPECT_TRUE([[NSFileManager defaultManager] fileExistsAtPath:walFilePath.get().path]);
-    RetainPtr<NSDictionary> fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:walFilePath.get().path error:nil];
+    EXPECT_TRUE([[NSFileManager defaultManager] fileExistsAtPath:walFilePath.path]);
+    auto fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:walFilePath.path error:nil];
     NSNumber *fileSizeBefore = [fileAttributes objectForKey:NSFileSize];
 
     // Open the same database again.
@@ -107,7 +109,7 @@
     TestWebKitAPI::Util::run(&receivedScriptMessage);
     RetainPtr<NSString> string3 = (NSString *)[lastScriptMessage body];
 
-    fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:walFilePath.get().path error:nil];
+    fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:walFilePath.path error:nil];
     NSNumber *fileSizeAfter = [fileAttributes objectForKey:NSFileSize];
     EXPECT_GT([fileSizeBefore longLongValue], [fileSizeAfter longLongValue]);
 

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/StoreBlobThenDelete.mm (291850 => 291851)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/StoreBlobThenDelete.mm	2022-03-25 07:43:36 UTC (rev 291850)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/StoreBlobThenDelete.mm	2022-03-25 08:54:16 UTC (rev 291851)
@@ -52,12 +52,10 @@
 
 TEST(IndexedDB, StoreBlobThenRemoveData)
 {
-    RetainPtr<StoreBlobMessageHandler> handler = adoptNS([[StoreBlobMessageHandler alloc] init]);
-    RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    auto handler = adoptNS([[StoreBlobMessageHandler alloc] init]);
+    auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
     [[configuration userContentController] addScriptMessageHandler:handler.get() name:@"testHandler"];
-
-    RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
-
+    auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
     NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"StoreBlobToBeDeleted" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
     [webView loadRequest:request];
 
@@ -65,14 +63,22 @@
     EXPECT_WK_STREQ(@"Success", (NSString *)[lastScriptMessage body]);
 
     NSString *hash = WebCore::SQLiteFileSystem::computeHashForFileName("StoreBlobToBeDeleted");
-    NSString *originDirectory = @"~/Library/WebKit/com.apple.WebKit.TestWebKitAPI/WebsiteData/IndexedDB/v1/file__0/";
-    NSString *databaseDirectory = [[originDirectory stringByAppendingString:hash] stringByExpandingTildeInPath];
-    NSString *blobFilePath = [databaseDirectory stringByAppendingPathComponent:@"1.blob"];
-    NSString *databaseFilePath = [databaseDirectory stringByAppendingPathComponent:@"IndexedDB.sqlite3"];
+    NSURL *originURL = [NSURL URLWithString:@"file://"];
+    __block NSString *originDirectoryString = nil;
+    readyToContinue = false;
+    [configuration.get().websiteDataStore _originDirectoryForTesting:originURL topOrigin:originURL type:WKWebsiteDataTypeIndexedDBDatabases completionHandler:^(NSString *result) {
+        originDirectoryString = result;
+        readyToContinue = true;
+    }];
+    TestWebKitAPI::Util::run(&readyToContinue);
+    NSURL *originDirectory = [NSURL fileURLWithPath:originDirectoryString isDirectory:YES];
+    NSURL *databaseDirectory = [originDirectory URLByAppendingPathComponent:hash];
+    NSURL *blobFileURL = [databaseDirectory URLByAppendingPathComponent:@"1.blob"];
+    NSURL *databaseFileURL = [databaseDirectory URLByAppendingPathComponent:@"IndexedDB.sqlite3"];
 
     // The database file and blob file should definitely be there right now.
-    EXPECT_TRUE([[NSFileManager defaultManager] fileExistsAtPath:blobFilePath]);
-    EXPECT_TRUE([[NSFileManager defaultManager] fileExistsAtPath:databaseFilePath]);
+    EXPECT_TRUE([[NSFileManager defaultManager] fileExistsAtPath:blobFileURL.path]);
+    EXPECT_TRUE([[NSFileManager defaultManager] fileExistsAtPath:databaseFileURL.path]);
 
     // To make sure that the -wal and -shm files for a database are deleted even if the sqlite3 file is already missing,
     // we need to:
@@ -80,44 +86,44 @@
     // 2 - Move -wal and -shm files into that directory
     // 3 - Make sure the entire directory is deleted
     NSString *fakeHash = WebCore::SQLiteFileSystem::computeHashForFileName("FakeDatabasePath");
-    NSString *fakeDatabaseDirectory = [[originDirectory stringByAppendingString:fakeHash] stringByExpandingTildeInPath];
-    NSString *fakeShmPath = [fakeDatabaseDirectory stringByAppendingPathComponent:@"IndexedDB.sqlite3-wal"];
-    NSString *fakeWalPath = [fakeDatabaseDirectory stringByAppendingPathComponent:@"IndexedDB.sqlite3-shm"];
-    [[NSFileManager defaultManager] createDirectoryAtPath:fakeDatabaseDirectory withIntermediateDirectories:NO attributes:nil error:nil];
-    [[NSFileManager defaultManager] copyItemAtPath:databaseFilePath toPath:fakeShmPath error:nil];
-    [[NSFileManager defaultManager] copyItemAtPath:databaseFilePath toPath:fakeWalPath error:nil];
+    NSURL *fakeDatabaseDirectory = [originDirectory URLByAppendingPathComponent:fakeHash];
+    NSURL *fakeShmURL = [fakeDatabaseDirectory URLByAppendingPathComponent:@"IndexedDB.sqlite3-wal"];
+    NSURL *fakeWalURL = [fakeDatabaseDirectory URLByAppendingPathComponent:@"IndexedDB.sqlite3-shm"];
+    [[NSFileManager defaultManager] createDirectoryAtURL:fakeDatabaseDirectory withIntermediateDirectories:YES attributes:nil error:nil];
+    [[NSFileManager defaultManager] copyItemAtURL:blobFileURL toURL:fakeShmURL error:nil];
+    [[NSFileManager defaultManager] copyItemAtURL:databaseFileURL toURL:fakeWalURL error:nil];
 
     // Make some other .blob files in the database directory to later validate all blob files in the directory are deleted.
-    NSString *otherBlob1 = [databaseDirectory stringByAppendingPathComponent:@"7182.blob"];
-    NSString *otherBlob2 = [databaseDirectory stringByAppendingPathComponent:@"1a.blob"];
-    NSString *otherBlob3 = [databaseDirectory stringByAppendingPathComponent:@"a1.blob"];
-    NSString *otherBlob4 = [databaseDirectory stringByAppendingPathComponent:@".blob"];
-    [[NSFileManager defaultManager] copyItemAtPath:blobFilePath toPath:otherBlob1 error:nil];
-    [[NSFileManager defaultManager] copyItemAtPath:blobFilePath toPath:otherBlob2 error:nil];
-    [[NSFileManager defaultManager] copyItemAtPath:blobFilePath toPath:otherBlob3 error:nil];
-    [[NSFileManager defaultManager] copyItemAtPath:blobFilePath toPath:otherBlob4 error:nil];
+    NSURL *otherBlob1 = [databaseDirectory URLByAppendingPathComponent:@"7182.blob"];
+    NSURL *otherBlob2 = [databaseDirectory URLByAppendingPathComponent:@"1a.blob"];
+    NSURL *otherBlob3 = [databaseDirectory URLByAppendingPathComponent:@"a1.blob"];
+    NSURL *otherBlob4 = [databaseDirectory URLByAppendingPathComponent:@".blob"];
+    [[NSFileManager defaultManager] copyItemAtURL:blobFileURL toURL:otherBlob1 error:nil];
+    [[NSFileManager defaultManager] copyItemAtURL:blobFileURL toURL:otherBlob2 error:nil];
+    [[NSFileManager defaultManager] copyItemAtURL:blobFileURL toURL:otherBlob3 error:nil];
+    [[NSFileManager defaultManager] copyItemAtURL:blobFileURL toURL:otherBlob4 error:nil];
 
     readyToContinue = false;
     [[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:^() {
-        EXPECT_FALSE([[NSFileManager defaultManager] fileExistsAtPath:blobFilePath]);
-        EXPECT_FALSE([[NSFileManager defaultManager] fileExistsAtPath:databaseFilePath]);
+        EXPECT_FALSE([[NSFileManager defaultManager] fileExistsAtPath:blobFileURL.path]);
+        EXPECT_FALSE([[NSFileManager defaultManager] fileExistsAtPath:databaseFileURL.path]);
 
         // Make sure all fake blob file are gone.
-        EXPECT_FALSE([[NSFileManager defaultManager] fileExistsAtPath:otherBlob1]);
+        EXPECT_FALSE([[NSFileManager defaultManager] fileExistsAtPath:otherBlob1.path]);
 
-        EXPECT_FALSE([[NSFileManager defaultManager] fileExistsAtPath:otherBlob2]);
-        EXPECT_FALSE([[NSFileManager defaultManager] fileExistsAtPath:otherBlob3]);
-        EXPECT_FALSE([[NSFileManager defaultManager] fileExistsAtPath:otherBlob4]);
+        EXPECT_FALSE([[NSFileManager defaultManager] fileExistsAtPath:otherBlob2.path]);
+        EXPECT_FALSE([[NSFileManager defaultManager] fileExistsAtPath:otherBlob3.path]);
+        EXPECT_FALSE([[NSFileManager defaultManager] fileExistsAtPath:otherBlob4.path]);
 
         // Make sure everything related to the fake database is gone.
-        EXPECT_FALSE([[NSFileManager defaultManager] fileExistsAtPath:fakeShmPath]);
-        EXPECT_FALSE([[NSFileManager defaultManager] fileExistsAtPath:fakeWalPath]);
-        EXPECT_FALSE([[NSFileManager defaultManager] fileExistsAtPath:fakeDatabaseDirectory]);
+        EXPECT_FALSE([[NSFileManager defaultManager] fileExistsAtPath:fakeShmURL.path]);
+        EXPECT_FALSE([[NSFileManager defaultManager] fileExistsAtPath:fakeWalURL.path]);
+        EXPECT_FALSE([[NSFileManager defaultManager] fileExistsAtPath:fakeDatabaseDirectory.path]);
 
         // Now delete them so we're not leaving files around.
-        [[NSFileManager defaultManager] removeItemAtPath:otherBlob2 error:nil];
-        [[NSFileManager defaultManager] removeItemAtPath:otherBlob3 error:nil];
-        [[NSFileManager defaultManager] removeItemAtPath:otherBlob4 error:nil];
+        [[NSFileManager defaultManager] removeItemAtURL:otherBlob2 error:nil];
+        [[NSFileManager defaultManager] removeItemAtURL:otherBlob3 error:nil];
+        [[NSFileManager defaultManager] removeItemAtURL:otherBlob4 error:nil];
 
         readyToContinue = true;
     }];
@@ -136,17 +142,25 @@
     EXPECT_WK_STREQ(@"Success", (NSString *)[lastScriptMessage body]);
 
     NSString *hash = WebCore::SQLiteFileSystem::computeHashForFileName("StoreBlobToBeDeleted");
-    NSString *originDirectory = @"~/Library/WebKit/com.apple.WebKit.TestWebKitAPI/WebsiteData/IndexedDB/v1/file__0/";
-    NSString *databaseDirectory = [[originDirectory stringByAppendingString:hash] stringByExpandingTildeInPath];
-    NSString *blobFilePath = [databaseDirectory stringByAppendingPathComponent:@"1.blob"];
-    NSString *databaseFilePath = [databaseDirectory stringByAppendingPathComponent:@"IndexedDB.sqlite3"];
+    NSURL *originURL = [NSURL URLWithString:@"file://"];
+    __block NSString *originDirectoryString = nil;
+    readyToContinue = false;
+    [configuration.get().websiteDataStore _originDirectoryForTesting:originURL topOrigin:originURL type:WKWebsiteDataTypeIndexedDBDatabases completionHandler:^(NSString *result) {
+        originDirectoryString = result;
+        readyToContinue = true;
+    }];
+    TestWebKitAPI::Util::run(&readyToContinue);
+    NSURL *originDirectory = [NSURL fileURLWithPath:originDirectoryString isDirectory:YES];
+    NSURL *databaseDirectory = [originDirectory URLByAppendingPathComponent:hash];
+    NSURL *blobFileURL = [databaseDirectory URLByAppendingPathComponent:@"1.blob"];
+    NSURL *databaseFileURL = [databaseDirectory URLByAppendingPathComponent:@"IndexedDB.sqlite3"];
 
-    EXPECT_TRUE([[NSFileManager defaultManager] fileExistsAtPath:blobFilePath]);
-    EXPECT_TRUE([[NSFileManager defaultManager] fileExistsAtPath:databaseFilePath]);
+    EXPECT_TRUE([[NSFileManager defaultManager] fileExistsAtPath:blobFileURL.path]);
+    EXPECT_TRUE([[NSFileManager defaultManager] fileExistsAtPath:databaseFileURL.path]);
 
     // Add a .blob file that is not created by IndexedDB API.
-    NSString *anotherBlobFilePath = [databaseDirectory stringByAppendingPathComponent:@"7182.blob"];
-    [[NSFileManager defaultManager] copyItemAtPath:blobFilePath toPath:anotherBlobFilePath error:nil];
+    NSURL *anotherBlobFileURL = [databaseDirectory URLByAppendingPathComponent:@"7182.blob"];
+    [[NSFileManager defaultManager] copyItemAtPath:blobFileURL.path toPath:anotherBlobFileURL.path error:nil];
 
     readyToContinue = false;
     [webView evaluateJavaScript:@"deleteDatabase(() => { sendMessage('Delete success'); })" completionHandler:nil];
@@ -153,7 +167,7 @@
     TestWebKitAPI::Util::run(&readyToContinue);
     EXPECT_WK_STREQ(@"Delete success", (NSString *)[lastScriptMessage body]);
 
-    EXPECT_FALSE([[NSFileManager defaultManager] fileExistsAtPath:blobFilePath]);
-    EXPECT_FALSE([[NSFileManager defaultManager] fileExistsAtPath:databaseFilePath]);
-    EXPECT_TRUE([[NSFileManager defaultManager] fileExistsAtPath:anotherBlobFilePath]);
+    EXPECT_FALSE([[NSFileManager defaultManager] fileExistsAtPath:blobFileURL.path]);
+    EXPECT_FALSE([[NSFileManager defaultManager] fileExistsAtPath:databaseFileURL.path]);
+    EXPECT_TRUE([[NSFileManager defaultManager] fileExistsAtPath:anotherBlobFileURL.path]);
 }

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WebsiteDataStoreCustomPaths.mm (291850 => 291851)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WebsiteDataStoreCustomPaths.mm	2022-03-25 07:43:36 UTC (rev 291850)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WebsiteDataStoreCustomPaths.mm	2022-03-25 08:54:16 UTC (rev 291851)
@@ -77,8 +77,8 @@
     processPoolConfiguration.get().prewarmsProcessesAutomatically = shouldEnableProcessPrewarming == ShouldEnableProcessPrewarming::Yes ? YES : NO;
     auto processPool = adoptNS([[WKProcessPool alloc] _initWithConfiguration:processPoolConfiguration.get()]);
 
-    RetainPtr<WebsiteDataStoreCustomPathsMessageHandler> handler = adoptNS([[WebsiteDataStoreCustomPathsMessageHandler alloc] init]);
-    RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    auto handler = adoptNS([[WebsiteDataStoreCustomPathsMessageHandler alloc] init]);
+    auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
     [[configuration userContentController] addScriptMessageHandler:handler.get() name:@"testHandler"];
 
     NSURL *sqlPath = [NSURL fileURLWithPath:[@"~/Library/WebKit/com.apple.WebKit.TestWebKitAPI/CustomWebsiteData/WebSQL/" stringByExpandingTildeInPath] isDirectory:YES];
@@ -86,7 +86,6 @@
     NSURL *localStoragePath = [NSURL fileURLWithPath:[@"~/Library/WebKit/com.apple.WebKit.TestWebKitAPI/CustomWebsiteData/LocalStorage/" stringByExpandingTildeInPath] isDirectory:YES];
     NSURL *cookieStorageFile = [NSURL fileURLWithPath:[@"~/Library/WebKit/com.apple.WebKit.TestWebKitAPI/CustomWebsiteData/CookieStorage/Cookie.File" stringByExpandingTildeInPath] isDirectory:NO];
     NSURL *resourceLoadStatisticsPath = [NSURL fileURLWithPath:[@"~/Library/WebKit/com.apple.WebKit.TestWebKitAPI/CustomWebsiteData/ResourceLoadStatistics/" stringByExpandingTildeInPath] isDirectory:YES];
-
     NSURL *defaultSQLPath = [NSURL fileURLWithPath:[@"~/Library/WebKit/com.apple.WebKit.TestWebKitAPI/WebsiteData/WebSQL/" stringByExpandingTildeInPath] isDirectory:YES];
     NSURL *defaultIDBPath = [NSURL fileURLWithPath:[@"~/Library/WebKit/com.apple.WebKit.TestWebKitAPI/WebsiteData/IndexedDB/" stringByExpandingTildeInPath] isDirectory:YES];
     NSURL *defaultLocalStoragePath = [NSURL fileURLWithPath:[@"~/Library/WebKit/com.apple.WebKit.TestWebKitAPI/WebsiteData/LocalStorage/" stringByExpandingTildeInPath] isDirectory:YES];
@@ -112,7 +111,7 @@
     EXPECT_FALSE([[NSFileManager defaultManager] fileExistsAtPath:defaultLocalStoragePath.path]);
     EXPECT_FALSE([[NSFileManager defaultManager] fileExistsAtPath:defaultResourceLoadStatisticsPath.path]);
 
-    RetainPtr<_WKWebsiteDataStoreConfiguration> websiteDataStoreConfiguration = adoptNS([[_WKWebsiteDataStoreConfiguration alloc] init]);
+    auto websiteDataStoreConfiguration = adoptNS([[_WKWebsiteDataStoreConfiguration alloc] init]);
     websiteDataStoreConfiguration.get()._webSQLDatabaseDirectory = sqlPath;
     websiteDataStoreConfiguration.get()._indexedDBDatabaseDirectory = idbPath;
     websiteDataStoreConfiguration.get()._webStorageDirectory = localStoragePath;
@@ -122,7 +121,7 @@
     configuration.get().websiteDataStore = adoptNS([[WKWebsiteDataStore alloc] _initWithConfiguration:websiteDataStoreConfiguration.get()]).get();
     configuration.get().processPool = processPool.get();
 
-    RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
+    auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
     [webView setNavigationDelegate:handler.get()];
 
     auto preferences = (__bridge WKPreferencesRef)[[webView configuration] preferences];
@@ -145,6 +144,17 @@
     }];
     TestWebKitAPI::Util::run(&flushed);
 
+    // Get the IndexedDB database path in use.
+    NSURL *fileURL = [NSURL URLWithString:@"file://"];
+    __block NSString *fileIDBPathString = nil;
+    done = false;
+    [configuration.get().websiteDataStore _originDirectoryForTesting:fileURL topOrigin:fileURL type:WKWebsiteDataTypeIndexedDBDatabases completionHandler:^(NSString *result) {
+        fileIDBPathString = result;
+        done = true;
+    }];
+    TestWebKitAPI::Util::run(&done);
+    NSURL *fileIDBPath = [NSURL fileURLWithPath:fileIDBPathString isDirectory:YES];
+
     // Forcibly shut down everything of WebKit that we can.
     auto pid = [webView _webProcessIdentifier];
     if (pid)
@@ -184,32 +194,46 @@
 
     EXPECT_TRUE([[NSFileManager defaultManager] fileExistsAtPath:idbPath.path]);
     EXPECT_TRUE([[NSFileManager defaultManager] fileExistsAtPath:defaultIDBPath.path]);
-    RetainPtr<NSURL> fileIDBPath = [[idbPath URLByAppendingPathComponent:@"v1"] URLByAppendingPathComponent:@"file__0"];
-    EXPECT_TRUE([[NSFileManager defaultManager] fileExistsAtPath:fileIDBPath.get().path]);
+    EXPECT_TRUE([[NSFileManager defaultManager] fileExistsAtPath:fileIDBPath.path]);
 
     @autoreleasepool {
         auto dataStore = adoptNS([[WKWebsiteDataStore alloc] _initWithConfiguration:websiteDataStoreConfiguration.get()]);
-        RetainPtr<NSSet> types = adoptNS([[NSSet alloc] initWithObjects:WKWebsiteDataTypeIndexedDBDatabases, nil]);
+        auto types = adoptNS([[NSSet alloc] initWithObjects:WKWebsiteDataTypeIndexedDBDatabases, nil]);
+        
+        NSURL *appleURL = [NSURL URLWithString:@"https://apple.com"];
+        __block NSString *idbPathString = nil;
+        done = false;
+        [dataStore _originDirectoryForTesting:appleURL topOrigin:fileURL type:WKWebsiteDataTypeIndexedDBDatabases completionHandler:^(NSString *result) {
+            idbPathString = result;
+            done = true;
+        }];
+        TestWebKitAPI::Util::run(&done);
+        NSURL *fileAppleIDBPath = [NSURL fileURLWithPath:idbPathString isDirectory:YES];
 
+        NSURL *webkitURL = [NSURL URLWithString:@"https://webkit.org"];
+        done = false;
+        [dataStore _originDirectoryForTesting:webkitURL topOrigin:fileURL type:WKWebsiteDataTypeIndexedDBDatabases completionHandler:^(NSString *result) {
+            idbPathString = result;
+            done = true;
+        }];
+        TestWebKitAPI::Util::run(&done);
+        NSURL *fileWebKitIDBPath = [NSURL fileURLWithPath:idbPathString isDirectory:YES];
+
         // Subframe of different origins may also create IndexedDB files.
         RetainPtr<NSURL> url1 = [[NSBundle mainBundle] URLForResource:@"IndexedDB" withExtension:@"sqlite3" subdirectory:@"TestWebKitAPI.resources"];
         RetainPtr<NSURL> url2 = [[NSBundle mainBundle] URLForResource:@"IndexedDB" withExtension:@"sqlite3-shm" subdirectory:@"TestWebKitAPI.resources"];
         RetainPtr<NSURL> url3 = [[NSBundle mainBundle] URLForResource:@"IndexedDB" withExtension:@"sqlite3-wal" subdirectory:@"TestWebKitAPI.resources"];
 
-        RetainPtr<NSURL> frameIDBPath = [[fileIDBPath URLByAppendingPathComponent:@"https_apple.com_0"] URLByAppendingPathComponent:@"WebsiteDataStoreCustomPaths"];
-        [[NSFileManager defaultManager] createDirectoryAtURL:frameIDBPath.get() withIntermediateDirectories:YES attributes:nil error:nil];
+        [[NSFileManager defaultManager] createDirectoryAtURL:fileAppleIDBPath withIntermediateDirectories:YES attributes:nil error:nil];
+        [[NSFileManager defaultManager] copyItemAtURL:url1.get() toURL:[fileAppleIDBPath URLByAppendingPathComponent:@"IndexedDB.sqlite3"] error:nil];
+        [[NSFileManager defaultManager] copyItemAtURL:url2.get() toURL:[fileAppleIDBPath URLByAppendingPathComponent:@"IndexedDB.sqlite3-shm"] error:nil];
+        [[NSFileManager defaultManager] copyItemAtURL:url3.get() toURL:[fileAppleIDBPath URLByAppendingPathComponent:@"IndexedDB.sqlite3-wal"] error:nil];
 
-        [[NSFileManager defaultManager] copyItemAtURL:url1.get() toURL:[frameIDBPath.get() URLByAppendingPathComponent:@"IndexedDB.sqlite3"] error:nil];
-        [[NSFileManager defaultManager] copyItemAtURL:url2.get() toURL:[frameIDBPath.get() URLByAppendingPathComponent:@"IndexedDB.sqlite3-shm"] error:nil];
-        [[NSFileManager defaultManager] copyItemAtURL:url3.get() toURL:[frameIDBPath.get() URLByAppendingPathComponent:@"IndexedDB.sqlite3-wal"] error:nil];
+        [[NSFileManager defaultManager] createDirectoryAtURL:fileWebKitIDBPath withIntermediateDirectories:YES attributes:nil error:nil];
+        [[NSFileManager defaultManager] copyItemAtURL:url1.get() toURL:[fileWebKitIDBPath URLByAppendingPathComponent:@"IndexedDB.sqlite3"] error:nil];
+        [[NSFileManager defaultManager] copyItemAtURL:url2.get() toURL:[fileWebKitIDBPath URLByAppendingPathComponent:@"IndexedDB.sqlite3-shm"] error:nil];
+        [[NSFileManager defaultManager] copyItemAtURL:url3.get() toURL:[fileWebKitIDBPath URLByAppendingPathComponent:@"IndexedDB.sqlite3-wal"] error:nil];
 
-        RetainPtr<NSURL> frameIDBPath2 = [[fileIDBPath URLByAppendingPathComponent:@"https_webkit.org_0"] URLByAppendingPathComponent:@"WebsiteDataStoreCustomPaths"];
-        [[NSFileManager defaultManager] createDirectoryAtURL:frameIDBPath2.get() withIntermediateDirectories:YES attributes:nil error:nil];
-
-        [[NSFileManager defaultManager] copyItemAtURL:url1.get() toURL:[frameIDBPath2.get() URLByAppendingPathComponent:@"IndexedDB.sqlite3"] error:nil];
-        [[NSFileManager defaultManager] copyItemAtURL:url2.get() toURL:[frameIDBPath2.get() URLByAppendingPathComponent:@"IndexedDB.sqlite3-shm"] error:nil];
-        [[NSFileManager defaultManager] copyItemAtURL:url3.get() toURL:[frameIDBPath2.get() URLByAppendingPathComponent:@"IndexedDB.sqlite3-wal"] error:nil];
-
         [dataStore fetchDataRecordsOfTypes:types.get() completionHandler:^(NSArray<WKWebsiteDataRecord *> * records) {
             EXPECT_EQ([records count], (unsigned long)3);
             for (id record in records) {
@@ -216,7 +240,7 @@
                 if ([[record displayName] isEqual: @"apple.com"]) {
                     [dataStore removeDataOfTypes:types.get() forDataRecords:@[record] completionHandler:^() {
                         receivedScriptMessage = true;
-                        EXPECT_FALSE([[NSFileManager defaultManager] fileExistsAtPath:frameIDBPath.get().path]);
+                        EXPECT_FALSE([[NSFileManager defaultManager] fileExistsAtPath:fileAppleIDBPath.path]);
                     }];
                 }
             }
@@ -230,7 +254,7 @@
         receivedScriptMessage = false;
         TestWebKitAPI::Util::run(&receivedScriptMessage);
 
-        EXPECT_FALSE([[NSFileManager defaultManager] fileExistsAtPath:fileIDBPath.get().path]);
+        EXPECT_FALSE([[NSFileManager defaultManager] fileExistsAtPath:fileWebKitIDBPath.path]);
 
         // Now, with brand new WKWebsiteDataStores pointing at the same custom cookie storage location,
         // in newly fired up NetworkProcesses, verify that the fetch and delete APIs work as expected.
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to