Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(46)

Unified Diff: chrome/test/data/indexeddb/perf_shared.js

Issue 10803029: Add read/write tests, index creation/deletion test. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rolled in code review feedback. Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/test/data/indexeddb/perf_test.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/data/indexeddb/perf_shared.js
diff --git a/chrome/test/data/indexeddb/perf_shared.js b/chrome/test/data/indexeddb/perf_shared.js
index 0d42f9287859f785f5514cbea8dfd51da96f6986..e761813e22f401ceda3d01c4319cd2cd8a252617 100644
--- a/chrome/test/data/indexeddb/perf_shared.js
+++ b/chrome/test/data/indexeddb/perf_shared.js
@@ -49,17 +49,18 @@ function onError(e) {
throw new Error(e);
}
-var version = 2; // The version with our object stores.
+var baseVersion = 2; // The version with our object stores.
+var curVersion;
// Valid options fields:
// indexName: the name of an index to create on each object store
-// indexKeyPath: likewise
+// indexKeyPath: the key path for that index
// indexIsUnique: the "unique" option for IDBIndexParameters
// indexIsMultiEntry: the "multiEntry" option for IDBIndexParameters
//
function createDatabase(
name, objectStoreNames, handler, errorHandler, options) {
- var openRequest = indexedDB.open(name, version);
+ var openRequest = indexedDB.open(name, baseVersion);
openRequest.onblocked = errorHandler;
function createObjectStores(db) {
for (var store in objectStoreNames) {
@@ -87,24 +88,60 @@ function createDatabase(
db.onerror = function(ev) {
console.log("db error", arguments, openRequest.webkitErrorMessage);
errorHandler();
- };
- if (db.version != version) {
+ }
+ if (db.version != baseVersion) {
// This is the current Chrome path.
- var setVersionRequest = db.setVersion(version);
- setVersionRequest.onfailure = errorHandler;
+ 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;
- versionTransaction.oncomplete = function() {handler(db); };
+ versionTransaction.oncomplete = function() { handler(db); };
versionTransaction.onerror = onError;
- };
+ }
} else {
handler(db);
}
}
}
+// You must close all database connections before calling this.
+function alterObjectStores(
+ name, objectStoreNames, func, handler, errorHandler) {
+ var version = curVersion + 1;
+ var openRequest = indexedDB.open(name, version);
+ openRequest.onblocked = errorHandler;
+ // TODO: This won't work in Firefox yet; see above in createDatabase.
+ openRequest.onsuccess = function(ev) {
+ assert(openRequest == ev.target);
+ var db = openRequest.result;
+ db.onerror = function(ev) {
+ console.log("error altering db", arguments,
+ openRequest.webkitErrorMessage);
+ errorHandler();
+ }
+ if (db.version != version) {
+ var setVersionRequest = db.setVersion(version);
+ setVersionRequest.onerror = errorHandler;
+ setVersionRequest.onsuccess =
+ function(e) {
+ curVersion = db.version;
+ assert(setVersionRequest == e.target);
+ var versionTransaction = setVersionRequest.result;
+ versionTransaction.oncomplete = function() { handler(db); };
+ versionTransaction.onerror = onError;
+ for (var store in objectStoreNames) {
+ func(versionTransaction.objectStore(objectStoreNames[store]));
+ }
+ }
+ } else {
+ errorHandler();
+ }
+ }
+}
+
function getTransaction(db, objectStoreNames, mode, opt_handler) {
var transaction = db.transaction(objectStoreNames, mode);
transaction.onerror = onError;
@@ -139,6 +176,68 @@ function getCompletionFunc(testName, startTime, onTestComplete) {
}
}
+function getDisplayName(args) {
+ // The last arg is the completion callback the test runner tacks on.
+ return getDisplayName.caller.name + "_" +
+ Array.prototype.slice.call(args, 0, args.length - 1).join("_");
+}
+
+function getSimpleKey(i) {
+ return "key " + i;
+}
+
+function getSimpleValue(i) {
+ return "value " + i;
+}
+
+function putLinearValues(
+ transaction, objectStoreNames, numKeys, getKey, getValue) {
+ if (!getKey)
+ getKey = getSimpleKey;
+ if (!getValue)
+ getValue = getSimpleValue;
+ for (var i in objectStoreNames) {
+ var os = transaction.objectStore(objectStoreNames[i]);
+ for (var j = 0; j < numKeys; ++j) {
+ var request = os.put(getValue(j), getKey(j));
+ request.onerror = onError;
+ }
+ }
+}
+
+function getRandomValues(
+ transaction, objectStoreNames, numReads, numKeys, indexName, getKey) {
+ if (!getKey)
+ getKey = getSimpleKey;
+ for (var i in objectStoreNames) {
+ var os = transaction.objectStore(objectStoreNames[i]);
+ var source = os;
+ if (indexName)
+ source = source.index(indexName);
+ for (var j = 0; j < numReads; ++j) {
+ var rand = Math.floor(Math.random() * numKeys);
+ var request = source.get(getKey(rand));
+ request.onerror = onError;
+ }
+ }
+}
+
+function putRandomValues(
+ transaction, objectStoreNames, numPuts, numKeys, getKey, getValue) {
+ if (!getKey)
+ getKey = getSimpleKey;
+ if (!getValue)
+ getValue = getSimpleValue;
+ for (var i in objectStoreNames) {
+ var os = transaction.objectStore(objectStoreNames[i]);
+ for (var j = 0; j < numPuts; ++j) {
+ var rand = Math.floor(Math.random() * numKeys);
+ var request = os.put(getValue(rand), getKey(rand));
+ request.onerror = onError;
+ }
+ }
+}
+
function stringOfLength(n) {
assert(n > 0);
assert(n == Math.floor(n));
« no previous file with comments | « no previous file | chrome/test/data/indexeddb/perf_test.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698