235 lines
9.7 KiB
Plaintext
235 lines
9.7 KiB
Plaintext
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.deleteDatabase(dbname)
|
|
indexedDB.open(dbname)
|
|
|
|
prepareDatabase():
|
|
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'
|
|
Exception message: Failed to execute 'index' on 'IDBObjectStore': The specified index was not found.
|
|
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'
|
|
Exception message: Failed to execute 'index' on 'IDBObjectStore': The specified index was not found.
|
|
indexedDB.open(dbname, 2)
|
|
db.close()
|
|
PASS db.version is 2
|
|
setVersionTrans = event.target.transaction
|
|
PASS setVersionTrans is non-null.
|
|
store = setVersionTrans.objectStore('storeName')
|
|
index = store.createIndex('indexFail', 'x')
|
|
PASS db.version is 1
|
|
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 undefined.
|
|
PASS store.indexNames[100] is undefined.
|
|
PASS store.indexNames.item(1) is null
|
|
PASS store.indexNames.item(100) is null
|
|
|
|
openAgain():
|
|
indexedDB.open(dbname)
|
|
|
|
addData():
|
|
db = event.target.result
|
|
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
|
|
Exception message: The object can not be cloned.
|
|
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.error.name is 'ConstraintError'
|
|
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 0
|
|
PASS ename is 'DataError'
|
|
Exception message: Failed to store record in an IDBObjectStore: The parameter is not a valid key.
|
|
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 0
|
|
PASS ename is 'DataError'
|
|
Exception message: Failed to execute 'get' on 'IDBObjectStore': The parameter is not a valid key.
|
|
Passing an invalid key into store.delete().
|
|
Expecting exception from store.delete({})
|
|
PASS Exception was thrown.
|
|
PASS code is 0
|
|
PASS ename is 'DataError'
|
|
Exception message: Failed to execute 'delete' on 'IDBObjectStore': The parameter is not a valid key.
|
|
Passing an invalid key into store.add().
|
|
Expecting exception from store.add(null, {})
|
|
PASS Exception was thrown.
|
|
PASS code is 0
|
|
PASS ename is 'DataError'
|
|
Exception message: Failed to store record in an IDBObjectStore: The parameter is not a valid key.
|
|
Passing an invalid key into store.put().
|
|
Expecting exception from store.put(null, {})
|
|
PASS Exception was thrown.
|
|
PASS code is 0
|
|
PASS ename is 'DataError'
|
|
Exception message: Failed to store record in an IDBObjectStore: The parameter is not a valid key.
|
|
|
|
testPreConditions():
|
|
indexedDB.open(dbname, 3)
|
|
|
|
upgradeNeeded():
|
|
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 0
|
|
PASS ename is 'DataError'
|
|
Exception message: Failed to store record in an IDBObjectStore: The object store uses in-line keys and the key parameter was provided.
|
|
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 0
|
|
PASS ename is 'DataError'
|
|
Exception message: Failed to store record in an IDBObjectStore: The object store uses out-of-line keys and has no key generator and the key parameter was not provided.
|
|
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 0
|
|
PASS ename is 'DataError'
|
|
Exception message: Failed to store record in an IDBObjectStore: Evaluating the object store's key path yielded a value that is not a valid key.
|
|
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 0
|
|
PASS ename is 'DataError'
|
|
Exception message: Failed to store record in an IDBObjectStore: Evaluating the object store's key path did not yield a value.
|
|
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 0
|
|
PASS ename is 'DataError'
|
|
Exception message: Failed to store record in an IDBObjectStore: The parameter is not a valid key.
|
|
|
|
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 0
|
|
PASS ename is 'DataError'
|
|
Exception message: Failed to store record in an IDBObjectStore: The object store uses in-line keys and the key parameter was provided.
|
|
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 0
|
|
PASS ename is 'DataError'
|
|
Exception message: Failed to store record in an IDBObjectStore: The object store uses out-of-line keys and has no key generator and the key parameter was not provided.
|
|
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 0
|
|
PASS ename is 'DataError'
|
|
Exception message: Failed to store record in an IDBObjectStore: Evaluating the object store's key path yielded a value that is not a valid key.
|
|
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 0
|
|
PASS ename is 'DataError'
|
|
Exception message: Failed to store record in an IDBObjectStore: Evaluating the object store's key path did not yield a value.
|
|
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 0
|
|
PASS ename is 'DataError'
|
|
Exception message: Failed to store record in an IDBObjectStore: The parameter is not a valid key.
|
|
PASS successfullyParsed is true
|
|
|
|
TEST COMPLETE
|
|
|