1 Test features of IndexedDB's multiEntry indices.
3 On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
6 dbname = "index-multientry.html"
7 indexedDB.deleteDatabase(dbname)
9 store = db.createObjectStore('store')
10 store.createIndex('index', 'x', {multiEntry: true})
11 store2 = db.createObjectStore('store-unique')
12 store2.createIndex('index-unique', 'x', {multiEntry: true, unique: true})
14 Populating stores (and indexes)
15 transaction = db.transaction(['store'], 'readwrite')
16 First try some keys that aren't what we're expecting
17 transaction.objectStore('store').put({x: [7, 8, 9], y: 'a'}, 'foo')
18 Now overwrite them with what we're expecting
19 transaction.objectStore('store').put({x: [1, 2, 3], y: 'a'}, 'foo')
20 transaction.objectStore('store').put({x: [4, 5, 6], y: 'b'}, 'bar')
21 transaction.objectStore('store').put({x: [7, 7, 8, 7], y: 'c'}, 'baz')
22 transaction.objectStore('store').put({x: [null, 9, 9], y: 'd'}, 'bloop')
24 Verifying index: index
25 transaction = db.transaction(['store'], 'readonly')
26 transaction.objectStore('store').index('index').openCursor()
27 cursor = event.target.result
30 PASS cursor.primaryKey is "foo"
31 PASS cursor.value.y is "a"
33 cursor = event.target.result
36 PASS cursor.primaryKey is "foo"
37 PASS cursor.value.y is "a"
39 cursor = event.target.result
42 PASS cursor.primaryKey is "foo"
43 PASS cursor.value.y is "a"
45 cursor = event.target.result
48 PASS cursor.primaryKey is "bar"
49 PASS cursor.value.y is "b"
51 cursor = event.target.result
54 PASS cursor.primaryKey is "bar"
55 PASS cursor.value.y is "b"
57 cursor = event.target.result
60 PASS cursor.primaryKey is "bar"
61 PASS cursor.value.y is "b"
63 cursor = event.target.result
66 PASS cursor.primaryKey is "baz"
67 PASS cursor.value.y is "c"
69 cursor = event.target.result
72 PASS cursor.primaryKey is "baz"
73 PASS cursor.value.y is "c"
75 cursor = event.target.result
78 PASS cursor.primaryKey is "bloop"
79 PASS cursor.value.y is "d"
81 cursor = event.target.result
82 PASS expected.length is 0
83 transaction = db.transaction(['store'])
84 transaction.objectStore('store').index('index')
86 PASS event.target.result is 9
88 PASS event.target.result is 1
90 Verifying unique constraint on multiEntry index
91 transaction = db.transaction(['store-unique'], 'readwrite')
92 transaction.objectStore('store-unique').put({x: [1, 2, 3], y: 'a'}, 'foo')
94 Replace an existing record - this should work
95 transaction.objectStore('store-unique').put({x: [1, 2, 7], y: 'a'}, 'foo')
97 This should fail the uniqueness constraint on the index, and fail:
98 transaction.objectStore('store-unique').put({x: [5, 2], y: 'c'}, 'should fail')
99 PASS request.result is undefined.
100 PASS request.error is non-null.
101 Request failed, as expected (ConstraintError)
102 Transaction aborted as expected
104 Create an index on a populated store
106 indexedDB.open(dbname, 2)
107 db = event.target.result
108 trans = event.target.transaction
109 store = trans.objectStore('store')
110 store.createIndex('index-new', 'x', {multiEntry: true})
112 Verifying index: index-new
113 transaction = db.transaction(['store'], 'readonly')
114 transaction.objectStore('store').index('index-new').openCursor()
115 cursor = event.target.result
118 PASS cursor.primaryKey is "foo"
119 PASS cursor.value.y is "a"
121 cursor = event.target.result
124 PASS cursor.primaryKey is "foo"
125 PASS cursor.value.y is "a"
127 cursor = event.target.result
130 PASS cursor.primaryKey is "foo"
131 PASS cursor.value.y is "a"
133 cursor = event.target.result
136 PASS cursor.primaryKey is "bar"
137 PASS cursor.value.y is "b"
139 cursor = event.target.result
142 PASS cursor.primaryKey is "bar"
143 PASS cursor.value.y is "b"
145 cursor = event.target.result
148 PASS cursor.primaryKey is "bar"
149 PASS cursor.value.y is "b"
151 cursor = event.target.result
154 PASS cursor.primaryKey is "baz"
155 PASS cursor.value.y is "c"
157 cursor = event.target.result
160 PASS cursor.primaryKey is "baz"
161 PASS cursor.value.y is "c"
163 cursor = event.target.result
166 PASS cursor.primaryKey is "bloop"
167 PASS cursor.value.y is "d"
169 cursor = event.target.result
170 PASS expected.length is 0
171 transaction = db.transaction(['store'])
172 transaction.objectStore('store').index('index')
174 PASS event.target.result is 9
176 PASS event.target.result is 1
177 PASS successfullyParsed is true