blob: e8c1c2ddbf009dd0f379a72c710352d01ac5e686 [file] [log] [blame]
Test IndexedDB 'steps for closing a database connection'
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
indexedDB = self.indexedDB || self.webkitIndexedDB || self.mozIndexedDB || self.msIndexedDB || self.OIndexedDB;
indexedDB.deleteDatabase(dbname)
indexedDB.open(dbname)
store = connection.createObjectStore('store')
store.put('value1', 'key1')
store.put('value2', 'key2')
testClose():
Create transactions using connection:
trans1 = connection.transaction('store')
trans2 = connection.transaction('store')
Close the connection:
connection.close()
Step 1: Set the internal closePending flag of connection to true. [Verified via side effects, below.]
Step 2: Wait for all transactions created using connection to complete. Once they are complete, connection is closed.
awaiting_transaction_count = 2
trans1.objectStore('store').get('key1')
trans2.objectStore('store').get('key2')
NOTE: Once the closePending flag has been set to true no new transactions can be created using connection. All functions that create transactions first check the closePending flag first and throw an exception if it is true.
Expecting exception from trans3 = connection.transaction('store')
PASS Exception was thrown.
PASS code is DOMException.INVALID_STATE_ERR
PASS ename is 'InvalidStateError'
Exception message: Failed to execute 'transaction' on 'IDBDatabase': The database connection is closing.
NOTE: Once the connection is closed, this can unblock the steps for deleting a database, which waits for connections to a given database to be closed before continuing.
indexedDB.deleteDatabase(dbname)
transaction #1 request successful
PASS event.target.result is "value1"
transaction #2 request successful
PASS event.target.result is "value2"
All transactions completed - database deletes should now be unblocked.
delete database unblocked
PASS awaiting_transaction_count is 0
PASS successfullyParsed is true
TEST COMPLETE