blob: 7427536f7befc7a183c1342610fa8ee762cbd7f9 [file] [log] [blame]
Test IndexedDB IDBDatabase internal closePending flag
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')
First, verify that the database connection is not closed:
PASS transaction = connection.transaction('store') did not throw exception.
Database closing steps
"1. Set the internal closePending flag of connection to true."
connection.close()
Expecting exception from 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.
"2. Wait for all transactions created using connection to complete. Once they are complete, connection is closed."
transaction.oncomplete = testIDBDatabaseName
IDBDatabase.name:
"The function must return this name even if the closePending flag is set on the connection."
PASS connection.name is dbname
IDBDatabase.objectStoreNames:
"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."
request = indexedDB.open(dbname, 2)
version_change_connection = request.result
version_change_connection.createObjectStore('new_store')
PASS version_change_connection.objectStoreNames.contains('new_store') is true
PASS connection.objectStoreNames.contains('new_store') is false
version_change_connection.close()
IDBDatabase.transaction():
"...if this method is called on a IDBDatabase instance where the closePending flag is set, a InvalidStateError exception must be thrown."
Expecting exception from 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.
"versionchange" transaction steps:
"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."
request = indexedDB.open(dbname)
connection = request.result
versionChangeWasFired = false
connection.onversionchange = function () { versionChangeWasFired = true; }
transaction = connection.transaction('store')
connection.close()
closePending is set, but active transaction will keep connection from closing
request = indexedDB.open(dbname, 3)
'blocked' event fired, letting transaction complete and connection close
version_change_connection = request.result
PASS versionChangeWasFired is false
version_change_connection.close()
Database deletion steps:
"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."
request = indexedDB.open(dbname)
connection = request.result
versionChangeWasFired = false
connection.onversionchange = function () { versionChangeWasFired = true; }
transaction = connection.transaction('store')
connection.close()
closePending is set, but active transaction will keep connection from closing
request = indexedDB.deleteDatabase(dbname)
'blocked' event fired, letting transaction complete and connection close
PASS versionChangeWasFired is false
PASS successfullyParsed is true
TEST COMPLETE