| <!DOCTYPE html> |
| <html> |
| <body> |
| <script src="../../resources/runner.js"></script> |
| <script> |
| |
| const numberOfIterations = 20; |
| |
| // Delete all databases for the test ahead of time. |
| var numberDeleted = 0; |
| var databaseNamePrefix = "index-multientry-DB-"; |
| for (var i = 0; i < numberOfIterations + 1; ++i) { |
| req = indexedDB.deleteDatabase(databaseNamePrefix + i); |
| req.onsuccess = function() { |
| if (++numberDeleted == numberOfIterations) |
| startIteration(); |
| } |
| } |
| |
| var testGenerator = null; |
| var db = null; |
| var transaction = null; |
| var currentIteration = 0; |
| |
| PerfTestRunner.prepareToMeasureValuesAsync({ |
| customIterationCount: numberOfIterations, |
| unit: 'ms', |
| done: function () { |
| transaction = null; |
| db = null; |
| testGenerator = null; |
| PerfTestRunner.gc(); |
| ++currentIteration; |
| } |
| }); |
| |
| function startIteration() |
| { |
| testGenerator = runIteration(); |
| nextStep(); |
| } |
| |
| function nextStep() |
| { |
| testGenerator.next(); |
| } |
| |
| var object = { test: 'yo', indexKeys: [] }; |
| for (var i = 0; i < 5000; i++) |
| object.indexKeys.push('index_no_' + i); |
| |
| function *runIteration() |
| { |
| var startTime = PerfTestRunner.now(); |
| |
| var openRequest = indexedDB.open(databaseNamePrefix + currentIteration); |
| openRequest.onupgradeneeded = function(event) { |
| db = event.target.result; |
| db.createObjectStore('store').createIndex('index', 'indexKeys', { multiEntry: true }); |
| } |
| openRequest.onsuccess = nextStep; |
| |
| yield; |
| |
| transaction = db.transaction('store', 'readwrite'); |
| transaction.objectStore('store').put(object, 1); |
| transaction.oncomplete = nextStep; |
| |
| yield; |
| |
| var index = db.transaction('store').objectStore('store').index('index'); |
| |
| var completedGets = 0; |
| for (var i = 0; i < 1000; i++) |
| { |
| index.get('index_no_' + i).onsuccess = function (event) { |
| if (event.target.result.test != "yo") |
| alert("Expected 'yo', got '" + event.target.result.test + "'"); |
| |
| if (++completedGets == 1000) |
| nextStep(); |
| }; |
| } |
| |
| yield; |
| |
| if (!PerfTestRunner.measureValueAsync(PerfTestRunner.now() - startTime)) |
| return; |
| |
| setTimeout(startIteration, 0); |
| } |
| </script> |
| </body> |
| </html> |