- Revision
- 239358
- Author
- [email protected]
- Date
- 2018-12-18 15:56:23 -0800 (Tue, 18 Dec 2018)
Log Message
Clean up IndexedDB files between tests
https://bugs.webkit.org/show_bug.cgi?id=192796
Reviewed by Geoffrey Garen.
Source/WebCore:
We should clean up the IndexedDB files between tests to make sure each test is independent of others.
This patch also fixes some issues in IDB.
Covered by existing tests.
* Modules/indexeddb/server/IDBServer.cpp:
(WebCore::IDBServer::IDBServer::closeAndDeleteDatabasesModifiedSince):
We should shut down all open databases instead of databases from open database connections before deleting
files, because database starts accessing files before connection to database is established.
* Modules/indexeddb/server/UniqueIDBDatabase.cpp:
(WebCore::IDBServer::UniqueIDBDatabase::shutdownForClose):
We should shutdown database after tasks in queue are completed, because tasks have pointer of UniqueIDBDatabase
and UniqueIDBDatabase can be destructed after shutdown.
(WebCore::IDBServer::UniqueIDBDatabase::didDeleteBackingStore):
didDeleteBackingStore can be posted to main thread after immediateCloseForUserDelete, and timer should not be
invoked during the hard close.
(WebCore::IDBServer::UniqueIDBDatabase::handleDatabaseOperations):
Tasks like didOpenBackingStore could be posted from database thread to main thread after
immediateCloseForUserDelete, but we know the backing store will be deleted soon, so no need to handle any
database operation.
(WebCore::IDBServer::UniqueIDBDatabase::performPrefetchCursor):
performPrefetchCursor needs to be aware of whether UniqueIDBDatabase is being closed, so that it will not access
m_backingStore when m_backingStore may already be deleted.
(WebCore::IDBServer::UniqueIDBDatabase::immediateCloseForUserDelete):
immediateCloseForUserDelete does not handle transactions that are in the process of commit or abort.
m_objectStoreTransactionCounts and m_objectStoreWriteTransactions may be used by those transactions in
transactionCompleted, so they do not need to be cleared here.
Source/WebKit:
* UIProcess/API/C/WKWebsiteDataStoreRef.cpp:
(WKWebsiteDataStoreRemoveAllIndexedDatabasesSync):
* 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:
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (239357 => 239358)
--- trunk/Source/WebCore/ChangeLog 2018-12-18 23:38:54 UTC (rev 239357)
+++ trunk/Source/WebCore/ChangeLog 2018-12-18 23:56:23 UTC (rev 239358)
@@ -1,3 +1,44 @@
+2018-12-18 Sihui Liu <[email protected]>
+
+ Clean up IndexedDB files between tests
+ https://bugs.webkit.org/show_bug.cgi?id=192796
+
+ Reviewed by Geoffrey Garen.
+
+ We should clean up the IndexedDB files between tests to make sure each test is independent of others.
+
+ This patch also fixes some issues in IDB.
+
+ Covered by existing tests.
+
+ * Modules/indexeddb/server/IDBServer.cpp:
+ (WebCore::IDBServer::IDBServer::closeAndDeleteDatabasesModifiedSince):
+ We should shut down all open databases instead of databases from open database connections before deleting
+ files, because database starts accessing files before connection to database is established.
+
+ * Modules/indexeddb/server/UniqueIDBDatabase.cpp:
+ (WebCore::IDBServer::UniqueIDBDatabase::shutdownForClose):
+ We should shutdown database after tasks in queue are completed, because tasks have pointer of UniqueIDBDatabase
+ and UniqueIDBDatabase can be destructed after shutdown.
+
+ (WebCore::IDBServer::UniqueIDBDatabase::didDeleteBackingStore):
+ didDeleteBackingStore can be posted to main thread after immediateCloseForUserDelete, and timer should not be
+ invoked during the hard close.
+
+ (WebCore::IDBServer::UniqueIDBDatabase::handleDatabaseOperations):
+ Tasks like didOpenBackingStore could be posted from database thread to main thread after
+ immediateCloseForUserDelete, but we know the backing store will be deleted soon, so no need to handle any
+ database operation.
+
+ (WebCore::IDBServer::UniqueIDBDatabase::performPrefetchCursor):
+ performPrefetchCursor needs to be aware of whether UniqueIDBDatabase is being closed, so that it will not access
+ m_backingStore when m_backingStore may already be deleted.
+
+ (WebCore::IDBServer::UniqueIDBDatabase::immediateCloseForUserDelete):
+ immediateCloseForUserDelete does not handle transactions that are in the process of commit or abort.
+ m_objectStoreTransactionCounts and m_objectStoreWriteTransactions may be used by those transactions in
+ transactionCompleted, so they do not need to be cleared here.
+
2018-12-18 Myles C. Maxfield <[email protected]>
Thick overlines and line-throughs grow in the wrong direction
Modified: trunk/Source/WebCore/Modules/indexeddb/server/IDBServer.cpp (239357 => 239358)
--- trunk/Source/WebCore/Modules/indexeddb/server/IDBServer.cpp 2018-12-18 23:38:54 UTC (rev 239357)
+++ trunk/Source/WebCore/Modules/indexeddb/server/IDBServer.cpp 2018-12-18 23:56:23 UTC (rev 239358)
@@ -509,8 +509,8 @@
}
HashSet<UniqueIDBDatabase*> openDatabases;
- for (auto* connection : m_databaseConnections.values())
- openDatabases.add(connection->database());
+ for (auto& database : m_uniqueIDBDatabaseMap.values())
+ openDatabases.add(database.get());
for (auto& database : openDatabases)
database->immediateCloseForUserDelete();
Modified: trunk/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp (239357 => 239358)
--- trunk/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp 2018-12-18 23:38:54 UTC (rev 239357)
+++ trunk/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp 2018-12-18 23:56:23 UTC (rev 239358)
@@ -294,7 +294,10 @@
m_backingStoreSupportsSimultaneousTransactions = false;
m_backingStoreIsEphemeral = false;
- ASSERT(m_databaseQueue.isEmpty());
+ if (!m_databaseQueue.isEmpty()) {
+ postDatabaseTask(createCrossThreadTask(*this, &UniqueIDBDatabase::shutdownForClose));
+ return;
+ }
m_databaseQueue.kill();
postDatabaseTaskReply(createCrossThreadTask(*this, &UniqueIDBDatabase::didShutdownForClose));
@@ -336,7 +339,9 @@
}
m_deleteBackingStoreInProgress = false;
- invokeOperationAndTransactionTimer();
+
+ if (!m_hardClosedForUserDelete)
+ invokeOperationAndTransactionTimer();
}
void UniqueIDBDatabase::handleDatabaseOperations()
@@ -343,8 +348,10 @@
{
ASSERT(isMainThread());
LOG(IndexedDB, "(main) UniqueIDBDatabase::handleDatabaseOperations - There are %u pending", m_pendingOpenDBRequests.size());
- ASSERT(!m_hardClosedForUserDelete);
+ if (m_hardClosedForUserDelete)
+ return;
+
if (m_deleteBackingStoreInProgress)
return;
@@ -1278,6 +1285,9 @@
ASSERT(m_cursorPrefetches.contains(cursorIdentifier));
LOG(IndexedDB, "(db) UniqueIDBDatabase::performPrefetchCursor");
+ if (m_owningPointerForClose)
+ return;
+
if (m_backingStore->prefetchCursor(transactionIdentifier, cursorIdentifier))
postDatabaseTask(createCrossThreadTask(*this, &UniqueIDBDatabase::performPrefetchCursor, transactionIdentifier, cursorIdentifier));
else
@@ -1818,8 +1828,6 @@
for (auto& transaction : m_pendingTransactions)
transaction->databaseConnection().deleteTransaction(*transaction);
m_pendingTransactions.clear();
- m_objectStoreTransactionCounts.clear();
- m_objectStoreWriteTransactions.clear();
// Error out all pending callbacks
IDBError error = IDBError::userDeleteError();
Modified: trunk/Source/WebKit/ChangeLog (239357 => 239358)
--- trunk/Source/WebKit/ChangeLog 2018-12-18 23:38:54 UTC (rev 239357)
+++ trunk/Source/WebKit/ChangeLog 2018-12-18 23:56:23 UTC (rev 239358)
@@ -1,3 +1,14 @@
+2018-12-18 Sihui Liu <[email protected]>
+
+ Clean up IndexedDB files between tests
+ https://bugs.webkit.org/show_bug.cgi?id=192796
+
+ Reviewed by Geoffrey Garen.
+
+ * UIProcess/API/C/WKWebsiteDataStoreRef.cpp:
+ (WKWebsiteDataStoreRemoveAllIndexedDatabasesSync):
+ * UIProcess/API/C/WKWebsiteDataStoreRef.h:
+
2018-12-18 Vivek Seth <[email protected]>
HTTPS Upgrade: Scripts / preprocessing necessary to create new database in future
Modified: trunk/Source/WebKit/UIProcess/API/C/WKWebsiteDataStoreRef.cpp (239357 => 239358)
--- trunk/Source/WebKit/UIProcess/API/C/WKWebsiteDataStoreRef.cpp 2018-12-18 23:38:54 UTC (rev 239357)
+++ trunk/Source/WebKit/UIProcess/API/C/WKWebsiteDataStoreRef.cpp 2018-12-18 23:56:23 UTC (rev 239358)
@@ -511,10 +511,13 @@
});
}
-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)
Modified: trunk/Source/WebKit/UIProcess/API/C/WKWebsiteDataStoreRef.h (239357 => 239358)
--- trunk/Source/WebKit/UIProcess/API/C/WKWebsiteDataStoreRef.h 2018-12-18 23:38:54 UTC (rev 239357)
+++ trunk/Source/WebKit/UIProcess/API/C/WKWebsiteDataStoreRef.h 2018-12-18 23:56:23 UTC (rev 239358)
@@ -103,7 +103,8 @@
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);
Modified: trunk/Tools/ChangeLog (239357 => 239358)
--- trunk/Tools/ChangeLog 2018-12-18 23:38:54 UTC (rev 239357)
+++ trunk/Tools/ChangeLog 2018-12-18 23:56:23 UTC (rev 239358)
@@ -1,3 +1,19 @@
+2018-12-18 Sihui Liu <[email protected]>
+
+ Clean up IndexedDB files between tests
+ https://bugs.webkit.org/show_bug.cgi?id=192796
+
+ 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:
+
2018-12-18 Alex Christensen <[email protected]>
Fix API test introduced in r239339 on iOS.
Modified: trunk/Tools/DumpRenderTree/mac/DumpRenderTree.mm (239357 => 239358)
--- trunk/Tools/DumpRenderTree/mac/DumpRenderTree.mm 2018-12-18 23:38:54 UTC (rev 239357)
+++ trunk/Tools/DumpRenderTree/mac/DumpRenderTree.mm 2018-12-18 23:56:23 UTC (rev 239358)
@@ -2012,6 +2012,8 @@
sizeWebViewForCurrentTest();
gTestRunner->setIconDatabaseEnabled(false);
gTestRunner->clearAllApplicationCaches();
+ gTestRunner->clearAllDatabases();
+ gTestRunner->setIDBPerOriginQuota(50 * MB);
if (disallowedURLs)
CFSetRemoveAllValues(disallowedURLs);
Modified: trunk/Tools/WebKitTestRunner/TestController.cpp (239357 => 239358)
--- trunk/Tools/WebKitTestRunner/TestController.cpp 2018-12-18 23:38:54 UTC (rev 239357)
+++ trunk/Tools/WebKitTestRunner/TestController.cpp 2018-12-18 23:56:23 UTC (rev 239358)
@@ -867,6 +867,9 @@
WKContextClearCachedCredentials(TestController::singleton().context());
+ ClearIndexedDatabases();
+ setIDBPerOriginQuota(50 * MB);
+
clearServiceWorkerRegistrations();
clearDOMCaches();
@@ -2759,6 +2762,28 @@
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)
Modified: trunk/Tools/WebKitTestRunner/TestController.h (239357 => 239358)
--- trunk/Tools/WebKitTestRunner/TestController.h 2018-12-18 23:38:54 UTC (rev 239357)
+++ trunk/Tools/WebKitTestRunner/TestController.h 2018-12-18 23:56:23 UTC (rev 239358)
@@ -242,6 +242,8 @@
void removeAllSessionCredentials();
+ void ClearIndexedDatabases();
+
void clearServiceWorkerRegistrations();
void clearDOMCache(WKStringRef origin);
Modified: trunk/Tools/WebKitTestRunner/TestInvocation.cpp (239357 => 239358)
--- trunk/Tools/WebKitTestRunner/TestInvocation.cpp 2018-12-18 23:38:54 UTC (rev 239357)
+++ trunk/Tools/WebKitTestRunner/TestInvocation.cpp 2018-12-18 23:56:23 UTC (rev 239358)
@@ -903,7 +903,7 @@
}
if (WKStringIsEqualToUTF8CString(messageName, "DeleteAllIndexedDatabases")) {
- WKWebsiteDataStoreRemoveAllIndexedDatabases(WKContextGetWebsiteDataStore(TestController::singleton().context()));
+ WKWebsiteDataStoreRemoveAllIndexedDatabases(WKContextGetWebsiteDataStore(TestController::singleton().context()), nullptr, { });
return nullptr;
}