Modern IDB: After versionchange transactions abort, fire onerror on the original...
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 30 Nov 2015 20:12:07 +0000 (20:12 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 30 Nov 2015 20:12:07 +0000 (20:12 +0000)
https://bugs.webkit.org/show_bug.cgi?id=151648

Reviewed by Andy Estes.

Source/WebCore:

No new tests. Covered by at least one existing failing test which now passes, and many
other tests updated to fix their incorrect behavior.

* Modules/indexeddb/client/IDBDatabaseImpl.cpp:
(WebCore::IDBClient::IDBDatabase::transaction):
(WebCore::IDBClient::IDBDatabase::willAbortTransaction):
(WebCore::IDBClient::IDBDatabase::didAbortTransaction):

* Modules/indexeddb/client/IDBOpenDBRequestImpl.cpp:
(WebCore::IDBClient::IDBOpenDBRequest::fireErrorAfterVersionChangeAbort):
* Modules/indexeddb/client/IDBOpenDBRequestImpl.h:

* Modules/indexeddb/client/IDBTransactionImpl.cpp:
(WebCore::IDBClient::IDBTransaction::notifyDidAbort):
(WebCore::IDBClient::IDBTransaction::didAbort):
(WebCore::IDBClient::IDBTransaction::didCommit):
* Modules/indexeddb/client/IDBTransactionImpl.h:

LayoutTests:

* platform/mac-wk1/TestExpectations:
* storage/indexeddb/modern/abort-requests-cancelled-expected.txt:
* storage/indexeddb/modern/abort-requests-cancelled.html:
* storage/indexeddb/modern/aborted-put-expected.txt:
* storage/indexeddb/modern/aborted-put.html:
* storage/indexeddb/modern/createobjectstore-basic-expected.txt:
* storage/indexeddb/modern/createobjectstore-basic.html:
* storage/indexeddb/modern/deleteindex-2-expected.txt:
* storage/indexeddb/modern/deleteindex-2.html:
* storage/indexeddb/modern/deleteobjectstore-1-expected.txt:
* storage/indexeddb/modern/deleteobjectstore-1.html:
* storage/indexeddb/modern/idbdatabase-transaction-failures-expected.txt:
* storage/indexeddb/modern/versionchange-abort-then-reopen-expected.txt:
* storage/indexeddb/modern/versionchange-abort-then-reopen.html:

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

21 files changed:
LayoutTests/ChangeLog
LayoutTests/platform/mac-wk1/TestExpectations
LayoutTests/storage/indexeddb/modern/abort-requests-cancelled-expected.txt
LayoutTests/storage/indexeddb/modern/abort-requests-cancelled.html
LayoutTests/storage/indexeddb/modern/aborted-put-expected.txt
LayoutTests/storage/indexeddb/modern/aborted-put.html
LayoutTests/storage/indexeddb/modern/createobjectstore-basic-expected.txt
LayoutTests/storage/indexeddb/modern/createobjectstore-basic.html
LayoutTests/storage/indexeddb/modern/deleteindex-2-expected.txt
LayoutTests/storage/indexeddb/modern/deleteindex-2.html
LayoutTests/storage/indexeddb/modern/deleteobjectstore-1-expected.txt
LayoutTests/storage/indexeddb/modern/deleteobjectstore-1.html
LayoutTests/storage/indexeddb/modern/idbdatabase-transaction-failures-expected.txt
LayoutTests/storage/indexeddb/modern/versionchange-abort-then-reopen-expected.txt
LayoutTests/storage/indexeddb/modern/versionchange-abort-then-reopen.html
Source/WebCore/ChangeLog
Source/WebCore/Modules/indexeddb/client/IDBDatabaseImpl.cpp
Source/WebCore/Modules/indexeddb/client/IDBOpenDBRequestImpl.cpp
Source/WebCore/Modules/indexeddb/client/IDBOpenDBRequestImpl.h
Source/WebCore/Modules/indexeddb/client/IDBTransactionImpl.cpp
Source/WebCore/Modules/indexeddb/client/IDBTransactionImpl.h

index 13bc0d6..987aa4b 100644 (file)
@@ -1,3 +1,25 @@
+2015-11-30  Brady Eidson  <beidson@apple.com>
+
+        Modern IDB: After versionchange transactions abort, fire onerror on the original IDBOpenDBRequest.
+        https://bugs.webkit.org/show_bug.cgi?id=151648
+
+        Reviewed by Andy Estes.
+
+        * platform/mac-wk1/TestExpectations:
+        * storage/indexeddb/modern/abort-requests-cancelled-expected.txt:
+        * storage/indexeddb/modern/abort-requests-cancelled.html:
+        * storage/indexeddb/modern/aborted-put-expected.txt:
+        * storage/indexeddb/modern/aborted-put.html:
+        * storage/indexeddb/modern/createobjectstore-basic-expected.txt:
+        * storage/indexeddb/modern/createobjectstore-basic.html:
+        * storage/indexeddb/modern/deleteindex-2-expected.txt:
+        * storage/indexeddb/modern/deleteindex-2.html:
+        * storage/indexeddb/modern/deleteobjectstore-1-expected.txt:
+        * storage/indexeddb/modern/deleteobjectstore-1.html:
+        * storage/indexeddb/modern/idbdatabase-transaction-failures-expected.txt:
+        * storage/indexeddb/modern/versionchange-abort-then-reopen-expected.txt:
+        * storage/indexeddb/modern/versionchange-abort-then-reopen.html:
+
 2015-11-30  Chris Dumez  <cdumez@apple.com>
 
         location.origin is undefined in a web worker
index d70fe76..529445b 100644 (file)
@@ -71,6 +71,7 @@ crypto/subtle/rsa-indexeddb-non-exportable.html
 inspector/indexeddb
 
 # But Modern IndexedDB is.
+storage/indexeddb/aborted-versionchange-closes.html [ Pass ]
 storage/indexeddb/modern [ Pass ]
 storage/indexeddb/mozilla/add-twice-failure.html [ Pass ]
 storage/indexeddb/mozilla/autoincrement-indexes.html [ Pass ]
index 89c0c77..bb01f2b 100644 (file)
@@ -4,6 +4,7 @@ Error handling: "objectStore.put({ bar: 'A' }, 1);" (error)
 Error handling: "objectStore.put({ bar: 'B' }, 2);" (error)
 Error handling: "objectStore.put({ bar: 'C' }, 3);" (error)
 Initial upgrade versionchange transaction aborted
+Initial upgrade versionchange transaction error [object Event]
 Second upgrade needed: Old version - 0 New version - 1
 Success handling: "objectStore.put({ bar: 'A' }, 1);"
 Success handling: "objectStore.put({ bar: 'B' }, 2);"
index e153b68..d70d977 100644 (file)
@@ -64,8 +64,7 @@ function startTest() {
         }
 
         versionTransaction.onerror = function(event) {
-            log("Initial upgrade versionchange transaction unexpected error" + event);
-            done();
+            log("Initial upgrade versionchange transaction error " + event);
         }
     }
 }
