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) {
this.results[name] = result;
var elt = document.getElementById('results');
var div = document.createElement('div');
div.innerText = name + ": " + result;
div.textContent = name + ": " + result;
elt.appendChild(div);
};
......@@ -29,7 +29,7 @@ automation.getResults = function() {
};
automation.setStatus = function(s) {
document.getElementById('status').innerText = s;
document.getElementById('status').textContent = s;
};
function assert(t) {
......@@ -44,6 +44,8 @@ function onError(e) {
var s = "Caught error.";
if (e.target && e.target.webkitErrorMessage)
s += "\n" + e.target.webkitErrorMessage;
else if (e.target && e.target.error)
s += "\n" + e.target.error.name;
console.log(s);
automation.setStatus(s);
e.stopPropagation();
......@@ -63,6 +65,7 @@ function createDatabase(
name, objectStoreNames, handler, errorHandler, optionSets) {
var openRequest = indexedDB.open(name, baseVersion);
openRequest.onblocked = errorHandler;
openRequest.onerror = errorHandler;
function createObjectStores(db) {
for (var store in objectStoreNames) {
var name = objectStoreNames[store];
......@@ -81,25 +84,27 @@ function createDatabase(
}
}
openRequest.onupgradeneeded = function(ev) {
// TODO(ericu): This is the spec-compliant path, which doesn't yet work in
// Chrome, and isn't yet tested, as this function won't currently be called.
// This is the spec-compliant path, which doesn't yet run in Chrome, but
// works in Firefox.
assert(openRequest == ev.target);
createObjectStores(openRequest.result);
var db = openRequest.result;
db.onerror = errorHandler;
createObjectStores(db);
// onsuccess will get called after this exits.
};
openRequest.onsuccess = function(ev) {
assert(openRequest == ev.target);
var db = openRequest.result;
curVersion = db.version;
db.onerror = function(ev) {
console.log("db error", arguments, openRequest.webkitErrorMessage);
errorHandler();
errorHandler(ev);
}
if (db.version != baseVersion) {
// This is the current Chrome path.
if (curVersion != baseVersion) {
// This is the legacy path, which runs only in Chrome.
var setVersionRequest = db.setVersion(baseVersion);
setVersionRequest.onerror = errorHandler;
setVersionRequest.onsuccess = function(e) {
curVersion = db.version;
assert(setVersionRequest == e.target);
createObjectStores(db);
var versionTransaction = setVersionRequest.result;
......@@ -118,7 +123,12 @@ function alterObjectStores(
var version = curVersion + 1;
var openRequest = indexedDB.open(name, version);
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) {
assert(openRequest == ev.target);
var db = openRequest.result;
......@@ -128,6 +138,7 @@ function alterObjectStores(
errorHandler();
}
if (db.version != version) {
// This is the legacy path, which runs only in Chrome.
var setVersionRequest = db.setVersion(version);
setVersionRequest.onerror = errorHandler;
setVersionRequest.onsuccess =
......@@ -137,12 +148,15 @@ function alterObjectStores(
var versionTransaction = setVersionRequest.result;
versionTransaction.oncomplete = function() { handler(db); };
versionTransaction.onerror = onError;
for (var store in objectStoreNames) {
func(versionTransaction.objectStore(objectStoreNames[store]));
}
doAlteration(versionTransaction);
}
} else {
errorHandler();
handler(db);
}
}
function doAlteration(target) {
for (var store in objectStoreNames) {
func(target.objectStore(objectStoreNames[store]));
}
}
}
......
<html>
<head>
<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_test.js"></script>
</head>
......
......@@ -16,33 +16,33 @@ var kPlaceholderArg = false;
var tests = [
// Create a single small item in a single object store, then delete everything.
[testCreateAndDeleteDatabase, 1, 1, 1],
// Create a single small item in a single object store, then delete everything.
[testCreateAndDeleteDatabase, 100, 1, 1],
// Create a single small item in a single object store, then delete everything.
[testCreateAndDeleteDatabase, 1, 100, 1],
// Create a single small item in a single object store, then delete everything.
[testCreateAndDeleteDatabase, 100, 1, 10000],
// Create many small items in a single object store, then delete everything.
[testCreateAndDeleteDatabase, 1000, 1, 1],
// Create a single small item in many object stores, then delete everything.
[testCreateAndDeleteDatabase, 1, 1000, 1],
// Create many large items in a single object store, then delete everything.
[testCreateAndDeleteDatabase, 1000, 1, 10000],
// Create a single small item in a single object store.
[testCreateKeysInStores, 1, 1, 1],
// 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.
[testCreateKeysInStores, 1, 100, 1],
[testCreateKeysInStores, 1, 1000, 1],
// 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.
[testRandomReadsAndWrites, 1000, 5, 0, 50, kDontUseIndex],
[testRandomReadsAndWrites, 1000, 5, 0, 100, kDontUseIndex],
// 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.
[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.
[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.
[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
// 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.
[testRandomReadsAndWrites, 1000, 5, 5, 50, kDontUseIndex],
// Read and write a few random items, reading from an index, in each of many
......@@ -70,16 +70,16 @@ var tests = [
[testSporadicWrites, 5, 0],
// Make large batches of random writes into a store, triggered by periodic
// setTimeout calls.
[testSporadicWrites, 50, 0],
[testSporadicWrites, 500, 0],
// Make batches of random writes into a store with many indices, triggered by
// periodic setTimeout calls.
[testSporadicWrites, 5, 10],
// Make large batches of random writes into a store with many indices, triggered
// by periodic setTimeout calls.
[testSporadicWrites, 50, 10],
[testSporadicWrites, 500, 10],
// Create and delete an index on a store that already contains data [produces
// a timing result for each of creation and deletion].
[testCreateAndDeleteIndex, 1000]
[testCreateAndDeleteIndex, 5000]
];
var currentTest = 0;
......@@ -272,19 +272,31 @@ function testCreateAndDeleteIndex(numKeys, onTestComplete) {
alterObjectStores(testName, objectStoreNames, f, onIndexCreated, onError);
}
var completionFunc;
var indexCreationCompleteTime;
function onIndexCreated(db) {
db.close();
var indexCreationCompleteTime = Date.now();
indexCreationCompleteTime = Date.now();
automation.addResult("testCreateIndex",
indexCreationCompleteTime - startTime);
completionFunc = getCompletionFunc(db, "testDeleteIndex",
indexCreationCompleteTime, onTestComplete);
var f = function(objectStore) {
objectStore.deleteIndex("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(
// writes, as we create both object stores with the same configurations.
// We could do that if needed, but it's simpler not to.
assert(!useIndexForReads || !writeAlso);
var numKeys = 1000;
var numReadsPerTransaction = 100;
var numKeys = 10000;
var numReadsPerTransaction = 1000;
var testName = getDisplayName(arguments);
var objectStoreNames = ["input store"];
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