Chromium Code Reviews| Index: chrome/test/data/indexeddb/perf_test.js |
| diff --git a/chrome/test/data/indexeddb/perf_test.js b/chrome/test/data/indexeddb/perf_test.js |
| index a90b69999f43dfffc9dc3f1dbe9c6cea40b5f8f7..2ad37a9833c6f5b4420539f139bbab7d1b7df148 100644 |
| --- a/chrome/test/data/indexeddb/perf_test.js |
| +++ b/chrome/test/data/indexeddb/perf_test.js |
| @@ -105,6 +105,10 @@ var tests = [ |
| // Walk through many cursors into the same object store, round-robin, until |
| // you've reached the end of each of them. |
| [testWalkingMultipleCursors, 50], |
| +// Open an object store cursor, then continue(key) to the last value. |
| + [testCursorSeeks, 2000, 10, 4, kDontUseIndex], |
| +// Open an index key cursor, then continue(key) to the last value. |
| + [testCursorSeeks, 2000, 10, 4, kUseIndex], |
| ]; |
| var currentTest = 0; |
| @@ -604,3 +608,69 @@ function testWalkingMultipleCursors(numCursors, onTestComplete) { |
| } |
| } |
| +function testCursorSeeks( |
| + numKeys, numSeeksPerTransaction, numTransactions, useIndexForReads, |
| + onTestComplete) { |
| + var testName = getDisplayName(arguments); |
| + var objectStoreNames = ["store"]; |
| + var getKey = useIndexForReads ? getForwardIndexKey : getSimpleKey; |
| + var indexName; |
| + if (useIndexForReads) { |
| + indexName = "index"; |
| + } |
| + |
| + automation.setStatus("Creating database."); |
| + var options; |
| + if (useIndexForReads) { |
| + options = [{ |
| + indexName: indexName, |
| + indexKeyPath: "firstName", |
| + indexIsUnique: true, |
| + indexIsMultiEntry: false, |
| + }]; |
| + } |
| + createDatabase(testName, objectStoreNames, onCreated, onError, options); |
| + |
| + function onCreated(db) { |
| + console.log("created: " + testName); |
|
dgrogan
2013/03/16 00:49:51
Unintentional?
|
| + automation.setStatus("Setting up test database."); |
| + var transaction = getTransaction(db, objectStoreNames, "readwrite", |
| + function() { onSetupComplete(db); }); |
| + putLinearValues(transaction, objectStoreNames, numKeys, getSimpleKey, |
| + getObjectValue); |
| + } |
| + function onSetupComplete(db) { |
| + automation.setStatus("Setup complete."); |
| + var completionFunc = |
| + getCompletionFunc(db, testName, Date.now(), onTestComplete); |
| + var mode = "readonly"; |
| + runTransactionBatch(db, numTransactions, batchFunc, objectStoreNames, mode, |
| + completionFunc); |
| + } |
| + |
| + function batchFunc(transaction) { |
| + for (var i in objectStoreNames) { |
| + var os = transaction.objectStore(objectStoreNames[i]); |
| + var source = os; |
|
dgrogan
2013/03/16 00:49:51
I'd say get rid of the os variable.
|
| + if (useIndexForReads) |
| + source = source.index(indexName); |
| + for (var j = 0; j < numSeeksPerTransaction; ++j) { |
| + randomSeek(source); |
| + } |
| + } |
| + } |
| + |
| + function randomSeek(source) { |
| + var request = useIndexForReads ? source.openKeyCursor() |
|
dgrogan
2013/03/16 00:49:51
Why not always use a CursorWithValue?
|
| + : source.openCursor(); |
| + var first = true; |
| + request.onerror = onError; |
| + request.onsuccess = function() { |
| + var cursor = request.result; |
| + if (cursor && first) { |
| + first = false; |
| + cursor.continue(getKey(numKeys - 1)); |
| + } |
| + }; |
| + } |
| +} |