index dd46037..9dad078 100644 (file)
@@ -11,6 +11,7 @@ ALERT: [object IDBDatabase]
 ALERT: get1 'foo' succeeded - value was 'baz'
 ALERT: get2 'far' succeeded - value was 'boo'
 ALERT: Second version change transaction abort
+ALERT: Second version change transaction error - [object Event]
 ALERT: Third upgrade needed: Old version - 1 New version - 2
 ALERT: [object IDBTransaction] - versionchange
 ALERT: [object IDBDatabase]
index e9ce129..89f8e56 100644 (file)
@@ -142,8 +142,7 @@ function continueTest1()
         }
 
         tx.onerror = function(event) {
-            alert("Second version change transaction unexpected error - " + event);
-            done();
+            alert("Second version change transaction error - " + event);
         }
     }
 }
index 39cfd05..f15a2ec 100644 (file)
@@ -4,6 +4,7 @@ ALERT: FirstAbortedObjectStore
 ALERT: Put succeeded
 ALERT: Initial upgrade versionchange transaction aborted
 ALERT: Object store names:
+ALERT: Initial upgrade versionchange transaction error [object Event]
 ALERT: Second upgrade needed: Old version - 0 New version - 1
 ALERT: Object store names:
 ALERT: Second upgrade versionchange transaction complete
