Test the basics of IndexedDB's IDBObjectStore.

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.open('objectstore-basics')
openSuccess():
db = event.target.result
db.setVersion('new version')
setVersionSuccess():
trans = event.target.result
PASS trans is non-null.
Deleted all object stores.
createObjectStore():
store = db.createObjectStore('storeName', null)
storeNames = db.objectStoreNames
PASS 'name' in store is true
PASS 'keyPath' in store is true
PASS 'indexNames' in store is true
PASS 'transaction' in store is true
PASS 'autoIncrement' in store is true
PASS 'put' in store is true
PASS typeof store.put is "function"
PASS 'add' in store is true
PASS typeof store.add is "function"
PASS 'delete' in store is true
PASS typeof store.delete is "function"
PASS 'get' in store is true
PASS typeof store.get is "function"
PASS 'clear' in store is true
PASS typeof store.clear is "function"
PASS 'openCursor' in store is true
PASS typeof store.openCursor is "function"
PASS 'createIndex' in store is true
PASS typeof store.createIndex is "function"
PASS 'index' in store is true
PASS typeof store.index is "function"
PASS 'deleteIndex' in store is true
PASS typeof store.deleteIndex is "function"
PASS 'count' in store is true
PASS typeof store.count is "function"
PASS store.name is "storeName"
PASS store.keyPath is null
PASS store.autoIncrement is false
PASS storeNames.contains('storeName') is true
PASS storeNames.length is 1
PASS db.createObjectStore('storeWithKeyPath', {keyPath: 'path'}).keyPath is "path"
PASS db.createObjectStore('storeWithKeyGenerator', {autoIncrement: true}).autoIncrement is true
Ask for an index that doesn't exist:
Expecting exception from store.index('asdf')
PASS Exception was thrown.
PASS code is DOMException.NOT_FOUND_ERR
PASS ename is 'NotFoundError'
createIndex():
index = store.createIndex('indexName', 'x', {unique: true})
PASS index is non-null.
PASS store.indexNames.contains('indexName') is true
index = store.index('indexName')
PASS index is non-null.
Ask for an index that doesn't exist:
Expecting exception from store.index('asdf')
PASS Exception was thrown.
PASS code is DOMException.NOT_FOUND_ERR
PASS ename is 'NotFoundError'
db.setVersion("version fail")
PASS db.version is "version fail"
setVersionTrans = event.target.result
PASS setVersionTrans is non-null.
store = setVersionTrans.objectStore('storeName')
index = store.createIndex('indexFail', 'x')
PASS db.version is "new version"
PASS store.transaction is setVersionTrans
PASS store.indexNames is ['indexName']
PASS store.indexNames.length is 1
PASS store.indexNames.contains('') is false
PASS store.indexNames.contains('indexFail') is false
PASS store.indexNames.contains('indexName') is true
PASS store.indexNames[0] is "indexName"
PASS store.indexNames[1] is null
PASS store.indexNames[100] is null
PASS store.indexNames.item(1) is null
PASS store.indexNames.item(100) is null
transaction = db.transaction(['storeName'], 'readwrite')
store = transaction.objectStore('storeName')
Try to insert data with a Date key:
store.add({x: 'foo'}, testDate)
Try to insert a value not handled by structured clone:
Expecting exception from store.add({x: 'bar', y: self}, 'bar')
PASS Exception was thrown.
PASS code is DOMException.DATA_CLONE_ERR
Try to insert data where key path yields a Date key:
store.add({x: testDateB, y: 'value'}, 'key')
addSuccess():
PASS event.target.result is "key"
event.target.source.add({x: 'foo'}, 'zzz')
addAgainFailure():
PASS event.target.errorCode is IDBDatabaseException.DATA_ERR
PASS event.target.error.name is 'DataError'
event.preventDefault()
db.transaction(['storeName'], 'readwrite')
store = transaction.objectStore('storeName')
store.add({x: 'somevalue'}, 'somekey')
Expecting exception from store.add({x: 'othervalue'}, null)
PASS Exception was thrown.
PASS code is IDBDatabaseException.DATA_ERR
PASS ename is 'DataError'
db.transaction(['storeName'], 'readwrite')
store = transaction.objectStore('storeName')
Ensure invalid key pointed at by index keyPath is ignored
store.add({x: null}, 'validkey')
db.transaction(['storeName'], 'readwrite')
store = transaction.objectStore('storeName')
store.get('key')
getSuccess():
PASS event.target.result.y is "value"
store = event.target.source
store.get(testDate)
getSuccessDateKey():
PASS event.target.result.x is "foo"
store.delete('key')
removeSuccess():
PASS event.target.result is undefined
store.delete('key')
removeSuccessButNotThere():
PASS event.target.result is undefined
store = event.target.source
Passing an invalid key into store.get().
Expecting exception from store.get({})
PASS Exception was thrown.
PASS code is IDBDatabaseException.DATA_ERR
PASS ename is 'DataError'
Passing an invalid key into store.delete().
Expecting exception from store.delete({})
PASS Exception was thrown.
PASS code is IDBDatabaseException.DATA_ERR
PASS ename is 'DataError'
Passing an invalid key into store.add().
Expecting exception from store.add(null, {})
PASS Exception was thrown.
PASS code is IDBDatabaseException.DATA_ERR
PASS ename is 'DataError'
Passing an invalid key into store.put().
Expecting exception from store.put(null, {})
PASS Exception was thrown.
PASS code is IDBDatabaseException.DATA_ERR
PASS ename is 'DataError'

