1 Test IndexedDB IDBDatabase internal closePending flag
3 On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
6 dbname = "database-closepending-flag.html"
7 indexedDB.deleteDatabase(dbname)
9 store = connection.createObjectStore('store')
11 First, verify that the database connection is not closed:
12 PASS transaction = connection.transaction('store') did not throw exception.
14 Database closing steps
15 "1. Set the internal closePending flag of connection to true."
17 Expecting exception from connection.transaction('store')
18 PASS Exception was thrown.
19 PASS code is DOMException.INVALID_STATE_ERR
20 PASS ename is 'InvalidStateError'
21 Exception message: Failed to execute 'transaction' on 'IDBDatabase': The database connection is closing.
22 "2. Wait for all transactions created using connection to complete. Once they are complete, connection is closed."
23 transaction.oncomplete = testIDBDatabaseName
26 "The function must return this name even if the closePending flag is set on the connection."
27 PASS connection.name is dbname
29 IDBDatabase.objectStoreNames:
30 "Once the closePending flag is set on the connection, this function must return a snapshot of the list of names of the object stores taken at the time when the close method was called."
31 request = indexedDB.open(dbname, 2)
32 version_change_connection = request.result
33 version_change_connection.createObjectStore('new_store')
34 PASS version_change_connection.objectStoreNames.contains('new_store') is true
35 PASS connection.objectStoreNames.contains('new_store') is false
36 version_change_connection.close()
38 IDBDatabase.transaction():
39 "...if this method is called on a IDBDatabase instance where the closePending flag is set, a InvalidStateError exception must be thrown."
40 Expecting exception from connection.transaction('store')
41 PASS Exception was thrown.
42 PASS code is DOMException.INVALID_STATE_ERR
43 PASS ename is 'InvalidStateError'
44 Exception message: Failed to execute 'transaction' on 'IDBDatabase': The database connection is closing.
46 "versionchange" transaction steps:
47 "Fire a versionchange event at each object in openDatabases that is open. The event must not be fired on objects which has the closePending flag set."
48 request = indexedDB.open(dbname)
49 connection = request.result
50 versionChangeWasFired = false
51 connection.onversionchange = function () { versionChangeWasFired = true; }
52 transaction = connection.transaction('store')
54 closePending is set, but active transaction will keep connection from closing
55 request = indexedDB.open(dbname, 3)
56 'blocked' event fired, letting transaction complete and connection close
57 version_change_connection = request.result
58 PASS versionChangeWasFired is false
59 version_change_connection.close()
61 Database deletion steps:
62 "Fire a versionchange event at each object in openDatabases that is open. The event must not be fired on objects which has the closePending flag set."
63 request = indexedDB.open(dbname)
64 connection = request.result
65 versionChangeWasFired = false
66 connection.onversionchange = function () { versionChangeWasFired = true; }
67 transaction = connection.transaction('store')
69 closePending is set, but active transaction will keep connection from closing
70 request = indexedDB.deleteDatabase(dbname)
71 'blocked' event fired, letting transaction complete and connection close
72 PASS versionChangeWasFired is false
73 PASS successfullyParsed is true