index 2104f99..10ef1b9 100644 (file)
@@ -56,8 +56,7 @@ createRequest.onupgradeneeded = function(event) {
     }
 
     versionTransaction.onerror = function(event) {
-        alert("Initial upgrade versionchange transaction unexpected error" + event);
-        done();
+        alert("Initial upgrade versionchange transaction error " + event);
     }
 }
 
index 4c7e83d..a2c4e13 100644 (file)
@@ -8,6 +8,7 @@ Second upgrade needed: Old version - 1 New version - 2
 Deleted the index
 Aborted the transaction
 Second upgrade versionchange transaction abort
+Second upgrade versionchange transaction error [object Event]
 Third upgrade needed: Old version - 1 New version - 3
 Count is: 2
 Cursor at record: A / 1
index 54420e3..eddfaff 100644 (file)
@@ -102,8 +102,7 @@ function continueTest1() {
         }
 
         versionTransaction.onerror = function(event) {
-            log("Second upgrade versionchange transaction unexpected error" + event);
-            done();
+            log("Second upgrade versionchange transaction error " + event);
         }
     }
 }
index debb2bb..88bc9d4 100644 (file)
@@ -3,6 +3,8 @@ ALERT: Initial upgrade versionchange transaction complete
 ALERT: Second upgrade needed: Old version - 1 New version - 2
 ALERT: Deleting object store
 ALERT: Second version change transaction abort
+ALERT: Request error - [object Event]
+ALERT: Second version change transaction error - [object Event]
 ALERT: Success opening database connection - Starting final transaction
 ALERT: Value gotten was AH AH AH AH AH
 ALERT: Value gotten was AH AH AH AH AH
index f0b3b97..8f35485 100644 (file)
@@ -52,8 +52,7 @@ function continueTest1()
     var openRequest = window.indexedDB.open("DeleteObjectStore1Database", 2);
 
     openRequest.onerror = function(event) {
-        alert("Request unexpected error - " + event);
-        done();
+        alert("Request error - " + event);
     }
     openRequest.onblocked = function(event) {
         alert("Request unexpected blocked - " + event);
@@ -87,8 +86,7 @@ function continueTest1()
         }
 
         versionTransaction.onerror = function(event) {
-            alert("Second version change transaction unexpected error - " + event);
-            done();
+            alert("Second version change transaction error - " + event);
         }
     }
 }
index 2cede3a..35b9095 100644 (file)
@@ -1,10 +1,10 @@
 ALERT: Upgrade needed: Old version - 0 New version - 1
-ALERT: Failed to start a transaction while a versionChange transaction was in progress - Error: InvalidStateError: DOM Exception 11
+ALERT: Failed to start a transaction while a versionChange transaction was in progress - Error: InvalidStateError: DOM IDBDatabase Exception 11
 ALERT: versionchange transaction completed
-ALERT: Failed to start a transaction with an empty set of object stores - Error: InvalidAccessError: DOM Exception 15
-ALERT: Failed to start a transaction to a nonexistent object store - Error: NotFoundError: DOM Exception 8
+ALERT: Failed to start a transaction with an empty set of object stores - Error: InvalidAccessError: DOM IDBDatabase Exception 15
+ALERT: Failed to start a transaction to a nonexistent object store - Error: NotFoundError: DOM IDBDatabase Exception 8
 ALERT: Failed to start a transaction with an invalid mode - TypeError: Type error
 ALERT: Failed to explicitly start a versionchange transaction - TypeError: Type error
-ALERT: Failed to explicitly start a transaction with the close pending flag set - Error: InvalidStateError: DOM Exception 11
+ALERT: Failed to explicitly start a transaction with the close pending flag set - Error: InvalidStateError: DOM IDBDatabase Exception 11
 ALERT: Done
 This tests some obvious failures that can happen while calling IDBDatabase.transaction()
index fa69783..71ab9f0 100644 (file)
@@ -1,9 +1,11 @@
 ALERT: Initial upgrade needed: Old version - 0 New version - 1
 ALERT: Initial upgrade versionchange transaction aborted
