78 lines
3.1 KiB
Plaintext
78 lines
3.1 KiB
Plaintext
Test IndexedDB keyPath edge cases
|
|
|
|
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)
|
|
db.createObjectStore('store-with-path', {keyPath: 'foo'})
|
|
db.createObjectStore('store-with-path-and-generator', {keyPath: 'foo', autoIncrement: true})
|
|
|
|
testKeyPaths():
|
|
transaction = db.transaction(['store-with-path'], 'readwrite')
|
|
store = transaction.objectStore('store-with-path')
|
|
|
|
Key path doesn't resolve to a value; should yield null, should throw DATA_ERR
|
|
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: Evaluating the object store's key path did not yield a value.
|
|
|
|
Key path doesn't resolve to a value; should yield null, should throw DATA_ERR
|
|
Expecting exception from store.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.
|
|
|
|
Key path resolves to a value that is invalid key; should yield 'invalid' key, should throw DATA_ERR
|
|
Expecting exception from store.put({foo: 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.
|
|
|
|
Key path resolves to a value that is valid key; should yield 'string' key, should succeed
|
|
store.put({foo: 'zoo'})
|
|
PASS store.put succeeded
|
|
|
|
testKeyPathsAndGenerator():
|
|
transaction = db.transaction(['store-with-path-and-generator'], 'readwrite')
|
|
store = transaction.objectStore('store-with-path-and-generator')
|
|
|
|
Key path doesn't resolve to a value; should yield null but insertion would fail, so put request should raise exception
|
|
Expecting exception from store.put(null)
|
|
PASS Exception was thrown.
|
|
PASS code is 0
|
|
PASS ename is 'DataError'
|
|
Exception message: Provided data is inadequate.
|
|
|
|
Key path doesn't resolve to a value; should yield null but insertion would fail, so put request should raise exception
|
|
Expecting exception from store.put('string')
|
|
PASS Exception was thrown.
|
|
PASS code is 0
|
|
PASS ename is 'DataError'
|
|
Exception message: Provided data is inadequate.
|
|
|
|
Key path doesn't resolve to a value; should yield null, key should be generated, put request should succeed
|
|
store.put({})
|
|
PASS store.put succeeded
|
|
|
|
Key path resolves to a value that is invalid key; should yield 'invalid' key, should throw DATA_ERR
|
|
Expecting exception from store.put({foo: 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.
|
|
|
|
Key path resolves to a value that is valid key; should yield 'string' key, should succeed
|
|
store.put({foo: 'zoo'})
|
|
PASS store.put succeeded
|
|
PASS successfullyParsed is true
|
|
|
|
TEST COMPLETE
|
|
|