OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // These constants should match the ones in renderer_webidbcursor_impl.h | 5 // These constants should match the ones in renderer_webidbcursor_impl.h |
6 // to make sure the test hits the right code paths. | 6 // to make sure the test hits the right code paths. |
7 var kPrefetchThreshold = 2; | 7 var kPrefetchThreshold = 2; |
8 var kMinPrefetchAmount = 5; | 8 var kMinPrefetchAmount = 5; |
9 | 9 |
10 var kNumberOfItems = 200; | 10 var kNumberOfItems = 200; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 } | 60 } |
61 | 61 |
62 if (cursor.key !== count) | 62 if (cursor.key !== count) |
63 shouldBe("cursor.key", "count"); | 63 shouldBe("cursor.key", "count"); |
64 if (cursor.value !== count) | 64 if (cursor.value !== count) |
65 shouldBe("cursor.value", "count"); | 65 shouldBe("cursor.value", "count"); |
66 | 66 |
67 ++count; | 67 ++count; |
68 | 68 |
69 cursor.continue(); | 69 cursor.continue(); |
70 } | 70 }; |
71 } | 71 } |
72 | 72 |
73 function secondTest() { | 73 function secondTest() { |
74 debug("secondTest()"); | 74 debug("secondTest()"); |
75 | 75 |
76 // Test iterating through the object store, intermixed with | 76 // Test iterating through the object store, intermixed with |
77 // continue calls to specific keys. | 77 // continue calls to specific keys. |
78 | 78 |
79 var trans = db.transaction(['store'], 'readwrite'); | 79 var trans = db.transaction(['store'], 'readwrite'); |
80 trans.onabort = unexpectedAbortCallback; | 80 trans.onabort = unexpectedAbortCallback; |
(...skipping 30 matching lines...) Expand all Loading... |
111 if (jumpTable[i].from === cursor.key) { | 111 if (jumpTable[i].from === cursor.key) { |
112 expectedKey = jumpTable[i].to; | 112 expectedKey = jumpTable[i].to; |
113 debug("Jumping from "+ cursor.key + " to " + expectedKey); | 113 debug("Jumping from "+ cursor.key + " to " + expectedKey); |
114 cursor.continue(expectedKey); | 114 cursor.continue(expectedKey); |
115 return; | 115 return; |
116 } | 116 } |
117 } | 117 } |
118 | 118 |
119 ++expectedKey; | 119 ++expectedKey; |
120 cursor.continue(); | 120 cursor.continue(); |
121 } | 121 }; |
122 } | 122 } |
123 | 123 |
124 function thirdTest() { | 124 function thirdTest() { |
125 debug("thirdTest()"); | 125 debug("thirdTest()"); |
126 | 126 |
127 // Test iterating straight through the object store in reverse. | 127 // Test iterating straight through the object store in reverse. |
128 | 128 |
129 var trans = db.transaction(['store'], 'readwrite'); | 129 var trans = db.transaction(['store'], 'readwrite'); |
130 trans.onabort = unexpectedAbortCallback; | 130 trans.onabort = unexpectedAbortCallback; |
131 trans.oncomplete = fourthTest; | 131 trans.oncomplete = fourthTest; |
(...skipping 14 matching lines...) Expand all Loading... |
146 expectedKey = kNumberOfItems - count - 1; | 146 expectedKey = kNumberOfItems - count - 1; |
147 | 147 |
148 if (cursor.key !== expectedKey) | 148 if (cursor.key !== expectedKey) |
149 shouldBe("cursor.key", "expectedKey"); | 149 shouldBe("cursor.key", "expectedKey"); |
150 if (cursor.value !== expectedKey) | 150 if (cursor.value !== expectedKey) |
151 shouldBe("cursor.value", "expectedKey"); | 151 shouldBe("cursor.value", "expectedKey"); |
152 | 152 |
153 ++count; | 153 ++count; |
154 | 154 |
155 cursor.continue(); | 155 cursor.continue(); |
156 } | 156 }; |
157 } | 157 } |
158 | 158 |
159 function fourthTest() { | 159 function fourthTest() { |
160 debug("fourthTest()"); | 160 debug("fourthTest()"); |
161 | 161 |
162 // Test iterating, and then stopping before reaching the end. | 162 // Test iterating, and then stopping before reaching the end. |
163 // Make sure transaction terminates anyway. | 163 // Make sure transaction terminates anyway. |
164 | 164 |
165 var trans = db.transaction(['store'], 'readwrite'); | 165 var trans = db.transaction(['store'], 'readwrite'); |
166 trans.onabort = unexpectedAbortCallback; | 166 trans.onabort = unexpectedAbortCallback; |
167 trans.oncomplete = function() { | 167 trans.oncomplete = function() { |
168 debug("fourthTest() transaction completed"); | 168 debug("fourthTest() transaction completed"); |
169 fifthTest(); | 169 fifthTest(); |
170 } | 170 }; |
171 | 171 |
172 var store = trans.objectStore('store'); | 172 var store = trans.objectStore('store'); |
173 var cursorReq = store.openCursor(); | 173 var cursorReq = store.openCursor(); |
174 cursorReq.onerror = unexpectedErrorCallback; | 174 cursorReq.onerror = unexpectedErrorCallback; |
175 | 175 |
176 count = 0; | 176 count = 0; |
177 cursorReq.onsuccess = function() { | 177 cursorReq.onsuccess = function() { |
178 cursor = event.target.result; | 178 cursor = event.target.result; |
179 | 179 |
180 if (cursor.key !== count) | 180 if (cursor.key !== count) |
181 shouldBe("cursor.key", "count"); | 181 shouldBe("cursor.key", "count"); |
182 if (cursor.value !== count) | 182 if (cursor.value !== count) |
183 shouldBe("cursor.value", "count"); | 183 shouldBe("cursor.value", "count"); |
184 | 184 |
185 ++count; | 185 ++count; |
186 | 186 |
187 if (count === 25) { | 187 if (count === 25) { |
188 // Schedule some other request. | 188 // Schedule some other request. |
189 var otherReq = store.get(42); | 189 var otherReq = store.get(42); |
190 otherReq.onerror = unexpectedErrorCallback; | 190 otherReq.onerror = unexpectedErrorCallback; |
191 otherReq.onsuccess = function() { | 191 otherReq.onsuccess = function() { |
192 if (count === 25) { | 192 if (count === 25) { |
193 debug("Other request fired before continue, as expected."); | 193 debug("Other request fired before continue, as expected."); |
194 } else { | 194 } else { |
195 debug("Other request fired out-of-order!"); | 195 debug("Other request fired out-of-order!"); |
196 fail(); | 196 fail(); |
197 } | 197 } |
198 } | 198 }; |
199 | 199 |
200 cursor.continue(); | 200 cursor.continue(); |
201 return; | 201 return; |
202 } | 202 } |
203 | 203 |
204 if (count === 30) { | 204 if (count === 30) { |
205 // Do a continue first, then another request. | 205 // Do a continue first, then another request. |
206 cursor.continue(); | 206 cursor.continue(); |
207 | 207 |
208 var otherReq = store.get(42); | 208 var otherReq = store.get(42); |
209 otherReq.onerror = unexpectedErrorCallback; | 209 otherReq.onerror = unexpectedErrorCallback; |
210 otherReq.onsuccess = function() { | 210 otherReq.onsuccess = function() { |
211 if (count === 31) { | 211 if (count === 31) { |
212 debug("Other request fired right after continue as expected."); | 212 debug("Other request fired right after continue as expected."); |
213 } else { | 213 } else { |
214 debug("Other request didn't fire right after continue as expected."); | 214 debug("Other request didn't fire right after continue as expected."); |
215 fail(); | 215 fail(); |
216 } | 216 } |
217 } | 217 }; |
218 | 218 |
219 return; | 219 return; |
220 } | 220 } |
221 | 221 |
222 if (count === 75) { | 222 if (count === 75) { |
223 return; // Sudden stop. | 223 return; // Sudden stop. |
224 } | 224 } |
225 | 225 |
226 cursor.continue(); | 226 cursor.continue(); |
227 } | 227 }; |
228 } | 228 } |
229 | 229 |
230 function fifthTest() { | 230 function fifthTest() { |
231 debug("fifthTest()"); | 231 debug("fifthTest()"); |
232 | 232 |
233 // Test iterating over the pre-fetch threshold, but make sure the | 233 // Test iterating over the pre-fetch threshold, but make sure the |
234 // cursor is positioned so that it is actually at the last element | 234 // cursor is positioned so that it is actually at the last element |
235 // in the range when pre-fetch fires, and make sure a null cursor | 235 // in the range when pre-fetch fires, and make sure a null cursor |
236 // is the result as expected. | 236 // is the result as expected. |
237 | 237 |
(...skipping 13 matching lines...) Expand all Loading... |
251 | 251 |
252 if (cursor === null) { | 252 if (cursor === null) { |
253 debug("cursor is null"); | 253 debug("cursor is null"); |
254 shouldBe("count", "kPrefetchThreshold + 1"); | 254 shouldBe("count", "kPrefetchThreshold + 1"); |
255 return; | 255 return; |
256 } | 256 } |
257 | 257 |
258 debug("count: " + count); | 258 debug("count: " + count); |
259 ++count; | 259 ++count; |
260 cursor.continue(); | 260 cursor.continue(); |
261 } | 261 }; |
262 } | 262 } |
263 | 263 |
264 function sixthTest() { | 264 function sixthTest() { |
265 debug("sixthTest()"); | 265 debug("sixthTest()"); |
266 | 266 |
267 // Test stepping two cursors simultaneously. First cursor1 steps | 267 // Test stepping two cursors simultaneously. First cursor1 steps |
268 // for a while, then cursor2, then back to cursor1, etc. | 268 // for a while, then cursor2, then back to cursor1, etc. |
269 | 269 |
270 var trans = db.transaction(['store'], 'readwrite'); | 270 var trans = db.transaction(['store'], 'readwrite'); |
271 trans.onabort = unexpectedAbortCallback; | 271 trans.onabort = unexpectedAbortCallback; |
(...skipping 29 matching lines...) Expand all Loading... |
301 if (cursor2 !== null) { | 301 if (cursor2 !== null) { |
302 cursor2.continue(); | 302 cursor2.continue(); |
303 } else { | 303 } else { |
304 var req = store.openCursor(); | 304 var req = store.openCursor(); |
305 req.onerror = unexpectedErrorCallback; | 305 req.onerror = unexpectedErrorCallback; |
306 req.onsuccess = cursor2func; | 306 req.onsuccess = cursor2func; |
307 } | 307 } |
308 } else { | 308 } else { |
309 cursor1.continue(); | 309 cursor1.continue(); |
310 } | 310 } |
311 } | 311 }; |
312 | 312 |
313 var cursor2func = function() { | 313 var cursor2func = function() { |
314 var cursor = event.target.result; | 314 var cursor = event.target.result; |
315 if (cursor === null) { | 315 if (cursor === null) { |
316 shouldBe("count2", "kNumberOfItems"); | 316 shouldBe("count2", "kNumberOfItems"); |
317 return; | 317 return; |
318 } | 318 } |
319 | 319 |
320 if (cursor2 === null) { | 320 if (cursor2 === null) { |
321 cursor2 = cursor; | 321 cursor2 = cursor; |
322 } | 322 } |
323 | 323 |
324 if (cursor2.key !== count2) | 324 if (cursor2.key !== count2) |
325 shouldBe("cursor2.key", "count2"); | 325 shouldBe("cursor2.key", "count2"); |
326 if (cursor2.value !== count2) | 326 if (cursor2.value !== count2) |
327 shouldBe("cursor2.value", "count2"); | 327 shouldBe("cursor2.value", "count2"); |
328 | 328 |
329 ++count2; | 329 ++count2; |
330 | 330 |
331 if (count2 % 20 === 0) { | 331 if (count2 % 20 === 0) { |
332 cursor1.continue(); | 332 cursor1.continue(); |
333 } else { | 333 } else { |
334 cursor2.continue(); | 334 cursor2.continue(); |
335 } | 335 } |
336 } | 336 }; |
337 | 337 |
338 var req = store.openCursor(); | 338 var req = store.openCursor(); |
339 req.onerror = unexpectedErrorCallback; | 339 req.onerror = unexpectedErrorCallback; |
340 req.onsuccess = cursor1func; | 340 req.onsuccess = cursor1func; |
341 } | 341 } |
342 | 342 |
343 function seventhTest() { | 343 function seventhTest() { |
344 debug("seventhTest()"); | 344 debug("seventhTest()"); |
345 | 345 |
346 // Test iterating straight through an index. | 346 // Test iterating straight through an index. |
(...skipping 18 matching lines...) Expand all Loading... |
365 | 365 |
366 if (cursor.key !== count) | 366 if (cursor.key !== count) |
367 shouldBe("cursor.key", "count"); | 367 shouldBe("cursor.key", "count"); |
368 if (cursor.primaryKey !== count) | 368 if (cursor.primaryKey !== count) |
369 shouldBe("cursor.primaryKey", "count"); | 369 shouldBe("cursor.primaryKey", "count"); |
370 if (cursor.value !== count) | 370 if (cursor.value !== count) |
371 shouldBe("cursor.value", "count"); | 371 shouldBe("cursor.value", "count"); |
372 | 372 |
373 ++count; | 373 ++count; |
374 cursor.continue(); | 374 cursor.continue(); |
375 } | 375 }; |
376 } | 376 } |
377 | 377 |
378 function eighthTest() { | 378 function eighthTest() { |
379 debug("eighthTest()"); | 379 debug("eighthTest()"); |
380 | 380 |
381 // Run a key cursor over an index. | 381 // Run a key cursor over an index. |
382 | 382 |
383 var trans = db.transaction(['store'], 'readwrite'); | 383 var trans = db.transaction(['store'], 'readwrite'); |
384 trans.onabort = unexpectedAbortCallback; | 384 trans.onabort = unexpectedAbortCallback; |
385 trans.oncomplete = done; | 385 trans.oncomplete = done; |
(...skipping 12 matching lines...) Expand all Loading... |
398 return; | 398 return; |
399 } | 399 } |
400 | 400 |
401 if (cursor.key !== count) | 401 if (cursor.key !== count) |
402 shouldBe("cursor.key", "count"); | 402 shouldBe("cursor.key", "count"); |
403 if (cursor.primaryKey !== count) | 403 if (cursor.primaryKey !== count) |
404 shouldBe("cursor.primaryKey", "count"); | 404 shouldBe("cursor.primaryKey", "count"); |
405 | 405 |
406 ++count; | 406 ++count; |
407 cursor.continue(); | 407 cursor.continue(); |
408 } | 408 }; |
409 } | 409 } |
OLD | NEW |