Test IndexedDB's transaction and objectStore calls

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;

dbname = "transaction-and-objectstore-calls.html"
indexedDB.deleteDatabase(dbname)
indexedDB.open(dbname)
db.createObjectStore('a')
db.createObjectStore('b')
db.createObjectStore('store').createIndex('index', 'some_path')

trans = db.transaction(['a'])
trans.objectStore('a')
Expecting exception from trans.objectStore('b')
PASS Exception was thrown.
PASS code is DOMException.NOT_FOUND_ERR
PASS ename is 'NotFoundError'
Expecting exception from trans.objectStore('x')
PASS Exception was thrown.
PASS code is DOMException.NOT_FOUND_ERR
PASS ename is 'NotFoundError'

trans = db.transaction(['a'])
trans.objectStore('a')
Expecting exception from trans.objectStore('b')
PASS Exception was thrown.
PASS code is DOMException.NOT_FOUND_ERR
PASS ename is 'NotFoundError'
Expecting exception from trans.objectStore('x')
PASS Exception was thrown.
PASS code is DOMException.NOT_FOUND_ERR
PASS ename is 'NotFoundError'

trans = db.transaction(['b'])
trans.objectStore('b')
Expecting exception from trans.objectStore('a')
PASS Exception was thrown.
PASS code is DOMException.NOT_FOUND_ERR
PASS ename is 'NotFoundError'
Expecting exception from trans.objectStore('x')
PASS Exception was thrown.
PASS code is DOMException.NOT_FOUND_ERR
PASS ename is 'NotFoundError'

trans = db.transaction(['a', 'b'])
trans.objectStore('a')
trans.objectStore('b')
Expecting exception from trans.objectStore('x')
PASS Exception was thrown.
PASS code is DOMException.NOT_FOUND_ERR
PASS ename is 'NotFoundError'

trans = db.transaction(['b', 'a'])
trans.objectStore('a')
trans.objectStore('b')
Expecting exception from trans.objectStore('x')
PASS Exception was thrown.
PASS code is DOMException.NOT_FOUND_ERR
PASS ename is 'NotFoundError'

Passing a string as the first argument is a shortcut for just one object store:
trans = db.transaction('a')
trans.objectStore('a')
Expecting exception from trans.objectStore('b')
PASS Exception was thrown.
PASS code is DOMException.NOT_FOUND_ERR
PASS ename is 'NotFoundError'
Expecting exception from trans.objectStore('x')
PASS Exception was thrown.
PASS code is DOMException.NOT_FOUND_ERR
PASS ename is 'NotFoundError'

PASS trans = db.transaction() threw exception TypeError: Not enough arguments.

Expecting exception from db.transaction(['x'])
PASS Exception was thrown.
PASS code is DOMException.NOT_FOUND_ERR
PASS ename is 'NotFoundError'
Expecting exception from db.transaction(['x'])
PASS Exception was thrown.
PASS code is DOMException.NOT_FOUND_ERR
PASS ename is 'NotFoundError'
Expecting exception from db.transaction(['a', 'x'])
PASS Exception was thrown.
PASS code is DOMException.NOT_FOUND_ERR
PASS ename is 'NotFoundError'
Expecting exception from db.transaction(['x', 'x'])
PASS Exception was thrown.
PASS code is DOMException.NOT_FOUND_ERR
PASS ename is 'NotFoundError'
Expecting exception from db.transaction(['a', 'x', 'b'])
PASS Exception was thrown.
PASS code is DOMException.NOT_FOUND_ERR
PASS ename is 'NotFoundError'

Exception thrown when no stores specified:
Expecting exception from db.transaction([])
PASS Exception was thrown.
PASS code is DOMException.INVALID_ACCESS_ERR

{} coerces to a string - so no match, but not a type error:
Expecting exception from db.transaction({})
PASS Exception was thrown.
PASS code is DOMException.NOT_FOUND_ERR
PASS ename is 'NotFoundError'
Expecting exception from db.transaction({mode:0})
PASS Exception was thrown.
PASS code is DOMException.NOT_FOUND_ERR
PASS ename is 'NotFoundError'

Overriding the default string coercion makes these work:
db.transaction({toString:function(){return 'a';}})
db.transaction([{toString:function(){return 'a';}}])
... but you still need to specify a real store:
Expecting exception from db.transaction([{toString:function(){return 'x';}}])
PASS Exception was thrown.
PASS code is DOMException.NOT_FOUND_ERR
PASS ename is 'NotFoundError'
Expecting exception from db.transaction([{toString:function(){return 'x';}}])
PASS Exception was thrown.
PASS code is DOMException.NOT_FOUND_ERR
PASS ename is 'NotFoundError'

trans = db.transaction(['store'])
PASS trans is non-null.
store = trans.objectStore('store')
PASS store is non-null.
store.get('some_key')
transaction complete, ensuring methods fail
PASS trans is non-null.
PASS store is non-null.
Expecting exception from trans.objectStore('store')
PASS Exception was thrown.
PASS code is DOMException.INVALID_STATE_ERR
PASS ename is 'InvalidStateError'
Expecting exception from store.index('index')
PASS Exception was thrown.
PASS code is DOMException.INVALID_STATE_ERR
PASS ename is 'InvalidStateError'
PASS successfullyParsed is true

TEST COMPLETE

