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 69f74b1e5256b668bb3322855bfd2c08ec9961d9..c2ee3ae742a1788a9d99392805bc85f6d41e7a13 100644 |
--- a/chrome/test/data/indexeddb/perf_shared.js |
+++ b/chrome/test/data/indexeddb/perf_shared.js |
@@ -49,17 +49,17 @@ function onError(e) { |
throw new Error(e); |
} |
-var version = 2; // The version with our object stores. |
-var db; |
+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, objectStores, 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 objectStores) { |
@@ -78,27 +78,28 @@ function createDatabase(name, objectStores, handler, errorHandler, options) { |
// TODO: 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. |
assert(openRequest == ev.target); |
- db = openRequest.result; |
+ var db = openRequest.result; |
jsbell
2012/07/26 18:52:41
Ignore my comment in the previous review.
|
createObjectStores(db); |
// onsuccess will get called after this exits. |
}; |
openRequest.onsuccess = function(ev) { |
assert(openRequest == ev.target); |
- db = openRequest.result; |
+ var db = openRequest.result; |
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 { |
@@ -107,6 +108,41 @@ function createDatabase(name, objectStores, handler, errorHandler, options) { |
} |
} |
+// 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. |
jsbell
2012/07/26 18:52:41
I wrote an upgradeneeded shim for the current vers
ericu
2012/07/26 21:03:12
I'll consider adding that in a later CL, especiall
|
+ 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; |
@@ -141,6 +177,70 @@ function getCleanUpFunc(testName, startTime, onTestComplete) { |
} |
} |
+function getDisplayName(args) { |
+ return getDisplayName.caller.name + "_" + |
+ Array.prototype.slice.call(args, 0, args.length - 1).join("_"); |
jsbell
2012/07/26 18:52:41
Cute. :) Maybe a comment that last argument is ass
ericu
2012/07/26 21:03:12
Done.
|
+} |
+ |
+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]); |
jsbell
2012/07/26 18:52:41
This will throw if not found, never return null. S
ericu
2012/07/26 21:03:13
Removed. It'll fail quickly enough anyway.
|
+ assert(os); |
+ 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]); |
+ assert(os); |
+ var queryObject = os; |
jsbell
2012/07/26 18:52:41
FYI, in the IDB spec itself this (a store or index
ericu
2012/07/26 21:03:13
Sounds good; changed to "source".
|
+ if (indexName) |
+ queryObject = queryObject.index(indexName); |
+ for (var j = 0; j < numReads; ++j) { |
+ var rand = Math.floor(Math.random() * numKeys); |
+ var request = queryObject.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]); |
+ assert(os); |
+ 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)); |