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 storeName_ToBeDeleted = "test store to be deleted";
12 const storeName_v0 = "test store v0";
13 const storeName_v1 = "test store v1";
14 const storeName_v2 = "test store v2";
15 const storeName_v3 = storeName_ToBeDeleted;
16 const storeName_v4 = "test store v4";
18 info("Rename in v1.");
19 let request = indexedDB.open(name, 1);
20 request.onerror = errorHandler;
21 request.onupgradeneeded = grabEventAndContinueHandler;
22 request.onsuccess = unexpectedSuccessHandler;
23 let event = yield undefined;
25 let db = event.target.result;
26 let txn = event.target.transaction;
28 is(db.objectStoreNames.length, 0, "Correct objectStoreNames list");
30 // create objectstore to be deleted later in v3.
31 db.createObjectStore(storeName_ToBeDeleted, { keyPath: "foo" });
32 is(db.objectStoreNames.length, 1, "Correct objectStoreNames list");
33 ok(db.objectStoreNames.contains(storeName_ToBeDeleted), "Correct name");
35 // create target objectstore to be renamed.
36 let objectStore = db.createObjectStore(storeName_v0, { keyPath: "bar" });
37 is(db.objectStoreNames.length, 2, "Correct objectStoreNames list");
38 ok(db.objectStoreNames.contains(objectStore.name), "Correct name");
40 objectStore.name = storeName_v1;
41 is(objectStore.name, storeName_v1, "Renamed successfully");
43 txn.oncomplete = continueToNextStepSync;
45 request.onsuccess = continueToNextStep;
49 info("Verify renaming done in v1 and run renaming in v2.");
50 request = indexedDB.open(name, 2);
51 request.onerror = errorHandler;
52 request.onupgradeneeded = grabEventAndContinueHandler;
53 request.onsuccess = unexpectedSuccessHandler;
54 event = yield undefined;
56 db = event.target.result;
57 txn = event.target.transaction;
59 is(db.objectStoreNames.length, 2, "Correct objectStoreNames list");
60 ok(db.objectStoreNames.contains(storeName_v1), "Correct name");
61 ok(db.objectStoreNames.contains(storeName_ToBeDeleted), "Correct name");
63 objectStore = txn.objectStore(storeName_v1);
64 objectStore.name = storeName_v2;
65 is(objectStore.name, storeName_v2, "Renamed successfully");
67 txn.oncomplete = continueToNextStepSync;
69 request.onsuccess = continueToNextStep;
73 info("Verify renaming done in v2.");
74 request = indexedDB.open(name, 2);
75 request.onerror = errorHandler;
76 request.onupgradeneeded = errorHandler;
77 request.onsuccess = grabEventAndContinueHandler;
78 event = yield undefined;
80 db = event.target.result;
82 is(db.objectStoreNames.length, 2, "Correct objectStoreNames list");
83 ok(db.objectStoreNames.contains(storeName_v2), "Correct name");
84 ok(db.objectStoreNames.contains(storeName_ToBeDeleted), "Correct name");
88 info("Rename in v3.");
89 request = indexedDB.open(name, 3);
90 request.onerror = errorHandler;
91 request.onupgradeneeded = grabEventAndContinueHandler;
92 request.onsuccess = unexpectedSuccessHandler;
93 event = yield undefined;
95 db = event.target.result;
96 txn = event.target.transaction;
98 is(db.objectStoreNames.length, 2, "Correct objectStoreNames list");
99 ok(db.objectStoreNames.contains(storeName_v2), "Correct name");
100 ok(db.objectStoreNames.contains(storeName_ToBeDeleted), "Correct name");
101 db.deleteObjectStore(storeName_ToBeDeleted);
102 is(db.objectStoreNames.length, 1, "Correct objectStoreNames list");
104 db.objectStoreNames.contains(storeName_v2) &&
105 !db.objectStoreNames.contains(storeName_ToBeDeleted),
109 objectStore = txn.objectStore(storeName_v2);
110 objectStore.name = storeName_v3;
111 is(objectStore.name, storeName_v3, "Renamed successfully");
113 txn.oncomplete = continueToNextStepSync;
115 request.onsuccess = continueToNextStep;
119 info("Verify renaming done in v3.");
120 request = indexedDB.open(name, 3);
121 request.onerror = errorHandler;
122 request.onupgradeneeded = errorHandler;
123 request.onsuccess = grabEventAndContinueHandler;
124 event = yield undefined;
126 db = event.target.result;
128 is(db.objectStoreNames.length, 1, "Correct objectStoreNames list");
129 ok(db.objectStoreNames.contains(storeName_v3), "Correct name");
133 info("Abort the version change transaction while renaming objectstore.");
134 request = indexedDB.open(name, 4);
135 request.onerror = errorHandler;
136 request.onupgradeneeded = grabEventAndContinueHandler;
137 request.onsuccess = unexpectedSuccessHandler;
138 event = yield undefined;
140 db = event.target.result;
141 txn = event.target.transaction;
143 objectStore = txn.objectStore(storeName_v3);
144 objectStore.name = storeName_v4;
145 is(objectStore.name, storeName_v4, "Renamed successfully");
146 let putRequest = objectStore.put({ bar: "barValue" });
147 putRequest.onsuccess = continueToNextStepSync;
150 // Aborting the transaction.
151 request.onerror = expectedErrorHandler("AbortError");
155 // Verify if the name of the objectStore handle is reverted.
156 is(objectStore.name, storeName_v3, "The name is reverted after aborted.");
158 info("Verify if the objectstore name is unchanged.");
159 request = indexedDB.open(name, 3);
160 request.onerror = errorHandler;
161 request.onupgradeneeded = errorHandler;
162 request.onsuccess = grabEventAndContinueHandler;
163 event = yield undefined;
165 db = event.target.result;
167 is(db.objectStoreNames.length, 1, "Correct objectStoreNames list");
168 ok(db.objectStoreNames.contains(storeName_v3), "Correct name");