|
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 osName = "people"; |
|
11 const indexName = "weight"; |
|
12 |
|
13 const data = [ |
|
14 { ssn: "237-23-7732", name: "Bob", height: 60, weight: 120 }, |
|
15 { ssn: "237-23-7733", name: "Ann", height: 52, weight: 110 }, |
|
16 { ssn: "237-23-7734", name: "Ron", height: 73, weight: 180 }, |
|
17 { ssn: "237-23-7735", name: "Sue", height: 58, weight: 130 }, |
|
18 { ssn: "237-23-7736", name: "Joe", height: 65, weight: 150 }, |
|
19 { ssn: "237-23-7737", name: "Pat", height: 65 }, |
|
20 { ssn: "237-23-7738", name: "Mel", height: 66, weight: {} }, |
|
21 { ssn: "237-23-7739", name: "Tom", height: 62, weight: 130 } |
|
22 ]; |
|
23 |
|
24 const weightSort = [1, 0, 3, 7, 4, 2]; |
|
25 |
|
26 let request = indexedDB.open(this.window ? window.location.pathname : "Splendid Test", 1); |
|
27 request.onerror = errorHandler; |
|
28 request.onupgradeneeded = grabEventAndContinueHandler; |
|
29 request.onsuccess = grabEventAndContinueHandler; |
|
30 let event = yield undefined; |
|
31 |
|
32 is(event.type, "upgradeneeded", "Got upgradeneeded event"); |
|
33 |
|
34 let db = event.target.result; |
|
35 db.onerror = errorHandler; |
|
36 |
|
37 let objectStore = db.createObjectStore(osName, { keyPath: "ssn" }); |
|
38 objectStore.createIndex(indexName, "weight", { unique: false }); |
|
39 |
|
40 for each (let i in data) { |
|
41 objectStore.add(i); |
|
42 } |
|
43 |
|
44 event = yield undefined; |
|
45 |
|
46 is(event.type, "success", "Got success event"); |
|
47 |
|
48 try { |
|
49 IDBKeyRange.bound(1, -1); |
|
50 ok(false, "Bound keyRange with backwards args should throw!"); |
|
51 } |
|
52 catch (e) { |
|
53 is(e.name, "DataError", "Threw correct exception"); |
|
54 is(e.code, 0, "Threw with correct code"); |
|
55 } |
|
56 |
|
57 try { |
|
58 IDBKeyRange.bound(1, 1); |
|
59 ok(true, "Bound keyRange with same arg should be ok"); |
|
60 } |
|
61 catch (e) { |
|
62 ok(false, "Bound keyRange with same arg should have been ok"); |
|
63 } |
|
64 |
|
65 try { |
|
66 IDBKeyRange.bound(1, 1, true); |
|
67 ok(false, "Bound keyRange with same arg and open should throw!"); |
|
68 } |
|
69 catch (e) { |
|
70 is(e.name, "DataError", "Threw correct exception"); |
|
71 is(e.code, 0, "Threw with correct code"); |
|
72 } |
|
73 |
|
74 try { |
|
75 IDBKeyRange.bound(1, 1, true, true); |
|
76 ok(false, "Bound keyRange with same arg and open should throw!"); |
|
77 } |
|
78 catch (e) { |
|
79 is(e.name, "DataError", "Threw correct exception"); |
|
80 is(e.code, 0, "Threw with correct code"); |
|
81 } |
|
82 |
|
83 objectStore = db.transaction(osName).objectStore(osName); |
|
84 |
|
85 try { |
|
86 objectStore.get(); |
|
87 ok(false, "Get with unspecified arg should have thrown"); |
|
88 } |
|
89 catch(e) { |
|
90 ok(true, "Get with unspecified arg should have thrown"); |
|
91 } |
|
92 |
|
93 try { |
|
94 objectStore.get(undefined); |
|
95 ok(false, "Get with undefined should have thrown"); |
|
96 } |
|
97 catch(e) { |
|
98 ok(true, "Get with undefined arg should have thrown"); |
|
99 } |
|
100 |
|
101 try { |
|
102 objectStore.get(null); |
|
103 ok(false, "Get with null should have thrown"); |
|
104 } |
|
105 catch(e) { |
|
106 is(e instanceof DOMException, true, |
|
107 "Got right kind of exception"); |
|
108 is(e.name, "DataError", "Correct error."); |
|
109 is(e.code, 0, "Correct code."); |
|
110 } |
|
111 |
|
112 objectStore.get(data[2].ssn).onsuccess = grabEventAndContinueHandler; |
|
113 event = yield undefined; |
|
114 |
|
115 is(event.target.result.name, data[2].name, "Correct data"); |
|
116 |
|
117 let keyRange = IDBKeyRange.only(data[2].ssn); |
|
118 |
|
119 objectStore.get(keyRange).onsuccess = grabEventAndContinueHandler; |
|
120 event = yield undefined; |
|
121 |
|
122 is(event.target.result.name, data[2].name, "Correct data"); |
|
123 |
|
124 keyRange = IDBKeyRange.lowerBound(data[2].ssn); |
|
125 |
|
126 objectStore.get(keyRange).onsuccess = grabEventAndContinueHandler; |
|
127 event = yield undefined; |
|
128 |
|
129 is(event.target.result.name, data[2].name, "Correct data"); |
|
130 |
|
131 keyRange = IDBKeyRange.lowerBound(data[2].ssn, true); |
|
132 |
|
133 objectStore.get(keyRange).onsuccess = grabEventAndContinueHandler; |
|
134 event = yield undefined; |
|
135 |
|
136 is(event.target.result.name, data[3].name, "Correct data"); |
|
137 |
|
138 keyRange = IDBKeyRange.upperBound(data[2].ssn); |
|
139 |
|
140 objectStore.get(keyRange).onsuccess = grabEventAndContinueHandler; |
|
141 event = yield undefined; |
|
142 |
|
143 is(event.target.result.name, data[0].name, "Correct data"); |
|
144 |
|
145 keyRange = IDBKeyRange.bound(data[2].ssn, data[4].ssn); |
|
146 |
|
147 objectStore.get(keyRange).onsuccess = grabEventAndContinueHandler; |
|
148 event = yield undefined; |
|
149 |
|
150 is(event.target.result.name, data[2].name, "Correct data"); |
|
151 |
|
152 keyRange = IDBKeyRange.bound(data[2].ssn, data[4].ssn, true); |
|
153 |
|
154 objectStore.get(keyRange).onsuccess = grabEventAndContinueHandler; |
|
155 event = yield undefined; |
|
156 |
|
157 is(event.target.result.name, data[3].name, "Correct data"); |
|
158 |
|
159 objectStore = db.transaction(osName, "readwrite") |
|
160 .objectStore(osName); |
|
161 |
|
162 try { |
|
163 objectStore.delete(); |
|
164 ok(false, "Delete with unspecified arg should have thrown"); |
|
165 } |
|
166 catch(e) { |
|
167 ok(true, "Delete with unspecified arg should have thrown"); |
|
168 } |
|
169 |
|
170 try { |
|
171 objectStore.delete(undefined); |
|
172 ok(false, "Delete with undefined should have thrown"); |
|
173 } |
|
174 catch(e) { |
|
175 ok(true, "Delete with undefined arg should have thrown"); |
|
176 } |
|
177 |
|
178 try { |
|
179 objectStore.delete(null); |
|
180 ok(false, "Delete with null should have thrown"); |
|
181 } |
|
182 catch(e) { |
|
183 is(e instanceof DOMException, true, |
|
184 "Got right kind of exception"); |
|
185 is(e.name, "DataError", "Correct error."); |
|
186 is(e.code, 0, "Correct code."); |
|
187 } |
|
188 |
|
189 objectStore.count().onsuccess = grabEventAndContinueHandler; |
|
190 event = yield undefined; |
|
191 |
|
192 is(event.target.result, data.length, "Correct count"); |
|
193 |
|
194 objectStore.delete(data[2].ssn).onsuccess = grabEventAndContinueHandler; |
|
195 event = yield undefined; |
|
196 |
|
197 ok(event.target.result === undefined, "Correct result"); |
|
198 |
|
199 objectStore.count().onsuccess = grabEventAndContinueHandler; |
|
200 event = yield undefined; |
|
201 |
|
202 is(event.target.result, data.length - 1, "Correct count"); |
|
203 |
|
204 keyRange = IDBKeyRange.bound(data[3].ssn, data[5].ssn); |
|
205 |
|
206 objectStore.delete(keyRange).onsuccess = grabEventAndContinueHandler; |
|
207 event = yield undefined; |
|
208 |
|
209 ok(event.target.result === undefined, "Correct result"); |
|
210 |
|
211 objectStore.count().onsuccess = grabEventAndContinueHandler; |
|
212 event = yield undefined; |
|
213 |
|
214 is(event.target.result, data.length - 4, "Correct count"); |
|
215 |
|
216 keyRange = IDBKeyRange.lowerBound(10); |
|
217 |
|
218 objectStore.delete(keyRange).onsuccess = grabEventAndContinueHandler; |
|
219 event = yield undefined; |
|
220 |
|
221 ok(event.target.result === undefined, "Correct result"); |
|
222 |
|
223 objectStore.count().onsuccess = grabEventAndContinueHandler; |
|
224 event = yield undefined; |
|
225 |
|
226 is(event.target.result, 0, "Correct count"); |
|
227 |
|
228 event.target.transaction.oncomplete = grabEventAndContinueHandler; |
|
229 |
|
230 for each (let i in data) { |
|
231 objectStore.add(i); |
|
232 } |
|
233 |
|
234 yield undefined; |
|
235 |
|
236 objectStore = db.transaction(osName).objectStore(osName); |
|
237 |
|
238 objectStore.count().onsuccess = grabEventAndContinueHandler; |
|
239 event = yield undefined; |
|
240 |
|
241 is(event.target.result, data.length, "Correct count"); |
|
242 |
|
243 let count = 0; |
|
244 |
|
245 objectStore.openCursor().onsuccess = function(event) { |
|
246 let cursor = event.target.result; |
|
247 if (cursor) { |
|
248 count++; |
|
249 cursor.continue(); |
|
250 } |
|
251 else { |
|
252 testGenerator.next(); |
|
253 } |
|
254 } |
|
255 yield undefined; |
|
256 |
|
257 is(count, data.length, "Correct count for no arg to openCursor"); |
|
258 |
|
259 count = 0; |
|
260 |
|
261 objectStore.openCursor(null).onsuccess = function(event) { |
|
262 let cursor = event.target.result; |
|
263 if (cursor) { |
|
264 count++; |
|
265 cursor.continue(); |
|
266 } |
|
267 else { |
|
268 testGenerator.next(); |
|
269 } |
|
270 } |
|
271 yield undefined; |
|
272 |
|
273 is(count, data.length, "Correct count for null arg to openCursor"); |
|
274 |
|
275 count = 0; |
|
276 |
|
277 objectStore.openCursor(undefined).onsuccess = function(event) { |
|
278 let cursor = event.target.result; |
|
279 if (cursor) { |
|
280 count++; |
|
281 cursor.continue(); |
|
282 } |
|
283 else { |
|
284 testGenerator.next(); |
|
285 } |
|
286 } |
|
287 yield undefined; |
|
288 |
|
289 is(count, data.length, "Correct count for undefined arg to openCursor"); |
|
290 |
|
291 count = 0; |
|
292 |
|
293 objectStore.openCursor(data[2].ssn).onsuccess = function(event) { |
|
294 let cursor = event.target.result; |
|
295 if (cursor) { |
|
296 count++; |
|
297 cursor.continue(); |
|
298 } |
|
299 else { |
|
300 testGenerator.next(); |
|
301 } |
|
302 } |
|
303 yield undefined; |
|
304 |
|
305 is(count, 1, "Correct count for single key arg to openCursor"); |
|
306 |
|
307 count = 0; |
|
308 |
|
309 objectStore.openCursor("foo").onsuccess = function(event) { |
|
310 let cursor = event.target.result; |
|
311 if (cursor) { |
|
312 count++; |
|
313 cursor.continue(); |
|
314 } |
|
315 else { |
|
316 testGenerator.next(); |
|
317 } |
|
318 } |
|
319 yield undefined; |
|
320 |
|
321 is(count, 0, |
|
322 "Correct count for non-existent single key arg to openCursor"); |
|
323 |
|
324 count = 0; |
|
325 keyRange = IDBKeyRange.only(data[2].ssn); |
|
326 |
|
327 objectStore.openCursor(keyRange).onsuccess = function(event) { |
|
328 let cursor = event.target.result; |
|
329 if (cursor) { |
|
330 count++; |
|
331 cursor.continue(); |
|
332 } |
|
333 else { |
|
334 testGenerator.next(); |
|
335 } |
|
336 } |
|
337 yield undefined; |
|
338 |
|
339 is(count, 1, "Correct count for only keyRange arg to openCursor"); |
|
340 |
|
341 count = 0; |
|
342 keyRange = IDBKeyRange.lowerBound(data[2].ssn); |
|
343 |
|
344 objectStore.openCursor(keyRange).onsuccess = function(event) { |
|
345 let cursor = event.target.result; |
|
346 if (cursor) { |
|
347 count++; |
|
348 cursor.continue(); |
|
349 } |
|
350 else { |
|
351 testGenerator.next(); |
|
352 } |
|
353 } |
|
354 yield undefined; |
|
355 |
|
356 is(count, data.length - 2, |
|
357 "Correct count for lowerBound arg to openCursor"); |
|
358 |
|
359 count = 0; |
|
360 keyRange = IDBKeyRange.lowerBound(data[2].ssn, true); |
|
361 |
|
362 objectStore.openCursor(keyRange).onsuccess = function(event) { |
|
363 let cursor = event.target.result; |
|
364 if (cursor) { |
|
365 count++; |
|
366 cursor.continue(); |
|
367 } |
|
368 else { |
|
369 testGenerator.next(); |
|
370 } |
|
371 } |
|
372 yield undefined; |
|
373 |
|
374 is(count, data.length - 3, |
|
375 "Correct count for lowerBound arg to openCursor"); |
|
376 |
|
377 count = 0; |
|
378 keyRange = IDBKeyRange.lowerBound("foo"); |
|
379 |
|
380 objectStore.openCursor(keyRange).onsuccess = function(event) { |
|
381 let cursor = event.target.result; |
|
382 if (cursor) { |
|
383 count++; |
|
384 cursor.continue(); |
|
385 } |
|
386 else { |
|
387 testGenerator.next(); |
|
388 } |
|
389 } |
|
390 yield undefined; |
|
391 |
|
392 is(count, 0, |
|
393 "Correct count for non-existent lowerBound arg to openCursor"); |
|
394 |
|
395 count = 0; |
|
396 keyRange = IDBKeyRange.bound(data[2].ssn, data[3].ssn); |
|
397 |
|
398 objectStore.openCursor(keyRange).onsuccess = function(event) { |
|
399 let cursor = event.target.result; |
|
400 if (cursor) { |
|
401 count++; |
|
402 cursor.continue(); |
|
403 } |
|
404 else { |
|
405 testGenerator.next(); |
|
406 } |
|
407 } |
|
408 yield undefined; |
|
409 |
|
410 is(count, 2, "Correct count for bound arg to openCursor"); |
|
411 |
|
412 count = 0; |
|
413 keyRange = IDBKeyRange.bound(data[2].ssn, data[3].ssn, true); |
|
414 |
|
415 objectStore.openCursor(keyRange).onsuccess = function(event) { |
|
416 let cursor = event.target.result; |
|
417 if (cursor) { |
|
418 count++; |
|
419 cursor.continue(); |
|
420 } |
|
421 else { |
|
422 testGenerator.next(); |
|
423 } |
|
424 } |
|
425 yield undefined; |
|
426 |
|
427 is(count, 1, "Correct count for bound arg to openCursor"); |
|
428 |
|
429 count = 0; |
|
430 keyRange = IDBKeyRange.bound(data[2].ssn, data[3].ssn, true, true); |
|
431 |
|
432 objectStore.openCursor(keyRange).onsuccess = function(event) { |
|
433 let cursor = event.target.result; |
|
434 if (cursor) { |
|
435 count++; |
|
436 cursor.continue(); |
|
437 } |
|
438 else { |
|
439 testGenerator.next(); |
|
440 } |
|
441 } |
|
442 yield undefined; |
|
443 |
|
444 is(count, 0, "Correct count for bound arg to openCursor"); |
|
445 |
|
446 let index = objectStore.index(indexName); |
|
447 |
|
448 count = 0; |
|
449 |
|
450 index.openKeyCursor().onsuccess = function(event) { |
|
451 let cursor = event.target.result; |
|
452 if (cursor) { |
|
453 count++; |
|
454 cursor.continue(); |
|
455 } |
|
456 else { |
|
457 testGenerator.next(); |
|
458 } |
|
459 } |
|
460 yield undefined; |
|
461 |
|
462 is(count, weightSort.length, |
|
463 "Correct count for unspecified arg to index.openKeyCursor"); |
|
464 |
|
465 count = 0; |
|
466 |
|
467 index.openKeyCursor(null).onsuccess = function(event) { |
|
468 let cursor = event.target.result; |
|
469 if (cursor) { |
|
470 count++; |
|
471 cursor.continue(); |
|
472 } |
|
473 else { |
|
474 testGenerator.next(); |
|
475 } |
|
476 } |
|
477 yield undefined; |
|
478 |
|
479 is(count, weightSort.length, |
|
480 "Correct count for null arg to index.openKeyCursor"); |
|
481 |
|
482 count = 0; |
|
483 |
|
484 index.openKeyCursor(undefined).onsuccess = function(event) { |
|
485 let cursor = event.target.result; |
|
486 if (cursor) { |
|
487 count++; |
|
488 cursor.continue(); |
|
489 } |
|
490 else { |
|
491 testGenerator.next(); |
|
492 } |
|
493 } |
|
494 yield undefined; |
|
495 |
|
496 is(count, weightSort.length, |
|
497 "Correct count for undefined arg to index.openKeyCursor"); |
|
498 |
|
499 count = 0; |
|
500 |
|
501 index.openKeyCursor(data[0].weight).onsuccess = function(event) { |
|
502 let cursor = event.target.result; |
|
503 if (cursor) { |
|
504 count++; |
|
505 cursor.continue(); |
|
506 } |
|
507 else { |
|
508 testGenerator.next(); |
|
509 } |
|
510 } |
|
511 yield undefined; |
|
512 |
|
513 is(count, 1, "Correct count for single key arg to index.openKeyCursor"); |
|
514 |
|
515 count = 0; |
|
516 |
|
517 index.openKeyCursor("foo").onsuccess = function(event) { |
|
518 let cursor = event.target.result; |
|
519 if (cursor) { |
|
520 count++; |
|
521 cursor.continue(); |
|
522 } |
|
523 else { |
|
524 testGenerator.next(); |
|
525 } |
|
526 } |
|
527 yield undefined; |
|
528 |
|
529 is(count, 0, |
|
530 "Correct count for non-existent key arg to index.openKeyCursor"); |
|
531 |
|
532 count = 0; |
|
533 keyRange = IDBKeyRange.only("foo"); |
|
534 |
|
535 index.openKeyCursor(keyRange).onsuccess = function(event) { |
|
536 let cursor = event.target.result; |
|
537 if (cursor) { |
|
538 count++; |
|
539 cursor.continue(); |
|
540 } |
|
541 else { |
|
542 testGenerator.next(); |
|
543 } |
|
544 } |
|
545 yield undefined; |
|
546 |
|
547 is(count, 0, |
|
548 "Correct count for non-existent keyRange arg to index.openKeyCursor"); |
|
549 |
|
550 count = 0; |
|
551 keyRange = IDBKeyRange.only(data[0].weight); |
|
552 |
|
553 index.openKeyCursor(keyRange).onsuccess = function(event) { |
|
554 let cursor = event.target.result; |
|
555 if (cursor) { |
|
556 count++; |
|
557 cursor.continue(); |
|
558 } |
|
559 else { |
|
560 testGenerator.next(); |
|
561 } |
|
562 } |
|
563 yield undefined; |
|
564 |
|
565 is(count, 1, |
|
566 "Correct count for only keyRange arg to index.openKeyCursor"); |
|
567 |
|
568 count = 0; |
|
569 keyRange = IDBKeyRange.lowerBound(data[weightSort[0]].weight); |
|
570 |
|
571 index.openKeyCursor(keyRange).onsuccess = function(event) { |
|
572 let cursor = event.target.result; |
|
573 if (cursor) { |
|
574 count++; |
|
575 cursor.continue(); |
|
576 } |
|
577 else { |
|
578 testGenerator.next(); |
|
579 } |
|
580 } |
|
581 yield undefined; |
|
582 |
|
583 is(count, weightSort.length, |
|
584 "Correct count for lowerBound keyRange arg to index.openKeyCursor"); |
|
585 |
|
586 count = 0; |
|
587 keyRange = IDBKeyRange.lowerBound(data[weightSort[0]].weight, true); |
|
588 |
|
589 index.openKeyCursor(keyRange).onsuccess = function(event) { |
|
590 let cursor = event.target.result; |
|
591 if (cursor) { |
|
592 count++; |
|
593 cursor.continue(); |
|
594 } |
|
595 else { |
|
596 testGenerator.next(); |
|
597 } |
|
598 } |
|
599 yield undefined; |
|
600 |
|
601 is(count, weightSort.length - 1, |
|
602 "Correct count for lowerBound keyRange arg to index.openKeyCursor"); |
|
603 |
|
604 count = 0; |
|
605 keyRange = IDBKeyRange.lowerBound("foo"); |
|
606 |
|
607 index.openKeyCursor(keyRange).onsuccess = function(event) { |
|
608 let cursor = event.target.result; |
|
609 if (cursor) { |
|
610 count++; |
|
611 cursor.continue(); |
|
612 } |
|
613 else { |
|
614 testGenerator.next(); |
|
615 } |
|
616 } |
|
617 yield undefined; |
|
618 |
|
619 is(count, 0, |
|
620 "Correct count for lowerBound keyRange arg to index.openKeyCursor"); |
|
621 |
|
622 count = 0; |
|
623 keyRange = IDBKeyRange.upperBound(data[weightSort[0]].weight); |
|
624 |
|
625 index.openKeyCursor(keyRange).onsuccess = function(event) { |
|
626 let cursor = event.target.result; |
|
627 if (cursor) { |
|
628 count++; |
|
629 cursor.continue(); |
|
630 } |
|
631 else { |
|
632 testGenerator.next(); |
|
633 } |
|
634 } |
|
635 yield undefined; |
|
636 |
|
637 is(count, 1, |
|
638 "Correct count for upperBound keyRange arg to index.openKeyCursor"); |
|
639 |
|
640 count = 0; |
|
641 keyRange = IDBKeyRange.upperBound(data[weightSort[0]].weight, true); |
|
642 |
|
643 index.openKeyCursor(keyRange).onsuccess = function(event) { |
|
644 let cursor = event.target.result; |
|
645 if (cursor) { |
|
646 count++; |
|
647 cursor.continue(); |
|
648 } |
|
649 else { |
|
650 testGenerator.next(); |
|
651 } |
|
652 } |
|
653 yield undefined; |
|
654 |
|
655 is(count, 0, |
|
656 "Correct count for upperBound keyRange arg to index.openKeyCursor"); |
|
657 |
|
658 count = 0; |
|
659 keyRange = IDBKeyRange.upperBound(data[weightSort[weightSort.length - 1]].weight); |
|
660 |
|
661 index.openKeyCursor(keyRange).onsuccess = function(event) { |
|
662 let cursor = event.target.result; |
|
663 if (cursor) { |
|
664 count++; |
|
665 cursor.continue(); |
|
666 } |
|
667 else { |
|
668 testGenerator.next(); |
|
669 } |
|
670 } |
|
671 yield undefined; |
|
672 |
|
673 is(count, weightSort.length, |
|
674 "Correct count for upperBound keyRange arg to index.openKeyCursor"); |
|
675 |
|
676 count = 0; |
|
677 keyRange = IDBKeyRange.upperBound(data[weightSort[weightSort.length - 1]].weight, |
|
678 true); |
|
679 |
|
680 index.openKeyCursor(keyRange).onsuccess = function(event) { |
|
681 let cursor = event.target.result; |
|
682 if (cursor) { |
|
683 count++; |
|
684 cursor.continue(); |
|
685 } |
|
686 else { |
|
687 testGenerator.next(); |
|
688 } |
|
689 } |
|
690 yield undefined; |
|
691 |
|
692 is(count, weightSort.length - 1, |
|
693 "Correct count for upperBound keyRange arg to index.openKeyCursor"); |
|
694 |
|
695 count = 0; |
|
696 keyRange = IDBKeyRange.upperBound("foo"); |
|
697 |
|
698 index.openKeyCursor(keyRange).onsuccess = function(event) { |
|
699 let cursor = event.target.result; |
|
700 if (cursor) { |
|
701 count++; |
|
702 cursor.continue(); |
|
703 } |
|
704 else { |
|
705 testGenerator.next(); |
|
706 } |
|
707 } |
|
708 yield undefined; |
|
709 |
|
710 is(count, weightSort.length, |
|
711 "Correct count for upperBound keyRange arg to index.openKeyCursor"); |
|
712 |
|
713 count = 0; |
|
714 keyRange = IDBKeyRange.upperBound(0); |
|
715 |
|
716 index.openKeyCursor(keyRange).onsuccess = function(event) { |
|
717 let cursor = event.target.result; |
|
718 if (cursor) { |
|
719 count++; |
|
720 cursor.continue(); |
|
721 } |
|
722 else { |
|
723 testGenerator.next(); |
|
724 } |
|
725 } |
|
726 yield undefined; |
|
727 |
|
728 is(count, 0, |
|
729 "Correct count for upperBound keyRange arg to index.openKeyCursor"); |
|
730 |
|
731 count = 0; |
|
732 keyRange = IDBKeyRange.bound(data[weightSort[0]].weight, |
|
733 data[weightSort[weightSort.length - 1]].weight); |
|
734 |
|
735 index.openKeyCursor(keyRange).onsuccess = function(event) { |
|
736 let cursor = event.target.result; |
|
737 if (cursor) { |
|
738 count++; |
|
739 cursor.continue(); |
|
740 } |
|
741 else { |
|
742 testGenerator.next(); |
|
743 } |
|
744 } |
|
745 yield undefined; |
|
746 |
|
747 is(count, weightSort.length, |
|
748 "Correct count for bound keyRange arg to index.openKeyCursor"); |
|
749 |
|
750 count = 0; |
|
751 keyRange = IDBKeyRange.bound(data[weightSort[0]].weight, |
|
752 data[weightSort[weightSort.length - 1]].weight, |
|
753 true); |
|
754 |
|
755 index.openKeyCursor(keyRange).onsuccess = function(event) { |
|
756 let cursor = event.target.result; |
|
757 if (cursor) { |
|
758 count++; |
|
759 cursor.continue(); |
|
760 } |
|
761 else { |
|
762 testGenerator.next(); |
|
763 } |
|
764 } |
|
765 yield undefined; |
|
766 |
|
767 is(count, weightSort.length - 1, |
|
768 "Correct count for bound keyRange arg to index.openKeyCursor"); |
|
769 |
|
770 count = 0; |
|
771 keyRange = IDBKeyRange.bound(data[weightSort[0]].weight, |
|
772 data[weightSort[weightSort.length - 1]].weight, |
|
773 true, true); |
|
774 |
|
775 index.openKeyCursor(keyRange).onsuccess = function(event) { |
|
776 let cursor = event.target.result; |
|
777 if (cursor) { |
|
778 count++; |
|
779 cursor.continue(); |
|
780 } |
|
781 else { |
|
782 testGenerator.next(); |
|
783 } |
|
784 } |
|
785 yield undefined; |
|
786 |
|
787 is(count, weightSort.length - 2, |
|
788 "Correct count for bound keyRange arg to index.openKeyCursor"); |
|
789 |
|
790 count = 0; |
|
791 keyRange = IDBKeyRange.bound(data[weightSort[0]].weight - 1, |
|
792 data[weightSort[weightSort.length - 1]].weight + 1); |
|
793 |
|
794 index.openKeyCursor(keyRange).onsuccess = function(event) { |
|
795 let cursor = event.target.result; |
|
796 if (cursor) { |
|
797 count++; |
|
798 cursor.continue(); |
|
799 } |
|
800 else { |
|
801 testGenerator.next(); |
|
802 } |
|
803 } |
|
804 yield undefined; |
|
805 |
|
806 is(count, weightSort.length, |
|
807 "Correct count for bound keyRange arg to index.openKeyCursor"); |
|
808 |
|
809 count = 0; |
|
810 keyRange = IDBKeyRange.bound(data[weightSort[0]].weight - 2, |
|
811 data[weightSort[0]].weight - 1); |
|
812 |
|
813 index.openKeyCursor(keyRange).onsuccess = function(event) { |
|
814 let cursor = event.target.result; |
|
815 if (cursor) { |
|
816 count++; |
|
817 cursor.continue(); |
|
818 } |
|
819 else { |
|
820 testGenerator.next(); |
|
821 } |
|
822 } |
|
823 yield undefined; |
|
824 |
|
825 is(count, 0, |
|
826 "Correct count for bound keyRange arg to index.openKeyCursor"); |
|
827 |
|
828 count = 0; |
|
829 keyRange = IDBKeyRange.bound(data[weightSort[1]].weight, |
|
830 data[weightSort[2]].weight); |
|
831 |
|
832 index.openKeyCursor(keyRange).onsuccess = function(event) { |
|
833 let cursor = event.target.result; |
|
834 if (cursor) { |
|
835 count++; |
|
836 cursor.continue(); |
|
837 } |
|
838 else { |
|
839 testGenerator.next(); |
|
840 } |
|
841 } |
|
842 yield undefined; |
|
843 |
|
844 is(count, 3, |
|
845 "Correct count for bound keyRange arg to index.openKeyCursor"); |
|
846 |
|
847 count = 0; |
|
848 |
|
849 index.openCursor().onsuccess = function(event) { |
|
850 let cursor = event.target.result; |
|
851 if (cursor) { |
|
852 count++; |
|
853 cursor.continue(); |
|
854 } |
|
855 else { |
|
856 testGenerator.next(); |
|
857 } |
|
858 } |
|
859 yield undefined; |
|
860 |
|
861 is(count, weightSort.length, |
|
862 "Correct count for unspecified arg to index.openCursor"); |
|
863 |
|
864 count = 0; |
|
865 |
|
866 index.openCursor(null).onsuccess = function(event) { |
|
867 let cursor = event.target.result; |
|
868 if (cursor) { |
|
869 count++; |
|
870 cursor.continue(); |
|
871 } |
|
872 else { |
|
873 testGenerator.next(); |
|
874 } |
|
875 } |
|
876 yield undefined; |
|
877 |
|
878 is(count, weightSort.length, |
|
879 "Correct count for null arg to index.openCursor"); |
|
880 |
|
881 count = 0; |
|
882 |
|
883 index.openCursor(undefined).onsuccess = function(event) { |
|
884 let cursor = event.target.result; |
|
885 if (cursor) { |
|
886 count++; |
|
887 cursor.continue(); |
|
888 } |
|
889 else { |
|
890 testGenerator.next(); |
|
891 } |
|
892 } |
|
893 yield undefined; |
|
894 |
|
895 is(count, weightSort.length, |
|
896 "Correct count for undefined arg to index.openCursor"); |
|
897 |
|
898 count = 0; |
|
899 |
|
900 index.openCursor(data[0].weight).onsuccess = function(event) { |
|
901 let cursor = event.target.result; |
|
902 if (cursor) { |
|
903 count++; |
|
904 cursor.continue(); |
|
905 } |
|
906 else { |
|
907 testGenerator.next(); |
|
908 } |
|
909 } |
|
910 yield undefined; |
|
911 |
|
912 is(count, 1, "Correct count for single key arg to index.openCursor"); |
|
913 |
|
914 count = 0; |
|
915 |
|
916 index.openCursor("foo").onsuccess = function(event) { |
|
917 let cursor = event.target.result; |
|
918 if (cursor) { |
|
919 count++; |
|
920 cursor.continue(); |
|
921 } |
|
922 else { |
|
923 testGenerator.next(); |
|
924 } |
|
925 } |
|
926 yield undefined; |
|
927 |
|
928 is(count, 0, |
|
929 "Correct count for non-existent key arg to index.openCursor"); |
|
930 |
|
931 count = 0; |
|
932 keyRange = IDBKeyRange.only("foo"); |
|
933 |
|
934 index.openCursor(keyRange).onsuccess = function(event) { |
|
935 let cursor = event.target.result; |
|
936 if (cursor) { |
|
937 count++; |
|
938 cursor.continue(); |
|
939 } |
|
940 else { |
|
941 testGenerator.next(); |
|
942 } |
|
943 } |
|
944 yield undefined; |
|
945 |
|
946 is(count, 0, |
|
947 "Correct count for non-existent keyRange arg to index.openCursor"); |
|
948 |
|
949 count = 0; |
|
950 keyRange = IDBKeyRange.only(data[0].weight); |
|
951 |
|
952 index.openCursor(keyRange).onsuccess = function(event) { |
|
953 let cursor = event.target.result; |
|
954 if (cursor) { |
|
955 count++; |
|
956 cursor.continue(); |
|
957 } |
|
958 else { |
|
959 testGenerator.next(); |
|
960 } |
|
961 } |
|
962 yield undefined; |
|
963 |
|
964 is(count, 1, |
|
965 "Correct count for only keyRange arg to index.openCursor"); |
|
966 |
|
967 count = 0; |
|
968 keyRange = IDBKeyRange.lowerBound(data[weightSort[0]].weight); |
|
969 |
|
970 index.openCursor(keyRange).onsuccess = function(event) { |
|
971 let cursor = event.target.result; |
|
972 if (cursor) { |
|
973 count++; |
|
974 cursor.continue(); |
|
975 } |
|
976 else { |
|
977 testGenerator.next(); |
|
978 } |
|
979 } |
|
980 yield undefined; |
|
981 |
|
982 is(count, weightSort.length, |
|
983 "Correct count for lowerBound keyRange arg to index.openCursor"); |
|
984 |
|
985 count = 0; |
|
986 keyRange = IDBKeyRange.lowerBound(data[weightSort[0]].weight, true); |
|
987 |
|
988 index.openCursor(keyRange).onsuccess = function(event) { |
|
989 let cursor = event.target.result; |
|
990 if (cursor) { |
|
991 count++; |
|
992 cursor.continue(); |
|
993 } |
|
994 else { |
|
995 testGenerator.next(); |
|
996 } |
|
997 } |
|
998 yield undefined; |
|
999 |
|
1000 is(count, weightSort.length - 1, |
|
1001 "Correct count for lowerBound keyRange arg to index.openCursor"); |
|
1002 |
|
1003 count = 0; |
|
1004 keyRange = IDBKeyRange.lowerBound("foo"); |
|
1005 |
|
1006 index.openCursor(keyRange).onsuccess = function(event) { |
|
1007 let cursor = event.target.result; |
|
1008 if (cursor) { |
|
1009 count++; |
|
1010 cursor.continue(); |
|
1011 } |
|
1012 else { |
|
1013 testGenerator.next(); |
|
1014 } |
|
1015 } |
|
1016 yield undefined; |
|
1017 |
|
1018 is(count, 0, |
|
1019 "Correct count for lowerBound keyRange arg to index.openCursor"); |
|
1020 |
|
1021 count = 0; |
|
1022 keyRange = IDBKeyRange.upperBound(data[weightSort[0]].weight); |
|
1023 |
|
1024 index.openCursor(keyRange).onsuccess = function(event) { |
|
1025 let cursor = event.target.result; |
|
1026 if (cursor) { |
|
1027 count++; |
|
1028 cursor.continue(); |
|
1029 } |
|
1030 else { |
|
1031 testGenerator.next(); |
|
1032 } |
|
1033 } |
|
1034 yield undefined; |
|
1035 |
|
1036 is(count, 1, |
|
1037 "Correct count for upperBound keyRange arg to index.openCursor"); |
|
1038 |
|
1039 count = 0; |
|
1040 keyRange = IDBKeyRange.upperBound(data[weightSort[0]].weight, true); |
|
1041 |
|
1042 index.openCursor(keyRange).onsuccess = function(event) { |
|
1043 let cursor = event.target.result; |
|
1044 if (cursor) { |
|
1045 count++; |
|
1046 cursor.continue(); |
|
1047 } |
|
1048 else { |
|
1049 testGenerator.next(); |
|
1050 } |
|
1051 } |
|
1052 yield undefined; |
|
1053 |
|
1054 is(count, 0, |
|
1055 "Correct count for upperBound keyRange arg to index.openCursor"); |
|
1056 |
|
1057 count = 0; |
|
1058 keyRange = IDBKeyRange.upperBound(data[weightSort[weightSort.length - 1]].weight); |
|
1059 |
|
1060 index.openCursor(keyRange).onsuccess = function(event) { |
|
1061 let cursor = event.target.result; |
|
1062 if (cursor) { |
|
1063 count++; |
|
1064 cursor.continue(); |
|
1065 } |
|
1066 else { |
|
1067 testGenerator.next(); |
|
1068 } |
|
1069 } |
|
1070 yield undefined; |
|
1071 |
|
1072 is(count, weightSort.length, |
|
1073 "Correct count for upperBound keyRange arg to index.openCursor"); |
|
1074 |
|
1075 count = 0; |
|
1076 keyRange = IDBKeyRange.upperBound(data[weightSort[weightSort.length - 1]].weight, |
|
1077 true); |
|
1078 |
|
1079 index.openCursor(keyRange).onsuccess = function(event) { |
|
1080 let cursor = event.target.result; |
|
1081 if (cursor) { |
|
1082 count++; |
|
1083 cursor.continue(); |
|
1084 } |
|
1085 else { |
|
1086 testGenerator.next(); |
|
1087 } |
|
1088 } |
|
1089 yield undefined; |
|
1090 |
|
1091 is(count, weightSort.length - 1, |
|
1092 "Correct count for upperBound keyRange arg to index.openCursor"); |
|
1093 |
|
1094 count = 0; |
|
1095 keyRange = IDBKeyRange.upperBound("foo"); |
|
1096 |
|
1097 index.openCursor(keyRange).onsuccess = function(event) { |
|
1098 let cursor = event.target.result; |
|
1099 if (cursor) { |
|
1100 count++; |
|
1101 cursor.continue(); |
|
1102 } |
|
1103 else { |
|
1104 testGenerator.next(); |
|
1105 } |
|
1106 } |
|
1107 yield undefined; |
|
1108 |
|
1109 is(count, weightSort.length, |
|
1110 "Correct count for upperBound keyRange arg to index.openCursor"); |
|
1111 |
|
1112 count = 0; |
|
1113 keyRange = IDBKeyRange.upperBound(0); |
|
1114 |
|
1115 index.openCursor(keyRange).onsuccess = function(event) { |
|
1116 let cursor = event.target.result; |
|
1117 if (cursor) { |
|
1118 count++; |
|
1119 cursor.continue(); |
|
1120 } |
|
1121 else { |
|
1122 testGenerator.next(); |
|
1123 } |
|
1124 } |
|
1125 yield undefined; |
|
1126 |
|
1127 is(count, 0, |
|
1128 "Correct count for upperBound keyRange arg to index.openCursor"); |
|
1129 |
|
1130 count = 0; |
|
1131 keyRange = IDBKeyRange.bound(data[weightSort[0]].weight, |
|
1132 data[weightSort[weightSort.length - 1]].weight); |
|
1133 |
|
1134 index.openCursor(keyRange).onsuccess = function(event) { |
|
1135 let cursor = event.target.result; |
|
1136 if (cursor) { |
|
1137 count++; |
|
1138 cursor.continue(); |
|
1139 } |
|
1140 else { |
|
1141 testGenerator.next(); |
|
1142 } |
|
1143 } |
|
1144 yield undefined; |
|
1145 |
|
1146 is(count, weightSort.length, |
|
1147 "Correct count for bound keyRange arg to index.openCursor"); |
|
1148 |
|
1149 count = 0; |
|
1150 keyRange = IDBKeyRange.bound(data[weightSort[0]].weight, |
|
1151 data[weightSort[weightSort.length - 1]].weight, |
|
1152 true); |
|
1153 |
|
1154 index.openCursor(keyRange).onsuccess = function(event) { |
|
1155 let cursor = event.target.result; |
|
1156 if (cursor) { |
|
1157 count++; |
|
1158 cursor.continue(); |
|
1159 } |
|
1160 else { |
|
1161 testGenerator.next(); |
|
1162 } |
|
1163 } |
|
1164 yield undefined; |
|
1165 |
|
1166 is(count, weightSort.length - 1, |
|
1167 "Correct count for bound keyRange arg to index.openCursor"); |
|
1168 |
|
1169 count = 0; |
|
1170 keyRange = IDBKeyRange.bound(data[weightSort[0]].weight, |
|
1171 data[weightSort[weightSort.length - 1]].weight, |
|
1172 true, true); |
|
1173 |
|
1174 index.openCursor(keyRange).onsuccess = function(event) { |
|
1175 let cursor = event.target.result; |
|
1176 if (cursor) { |
|
1177 count++; |
|
1178 cursor.continue(); |
|
1179 } |
|
1180 else { |
|
1181 testGenerator.next(); |
|
1182 } |
|
1183 } |
|
1184 yield undefined; |
|
1185 |
|
1186 is(count, weightSort.length - 2, |
|
1187 "Correct count for bound keyRange arg to index.openCursor"); |
|
1188 |
|
1189 count = 0; |
|
1190 keyRange = IDBKeyRange.bound(data[weightSort[0]].weight - 1, |
|
1191 data[weightSort[weightSort.length - 1]].weight + 1); |
|
1192 |
|
1193 index.openCursor(keyRange).onsuccess = function(event) { |
|
1194 let cursor = event.target.result; |
|
1195 if (cursor) { |
|
1196 count++; |
|
1197 cursor.continue(); |
|
1198 } |
|
1199 else { |
|
1200 testGenerator.next(); |
|
1201 } |
|
1202 } |
|
1203 yield undefined; |
|
1204 |
|
1205 is(count, weightSort.length, |
|
1206 "Correct count for bound keyRange arg to index.openCursor"); |
|
1207 |
|
1208 count = 0; |
|
1209 keyRange = IDBKeyRange.bound(data[weightSort[0]].weight - 2, |
|
1210 data[weightSort[0]].weight - 1); |
|
1211 |
|
1212 index.openCursor(keyRange).onsuccess = function(event) { |
|
1213 let cursor = event.target.result; |
|
1214 if (cursor) { |
|
1215 count++; |
|
1216 cursor.continue(); |
|
1217 } |
|
1218 else { |
|
1219 testGenerator.next(); |
|
1220 } |
|
1221 } |
|
1222 yield undefined; |
|
1223 |
|
1224 is(count, 0, |
|
1225 "Correct count for bound keyRange arg to index.openCursor"); |
|
1226 |
|
1227 count = 0; |
|
1228 keyRange = IDBKeyRange.bound(data[weightSort[1]].weight, |
|
1229 data[weightSort[2]].weight); |
|
1230 |
|
1231 index.openCursor(keyRange).onsuccess = function(event) { |
|
1232 let cursor = event.target.result; |
|
1233 if (cursor) { |
|
1234 count++; |
|
1235 cursor.continue(); |
|
1236 } |
|
1237 else { |
|
1238 testGenerator.next(); |
|
1239 } |
|
1240 } |
|
1241 yield undefined; |
|
1242 |
|
1243 is(count, 3, |
|
1244 "Correct count for bound keyRange arg to index.openCursor"); |
|
1245 |
|
1246 try { |
|
1247 index.get(); |
|
1248 ok(false, "Get with unspecified arg should have thrown"); |
|
1249 } |
|
1250 catch(e) { |
|
1251 ok(true, "Get with unspecified arg should have thrown"); |
|
1252 } |
|
1253 |
|
1254 try { |
|
1255 index.get(undefined); |
|
1256 ok(false, "Get with undefined should have thrown"); |
|
1257 } |
|
1258 catch(e) { |
|
1259 ok(true, "Get with undefined arg should have thrown"); |
|
1260 } |
|
1261 |
|
1262 try { |
|
1263 index.get(null); |
|
1264 ok(false, "Get with null should have thrown"); |
|
1265 } |
|
1266 catch(e) { |
|
1267 is(e instanceof DOMException, true, |
|
1268 "Got right kind of exception"); |
|
1269 is(e.name, "DataError", "Correct error."); |
|
1270 is(e.code, 0, "Correct code."); |
|
1271 } |
|
1272 |
|
1273 index.get(data[0].weight).onsuccess = grabEventAndContinueHandler; |
|
1274 event = yield undefined; |
|
1275 |
|
1276 is(event.target.result.weight, data[0].weight, "Got correct result"); |
|
1277 |
|
1278 keyRange = IDBKeyRange.only(data[0].weight); |
|
1279 |
|
1280 index.get(keyRange).onsuccess = grabEventAndContinueHandler; |
|
1281 event = yield undefined; |
|
1282 |
|
1283 is(event.target.result.weight, data[0].weight, "Got correct result"); |
|
1284 |
|
1285 keyRange = IDBKeyRange.lowerBound(data[weightSort[0]].weight); |
|
1286 |
|
1287 index.get(keyRange).onsuccess = grabEventAndContinueHandler; |
|
1288 event = yield undefined; |
|
1289 |
|
1290 is(event.target.result.weight, data[weightSort[0]].weight, |
|
1291 "Got correct result"); |
|
1292 |
|
1293 keyRange = IDBKeyRange.lowerBound(data[weightSort[0]].weight - 1); |
|
1294 |
|
1295 index.get(keyRange).onsuccess = grabEventAndContinueHandler; |
|
1296 event = yield undefined; |
|
1297 |
|
1298 is(event.target.result.weight, data[weightSort[0]].weight, |
|
1299 "Got correct result"); |
|
1300 |
|
1301 keyRange = IDBKeyRange.lowerBound(data[weightSort[0]].weight + 1); |
|
1302 |
|
1303 index.get(keyRange).onsuccess = grabEventAndContinueHandler; |
|
1304 event = yield undefined; |
|
1305 |
|
1306 is(event.target.result.weight, data[weightSort[1]].weight, |
|
1307 "Got correct result"); |
|
1308 |
|
1309 keyRange = IDBKeyRange.lowerBound(data[weightSort[0]].weight, true); |
|
1310 |
|
1311 index.get(keyRange).onsuccess = grabEventAndContinueHandler; |
|
1312 event = yield undefined; |
|
1313 |
|
1314 is(event.target.result.weight, data[weightSort[1]].weight, |
|
1315 "Got correct result"); |
|
1316 |
|
1317 keyRange = IDBKeyRange.bound(data[weightSort[0]].weight, |
|
1318 data[weightSort[1]].weight); |
|
1319 |
|
1320 index.get(keyRange).onsuccess = grabEventAndContinueHandler; |
|
1321 event = yield undefined; |
|
1322 |
|
1323 is(event.target.result.weight, data[weightSort[0]].weight, |
|
1324 "Got correct result"); |
|
1325 |
|
1326 keyRange = IDBKeyRange.bound(data[weightSort[0]].weight, |
|
1327 data[weightSort[1]].weight, true); |
|
1328 |
|
1329 index.get(keyRange).onsuccess = grabEventAndContinueHandler; |
|
1330 event = yield undefined; |
|
1331 |
|
1332 is(event.target.result.weight, data[weightSort[1]].weight, |
|
1333 "Got correct result"); |
|
1334 |
|
1335 keyRange = IDBKeyRange.bound(data[weightSort[0]].weight, |
|
1336 data[weightSort[1]].weight, true, true); |
|
1337 |
|
1338 index.get(keyRange).onsuccess = grabEventAndContinueHandler; |
|
1339 event = yield undefined; |
|
1340 |
|
1341 is(event.target.result, undefined, "Got correct result"); |
|
1342 |
|
1343 keyRange = IDBKeyRange.upperBound(data[weightSort[5]].weight); |
|
1344 |
|
1345 index.get(keyRange).onsuccess = grabEventAndContinueHandler; |
|
1346 event = yield undefined; |
|
1347 |
|
1348 is(event.target.result.weight, data[weightSort[0]].weight, |
|
1349 "Got correct result"); |
|
1350 |
|
1351 keyRange = IDBKeyRange.upperBound(data[weightSort[0]].weight, true); |
|
1352 |
|
1353 index.get(keyRange).onsuccess = grabEventAndContinueHandler; |
|
1354 event = yield undefined; |
|
1355 |
|
1356 is(event.target.result, undefined, "Got correct result"); |
|
1357 |
|
1358 try { |
|
1359 index.getKey(); |
|
1360 ok(false, "Get with unspecified arg should have thrown"); |
|
1361 } |
|
1362 catch(e) { |
|
1363 ok(true, "Get with unspecified arg should have thrown"); |
|
1364 } |
|
1365 |
|
1366 try { |
|
1367 index.getKey(undefined); |
|
1368 ok(false, "Get with undefined should have thrown"); |
|
1369 } |
|
1370 catch(e) { |
|
1371 ok(true, "Get with undefined arg should have thrown"); |
|
1372 } |
|
1373 |
|
1374 try { |
|
1375 index.getKey(null); |
|
1376 ok(false, "Get with null should have thrown"); |
|
1377 } |
|
1378 catch(e) { |
|
1379 is(e instanceof DOMException, true, |
|
1380 "Got right kind of exception"); |
|
1381 is(e.name, "DataError", "Correct error."); |
|
1382 is(e.code, 0, "Correct code."); |
|
1383 } |
|
1384 |
|
1385 index.getKey(data[0].weight).onsuccess = grabEventAndContinueHandler; |
|
1386 event = yield undefined; |
|
1387 |
|
1388 is(event.target.result, data[0].ssn, "Got correct result"); |
|
1389 |
|
1390 keyRange = IDBKeyRange.only(data[0].weight); |
|
1391 |
|
1392 index.getKey(keyRange).onsuccess = grabEventAndContinueHandler; |
|
1393 event = yield undefined; |
|
1394 |
|
1395 is(event.target.result, data[0].ssn, "Got correct result"); |
|
1396 |
|
1397 keyRange = IDBKeyRange.lowerBound(data[weightSort[0]].weight); |
|
1398 |
|
1399 index.getKey(keyRange).onsuccess = grabEventAndContinueHandler; |
|
1400 event = yield undefined; |
|
1401 |
|
1402 is(event.target.result, data[weightSort[0]].ssn, "Got correct result"); |
|
1403 |
|
1404 keyRange = IDBKeyRange.lowerBound(data[weightSort[0]].weight - 1); |
|
1405 |
|
1406 index.getKey(keyRange).onsuccess = grabEventAndContinueHandler; |
|
1407 event = yield undefined; |
|
1408 |
|
1409 is(event.target.result, data[weightSort[0]].ssn, "Got correct result"); |
|
1410 |
|
1411 keyRange = IDBKeyRange.lowerBound(data[weightSort[0]].weight + 1); |
|
1412 |
|
1413 index.getKey(keyRange).onsuccess = grabEventAndContinueHandler; |
|
1414 event = yield undefined; |
|
1415 |
|
1416 is(event.target.result, data[weightSort[1]].ssn, "Got correct result"); |
|
1417 |
|
1418 keyRange = IDBKeyRange.lowerBound(data[weightSort[0]].weight, true); |
|
1419 |
|
1420 index.getKey(keyRange).onsuccess = grabEventAndContinueHandler; |
|
1421 event = yield undefined; |
|
1422 |
|
1423 is(event.target.result, data[weightSort[1]].ssn, "Got correct result"); |
|
1424 |
|
1425 keyRange = IDBKeyRange.bound(data[weightSort[0]].weight, |
|
1426 data[weightSort[1]].weight); |
|
1427 |
|
1428 index.getKey(keyRange).onsuccess = grabEventAndContinueHandler; |
|
1429 event = yield undefined; |
|
1430 |
|
1431 is(event.target.result, data[weightSort[0]].ssn, "Got correct result"); |
|
1432 |
|
1433 keyRange = IDBKeyRange.bound(data[weightSort[0]].weight, |
|
1434 data[weightSort[1]].weight, true); |
|
1435 |
|
1436 index.getKey(keyRange).onsuccess = grabEventAndContinueHandler; |
|
1437 event = yield undefined; |
|
1438 |
|
1439 is(event.target.result, data[weightSort[1]].ssn, "Got correct result"); |
|
1440 |
|
1441 keyRange = IDBKeyRange.bound(data[weightSort[0]].weight, |
|
1442 data[weightSort[1]].weight, true, true); |
|
1443 |
|
1444 index.getKey(keyRange).onsuccess = grabEventAndContinueHandler; |
|
1445 event = yield undefined; |
|
1446 |
|
1447 is(event.target.result, undefined, "Got correct result"); |
|
1448 |
|
1449 keyRange = IDBKeyRange.upperBound(data[weightSort[5]].weight); |
|
1450 |
|
1451 index.getKey(keyRange).onsuccess = grabEventAndContinueHandler; |
|
1452 event = yield undefined; |
|
1453 |
|
1454 is(event.target.result, data[weightSort[0]].ssn, "Got correct result"); |
|
1455 |
|
1456 keyRange = IDBKeyRange.upperBound(data[weightSort[0]].weight, true); |
|
1457 |
|
1458 index.getKey(keyRange).onsuccess = grabEventAndContinueHandler; |
|
1459 event = yield undefined; |
|
1460 |
|
1461 is(event.target.result, undefined, "Got correct result"); |
|
1462 |
|
1463 count = 0; |
|
1464 |
|
1465 index.openKeyCursor().onsuccess = function(event) { |
|
1466 let cursor = event.target.result; |
|
1467 if (cursor) { |
|
1468 count++; |
|
1469 cursor.continue(); |
|
1470 } |
|
1471 else { |
|
1472 testGenerator.next(); |
|
1473 } |
|
1474 } |
|
1475 yield undefined; |
|
1476 |
|
1477 is(count, weightSort.length, |
|
1478 "Correct count for no arg to index.openKeyCursor"); |
|
1479 |
|
1480 count = 0; |
|
1481 |
|
1482 index.openKeyCursor(null).onsuccess = function(event) { |
|
1483 let cursor = event.target.result; |
|
1484 if (cursor) { |
|
1485 count++; |
|
1486 cursor.continue(); |
|
1487 } |
|
1488 else { |
|
1489 testGenerator.next(); |
|
1490 } |
|
1491 } |
|
1492 yield undefined; |
|
1493 |
|
1494 is(count, weightSort.length, |
|
1495 "Correct count for null arg to index.openKeyCursor"); |
|
1496 |
|
1497 count = 0; |
|
1498 |
|
1499 index.openKeyCursor(undefined).onsuccess = function(event) { |
|
1500 let cursor = event.target.result; |
|
1501 if (cursor) { |
|
1502 count++; |
|
1503 cursor.continue(); |
|
1504 } |
|
1505 else { |
|
1506 testGenerator.next(); |
|
1507 } |
|
1508 } |
|
1509 yield undefined; |
|
1510 |
|
1511 is(count, weightSort.length, |
|
1512 "Correct count for undefined arg to index.openKeyCursor"); |
|
1513 |
|
1514 count = 0; |
|
1515 |
|
1516 index.openKeyCursor(data[weightSort[0]].weight).onsuccess = function(event) { |
|
1517 let cursor = event.target.result; |
|
1518 if (cursor) { |
|
1519 count++; |
|
1520 cursor.continue(); |
|
1521 } |
|
1522 else { |
|
1523 testGenerator.next(); |
|
1524 } |
|
1525 } |
|
1526 yield undefined; |
|
1527 |
|
1528 is(count, 1, "Correct count for single key arg to index.openKeyCursor"); |
|
1529 |
|
1530 count = 0; |
|
1531 |
|
1532 index.openKeyCursor("foo").onsuccess = function(event) { |
|
1533 let cursor = event.target.result; |
|
1534 if (cursor) { |
|
1535 count++; |
|
1536 cursor.continue(); |
|
1537 } |
|
1538 else { |
|
1539 testGenerator.next(); |
|
1540 } |
|
1541 } |
|
1542 yield undefined; |
|
1543 |
|
1544 is(count, 0, |
|
1545 "Correct count for non-existent single key arg to index.openKeyCursor"); |
|
1546 |
|
1547 count = 0; |
|
1548 keyRange = IDBKeyRange.only(data[weightSort[0]].weight); |
|
1549 |
|
1550 index.openKeyCursor(keyRange).onsuccess = function(event) { |
|
1551 let cursor = event.target.result; |
|
1552 if (cursor) { |
|
1553 count++; |
|
1554 cursor.continue(); |
|
1555 } |
|
1556 else { |
|
1557 testGenerator.next(); |
|
1558 } |
|
1559 } |
|
1560 yield undefined; |
|
1561 |
|
1562 is(count, 1, |
|
1563 "Correct count for only keyRange arg to index.openKeyCursor"); |
|
1564 |
|
1565 objectStore.mozGetAll(data[1].ssn).onsuccess = grabEventAndContinueHandler; |
|
1566 event = yield undefined; |
|
1567 |
|
1568 is(event.target.result instanceof Array, true, "Got an array"); |
|
1569 is(event.target.result.length, 1, "Got correct length"); |
|
1570 is(event.target.result[0].ssn, data[1].ssn, "Got correct result"); |
|
1571 |
|
1572 objectStore.mozGetAll(null).onsuccess = grabEventAndContinueHandler; |
|
1573 event = yield undefined; |
|
1574 |
|
1575 is(event.target.result instanceof Array, true, "Got an array"); |
|
1576 is(event.target.result.length, data.length, "Got correct length"); |
|
1577 for (let i in event.target.result) { |
|
1578 is(event.target.result[i].ssn, data[i].ssn, "Got correct value"); |
|
1579 } |
|
1580 |
|
1581 objectStore.mozGetAll(undefined).onsuccess = grabEventAndContinueHandler; |
|
1582 event = yield undefined; |
|
1583 |
|
1584 is(event.target.result instanceof Array, true, "Got an array"); |
|
1585 is(event.target.result.length, data.length, "Got correct length"); |
|
1586 for (let i in event.target.result) { |
|
1587 is(event.target.result[i].ssn, data[i].ssn, "Got correct value"); |
|
1588 } |
|
1589 |
|
1590 objectStore.mozGetAll().onsuccess = grabEventAndContinueHandler; |
|
1591 event = yield undefined; |
|
1592 |
|
1593 is(event.target.result instanceof Array, true, "Got an array"); |
|
1594 is(event.target.result.length, data.length, "Got correct length"); |
|
1595 for (let i in event.target.result) { |
|
1596 is(event.target.result[i].ssn, data[i].ssn, "Got correct value"); |
|
1597 } |
|
1598 |
|
1599 keyRange = IDBKeyRange.lowerBound(0); |
|
1600 |
|
1601 objectStore.mozGetAll(keyRange).onsuccess = grabEventAndContinueHandler; |
|
1602 event = yield undefined; |
|
1603 |
|
1604 is(event.target.result instanceof Array, true, "Got an array"); |
|
1605 is(event.target.result.length, data.length, "Got correct length"); |
|
1606 for (let i in event.target.result) { |
|
1607 is(event.target.result[i].ssn, data[i].ssn, "Got correct value"); |
|
1608 } |
|
1609 |
|
1610 index.mozGetAll().onsuccess = grabEventAndContinueHandler; |
|
1611 event = yield undefined; |
|
1612 |
|
1613 is(event.target.result instanceof Array, true, "Got an array"); |
|
1614 is(event.target.result.length, weightSort.length, "Got correct length"); |
|
1615 for (let i in event.target.result) { |
|
1616 is(event.target.result[i].ssn, data[weightSort[i]].ssn, |
|
1617 "Got correct value"); |
|
1618 } |
|
1619 |
|
1620 index.mozGetAll(undefined).onsuccess = grabEventAndContinueHandler; |
|
1621 event = yield undefined; |
|
1622 |
|
1623 is(event.target.result instanceof Array, true, "Got an array"); |
|
1624 is(event.target.result.length, weightSort.length, "Got correct length"); |
|
1625 for (let i in event.target.result) { |
|
1626 is(event.target.result[i].ssn, data[weightSort[i]].ssn, |
|
1627 "Got correct value"); |
|
1628 } |
|
1629 |
|
1630 index.mozGetAll(null).onsuccess = grabEventAndContinueHandler; |
|
1631 event = yield undefined; |
|
1632 |
|
1633 is(event.target.result instanceof Array, true, "Got an array"); |
|
1634 is(event.target.result.length, weightSort.length, "Got correct length"); |
|
1635 for (let i in event.target.result) { |
|
1636 is(event.target.result[i].ssn, data[weightSort[i]].ssn, |
|
1637 "Got correct value"); |
|
1638 } |
|
1639 |
|
1640 index.mozGetAll(data[weightSort[0]].weight).onsuccess = grabEventAndContinueHandler; |
|
1641 event = yield undefined; |
|
1642 |
|
1643 is(event.target.result instanceof Array, true, "Got an array"); |
|
1644 is(event.target.result.length, 1, "Got correct length"); |
|
1645 is(event.target.result[0].ssn, data[weightSort[0]].ssn, "Got correct result"); |
|
1646 |
|
1647 keyRange = IDBKeyRange.lowerBound(0); |
|
1648 |
|
1649 index.mozGetAll(keyRange).onsuccess = grabEventAndContinueHandler; |
|
1650 event = yield undefined; |
|
1651 |
|
1652 is(event.target.result instanceof Array, true, "Got an array"); |
|
1653 is(event.target.result.length, weightSort.length, "Got correct length"); |
|
1654 for (let i in event.target.result) { |
|
1655 is(event.target.result[i].ssn, data[weightSort[i]].ssn, |
|
1656 "Got correct value"); |
|
1657 } |
|
1658 |
|
1659 index.mozGetAllKeys().onsuccess = grabEventAndContinueHandler; |
|
1660 event = yield undefined; |
|
1661 |
|
1662 is(event.target.result instanceof Array, true, "Got an array"); |
|
1663 is(event.target.result.length, weightSort.length, "Got correct length"); |
|
1664 for (let i in event.target.result) { |
|
1665 is(event.target.result[i], data[weightSort[i]].ssn, |
|
1666 "Got correct value"); |
|
1667 } |
|
1668 |
|
1669 index.mozGetAllKeys(undefined).onsuccess = grabEventAndContinueHandler; |
|
1670 event = yield undefined; |
|
1671 |
|
1672 is(event.target.result instanceof Array, true, "Got an array"); |
|
1673 is(event.target.result.length, weightSort.length, "Got correct length"); |
|
1674 for (let i in event.target.result) { |
|
1675 is(event.target.result[i], data[weightSort[i]].ssn, |
|
1676 "Got correct value"); |
|
1677 } |
|
1678 |
|
1679 index.mozGetAllKeys(null).onsuccess = grabEventAndContinueHandler; |
|
1680 event = yield undefined; |
|
1681 |
|
1682 is(event.target.result instanceof Array, true, "Got an array"); |
|
1683 is(event.target.result.length, weightSort.length, "Got correct length"); |
|
1684 for (let i in event.target.result) { |
|
1685 is(event.target.result[i], data[weightSort[i]].ssn, |
|
1686 "Got correct value"); |
|
1687 } |
|
1688 |
|
1689 index.mozGetAllKeys(data[weightSort[0]].weight).onsuccess = grabEventAndContinueHandler; |
|
1690 event = yield undefined; |
|
1691 |
|
1692 is(event.target.result instanceof Array, true, "Got an array"); |
|
1693 is(event.target.result.length, 1, "Got correct length"); |
|
1694 is(event.target.result[0], data[weightSort[0]].ssn, "Got correct result"); |
|
1695 |
|
1696 keyRange = IDBKeyRange.lowerBound(0); |
|
1697 |
|
1698 index.mozGetAllKeys(keyRange).onsuccess = grabEventAndContinueHandler; |
|
1699 event = yield undefined; |
|
1700 |
|
1701 is(event.target.result instanceof Array, true, "Got an array"); |
|
1702 is(event.target.result.length, weightSort.length, "Got correct length"); |
|
1703 for (let i in event.target.result) { |
|
1704 is(event.target.result[i], data[weightSort[i]].ssn, |
|
1705 "Got correct value"); |
|
1706 } |
|
1707 |
|
1708 finishTest(); |
|
1709 yield undefined; |
|
1710 } |
|
1711 |