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 testName = "schema21upgrade";
28 new Date("1750-01-02"),
29 new Date("1800-12-31T12:34:56.001Z"),
37 new Date("1971-01-01"),
38 new Date("1971-01-01T01:01:01Z"),
39 new Date("1971-01-01T01:01:01.001Z"),
40 new Date("1971-01-01T01:01:01.01Z"),
41 new Date("1971-01-01T01:01:01.1Z"),
42 new Date("1980-02-02"),
43 new Date("3333-03-19T03:33:33.333Z"),
108 [2, 3.0000000000001],
115 [12, [[[[[[3], [[[[[4.2]]]]]]]]]]],
124 ["abc\x00", "\x00\x01"],
125 ["abc\x00", "\x00def"],
141 "abcdefghijklmnopqrstuvwxyz0123456789`~!@#$%^&*()-_+=,<.>/?\\|";
143 clearAllDatabases(continueToNextStepSync);
146 info("Installing profile");
148 installPackagedProfile(testName + "_profile");
150 info("Opening database with no version");
152 let request = indexedDB.open(testName);
153 request.onerror = errorHandler;
154 request.onupgradeneeded = unexpectedSuccessHandler;
155 request.onsuccess = grabEventAndContinueHandler;
156 let event = yield undefined;
158 let db = event.target.result;
160 is(db.version, 1, "Correct db version");
162 let transaction = db.transaction(testName);
163 transaction.oncomplete = grabEventAndContinueHandler;
165 let objectStore = transaction.objectStore(testName);
166 let index = objectStore.index("uniqueIndex");
168 info("Starting 'uniqueIndex' cursor");
171 index.openCursor().onsuccess = event => {
172 let cursor = event.target.result;
176 JSON.stringify(cursor.primaryKey) +
178 JSON.stringify(testKeys[cursor.key]) +
184 indexedDB.cmp(cursor.primaryKey, testKeys[cursor.key]),
186 "Keys compare equally via 'indexedDB.cmp'"
189 compareKeys(cursor.primaryKey, testKeys[cursor.key]),
191 "Keys compare equally via 'compareKeys'"
194 let indexProperty = cursor.value.index;
195 is(Array.isArray(indexProperty), true, "index property is Array");
196 is(indexProperty[0], cursor.key, "index property first item correct");
200 "index property second item correct"
203 is(cursor.key, keyIndex, "Cursor key property is correct");
205 is(cursor.value.testString, testString, "Test string compared equally");
213 is(keyIndex, testKeys.length, "Saw all keys");
215 transaction = db.transaction(testName, "readwrite");
216 transaction.oncomplete = grabEventAndContinueHandler;
218 objectStore = transaction.objectStore(testName);
219 index = objectStore.index("index");
221 info("Getting all 'index' keys");
223 index.getAllKeys().onsuccess = grabEventAndContinueHandler;
224 event = yield undefined;
226 is(event.target.result.length, testKeys.length * 2, "Got all keys");
228 info("Starting objectStore cursor");
230 objectStore.openCursor().onsuccess = event => {
231 let cursor = event.target.result;
233 let value = cursor.value;
234 is(value.testString, testString, "Test string compared equally");
237 cursor.update(value);
241 continueToNextStepSync();
246 info("Getting all 'index' keys");
248 index.getAllKeys().onsuccess = grabEventAndContinueHandler;
249 event = yield undefined;
251 is(event.target.result.length, 0, "Removed all keys");
256 info("Opening database with new version");
258 request = indexedDB.open(testName, 2);
259 request.onerror = errorHandler;
260 request.onupgradeneeded = grabEventAndContinueHandler;
261 request.onsuccess = grabEventAndContinueHandler;
262 event = yield undefined;
264 info("Deleting indexes");
266 objectStore = event.target.transaction.objectStore(testName);
267 objectStore.deleteIndex("index");
268 objectStore.deleteIndex("uniqueIndex");
270 event = yield undefined;
272 db = event.target.result;
274 transaction = db.transaction(testName, "readwrite");
275 transaction.oncomplete = grabEventAndContinueHandler;
277 info("Starting objectStore cursor");
279 objectStore = transaction.objectStore(testName);
280 objectStore.openCursor().onsuccess = event => {
281 let cursor = event.target.result;
283 let value = cursor.value;
284 is(value.testString, testString, "Test string compared equally");
286 value.index = value.keyPath;
287 cursor.update(value);
292 event = yield undefined;
296 info("Opening database with new version");
298 request = indexedDB.open(testName, 3);
299 request.onerror = errorHandler;
300 request.onupgradeneeded = grabEventAndContinueHandler;
301 request.onsuccess = grabEventAndContinueHandler;
302 event = yield undefined;
304 info("Creating indexes");
306 objectStore = event.target.transaction.objectStore(testName);
307 objectStore.createIndex("index", "index");
309 event = yield undefined;
311 db = event.target.result;
313 transaction = db.transaction(testName);
314 transaction.oncomplete = grabEventAndContinueHandler;
316 objectStore = transaction.objectStore(testName);
317 index = objectStore.index("index");
319 info("Starting 'index' cursor");
322 index.openCursor().onsuccess = event => {
323 let cursor = event.target.result;
326 indexedDB.cmp(cursor.primaryKey, testKeys[keyIndex]),
328 "Keys compare equally via 'indexedDB.cmp'"
331 compareKeys(cursor.primaryKey, testKeys[keyIndex]),
333 "Keys compare equally via 'compareKeys'"
336 indexedDB.cmp(cursor.key, testKeys[keyIndex]),
338 "Keys compare equally via 'indexedDB.cmp'"
341 compareKeys(cursor.key, testKeys[keyIndex]),
343 "Keys compare equally via 'compareKeys'"
346 let indexProperty = cursor.value.index;
348 indexedDB.cmp(indexProperty, testKeys[keyIndex]),
350 "Keys compare equally via 'indexedDB.cmp'"
353 compareKeys(indexProperty, testKeys[keyIndex]),
355 "Keys compare equally via 'compareKeys'"
358 is(cursor.value.testString, testString, "Test string compared equally");
366 is(keyIndex, testKeys.length, "Added all keys again");