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 objectStoreInfo = [
12 { name: "1", options: { keyPath: null } },
13 { name: "2", options: { keyPath: null, autoIncrement: true } },
14 { name: "3", options: { keyPath: null, autoIncrement: false } },
15 { name: "4", options: { keyPath: null } },
16 { name: "5", options: { keyPath: "foo" } },
18 { name: "7", options: null },
19 { name: "8", options: { autoIncrement: true } },
20 { name: "9", options: { autoIncrement: false } },
21 { name: "10", options: { keyPath: "foo", autoIncrement: false } },
22 { name: "11", options: { keyPath: "foo", autoIncrement: true } },
28 let request = indexedDB.open(name, 1);
29 request.onerror = errorHandler;
30 request.onupgradeneeded = grabEventAndContinueHandler;
31 request.onsuccess = unexpectedSuccessHandler;
32 let event = yield undefined;
34 let db = event.target.result;
36 let count = db.objectStoreNames.length;
37 is(count, 0, "correct objectStoreNames length");
40 db.createObjectStore("foo", "bar");
41 ok(false, "createObjectStore with bad options should throw");
43 ok(true, "createObjectStore with bad options");
47 db.createObjectStore("foo", { foo: "" }),
48 "createObjectStore with unknown options should not throw"
50 db.deleteObjectStore("foo");
52 for (let index in objectStoreInfo) {
53 index = parseInt(index);
54 const info = objectStoreInfo[index];
56 let objectStore = info.hasOwnProperty("options")
57 ? db.createObjectStore(info.name, info.options)
58 : db.createObjectStore(info.name);
60 is(db.objectStoreNames.length, index + 1, "updated objectStoreNames list");
65 } else if (name === undefined) {
70 for (let i = 0; i <= index; i++) {
71 if (db.objectStoreNames.item(i) == name) {
76 is(found, true, "objectStoreNames contains name");
78 is(objectStore.name, name, "Bad name");
81 info.options && info.options.keyPath ? info.options.keyPath : null,
84 is(objectStore.indexNames.length, 0, "Bad indexNames");
86 ok(event.target.transaction, "event has a transaction");
87 ok(event.target.transaction.db === db, "transaction has the right db");
89 event.target.transaction.mode,
91 "transaction has the correct mode"
94 event.target.transaction.objectStoreNames.length,
96 "transaction has correct objectStoreNames list"
99 for (let j = 0; j < event.target.transaction.objectStoreNames.length; j++) {
100 if (event.target.transaction.objectStoreNames.item(j) == name) {
105 is(found, true, "transaction has correct objectStoreNames list");
108 // Can't handle autoincrement and empty keypath
111 db.createObjectStore("storefail", { keyPath: "", autoIncrement: true });
115 ok(ex, "createObjectStore with empty keyPath and autoIncrement should throw");
116 is(ex.name, "InvalidAccessError", "should throw right exception");
117 ok(ex instanceof DOMException, "should throw right exception");
118 is(ex.code, DOMException.INVALID_ACCESS_ERR, "should throw right exception");
120 // Can't handle autoincrement and array keypath
122 db.createObjectStore("storefail", { keyPath: ["a"], autoIncrement: true });
126 ok(ex, "createObjectStore with array keyPath and autoIncrement should throw");
127 is(ex.name, "InvalidAccessError", "should throw right exception");
128 ok(ex instanceof DOMException, "should throw right exception");
129 is(ex.code, DOMException.INVALID_ACCESS_ERR, "should throw right exception");
131 request.onsuccess = grabEventAndContinueHandler;
132 request.onupgradeneeded = unexpectedSuccessHandler;
134 event = yield undefined;