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.open('lazy-index-population')
connection = request.result

Verify that uniqueness constraints are enforced with a pre-existing index:
connection.setVersion('1')
Deleted all object stores.
store = connection.createObjectStore('store')
store.createIndex('index1', 'name', {unique: true})
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

Verify that uniqueness constraints are enforced when index is created before puts:
connection.setVersion('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

Verify that uniqueness constraints are enforced when index is created after puts:
connection.setVersion('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

Verify that uniqueness constraints are enforced when index is created between puts:
connection.setVersion('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 successfullyParsed is true

TEST COMPLETE

