Wed, 31 Dec 2014 06:55:50 +0100
Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2
1 /**
2 * Any copyright is dedicated to the Public Domain.
3 * http://creativecommons.org/publicdomain/zero/1.0/
4 */
6 var testGenerator = testSteps();
8 function testSteps()
9 {
10 const osName = "people";
11 const indexName = "weight";
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 ];
24 const weightSort = [1, 0, 3, 7, 4, 2];
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;
32 is(event.type, "upgradeneeded", "Got upgradeneeded event");
34 let db = event.target.result;
35 db.onerror = errorHandler;
37 let objectStore = db.createObjectStore(osName, { keyPath: "ssn" });
38 objectStore.createIndex(indexName, "weight", { unique: false });
40 for each (let i in data) {
41 objectStore.add(i);
42 }
44 event = yield undefined;
46 is(event.type, "success", "Got success event");
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 }
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 }
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 }
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 }
83 objectStore = db.transaction(osName).objectStore(osName);
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 }
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 }
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 }
112 objectStore.get(data[2].ssn).onsuccess = grabEventAndContinueHandler;
113 event = yield undefined;
115 is(event.target.result.name, data[2].name, "Correct data");
117 let keyRange = IDBKeyRange.only(data[2].ssn);
119 objectStore.get(keyRange).onsuccess = grabEventAndContinueHandler;
120 event = yield undefined;
122 is(event.target.result.name, data[2].name, "Correct data");
124 keyRange = IDBKeyRange.lowerBound(data[2].ssn);
126 objectStore.get(keyRange).onsuccess = grabEventAndContinueHandler;
127 event = yield undefined;
129 is(event.target.result.name, data[2].name, "Correct data");
131 keyRange = IDBKeyRange.lowerBound(data[2].ssn, true);
133 objectStore.get(keyRange).onsuccess = grabEventAndContinueHandler;
134 event = yield undefined;
136 is(event.target.result.name, data[3].name, "Correct data");
138 keyRange = IDBKeyRange.upperBound(data[2].ssn);
140 objectStore.get(keyRange).onsuccess = grabEventAndContinueHandler;
141 event = yield undefined;
143 is(event.target.result.name, data[0].name, "Correct data");
145 keyRange = IDBKeyRange.bound(data[2].ssn, data[4].ssn);
147 objectStore.get(keyRange).onsuccess = grabEventAndContinueHandler;
148 event = yield undefined;
150 is(event.target.result.name, data[2].name, "Correct data");
152 keyRange = IDBKeyRange.bound(data[2].ssn, data[4].ssn, true);
154 objectStore.get(keyRange).onsuccess = grabEventAndContinueHandler;
155 event = yield undefined;
157 is(event.target.result.name, data[3].name, "Correct data");
159 objectStore = db.transaction(osName, "readwrite")
160 .objectStore(osName);
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 }
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 }
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 }
189 objectStore.count().onsuccess = grabEventAndContinueHandler;
190 event = yield undefined;
192 is(event.target.result, data.length, "Correct count");
194 objectStore.delete(data[2].ssn).onsuccess = grabEventAndContinueHandler;
195 event = yield undefined;
197 ok(event.target.result === undefined, "Correct result");
199 objectStore.count().onsuccess = grabEventAndContinueHandler;
200 event = yield undefined;
202 is(event.target.result, data.length - 1, "Correct count");
204 keyRange = IDBKeyRange.bound(data[3].ssn, data[5].ssn);
206 objectStore.delete(keyRange).onsuccess = grabEventAndContinueHandler;
207 event = yield undefined;
209 ok(event.target.result === undefined, "Correct result");
211 objectStore.count().onsuccess = grabEventAndContinueHandler;
212 event = yield undefined;
214 is(event.target.result, data.length - 4, "Correct count");
216 keyRange = IDBKeyRange.lowerBound(10);
218 objectStore.delete(keyRange).onsuccess = grabEventAndContinueHandler;
219 event = yield undefined;
221 ok(event.target.result === undefined, "Correct result");
223 objectStore.count().onsuccess = grabEventAndContinueHandler;
224 event = yield undefined;
226 is(event.target.result, 0, "Correct count");
228 event.target.transaction.oncomplete = grabEventAndContinueHandler;
230 for each (let i in data) {
231 objectStore.add(i);
232 }
234 yield undefined;
236 objectStore = db.transaction(osName).objectStore(osName);
238 objectStore.count().onsuccess = grabEventAndContinueHandler;
239 event = yield undefined;
241 is(event.target.result, data.length, "Correct count");
243 let count = 0;
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;
257 is(count, data.length, "Correct count for no arg to openCursor");
259 count = 0;
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;
273 is(count, data.length, "Correct count for null arg to openCursor");
275 count = 0;
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;
289 is(count, data.length, "Correct count for undefined arg to openCursor");
291 count = 0;
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;
305 is(count, 1, "Correct count for single key arg to openCursor");
307 count = 0;
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;
321 is(count, 0,
322 "Correct count for non-existent single key arg to openCursor");
324 count = 0;
325 keyRange = IDBKeyRange.only(data[2].ssn);
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;
339 is(count, 1, "Correct count for only keyRange arg to openCursor");
341 count = 0;
342 keyRange = IDBKeyRange.lowerBound(data[2].ssn);
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;
356 is(count, data.length - 2,
357 "Correct count for lowerBound arg to openCursor");
359 count = 0;
360 keyRange = IDBKeyRange.lowerBound(data[2].ssn, true);
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;
374 is(count, data.length - 3,
375 "Correct count for lowerBound arg to openCursor");
377 count = 0;
378 keyRange = IDBKeyRange.lowerBound("foo");
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;
392 is(count, 0,
393 "Correct count for non-existent lowerBound arg to openCursor");
395 count = 0;
396 keyRange = IDBKeyRange.bound(data[2].ssn, data[3].ssn);
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;
410 is(count, 2, "Correct count for bound arg to openCursor");
412 count = 0;
413 keyRange = IDBKeyRange.bound(data[2].ssn, data[3].ssn, true);
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;
427 is(count, 1, "Correct count for bound arg to openCursor");
429 count = 0;
430 keyRange = IDBKeyRange.bound(data[2].ssn, data[3].ssn, true, true);
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;
444 is(count, 0, "Correct count for bound arg to openCursor");
446 let index = objectStore.index(indexName);
448 count = 0;
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;
462 is(count, weightSort.length,
463 "Correct count for unspecified arg to index.openKeyCursor");
465 count = 0;
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;
479 is(count, weightSort.length,
480 "Correct count for null arg to index.openKeyCursor");
482 count = 0;
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;
496 is(count, weightSort.length,
497 "Correct count for undefined arg to index.openKeyCursor");
499 count = 0;
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;
513 is(count, 1, "Correct count for single key arg to index.openKeyCursor");
515 count = 0;
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;
529 is(count, 0,
530 "Correct count for non-existent key arg to index.openKeyCursor");
532 count = 0;
533 keyRange = IDBKeyRange.only("foo");
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;
547 is(count, 0,
548 "Correct count for non-existent keyRange arg to index.openKeyCursor");
550 count = 0;
551 keyRange = IDBKeyRange.only(data[0].weight);
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;
565 is(count, 1,
566 "Correct count for only keyRange arg to index.openKeyCursor");
568 count = 0;
569 keyRange = IDBKeyRange.lowerBound(data[weightSort[0]].weight);
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;
583 is(count, weightSort.length,
584 "Correct count for lowerBound keyRange arg to index.openKeyCursor");
586 count = 0;
587 keyRange = IDBKeyRange.lowerBound(data[weightSort[0]].weight, true);
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;
601 is(count, weightSort.length - 1,
602 "Correct count for lowerBound keyRange arg to index.openKeyCursor");
604 count = 0;
605 keyRange = IDBKeyRange.lowerBound("foo");
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;
619 is(count, 0,
620 "Correct count for lowerBound keyRange arg to index.openKeyCursor");
622 count = 0;
623 keyRange = IDBKeyRange.upperBound(data[weightSort[0]].weight);
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;
637 is(count, 1,
638 "Correct count for upperBound keyRange arg to index.openKeyCursor");
640 count = 0;
641 keyRange = IDBKeyRange.upperBound(data[weightSort[0]].weight, true);
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;
655 is(count, 0,
656 "Correct count for upperBound keyRange arg to index.openKeyCursor");
658 count = 0;
659 keyRange = IDBKeyRange.upperBound(data[weightSort[weightSort.length - 1]].weight);
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;
673 is(count, weightSort.length,
674 "Correct count for upperBound keyRange arg to index.openKeyCursor");
676 count = 0;
677 keyRange = IDBKeyRange.upperBound(data[weightSort[weightSort.length - 1]].weight,
678 true);
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;
692 is(count, weightSort.length - 1,
693 "Correct count for upperBound keyRange arg to index.openKeyCursor");
695 count = 0;
696 keyRange = IDBKeyRange.upperBound("foo");
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;
710 is(count, weightSort.length,
711 "Correct count for upperBound keyRange arg to index.openKeyCursor");
713 count = 0;
714 keyRange = IDBKeyRange.upperBound(0);
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;
728 is(count, 0,
729 "Correct count for upperBound keyRange arg to index.openKeyCursor");
731 count = 0;
732 keyRange = IDBKeyRange.bound(data[weightSort[0]].weight,
733 data[weightSort[weightSort.length - 1]].weight);
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;
747 is(count, weightSort.length,
748 "Correct count for bound keyRange arg to index.openKeyCursor");
750 count = 0;
751 keyRange = IDBKeyRange.bound(data[weightSort[0]].weight,
752 data[weightSort[weightSort.length - 1]].weight,
753 true);
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;
767 is(count, weightSort.length - 1,
768 "Correct count for bound keyRange arg to index.openKeyCursor");
770 count = 0;
771 keyRange = IDBKeyRange.bound(data[weightSort[0]].weight,
772 data[weightSort[weightSort.length - 1]].weight,
773 true, true);
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;
787 is(count, weightSort.length - 2,
788 "Correct count for bound keyRange arg to index.openKeyCursor");
790 count = 0;
791 keyRange = IDBKeyRange.bound(data[weightSort[0]].weight - 1,
792 data[weightSort[weightSort.length - 1]].weight + 1);
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;
806 is(count, weightSort.length,
807 "Correct count for bound keyRange arg to index.openKeyCursor");
809 count = 0;
810 keyRange = IDBKeyRange.bound(data[weightSort[0]].weight - 2,
811 data[weightSort[0]].weight - 1);
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;
825 is(count, 0,
826 "Correct count for bound keyRange arg to index.openKeyCursor");
828 count = 0;
829 keyRange = IDBKeyRange.bound(data[weightSort[1]].weight,
830 data[weightSort[2]].weight);
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;
844 is(count, 3,
845 "Correct count for bound keyRange arg to index.openKeyCursor");
847 count = 0;
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;
861 is(count, weightSort.length,
862 "Correct count for unspecified arg to index.openCursor");
864 count = 0;
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;
878 is(count, weightSort.length,
879 "Correct count for null arg to index.openCursor");
881 count = 0;
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;
895 is(count, weightSort.length,
896 "Correct count for undefined arg to index.openCursor");
898 count = 0;
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;
912 is(count, 1, "Correct count for single key arg to index.openCursor");
914 count = 0;
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;
928 is(count, 0,
929 "Correct count for non-existent key arg to index.openCursor");
931 count = 0;
932 keyRange = IDBKeyRange.only("foo");
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;
946 is(count, 0,
947 "Correct count for non-existent keyRange arg to index.openCursor");
949 count = 0;
950 keyRange = IDBKeyRange.only(data[0].weight);
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;
964 is(count, 1,
965 "Correct count for only keyRange arg to index.openCursor");
967 count = 0;
968 keyRange = IDBKeyRange.lowerBound(data[weightSort[0]].weight);
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;
982 is(count, weightSort.length,
983 "Correct count for lowerBound keyRange arg to index.openCursor");
985 count = 0;
986 keyRange = IDBKeyRange.lowerBound(data[weightSort[0]].weight, true);
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;
1000 is(count, weightSort.length - 1,
1001 "Correct count for lowerBound keyRange arg to index.openCursor");
1003 count = 0;
1004 keyRange = IDBKeyRange.lowerBound("foo");
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;
1018 is(count, 0,
1019 "Correct count for lowerBound keyRange arg to index.openCursor");
1021 count = 0;
1022 keyRange = IDBKeyRange.upperBound(data[weightSort[0]].weight);
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;
1036 is(count, 1,
1037 "Correct count for upperBound keyRange arg to index.openCursor");
1039 count = 0;
1040 keyRange = IDBKeyRange.upperBound(data[weightSort[0]].weight, true);
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;
1054 is(count, 0,
1055 "Correct count for upperBound keyRange arg to index.openCursor");
1057 count = 0;
1058 keyRange = IDBKeyRange.upperBound(data[weightSort[weightSort.length - 1]].weight);
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;
1072 is(count, weightSort.length,
1073 "Correct count for upperBound keyRange arg to index.openCursor");
1075 count = 0;
1076 keyRange = IDBKeyRange.upperBound(data[weightSort[weightSort.length - 1]].weight,
1077 true);
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;
1091 is(count, weightSort.length - 1,
1092 "Correct count for upperBound keyRange arg to index.openCursor");
1094 count = 0;
1095 keyRange = IDBKeyRange.upperBound("foo");
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;
1109 is(count, weightSort.length,
1110 "Correct count for upperBound keyRange arg to index.openCursor");
1112 count = 0;
1113 keyRange = IDBKeyRange.upperBound(0);
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;
1127 is(count, 0,
1128 "Correct count for upperBound keyRange arg to index.openCursor");
1130 count = 0;
1131 keyRange = IDBKeyRange.bound(data[weightSort[0]].weight,
1132 data[weightSort[weightSort.length - 1]].weight);
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;
1146 is(count, weightSort.length,
1147 "Correct count for bound keyRange arg to index.openCursor");
1149 count = 0;
1150 keyRange = IDBKeyRange.bound(data[weightSort[0]].weight,
1151 data[weightSort[weightSort.length - 1]].weight,
1152 true);
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;
1166 is(count, weightSort.length - 1,
1167 "Correct count for bound keyRange arg to index.openCursor");
1169 count = 0;
1170 keyRange = IDBKeyRange.bound(data[weightSort[0]].weight,
1171 data[weightSort[weightSort.length - 1]].weight,
1172 true, true);
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;
1186 is(count, weightSort.length - 2,
1187 "Correct count for bound keyRange arg to index.openCursor");
1189 count = 0;
1190 keyRange = IDBKeyRange.bound(data[weightSort[0]].weight - 1,
1191 data[weightSort[weightSort.length - 1]].weight + 1);
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;
1205 is(count, weightSort.length,
1206 "Correct count for bound keyRange arg to index.openCursor");
1208 count = 0;
1209 keyRange = IDBKeyRange.bound(data[weightSort[0]].weight - 2,
1210 data[weightSort[0]].weight - 1);
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;
1224 is(count, 0,
1225 "Correct count for bound keyRange arg to index.openCursor");
1227 count = 0;
1228 keyRange = IDBKeyRange.bound(data[weightSort[1]].weight,
1229 data[weightSort[2]].weight);
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;
1243 is(count, 3,
1244 "Correct count for bound keyRange arg to index.openCursor");
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 }
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 }
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 }
1273 index.get(data[0].weight).onsuccess = grabEventAndContinueHandler;
1274 event = yield undefined;
1276 is(event.target.result.weight, data[0].weight, "Got correct result");
1278 keyRange = IDBKeyRange.only(data[0].weight);
1280 index.get(keyRange).onsuccess = grabEventAndContinueHandler;
1281 event = yield undefined;
1283 is(event.target.result.weight, data[0].weight, "Got correct result");
1285 keyRange = IDBKeyRange.lowerBound(data[weightSort[0]].weight);
1287 index.get(keyRange).onsuccess = grabEventAndContinueHandler;
1288 event = yield undefined;
1290 is(event.target.result.weight, data[weightSort[0]].weight,
1291 "Got correct result");
1293 keyRange = IDBKeyRange.lowerBound(data[weightSort[0]].weight - 1);
1295 index.get(keyRange).onsuccess = grabEventAndContinueHandler;
1296 event = yield undefined;
1298 is(event.target.result.weight, data[weightSort[0]].weight,
1299 "Got correct result");
1301 keyRange = IDBKeyRange.lowerBound(data[weightSort[0]].weight + 1);
1303 index.get(keyRange).onsuccess = grabEventAndContinueHandler;
1304 event = yield undefined;
1306 is(event.target.result.weight, data[weightSort[1]].weight,
1307 "Got correct result");
1309 keyRange = IDBKeyRange.lowerBound(data[weightSort[0]].weight, true);
1311 index.get(keyRange).onsuccess = grabEventAndContinueHandler;
1312 event = yield undefined;
1314 is(event.target.result.weight, data[weightSort[1]].weight,
1315 "Got correct result");
1317 keyRange = IDBKeyRange.bound(data[weightSort[0]].weight,
1318 data[weightSort[1]].weight);
1320 index.get(keyRange).onsuccess = grabEventAndContinueHandler;
1321 event = yield undefined;
1323 is(event.target.result.weight, data[weightSort[0]].weight,
1324 "Got correct result");
1326 keyRange = IDBKeyRange.bound(data[weightSort[0]].weight,
1327 data[weightSort[1]].weight, true);
1329 index.get(keyRange).onsuccess = grabEventAndContinueHandler;
1330 event = yield undefined;
1332 is(event.target.result.weight, data[weightSort[1]].weight,
1333 "Got correct result");
1335 keyRange = IDBKeyRange.bound(data[weightSort[0]].weight,
1336 data[weightSort[1]].weight, true, true);
1338 index.get(keyRange).onsuccess = grabEventAndContinueHandler;
1339 event = yield undefined;
1341 is(event.target.result, undefined, "Got correct result");
1343 keyRange = IDBKeyRange.upperBound(data[weightSort[5]].weight);
1345 index.get(keyRange).onsuccess = grabEventAndContinueHandler;
1346 event = yield undefined;
1348 is(event.target.result.weight, data[weightSort[0]].weight,
1349 "Got correct result");
1351 keyRange = IDBKeyRange.upperBound(data[weightSort[0]].weight, true);
1353 index.get(keyRange).onsuccess = grabEventAndContinueHandler;
1354 event = yield undefined;
1356 is(event.target.result, undefined, "Got correct result");
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 }
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 }
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 }
1385 index.getKey(data[0].weight).onsuccess = grabEventAndContinueHandler;
1386 event = yield undefined;
1388 is(event.target.result, data[0].ssn, "Got correct result");
1390 keyRange = IDBKeyRange.only(data[0].weight);
1392 index.getKey(keyRange).onsuccess = grabEventAndContinueHandler;
1393 event = yield undefined;
1395 is(event.target.result, data[0].ssn, "Got correct result");
1397 keyRange = IDBKeyRange.lowerBound(data[weightSort[0]].weight);
1399 index.getKey(keyRange).onsuccess = grabEventAndContinueHandler;
1400 event = yield undefined;
1402 is(event.target.result, data[weightSort[0]].ssn, "Got correct result");
1404 keyRange = IDBKeyRange.lowerBound(data[weightSort[0]].weight - 1);
1406 index.getKey(keyRange).onsuccess = grabEventAndContinueHandler;
1407 event = yield undefined;
1409 is(event.target.result, data[weightSort[0]].ssn, "Got correct result");
1411 keyRange = IDBKeyRange.lowerBound(data[weightSort[0]].weight + 1);
1413 index.getKey(keyRange).onsuccess = grabEventAndContinueHandler;
1414 event = yield undefined;
1416 is(event.target.result, data[weightSort[1]].ssn, "Got correct result");
1418 keyRange = IDBKeyRange.lowerBound(data[weightSort[0]].weight, true);
1420 index.getKey(keyRange).onsuccess = grabEventAndContinueHandler;
1421 event = yield undefined;
1423 is(event.target.result, data[weightSort[1]].ssn, "Got correct result");
1425 keyRange = IDBKeyRange.bound(data[weightSort[0]].weight,
1426 data[weightSort[1]].weight);
1428 index.getKey(keyRange).onsuccess = grabEventAndContinueHandler;
1429 event = yield undefined;
1431 is(event.target.result, data[weightSort[0]].ssn, "Got correct result");
1433 keyRange = IDBKeyRange.bound(data[weightSort[0]].weight,
1434 data[weightSort[1]].weight, true);
1436 index.getKey(keyRange).onsuccess = grabEventAndContinueHandler;
1437 event = yield undefined;
1439 is(event.target.result, data[weightSort[1]].ssn, "Got correct result");
1441 keyRange = IDBKeyRange.bound(data[weightSort[0]].weight,
1442 data[weightSort[1]].weight, true, true);
1444 index.getKey(keyRange).onsuccess = grabEventAndContinueHandler;
1445 event = yield undefined;
1447 is(event.target.result, undefined, "Got correct result");
1449 keyRange = IDBKeyRange.upperBound(data[weightSort[5]].weight);
1451 index.getKey(keyRange).onsuccess = grabEventAndContinueHandler;
1452 event = yield undefined;
1454 is(event.target.result, data[weightSort[0]].ssn, "Got correct result");
1456 keyRange = IDBKeyRange.upperBound(data[weightSort[0]].weight, true);
1458 index.getKey(keyRange).onsuccess = grabEventAndContinueHandler;
1459 event = yield undefined;
1461 is(event.target.result, undefined, "Got correct result");
1463 count = 0;
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;
1477 is(count, weightSort.length,
1478 "Correct count for no arg to index.openKeyCursor");
1480 count = 0;
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;
1494 is(count, weightSort.length,
1495 "Correct count for null arg to index.openKeyCursor");
1497 count = 0;
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;
1511 is(count, weightSort.length,
1512 "Correct count for undefined arg to index.openKeyCursor");
1514 count = 0;
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;
1528 is(count, 1, "Correct count for single key arg to index.openKeyCursor");
1530 count = 0;
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;
1544 is(count, 0,
1545 "Correct count for non-existent single key arg to index.openKeyCursor");
1547 count = 0;
1548 keyRange = IDBKeyRange.only(data[weightSort[0]].weight);
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;
1562 is(count, 1,
1563 "Correct count for only keyRange arg to index.openKeyCursor");
1565 objectStore.mozGetAll(data[1].ssn).onsuccess = grabEventAndContinueHandler;
1566 event = yield undefined;
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");
1572 objectStore.mozGetAll(null).onsuccess = grabEventAndContinueHandler;
1573 event = yield undefined;
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 }
1581 objectStore.mozGetAll(undefined).onsuccess = grabEventAndContinueHandler;
1582 event = yield undefined;
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 }
1590 objectStore.mozGetAll().onsuccess = grabEventAndContinueHandler;
1591 event = yield undefined;
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 }
1599 keyRange = IDBKeyRange.lowerBound(0);
1601 objectStore.mozGetAll(keyRange).onsuccess = grabEventAndContinueHandler;
1602 event = yield undefined;
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 }
1610 index.mozGetAll().onsuccess = grabEventAndContinueHandler;
1611 event = yield undefined;
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 }
1620 index.mozGetAll(undefined).onsuccess = grabEventAndContinueHandler;
1621 event = yield undefined;
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 }
1630 index.mozGetAll(null).onsuccess = grabEventAndContinueHandler;
1631 event = yield undefined;
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 }
1640 index.mozGetAll(data[weightSort[0]].weight).onsuccess = grabEventAndContinueHandler;
1641 event = yield undefined;
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");
1647 keyRange = IDBKeyRange.lowerBound(0);
1649 index.mozGetAll(keyRange).onsuccess = grabEventAndContinueHandler;
1650 event = yield undefined;
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 }
1659 index.mozGetAllKeys().onsuccess = grabEventAndContinueHandler;
1660 event = yield undefined;
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 }
1669 index.mozGetAllKeys(undefined).onsuccess = grabEventAndContinueHandler;
1670 event = yield undefined;
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 }
1679 index.mozGetAllKeys(null).onsuccess = grabEventAndContinueHandler;
1680 event = yield undefined;
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 }
1689 index.mozGetAllKeys(data[weightSort[0]].weight).onsuccess = grabEventAndContinueHandler;
1690 event = yield undefined;
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");
1696 keyRange = IDBKeyRange.lowerBound(0);
1698 index.mozGetAllKeys(keyRange).onsuccess = grabEventAndContinueHandler;
1699 event = yield undefined;
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 }
1708 finishTest();
1709 yield undefined;
1710 }