Clean up IndexedDB files between tests
authorsihui_liu@apple.com <sihui_liu@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 23 Jan 2019 21:39:19 +0000 (21:39 +0000)
committersihui_liu@apple.com <sihui_liu@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 23 Jan 2019 21:39:19 +0000 (21:39 +0000)
https://bugs.webkit.org/show_bug.cgi?id=192796
<rdar://problem/46824999>

Reviewed by Geoffrey Garen.

Source/WebCore:

We should clean up the IndexedDB files between tests to make sure each IDB test is independent of others.

* Modules/indexeddb/server/UniqueIDBDatabase.cpp:
(WebCore::IDBServer::UniqueIDBDatabase::didDeleteBackingStore):
(WebCore::IDBServer::UniqueIDBDatabase::transactionCompleted):

Source/WebKit:

* UIProcess/API/C/WKWebsiteDataStoreRef.cpp:
(WKWebsiteDataStoreRemoveAllIndexedDatabases):
* UIProcess/API/C/WKWebsiteDataStoreRef.h:

Tools:

* DumpRenderTree/mac/DumpRenderTree.mm:
(runTest):
* WebKitTestRunner/TestController.cpp:
(WTR::TestController::resetStateToConsistentValues):
(WTR::RemoveAllIndexedDatabasesCallbackContext::RemoveAllIndexedDatabasesCallbackContext):
(WTR::RemoveAllIndexedDatabasesCallback):
(WTR::TestController::ClearIndexedDatabases):
* WebKitTestRunner/TestController.h:
* WebKitTestRunner/TestInvocation.cpp:
(WTR::TestInvocation::didReceiveSynchronousMessageFromInjectedBundle):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@240358 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp
Source/WebKit/ChangeLog
Source/WebKit/UIProcess/API/C/WKWebsiteDataStoreRef.cpp
Source/WebKit/UIProcess/API/C/WKWebsiteDataStoreRef.h
Tools/ChangeLog
Tools/DumpRenderTree/mac/DumpRenderTree.mm
Tools/WebKitTestRunner/TestController.cpp
Tools/WebKitTestRunner/TestController.h
Tools/WebKitTestRunner/TestInvocation.cpp

index 24ae30e..31aadd8 100644 (file)
@@ -1,3 +1,17 @@
+2019-01-23  Sihui Liu  <sihui_liu@apple.com>
+
+        Clean up IndexedDB files between tests
+        https://bugs.webkit.org/show_bug.cgi?id=192796
+        <rdar://problem/46824999>
+
+        Reviewed by Geoffrey Garen.
+
+        We should clean up the IndexedDB files between tests to make sure each IDB test is independent of others.
+
+        * Modules/indexeddb/server/UniqueIDBDatabase.cpp:
+        (WebCore::IDBServer::UniqueIDBDatabase::didDeleteBackingStore):
+        (WebCore::IDBServer::UniqueIDBDatabase::transactionCompleted):
+
 2019-01-23  Oriol Brufau  <obrufau@igalia.com>
 
         Add CSS Logical spec to features.json
index 238320d..dfad787 100644 (file)
@@ -337,6 +337,10 @@ void UniqueIDBDatabase::didDeleteBackingStore(uint64_t deletedVersion)
     }
 
     m_deleteBackingStoreInProgress = false;
+
+    if (m_hardClosedForUserDelete)
+        return;
+
     invokeOperationAndTransactionTimer();
 }
 
@@ -634,6 +638,9 @@ void UniqueIDBDatabase::didOpenBackingStore(const IDBDatabaseInfo& info, const I
     ASSERT(m_isOpeningBackingStore);
     m_isOpeningBackingStore = false;
 
+    if (m_hardClosedForUserDelete)
+        return;
+
     handleDatabaseOperations();
 }
 
