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;
PASS Boolean(indexedDB && IDBCursor && IDBDatabase && IDBDatabaseError && IDBDatabaseException && IDBFactory && IDBIndex && IDBKeyRange && IDBObjectStore && IDBRequest && IDBTransaction) is true

indexedDB.open('objectstore-basics')
openSuccess():
db = event.target.result
db.setVersion('new version')
setVersionSuccess():
trans = event.target.result
PASS trans !== null is true
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 '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 storeNames.contains('storeName') is true
PASS storeNames.length is 1
Ask for an index that doesn't exist:
index = store.index('asdf')
PASS Exception thrown.
PASS code is IDBDatabaseException.NOT_FOUND_ERR
createIndex():
index = store.createIndex('indexName', 'x', {unique: true})
PASS index !== null is true
PASS store.indexNames.contains('indexName') is true
index = store.index('indexName')
PASS index !== null is true
Ask for an index that doesn't exist:
index = store.index('asdf')
PASS Exception thrown.
PASS code is IDBDatabaseException.NOT_FOUND_ERR
db.setVersion("version fail")
PASS db.version is "version fail"
setVersionTrans = event.target.result
PASS setVersionTrans !== null is true
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'], IDBTransaction.READ_WRITE)
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:
store.add({x: 'bar', y: self}, 'bar')
PASS Exception thrown
PASS code is 25
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.CONSTRAINT_ERR
event.preventDefault()
db.transaction(['storeName'], IDBTransaction.READ_WRITE)
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
db.transaction(['storeName'], IDBTransaction.READ_WRITE)
store = transaction.objectStore('storeName')
Expecting exception from store.add({x: null}, 'validkey')
PASS Exception was thrown.
PASS code is IDBDatabaseException.DATA_ERR
db.transaction(['storeName'], IDBTransaction.READ_WRITE)
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
Passing an invalid key into store.delete().
Expecting exception from store.delete({})
PASS Exception was thrown.
PASS code is IDBDatabaseException.DATA_ERR
Passing an invalid key into store.add().
Expecting exception from store.add(null, {})
PASS Exception was thrown.
PASS code is IDBDatabaseException.DATA_ERR
Passing an invalid key into store.put().
Expecting exception from store.put(null, {})
PASS Exception was thrown.
PASS code is IDBDatabaseException.DATA_ERR

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
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
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
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
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
If there are any indexes referencing this object store whose key path is a string, evaluating their key path on the value parameter yields a value, and that value is not a valid key.
Expecting exception from storeWithIndex.put({indexKey: null}, 'key')
PASS Exception was thrown.
PASS code is IDBDatabaseException.DATA_ERR

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
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
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
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
If there are any indexes referencing this object store whose key path is a string, evaluating their key path on the value parameter yields a value, and that value is not a valid key.
Expecting exception from storeWithIndex.add({indexKey: null}, 'key')
PASS Exception was thrown.
PASS code is IDBDatabaseException.DATA_ERR
PASS successfullyParsed is true

TEST COMPLETE

