1 Verify edge cases that lazy index population in an IndexedDB implementation might reveal.
3 On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
6 dbname = "lazy-index-population.html"
7 indexedDB.deleteDatabase(dbname)
9 Deleted all object stores.
10 store = connection.createObjectStore('store')
11 store.createIndex('index1', 'name', {unique: true})
12 Verify that uniqueness constraints are enforced with a pre-existing index:
13 trans = connection.transaction('store', 'readwrite')
14 store = trans.objectStore('store')
15 request1 = store.put({name: 'bob'}, 1)
16 request2 = store.put({name: 'bob'}, 2)
18 request1 received success event
20 request2 received error event
24 PASS trans.error.name is 'ConstraintError'
26 Verify that uniqueness constraints are enforced when index is created before puts:
28 indexedDB.open(dbname, 2)
29 deleteAllObjectStores(connection)
30 Deleted all object stores.
31 store = connection.createObjectStore('store')
32 store.createIndex('index2', 'name', {unique: true})
33 request1 = store.put({name: 'carol'}, 1)
34 request2 = store.put({name: 'carol'}, 2)
36 request1 (index2) received success event
38 request2 (index2) received error event
42 PASS trans.error.name is 'ConstraintError'
44 Verify that uniqueness constraints are enforced when index is created after puts:
45 indexedDB.open(dbname, 3)
46 deleteAllObjectStores(connection)
47 Deleted all object stores.
48 store = connection.createObjectStore('store')
49 request1 = store.put({name: 'ted'}, 1)
50 request2 = store.put({name: 'ted'}, 2)
51 store.createIndex('index3', 'name', {unique: true})
53 request1 received success event
55 request2 received success event
59 PASS trans.error.name is 'ConstraintError'
61 Verify that uniqueness constraints are enforced when index is created between puts:
62 indexedDB.open(dbname, 4)
63 deleteAllObjectStores(connection)
64 Deleted all object stores.
65 store = connection.createObjectStore('store')
66 request1 = store.put({name: 'alice'}, 1)
67 store.createIndex('index4', 'name', {unique: true})
68 request2 = store.put({name: 'alice'}, 2)
70 request1 received success event
72 request2 received error event
76 PASS trans.error.name is 'ConstraintError'
77 PASS successfullyParsed is true