@@ -1708,7 +1715,7 @@ void UniqueIDBDatabase::transactionCompleted(RefPtr<UniqueIDBDatabaseTransaction
     for (auto objectStore : transaction->objectStoreIdentifiers()) {
         if (!transaction->isReadOnly()) {
             m_objectStoreWriteTransactions.remove(objectStore);
-            ASSERT(m_objectStoreTransactionCounts.count(objectStore) == 1);
+            ASSERT(m_objectStoreTransactionCounts.count(objectStore) == 1 || m_hardClosedForUserDelete);
         }
         m_objectStoreTransactionCounts.remove(objectStore);
     }
index e2f429f..54b444c 100644 (file)
@@ -1,3 +1,15 @@
+2019-01-23  Sihui Liu  <sihui_liu@apple.com>
+
+        Clean up IndexedDB files between tests
+        https://bugs.webkit.org/show_bug.cgi?id=192796
+        <rdar://problem/46824999>
+
+        Reviewed by Geoffrey Garen.
+
+        * UIProcess/API/C/WKWebsiteDataStoreRef.cpp:
+        (WKWebsiteDataStoreRemoveAllIndexedDatabases):
+        * UIProcess/API/C/WKWebsiteDataStoreRef.h:
+
 2019-01-23  Wenson Hsieh  <wenson_hsieh@apple.com>
 
         [iOS] fast/events/touch/ios/hover-when-style-change-is-async.html times out
index ba333c9..528c4c2 100644 (file)
@@ -448,10 +448,13 @@ void WKWebsiteDataStoreRemoveFetchCacheForOrigin(WKWebsiteDataStoreRef dataStore
     });
 }
 
-void WKWebsiteDataStoreRemoveAllIndexedDatabases(WKWebsiteDataStoreRef dataStoreRef)
+void WKWebsiteDataStoreRemoveAllIndexedDatabases(WKWebsiteDataStoreRef dataStoreRef, void* context, WKWebsiteDataStoreRemoveAllIndexedDatabasesCallback callback)
 {
     OptionSet<WebKit::WebsiteDataType> dataTypes = WebKit::WebsiteDataType::IndexedDBDatabases;
-    WebKit::toImpl(dataStoreRef)->websiteDataStore().removeData(dataTypes, -WallTime::infinity(), [] { });
+    WebKit::toImpl(dataStoreRef)->websiteDataStore().removeData(dataTypes, -WallTime::infinity(), [context, callback] {
+    if (callback)
+        callback(context);
+    });
 }
 
 void WKWebsiteDataStoreRemoveAllServiceWorkerRegistrations(WKWebsiteDataStoreRef dataStoreRef, void* context, WKWebsiteDataStoreRemoveAllServiceWorkerRegistrationsCallback callback)