+ALERT: Initial upgrade versionchange transaction error [object Event]
 ALERT: Second upgrade needed: Old version - 0 New version - 1
 ALERT: Second upgrade versionchange transaction complete
 ALERT: Third upgrade needed: Old version - 1 New version - 2
 ALERT: Third upgrade versionchange transaction aborted
+ALERT: Third upgrade versionchange transaction error[object Event]
 ALERT: Fourth upgrade needed: Old version - 1 New version - 2
 ALERT: Done
 This test opens a new database, then aborts the version change transaction.
index b07f7e8..5e5b3dd 100644 (file)
@@ -38,8 +38,7 @@ createRequest.onupgradeneeded = function(event) {
     }
 
     versionTransaction.onerror = function(event) {
-        alert("Initial upgrade versionchange transaction unexpected error" + event);
-        done();
+        alert("Initial upgrade versionchange transaction error " + event);
     }
 }
 
@@ -95,8 +94,7 @@ function continueTest2()
         }
 
         versionTransaction.onerror = function(event) {
-            alert("Third upgrade versionchange transaction unexpected error" + event);
-            done();
+            alert("Third upgrade versionchange transaction error" + event);
         }
     }
 }
index 770a1df..57827f3 100644 (file)
@@ -1,3 +1,28 @@
+2015-11-30  Brady Eidson  <beidson@apple.com>
+
+        Modern IDB: After versionchange transactions abort, fire onerror on the original IDBOpenDBRequest.
+        https://bugs.webkit.org/show_bug.cgi?id=151648
+
+        Reviewed by Andy Estes.
+
+        No new tests. Covered by at least one existing failing test which now passes, and many
+        other tests updated to fix their incorrect behavior.
+
+        * Modules/indexeddb/client/IDBDatabaseImpl.cpp:
+        (WebCore::IDBClient::IDBDatabase::transaction):
+        (WebCore::IDBClient::IDBDatabase::willAbortTransaction):
+        (WebCore::IDBClient::IDBDatabase::didAbortTransaction):
+        
+        * Modules/indexeddb/client/IDBOpenDBRequestImpl.cpp:
+        (WebCore::IDBClient::IDBOpenDBRequest::fireErrorAfterVersionChangeAbort):
+        * Modules/indexeddb/client/IDBOpenDBRequestImpl.h:
+        
+        * Modules/indexeddb/client/IDBTransactionImpl.cpp:
+        (WebCore::IDBClient::IDBTransaction::notifyDidAbort):
+        (WebCore::IDBClient::IDBTransaction::didAbort):
+        (WebCore::IDBClient::IDBTransaction::didCommit):
+        * Modules/indexeddb/client/IDBTransactionImpl.h:
+
 2015-11-30  Chris Dumez  <cdumez@apple.com>
 
         location.origin is undefined in a web worker
index 89d43e9..7f0500d 100644 (file)
@@ -138,12 +138,12 @@ RefPtr<WebCore::IDBTransaction> IDBDatabase::transaction(ScriptExecutionContext*
     LOG(IndexedDB, "IDBDatabase::transaction");
 
     if (m_closePending) {
-        ec = INVALID_STATE_ERR;
+        ec = IDBDatabaseException::InvalidStateError;
         return nullptr;
     }
 
     if (objectStores.isEmpty()) {
-        ec = INVALID_ACCESS_ERR;
+        ec = IDBDatabaseException::InvalidAccessError;
         return nullptr;
     }
 
@@ -157,14 +157,14 @@ RefPtr<WebCore::IDBTransaction> IDBDatabase::transaction(ScriptExecutionContext*
     }
 
     if (m_versionChangeTransaction && !m_versionChangeTransaction->isFinishedOrFinishing()) {
-        ec = INVALID_STATE_ERR;
+        ec = IDBDatabaseException::InvalidStateError;
         return nullptr;
     }
 
     for (auto& objectStoreName : objectStores) {
         if (m_info.hasObjectStore(objectStoreName))
             continue;
-        ec = NOT_FOUND_ERR;
+        ec = IDBDatabaseException::NotFoundError;
         return nullptr;
     }
 
@@ -294,6 +294,9 @@ void IDBDatabase::willAbortTransaction(IDBTransaction& transaction)
     auto refTransaction = m_activeTransactions.take(transaction.info().identifier());
     ASSERT(refTransaction);
     m_abortingTransactions.set(transaction.info().identifier(), WTF::move(refTransaction));
+
+    if (transaction.isVersionChange())
+        m_closePending = true;
 }
 
 void IDBDatabase::didAbortTransaction(IDBTransaction& transaction)
