2 * Any copyright is dedicated to the Public Domain.
3 * http://creativecommons.org/publicdomain/zero/1.0/
6 var testGenerator = testSteps();
8 function* testSteps() {
9 const name = this.window ? window.location.pathname : "Splendid Test";
11 const values = ["a", "1", 1, "foo", 300, true, false, 4.5, null];
13 let request = indexedDB.open(name, 1);
14 request.onerror = errorHandler;
15 request.onupgradeneeded = grabEventAndContinueHandler;
16 let event = yield undefined;
18 let db = event.target.result;
20 let objectStore = db.createObjectStore("foo", { autoIncrement: true });
22 request.onsuccess = grabEventAndContinueHandler;
23 request = objectStore.mozGetAll();
24 request.onerror = errorHandler;
25 request.onsuccess = grabEventAndContinueHandler;
26 event = yield undefined;
28 is(event.target.result instanceof Array, true, "Got an array object");
29 is(event.target.result.length, 0, "No elements");
33 for (let i in values) {
34 request = objectStore.add(values[i]);
35 request.onerror = errorHandler;
36 request.onsuccess = function(event) {
37 if (++addedCount == values.length) {
38 executeSoon(function() {
51 request.onerror = errorHandler;
52 request.onsuccess = grabEventAndContinueHandler;
53 event = yield undefined;
55 is(event.target.result instanceof Array, true, "Got an array object");
56 is(event.target.result.length, values.length, "Same length");
58 for (let i in event.target.result) {
59 is(event.target.result[i], values[i], "Same value");
66 request.onerror = errorHandler;
67 request.onsuccess = grabEventAndContinueHandler;
68 event = yield undefined;
70 is(event.target.result instanceof Array, true, "Got an array object");
71 is(event.target.result.length, 5, "Correct length");
73 for (let i in event.target.result) {
74 is(event.target.result[i], values[i], "Same value");
77 let keyRange = IDBKeyRange.bound(1, 9);
83 request.onerror = errorHandler;
84 request.onsuccess = grabEventAndContinueHandler;
85 event = yield undefined;
87 is(event.target.result instanceof Array, true, "Got an array object");
88 is(event.target.result.length, values.length, "Correct length");
90 for (let i in event.target.result) {
91 is(event.target.result[i], values[i], "Same value");
97 .mozGetAll(keyRange, 0);
98 request.onerror = errorHandler;
99 request.onsuccess = grabEventAndContinueHandler;
100 event = yield undefined;
102 is(event.target.result instanceof Array, true, "Got an array object");
103 is(event.target.result.length, values.length, "Correct length");
105 for (let i in event.target.result) {
106 is(event.target.result[i], values[i], "Same value");
112 .mozGetAll(keyRange, null);
113 request.onerror = errorHandler;
114 request.onsuccess = grabEventAndContinueHandler;
115 event = yield undefined;
117 is(event.target.result instanceof Array, true, "Got an array object");
118 is(event.target.result.length, values.length, "Correct length");
120 for (let i in event.target.result) {
121 is(event.target.result[i], values[i], "Same value");
127 .mozGetAll(keyRange, undefined);
128 request.onerror = errorHandler;
129 request.onsuccess = grabEventAndContinueHandler;
130 event = yield undefined;
132 is(event.target.result instanceof Array, true, "Got an array object");
133 is(event.target.result.length, values.length, "Correct length");
135 for (let i in event.target.result) {
136 is(event.target.result[i], values[i], "Same value");
139 keyRange = IDBKeyRange.bound(4, 7);
144 .mozGetAll(keyRange);
145 request.onerror = errorHandler;
146 request.onsuccess = grabEventAndContinueHandler;
147 event = yield undefined;
149 is(event.target.result instanceof Array, true, "Got an array object");
150 is(event.target.result.length, 4, "Correct length");
152 for (let i in event.target.result) {
153 is(event.target.result[i], values[parseInt(i) + 3], "Same value");
156 // Get should take a key range also but it doesn't return an array.
161 request.onerror = errorHandler;
162 request.onsuccess = grabEventAndContinueHandler;
163 event = yield undefined;
165 is(event.target.result instanceof Array, false, "Not an array object");
166 is(event.target.result, values[3], "Correct value");
171 .mozGetAll(keyRange, 2);
172 request.onerror = errorHandler;
173 request.onsuccess = grabEventAndContinueHandler;
174 event = yield undefined;
176 is(event.target.result instanceof Array, true, "Got an array object");
177 is(event.target.result.length, 2, "Correct length");
179 for (let i in event.target.result) {
180 is(event.target.result[i], values[parseInt(i) + 3], "Same value");
183 keyRange = IDBKeyRange.bound(4, 7);
188 .mozGetAll(keyRange, 50);
189 request.onerror = errorHandler;
190 request.onsuccess = grabEventAndContinueHandler;
191 event = yield undefined;
193 is(event.target.result instanceof Array, true, "Got an array object");
194 is(event.target.result.length, 4, "Correct length");
196 for (let i in event.target.result) {
197 is(event.target.result[i], values[parseInt(i) + 3], "Same value");
200 keyRange = IDBKeyRange.bound(4, 7);
205 .mozGetAll(keyRange, 0);
206 request.onerror = errorHandler;
207 request.onsuccess = grabEventAndContinueHandler;
208 event = yield undefined;
210 is(event.target.result instanceof Array, true, "Got an array object");
211 is(event.target.result.length, 4, "Correct length");
213 keyRange = IDBKeyRange.bound(4, 7, true, true);
218 .mozGetAll(keyRange);
219 request.onerror = errorHandler;
220 request.onsuccess = grabEventAndContinueHandler;
221 event = yield undefined;
223 is(event.target.result instanceof Array, true, "Got an array object");
224 is(event.target.result.length, 2, "Correct length");
226 for (let i in event.target.result) {
227 is(event.target.result[i], values[parseInt(i) + 4], "Same value");