OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 var overallTestStartTime = Date.now(); |
| 6 |
| 7 function testCreateKeysInStores( |
| 8 numKeys, numStores, payloadLength, onTestComplete) { |
| 9 var testName = "testCreateKeysInStores_" + numKeys + "_" + numStores + "_" + |
| 10 payloadLength; |
| 11 assert(numKeys >= 0); |
| 12 assert(numStores >= 1); |
| 13 var objectStoreNames = []; |
| 14 for (var i=0; i < numStores; ++i) { |
| 15 objectStoreNames.push("store " + i); |
| 16 } |
| 17 var value = stringOfLength(payloadLength); |
| 18 var start; |
| 19 |
| 20 function onCreated(db) { |
| 21 automation.setStatus("Constructing transaction."); |
| 22 start = Date.now(); // Ignore the setup time for this test. |
| 23 var transaction = getTransaction(db, objectStoreNames, "readwrite", |
| 24 function() { onTransactionComplete(db); }); |
| 25 for (var i in objectStoreNames) { |
| 26 var os = transaction.objectStore(objectStoreNames[i]); |
| 27 assert(os); |
| 28 for (var j = 0; j < numKeys; ++j) { |
| 29 os.put("key " + j, value); |
| 30 } |
| 31 } |
| 32 } |
| 33 function onTransactionComplete(db) { |
| 34 var duration = Date.now() - start; |
| 35 // Ignore the cleanup time for this test. |
| 36 automation.addResult(testName, duration); |
| 37 automation.setStatus("Deleting."); |
| 38 deleteDatabase(db, onDeleted); |
| 39 } |
| 40 function onDeleted() { |
| 41 automation.setStatus("Deleted."); |
| 42 onTestComplete(); |
| 43 } |
| 44 automation.setStatus("Creating."); |
| 45 createDatabase(testName, objectStoreNames, onCreated, onError); |
| 46 } |
| 47 |
| 48 var tests = [ |
| 49 [testCreateKeysInStores, 1, 1, 1], |
| 50 [testCreateKeysInStores, 100, 1, 1], |
| 51 [testCreateKeysInStores, 1, 100, 1], |
| 52 [testCreateKeysInStores, 100, 1, 100000] |
| 53 ]; |
| 54 |
| 55 var currentTest = 0; |
| 56 |
| 57 function runNextTest() { |
| 58 if (currentTest < tests.length) { |
| 59 var test = tests[currentTest++].slice(); |
| 60 var f = test.shift(); |
| 61 test.push(runNextTest); |
| 62 f.apply(null, test); |
| 63 } else { |
| 64 onAllTestsComplete(); |
| 65 } |
| 66 } |
| 67 |
| 68 function onAllTestsComplete() { |
| 69 var overallDuration = Date.now() - overallTestStartTime; |
| 70 automation.addResult("OverallTestDuration", overallDuration); |
| 71 automation.setDone(); |
| 72 } |
| 73 |
| 74 function test() { |
| 75 runNextTest(); |
| 76 } |
OLD | NEW |