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 = window.performance.now(); | 5 var overallTestStartTime = window.performance.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; |
11 var kDontWrite = false; | 11 var kDontWrite = false; |
12 var kWriteSameStore = true; | 12 var kWriteSameStore = true; |
13 var kWriteDifferentStore = false; | 13 var kWriteDifferentStore = false; |
14 var kPlaceholderArg = false; | 14 var kPlaceholderArg = false; |
15 var kDontRead = false; | 15 var kDontRead = false; |
16 var kAlternateWithReads = true; | 16 var kAlternateWithReads = true; |
17 | 17 |
18 var tests = [ | 18 var tests = [ |
| 19 // Create 30 databases, populate them with 20 object stores with 10 items |
| 20 // each, and then open them 60 times. Each item is 100 bytes long. |
| 21 [testCreateAndDeleteDatabases, 30, 60, 10, 20, 100], |
19 // Create a single small item in a single object store, then delete everything. | 22 // Create a single small item in a single object store, then delete everything. |
20 [testCreateAndDeleteDatabase, 1, 1, 1], | 23 [testCreateAndDeleteDatabase, 1, 1, 1], |
21 // Create many small items in a single object store, then delete everything. | 24 // Create many small items in a single object store, then delete everything. |
22 [testCreateAndDeleteDatabase, 1000, 1, 1], | 25 [testCreateAndDeleteDatabase, 1000, 1, 1], |
23 // Create a single small item in many object stores, then delete everything. | 26 // Create a single small item in many object stores, then delete everything. |
24 [testCreateAndDeleteDatabase, 1, 1000, 1], | 27 [testCreateAndDeleteDatabase, 1, 1000, 1], |
25 // Create many large items in a single object store, then delete everything. | 28 // Create many large items in a single object store, then delete everything. |
26 [testCreateAndDeleteDatabase, 1000, 1, 10000], | 29 [testCreateAndDeleteDatabase, 1000, 1, 10000], |
27 // Create a single small item in a single object store. | 30 // Create a single small item in a single object store. |
28 [testCreateKeysInStores, 1, 1, 1], | 31 [testCreateKeysInStores, 1, 1, 1], |
29 // Create many small items in a single object store. | 32 // Create many small items in a single object store. |
30 [testCreateKeysInStores, 1000, 1, 1], | 33 [testCreateKeysInStores, 1000, 1, 1], |
31 // Create a single small item in many object stores. | 34 // Create a single small item in many object stores. |
32 [testCreateKeysInStores, 1, 1000, 1], | 35 [testCreateKeysInStores, 1, 1000, 1], |
33 // Create many large items in a single object store. | 36 // Create many large items in a single object store. |
34 [testCreateKeysInStores, 1000, 1, 10000], | 37 [testCreateKeysInStores, 1000, 1, 10000], |
| 38 |
35 // Read one item per transaction. | 39 // Read one item per transaction. |
36 [testRandomReadsAndWrites, 1000, 1, 0, 1000, kDontUseIndex], | 40 [testRandomReadsAndWritesWithoutIndex, 1000, 1, 0, 1000], |
37 // Read a few random items in each of many transactions. | 41 // Read a few random items in each of many transactions. |
38 [testRandomReadsAndWrites, 1000, 5, 0, 100, kDontUseIndex], | 42 [testRandomReadsAndWritesWithoutIndex, 1000, 5, 0, 100], |
39 // Read many random items in each of a few transactions. | 43 // Read many random items in each of a few transactions. |
40 [testRandomReadsAndWrites, 1000, 500, 0, 5, kDontUseIndex], | 44 [testRandomReadsAndWritesWithoutIndex, 1000, 500, 0, 5], |
41 // Read many random items in each of a few transactions, in a large store. | 45 // Read many random items in each of a few transactions, in a large store. |
42 [testRandomReadsAndWrites, 10000, 500, 0, 5, kDontUseIndex], | 46 [testRandomReadsAndWritesWithoutIndex, 10000, 500, 0, 5], |
| 47 // Read and write a few random items in each of many transactions. |
| 48 [testRandomReadsAndWritesWithoutIndex, 1000, 5, 5, 50], |
| 49 |
| 50 // Read one item per transaction. |
| 51 [testRandomReadsAndWritesWithIndex, 1000, 1, 0, 1000], |
43 // Read a few random items from an index, in each of many transactions. | 52 // Read a few random items from an index, in each of many transactions. |
44 [testRandomReadsAndWrites, 1000, 5, 0, 100, kUseIndex], | 53 [testRandomReadsAndWritesWithIndex, 1000, 5, 0, 100], |
45 // Read many random items from an index, in each of a few transactions. | 54 // Read many random items from an index, in each of a few transactions. |
46 [testRandomReadsAndWrites, 1000, 500, 0, 5, kUseIndex], | 55 [testRandomReadsAndWritesWithIndex, 1000, 500, 0, 5], |
47 // Read many random items from an index, in each of a few transactions, in a | 56 // Read many random items from an index, in each of a few transactions, in a |
48 // large store. | 57 // large store. |
49 [testRandomReadsAndWrites, 10000, 500, 0, 5, kUseIndex], | 58 [testRandomReadsAndWritesWithIndex, 10000, 500, 0, 5], |
50 // Read and write a few random items in each of many transactions. | |
51 [testRandomReadsAndWrites, 1000, 5, 5, 50, kDontUseIndex], | |
52 // Read and write a few random items, reading from an index, in each of many | 59 // Read and write a few random items, reading from an index, in each of many |
53 // transactions. | 60 // transactions. |
54 [testRandomReadsAndWrites, 1000, 5, 5, 50, kUseIndex], | 61 [testRandomReadsAndWritesWithIndex, 1000, 5, 5, 50], |
| 62 |
55 // Read a long, contiguous sequence of an object store via a cursor. | 63 // Read a long, contiguous sequence of an object store via a cursor. |
56 [testCursorReadsAndRandomWrites, kReadDataToo, kDontUseIndex, kDontWrite, | 64 [testCursorReadsAndRandomWrites, kReadDataToo, kDontUseIndex, kDontWrite, |
57 kPlaceholderArg], | 65 kPlaceholderArg], |
58 // Read a sequence of an object store via a cursor, writing | 66 // Read a sequence of an object store via a cursor, writing |
59 // transformed values into another. | 67 // transformed values into another. |
60 [testCursorReadsAndRandomWrites, kReadDataToo, kDontUseIndex, kWriteToo, | 68 [testCursorReadsAndRandomWrites, kReadDataToo, kDontUseIndex, kWriteToo, |
61 kWriteDifferentStore], | 69 kWriteDifferentStore], |
62 // Read a sequence of an object store via a cursor, writing | 70 // Read a sequence of an object store via a cursor, writing |
63 // transformed values into another. | 71 // transformed values into another. |
64 [testCursorReadsAndRandomWrites, kReadDataToo, kDontUseIndex, kWriteToo, | 72 [testCursorReadsAndRandomWrites, kReadDataToo, kDontUseIndex, kWriteToo, |
65 kWriteSameStore], | 73 kWriteSameStore], |
66 // Read a sequence of an index into an object store via a cursor. | 74 // Read a sequence of an index into an object store via a cursor. |
67 [testCursorReadsAndRandomWrites, kReadDataToo, kUseIndex, kDontWrite, | 75 [testCursorReadsAndRandomWrites, kReadDataToo, kUseIndex, kDontWrite, |
68 kPlaceholderArg], | 76 kPlaceholderArg], |
69 // Read a sequence of an index into an object store via a key cursor. | 77 // Read a sequence of an index into an object store via a key cursor. |
70 [testCursorReadsAndRandomWrites, kReadKeysOnly, kUseIndex, kDontWrite, | 78 [testCursorReadsAndRandomWrites, kReadKeysOnly, kUseIndex, kDontWrite, |
71 kPlaceholderArg], | 79 kPlaceholderArg], |
| 80 |
72 // Make a small bunch of batches of reads of the same keys from an object store. | 81 // Make a small bunch of batches of reads of the same keys from an object store. |
73 [testReadCache, 10, kDontUseIndex], | 82 [testReadCacheWithoutIndex, 10], |
| 83 // Make a bunch of batches of reads of the same keys from an object store. |
| 84 [testReadCacheWithoutIndex, 50], |
| 85 // Make a small bunch of batches of reads of the same keys from an object store. |
| 86 [testReadCacheWithIndex, 10], |
74 // Make a bunch of batches of reads of the same keys from an index. | 87 // Make a bunch of batches of reads of the same keys from an index. |
75 [testReadCache, 50, kUseIndex], | 88 [testReadCacheWithIndex, 50], |
76 // Make a small bunch of batches of reads of the same keys from an object store. | 89 |
77 [testReadCache, 10, kDontUseIndex], | |
78 // Make a bunch of batches of reads of the same keys from an index. | |
79 [testReadCache, 50, kUseIndex], | |
80 // Create and delete an index on a store that already contains data [produces | 90 // Create and delete an index on a store that already contains data [produces |
81 // a timing result for each of creation and deletion]. | 91 // a timing result for each of creation and deletion]. |
82 [testCreateAndDeleteIndex, 5000], | 92 [testCreateAndDeleteIndex, 5000], |
83 // Walk through multiple cursors into the same object store, round-robin, until | 93 // Walk through multiple cursors into the same object store, round-robin, until |
84 // you've reached the end of each of them. | 94 // you've reached the end of each of them. |
85 [testWalkingMultipleCursors, 5], | 95 [testWalkingMultipleCursors, 5], |
86 // Walk through many cursors into the same object store, round-robin, until | 96 // Walk through many cursors into the same object store, round-robin, until |
87 // you've reached the end of each of them. | 97 // you've reached the end of each of them. |
88 [testWalkingMultipleCursors, 50], | 98 [testWalkingMultipleCursors, 50], |
89 // Open an object store cursor, then continue(key) to the last value. | 99 // Open an object store cursor, then continue(key) to the last value. |
90 [testCursorSeeks, 2000, 10, 4, kDontUseIndex], | 100 [testCursorSeeksWithoutIndex, 2000, 10, 4], |
91 // Open an index key cursor, then continue(key) to the last value. | 101 // Open an index key cursor, then continue(key) to the last value. |
92 [testCursorSeeks, 2000, 10, 4, kUseIndex], | 102 [testCursorSeeksWithIndex, 2000, 10, 4], |
93 ]; | 103 ]; |
94 | 104 |
| 105 |
| 106 function testRandomReadsAndWritesWithIndex( |
| 107 numKeys, numReadsPerTransaction, numWritesPerTransaction, |
| 108 numTransactions, onTestComplete) { |
| 109 testRandomReadsAndWrites(numKeys, numReadsPerTransaction, |
| 110 numWritesPerTransaction, |
| 111 numTransactions, true, onTestComplete); |
| 112 } |
| 113 |
| 114 function testRandomReadsAndWritesWithoutIndex( |
| 115 numKeys, numReadsPerTransaction, numWritesPerTransaction, |
| 116 numTransactions, onTestComplete) { |
| 117 testRandomReadsAndWrites(numKeys, numReadsPerTransaction, |
| 118 numWritesPerTransaction, |
| 119 numTransactions, false, onTestComplete); |
| 120 } |
| 121 |
| 122 |
| 123 function testReadCacheWithIndex(numTransactions, onTestComplete) { |
| 124 testReadCache(numTransactions, true, onTestComplete); |
| 125 } |
| 126 |
| 127 function testReadCacheWithoutIndex(numTransactions, onTestComplete) { |
| 128 testReadCache(numTransactions, false, onTestComplete) |
| 129 } |
| 130 |
| 131 function testCursorSeeksWithIndex(numKeys, numSeeksPerTransaction, |
| 132 numTransactions, onTestComplete) { |
| 133 testCursorSeeks(numKeys, numSeeksPerTransaction, numTransactions, |
| 134 true, onTestComplete); |
| 135 } |
| 136 |
| 137 function testCursorSeeksWithoutIndex(numKeys, numSeeksPerTransaction, |
| 138 numTransactions, onTestComplete) { |
| 139 testCursorSeeks(numKeys, numSeeksPerTransaction, numTransactions, |
| 140 false, onTestComplete); |
| 141 } |
| 142 |
| 143 |
| 144 |
95 var currentTest = 0; | 145 var currentTest = 0; |
| 146 var testFilter; |
| 147 var done = false; |
96 | 148 |
97 function test() { | 149 function test() { |
| 150 done = false; |
98 runNextTest(); | 151 runNextTest(); |
99 } | 152 } |
100 | 153 |
| 154 |
101 function runNextTest() { | 155 function runNextTest() { |
102 var filter = window.location.hash.slice(1); | 156 var running_test, f; |
103 var test, f; | |
104 while (currentTest < tests.length) { | 157 while (currentTest < tests.length) { |
105 test = tests[currentTest]; | 158 running_test = tests[currentTest]; |
106 f = test.shift(); | 159 f = running_test.shift(); |
107 if (!filter || f.name == filter) | 160 if (!testFilter || f.name == testFilter) |
108 break; | 161 break; |
109 ++currentTest; | 162 ++currentTest; |
110 } | 163 } |
111 | 164 |
112 if (currentTest < tests.length) { | 165 if (currentTest < tests.length) { |
113 test.push(runNextTest); | 166 running_test.push(runNextTest); |
114 f.apply(null, test); | 167 f.apply(null, running_test); |
115 ++currentTest; | 168 ++currentTest; |
116 } else { | 169 } else { |
117 onAllTestsComplete(); | 170 onAllTestsComplete(); |
118 } | 171 } |
119 } | 172 } |
120 | 173 |
121 function onAllTestsComplete() { | 174 function onAllTestsComplete() { |
122 var overallDuration = window.performance.now() - overallTestStartTime; | 175 var overallDuration = window.performance.now() - overallTestStartTime; |
123 automation.addResult("OverallTestDuration", overallDuration); | 176 automation.addResult("OverallTestDuration", overallDuration); |
124 automation.setDone(); | 177 automation.setDone(); |
| 178 done = true; |
| 179 } |
| 180 |
| 181 function testCreateAndDeleteDatabases( |
| 182 numDatabases, numOpens, numKeys, numStores, |
| 183 payloadLength, onTestComplete) { |
| 184 var testName = getDisplayName(arguments); |
| 185 assert(numOpens >= 1); |
| 186 assert(numKeys >= 0); |
| 187 assert(numStores >= 1); |
| 188 var objectStoreNames = []; |
| 189 for (var i=0; i < numStores; ++i) { |
| 190 objectStoreNames.push("store " + i); |
| 191 } |
| 192 var value = stringOfLength(payloadLength); |
| 193 function getValue() { |
| 194 return value; |
| 195 } |
| 196 |
| 197 automation.setStatus("Creating databases."); |
| 198 var startTime = window.performance.now(); |
| 199 |
| 200 var numCreated = 0; |
| 201 for (var i = 0; i < numDatabases; i++) { |
| 202 createDatabase(testName + i, objectStoreNames, onCreated, onError); |
| 203 } |
| 204 |
| 205 function onCreated(db) { |
| 206 automation.setStatus("Constructing transactions."); |
| 207 var transaction = |
| 208 getTransaction(db, objectStoreNames, "readwrite", |
| 209 function() { openLoop(db, numOpens); }); |
| 210 putLinearValues(transaction, objectStoreNames, numKeys, null, getValue); |
| 211 } |
| 212 |
| 213 function openLoop(db, timesLeft) { |
| 214 db.close(); |
| 215 if (timesLeft == 0) { |
| 216 deleteDatabase(db.name, onDeleted); |
| 217 return; |
| 218 } |
| 219 createDatabase(db.name, objectStoreNames, |
| 220 function(db) { openLoop(db, timesLeft - 1); }, onError) |
| 221 } |
| 222 |
| 223 var numDeleted = 0; |
| 224 function onDeleted() { |
| 225 var duration = window.performance.now() - startTime; |
| 226 automation.addResult(testName, duration); |
| 227 automation.setStatus("Deleted database."); |
| 228 if (++numDeleted == numDatabases) { |
| 229 onTestComplete(); |
| 230 } |
| 231 } |
| 232 } |
| 233 |
| 234 function testCreateKeysInStores( |
| 235 numKeys, numStores, payloadLength, onTestComplete) { |
| 236 var testName = getDisplayName(arguments); |
| 237 assert(numKeys >= 0); |
| 238 assert(numStores >= 1); |
| 239 var objectStoreNames = []; |
| 240 for (var i=0; i < numStores; ++i) { |
| 241 objectStoreNames.push("store " + i); |
| 242 } |
| 243 var value = stringOfLength(payloadLength); |
| 244 function getValue() { |
| 245 return value; |
| 246 } |
| 247 |
| 248 automation.setStatus("Creating database."); |
| 249 createDatabase(testName, objectStoreNames, onCreated, onError); |
| 250 |
| 251 function onCreated(db) { |
| 252 automation.setStatus("Constructing transaction."); |
| 253 var completionFunc = |
| 254 getCompletionFunc(db, testName, window.performance.now(), |
| 255 onTestComplete); |
| 256 var transaction = |
| 257 getTransaction(db, objectStoreNames, "readwrite", completionFunc); |
| 258 putLinearValues(transaction, objectStoreNames, numKeys, null, getValue); |
| 259 } |
125 } | 260 } |
126 | 261 |
127 // This is the only test that includes database creation and deletion in its | 262 // This is the only test that includes database creation and deletion in its |
128 // results; the others just test specific operations. To see only the | 263 // results; the others just test specific operations. To see only the |
129 // creation/deletion without the specific operations used to build up the data | 264 // creation/deletion without the specific operations used to build up the data |
130 // in the object stores here, subtract off the results of | 265 // in the object stores here, subtract off the results of |
131 // testCreateKeysInStores. | 266 // testCreateKeysInStores. |
132 function testCreateAndDeleteDatabase( | 267 function testCreateAndDeleteDatabase( |
133 numKeys, numStores, payloadLength, onTestComplete) { | 268 numKeys, numStores, payloadLength, onTestComplete) { |
134 var testName = getDisplayName(arguments); | 269 var testName = getDisplayName(arguments); |
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
579 request.onerror = onError; | 714 request.onerror = onError; |
580 request.onsuccess = function() { | 715 request.onsuccess = function() { |
581 var cursor = request.result; | 716 var cursor = request.result; |
582 if (cursor && first) { | 717 if (cursor && first) { |
583 first = false; | 718 first = false; |
584 cursor.continue(getKey(numKeys - 1)); | 719 cursor.continue(getKey(numKeys - 1)); |
585 } | 720 } |
586 }; | 721 }; |
587 } | 722 } |
588 } | 723 } |
OLD | NEW |