index 01b98e1..93e5218 100644 (file)
@@ -103,7 +103,8 @@ WK_EXPORT void WKWebsiteDataStoreRemoveAllFetchCaches(WKWebsiteDataStoreRef data
 typedef void (*WKWebsiteDataStoreRemoveAllServiceWorkerRegistrationsCallback)(void* functionContext);
 WK_EXPORT void WKWebsiteDataStoreRemoveAllServiceWorkerRegistrations(WKWebsiteDataStoreRef dataStoreRef, void* context, WKWebsiteDataStoreRemoveAllServiceWorkerRegistrationsCallback callback);
 
-WK_EXPORT void WKWebsiteDataStoreRemoveAllIndexedDatabases(WKWebsiteDataStoreRef dataStoreRef);
+typedef void (*WKWebsiteDataStoreRemoveAllIndexedDatabasesCallback)(void* functionContext);
+WK_EXPORT void WKWebsiteDataStoreRemoveAllIndexedDatabases(WKWebsiteDataStoreRef dataStoreRef, void* context, WKWebsiteDataStoreRemoveAllIndexedDatabasesCallback callback);
 
 typedef void (*WKWebsiteDataStoreGetFetchCacheOriginsFunction)(WKArrayRef, void*);
 WK_EXPORT void WKWebsiteDataStoreGetFetchCacheOrigins(WKWebsiteDataStoreRef dataStoreRef, void* context, WKWebsiteDataStoreGetFetchCacheOriginsFunction function);
index 9e3e960..8330579 100644 (file)
@@ -1,3 +1,22 @@
+2019-01-23  Sihui Liu  <sihui_liu@apple.com>
+
+        Clean up IndexedDB files between tests
+        https://bugs.webkit.org/show_bug.cgi?id=192796
+        <rdar://problem/46824999>
+
+        Reviewed by Geoffrey Garen.
+
+        * DumpRenderTree/mac/DumpRenderTree.mm:
+        (runTest):
+        * WebKitTestRunner/TestController.cpp:
+        (WTR::TestController::resetStateToConsistentValues):
+        (WTR::RemoveAllIndexedDatabasesCallbackContext::RemoveAllIndexedDatabasesCallbackContext):
+        (WTR::RemoveAllIndexedDatabasesCallback):
+        (WTR::TestController::ClearIndexedDatabases):
+        * WebKitTestRunner/TestController.h:
+        * WebKitTestRunner/TestInvocation.cpp:
+        (WTR::TestInvocation::didReceiveSynchronousMessageFromInjectedBundle):
+
 2019-01-23  Aakash Jain  <aakash_jain@apple.com>
 
         [ews-app] Rename ews model Builds to Build
index d6b5a65..f313aeb 100644 (file)
@@ -2013,6 +2013,9 @@ static void runTest(const string& inputLine)
     gTestRunner->setIconDatabaseEnabled(false);
     gTestRunner->clearAllApplicationCaches();
 
+    gTestRunner->clearAllDatabases();
+    gTestRunner->setIDBPerOriginQuota(50 * MB);
+
     if (disallowedURLs)
         CFSetRemoveAllValues(disallowedURLs);
     if (shouldLogFrameLoadDelegates(pathOrURL.c_str()))
index a7040b2..7b662aa 100644 (file)
@@ -868,6 +868,9 @@ bool TestController::resetStateToConsistentValues(const TestOptions& options, Re
 
     WKContextClearCachedCredentials(TestController::singleton().context());
 
+    ClearIndexedDatabases();
+    setIDBPerOriginQuota(50 * MB);
+
     clearServiceWorkerRegistrations();
     clearDOMCaches();
 
@@ -2766,6 +2769,31 @@ void TestController::setIDBPerOriginQuota(uint64_t quota)
     WKContextSetIDBPerOriginQuota(platformContext(), quota);
 }
 
+struct RemoveAllIndexedDatabasesCallbackContext {
+    explicit RemoveAllIndexedDatabasesCallbackContext(TestController& controller)
+        : testController(controller)
+    {
+    }
+
+    TestController& testController;
+    bool done { false };
+};
+
+static void RemoveAllIndexedDatabasesCallback(void* userData)
+{
+    auto* context = static_cast<RemoveAllIndexedDatabasesCallbackContext*>(userData);
+    context->done = true;
+    context->testController.notifyDone();
+}
+
+void TestController::ClearIndexedDatabases()
+{
+    auto websiteDataStore = WKContextGetWebsiteDataStore(platformContext());
+    RemoveAllIndexedDatabasesCallbackContext context(*this);
+    WKWebsiteDataStoreRemoveAllIndexedDatabases(websiteDataStore, &context, RemoveAllIndexedDatabasesCallback);
+    runUntil(context.done, noTimeout);
+}
+
 struct FetchCacheOriginsCallbackContext {
     FetchCacheOriginsCallbackContext(TestController& controller, WKStringRef origin)
         : testController(controller)
index 1425cbf..2058c79 100644 (file)
@@ -242,6 +242,8 @@ public:
 
     void removeAllSessionCredentials();
 
+    void ClearIndexedDatabases();
+
     void clearServiceWorkerRegistrations();
 
     void clearDOMCache(WKStringRef origin);
index 1d8d7d9..1fedd8b 100644 (file)
@@ -911,7 +911,7 @@ WKRetainPtr<WKTypeRef> TestInvocation::didReceiveSynchronousMessageFromInjectedB
     }
     
     if (WKStringIsEqualToUTF8CString(messageName, "DeleteAllIndexedDatabases")) {
-        WKWebsiteDataStoreRemoveAllIndexedDatabases(WKContextGetWebsiteDataStore(TestController::singleton().context()));
+        WKWebsiteDataStoreRemoveAllIndexedDatabases(WKContextGetWebsiteDataStore(TestController::singleton().context()), nullptr, { });
         return nullptr;
     }