3 On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
4
5
6 indexedDB = self.indexedDB || self.webkitIndexedDB || self.mozIndexedDB || self.msIndexedDB || self.OIndexedDB;
7
8
9 Verify that each object store has an independent key generator.
10 indexedDB = self.indexedDB || self.webkitIndexedDB || self.mozIndexedDB || self.msIndexedDB || self.OIndexedDB;
11
12 indexedDB.deleteDatabase(dbname)
13 indexedDB.open(dbname)
14 store1 = db.createObjectStore('store1', { autoIncrement: true })
15 store1.put('a')
16 request = store.get(1)
17 store2 = db.createObjectStore('store2', { autoIncrement: true })
18 store2.put('a')
19 request = store.get(1)
20 store1.put('b')
21 request = store.get(2)
22 store2.put('b')
23 request = store.get(2)
24 PASS Got "a" for key: 1
25 PASS Got "a" for key: 1
26 PASS Got "b" for key: 2
27 PASS Got "b" for key: 2
28 db.close()
29
30 Verify that the key generator is not updated if insertion fails
31 indexedDB = self.indexedDB || self.webkitIndexedDB || self.mozIndexedDB || self.msIndexedDB || self.OIndexedDB;
32
33 indexedDB.deleteDatabase(dbname)
34 indexedDB.open(dbname)
35 store = db.createObjectStore('store1', { autoIncrement: true })
36 index = store.createIndex('index1', 'ix', { unique: true })
37 store.put({ ix: 'a'})
38 request = store.get(1)
39 store.put({ ix: 'a'})
40 store.put({ ix: 'b'})
41 request = store.get(2)
42 PASS Got {"ix":"a"} for key: 1
43 PASS Got {"ix":"b"} for key: 2
44 db.close()
45
46 Verify that the key generator is not affected by item removal (delete or clear).
47 indexedDB = self.indexedDB || self.webkitIndexedDB || self.mozIndexedDB || self.msIndexedDB || self.OIndexedDB;
48
49 indexedDB.deleteDatabase(dbname)
50 indexedDB.open(dbname)
51 store = db.createObjectStore('store1', { autoIncrement: true })
52 store.put('a')
53 request = store.get(1)
54 store.delete(1)
55 store.put('b')
56 request = store.get(2)
57 store.clear()
58 store.put('c')
59 request = store.get(3)
60 store.delete(IDBKeyRange.lowerBound(0))
61 store.put('d')
62 request = store.get(4)
63 PASS Got "a" for key: 1
64 PASS Got "b" for key: 2
65 PASS Got "c" for key: 3
66 PASS Got "d" for key: 4
67 db.close()
68
69 Verify that the key generator is only set if and only if a numeric key greater than the last generated key is used.
70 indexedDB = self.indexedDB || self.webkitIndexedDB || self.mozIndexedDB || self.msIndexedDB || self.OIndexedDB;
71
72 indexedDB.deleteDatabase(dbname)
73 indexedDB.open(dbname)
74 store = db.createObjectStore('store1', { autoIncrement: true })
75 store.put('a')
76 request = store.get(1)
77 store.put('b', 3)
78 request = store.get(3)
79 store.put('c')
80 request = store.get(4)
81 store.put('d', -10)
82 request = store.get(-10)
83 store.put('e')
84 request = store.get(5)
85 store.put('f', 6.00001)
86 request = store.get(6.00001)
87 store.put('g')
88 request = store.get(7)
89 store.put('f', 8.9999)
90 request = store.get(8.9999)
91 store.put('g')
92 request = store.get(9)
93 store.put('h', 'foo')
94 request = store.get("foo")
95 store.put('i')
96 request = store.get(10)
97 store.put('j', [1000])
98 request = store.get([1000])
99 store.put('k')
100 request = store.get(11)
101 PASS Got "a" for key: 1
102 PASS Got "b" for key: 3
103 PASS Got "c" for key: 4
104 PASS Got "d" for key: -10
105 PASS Got "e" for key: 5
106 PASS Got "f" for key: 6.00001
107 PASS Got "g" for key: 7
108 PASS Got "f" for key: 8.9999
109 PASS Got "g" for key: 9
110 PASS Got "h" for key: "foo"
111 PASS Got "i" for key: 10
112 PASS Got "j" for key: [1000]
113 PASS Got "k" for key: 11
114 db.close()
115
116 Verify that aborting a transaction resets the key generator state.
117 indexedDB = self.indexedDB || self.webkitIndexedDB || self.mozIndexedDB || self.msIndexedDB || self.OIndexedDB;
118
119 indexedDB.deleteDatabase(dbname)
120 indexedDB.open(dbname)
121 trans1 = db.transaction(['store'], 'readwrite')
122 store_t1 = trans1.objectStore('store')
123 store_t1.put('a')
124 request = store.get(1)
125 store_t1.put('b')
126 request = store.get(2)
127 PASS Got "a" for key: 1
128 PASS Got "b" for key: 2
129 aborting...
130 trans1.abort()
131 aborted!
132 trans2 = db.transaction(['store'], 'readwrite')
133 store_t2 = trans2.objectStore('store')
134 store_t2.put('c')
135 request = store.get(1)
136 store_t2.put('d')
137 request = store.get(2)
138 PASS Got "c" for key: 1
139 PASS Got "d" for key: 2
140 db.close()
141
142 Verify that keys above 2^53 result in errors.
143 indexedDB = self.indexedDB || self.webkitIndexedDB || self.mozIndexedDB || self.msIndexedDB || self.OIndexedDB;
144
145 indexedDB.deleteDatabase(dbname)
146 indexedDB.open(dbname)
147 trans1 = db.transaction(['store'], 'readwrite')
148 store_t1 = trans1.objectStore('store')
149 store_t1.put('a')
150 request = store.get(1)
151 store_t1.put('b', 9007199254740992)
152 request = store.get(9007199254740992)
153 store_t1.put('c')
154 store_t1.put('d', 2)
155 request = store.get(2)
156 PASS Got "a" for key: 1
157 PASS Got "b" for key: 9007199254740992
158 Error event fired auto-incrementing past 2^53 (as expected)
159 PASS event.target.error.name is 'ConstraintError'
160 event.preventDefault()
161 PASS Got "d" for key: 2
162 db.close()
163
164 Ensure key generator state is maintained across connections:
165 indexedDB = self.indexedDB || self.webkitIndexedDB || self.mozIndexedDB || self.msIndexedDB || self.OIndexedDB;
166
167 indexedDB.deleteDatabase(dbname)
168 indexedDB.open(dbname)
169 db.createObjectStore('store', {autoIncrement: true})
170
171 trans = db.transaction('store', 'readwrite')
172 request = trans.objectStore('store').put('value1')
173 PASS request.result is 1
174 trans.objectStore('store').clear()
175 db.close()
176
177 request = indexedDB.open(dbname)
178 db = request.result
179 trans = db.transaction('store', 'readwrite')
180 request = trans.objectStore('store').put('value2')
181 PASS request.result is 2
182
183 PASS successfullyParsed is true
184
185 TEST COMPLETE
186