blob: 060466b509b5327db7898625056101b9c810ab8f [file] [log] [blame]
Verify edge cases that lazy index population in an IndexedDB implementation might reveal.
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)
Deleted all object stores.
store = connection.createObjectStore('store')
store.createIndex('index1', 'name', {unique: true})
Verify that uniqueness constraints are enforced with a pre-existing index:
trans = connection.transaction('store', 'readwrite')
store = trans.objectStore('store')
request1 = store.put({name: 'bob'}, 1)
request2 = store.put({name: 'bob'}, 2)
state = 0
request1 received success event
PASS ++state is 1
request2 received error event
PASS ++state is 2
transaction aborted
PASS ++state is 3
PASS trans.error.name is 'ConstraintError'
Verify that uniqueness constraints are enforced when index is created before puts:
connection.close()
indexedDB.open(dbname, 2)
deleteAllObjectStores(connection)
Deleted all object stores.
store = connection.createObjectStore('store')
store.createIndex('index2', 'name', {unique: true})
request1 = store.put({name: 'carol'}, 1)
request2 = store.put({name: 'carol'}, 2)
state = 0
request1 (index2) received success event
PASS ++state is 1
request2 (index2) received error event
PASS ++state is 2
transaction aborted
PASS ++state is 3
PASS trans.error.name is 'ConstraintError'
Verify that uniqueness constraints are enforced when index is created after puts:
indexedDB.open(dbname, 3)
deleteAllObjectStores(connection)
Deleted all object stores.
store = connection.createObjectStore('store')
request1 = store.put({name: 'ted'}, 1)
request2 = store.put({name: 'ted'}, 2)
store.createIndex('index3', 'name', {unique: true})
state = 0
request1 received success event
PASS ++state is 1
request2 received success event
PASS ++state is 2
transaction aborted
PASS ++state is 3
PASS trans.error.name is 'ConstraintError'
Verify that uniqueness constraints are enforced when index is created between puts:
indexedDB.open(dbname, 4)
deleteAllObjectStores(connection)
Deleted all object stores.
store = connection.createObjectStore('store')
request1 = store.put({name: 'alice'}, 1)
store.createIndex('index4', 'name', {unique: true})
request2 = store.put({name: 'alice'}, 2)
state = 0
request1 received success event
PASS ++state is 1
request2 received error event
PASS ++state is 2
transaction aborted
PASS ++state is 3
PASS trans.error.name is 'ConstraintError'
PASS successfullyParsed is true
TEST COMPLETE