blob: bce78dd04fa8b6780c6d2cd62836d41ab931953c [file] [log] [blame]
Test IndexedDB's key generator behavior.
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;
Verify that each object store has an independent key generator.
indexedDB = self.indexedDB || self.webkitIndexedDB || self.mozIndexedDB || self.msIndexedDB || self.OIndexedDB;
indexedDB.deleteDatabase(dbname)
indexedDB.open(dbname)
store1 = db.createObjectStore('store1', { autoIncrement: true })
store1.put('a')
request = store.get(1)
store2 = db.createObjectStore('store2', { autoIncrement: true })
store2.put('a')
request = store.get(1)
store1.put('b')
request = store.get(2)
store2.put('b')
request = store.get(2)
PASS Got "a" for key: 1
PASS Got "a" for key: 1
PASS Got "b" for key: 2
PASS Got "b" for key: 2
db.close()
Verify that the key generator is not updated if insertion fails
indexedDB = self.indexedDB || self.webkitIndexedDB || self.mozIndexedDB || self.msIndexedDB || self.OIndexedDB;
indexedDB.deleteDatabase(dbname)
indexedDB.open(dbname)
store = db.createObjectStore('store1', { autoIncrement: true })
index = store.createIndex('index1', 'ix', { unique: true })
store.put({ ix: 'a'})
request = store.get(1)
store.put({ ix: 'a'})
store.put({ ix: 'b'})
request = store.get(2)
PASS Got {"ix":"a"} for key: 1
PASS Got {"ix":"b"} for key: 2
db.close()
Verify that the key generator is not affected by item removal (delete or clear).
indexedDB = self.indexedDB || self.webkitIndexedDB || self.mozIndexedDB || self.msIndexedDB || self.OIndexedDB;
indexedDB.deleteDatabase(dbname)
indexedDB.open(dbname)
store = db.createObjectStore('store1', { autoIncrement: true })
store.put('a')
request = store.get(1)
store.delete(1)
store.put('b')
request = store.get(2)
store.clear()
store.put('c')
request = store.get(3)
store.delete(IDBKeyRange.lowerBound(0))
store.put('d')
request = store.get(4)
PASS Got "a" for key: 1
PASS Got "b" for key: 2
PASS Got "c" for key: 3
PASS Got "d" for key: 4
db.close()
Verify that the key generator is only set if and only if a numeric key greater than the last generated key is used.
indexedDB = self.indexedDB || self.webkitIndexedDB || self.mozIndexedDB || self.msIndexedDB || self.OIndexedDB;
indexedDB.deleteDatabase(dbname)
indexedDB.open(dbname)
store = db.createObjectStore('store1', { autoIncrement: true })
store.put('a')
request = store.get(1)
store.put('b', 3)
request = store.get(3)
store.put('c')
request = store.get(4)
store.put('d', -10)
request = store.get(-10)
store.put('e')
request = store.get(5)
store.put('f', 6.00001)
request = store.get(6.00001)
store.put('g')
request = store.get(7)
store.put('f', 8.9999)
request = store.get(8.9999)
store.put('g')
request = store.get(9)
store.put('h', 'foo')
request = store.get("foo")
store.put('i')
request = store.get(10)
store.put('j', [1000])
request = store.get([1000])
store.put('k')
request = store.get(11)
PASS Got "a" for key: 1
PASS Got "b" for key: 3
PASS Got "c" for key: 4
PASS Got "d" for key: -10
PASS Got "e" for key: 5
PASS Got "f" for key: 6.00001
PASS Got "g" for key: 7
PASS Got "f" for key: 8.9999
PASS Got "g" for key: 9
PASS Got "h" for key: "foo"
PASS Got "i" for key: 10
PASS Got "j" for key: [1000]
PASS Got "k" for key: 11
db.close()
Verify that aborting a transaction resets the key generator state.
indexedDB = self.indexedDB || self.webkitIndexedDB || self.mozIndexedDB || self.msIndexedDB || self.OIndexedDB;
indexedDB.deleteDatabase(dbname)
indexedDB.open(dbname)
trans1 = db.transaction(['store'], 'readwrite')
store_t1 = trans1.objectStore('store')
store_t1.put('a')
request = store.get(1)
store_t1.put('b')
request = store.get(2)
PASS Got "a" for key: 1
PASS Got "b" for key: 2
aborting...
trans1.abort()
aborted!
trans2 = db.transaction(['store'], 'readwrite')
store_t2 = trans2.objectStore('store')
store_t2.put('c')
request = store.get(1)
store_t2.put('d')
request = store.get(2)
PASS Got "c" for key: 1
PASS Got "d" for key: 2
db.close()
Verify that keys above 2^53 result in errors.
indexedDB = self.indexedDB || self.webkitIndexedDB || self.mozIndexedDB || self.msIndexedDB || self.OIndexedDB;
indexedDB.deleteDatabase(dbname)
indexedDB.open(dbname)
trans1 = db.transaction(['store'], 'readwrite')
store_t1 = trans1.objectStore('store')
store_t1.put('a')
request = store.get(1)
store_t1.put('b', 9007199254740992)
request = store.get(9007199254740992)
store_t1.put('c')
store_t1.put('d', 2)
request = store.get(2)
PASS Got "a" for key: 1
PASS Got "b" for key: 9007199254740992
Error event fired auto-incrementing past 2^53 (as expected)
PASS event.target.error.name is 'ConstraintError'
event.preventDefault()
PASS Got "d" for key: 2
db.close()
Ensure key generator state is maintained across connections:
indexedDB = self.indexedDB || self.webkitIndexedDB || self.mozIndexedDB || self.msIndexedDB || self.OIndexedDB;
indexedDB.deleteDatabase(dbname)
indexedDB.open(dbname)
db.createObjectStore('store', {autoIncrement: true})
trans = db.transaction('store', 'readwrite')
request = trans.objectStore('store').put('value1')
PASS request.result is 1
trans.objectStore('store').clear()
db.close()
request = indexedDB.open(dbname)
db = request.result
trans = db.transaction('store', 'readwrite')
request = trans.objectStore('store').put('value2')
PASS request.result is 2
PASS successfullyParsed is true
TEST COMPLETE