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 window.indexedDB = window.indexedDB || window.webkitIndexedDB || | 5 window.indexedDB = window.indexedDB || window.webkitIndexedDB || |
6 window.mozIndexedDB || window.msIndexedDB; | 6 window.mozIndexedDB || window.msIndexedDB; |
7 window.IDBKeyRange = window.IDBKeyRange || window.webkitIDBKeyRange; | 7 window.IDBKeyRange = window.IDBKeyRange || window.webkitIDBKeyRange; |
8 | 8 |
9 var automation = { | 9 var automation = { |
10 results: {} | 10 results: {} |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 getValue = getSimpleValue; | 271 getValue = getSimpleValue; |
272 for (var i in objectStoreNames) { | 272 for (var i in objectStoreNames) { |
273 var os = transaction.objectStore(objectStoreNames[i]); | 273 var os = transaction.objectStore(objectStoreNames[i]); |
274 for (var j = 0; j < numKeys; ++j) { | 274 for (var j = 0; j < numKeys; ++j) { |
275 var request = os.put(getValue(j), getKey(j)); | 275 var request = os.put(getValue(j), getKey(j)); |
276 request.onerror = onError; | 276 request.onerror = onError; |
277 } | 277 } |
278 } | 278 } |
279 } | 279 } |
280 | 280 |
| 281 function verifyResultNonNull(result) { |
| 282 assert(result != null); |
| 283 } |
| 284 |
281 function getRandomValues( | 285 function getRandomValues( |
282 transaction, objectStoreNames, numReads, numKeys, indexName, getKey) { | 286 transaction, objectStoreNames, numReads, numKeys, indexName, getKey) { |
283 if (!getKey) | 287 if (!getKey) |
284 getKey = getSimpleKey; | 288 getKey = getSimpleKey; |
285 for (var i in objectStoreNames) { | 289 for (var i in objectStoreNames) { |
286 var os = transaction.objectStore(objectStoreNames[i]); | 290 var os = transaction.objectStore(objectStoreNames[i]); |
287 var source = os; | 291 var source = os; |
288 if (indexName) | 292 if (indexName) |
289 source = source.index(indexName); | 293 source = source.index(indexName); |
290 for (var j = 0; j < numReads; ++j) { | 294 for (var j = 0; j < numReads; ++j) { |
291 var rand = Math.floor(Math.random() * numKeys); | 295 var rand = Math.floor(Math.random() * numKeys); |
292 var request = source.get(getKey(rand)); | 296 var request = source.get(getKey(rand)); |
293 request.onerror = onError; | 297 request.onerror = onError; |
| 298 request.onsuccess = verifyResultNonNull; |
294 } | 299 } |
295 } | 300 } |
296 } | 301 } |
297 | 302 |
298 function putRandomValues( | 303 function putRandomValues( |
299 transaction, objectStoreNames, numPuts, numKeys, getKey, getValue) { | 304 transaction, objectStoreNames, numPuts, numKeys, getKey, getValue) { |
300 if (!getKey) | 305 if (!getKey) |
301 getKey = getSimpleKey; | 306 getKey = getSimpleKey; |
302 if (!getValue) | 307 if (!getValue) |
303 getValue = getSimpleValue; | 308 getValue = getSimpleValue; |
304 for (var i in objectStoreNames) { | 309 for (var i in objectStoreNames) { |
305 var os = transaction.objectStore(objectStoreNames[i]); | 310 var os = transaction.objectStore(objectStoreNames[i]); |
306 for (var j = 0; j < numPuts; ++j) { | 311 for (var j = 0; j < numPuts; ++j) { |
307 var rand = Math.floor(Math.random() * numKeys); | 312 var rand = Math.floor(Math.random() * numKeys); |
308 var request = os.put(getValue(rand), getKey(rand)); | 313 var request = os.put(getValue(rand), getKey(rand)); |
309 request.onerror = onError; | 314 request.onerror = onError; |
310 } | 315 } |
311 } | 316 } |
312 } | 317 } |
313 | 318 |
| 319 function getSpecificValues(transaction, objectStoreNames, indexName, keys) { |
| 320 for (var i in objectStoreNames) { |
| 321 var os = transaction.objectStore(objectStoreNames[i]); |
| 322 var source = os; |
| 323 if (indexName) |
| 324 source = source.index(indexName); |
| 325 for (var j = 0; j < keys.length; ++j) { |
| 326 var request = source.get(keys[j]); |
| 327 request.onerror = onError; |
| 328 request.onsuccess = verifyResultNonNull; |
| 329 } |
| 330 } |
| 331 } |
| 332 |
314 // getKey should be deterministic, as we assume that a cursor that starts at | 333 // getKey should be deterministic, as we assume that a cursor that starts at |
315 // getKey(X) and runs through getKey(X + K) has exactly K values available. | 334 // getKey(X) and runs through getKey(X + K) has exactly K values available. |
316 // This is annoying to guarantee generally when using an index, so we avoid both | 335 // This is annoying to guarantee generally when using an index, so we avoid both |
317 // ends of the key space just in case and use simple indices. | 336 // ends of the key space just in case and use simple indices. |
318 // TODO(ericu): Figure out if this can be simplified and we can remove uses of | 337 // TODO(ericu): Figure out if this can be simplified and we can remove uses of |
319 // getObjectValue in favor of getNFieldObjectValue. | 338 // getObjectValue in favor of getNFieldObjectValue. |
320 function getValuesFromCursor( | 339 function getValuesFromCursor( |
321 transaction, inputObjectStoreName, numReads, numKeys, indexName, getKey, | 340 transaction, inputObjectStoreName, numReads, numKeys, indexName, getKey, |
322 readKeysOnly, outputObjectStoreName) { | 341 readKeysOnly, outputObjectStoreName) { |
323 assert(2 * numReads < numKeys); | 342 assert(2 * numReads < numKeys); |
(...skipping 29 matching lines...) Expand all Loading... |
353 // outside its range. | 372 // outside its range. |
354 oos.put(cursor.value, numKeys + Math.random()); | 373 oos.put(cursor.value, numKeys + Math.random()); |
355 values.push({key: cursor.key, value: cursor.value}); | 374 values.push({key: cursor.key, value: cursor.value}); |
356 cursor.continue(); | 375 cursor.continue(); |
357 } else { | 376 } else { |
358 assert(!numReadsLeft); | 377 assert(!numReadsLeft); |
359 } | 378 } |
360 } | 379 } |
361 request.onerror = onError; | 380 request.onerror = onError; |
362 } | 381 } |
| 382 |
| 383 function runTransactionBatch(db, count, batchFunc, objectStoreNames, mode, |
| 384 onComplete) { |
| 385 var numTransactionsRunning = 0; |
| 386 |
| 387 runOneBatch(db); |
| 388 |
| 389 function runOneBatch(db) { |
| 390 if (count <= 0) { |
| 391 return; |
| 392 } |
| 393 --count; |
| 394 ++numTransactionsRunning; |
| 395 var transaction = getTransaction(db, objectStoreNames, mode, |
| 396 function() { |
| 397 assert(!--numTransactionsRunning); |
| 398 if (count <= 0) { |
| 399 onComplete(); |
| 400 } else { |
| 401 runOneBatch(db); |
| 402 } |
| 403 }); |
| 404 |
| 405 batchFunc(transaction); |
| 406 } |
| 407 } |
| 408 |
OLD | NEW |