@@ -303,6 +306,9 @@ void IDBDatabase::didAbortTransaction(IDBTransaction& transaction)
     if (transaction.isVersionChange()) {
         ASSERT(transaction.originalDatabaseInfo());
         m_info = *transaction.originalDatabaseInfo();
+        m_closePending = true;
+        m_closedInServer = true;
+        m_serverConnection->databaseConnectionClosed(*this);
     }
 
     didCommitOrAbortTransaction(transaction);
index a09cb26..b1e144d 100644 (file)
@@ -79,6 +79,19 @@ void IDBOpenDBRequest::fireSuccessAfterVersionChangeCommit()
     enqueueEvent(Event::create(eventNames().successEvent, false, false));
 }
 
+void IDBOpenDBRequest::fireErrorAfterVersionChangeAbort()
+{
+    LOG(IndexedDB, "IDBOpenDBRequest::fireErrorAfterVersionChangeAbort()");
+
+    ASSERT(hasPendingActivity());
+
+    IDBError idbError(IDBExceptionCode::AbortError);
+    m_domError = DOMError::create(idbError.name());
+
+    m_transaction->addRequest(*this);
+    enqueueEvent(Event::create(eventNames().errorEvent, true, true));
+}
+
 void IDBOpenDBRequest::onSuccess(const IDBResultData& resultData)
 {
     LOG(IndexedDB, "IDBOpenDBRequest::onSuccess()");
index 83a176a..57cef21 100644 (file)
@@ -52,6 +52,7 @@ public:
 
     void requestCompleted(const IDBResultData&);
     void fireSuccessAfterVersionChangeCommit();
+    void fireErrorAfterVersionChangeAbort();
 
 private:
     IDBOpenDBRequest(IDBConnectionToServer&, ScriptExecutionContext*, const IDBDatabaseIdentifier&, uint64_t version);
index e4085df..f57c8e3 100644 (file)
@@ -321,6 +321,18 @@ void IDBTransaction::didStart(const IDBError& error)
     scheduleOperationTimer();
 }
 
+void IDBTransaction::notifyDidAbort(const IDBError& error)
+{
+    m_database->didAbortTransaction(*this);
+    m_idbError = error;
+    fireOnAbort();
+
+    if (isVersionChange()) {
+        ASSERT(m_openDBRequest);
+        m_openDBRequest->fireErrorAfterVersionChangeAbort();
+    }
+}
+
 void IDBTransaction::didAbort(const IDBError& error)
 {
     LOG(IndexedDB, "IDBTransaction::didAbort");
@@ -328,10 +340,7 @@ void IDBTransaction::didAbort(const IDBError& error)
     if (m_state == IndexedDB::TransactionState::Finished)
         return;
 
-    m_database->didAbortTransaction(*this);
-
-    m_idbError = error;
-    fireOnAbort();
+    notifyDidAbort(error);
 
     finishAbortOrCommit();
 }
@@ -345,11 +354,8 @@ void IDBTransaction::didCommit(const IDBError& error)
     if (error.isNull()) {
         m_database->didCommitTransaction(*this);
         fireOnComplete();
-    } else {
-        m_database->didAbortTransaction(*this);
-        m_idbError = error;
-        fireOnAbort();
-    }
+    } else
+        notifyDidAbort(error);
 
     finishAbortOrCommit();
 }
index 142447b..b5374f3 100644 (file)
@@ -130,6 +130,7 @@ private:
 
     void commit();
 
+    void notifyDidAbort(const IDBError&);
     void finishAbortOrCommit();
 
     void scheduleOperation(RefPtr<TransactionOperation>&&);