Commit 609cea6a authored by ericu@google.com's avatar ericu@google.com

Make tests work in Firefox.

Fix some comments.
Make the tests a bit harder.
Fix db deletion in testCreateAndDeleteIndex.

BUG=137764

Review URL: https://chromiumcodereview.appspot.com/10856002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@150368 0039d316-1c4b-4281-b951-d872f2087c98
parent 6ce760be
...@@ -20,7 +20,7 @@ automation.addResult = function(name, result) { ...@@ -20,7 +20,7 @@ automation.addResult = function(name, result) {
this.results[name] = result; this.results[name] = result;
var elt = document.getElementById('results'); var elt = document.getElementById('results');
var div = document.createElement('div'); var div = document.createElement('div');
div.innerText = name + ": " + result; div.textContent = name + ": " + result;
elt.appendChild(div); elt.appendChild(div);
}; };
...@@ -29,7 +29,7 @@ automation.getResults = function() { ...@@ -29,7 +29,7 @@ automation.getResults = function() {
}; };
automation.setStatus = function(s) { automation.setStatus = function(s) {
document.getElementById('status').innerText = s; document.getElementById('status').textContent = s;
}; };
function assert(t) { function assert(t) {
...@@ -44,6 +44,8 @@ function onError(e) { ...@@ -44,6 +44,8 @@ function onError(e) {
var s = "Caught error."; var s = "Caught error.";
if (e.target && e.target.webkitErrorMessage) if (e.target && e.target.webkitErrorMessage)
s += "\n" + e.target.webkitErrorMessage; s += "\n" + e.target.webkitErrorMessage;
else if (e.target && e.target.error)
s += "\n" + e.target.error.name;
console.log(s); console.log(s);
automation.setStatus(s); automation.setStatus(s);
e.stopPropagation(); e.stopPropagation();
...@@ -63,6 +65,7 @@ function createDatabase( ...@@ -63,6 +65,7 @@ function createDatabase(
name, objectStoreNames, handler, errorHandler, optionSets) { name, objectStoreNames, handler, errorHandler, optionSets) {
var openRequest = indexedDB.open(name, baseVersion); var openRequest = indexedDB.open(name, baseVersion);
openRequest.onblocked = errorHandler; openRequest.onblocked = errorHandler;
openRequest.onerror = errorHandler;
function createObjectStores(db) { function createObjectStores(db) {
for (var store in objectStoreNames) { for (var store in objectStoreNames) {
var name = objectStoreNames[store]; var name = objectStoreNames[store];
...@@ -81,25 +84,27 @@ function createDatabase( ...@@ -81,25 +84,27 @@ function createDatabase(
} }
} }
openRequest.onupgradeneeded = function(ev) { openRequest.onupgradeneeded = function(ev) {
// TODO(ericu): This is the spec-compliant path, which doesn't yet work in // This is the spec-compliant path, which doesn't yet run in Chrome, but
// Chrome, and isn't yet tested, as this function won't currently be called. // works in Firefox.
assert(openRequest == ev.target); assert(openRequest == ev.target);
createObjectStores(openRequest.result); var db = openRequest.result;
db.onerror = errorHandler;
createObjectStores(db);
// onsuccess will get called after this exits. // onsuccess will get called after this exits.
}; };
openRequest.onsuccess = function(ev) { openRequest.onsuccess = function(ev) {
assert(openRequest == ev.target); assert(openRequest == ev.target);
var db = openRequest.result; var db = openRequest.result;
curVersion = db.version;
db.onerror = function(ev) { db.onerror = function(ev) {
console.log("db error", arguments, openRequest.webkitErrorMessage); console.log("db error", arguments, openRequest.webkitErrorMessage);
errorHandler(); errorHandler(ev);
} }
if (db.version != baseVersion) { if (curVersion != baseVersion) {
// This is the current Chrome path. // This is the legacy path, which runs only in Chrome.
var setVersionRequest = db.setVersion(baseVersion); var setVersionRequest = db.setVersion(baseVersion);
setVersionRequest.onerror = errorHandler; setVersionRequest.onerror = errorHandler;
setVersionRequest.onsuccess = function(e) { setVersionRequest.onsuccess = function(e) {
curVersion = db.version;
assert(setVersionRequest == e.target); assert(setVersionRequest == e.target);
createObjectStores(db); createObjectStores(db);
var versionTransaction = setVersionRequest.result; var versionTransaction = setVersionRequest.result;
...@@ -118,7 +123,12 @@ function alterObjectStores( ...@@ -118,7 +123,12 @@ function alterObjectStores(
var version = curVersion + 1; var version = curVersion + 1;
var openRequest = indexedDB.open(name, version); var openRequest = indexedDB.open(name, version);
openRequest.onblocked = errorHandler; openRequest.onblocked = errorHandler;
// TODO(ericu): This won't work in Firefox yet; see above in createDatabase. openRequest.onupgradeneeded = function(ev) {
// This is the spec-compliant path, which doesn't yet run in Chrome, but
// works in Firefox.
doAlteration(ev.target.transaction);
// onsuccess will get called after this exits.
};
openRequest.onsuccess = function(ev) { openRequest.onsuccess = function(ev) {
assert(openRequest == ev.target); assert(openRequest == ev.target);
var db = openRequest.result; var db = openRequest.result;
...@@ -128,6 +138,7 @@ function alterObjectStores( ...@@ -128,6 +138,7 @@ function alterObjectStores(
errorHandler(); errorHandler();
} }
if (db.version != version) { if (db.version != version) {
// This is the legacy path, which runs only in Chrome.
var setVersionRequest = db.setVersion(version); var setVersionRequest = db.setVersion(version);
setVersionRequest.onerror = errorHandler; setVersionRequest.onerror = errorHandler;
setVersionRequest.onsuccess = setVersionRequest.onsuccess =
...@@ -137,12 +148,15 @@ function alterObjectStores( ...@@ -137,12 +148,15 @@ function alterObjectStores(
var versionTransaction = setVersionRequest.result; var versionTransaction = setVersionRequest.result;
versionTransaction.oncomplete = function() { handler(db); }; versionTransaction.oncomplete = function() { handler(db); };
versionTransaction.onerror = onError; versionTransaction.onerror = onError;
for (var store in objectStoreNames) { doAlteration(versionTransaction);
func(versionTransaction.objectStore(objectStoreNames[store]));
}
} }
} else { } else {
errorHandler(); handler(db);
}
}
function doAlteration(target) {
for (var store in objectStoreNames) {
func(target.objectStore(objectStoreNames[store]));
} }
} }
} }
......
<html> <html>
<head> <head>
<title>IndexedDB perf test first try</title> <title>IndexedDB perf test first try</title>
<meta charset="UTF-8">
<script type="text/javascript" src="perf_shared.js"></script> <script type="text/javascript" src="perf_shared.js"></script>
<script type="text/javascript" src="perf_test.js"></script> <script type="text/javascript" src="perf_test.js"></script>
</head> </head>
......
...@@ -16,33 +16,33 @@ var kPlaceholderArg = false; ...@@ -16,33 +16,33 @@ var kPlaceholderArg = false;
var tests = [ var tests = [
// Create a single small item in a single object store, then delete everything. // Create a single small item in a single object store, then delete everything.
[testCreateAndDeleteDatabase, 1, 1, 1], [testCreateAndDeleteDatabase, 1, 1, 1],
// Create a single small item in a single object store, then delete everything. // Create many small items in a single object store, then delete everything.
[testCreateAndDeleteDatabase, 100, 1, 1], [testCreateAndDeleteDatabase, 1000, 1, 1],
// Create a single small item in a single object store, then delete everything. // Create a single small item in many object stores, then delete everything.
[testCreateAndDeleteDatabase, 1, 100, 1], [testCreateAndDeleteDatabase, 1, 1000, 1],
// Create a single small item in a single object store, then delete everything. // Create many large items in a single object store, then delete everything.
[testCreateAndDeleteDatabase, 100, 1, 10000], [testCreateAndDeleteDatabase, 1000, 1, 10000],
// Create a single small item in a single object store. // Create a single small item in a single object store.
[testCreateKeysInStores, 1, 1, 1], [testCreateKeysInStores, 1, 1, 1],
// Create many small items in a single object store. // Create many small items in a single object store.
[testCreateKeysInStores, 100, 1, 1], [testCreateKeysInStores, 1000, 1, 1],
// Create a single small item in many object stores. // Create a single small item in many object stores.
[testCreateKeysInStores, 1, 100, 1], [testCreateKeysInStores, 1, 1000, 1],
// Create many large items in a single object store. // Create many large items in a single object store.
[testCreateKeysInStores, 100, 1, 10000], [testCreateKeysInStores, 1000, 1, 10000],
// Read a few random items in each of many transactions. // Read a few random items in each of many transactions.
[testRandomReadsAndWrites, 1000, 5, 0, 50, kDontUseIndex], [testRandomReadsAndWrites, 1000, 5, 0, 100, kDontUseIndex],
// Read many random items in each of a few transactions. // Read many random items in each of a few transactions.
[testRandomReadsAndWrites, 1000, 50, 0, 5, kDontUseIndex], [testRandomReadsAndWrites, 1000, 500, 0, 5, kDontUseIndex],
// Read many random items in each of a few transactions, in a large store. // Read many random items in each of a few transactions, in a large store.
[testRandomReadsAndWrites, 5000, 50, 0, 5, kDontUseIndex], [testRandomReadsAndWrites, 10000, 500, 0, 5, kDontUseIndex],
// Read a few random items from an index, in each of many transactions. // Read a few random items from an index, in each of many transactions.
[testRandomReadsAndWrites, 1000, 5, 0, 50, kUseIndex], [testRandomReadsAndWrites, 1000, 5, 0, 100, kUseIndex],
// Read many random items from an index, in each of a few transactions. // Read many random items from an index, in each of a few transactions.
[testRandomReadsAndWrites, 1000, 50, 0, 5, kUseIndex], [testRandomReadsAndWrites, 1000, 500, 0, 5, kUseIndex],
// Read many random items from an index, in each of a few transactions, in a // Read many random items from an index, in each of a few transactions, in a
// large store. // large store.
[testRandomReadsAndWrites, 5000, 50, 0, 5, kUseIndex], [testRandomReadsAndWrites, 10000, 500, 0, 5, kUseIndex],
// Read and write a few random items in each of many transactions. // Read and write a few random items in each of many transactions.
[testRandomReadsAndWrites, 1000, 5, 5, 50, kDontUseIndex], [testRandomReadsAndWrites, 1000, 5, 5, 50, kDontUseIndex],
// Read and write a few random items, reading from an index, in each of many // Read and write a few random items, reading from an index, in each of many
...@@ -70,16 +70,16 @@ var tests = [ ...@@ -70,16 +70,16 @@ var tests = [
[testSporadicWrites, 5, 0], [testSporadicWrites, 5, 0],
// Make large batches of random writes into a store, triggered by periodic // Make large batches of random writes into a store, triggered by periodic
// setTimeout calls. // setTimeout calls.
[testSporadicWrites, 50, 0], [testSporadicWrites, 500, 0],
// Make batches of random writes into a store with many indices, triggered by // Make batches of random writes into a store with many indices, triggered by
// periodic setTimeout calls. // periodic setTimeout calls.
[testSporadicWrites, 5, 10], [testSporadicWrites, 5, 10],
// Make large batches of random writes into a store with many indices, triggered // Make large batches of random writes into a store with many indices, triggered
// by periodic setTimeout calls. // by periodic setTimeout calls.
[testSporadicWrites, 50, 10], [testSporadicWrites, 500, 10],
// Create and delete an index on a store that already contains data [produces // Create and delete an index on a store that already contains data [produces
// a timing result for each of creation and deletion]. // a timing result for each of creation and deletion].
[testCreateAndDeleteIndex, 1000] [testCreateAndDeleteIndex, 5000]
]; ];
var currentTest = 0; var currentTest = 0;
...@@ -272,19 +272,31 @@ function testCreateAndDeleteIndex(numKeys, onTestComplete) { ...@@ -272,19 +272,31 @@ function testCreateAndDeleteIndex(numKeys, onTestComplete) {
alterObjectStores(testName, objectStoreNames, f, onIndexCreated, onError); alterObjectStores(testName, objectStoreNames, f, onIndexCreated, onError);
} }
var completionFunc; var indexCreationCompleteTime;
function onIndexCreated(db) { function onIndexCreated(db) {
db.close(); db.close();
var indexCreationCompleteTime = Date.now(); indexCreationCompleteTime = Date.now();
automation.addResult("testCreateIndex", automation.addResult("testCreateIndex",
indexCreationCompleteTime - startTime); indexCreationCompleteTime - startTime);
completionFunc = getCompletionFunc(db, "testDeleteIndex",
indexCreationCompleteTime, onTestComplete);
var f = function(objectStore) { var f = function(objectStore) {
objectStore.deleteIndex("index"); objectStore.deleteIndex("index");
}; };
automation.setStatus("Deleting index."); automation.setStatus("Deleting index.");
alterObjectStores(testName, objectStoreNames, f, completionFunc, onError); alterObjectStores(testName, objectStoreNames, f, onIndexDeleted, onError);
}
function onIndexDeleted(db) {
var duration = Date.now() - indexCreationCompleteTime;
// Ignore the cleanup time for this test.
automation.addResult("testDeleteIndex", duration);
automation.setStatus("Deleting database.");
db.close();
deleteDatabase(testName, onDeleted);
}
function onDeleted() {
automation.setStatus("Deleted database.");
onTestComplete();
} }
} }
...@@ -297,8 +309,8 @@ function testCursorReadsAndRandomWrites( ...@@ -297,8 +309,8 @@ function testCursorReadsAndRandomWrites(
// writes, as we create both object stores with the same configurations. // writes, as we create both object stores with the same configurations.
// We could do that if needed, but it's simpler not to. // We could do that if needed, but it's simpler not to.
assert(!useIndexForReads || !writeAlso); assert(!useIndexForReads || !writeAlso);
var numKeys = 1000; var numKeys = 10000;
var numReadsPerTransaction = 100; var numReadsPerTransaction = 1000;
var testName = getDisplayName(arguments); var testName = getDisplayName(arguments);
var objectStoreNames = ["input store"]; var objectStoreNames = ["input store"];
var outputStoreName; var outputStoreName;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment