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 storeName1 = "test store 1";
12 const storeName2 = "test store 2";
14 info("Setup test object stores.");
15 let request = indexedDB.open(name, 1);
16 request.onerror = errorHandler;
17 request.onupgradeneeded = grabEventAndContinueHandler;
18 request.onsuccess = unexpectedSuccessHandler;
19 let event = yield undefined;
21 let db = event.target.result;
22 let txn = event.target.transaction;
24 is(db.objectStoreNames.length, 0, "Correct objectStoreNames list");
26 let objectStore1 = db.createObjectStore(storeName1, { keyPath: "foo" });
27 is(db.objectStoreNames.length, 1, "Correct objectStoreNames list");
28 is(db.objectStoreNames.item(0), objectStore1.name, "Correct name");
29 is(objectStore1.name, storeName1, "Correct name");
31 let objectStore2 = db.createObjectStore(storeName2, { keyPath: "bar" });
32 is(db.objectStoreNames.length, 2, "Correct objectStoreNames list");
33 is(db.objectStoreNames.item(1), objectStore2.name, "Correct name");
34 is(objectStore2.name, storeName2, "Correct name");
36 txn.oncomplete = continueToNextStepSync;
38 request.onsuccess = continueToNextStep;
42 info("Verify IDB Errors in version 2.");
43 request = indexedDB.open(name, 2);
44 request.onerror = errorHandler;
45 request.onupgradeneeded = grabEventAndContinueHandler;
46 request.onsuccess = continueToNextStep;
47 event = yield undefined;
49 db = event.target.result;
50 txn = event.target.transaction;
52 is(db.objectStoreNames.length, 2, "Correct objectStoreNames list");
54 objectStore1 = txn.objectStore(storeName1);
55 objectStore2 = txn.objectStore(storeName2);
56 is(objectStore1.name, storeName1, "Correct name");
57 is(objectStore2.name, storeName2, "Correct name");
59 // Rename with the name already adopted by the other object store.
61 objectStore1.name = storeName2;
64 "ConstraintError shall be thrown if the store name already exists."
67 ok(e instanceof DOMException, "got a database exception");
68 is(e.name, "ConstraintError", "correct error");
71 // Rename with the identical name.
73 objectStore1.name = storeName1;
74 ok(true, "It shall be fine to set the same name.");
76 ok(false, "Got a database exception: " + e.name);
79 db.deleteObjectStore(storeName2);
81 // Rename after deleted.
83 objectStore2.name = storeName2;
84 ok(false, "InvalidStateError shall be thrown if deleted.");
86 ok(e instanceof DOMException, "got a database exception");
87 is(e.name, "InvalidStateError", "correct error");
90 txn.oncomplete = continueToNextStepSync;
92 request.onsuccess = continueToNextStep;
96 info("Rename when the transaction is inactive.");
98 objectStore1.name = storeName1;
101 "TransactionInactiveError shall be thrown if the transaction is inactive."
104 ok(e instanceof DOMException, "got a database exception");
105 is(e.name, "TransactionInactiveError", "correct error");
108 info("Rename when the transaction is not an upgrade one.");
109 request = indexedDB.open(name, 2);
110 request.onerror = errorHandler;
111 request.onupgradeneeded = errorHandler;
112 request.onsuccess = grabEventAndContinueHandler;
113 event = yield undefined;
115 db = event.target.result;
116 txn = db.transaction(storeName1);
117 objectStore1 = txn.objectStore(storeName1);
120 objectStore1.name = storeName1;
123 "InvalidStateError shall be thrown if it's not an upgrade transaction."
126 ok(e instanceof DOMException, "got a database exception");
127 is(e.name, "InvalidStateError", "correct error");
130 txn.oncomplete = continueToNextStepSync;