Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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 name = this.window ? window.location.pathname : "Splendid Test";
12 const objectStoreName = "People";
14 const objectStoreData = [
15 { key: "237-23-7732", value: { name: "Bob", height: 60, weight: 120 } },
16 { key: "237-23-7733", value: { name: "Ann", height: 52, weight: 110 } },
17 { key: "237-23-7734", value: { name: "Ron", height: 73, weight: 180 } },
18 { key: "237-23-7735", value: { name: "Sue", height: 58, weight: 130 } },
19 { key: "237-23-7736", value: { name: "Joe", height: 65, weight: 150 } },
20 { key: "237-23-7737", value: { name: "Pat", height: 65 } }
21 ];
23 const indexData = [
24 { name: "name", keyPath: "name", options: { unique: true } },
25 { name: "height", keyPath: "height", options: { } },
26 { name: "weight", keyPath: "weight", options: { unique: false } }
27 ];
29 const objectStoreDataNameSort = [
30 { key: "237-23-7733", value: { name: "Ann", height: 52, weight: 110 } },
31 { key: "237-23-7732", value: { name: "Bob", height: 60, weight: 120 } },
32 { key: "237-23-7736", value: { name: "Joe", height: 65, weight: 150 } },
33 { key: "237-23-7737", value: { name: "Pat", height: 65 } },
34 { key: "237-23-7734", value: { name: "Ron", height: 73, weight: 180 } },
35 { key: "237-23-7735", value: { name: "Sue", height: 58, weight: 130 } }
36 ];
38 const objectStoreDataWeightSort = [
39 { key: "237-23-7733", value: { name: "Ann", height: 52, weight: 110 } },
40 { key: "237-23-7732", value: { name: "Bob", height: 60, weight: 120 } },
41 { key: "237-23-7735", value: { name: "Sue", height: 58, weight: 130 } },
42 { key: "237-23-7736", value: { name: "Joe", height: 65, weight: 150 } },
43 { key: "237-23-7734", value: { name: "Ron", height: 73, weight: 180 } }
44 ];
46 const objectStoreDataHeightSort = [
47 { key: "237-23-7733", value: { name: "Ann", height: 52, weight: 110 } },
48 { key: "237-23-7735", value: { name: "Sue", height: 58, weight: 130 } },
49 { key: "237-23-7732", value: { name: "Bob", height: 60, weight: 120 } },
50 { key: "237-23-7736", value: { name: "Joe", height: 65, weight: 150 } },
51 { key: "237-23-7737", value: { name: "Pat", height: 65 } },
52 { key: "237-23-7734", value: { name: "Ron", height: 73, weight: 180 } }
53 ];
55 let request = indexedDB.open(name, 1);
56 request.onerror = errorHandler;
57 request.onupgradeneeded = grabEventAndContinueHandler;
58 request.onsuccess = grabEventAndContinueHandler;
59 let event = yield undefined;
60 let db = event.target.result;
62 let objectStore = db.createObjectStore(objectStoreName, { keyPath: null });
64 // First, add all our data to the object store.
65 let addedData = 0;
66 for (let i in objectStoreData) {
67 request = objectStore.add(objectStoreData[i].value,
68 objectStoreData[i].key);
69 request.onerror = errorHandler;
70 request.onsuccess = function(event) {
71 if (++addedData == objectStoreData.length) {
72 testGenerator.send(event);
73 }
74 }
75 }
76 event = yield undefined;
77 // Now create the indexes.
78 for (let i in indexData) {
79 objectStore.createIndex(indexData[i].name, indexData[i].keyPath,
80 indexData[i].options);
81 }
82 is(objectStore.indexNames.length, indexData.length, "Good index count");
83 yield undefined;
84 objectStore = db.transaction(objectStoreName)
85 .objectStore(objectStoreName);
87 // Check global properties to make sure they are correct.
88 is(objectStore.indexNames.length, indexData.length, "Good index count");
89 for (let i in indexData) {
90 let found = false;
91 for (let j = 0; j < objectStore.indexNames.length; j++) {
92 if (objectStore.indexNames.item(j) == indexData[i].name) {
93 found = true;
94 break;
95 }
96 }
97 is(found, true, "objectStore has our index");
98 let index = objectStore.index(indexData[i].name);
99 is(index.name, indexData[i].name, "Correct name");
100 is(index.storeName, objectStore.name, "Correct store name");
101 is(index.keyPath, indexData[i].keyPath, "Correct keyPath");
102 is(index.unique, indexData[i].options.unique ? true : false,
103 "Correct unique value");
104 }
106 request = objectStore.index("name").getKey("Bob");
107 request.onerror = errorHandler;
108 request.onsuccess = grabEventAndContinueHandler;
109 event = yield undefined;
111 is(event.target.result, "237-23-7732", "Correct key returned!");
113 request = objectStore.index("name").get("Bob");
114 request.onerror = errorHandler;
115 request.onsuccess = grabEventAndContinueHandler;
116 event = yield undefined;
118 is(event.target.result.name, "Bob", "Correct name returned!");
119 is(event.target.result.height, 60, "Correct height returned!");
120 is(event.target.result.weight, 120, "Correct weight returned!");
122 ok(true, "Test group 1");
124 let keyIndex = 0;
126 request = objectStore.index("name").openKeyCursor();
127 request.onerror = errorHandler;
128 request.onsuccess = function (event) {
129 let cursor = event.target.result;
130 if (cursor) {
131 is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
132 "Correct key");
133 is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key,
134 "Correct primary key");
135 ok(!("value" in cursor), "No value");
137 cursor.continue();
139 is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
140 "Correct key");
141 is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key,
142 "Correct value");
143 ok(!("value" in cursor), "No value");
145 keyIndex++;
146 }
147 else {
148 testGenerator.next();
149 }
150 }
151 yield undefined;
153 is(keyIndex, objectStoreData.length, "Saw all the expected keys");
155 ok(true, "Test group 2");
157 keyIndex = 0;
159 request = objectStore.index("weight").openKeyCursor(null, "next");
160 request.onerror = errorHandler;
161 request.onsuccess = function (event) {
162 let cursor = event.target.result;
163 if (cursor) {
164 is(cursor.key, objectStoreDataWeightSort[keyIndex].value.weight,
165 "Correct key");
166 is(cursor.primaryKey, objectStoreDataWeightSort[keyIndex].key,
167 "Correct value");
169 cursor.continue();
171 is(cursor.key, objectStoreDataWeightSort[keyIndex].value.weight,
172 "Correct key");
173 is(cursor.primaryKey, objectStoreDataWeightSort[keyIndex].key,
174 "Correct value");
176 keyIndex++;
177 }
178 else {
179 testGenerator.next();
180 }
181 }
182 yield undefined;
184 is(keyIndex, objectStoreData.length - 1, "Saw all the expected keys");
186 // Check that the name index enforces its unique constraint.
187 objectStore = db.transaction(objectStoreName, "readwrite")
188 .objectStore(objectStoreName);
189 request = objectStore.add({ name: "Bob", height: 62, weight: 170 },
190 "237-23-7738");
191 request.addEventListener("error", new ExpectError("ConstraintError", true));
192 request.onsuccess = unexpectedSuccessHandler;
193 event = yield undefined;
195 ok(true, "Test group 3");
197 keyIndex = objectStoreDataNameSort.length - 1;
199 request = objectStore.index("name").openKeyCursor(null, "prev");
200 request.onerror = errorHandler;
201 request.onsuccess = function (event) {
202 let cursor = event.target.result;
203 if (cursor) {
204 is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
205 "Correct key");
206 is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key,
207 "Correct value");
209 cursor.continue();
211 is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
212 "Correct key");
213 is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key,
214 "Correct value");
216 keyIndex--;
217 }
218 else {
219 testGenerator.next();
220 }
221 }
222 yield undefined;
224 is(keyIndex, -1, "Saw all the expected keys");
226 ok(true, "Test group 4");
228 keyIndex = 1;
229 let keyRange = IDBKeyRange.bound("Bob", "Ron");
231 request = objectStore.index("name").openKeyCursor(keyRange);
232 request.onerror = errorHandler;
233 request.onsuccess = function (event) {
234 let cursor = event.target.result;
235 if (cursor) {
236 is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
237 "Correct key");
238 is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key,
239 "Correct value");
241 cursor.continue();
242 keyIndex++;
243 }
244 else {
245 testGenerator.next();
246 }
247 }
248 yield undefined;
250 is(keyIndex, 5, "Saw all the expected keys");
252 ok(true, "Test group 5");
254 keyIndex = 2;
255 let keyRange = IDBKeyRange.bound("Bob", "Ron", true);
257 request = objectStore.index("name").openKeyCursor(keyRange);
258 request.onerror = errorHandler;
259 request.onsuccess = function (event) {
260 let cursor = event.target.result;
261 if (cursor) {
262 is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
263 "Correct key");
264 is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key,
265 "Correct value");
267 cursor.continue();
268 keyIndex++;
269 }
270 else {
271 testGenerator.next();
272 }
273 }
274 yield undefined;
276 is(keyIndex, 5, "Saw all the expected keys");
278 ok(true, "Test group 6");
280 keyIndex = 1;
281 let keyRange = IDBKeyRange.bound("Bob", "Ron", false, true);
283 request = objectStore.index("name").openKeyCursor(keyRange);
284 request.onerror = errorHandler;
285 request.onsuccess = function (event) {
286 let cursor = event.target.result;
287 if (cursor) {
288 is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
289 "Correct key");
290 is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key,
291 "Correct value");
293 cursor.continue();
294 keyIndex++;
295 }
296 else {
297 testGenerator.next();
298 }
299 }
300 yield undefined;
302 is(keyIndex, 4, "Saw all the expected keys");
304 ok(true, "Test group 7");
306 keyIndex = 2;
307 keyRange = IDBKeyRange.bound("Bob", "Ron", true, true);
309 request = objectStore.index("name").openKeyCursor(keyRange);
310 request.onerror = errorHandler;
311 request.onsuccess = function (event) {
312 let cursor = event.target.result;
313 if (cursor) {
314 is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
315 "Correct key");
316 is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key,
317 "Correct value");
319 cursor.continue();
320 keyIndex++;
321 }
322 else {
323 testGenerator.next();
324 }
325 }
326 yield undefined;
328 is(keyIndex, 4, "Saw all the expected keys");
330 ok(true, "Test group 8");
332 keyIndex = 1;
333 keyRange = IDBKeyRange.lowerBound("Bob");
335 request = objectStore.index("name").openKeyCursor(keyRange);
336 request.onerror = errorHandler;
337 request.onsuccess = function (event) {
338 let cursor = event.target.result;
339 if (cursor) {
340 is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
341 "Correct key");
342 is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key,
343 "Correct value");
345 cursor.continue();
346 keyIndex++;
347 }
348 else {
349 testGenerator.next();
350 }
351 }
352 yield undefined;
354 is(keyIndex, objectStoreDataNameSort.length, "Saw all the expected keys");
356 ok(true, "Test group 9");
358 keyIndex = 2;
359 keyRange = IDBKeyRange.lowerBound("Bob", true);
361 request = objectStore.index("name").openKeyCursor(keyRange);
362 request.onerror = errorHandler;
363 request.onsuccess = function (event) {
364 let cursor = event.target.result;
365 if (cursor) {
366 is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
367 "Correct key");
368 is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key,
369 "Correct value");
371 cursor.continue();
372 keyIndex++;
373 }
374 else {
375 testGenerator.next();
376 }
377 }
378 yield undefined;
380 is(keyIndex, objectStoreDataNameSort.length, "Saw all the expected keys");
382 ok(true, "Test group 10");
384 keyIndex = 0;
385 keyRange = IDBKeyRange.upperBound("Joe");
387 request = objectStore.index("name").openKeyCursor(keyRange);
388 request.onerror = errorHandler;
389 request.onsuccess = function (event) {
390 let cursor = event.target.result;
391 if (cursor) {
392 is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
393 "Correct key");
394 is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key,
395 "Correct value");
397 cursor.continue();
398 keyIndex++;
399 }
400 else {
401 testGenerator.next();
402 }
403 }
404 yield undefined;
406 is(keyIndex, 3, "Saw all the expected keys");
408 ok(true, "Test group 11");
410 keyIndex = 0;
411 keyRange = IDBKeyRange.upperBound("Joe", true);
413 request = objectStore.index("name").openKeyCursor(keyRange);
414 request.onerror = errorHandler;
415 request.onsuccess = function (event) {
416 let cursor = event.target.result;
417 if (cursor) {
418 is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
419 "Correct key");
420 is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key,
421 "Correct value");
423 cursor.continue();
424 keyIndex++;
425 }
426 else {
427 testGenerator.next();
428 }
429 }
430 yield undefined;
432 is(keyIndex, 2, "Saw all the expected keys");
434 ok(true, "Test group 12");
436 keyIndex = 3;
437 keyRange = IDBKeyRange.only("Pat");
439 request = objectStore.index("name").openKeyCursor(keyRange);
440 request.onerror = errorHandler;
441 request.onsuccess = function (event) {
442 let cursor = event.target.result;
443 if (cursor) {
444 is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
445 "Correct key");
446 is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key,
447 "Correct value");
449 cursor.continue();
450 keyIndex++;
451 }
452 else {
453 testGenerator.next();
454 }
455 }
456 yield undefined;
458 is(keyIndex, 4, "Saw all the expected keys");
460 ok(true, "Test group 13");
462 keyIndex = 0;
464 request = objectStore.index("name").openCursor();
465 request.onerror = errorHandler;
466 request.onsuccess = function (event) {
467 let cursor = event.target.result;
468 if (cursor) {
469 is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
470 "Correct key");
471 is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key,
472 "Correct primary key");
473 is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name,
474 "Correct name");
475 is(cursor.value.height,
476 objectStoreDataNameSort[keyIndex].value.height,
477 "Correct height");
478 if ("weight" in cursor.value) {
479 is(cursor.value.weight,
480 objectStoreDataNameSort[keyIndex].value.weight,
481 "Correct weight");
482 }
484 cursor.continue();
486 is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
487 "Correct key");
488 is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key,
489 "Correct primary key");
490 is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name,
491 "Correct name");
492 is(cursor.value.height,
493 objectStoreDataNameSort[keyIndex].value.height,
494 "Correct height");
495 if ("weight" in cursor.value) {
496 is(cursor.value.weight,
497 objectStoreDataNameSort[keyIndex].value.weight,
498 "Correct weight");
499 }
501 keyIndex++;
502 }
503 else {
504 testGenerator.next();
505 }
506 }
507 yield undefined;
509 is(keyIndex, objectStoreDataNameSort.length, "Saw all the expected keys");
511 ok(true, "Test group 14");
513 keyIndex = objectStoreDataNameSort.length - 1;
515 request = objectStore.index("name").openCursor(null, "prev");
516 request.onerror = errorHandler;
517 request.onsuccess = function (event) {
518 let cursor = event.target.result;
519 if (cursor) {
520 is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
521 "Correct key");
522 is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key,
523 "Correct primary key");
524 is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name,
525 "Correct name");
526 is(cursor.value.height,
527 objectStoreDataNameSort[keyIndex].value.height,
528 "Correct height");
529 if ("weight" in cursor.value) {
530 is(cursor.value.weight,
531 objectStoreDataNameSort[keyIndex].value.weight,
532 "Correct weight");
533 }
535 cursor.continue();
537 is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
538 "Correct key");
539 is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key,
540 "Correct primary key");
541 is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name,
542 "Correct name");
543 is(cursor.value.height,
544 objectStoreDataNameSort[keyIndex].value.height,
545 "Correct height");
546 if ("weight" in cursor.value) {
547 is(cursor.value.weight,
548 objectStoreDataNameSort[keyIndex].value.weight,
549 "Correct weight");
550 }
552 keyIndex--;
553 }
554 else {
555 testGenerator.next();
556 }
557 }
558 yield undefined;
560 is(keyIndex, -1, "Saw all the expected keys");
562 ok(true, "Test group 15");
564 keyIndex = 1;
565 keyRange = IDBKeyRange.bound("Bob", "Ron");
567 request = objectStore.index("name").openCursor(keyRange);
568 request.onerror = errorHandler;
569 request.onsuccess = function (event) {
570 let cursor = event.target.result;
571 if (cursor) {
572 is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
573 "Correct key");
574 is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key,
575 "Correct primary key");
576 is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name,
577 "Correct name");
578 is(cursor.value.height,
579 objectStoreDataNameSort[keyIndex].value.height,
580 "Correct height");
581 if ("weight" in cursor.value) {
582 is(cursor.value.weight,
583 objectStoreDataNameSort[keyIndex].value.weight,
584 "Correct weight");
585 }
587 cursor.continue();
589 is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
590 "Correct key");
591 is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key,
592 "Correct primary key");
593 is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name,
594 "Correct name");
595 is(cursor.value.height,
596 objectStoreDataNameSort[keyIndex].value.height,
597 "Correct height");
598 if ("weight" in cursor.value) {
599 is(cursor.value.weight,
600 objectStoreDataNameSort[keyIndex].value.weight,
601 "Correct weight");
602 }
604 keyIndex++;
605 }
606 else {
607 testGenerator.next();
608 }
609 }
610 yield undefined;
612 is(keyIndex, 5, "Saw all the expected keys");
614 ok(true, "Test group 16");
616 keyIndex = 2;
617 keyRange = IDBKeyRange.bound("Bob", "Ron", true);
619 request = objectStore.index("name").openCursor(keyRange);
620 request.onerror = errorHandler;
621 request.onsuccess = function (event) {
622 let cursor = event.target.result;
623 if (cursor) {
624 is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
625 "Correct key");
626 is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key,
627 "Correct primary key");
628 is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name,
629 "Correct name");
630 is(cursor.value.height,
631 objectStoreDataNameSort[keyIndex].value.height,
632 "Correct height");
633 if ("weight" in cursor.value) {
634 is(cursor.value.weight,
635 objectStoreDataNameSort[keyIndex].value.weight,
636 "Correct weight");
637 }
639 cursor.continue();
641 is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
642 "Correct key");
643 is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key,
644 "Correct primary key");
645 is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name,
646 "Correct name");
647 is(cursor.value.height,
648 objectStoreDataNameSort[keyIndex].value.height,
649 "Correct height");
650 if ("weight" in cursor.value) {
651 is(cursor.value.weight,
652 objectStoreDataNameSort[keyIndex].value.weight,
653 "Correct weight");
654 }
656 keyIndex++;
657 }
658 else {
659 testGenerator.next();
660 }
661 }
662 yield undefined;
664 is(keyIndex, 5, "Saw all the expected keys");
666 ok(true, "Test group 17");
668 keyIndex = 1;
669 keyRange = IDBKeyRange.bound("Bob", "Ron", false, true);
671 request = objectStore.index("name").openCursor(keyRange);
672 request.onerror = errorHandler;
673 request.onsuccess = function (event) {
674 let cursor = event.target.result;
675 if (cursor) {
676 is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
677 "Correct key");
678 is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key,
679 "Correct primary key");
680 is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name,
681 "Correct name");
682 is(cursor.value.height,
683 objectStoreDataNameSort[keyIndex].value.height,
684 "Correct height");
685 if ("weight" in cursor.value) {
686 is(cursor.value.weight,
687 objectStoreDataNameSort[keyIndex].value.weight,
688 "Correct weight");
689 }
691 cursor.continue();
693 is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
694 "Correct key");
695 is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key,
696 "Correct primary key");
697 is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name,
698 "Correct name");
699 is(cursor.value.height,
700 objectStoreDataNameSort[keyIndex].value.height,
701 "Correct height");
702 if ("weight" in cursor.value) {
703 is(cursor.value.weight,
704 objectStoreDataNameSort[keyIndex].value.weight,
705 "Correct weight");
706 }
708 keyIndex++;
709 }
710 else {
711 testGenerator.next();
712 }
713 }
714 yield undefined;
716 is(keyIndex, 4, "Saw all the expected keys");
718 ok(true, "Test group 18");
720 keyIndex = 2;
721 keyRange = IDBKeyRange.bound("Bob", "Ron", true, true);
723 request = objectStore.index("name").openCursor(keyRange);
724 request.onerror = errorHandler;
725 request.onsuccess = function (event) {
726 let cursor = event.target.result;
727 if (cursor) {
728 is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
729 "Correct key");
730 is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key,
731 "Correct primary key");
732 is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name,
733 "Correct name");
734 is(cursor.value.height,
735 objectStoreDataNameSort[keyIndex].value.height,
736 "Correct height");
737 if ("weight" in cursor.value) {
738 is(cursor.value.weight,
739 objectStoreDataNameSort[keyIndex].value.weight,
740 "Correct weight");
741 }
743 cursor.continue();
745 is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
746 "Correct key");
747 is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key,
748 "Correct primary key");
749 is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name,
750 "Correct name");
751 is(cursor.value.height,
752 objectStoreDataNameSort[keyIndex].value.height,
753 "Correct height");
754 if ("weight" in cursor.value) {
755 is(cursor.value.weight,
756 objectStoreDataNameSort[keyIndex].value.weight,
757 "Correct weight");
758 }
760 keyIndex++;
761 }
762 else {
763 testGenerator.next();
764 }
765 }
766 yield undefined;
768 is(keyIndex, 4, "Saw all the expected keys");
770 ok(true, "Test group 19");
772 keyIndex = 4;
773 keyRange = IDBKeyRange.bound("Bob", "Ron");
775 request = objectStore.index("name").openCursor(keyRange, "prev");
776 request.onerror = errorHandler;
777 request.onsuccess = function (event) {
778 let cursor = event.target.result;
779 if (cursor) {
780 is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
781 "Correct key");
782 is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key,
783 "Correct primary key");
784 is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name,
785 "Correct name");
786 is(cursor.value.height,
787 objectStoreDataNameSort[keyIndex].value.height,
788 "Correct height");
789 if ("weight" in cursor.value) {
790 is(cursor.value.weight,
791 objectStoreDataNameSort[keyIndex].value.weight,
792 "Correct weight");
793 }
795 cursor.continue();
797 is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
798 "Correct key");
799 is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key,
800 "Correct primary key");
801 is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name,
802 "Correct name");
803 is(cursor.value.height,
804 objectStoreDataNameSort[keyIndex].value.height,
805 "Correct height");
806 if ("weight" in cursor.value) {
807 is(cursor.value.weight,
808 objectStoreDataNameSort[keyIndex].value.weight,
809 "Correct weight");
810 }
812 keyIndex--;
813 }
814 else {
815 testGenerator.next();
816 }
817 }
818 yield undefined;
820 is(keyIndex, 0, "Saw all the expected keys");
822 ok(true, "Test group 20");
824 // Test "nextunique"
825 keyIndex = 3;
826 keyRange = IDBKeyRange.only(65);
828 request = objectStore.index("height").openKeyCursor(keyRange, "next");
829 request.onerror = errorHandler;
830 request.onsuccess = function (event) {
831 let cursor = event.target.result;
832 if (cursor) {
833 is(cursor.key, objectStoreDataHeightSort[keyIndex].value.height,
834 "Correct key");
835 is(cursor.primaryKey, objectStoreDataHeightSort[keyIndex].key,
836 "Correct value");
838 cursor.continue();
839 keyIndex++;
840 }
841 else {
842 testGenerator.next();
843 }
844 }
845 yield undefined;
847 is(keyIndex, 5, "Saw all the expected keys");
849 ok(true, "Test group 21");
851 keyIndex = 3;
852 keyRange = IDBKeyRange.only(65);
854 request = objectStore.index("height").openKeyCursor(keyRange,
855 "nextunique");
856 request.onerror = errorHandler;
857 request.onsuccess = function (event) {
858 let cursor = event.target.result;
859 if (cursor) {
860 is(cursor.key, objectStoreDataHeightSort[keyIndex].value.height,
861 "Correct key");
862 is(cursor.primaryKey, objectStoreDataHeightSort[keyIndex].key,
863 "Correct value");
865 cursor.continue();
866 keyIndex++;
867 }
868 else {
869 testGenerator.next();
870 }
871 }
872 yield undefined;
874 is(keyIndex, 4, "Saw all the expected keys");
876 ok(true, "Test group 21.5");
878 keyIndex = 5;
880 request = objectStore.index("height").openKeyCursor(null, "prev");
881 request.onerror = errorHandler;
882 request.onsuccess = function (event) {
883 let cursor = event.target.result;
884 if (cursor) {
885 is(cursor.key, objectStoreDataHeightSort[keyIndex].value.height,
886 "Correct key");
887 is(cursor.primaryKey, objectStoreDataHeightSort[keyIndex].key,
888 "Correct value");
890 cursor.continue();
891 keyIndex--;
892 }
893 else {
894 testGenerator.next();
895 }
896 }
897 yield undefined;
899 is(keyIndex, -1, "Saw all the expected keys");
901 ok(true, "Test group 22");
903 keyIndex = 5;
905 request = objectStore.index("height").openKeyCursor(null,
906 "prevunique");
907 request.onerror = errorHandler;
908 request.onsuccess = function (event) {
909 let cursor = event.target.result;
910 if (cursor) {
911 is(cursor.key, objectStoreDataHeightSort[keyIndex].value.height,
912 "Correct key");
913 is(cursor.primaryKey, objectStoreDataHeightSort[keyIndex].key,
914 "Correct value");
916 cursor.continue();
917 if (keyIndex == 5) {
918 keyIndex--;
919 }
920 keyIndex--;
921 }
922 else {
923 testGenerator.next();
924 }
925 }
926 yield undefined;
928 is(keyIndex, -1, "Saw all the expected keys");
930 ok(true, "Test group 23");
932 keyIndex = 3;
933 keyRange = IDBKeyRange.only(65);
935 request = objectStore.index("height").openCursor(keyRange, "next");
936 request.onerror = errorHandler;
937 request.onsuccess = function (event) {
938 let cursor = event.target.result;
939 if (cursor) {
940 is(cursor.key, objectStoreDataHeightSort[keyIndex].value.height,
941 "Correct key");
942 is(cursor.primaryKey, objectStoreDataHeightSort[keyIndex].key,
943 "Correct primary key");
944 is(cursor.value.name, objectStoreDataHeightSort[keyIndex].value.name,
945 "Correct name");
946 is(cursor.value.height,
947 objectStoreDataHeightSort[keyIndex].value.height,
948 "Correct height");
949 if ("weight" in cursor.value) {
950 is(cursor.value.weight,
951 objectStoreDataHeightSort[keyIndex].value.weight,
952 "Correct weight");
953 }
955 cursor.continue();
956 keyIndex++;
957 }
958 else {
959 testGenerator.next();
960 }
961 }
962 yield undefined;
964 is(keyIndex, 5, "Saw all the expected keys");
966 ok(true, "Test group 24");
968 keyIndex = 3;
969 keyRange = IDBKeyRange.only(65);
971 request = objectStore.index("height").openCursor(keyRange,
972 "nextunique");
973 request.onerror = errorHandler;
974 request.onsuccess = function (event) {
975 let cursor = event.target.result;
976 if (cursor) {
977 is(cursor.key, objectStoreDataHeightSort[keyIndex].value.height,
978 "Correct key");
979 is(cursor.primaryKey, objectStoreDataHeightSort[keyIndex].key,
980 "Correct primary key");
981 is(cursor.value.name, objectStoreDataHeightSort[keyIndex].value.name,
982 "Correct name");
983 is(cursor.value.height,
984 objectStoreDataHeightSort[keyIndex].value.height,
985 "Correct height");
986 if ("weight" in cursor.value) {
987 is(cursor.value.weight,
988 objectStoreDataHeightSort[keyIndex].value.weight,
989 "Correct weight");
990 }
992 cursor.continue();
993 keyIndex++;
994 }
995 else {
996 testGenerator.next();
997 }
998 }
999 yield undefined;
1001 is(keyIndex, 4, "Saw all the expected keys");
1003 ok(true, "Test group 24.5");
1005 keyIndex = 5;
1007 request = objectStore.index("height").openCursor(null, "prev");
1008 request.onerror = errorHandler;
1009 request.onsuccess = function (event) {
1010 let cursor = event.target.result;
1011 if (cursor) {
1012 is(cursor.key, objectStoreDataHeightSort[keyIndex].value.height,
1013 "Correct key");
1014 is(cursor.primaryKey, objectStoreDataHeightSort[keyIndex].key,
1015 "Correct primary key");
1016 is(cursor.value.name, objectStoreDataHeightSort[keyIndex].value.name,
1017 "Correct name");
1018 is(cursor.value.height,
1019 objectStoreDataHeightSort[keyIndex].value.height,
1020 "Correct height");
1021 if ("weight" in cursor.value) {
1022 is(cursor.value.weight,
1023 objectStoreDataHeightSort[keyIndex].value.weight,
1024 "Correct weight");
1025 }
1027 cursor.continue();
1028 keyIndex--;
1029 }
1030 else {
1031 testGenerator.next();
1032 }
1033 }
1034 yield undefined;
1036 is(keyIndex, -1, "Saw all the expected keys");
1038 ok(true, "Test group 25");
1040 keyIndex = 5;
1042 request = objectStore.index("height").openCursor(null,
1043 "prevunique");
1044 request.onerror = errorHandler;
1045 request.onsuccess = function (event) {
1046 let cursor = event.target.result;
1047 if (cursor) {
1048 is(cursor.key, objectStoreDataHeightSort[keyIndex].value.height,
1049 "Correct key");
1050 is(cursor.primaryKey, objectStoreDataHeightSort[keyIndex].key,
1051 "Correct primary key");
1052 is(cursor.value.name, objectStoreDataHeightSort[keyIndex].value.name,
1053 "Correct name");
1054 is(cursor.value.height,
1055 objectStoreDataHeightSort[keyIndex].value.height,
1056 "Correct height");
1057 if ("weight" in cursor.value) {
1058 is(cursor.value.weight,
1059 objectStoreDataHeightSort[keyIndex].value.weight,
1060 "Correct weight");
1061 }
1063 cursor.continue();
1064 if (keyIndex == 5) {
1065 keyIndex--;
1066 }
1067 keyIndex--;
1068 }
1069 else {
1070 testGenerator.next();
1071 }
1072 }
1073 yield undefined;
1075 is(keyIndex, -1, "Saw all the expected keys");
1077 ok(true, "Test group 26");
1079 keyIndex = 0;
1081 request = objectStore.index("name").openKeyCursor();
1082 request.onerror = errorHandler;
1083 request.onsuccess = function (event) {
1084 let cursor = event.target.result;
1085 if (cursor) {
1086 is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
1087 "Correct key");
1088 is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key,
1089 "Correct value");
1091 let nextKey = !keyIndex ? "Pat" : undefined;
1093 cursor.continue(nextKey);
1095 is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
1096 "Correct key");
1097 is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key,
1098 "Correct value");
1100 if (!keyIndex) {
1101 keyIndex = 3;
1102 }
1103 else {
1104 keyIndex++;
1105 }
1106 }
1107 else {
1108 testGenerator.next();
1109 }
1110 }
1111 yield undefined;
1113 is(keyIndex, objectStoreData.length, "Saw all the expected keys");
1115 ok(true, "Test group 27");
1117 keyIndex = 0;
1119 request = objectStore.index("name").openKeyCursor();
1120 request.onerror = errorHandler;
1121 request.onsuccess = function (event) {
1122 let cursor = event.target.result;
1123 if (cursor) {
1124 is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
1125 "Correct key");
1126 is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key,
1127 "Correct value");
1129 let nextKey = !keyIndex ? "Flo" : undefined;
1131 cursor.continue(nextKey);
1133 is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
1134 "Correct key");
1135 is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key,
1136 "Correct value");
1138 keyIndex += keyIndex ? 1 : 2;
1139 }
1140 else {
1141 testGenerator.next();
1142 }
1143 }
1144 yield undefined;
1146 is(keyIndex, objectStoreData.length, "Saw all the expected keys");
1148 ok(true, "Test group 28");
1150 keyIndex = 0;
1152 request = objectStore.index("name").openCursor();
1153 request.onerror = errorHandler;
1154 request.onsuccess = function (event) {
1155 let cursor = event.target.result;
1156 if (cursor) {
1157 is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
1158 "Correct key");
1159 is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key,
1160 "Correct primary key");
1161 is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name,
1162 "Correct name");
1163 is(cursor.value.height,
1164 objectStoreDataNameSort[keyIndex].value.height,
1165 "Correct height");
1166 if ("weight" in cursor.value) {
1167 is(cursor.value.weight,
1168 objectStoreDataNameSort[keyIndex].value.weight,
1169 "Correct weight");
1170 }
1172 let nextKey = !keyIndex ? "Pat" : undefined;
1174 cursor.continue(nextKey);
1176 is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
1177 "Correct key");
1178 is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key,
1179 "Correct primary key");
1180 is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name,
1181 "Correct name");
1182 is(cursor.value.height,
1183 objectStoreDataNameSort[keyIndex].value.height,
1184 "Correct height");
1185 if ("weight" in cursor.value) {
1186 is(cursor.value.weight,
1187 objectStoreDataNameSort[keyIndex].value.weight,
1188 "Correct weight");
1189 }
1191 if (!keyIndex) {
1192 keyIndex = 3;
1193 }
1194 else {
1195 keyIndex++;
1196 }
1197 }
1198 else {
1199 testGenerator.next();
1200 }
1201 }
1202 yield undefined;
1204 is(keyIndex, objectStoreDataNameSort.length, "Saw all the expected keys");
1206 ok(true, "Test group 29");
1208 keyIndex = 0;
1210 request = objectStore.index("name").openCursor();
1211 request.onerror = errorHandler;
1212 request.onsuccess = function (event) {
1213 let cursor = event.target.result;
1214 if (cursor) {
1215 is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
1216 "Correct key");
1217 is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key,
1218 "Correct primary key");
1219 is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name,
1220 "Correct name");
1221 is(cursor.value.height,
1222 objectStoreDataNameSort[keyIndex].value.height,
1223 "Correct height");
1224 if ("weight" in cursor.value) {
1225 is(cursor.value.weight,
1226 objectStoreDataNameSort[keyIndex].value.weight,
1227 "Correct weight");
1228 }
1230 let nextKey = !keyIndex ? "Flo" : undefined;
1232 cursor.continue(nextKey);
1234 is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
1235 "Correct key");
1236 is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key,
1237 "Correct primary key");
1238 is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name,
1239 "Correct name");
1240 is(cursor.value.height,
1241 objectStoreDataNameSort[keyIndex].value.height,
1242 "Correct height");
1243 if ("weight" in cursor.value) {
1244 is(cursor.value.weight,
1245 objectStoreDataNameSort[keyIndex].value.weight,
1246 "Correct weight");
1247 }
1249 keyIndex += keyIndex ? 1 : 2;
1250 }
1251 else {
1252 testGenerator.next();
1253 }
1254 }
1255 yield undefined;
1257 is(keyIndex, objectStoreDataNameSort.length, "Saw all the expected keys");
1259 finishTest();
1260 yield undefined;
1261 }