2 * Any copyright is dedicated to the Public Domain.
3 * http://creativecommons.org/publicdomain/zero/1.0/
6 /* exported testGenerator */
7 var testGenerator = testSteps();
9 function* testSteps() {
10 const name = this.window ? window.location.pathname : "Splendid Test";
11 const objectStoreName = "People";
13 const objectStoreData = [
14 { key: "237-23-7732", value: { name: "Bob", height: 60, weight: 120 } },
15 { key: "237-23-7733", value: { name: "Ann", height: 52, weight: 110 } },
16 { key: "237-23-7734", value: { name: "Ron", height: 73, weight: 180 } },
17 { key: "237-23-7735", value: { name: "Sue", height: 58, weight: 130 } },
18 { key: "237-23-7736", value: { name: "Joe", height: 65, weight: 150 } },
19 { key: "237-23-7737", value: { name: "Pat", height: 65 } },
20 { key: "237-23-7738", value: { name: "Mel", height: 66, weight: {} } },
21 { key: "237-23-7739", value: { name: "Tom", height: 62, weight: 130 } },
27 options: { unique: false },
30 const weightSort = [1, 0, 3, 7, 4, 2];
32 let request = indexedDB.open(name, 1);
33 request.onerror = errorHandler;
34 request.onupgradeneeded = grabEventAndContinueHandler;
35 request.onsuccess = grabEventAndContinueHandler;
36 let event = yield undefined;
38 is(event.type, "upgradeneeded", "Got correct event type");
40 let db = event.target.result;
41 db.onerror = errorHandler;
43 let objectStore = db.createObjectStore(objectStoreName, {});
44 objectStore.createIndex(indexData.name, indexData.keyPath, indexData.options);
46 for (let data of objectStoreData) {
47 objectStore.add(data.value, data.key);
50 event = yield undefined;
52 is(event.type, "success", "Got correct event type");
55 .transaction(db.objectStoreNames)
56 .objectStore(objectStoreName);
58 objectStore.count().onsuccess = grabEventAndContinueHandler;
59 event = yield undefined;
63 objectStoreData.length,
64 "Correct number of object store entries for all keys"
67 objectStore.count(null).onsuccess = grabEventAndContinueHandler;
68 event = yield undefined;
72 objectStoreData.length,
73 "Correct number of object store entries for null key"
77 objectStoreData[2].key
78 ).onsuccess = grabEventAndContinueHandler;
79 event = yield undefined;
84 "Correct number of object store entries for single existing key"
87 objectStore.count("foo").onsuccess = grabEventAndContinueHandler;
88 event = yield undefined;
93 "Correct number of object store entries for single non-existing key"
96 let keyRange = IDBKeyRange.only(objectStoreData[2].key);
97 objectStore.count(keyRange).onsuccess = grabEventAndContinueHandler;
98 event = yield undefined;
103 "Correct number of object store entries for existing only keyRange"
106 keyRange = IDBKeyRange.only("foo");
107 objectStore.count(keyRange).onsuccess = grabEventAndContinueHandler;
108 event = yield undefined;
113 "Correct number of object store entries for non-existing only keyRange"
116 keyRange = IDBKeyRange.lowerBound(objectStoreData[2].key);
117 objectStore.count(keyRange).onsuccess = grabEventAndContinueHandler;
118 event = yield undefined;
122 objectStoreData.length - 2,
123 "Correct number of object store entries for lowerBound keyRange"
126 keyRange = IDBKeyRange.lowerBound(objectStoreData[2].key, true);
127 objectStore.count(keyRange).onsuccess = grabEventAndContinueHandler;
128 event = yield undefined;
132 objectStoreData.length - 3,
133 "Correct number of object store entries for lowerBound keyRange"
136 keyRange = IDBKeyRange.lowerBound("foo");
137 objectStore.count(keyRange).onsuccess = grabEventAndContinueHandler;
138 event = yield undefined;
143 "Correct number of object store entries for lowerBound keyRange"
146 keyRange = IDBKeyRange.upperBound(objectStoreData[2].key, false);
147 objectStore.count(keyRange).onsuccess = grabEventAndContinueHandler;
148 event = yield undefined;
153 "Correct number of object store entries for upperBound keyRange"
156 keyRange = IDBKeyRange.upperBound(objectStoreData[2].key, true);
157 objectStore.count(keyRange).onsuccess = grabEventAndContinueHandler;
158 event = yield undefined;
163 "Correct number of object store entries for upperBound keyRange"
166 keyRange = IDBKeyRange.upperBound("foo", true);
167 objectStore.count(keyRange).onsuccess = grabEventAndContinueHandler;
168 event = yield undefined;
172 objectStoreData.length,
173 "Correct number of object store entries for upperBound keyRange"
176 keyRange = IDBKeyRange.bound(
177 objectStoreData[0].key,
178 objectStoreData[objectStoreData.length - 1].key
180 objectStore.count(keyRange).onsuccess = grabEventAndContinueHandler;
181 event = yield undefined;
185 objectStoreData.length,
186 "Correct number of object store entries for bound keyRange"
189 keyRange = IDBKeyRange.bound(
190 objectStoreData[0].key,
191 objectStoreData[objectStoreData.length - 1].key,
194 objectStore.count(keyRange).onsuccess = grabEventAndContinueHandler;
195 event = yield undefined;
199 objectStoreData.length - 1,
200 "Correct number of object store entries for bound keyRange"
203 keyRange = IDBKeyRange.bound(
204 objectStoreData[0].key,
205 objectStoreData[objectStoreData.length - 1].key,
209 objectStore.count(keyRange).onsuccess = grabEventAndContinueHandler;
210 event = yield undefined;
214 objectStoreData.length - 2,
215 "Correct number of object store entries for bound keyRange"
218 keyRange = IDBKeyRange.bound("foo", "foopy", true, true);
219 objectStore.count(keyRange).onsuccess = grabEventAndContinueHandler;
220 event = yield undefined;
225 "Correct number of object store entries for bound keyRange"
228 keyRange = IDBKeyRange.bound(objectStoreData[0].key, "foo", true, true);
229 objectStore.count(keyRange).onsuccess = grabEventAndContinueHandler;
230 event = yield undefined;
234 objectStoreData.length - 1,
235 "Correct number of object store entries for bound keyRange"
238 let index = objectStore.index(indexData.name);
240 index.count().onsuccess = grabEventAndContinueHandler;
241 event = yield undefined;
246 "Correct number of index entries for no key"
250 objectStoreData[7].value.weight
251 ).onsuccess = grabEventAndContinueHandler;
252 event = yield undefined;
257 "Correct number of index entries for duplicate key"
261 objectStoreData[0].value.weight
262 ).onsuccess = grabEventAndContinueHandler;
263 event = yield undefined;
265 is(event.target.result, 1, "Correct number of index entries for single key");
267 keyRange = IDBKeyRange.only(objectStoreData[0].value.weight);
268 index.count(keyRange).onsuccess = grabEventAndContinueHandler;
269 event = yield undefined;
274 "Correct number of index entries for only existing keyRange"
277 keyRange = IDBKeyRange.only("foo");
278 index.count(keyRange).onsuccess = grabEventAndContinueHandler;
279 event = yield undefined;
284 "Correct number of index entries for only non-existing keyRange"
287 keyRange = IDBKeyRange.only(objectStoreData[7].value.weight);
288 index.count(keyRange).onsuccess = grabEventAndContinueHandler;
289 event = yield undefined;
294 "Correct number of index entries for only duplicate keyRange"
297 keyRange = IDBKeyRange.lowerBound(
298 objectStoreData[weightSort[0]].value.weight
300 index.count(keyRange).onsuccess = grabEventAndContinueHandler;
301 event = yield undefined;
306 "Correct number of index entries for lowerBound keyRange"
309 keyRange = IDBKeyRange.lowerBound(
310 objectStoreData[weightSort[1]].value.weight
312 index.count(keyRange).onsuccess = grabEventAndContinueHandler;
313 event = yield undefined;
317 weightSort.length - 1,
318 "Correct number of index entries for lowerBound keyRange"
321 keyRange = IDBKeyRange.lowerBound(
322 objectStoreData[weightSort[0]].value.weight - 1
324 index.count(keyRange).onsuccess = grabEventAndContinueHandler;
325 event = yield undefined;
330 "Correct number of index entries for lowerBound keyRange"
333 keyRange = IDBKeyRange.lowerBound(
334 objectStoreData[weightSort[0]].value.weight,
337 index.count(keyRange).onsuccess = grabEventAndContinueHandler;
338 event = yield undefined;
342 weightSort.length - 1,
343 "Correct number of index entries for lowerBound keyRange"
346 keyRange = IDBKeyRange.lowerBound(
347 objectStoreData[weightSort[weightSort.length - 1]].value.weight
349 index.count(keyRange).onsuccess = grabEventAndContinueHandler;
350 event = yield undefined;
355 "Correct number of index entries for lowerBound keyRange"
358 keyRange = IDBKeyRange.lowerBound(
359 objectStoreData[weightSort[weightSort.length - 1]].value.weight,
362 index.count(keyRange).onsuccess = grabEventAndContinueHandler;
363 event = yield undefined;
368 "Correct number of index entries for lowerBound keyRange"
371 keyRange = IDBKeyRange.lowerBound(
372 objectStoreData[weightSort[weightSort.length - 1]].value.weight + 1,
375 index.count(keyRange).onsuccess = grabEventAndContinueHandler;
376 event = yield undefined;
381 "Correct number of index entries for lowerBound keyRange"
384 keyRange = IDBKeyRange.upperBound(
385 objectStoreData[weightSort[0]].value.weight
387 index.count(keyRange).onsuccess = grabEventAndContinueHandler;
388 event = yield undefined;
393 "Correct number of index entries for upperBound keyRange"
396 keyRange = IDBKeyRange.upperBound(
397 objectStoreData[weightSort[0]].value.weight,
400 index.count(keyRange).onsuccess = grabEventAndContinueHandler;
401 event = yield undefined;
406 "Correct number of index entries for upperBound keyRange"
409 keyRange = IDBKeyRange.upperBound(
410 objectStoreData[weightSort[weightSort.length - 1]].value.weight
412 index.count(keyRange).onsuccess = grabEventAndContinueHandler;
413 event = yield undefined;
418 "Correct number of index entries for upperBound keyRange"
421 keyRange = IDBKeyRange.upperBound(
422 objectStoreData[weightSort[weightSort.length - 1]].value.weight,
425 index.count(keyRange).onsuccess = grabEventAndContinueHandler;
426 event = yield undefined;
430 weightSort.length - 1,
431 "Correct number of index entries for upperBound keyRange"
434 keyRange = IDBKeyRange.upperBound(
435 objectStoreData[weightSort[weightSort.length - 1]].value.weight,
438 index.count(keyRange).onsuccess = grabEventAndContinueHandler;
439 event = yield undefined;
443 weightSort.length - 1,
444 "Correct number of index entries for upperBound keyRange"
447 keyRange = IDBKeyRange.upperBound("foo");
448 index.count(keyRange).onsuccess = grabEventAndContinueHandler;
449 event = yield undefined;
454 "Correct number of index entries for upperBound keyRange"
457 keyRange = IDBKeyRange.bound("foo", "foopy");
458 index.count(keyRange).onsuccess = grabEventAndContinueHandler;
459 event = yield undefined;
464 "Correct number of index entries for bound keyRange"
467 keyRange = IDBKeyRange.bound(
468 objectStoreData[weightSort[0]].value.weight,
469 objectStoreData[weightSort[weightSort.length - 1]].value.weight
471 index.count(keyRange).onsuccess = grabEventAndContinueHandler;
472 event = yield undefined;
477 "Correct number of index entries for bound keyRange"
480 keyRange = IDBKeyRange.bound(
481 objectStoreData[weightSort[0]].value.weight,
482 objectStoreData[weightSort[weightSort.length - 1]].value.weight,
485 index.count(keyRange).onsuccess = grabEventAndContinueHandler;
486 event = yield undefined;
490 weightSort.length - 1,
491 "Correct number of index entries for bound keyRange"
494 keyRange = IDBKeyRange.bound(
495 objectStoreData[weightSort[0]].value.weight,
496 objectStoreData[weightSort[weightSort.length - 1]].value.weight,
500 index.count(keyRange).onsuccess = grabEventAndContinueHandler;
501 event = yield undefined;
505 weightSort.length - 2,
506 "Correct number of index entries for bound keyRange"