1 if (this.importScripts) {
2 importScripts('../../../resources/js-test.js');
3 importScripts('shared.js');
6 description("Test IndexedDB's IDBCursor.continue() with a key parameter.");
10 // In order of how it should be sorted by IndexedDB.
23 new Date(date.valueOf() + 1000),
32 indexedDBTest(prepareDatabase, onTransactionComplete);
33 function prepareDatabase()
35 db = event.target.result;
36 event.target.transaction.onabort = unexpectedAbortCallback;
38 self.objectStore = evalAndLog("db.createObjectStore('someObjectStore')");
39 self.indexObject = evalAndLog("objectStore.createIndex('someIndex', 'x')");
46 result = evalAndLog("objectStore.add({'x': testData[nextToAdd]}, nextToAdd)");
47 result.onsuccess = ++self.nextToAdd < testData.length ? addData : ascendingTest;
48 result.onerror = unexpectedErrorCallback;
51 function ascendingTest()
54 var request = evalAndLog("indexObject.openKeyCursor(null, 'next')");
55 request.onsuccess = ascendingCallback;
56 request.onerror = unexpectedErrorCallback;
60 function ascendingCallback()
63 if (self.stage == 0) {
64 shouldBe("event.target.result.primaryKey", "0");
65 evalAndLog("event.target.result.continue(3.14159)");
66 } else if (self.stage == 1) {
67 shouldBe("event.target.result.primaryKey", "3");
68 evalAndLog("event.target.result.continue()");
69 } else if (self.stage == 2) {
70 shouldBe("event.target.result.primaryKey", "4");
71 evalAndLog("event.target.result.continue()");
72 } else if (self.stage == 3) {
73 shouldBe("event.target.result.primaryKey", "5");
74 evalAndLog("event.target.result.continue(12)");
75 } else if (self.stage == 4) {
76 shouldBe("event.target.result.primaryKey", "7");
77 evalAndLog("event.target.result.continue(date)");
78 } else if (self.stage == 5) {
79 shouldBe("event.target.result.primaryKey", "9");
80 evalAndLog("event.target.result.continue()");
81 } else if (self.stage == 6) {
82 shouldBe("event.target.result.primaryKey", "10");
83 evalAndLog("event.target.result.continue()");
84 } else if (self.stage == 7) {
85 shouldBe("event.target.result.primaryKey", "11");
86 evalAndLog("event.target.result.continue('A bit1')");
87 } else if (self.stage == 8) {
88 shouldBe("event.target.result.primaryKey", "14");
89 evalAndLog("event.target.result.continue('A bit3')");
90 } else if (self.stage == 9) {
91 shouldBe("event.target.result.primaryKey", "16");
92 evalAndLog("event.target.result.continue('the BIGGEST string')");
93 } else if (self.stage == 10) {
94 shouldBe("event.target.result.primaryKey", "17");
95 evalAndLog("event.target.result.continue()");
96 } else if (self.stage == 11) {
97 shouldBeNull("event.target.result");
101 testFailed("Illegal stage.");
106 function descendingTest()
109 var request = evalAndLog("indexObject.openKeyCursor(null, 'prev')");
110 request.onsuccess = descendingCallback;
111 request.onerror = unexpectedErrorCallback;
115 function descendingCallback()
117 if (self.stage == 0) {
118 shouldBe("event.target.result.primaryKey", "17");
119 evalAndLog("event.target.result.continue('A bit2')");
120 } else if (self.stage == 1) {
121 shouldBe("event.target.result.primaryKey", "15");
122 evalAndLog("event.target.result.continue()");
123 } else if (self.stage == 2) {
124 shouldBe("event.target.result.primaryKey", "14");
125 evalAndLog("event.target.result.continue(date)");
126 } else if (self.stage == 3) {
127 shouldBe("event.target.result.primaryKey", "10");
128 evalAndLog("event.target.result.continue()");
129 } else if (self.stage == 4) {
130 shouldBe("event.target.result.primaryKey", "9");
131 evalAndLog("event.target.result.continue(1)");
132 } else if (self.stage == 5) {
133 shouldBe("event.target.result.primaryKey", "2");
134 evalAndLog("event.target.result.continue()");
135 } else if (self.stage == 6) {
136 shouldBe("event.target.result.primaryKey", "1");
137 evalAndLog("event.target.result.continue()");
138 } else if (self.stage == 7) {
139 shouldBe("event.target.result.primaryKey", "0");
140 evalAndLog("event.target.result.continue()");
141 } else if (self.stage == 8) {
142 shouldBeNull("event.target.result");
143 descendingUniqueTest();
146 testFailed("Illegal stage.");
151 function descendingUniqueTest()
154 var request = evalAndLog("indexObject.openKeyCursor(null, 'prevunique')");
155 request.onsuccess = descendingUniqueCallback;
156 request.onerror = unexpectedErrorCallback;
160 function descendingUniqueCallback()
162 if (self.stage == 0) {
163 shouldBe("event.target.result.primaryKey", "17");
164 evalAndLog("event.target.result.continue('A bit2')");
165 } else if (self.stage == 1) {
166 shouldBe("event.target.result.primaryKey", "15");
167 evalAndLog("event.target.result.continue()");
168 } else if (self.stage == 2) {
169 shouldBe("event.target.result.primaryKey", "14");
170 evalAndLog("event.target.result.continue(date)");
171 } else if (self.stage == 3) {
172 shouldBe("event.target.result.primaryKey", "9");
173 evalAndLog("event.target.result.continue()");
174 } else if (self.stage == 4) {
175 shouldBe("event.target.result.primaryKey", "8");
176 evalAndLog("event.target.result.continue(12)");
177 } else if (self.stage == 5) {
178 shouldBe("event.target.result.primaryKey", "7");
179 evalAndLog("event.target.result.continue(3.5)");
180 } else if (self.stage == 6) {
181 shouldBe("event.target.result.primaryKey", "3");
182 evalAndLog("event.target.result.continue()");
183 } else if (self.stage == 7) {
184 shouldBe("event.target.result.primaryKey", "1");
185 evalAndLog("event.target.result.continue()");
186 } else if (self.stage == 8) {
187 shouldBe("event.target.result.primaryKey", "0");
188 evalAndLog("event.target.result.continue()");
189 } else if (self.stage == 9) {
190 shouldBeNull("event.target.result");
191 ascendingErrorTestLessThan();
194 testFailed("Illegal stage.");
199 function ascendingErrorTestLessThan()
202 var request = evalAndLog("indexObject.openKeyCursor(null, 'next')");
204 request.onerror = unexpectedErrorCallback;
205 request.onsuccess = function() {
206 if (self.stage === 0) {
207 shouldBe("event.target.result.primaryKey", "0");
208 evalAndLog("event.target.result.continue(3.14159)");
209 } else if (self.stage == 1) {
210 shouldBe("event.target.result.primaryKey", "3");
211 evalAndExpectException("event.target.result.continue(1)", "0", "'DataError'");
212 ascendingErrorTestEqual();
215 testFailed("Illegal stage.");
221 function ascendingErrorTestEqual()
224 var request = evalAndLog("indexObject.openKeyCursor(null, 'next')");
226 request.onerror = unexpectedErrorCallback;
227 request.onsuccess = function() {
228 if (self.stage === 0) {
229 shouldBe("event.target.result.primaryKey", "0");
230 evalAndLog("event.target.result.continue(3.14159)");
231 } else if (self.stage == 1) {
232 shouldBe("event.target.result.primaryKey", "3");
233 evalAndExpectException("event.target.result.continue(3.14159)", "0", "'DataError'");
234 descendingErrorTestGreaterThan();
237 testFailed("Illegal stage.");
243 function descendingErrorTestGreaterThan()
246 var request = evalAndLog("indexObject.openKeyCursor(null, 'prev')");
248 request.onerror = unexpectedErrorCallback;
249 request.onsuccess = function() {
250 if (self.stage == 0) {
251 shouldBe("event.target.result.primaryKey", "17");
252 evalAndLog("event.target.result.continue('A bit2')");
253 } else if (self.stage == 1) {
254 shouldBe("event.target.result.primaryKey", "15");
255 evalAndExpectException("event.target.result.continue('A bit3')", "0", "'DataError'");
256 descendingErrorTestEqual();
259 testFailed("Illegal stage.");
265 function descendingErrorTestEqual()
268 var request = evalAndLog("indexObject.openKeyCursor(null, 'prev')");
270 request.onerror = unexpectedErrorCallback;
271 request.onsuccess = function() {
272 if (self.stage == 0) {
273 shouldBe("event.target.result.primaryKey", "17");
274 evalAndLog("event.target.result.continue('A bit2')");
275 } else if (self.stage == 1) {
276 shouldBe("event.target.result.primaryKey", "15");
277 evalAndLog("cursor = event.target.result");
278 evalAndExpectException("event.target.result.continue('A bit2')", "0", "'DataError'");
281 testFailed("Illegal stage.");
287 function onTransactionComplete()
289 evalAndExpectException("cursor.continue()", "0", "'TransactionInactiveError'");