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";
10 const objectStoreName = "Objects";
12 let request = indexedDB.open(name, 1);
13 request.onerror = errorHandler;
14 request.onupgradeneeded = grabEventAndContinueHandler;
15 request.onsuccess = unexpectedSuccessHandler;
16 let event = yield undefined;
18 request.onupgradeneeded = unexpectedSuccessHandler;
19 request.onsuccess = grabEventAndContinueHandler;
21 let db = event.target.result;
22 is(db.objectStoreNames.length, 0, "Correct objectStoreNames list");
24 let objectStore = db.createObjectStore(objectStoreName, { keyPath: "foo" });
28 for (let i = 0; i < 100; i++) {
29 request = objectStore.add({ foo: i });
30 request.onerror = errorHandler;
31 request.onsuccess = function(event) {
32 if (++addedCount == 100) {
33 executeSoon(function() {
41 is(db.objectStoreNames.length, 1, "Correct objectStoreNames list");
42 is(db.objectStoreNames.item(0), objectStoreName, "Correct name");
44 event.target.transaction.oncomplete = grabEventAndContinueHandler;
45 event = yield undefined;
48 event = yield undefined;
52 request = indexedDB.open(name, 2);
53 request.onerror = errorHandler;
54 request.onupgradeneeded = grabEventAndContinueHandler;
55 request.onsuccess = unexpectedSuccessHandler;
56 event = yield undefined;
58 request.onupgradeneeded = unexpectedSuccessHandler;
59 request.onsuccess = grabEventAndContinueHandler;
61 db = event.target.result;
62 let trans = event.target.transaction;
64 let oldObjectStore = trans.objectStore(objectStoreName);
65 isnot(oldObjectStore, null, "Correct object store prior to deleting");
66 db.deleteObjectStore(objectStoreName);
67 is(db.objectStoreNames.length, 0, "Correct objectStores list");
69 trans.objectStore(objectStoreName);
70 ok(false, "should have thrown");
72 ok(ex instanceof DOMException, "Got a DOMException");
73 is(ex.name, "NotFoundError", "expect a NotFoundError");
74 is(ex.code, DOMException.NOT_FOUND_ERR, "expect a NOT_FOUND_ERR");
77 objectStore = db.createObjectStore(objectStoreName, { keyPath: "foo" });
78 is(db.objectStoreNames.length, 1, "Correct objectStoreNames list");
79 is(db.objectStoreNames.item(0), objectStoreName, "Correct name");
81 trans.objectStore(objectStoreName),
83 "Correct new objectStore"
85 isnot(oldObjectStore, objectStore, "Old objectStore is not new objectStore");
87 request = objectStore.openCursor();
88 request.onerror = errorHandler;
89 request.onsuccess = function(event) {
90 is(event.target.result, null, "ObjectStore shouldn't have any items");
91 testGenerator.next(event);
93 event = yield undefined;
95 db.deleteObjectStore(objectStore.name);
96 is(db.objectStoreNames.length, 0, "Correct objectStores list");
101 trans.oncomplete = grabEventAndContinueHandler;
102 event = yield undefined;
105 event = yield undefined;
109 request = indexedDB.open(name, 3);
110 request.onerror = errorHandler;
111 request.onupgradeneeded = grabEventAndContinueHandler;
112 event = yield undefined;
114 db = event.target.result;
115 trans = event.target.transaction;
117 objectStore = db.createObjectStore(objectStoreName, { keyPath: "foo" });
119 request = objectStore.add({ foo: "bar" });
120 request.onerror = errorHandler;
121 request.onsuccess = grabEventAndContinueHandler;
123 db.deleteObjectStore(objectStoreName);
125 event = yield undefined;
127 trans.oncomplete = grabEventAndContinueHandler;
128 event = yield undefined;