testPreConditions():
db.setVersion('precondition version')
storeWithInLineKeys = db.createObjectStore('storeWithInLineKeys', {keyPath: 'key'})
storeWithOutOfLineKeys = db.createObjectStore('storeWithOutIOfLineKeys')
storeWithIndex = db.createObjectStore('storeWithIndex')
index = storeWithIndex.createIndex('indexName', 'indexKey')

IDBObjectStore.put()
The object store uses in-line keys and the key parameter was provided.
Expecting exception from storeWithInLineKeys.put({key: 1}, 'key')
PASS Exception was thrown.
PASS code is IDBDatabaseException.DATA_ERR
PASS ename is 'DataError'
The object store uses out-of-line keys and has no key generator and the key parameter was not provided.
Expecting exception from storeWithOutOfLineKeys.put({})
PASS Exception was thrown.
PASS code is IDBDatabaseException.DATA_ERR
PASS ename is 'DataError'
The object store uses in-line keys and the result of evaluating the object store's key path yields a value and that value is not a valid key.
Expecting exception from storeWithInLineKeys.put({key: null})
PASS Exception was thrown.
PASS code is IDBDatabaseException.DATA_ERR
PASS ename is 'DataError'
The object store uses in-line keys but no key generator and the result of evaluating the object store's key path does not yield a value.
Expecting exception from storeWithInLineKeys.put({})
PASS Exception was thrown.
PASS code is IDBDatabaseException.DATA_ERR
PASS ename is 'DataError'
The key parameter was provided but does not contain a valid key.
Expecting exception from storeWithOutOfLineKeys.put({}, null)
PASS Exception was thrown.
PASS code is IDBDatabaseException.DATA_ERR
PASS ename is 'DataError'

IDBObjectStore.add()
The object store uses in-line keys and the key parameter was provided.
Expecting exception from storeWithInLineKeys.add({key: 1}, 'key')
PASS Exception was thrown.
PASS code is IDBDatabaseException.DATA_ERR
PASS ename is 'DataError'
The object store uses out-of-line keys and has no key generator and the key parameter was not provided.
Expecting exception from storeWithOutOfLineKeys.add({})
PASS Exception was thrown.
PASS code is IDBDatabaseException.DATA_ERR
PASS ename is 'DataError'
The object store uses in-line keys and the result of evaluating the object store's key path yields a value and that value is not a valid key.
Expecting exception from storeWithInLineKeys.add({key: null})
PASS Exception was thrown.
PASS code is IDBDatabaseException.DATA_ERR
PASS ename is 'DataError'
The object store uses in-line keys but no key generator and the result of evaluating the object store's key path does not yield a value.
Expecting exception from storeWithInLineKeys.add({})
PASS Exception was thrown.
PASS code is IDBDatabaseException.DATA_ERR
The key parameter was provided but does not contain a valid key.
Expecting exception from storeWithOutOfLineKeys.add({}, null)
PASS Exception was thrown.
PASS code is IDBDatabaseException.DATA_ERR
PASS successfullyParsed is true

TEST COMPLETE

