|
1 /** |
|
2 * Any copyright is dedicated to the Public Domain. |
|
3 * http://creativecommons.org/publicdomain/zero/1.0/ |
|
4 */ |
|
5 |
|
6 var testGenerator = testSteps(); |
|
7 |
|
8 function testSteps() |
|
9 { |
|
10 const name = this.window ? window.location.pathname : "Splendid Test"; |
|
11 |
|
12 let request = indexedDB.open(name, 1); |
|
13 request.onerror = errorHandler; |
|
14 request.onupgradeneeded = grabEventAndContinueHandler; |
|
15 let event = yield undefined; |
|
16 |
|
17 let db = event.target.result; |
|
18 db.addEventListener("error", function(event) { |
|
19 event.preventDefault(); |
|
20 }, false); |
|
21 |
|
22 let objectStore = db.createObjectStore("foo", { autoIncrement: true }); |
|
23 |
|
24 request = objectStore.add({}); |
|
25 request.onerror = errorHandler; |
|
26 request.onsuccess = grabEventAndContinueHandler; |
|
27 event = yield undefined; |
|
28 |
|
29 let key1 = event.target.result; |
|
30 |
|
31 request = objectStore.put({}, key1); |
|
32 request.onerror = errorHandler; |
|
33 request.onsuccess = grabEventAndContinueHandler; |
|
34 event = yield undefined; |
|
35 |
|
36 is(event.target.result, key1, "put gave the same key back"); |
|
37 |
|
38 let key2 = 10; |
|
39 |
|
40 request = objectStore.put({}, key2); |
|
41 request.onerror = errorHandler; |
|
42 request.onsuccess = grabEventAndContinueHandler; |
|
43 event = yield undefined; |
|
44 |
|
45 is(event.target.result, key2, "put gave the same key back"); |
|
46 |
|
47 key2 = 100; |
|
48 |
|
49 request = objectStore.add({}, key2); |
|
50 request.onerror = errorHandler; |
|
51 request.onsuccess = grabEventAndContinueHandler; |
|
52 event = yield undefined; |
|
53 |
|
54 is(event.target.result, key2, "put gave the same key back"); |
|
55 |
|
56 try { |
|
57 objectStore.put({}); |
|
58 ok(true, "put with no key should not throw with autoIncrement!"); |
|
59 } |
|
60 catch (e) { |
|
61 ok(false, "put with no key threw with autoIncrement"); |
|
62 } |
|
63 |
|
64 try { |
|
65 objectStore.put({}); |
|
66 ok(true, "put with no key should not throw with autoIncrement!"); |
|
67 } |
|
68 catch (e) { |
|
69 ok(false, "put with no key threw with autoIncrement"); |
|
70 } |
|
71 |
|
72 try { |
|
73 objectStore.delete(); |
|
74 ok(false, "remove with no key should throw!"); |
|
75 } |
|
76 catch (e) { |
|
77 ok(true, "remove with no key threw"); |
|
78 } |
|
79 |
|
80 objectStore = db.createObjectStore("bar"); |
|
81 |
|
82 try { |
|
83 objectStore.add({}); |
|
84 ok(false, "add with no key should throw!"); |
|
85 } |
|
86 catch (e) { |
|
87 ok(true, "add with no key threw"); |
|
88 } |
|
89 |
|
90 try { |
|
91 objectStore.put({}); |
|
92 ok(false, "put with no key should throw!"); |
|
93 } |
|
94 catch (e) { |
|
95 ok(true, "put with no key threw"); |
|
96 } |
|
97 |
|
98 try { |
|
99 objectStore.put({}); |
|
100 ok(false, "put with no key should throw!"); |
|
101 } |
|
102 catch (e) { |
|
103 ok(true, "put with no key threw"); |
|
104 } |
|
105 |
|
106 try { |
|
107 objectStore.delete(); |
|
108 ok(false, "remove with no key should throw!"); |
|
109 } |
|
110 catch (e) { |
|
111 ok(true, "remove with no key threw"); |
|
112 } |
|
113 |
|
114 objectStore = db.createObjectStore("baz", { keyPath: "id" }); |
|
115 |
|
116 try { |
|
117 objectStore.add({}); |
|
118 ok(false, "add with no key should throw!"); |
|
119 } |
|
120 catch (e) { |
|
121 ok(true, "add with no key threw"); |
|
122 } |
|
123 |
|
124 try { |
|
125 objectStore.add({id:5}, 5); |
|
126 ok(false, "add with inline key and passed key should throw!"); |
|
127 } |
|
128 catch (e) { |
|
129 ok(true, "add with inline key and passed key threw"); |
|
130 } |
|
131 |
|
132 try { |
|
133 objectStore.put({}); |
|
134 ok(false, "put with no key should throw!"); |
|
135 } |
|
136 catch (e) { |
|
137 ok(true, "put with no key threw"); |
|
138 } |
|
139 |
|
140 try { |
|
141 objectStore.put({}); |
|
142 ok(false, "put with no key should throw!"); |
|
143 } |
|
144 catch (e) { |
|
145 ok(true, "put with no key threw"); |
|
146 } |
|
147 |
|
148 try { |
|
149 objectStore.delete(); |
|
150 ok(false, "remove with no key should throw!"); |
|
151 } |
|
152 catch (e) { |
|
153 ok(true, "remove with no key threw"); |
|
154 } |
|
155 |
|
156 key1 = 10; |
|
157 |
|
158 request = objectStore.add({id:key1}); |
|
159 request.onerror = errorHandler; |
|
160 request.onsuccess = grabEventAndContinueHandler; |
|
161 event = yield undefined; |
|
162 |
|
163 is(event.target.result, key1, "add gave back the same key"); |
|
164 |
|
165 request = objectStore.put({id:10}); |
|
166 request.onerror = errorHandler; |
|
167 request.onsuccess = grabEventAndContinueHandler; |
|
168 event = yield undefined; |
|
169 |
|
170 is(event.target.result, key1, "put gave back the same key"); |
|
171 |
|
172 request = objectStore.put({id:10}); |
|
173 request.onerror = errorHandler; |
|
174 request.onsuccess = grabEventAndContinueHandler; |
|
175 event = yield undefined; |
|
176 |
|
177 is(event.target.result, key1, "put gave back the same key"); |
|
178 |
|
179 request = objectStore.add({id:10}); |
|
180 request.addEventListener("error", new ExpectError("ConstraintError", true)); |
|
181 request.onsuccess = unexpectedSuccessHandler; |
|
182 event = yield undefined; |
|
183 |
|
184 try { |
|
185 objectStore.add({}, null); |
|
186 ok(false, "add with null key should throw!"); |
|
187 } |
|
188 catch (e) { |
|
189 ok(true, "add with null key threw"); |
|
190 } |
|
191 |
|
192 try { |
|
193 objectStore.put({}, null); |
|
194 ok(false, "put with null key should throw!"); |
|
195 } |
|
196 catch (e) { |
|
197 ok(true, "put with null key threw"); |
|
198 } |
|
199 |
|
200 try { |
|
201 objectStore.put({}, null); |
|
202 ok(false, "put with null key should throw!"); |
|
203 } |
|
204 catch (e) { |
|
205 ok(true, "put with null key threw"); |
|
206 } |
|
207 |
|
208 try { |
|
209 objectStore.delete({}, null); |
|
210 ok(false, "remove with null key should throw!"); |
|
211 } |
|
212 catch (e) { |
|
213 ok(true, "remove with null key threw"); |
|
214 } |
|
215 |
|
216 objectStore = db.createObjectStore("bazing", { keyPath: "id", |
|
217 autoIncrement: true }); |
|
218 |
|
219 request = objectStore.add({}); |
|
220 request.onerror = errorHandler; |
|
221 request.onsuccess = grabEventAndContinueHandler; |
|
222 event = yield undefined; |
|
223 |
|
224 key1 = event.target.result; |
|
225 |
|
226 request = objectStore.put({id:key1}); |
|
227 request.onerror = errorHandler; |
|
228 request.onsuccess = grabEventAndContinueHandler; |
|
229 event = yield undefined; |
|
230 |
|
231 is(event.target.result, key1, "put gave the same key back"); |
|
232 |
|
233 key2 = 10; |
|
234 |
|
235 request = objectStore.put({id:key2}); |
|
236 request.onerror = errorHandler; |
|
237 request.onsuccess = grabEventAndContinueHandler; |
|
238 event = yield undefined; |
|
239 |
|
240 is(event.target.result, key2, "put gave the same key back"); |
|
241 |
|
242 try { |
|
243 objectStore.put({}); |
|
244 ok(true, "put with no key should not throw with autoIncrement!"); |
|
245 } |
|
246 catch (e) { |
|
247 ok(false, "put with no key threw with autoIncrement"); |
|
248 } |
|
249 |
|
250 try { |
|
251 objectStore.put({}); |
|
252 ok(true, "put with no key should not throw with autoIncrement!"); |
|
253 } |
|
254 catch (e) { |
|
255 ok(false, "put with no key threw with autoIncrement"); |
|
256 } |
|
257 |
|
258 try { |
|
259 objectStore.delete(); |
|
260 ok(false, "remove with no key should throw!"); |
|
261 } |
|
262 catch (e) { |
|
263 ok(true, "remove with no key threw"); |
|
264 } |
|
265 |
|
266 try { |
|
267 objectStore.add({id:5}, 5); |
|
268 ok(false, "add with inline key and passed key should throw!"); |
|
269 } |
|
270 catch (e) { |
|
271 ok(true, "add with inline key and passed key threw"); |
|
272 } |
|
273 |
|
274 request = objectStore.delete(key2); |
|
275 request.onerror = errorHandler; |
|
276 request.onsuccess = grabEventAndContinueHandler; |
|
277 event = yield undefined; |
|
278 |
|
279 finishTest(); |
|
280 yield undefined; |
|
281 } |