Modern IDB: Blocked event can fire on a delete request even after the last open conne...
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 8 Jan 2016 21:12:08 +0000 (21:12 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 8 Jan 2016 21:12:08 +0000 (21:12 +0000)
https://bugs.webkit.org/show_bug.cgi?id=152896

Reviewed by Alex Christensen.

LayoutTests/imported/w3c:

* indexeddb/idbfactory_open12-expected.txt:
* indexeddb/idbversionchangeevent-expected.txt:
* indexeddb/transaction-lifetime-expected.txt:

Source/WebCore:

No new tests (Progression in many tests).

* Modules/indexeddb/client/IDBFactoryImpl.cpp:
(WebCore::IDBClient::IDBFactory::deleteDatabase):

* Modules/indexeddb/server/UniqueIDBDatabase.cpp:
(WebCore::IDBServer::UniqueIDBDatabase::performCurrentDeleteOperation): Allow for handling 2+ delete operations in a row.
(WebCore::IDBServer::UniqueIDBDatabase::didDeleteBackingStore): Ditto.
(WebCore::IDBServer::UniqueIDBDatabase::connectionClosedFromClient): Call "notifyCurrentRequestConnectionClosedOrFiredVersionChangeEvent"
  after the connection is actually removed from the set of open connections.
* Modules/indexeddb/server/UniqueIDBDatabase.h:

LayoutTests:

* platform/mac-wk1/TestExpectations:

* platform/wk2/imported/w3c/indexeddb/idbfactory_open12-expected.txt: Copied from LayoutTests/imported/w3c/indexeddb/idbfactory_open12-expected.txt.
* platform/wk2/imported/w3c/indexeddb/idbversionchangeevent-expected.txt: Copied from LayoutTests/imported/w3c/indexeddb/idbversionchangeevent-expected.txt.

* storage/indexeddb/database-wrapper-expected.txt:
* storage/indexeddb/delete-in-upgradeneeded-close-in-versionchange-expected.txt:
* storage/indexeddb/deletedatabase-not-blocked-expected.txt:
* storage/indexeddb/intversion-upgrades-expected.txt:
* storage/indexeddb/resources/delete-in-upgradeneeded-close-in-versionchange.js:
* storage/indexeddb/resources/deletedatabase-not-blocked.js:
* storage/indexeddb/resources/setversion-not-blocked.js:
* storage/indexeddb/setversion-not-blocked-expected.txt:

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

20 files changed:
LayoutTests/ChangeLog
LayoutTests/imported/w3c/ChangeLog
LayoutTests/imported/w3c/indexeddb/idbfactory_open12-expected.txt
LayoutTests/imported/w3c/indexeddb/idbversionchangeevent-expected.txt
LayoutTests/imported/w3c/indexeddb/transaction-lifetime-expected.txt
LayoutTests/platform/mac-wk1/TestExpectations
LayoutTests/platform/wk2/imported/w3c/indexeddb/idbfactory_open12-expected.txt [new file with mode: 0644]
LayoutTests/platform/wk2/imported/w3c/indexeddb/idbversionchangeevent-expected.txt [new file with mode: 0644]
LayoutTests/storage/indexeddb/database-wrapper-expected.txt
LayoutTests/storage/indexeddb/delete-in-upgradeneeded-close-in-versionchange-expected.txt
LayoutTests/storage/indexeddb/deletedatabase-not-blocked-expected.txt
LayoutTests/storage/indexeddb/intversion-upgrades-expected.txt
LayoutTests/storage/indexeddb/resources/delete-in-upgradeneeded-close-in-versionchange.js
LayoutTests/storage/indexeddb/resources/deletedatabase-not-blocked.js
LayoutTests/storage/indexeddb/resources/setversion-not-blocked.js
LayoutTests/storage/indexeddb/setversion-not-blocked-expected.txt
Source/WebCore/ChangeLog
Source/WebCore/Modules/indexeddb/client/IDBFactoryImpl.cpp
Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp
Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.h

index 30fcf29..eb3fbbd 100644 (file)
@@ -1,3 +1,24 @@
+2016-01-08  Brady Eidson  <beidson@apple.com>
+
+        Modern IDB: Blocked event can fire on a delete request even after the last open connection has closed.
+        https://bugs.webkit.org/show_bug.cgi?id=152896
+
+        Reviewed by Alex Christensen.
+
+        * platform/mac-wk1/TestExpectations:
+        
+        * platform/wk2/imported/w3c/indexeddb/idbfactory_open12-expected.txt: Copied from LayoutTests/imported/w3c/indexeddb/idbfactory_open12-expected.txt.
+        * platform/wk2/imported/w3c/indexeddb/idbversionchangeevent-expected.txt: Copied from LayoutTests/imported/w3c/indexeddb/idbversionchangeevent-expected.txt.
+        
+        * storage/indexeddb/database-wrapper-expected.txt:
+        * storage/indexeddb/delete-in-upgradeneeded-close-in-versionchange-expected.txt:
+        * storage/indexeddb/deletedatabase-not-blocked-expected.txt:
+        * storage/indexeddb/intversion-upgrades-expected.txt:
+        * storage/indexeddb/resources/delete-in-upgradeneeded-close-in-versionchange.js:
+        * storage/indexeddb/resources/deletedatabase-not-blocked.js:
+        * storage/indexeddb/resources/setversion-not-blocked.js:
+        * storage/indexeddb/setversion-not-blocked-expected.txt:
+
 2016-01-08  Michael Catanzaro  <mcatanzaro@igalia.com>
 
         [GTK] Several animation tests fail with accelerated compositing enabled
index ed1e3a6..78e2d00 100644 (file)
@@ -1,5 +1,16 @@
 2016-01-08  Brady Eidson  <beidson@apple.com>
 
+        Modern IDB: Blocked event can fire on a delete request even after the last open connection has closed.
+        https://bugs.webkit.org/show_bug.cgi?id=152896
+
+        Reviewed by Alex Christensen.
+
+        * indexeddb/idbfactory_open12-expected.txt:
+        * indexeddb/idbversionchangeevent-expected.txt:
+        * indexeddb/transaction-lifetime-expected.txt:
+
+2016-01-08  Brady Eidson  <beidson@apple.com>
+
         Modern IDB: imported/w3c/indexeddb/idbobjectstore_createIndex6-event_order.htm fails.
         https://bugs.webkit.org/show_bug.cgi?id=152891
 
index bf86e70..d91bb27 100644 (file)
@@ -1,4 +1,4 @@
 
 PASS IDBFactory.open() - upgradeneeded gets VersionChangeEvent 
-FAIL IDBFactory.open() - upgradeneeded gets VersionChangeEvent - second upgrade assert_unreached: unexpected open.blocked event Reached unreachable code
+PASS IDBFactory.open() - upgradeneeded gets VersionChangeEvent - second upgrade 
 
index 833b846..ff2e832 100644 (file)
@@ -1,3 +1,3 @@
 
-FAIL IDBVersionChangeEvent fired in upgradeneeded, versionchange and deleteDatabase assert_equals: new version (versionchange) expected (object) null but got (number) 0
+PASS IDBVersionChangeEvent fired in upgradeneeded, versionchange and deleteDatabase 
 
index 5234708..3ab3fdd 100644 (file)
@@ -1,3 +1,3 @@
 
-FAIL Test events opening a second database when one connection is open already assert_unreached: open2.blocked Reached unreachable code
+PASS Test events opening a second database when one connection is open already 
 
index 0400307..e05d389 100644 (file)
@@ -74,7 +74,6 @@ imported/w3c/indexeddb/interfaces.html [ Skip ]
 imported/w3c/indexeddb/keyorder.htm [ Skip ]
 
 # W3C IDB tests - Legacy IDB fails, Modern IDB fails differently
-imported/w3c/indexeddb/idbversionchangeevent.htm [ Failure ]
 imported/w3c/indexeddb/keypath.htm [ Failure ]
 
 # W3C IDB tests where the test is wrong (the spec, other browsers, and WebKit all agree)
diff --git a/LayoutTests/platform/wk2/imported/w3c/indexeddb/idbfactory_open12-expected.txt b/LayoutTests/platform/wk2/imported/w3c/indexeddb/idbfactory_open12-expected.txt
new file mode 100644 (file)
index 0000000..bf86e70
--- /dev/null
@@ -0,0 +1,4 @@
+
+PASS IDBFactory.open() - upgradeneeded gets VersionChangeEvent 
+FAIL IDBFactory.open() - upgradeneeded gets VersionChangeEvent - second upgrade assert_unreached: unexpected open.blocked event Reached unreachable code
+
diff --git a/LayoutTests/platform/wk2/imported/w3c/indexeddb/idbversionchangeevent-expected.txt b/LayoutTests/platform/wk2/imported/w3c/indexeddb/idbversionchangeevent-expected.txt
new file mode 100644 (file)
index 0000000..833b846
--- /dev/null
@@ -0,0 +1,3 @@
+
+FAIL IDBVersionChangeEvent fired in upgradeneeded, versionchange and deleteDatabase assert_equals: new version (versionchange) expected (object) null but got (number) 0
+
index 5b2c73b..b5c80ae 100644 (file)
@@ -27,9 +27,6 @@ onVersionChange():
 event.target.close()
 sawVersionChangeEvent = true
 
-onBlocked():
-FIXME: Blocked event shouldn't fire. http://crbug.com/100123
-
 openAgainSuccess():
 PASS sawVersionChangeEvent is true
 PASS successfullyParsed is true
index c2e07a7..fd7c297 100644 (file)
@@ -27,14 +27,9 @@ sawVersionChange = true
 Closing the connection before the IDBOpenDBRequest's success fires will cause the open to fail.
 db.close()
 
-deleteBlockedCallback():
-PASS sawVersionChange is true
-sawDeleteBlocked = true
-
 deleteSuccessCallback():
 PASS sawVersionChange is true
-FIXME: Blocked events shouldn't fire if connections close in versionchange handler. http://crbug.com/100123
-FAIL sawDeleteBlocked should be false. Was true.
+PASS sawDeleteBlocked is false
 PASS sawUpgradeNeeded is true
 PASS successfullyParsed is true
 
index 142ce58..09c0d6d 100644 (file)
@@ -19,12 +19,8 @@ PASS event.oldVersion is 1
 PASS event.newVersion is null
 h.close()
 
-deleteDatabaseOnBlocked():
-blockedEventFired = true
-
 deleteDatabaseOnSuccess():
-FIXME: blocked event should not fire since connection closed. http://webkit.org/b/71130
-FAIL blockedEventFired should be false. Was true.
+PASS blockedEventFired is false
 PASS successfullyParsed is true
 
 TEST COMPLETE
index 794b516..1f44def 100644 (file)
@@ -23,9 +23,6 @@ request = indexedDB.open(dbname, 2)
 connection1VersionChangeCallback():
 connection1.close()
 
-connection2BlockedCallback():
-This should not be called: http://crbug.com/100123
-
 connection2UpgradeNeeded():
 connection2 = event.target.result
 PASS String(connection2) is "[object IDBDatabase]"
index 1b460ad..38cecff 100644 (file)
@@ -63,7 +63,6 @@ function deleteSuccessCallback(evt)
 {
     preamble(evt);
     shouldBeTrue("sawVersionChange");
-    debug("FIXME: Blocked events shouldn't fire if connections close in versionchange handler. http://crbug.com/100123");
     shouldBeFalse("sawDeleteBlocked");
     shouldBeTrue("sawUpgradeNeeded");
     finishJSTest();
index d2b1c0e..24321d0 100644 (file)
@@ -34,7 +34,6 @@ function test() {
         };
         request.onsuccess = function deleteDatabaseOnSuccess(evt) {
             preamble(evt);
-            debug("FIXME: blocked event should not fire since connection closed. http://webkit.org/b/71130");
             shouldBeFalse("blockedEventFired");
             finishJSTest();
         };
index a325dcc..981f48b 100644 (file)
@@ -42,7 +42,6 @@ function onOpen(evt)
     request.onsuccess = function h2OpenSuccess(evt) {
         preamble(evt);
         shouldBeTrue("versionchangeEventFired");
-        debug("FIXME: blocked should not have fired since connection closed; http://webkit.org/b/71130");
         shouldBeFalse("blockedEventFired");
         finishJSTest();
     };
index 977f23d..c6c8b23 100644 (file)
@@ -22,19 +22,13 @@ PASS event.oldVersion is 1
 PASS event.newVersion is 2
 h1.close()
 
-h2OpenBlocked():
-PASS event.oldVersion is 1
-PASS event.newVersion is 2
-blockedEventFired = true
-
 h2UpgradeNeeded():
 PASS event.oldVersion is 1
 PASS event.newVersion is 2
 
 h2OpenSuccess():
 PASS versionchangeEventFired is true
-FIXME: blocked should not have fired since connection closed; http://webkit.org/b/71130
-FAIL blockedEventFired should be false. Was true.
+PASS blockedEventFired is false
 PASS successfullyParsed is true
 
 TEST COMPLETE
index 24aaae3..2467217 100644 (file)
@@ -1,3 +1,22 @@
+2016-01-08  Brady Eidson  <beidson@apple.com>
+
+        Modern IDB: Blocked event can fire on a delete request even after the last open connection has closed.
+        https://bugs.webkit.org/show_bug.cgi?id=152896
+
+        Reviewed by Alex Christensen.
+
+        No new tests (Progression in many tests).
+
+        * Modules/indexeddb/client/IDBFactoryImpl.cpp:
+        (WebCore::IDBClient::IDBFactory::deleteDatabase):
+        
+        * Modules/indexeddb/server/UniqueIDBDatabase.cpp:
+        (WebCore::IDBServer::UniqueIDBDatabase::performCurrentDeleteOperation): Allow for handling 2+ delete operations in a row.
+        (WebCore::IDBServer::UniqueIDBDatabase::didDeleteBackingStore): Ditto.
+        (WebCore::IDBServer::UniqueIDBDatabase::connectionClosedFromClient): Call "notifyCurrentRequestConnectionClosedOrFiredVersionChangeEvent"
+          after the connection is actually removed from the set of open connections.
+        * Modules/indexeddb/server/UniqueIDBDatabase.h:
+
 2016-01-08  Zalan Bujtas  <zalan@apple.com>
 
         Hovering link on http://help.apple.com/appletv/#/ does not show text underline.
index fda69b5..2ae2693 100644 (file)
@@ -124,7 +124,7 @@ RefPtr<IDBOpenDBRequest> IDBFactory::openInternal(ScriptExecutionContext* contex
 
 RefPtr<WebCore::IDBOpenDBRequest> IDBFactory::deleteDatabase(ScriptExecutionContext* context, const String& name, ExceptionCode& ec)
 {
-    LOG(IndexedDB, "IDBFactory::deleteDatabase");
+    LOG(IndexedDB, "IDBFactory::deleteDatabase - %s", name.utf8().data());
 
     if (name.isNull()) {
         ec = TypeError;
index 7c86eac..223239b 100644 (file)
@@ -164,9 +164,8 @@ void UniqueIDBDatabase::performCurrentOpenOperation()
 void UniqueIDBDatabase::performCurrentDeleteOperation()
 {
     ASSERT(isMainThread());
-    LOG(IndexedDB, "(main) UniqueIDBDatabase::performCurrentDeleteOperation");
+    LOG(IndexedDB, "(main) UniqueIDBDatabase::performCurrentDeleteOperation - %s", m_identifier.debugString().utf8().data());
 
-    ASSERT(m_databaseInfo);
     ASSERT(m_currentOpenDBRequest);
     ASSERT(m_currentOpenDBRequest->isDeleteRequest());
 
@@ -189,8 +188,17 @@ void UniqueIDBDatabase::performCurrentDeleteOperation()
     ASSERT(m_pendingTransactions.isEmpty());
     ASSERT(m_openDatabaseConnections.isEmpty());
 
-    m_deleteBackingStoreInProgress = true;
-    m_server.postDatabaseTask(createCrossThreadTask(*this, &UniqueIDBDatabase::deleteBackingStore));
+    // It's possible to have multiple delete requests queued up in a row.
+    // In that scenario only the first request will actually have to delete the database.
+    // Subsequent requests can immediately notify their completion.
+
+    if (m_databaseInfo) {
+        m_deleteBackingStoreInProgress = true;
+        m_server.postDatabaseTask(createCrossThreadTask(*this, &UniqueIDBDatabase::deleteBackingStore));
+    } else {
+        ASSERT(m_mostRecentDeletedDatabaseInfo);
+        didDeleteBackingStore();
+    }
 }
 
 void UniqueIDBDatabase::deleteBackingStore()
@@ -211,7 +219,6 @@ void UniqueIDBDatabase::didDeleteBackingStore()
     ASSERT(isMainThread());
     LOG(IndexedDB, "(main) UniqueIDBDatabase::didDeleteBackingStore");
 
-    ASSERT(m_databaseInfo);
     ASSERT(m_currentOpenDBRequest);
     ASSERT(m_currentOpenDBRequest->isDeleteRequest());
     ASSERT(!hasAnyPendingCallbacks());
@@ -219,9 +226,13 @@ void UniqueIDBDatabase::didDeleteBackingStore()
     ASSERT(m_pendingTransactions.isEmpty());
     ASSERT(m_openDatabaseConnections.isEmpty());
 
-    m_currentOpenDBRequest->notifyDidDeleteDatabase(*m_databaseInfo);
+    if (m_databaseInfo)
+        m_mostRecentDeletedDatabaseInfo = WTFMove(m_databaseInfo);
+
+    ASSERT(m_mostRecentDeletedDatabaseInfo);
+    m_currentOpenDBRequest->notifyDidDeleteDatabase(*m_mostRecentDeletedDatabaseInfo);
     m_currentOpenDBRequest = nullptr;
-    m_databaseInfo = nullptr;
+
     m_deletePending = false;
     m_deleteBackingStoreInProgress = false;
 
@@ -1007,9 +1018,6 @@ void UniqueIDBDatabase::connectionClosedFromClient(UniqueIDBDatabaseConnection&
 
     ASSERT(m_openDatabaseConnections.contains(&connection));
 
-    if (m_currentOpenDBRequest)
-        notifyCurrentRequestConnectionClosedOrFiredVersionChangeEvent(connection.identifier());
-
     Deque<RefPtr<UniqueIDBDatabaseTransaction>> pendingTransactions;
     while (!m_pendingTransactions.isEmpty()) {
         auto transaction = m_pendingTransactions.takeFirst();
@@ -1022,6 +1030,10 @@ void UniqueIDBDatabase::connectionClosedFromClient(UniqueIDBDatabaseConnection&
 
     RefPtr<UniqueIDBDatabaseConnection> refConnection(&connection);
     m_openDatabaseConnections.remove(&connection);
+
+    if (m_currentOpenDBRequest)
+        notifyCurrentRequestConnectionClosedOrFiredVersionChangeEvent(connection.identifier());
+
     if (connection.hasNonFinishedTransactions()) {
         m_closePendingDatabaseConnections.add(WTFMove(refConnection));
         return;
index fc7bc76..a3fec21 100644 (file)
@@ -193,6 +193,7 @@ private:
     bool m_isOpeningBackingStore { false };
     std::unique_ptr<IDBBackingStore> m_backingStore;
     std::unique_ptr<IDBDatabaseInfo> m_databaseInfo;
+    std::unique_ptr<IDBDatabaseInfo> m_mostRecentDeletedDatabaseInfo;
 
     HashMap<uint64_t, ErrorCallback> m_errorCallbacks;
     HashMap<uint64_t, KeyDataCallback> m_keyDataCallbacks;