Chromium Code Reviews| 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 var overallTestStartTime = Date.now(); | 5 var overallTestStartTime = Date.now(); |
| 6 var kUseIndex = true; | 6 var kUseIndex = true; |
| 7 var kDontUseIndex = false; | 7 var kDontUseIndex = false; |
| 8 var kReadKeysOnly = true; | 8 var kReadKeysOnly = true; |
| 9 var kReadDataToo = false; | 9 var kReadDataToo = false; |
| 10 var kWriteToo = true; | 10 var kWriteToo = true; |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 98 [testReadCache, 50, kUseIndex], | 98 [testReadCache, 50, kUseIndex], |
| 99 // Create and delete an index on a store that already contains data [produces | 99 // Create and delete an index on a store that already contains data [produces |
| 100 // a timing result for each of creation and deletion]. | 100 // a timing result for each of creation and deletion]. |
| 101 [testCreateAndDeleteIndex, 5000], | 101 [testCreateAndDeleteIndex, 5000], |
| 102 // Walk through multiple cursors into the same object store, round-robin, until | 102 // Walk through multiple cursors into the same object store, round-robin, until |
| 103 // you've reached the end of each of them. | 103 // you've reached the end of each of them. |
| 104 [testWalkingMultipleCursors, 5], | 104 [testWalkingMultipleCursors, 5], |
| 105 // Walk through many cursors into the same object store, round-robin, until | 105 // Walk through many cursors into the same object store, round-robin, until |
| 106 // you've reached the end of each of them. | 106 // you've reached the end of each of them. |
| 107 [testWalkingMultipleCursors, 50], | 107 [testWalkingMultipleCursors, 50], |
| 108 // Open an object store cursor, then continue(key) to the last value. | |
| 109 [testCursorSeeks, 2000, 10, 4, kDontUseIndex], | |
| 110 // Open an index key cursor, then continue(key) to the last value. | |
| 111 [testCursorSeeks, 2000, 10, 4, kUseIndex], | |
| 108 ]; | 112 ]; |
| 109 | 113 |
| 110 var currentTest = 0; | 114 var currentTest = 0; |
| 111 | 115 |
| 112 function test() { | 116 function test() { |
| 113 runNextTest(); | 117 runNextTest(); |
| 114 } | 118 } |
| 115 | 119 |
| 116 function runNextTest() { | 120 function runNextTest() { |
| 117 var filter = window.location.hash.slice(1); | 121 var filter = window.location.hash.slice(1); |
| (...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 597 } | 601 } |
| 598 }; | 602 }; |
| 599 } | 603 } |
| 600 } | 604 } |
| 601 function verifyComplete() { | 605 function verifyComplete() { |
| 602 assert(!cursorsRunning); | 606 assert(!cursorsRunning); |
| 603 completionFunc(); | 607 completionFunc(); |
| 604 } | 608 } |
| 605 } | 609 } |
| 606 | 610 |
| 611 function testCursorSeeks( | |
| 612 numKeys, numSeeksPerTransaction, numTransactions, useIndexForReads, | |
| 613 onTestComplete) { | |
| 614 var testName = getDisplayName(arguments); | |
| 615 var objectStoreNames = ["store"]; | |
| 616 var getKey = useIndexForReads ? getForwardIndexKey : getSimpleKey; | |
| 617 var indexName; | |
| 618 if (useIndexForReads) { | |
| 619 indexName = "index"; | |
| 620 } | |
| 621 | |
| 622 automation.setStatus("Creating database."); | |
| 623 var options; | |
| 624 if (useIndexForReads) { | |
| 625 options = [{ | |
| 626 indexName: indexName, | |
| 627 indexKeyPath: "firstName", | |
| 628 indexIsUnique: true, | |
| 629 indexIsMultiEntry: false, | |
| 630 }]; | |
| 631 } | |
| 632 createDatabase(testName, objectStoreNames, onCreated, onError, options); | |
| 633 | |
| 634 function onCreated(db) { | |
| 635 console.log("created: " + testName); | |
|
dgrogan
2013/03/16 00:49:51
Unintentional?
| |
| 636 automation.setStatus("Setting up test database."); | |
| 637 var transaction = getTransaction(db, objectStoreNames, "readwrite", | |
| 638 function() { onSetupComplete(db); }); | |
| 639 putLinearValues(transaction, objectStoreNames, numKeys, getSimpleKey, | |
| 640 getObjectValue); | |
| 641 } | |
| 642 function onSetupComplete(db) { | |
| 643 automation.setStatus("Setup complete."); | |
| 644 var completionFunc = | |
| 645 getCompletionFunc(db, testName, Date.now(), onTestComplete); | |
| 646 var mode = "readonly"; | |
| 647 runTransactionBatch(db, numTransactions, batchFunc, objectStoreNames, mode, | |
| 648 completionFunc); | |
| 649 } | |
| 650 | |
| 651 function batchFunc(transaction) { | |
| 652 for (var i in objectStoreNames) { | |
| 653 var os = transaction.objectStore(objectStoreNames[i]); | |
| 654 var source = os; | |
|
dgrogan
2013/03/16 00:49:51
I'd say get rid of the os variable.
| |
| 655 if (useIndexForReads) | |
| 656 source = source.index(indexName); | |
| 657 for (var j = 0; j < numSeeksPerTransaction; ++j) { | |
| 658 randomSeek(source); | |
| 659 } | |
| 660 } | |
| 661 } | |
| 662 | |
| 663 function randomSeek(source) { | |
| 664 var request = useIndexForReads ? source.openKeyCursor() | |
|
dgrogan
2013/03/16 00:49:51
Why not always use a CursorWithValue?
| |
| 665 : source.openCursor(); | |
| 666 var first = true; | |
| 667 request.onerror = onError; | |
| 668 request.onsuccess = function() { | |
| 669 var cursor = request.result; | |
| 670 if (cursor && first) { | |
| 671 first = false; | |
| 672 cursor.continue(getKey(numKeys - 1)); | |
| 673 } | |
| 674 }; | |
| 675 } | |
| 676 } | |
| OLD | NEW |