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 let name = this.window ? window.location.pathname : "Splendid Test";
11 let request = indexedDB.open(name, 1);
12 request.onerror = errorHandler;
13 request.onupgradeneeded = grabEventAndContinueHandler;
14 request.onsuccess = grabEventAndContinueHandler;
16 let event = yield undefined;
18 let db = event.target.result;
19 db.onerror = errorHandler;
21 for (let autoIncrement of [false, true]) {
22 let objectStore = db.createObjectStore(autoIncrement, {
27 for (let i = 0; i < 10; i++) {
28 objectStore.add({ id: i, index: i });
31 for (let unique of [false, true]) {
32 objectStore.createIndex(unique, "index", { unique });
35 for (let i = 10; i < 20; i++) {
36 objectStore.add({ id: i, index: i });
40 event = yield undefined;
41 is(event.type, "success", "expect a success event");
43 for (let autoIncrement of [false, true]) {
44 let objectStore = db.transaction(autoIncrement).objectStore(autoIncrement);
46 objectStore.count().onsuccess = grabEventAndContinueHandler;
47 let event = yield undefined;
49 is(event.target.result, 20, "Correct number of entries in objectStore");
51 let objectStoreCount = event.target.result;
52 let indexCount = event.target.result;
54 for (let unique of [false, true]) {
56 .transaction(autoIncrement, "readwrite")
57 .objectStore(autoIncrement)
60 index.count().onsuccess = grabEventAndContinueHandler;
61 let event = yield undefined;
63 is(event.target.result, indexCount, "Correct number of entries in index");
65 let modifiedEntry = unique ? 5 : 10;
66 let keyRange = IDBKeyRange.only(modifiedEntry);
69 index.openCursor(keyRange).onsuccess = function(event) {
70 let cursor = event.target.result;
73 is(cursor.key, modifiedEntry, "Correct key");
75 cursor.value.index = unique ? 30 : 35;
76 cursor.update(cursor.value).onsuccess = function(event) {
85 is(sawEntry, true, "Saw entry for key value " + modifiedEntry);
87 // Recount index. Shouldn't change.
89 .transaction(autoIncrement, "readwrite")
90 .objectStore(autoIncrement)
93 index.count().onsuccess = grabEventAndContinueHandler;
94 event = yield undefined;
96 is(event.target.result, indexCount, "Correct number of entries in index");
98 modifiedEntry = unique ? 30 : 35;
99 keyRange = IDBKeyRange.only(modifiedEntry);
102 index.openCursor(keyRange).onsuccess = function(event) {
103 let cursor = event.target.result;
106 is(cursor.key, modifiedEntry, "Correct key");
108 delete cursor.value.index;
109 cursor.update(cursor.value).onsuccess = function(event) {
114 continueToNextStep();
119 is(sawEntry, true, "Saw entry for key value " + modifiedEntry);
121 // Recount objectStore. Should be unchanged.
123 .transaction(autoIncrement, "readwrite")
124 .objectStore(autoIncrement);
126 objectStore.count().onsuccess = grabEventAndContinueHandler;
127 event = yield undefined;
132 "Correct number of entries in objectStore"
135 // Recount index. Should be one item less.
136 index = objectStore.index(unique);
138 index.count().onsuccess = grabEventAndContinueHandler;
139 event = yield undefined;
141 is(event.target.result, indexCount, "Correct number of entries in index");
143 modifiedEntry = objectStoreCount - 1;
145 objectStore.delete(modifiedEntry).onsuccess = grabEventAndContinueHandler;
146 event = yield undefined;
151 objectStore.count().onsuccess = grabEventAndContinueHandler;
152 event = yield undefined;
157 "Correct number of entries in objectStore"
160 index.count().onsuccess = grabEventAndContinueHandler;
161 event = yield undefined;
163 is(event.target.result, indexCount, "Correct number of entries in index");
165 index = event = null; // Bug 943409 workaround.
167 objectStore = event = null; // Bug 943409 workaround.
171 event = db = request = null; // Bug 943409 workaround.