1 Test IndexedDB 'steps for closing a database connection'
3 On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
6 dbname = "database-close.html"
7 indexedDB.deleteDatabase(dbname)
9 store = connection.createObjectStore('store')
10 store.put('value1', 'key1')
11 store.put('value2', 'key2')
14 Create transactions using connection:
15 trans1 = connection.transaction('store')
16 trans2 = connection.transaction('store')
20 Step 1: Set the internal closePending flag of connection to true. [Verified via side effects, below.]
22 Step 2: Wait for all transactions created using connection to complete. Once they are complete, connection is closed.
23 awaiting_transaction_count = 2
24 trans1.objectStore('store').get('key1')
25 trans2.objectStore('store').get('key2')
27 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.
29 Expecting exception from trans3 = connection.transaction('store')
30 PASS Exception was thrown.
31 PASS code is DOMException.INVALID_STATE_ERR
32 PASS ename is 'InvalidStateError'
33 Exception message: Failed to execute 'transaction' on 'IDBDatabase': The database connection is closing.
35 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.
37 indexedDB.deleteDatabase(dbname)
39 transaction #1 request successful
40 PASS event.target.result is "value1"
42 transaction #2 request successful
43 PASS event.target.result is "value2"
45 All transactions completed - database deletes should now be unblocked.
47 delete database unblocked
48 PASS awaiting_transaction_count is 0
49 PASS successfullyParsed is true