|
1 /** |
|
2 * Any copyright is dedicated to the Public Domain. |
|
3 * http://creativecommons.org/publicdomain/zero/1.0/ |
|
4 */ |
|
5 |
|
6 var testGenerator = testSteps(); |
|
7 |
|
8 function testSteps() |
|
9 { |
|
10 const name = this.window ? window.location.pathname : "Splendid Test"; |
|
11 |
|
12 const objectStoreName = "People"; |
|
13 |
|
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 ]; |
|
22 |
|
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 ]; |
|
28 |
|
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 ]; |
|
37 |
|
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 ]; |
|
45 |
|
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 ]; |
|
54 |
|
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; |
|
61 |
|
62 let objectStore = db.createObjectStore(objectStoreName, { keyPath: null }); |
|
63 |
|
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); |
|
86 |
|
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 } |
|
105 |
|
106 request = objectStore.index("name").getKey("Bob"); |
|
107 request.onerror = errorHandler; |
|
108 request.onsuccess = grabEventAndContinueHandler; |
|
109 event = yield undefined; |
|
110 |
|
111 is(event.target.result, "237-23-7732", "Correct key returned!"); |
|
112 |
|
113 request = objectStore.index("name").get("Bob"); |
|
114 request.onerror = errorHandler; |
|
115 request.onsuccess = grabEventAndContinueHandler; |
|
116 event = yield undefined; |
|
117 |
|
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!"); |
|
121 |
|
122 ok(true, "Test group 1"); |
|
123 |
|
124 let keyIndex = 0; |
|
125 |
|
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"); |
|
136 |
|
137 cursor.continue(); |
|
138 |
|
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"); |
|
144 |
|
145 keyIndex++; |
|
146 } |
|
147 else { |
|
148 testGenerator.next(); |
|
149 } |
|
150 } |
|
151 yield undefined; |
|
152 |
|
153 is(keyIndex, objectStoreData.length, "Saw all the expected keys"); |
|
154 |
|
155 ok(true, "Test group 2"); |
|
156 |
|
157 keyIndex = 0; |
|
158 |
|
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"); |
|
168 |
|
169 cursor.continue(); |
|
170 |
|
171 is(cursor.key, objectStoreDataWeightSort[keyIndex].value.weight, |
|
172 "Correct key"); |
|
173 is(cursor.primaryKey, objectStoreDataWeightSort[keyIndex].key, |
|
174 "Correct value"); |
|
175 |
|
176 keyIndex++; |
|
177 } |
|
178 else { |
|
179 testGenerator.next(); |
|
180 } |
|
181 } |
|
182 yield undefined; |
|
183 |
|
184 is(keyIndex, objectStoreData.length - 1, "Saw all the expected keys"); |
|
185 |
|
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; |
|
194 |
|
195 ok(true, "Test group 3"); |
|
196 |
|
197 keyIndex = objectStoreDataNameSort.length - 1; |
|
198 |
|
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"); |
|
208 |
|
209 cursor.continue(); |
|
210 |
|
211 is(cursor.key, objectStoreDataNameSort[keyIndex].value.name, |
|
212 "Correct key"); |
|
213 is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key, |
|
214 "Correct value"); |
|
215 |
|
216 keyIndex--; |
|
217 } |
|
218 else { |
|
219 testGenerator.next(); |
|
220 } |
|
221 } |
|
222 yield undefined; |
|
223 |
|
224 is(keyIndex, -1, "Saw all the expected keys"); |
|
225 |
|
226 ok(true, "Test group 4"); |
|
227 |
|
228 keyIndex = 1; |
|
229 let keyRange = IDBKeyRange.bound("Bob", "Ron"); |
|
230 |
|
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"); |
|
240 |
|
241 cursor.continue(); |
|
242 keyIndex++; |
|
243 } |
|
244 else { |
|
245 testGenerator.next(); |
|
246 } |
|
247 } |
|
248 yield undefined; |
|
249 |
|
250 is(keyIndex, 5, "Saw all the expected keys"); |
|
251 |
|
252 ok(true, "Test group 5"); |
|
253 |
|
254 keyIndex = 2; |
|
255 let keyRange = IDBKeyRange.bound("Bob", "Ron", true); |
|
256 |
|
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"); |
|
266 |
|
267 cursor.continue(); |
|
268 keyIndex++; |
|
269 } |
|
270 else { |
|
271 testGenerator.next(); |
|
272 } |
|
273 } |
|
274 yield undefined; |
|
275 |
|
276 is(keyIndex, 5, "Saw all the expected keys"); |
|
277 |
|
278 ok(true, "Test group 6"); |
|
279 |
|
280 keyIndex = 1; |
|
281 let keyRange = IDBKeyRange.bound("Bob", "Ron", false, true); |
|
282 |
|
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"); |
|
292 |
|
293 cursor.continue(); |
|
294 keyIndex++; |
|
295 } |
|
296 else { |
|
297 testGenerator.next(); |
|
298 } |
|
299 } |
|
300 yield undefined; |
|
301 |
|
302 is(keyIndex, 4, "Saw all the expected keys"); |
|
303 |
|
304 ok(true, "Test group 7"); |
|
305 |
|
306 keyIndex = 2; |
|
307 keyRange = IDBKeyRange.bound("Bob", "Ron", true, true); |
|
308 |
|
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"); |
|
318 |
|
319 cursor.continue(); |
|
320 keyIndex++; |
|
321 } |
|
322 else { |
|
323 testGenerator.next(); |
|
324 } |
|
325 } |
|
326 yield undefined; |
|
327 |
|
328 is(keyIndex, 4, "Saw all the expected keys"); |
|
329 |
|
330 ok(true, "Test group 8"); |
|
331 |
|
332 keyIndex = 1; |
|
333 keyRange = IDBKeyRange.lowerBound("Bob"); |
|
334 |
|
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"); |
|
344 |
|
345 cursor.continue(); |
|
346 keyIndex++; |
|
347 } |
|
348 else { |
|
349 testGenerator.next(); |
|
350 } |
|
351 } |
|
352 yield undefined; |
|
353 |
|
354 is(keyIndex, objectStoreDataNameSort.length, "Saw all the expected keys"); |
|
355 |
|
356 ok(true, "Test group 9"); |
|
357 |
|
358 keyIndex = 2; |
|
359 keyRange = IDBKeyRange.lowerBound("Bob", true); |
|
360 |
|
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"); |
|
370 |
|
371 cursor.continue(); |
|
372 keyIndex++; |
|
373 } |
|
374 else { |
|
375 testGenerator.next(); |
|
376 } |
|
377 } |
|
378 yield undefined; |
|
379 |
|
380 is(keyIndex, objectStoreDataNameSort.length, "Saw all the expected keys"); |
|
381 |
|
382 ok(true, "Test group 10"); |
|
383 |
|
384 keyIndex = 0; |
|
385 keyRange = IDBKeyRange.upperBound("Joe"); |
|
386 |
|
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"); |
|
396 |
|
397 cursor.continue(); |
|
398 keyIndex++; |
|
399 } |
|
400 else { |
|
401 testGenerator.next(); |
|
402 } |
|
403 } |
|
404 yield undefined; |
|
405 |
|
406 is(keyIndex, 3, "Saw all the expected keys"); |
|
407 |
|
408 ok(true, "Test group 11"); |
|
409 |
|
410 keyIndex = 0; |
|
411 keyRange = IDBKeyRange.upperBound("Joe", true); |
|
412 |
|
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"); |
|
422 |
|
423 cursor.continue(); |
|
424 keyIndex++; |
|
425 } |
|
426 else { |
|
427 testGenerator.next(); |
|
428 } |
|
429 } |
|
430 yield undefined; |
|
431 |
|
432 is(keyIndex, 2, "Saw all the expected keys"); |
|
433 |
|
434 ok(true, "Test group 12"); |
|
435 |
|
436 keyIndex = 3; |
|
437 keyRange = IDBKeyRange.only("Pat"); |
|
438 |
|
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"); |
|
448 |
|
449 cursor.continue(); |
|
450 keyIndex++; |
|
451 } |
|
452 else { |
|
453 testGenerator.next(); |
|
454 } |
|
455 } |
|
456 yield undefined; |
|
457 |
|
458 is(keyIndex, 4, "Saw all the expected keys"); |
|
459 |
|
460 ok(true, "Test group 13"); |
|
461 |
|
462 keyIndex = 0; |
|
463 |
|
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 } |
|
483 |
|
484 cursor.continue(); |
|
485 |
|
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 } |
|
500 |
|
501 keyIndex++; |
|
502 } |
|
503 else { |
|
504 testGenerator.next(); |
|
505 } |
|
506 } |
|
507 yield undefined; |
|
508 |
|
509 is(keyIndex, objectStoreDataNameSort.length, "Saw all the expected keys"); |
|
510 |
|
511 ok(true, "Test group 14"); |
|
512 |
|
513 keyIndex = objectStoreDataNameSort.length - 1; |
|
514 |
|
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 } |
|
534 |
|
535 cursor.continue(); |
|
536 |
|
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 } |
|
551 |
|
552 keyIndex--; |
|
553 } |
|
554 else { |
|
555 testGenerator.next(); |
|
556 } |
|
557 } |
|
558 yield undefined; |
|
559 |
|
560 is(keyIndex, -1, "Saw all the expected keys"); |
|
561 |
|
562 ok(true, "Test group 15"); |
|
563 |
|
564 keyIndex = 1; |
|
565 keyRange = IDBKeyRange.bound("Bob", "Ron"); |
|
566 |
|
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 } |
|
586 |
|
587 cursor.continue(); |
|
588 |
|
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 } |
|
603 |
|
604 keyIndex++; |
|
605 } |
|
606 else { |
|
607 testGenerator.next(); |
|
608 } |
|
609 } |
|
610 yield undefined; |
|
611 |
|
612 is(keyIndex, 5, "Saw all the expected keys"); |
|
613 |
|
614 ok(true, "Test group 16"); |
|
615 |
|
616 keyIndex = 2; |
|
617 keyRange = IDBKeyRange.bound("Bob", "Ron", true); |
|
618 |
|
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 } |
|
638 |
|
639 cursor.continue(); |
|
640 |
|
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 } |
|
655 |
|
656 keyIndex++; |
|
657 } |
|
658 else { |
|
659 testGenerator.next(); |
|
660 } |
|
661 } |
|
662 yield undefined; |
|
663 |
|
664 is(keyIndex, 5, "Saw all the expected keys"); |
|
665 |
|
666 ok(true, "Test group 17"); |
|
667 |
|
668 keyIndex = 1; |
|
669 keyRange = IDBKeyRange.bound("Bob", "Ron", false, true); |
|
670 |
|
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 } |
|
690 |
|
691 cursor.continue(); |
|
692 |
|
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 } |
|
707 |
|
708 keyIndex++; |
|
709 } |
|
710 else { |
|
711 testGenerator.next(); |
|
712 } |
|
713 } |
|
714 yield undefined; |
|
715 |
|
716 is(keyIndex, 4, "Saw all the expected keys"); |
|
717 |
|
718 ok(true, "Test group 18"); |
|
719 |
|
720 keyIndex = 2; |
|
721 keyRange = IDBKeyRange.bound("Bob", "Ron", true, true); |
|
722 |
|
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 } |
|
742 |
|
743 cursor.continue(); |
|
744 |
|
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 } |
|
759 |
|
760 keyIndex++; |
|
761 } |
|
762 else { |
|
763 testGenerator.next(); |
|
764 } |
|
765 } |
|
766 yield undefined; |
|
767 |
|
768 is(keyIndex, 4, "Saw all the expected keys"); |
|
769 |
|
770 ok(true, "Test group 19"); |
|
771 |
|
772 keyIndex = 4; |
|
773 keyRange = IDBKeyRange.bound("Bob", "Ron"); |
|
774 |
|
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 } |
|
794 |
|
795 cursor.continue(); |
|
796 |
|
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 } |
|
811 |
|
812 keyIndex--; |
|
813 } |
|
814 else { |
|
815 testGenerator.next(); |
|
816 } |
|
817 } |
|
818 yield undefined; |
|
819 |
|
820 is(keyIndex, 0, "Saw all the expected keys"); |
|
821 |
|
822 ok(true, "Test group 20"); |
|
823 |
|
824 // Test "nextunique" |
|
825 keyIndex = 3; |
|
826 keyRange = IDBKeyRange.only(65); |
|
827 |
|
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"); |
|
837 |
|
838 cursor.continue(); |
|
839 keyIndex++; |
|
840 } |
|
841 else { |
|
842 testGenerator.next(); |
|
843 } |
|
844 } |
|
845 yield undefined; |
|
846 |
|
847 is(keyIndex, 5, "Saw all the expected keys"); |
|
848 |
|
849 ok(true, "Test group 21"); |
|
850 |
|
851 keyIndex = 3; |
|
852 keyRange = IDBKeyRange.only(65); |
|
853 |
|
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"); |
|
864 |
|
865 cursor.continue(); |
|
866 keyIndex++; |
|
867 } |
|
868 else { |
|
869 testGenerator.next(); |
|
870 } |
|
871 } |
|
872 yield undefined; |
|
873 |
|
874 is(keyIndex, 4, "Saw all the expected keys"); |
|
875 |
|
876 ok(true, "Test group 21.5"); |
|
877 |
|
878 keyIndex = 5; |
|
879 |
|
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"); |
|
889 |
|
890 cursor.continue(); |
|
891 keyIndex--; |
|
892 } |
|
893 else { |
|
894 testGenerator.next(); |
|
895 } |
|
896 } |
|
897 yield undefined; |
|
898 |
|
899 is(keyIndex, -1, "Saw all the expected keys"); |
|
900 |
|
901 ok(true, "Test group 22"); |
|
902 |
|
903 keyIndex = 5; |
|
904 |
|
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"); |
|
915 |
|
916 cursor.continue(); |
|
917 if (keyIndex == 5) { |
|
918 keyIndex--; |
|
919 } |
|
920 keyIndex--; |
|
921 } |
|
922 else { |
|
923 testGenerator.next(); |
|
924 } |
|
925 } |
|
926 yield undefined; |
|
927 |
|
928 is(keyIndex, -1, "Saw all the expected keys"); |
|
929 |
|
930 ok(true, "Test group 23"); |
|
931 |
|
932 keyIndex = 3; |
|
933 keyRange = IDBKeyRange.only(65); |
|
934 |
|
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 } |
|
954 |
|
955 cursor.continue(); |
|
956 keyIndex++; |
|
957 } |
|
958 else { |
|
959 testGenerator.next(); |
|
960 } |
|
961 } |
|
962 yield undefined; |
|
963 |
|
964 is(keyIndex, 5, "Saw all the expected keys"); |
|
965 |
|
966 ok(true, "Test group 24"); |
|
967 |
|
968 keyIndex = 3; |
|
969 keyRange = IDBKeyRange.only(65); |
|
970 |
|
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 } |
|
991 |
|
992 cursor.continue(); |
|
993 keyIndex++; |
|
994 } |
|
995 else { |
|
996 testGenerator.next(); |
|
997 } |
|
998 } |
|
999 yield undefined; |
|
1000 |
|
1001 is(keyIndex, 4, "Saw all the expected keys"); |
|
1002 |
|
1003 ok(true, "Test group 24.5"); |
|
1004 |
|
1005 keyIndex = 5; |
|
1006 |
|
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 } |
|
1026 |
|
1027 cursor.continue(); |
|
1028 keyIndex--; |
|
1029 } |
|
1030 else { |
|
1031 testGenerator.next(); |
|
1032 } |
|
1033 } |
|
1034 yield undefined; |
|
1035 |
|
1036 is(keyIndex, -1, "Saw all the expected keys"); |
|
1037 |
|
1038 ok(true, "Test group 25"); |
|
1039 |
|
1040 keyIndex = 5; |
|
1041 |
|
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 } |
|
1062 |
|
1063 cursor.continue(); |
|
1064 if (keyIndex == 5) { |
|
1065 keyIndex--; |
|
1066 } |
|
1067 keyIndex--; |
|
1068 } |
|
1069 else { |
|
1070 testGenerator.next(); |
|
1071 } |
|
1072 } |
|
1073 yield undefined; |
|
1074 |
|
1075 is(keyIndex, -1, "Saw all the expected keys"); |
|
1076 |
|
1077 ok(true, "Test group 26"); |
|
1078 |
|
1079 keyIndex = 0; |
|
1080 |
|
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"); |
|
1090 |
|
1091 let nextKey = !keyIndex ? "Pat" : undefined; |
|
1092 |
|
1093 cursor.continue(nextKey); |
|
1094 |
|
1095 is(cursor.key, objectStoreDataNameSort[keyIndex].value.name, |
|
1096 "Correct key"); |
|
1097 is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key, |
|
1098 "Correct value"); |
|
1099 |
|
1100 if (!keyIndex) { |
|
1101 keyIndex = 3; |
|
1102 } |
|
1103 else { |
|
1104 keyIndex++; |
|
1105 } |
|
1106 } |
|
1107 else { |
|
1108 testGenerator.next(); |
|
1109 } |
|
1110 } |
|
1111 yield undefined; |
|
1112 |
|
1113 is(keyIndex, objectStoreData.length, "Saw all the expected keys"); |
|
1114 |
|
1115 ok(true, "Test group 27"); |
|
1116 |
|
1117 keyIndex = 0; |
|
1118 |
|
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"); |
|
1128 |
|
1129 let nextKey = !keyIndex ? "Flo" : undefined; |
|
1130 |
|
1131 cursor.continue(nextKey); |
|
1132 |
|
1133 is(cursor.key, objectStoreDataNameSort[keyIndex].value.name, |
|
1134 "Correct key"); |
|
1135 is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key, |
|
1136 "Correct value"); |
|
1137 |
|
1138 keyIndex += keyIndex ? 1 : 2; |
|
1139 } |
|
1140 else { |
|
1141 testGenerator.next(); |
|
1142 } |
|
1143 } |
|
1144 yield undefined; |
|
1145 |
|
1146 is(keyIndex, objectStoreData.length, "Saw all the expected keys"); |
|
1147 |
|
1148 ok(true, "Test group 28"); |
|
1149 |
|
1150 keyIndex = 0; |
|
1151 |
|
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 } |
|
1171 |
|
1172 let nextKey = !keyIndex ? "Pat" : undefined; |
|
1173 |
|
1174 cursor.continue(nextKey); |
|
1175 |
|
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 } |
|
1190 |
|
1191 if (!keyIndex) { |
|
1192 keyIndex = 3; |
|
1193 } |
|
1194 else { |
|
1195 keyIndex++; |
|
1196 } |
|
1197 } |
|
1198 else { |
|
1199 testGenerator.next(); |
|
1200 } |
|
1201 } |
|
1202 yield undefined; |
|
1203 |
|
1204 is(keyIndex, objectStoreDataNameSort.length, "Saw all the expected keys"); |
|
1205 |
|
1206 ok(true, "Test group 29"); |
|
1207 |
|
1208 keyIndex = 0; |
|
1209 |
|
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 } |
|
1229 |
|
1230 let nextKey = !keyIndex ? "Flo" : undefined; |
|
1231 |
|
1232 cursor.continue(nextKey); |
|
1233 |
|
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 } |
|
1248 |
|
1249 keyIndex += keyIndex ? 1 : 2; |
|
1250 } |
|
1251 else { |
|
1252 testGenerator.next(); |
|
1253 } |
|
1254 } |
|
1255 yield undefined; |
|
1256 |
|
1257 is(keyIndex, objectStoreDataNameSort.length, "Saw all the expected keys"); |
|
1258 |
|
1259 finishTest(); |
|
1260 yield undefined; |
|
1261 } |