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

Unified Diff: third_party/WebKit/LayoutTests/storage/indexeddb/resources/generic-idb-operations.js

Issue 2163213006: [IndexedDB] Add Observer Tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@changes_renderer
Patch Set: Post cmumford review Created 4 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
Index: third_party/WebKit/LayoutTests/storage/indexeddb/resources/generic-idb-operations.js
diff --git a/third_party/WebKit/LayoutTests/storage/indexeddb/resources/generic-idb-operations.js b/third_party/WebKit/LayoutTests/storage/indexeddb/resources/generic-idb-operations.js
index add1dff579016336b020143ed7401d5aff376c6e..42d083434241cca0bc7b2a0450c4e5932e9be9ee 100644
--- a/third_party/WebKit/LayoutTests/storage/indexeddb/resources/generic-idb-operations.js
+++ b/third_party/WebKit/LayoutTests/storage/indexeddb/resources/generic-idb-operations.js
@@ -4,14 +4,17 @@ if (this.importScripts) {
function compareChanges(actual, expected) {
assert_equals(actual.database.name, expected.dbName, 'The change record database should be the same as the database being acted on');
- assert_equals(actual.records.size, expected.records.size, 'Incorrect number of objectStores recorded by observer');
- for (var key in expected.records) {
+ var stores = Object.keys(expected.records);
+ assert_equals(actual.records.size, stores.length, 'Incorrect number of objectStores recorded by observer');
+
+ for (var i in stores) {
+ var key = stores[i];
assert_true(actual.records.has(key));
- var actual_observation = actual.records.get(key);
- var expected_observation = expected.records[key];
- assert_equals(actual_observation.length, expected_observation.length, 'Number of observations recorded for objectStore '+key+ ' should match observed operations');
- for (var i in expected_observation)
- compareObservations(actual_observation[i], expected_observation[i]);
+ var actual_obsv = actual.records.get(key);
+ var expected_obsv = expected.records[key];
+ assert_equals(actual_obsv.length, expected_obsv.length, 'Number of observations recorded for objectStore '+ key + ' should match observed operations');
+ for (var j in expected_obsv)
+ compareObservations(actual_obsv[j], expected_obsv[j]);
}
}
@@ -22,44 +25,63 @@ function compareObservations(actual, expected) {
assert_equals(actual.value, null, 'clear operation has no value');
return;
}
- // TODO(palakj): Type should return 'delete' instead of 'kDelete', once fixed. Issue crbug.com/609934.
+ // TODO(dmurph): Type should return 'delete' instead of 'kDelete', once fixed. Issue crbug.com/609934.
if (actual.type == 'kDelete') {
assert_equals(actual.key.lower, expected.key.lower, 'Observed operation key lower bound should match operation performed');
assert_equals(actual.key.upper, expected.key.upper, 'Observed operation key upper bound should match operation performed');
assert_equals(actual.key.lower_open, expected.key.lower_open, 'Observed operation key lower open should match operation performed');
assert_equals(actual.key.upper_open, expected.key.upper_open, 'Observed operation key upper open should match operation performed');
- // TODO(palakj): Value needs to be updated, once returned correctly. Issue crbug.com/609934.
+ // TODO(dmurph): Value needs to be updated, once returned correctly. Issue crbug.com/609934.
assert_equals(actual.value, null, 'Delete operation has no value');
return;
}
assert_equals(actual.key.lower, expected.key, 'Observed operation key lower bound should match operation performed');
assert_equals(actual.key.upper, expected.key, 'Observed operation key upper bound should match operation performed');
- // TODO(palakj): Value needs to be updated, once returned correctly. Issue crbug.com/609934.
- assert_equals(actual.value, null, 'Put/Add operation value should be nil');
+ // TODO(dmurph): Value needs to be updated, once returned correctly. Issue crbug.com/609934.
+ assert_equals(actual.value, null, 'Put/Add operation value does not match');
}
function countCallbacks(actual, expected) {
assert_equals(actual, expected, 'Number of callbacks fired for observer should match number of transactions it observed')
}
-function createDatabase(db, stores) {
+function createObjectStores(db, stores) {
for (var i in stores)
db.createObjectStore(stores[i]);
}
+function operateOnDb(db, records) {
+ var tx = db.transaction(Object.keys(records), 'readwrite');
+ operateOnTx(tx, records);
+ tx.onerror = function() {
+ console.log('transaction should not fail')
+ }
+}
+
+function operateOnTx(tx, records) {
+ for (var storeName in records) {
+ var store = tx.objectStore(storeName);
+ operateOnStore(store, records[storeName]);
+ }
+}
+
function operateOnStore(store, operations) {
for (var i in operations ) {
var op = operations[i];
- assert_in_array(op.type, ['put', 'add', 'delete', 'clear', 'get'], 'Operation type not defined');
+ var request;
+ assert_in_array(op.type, ['put', 'add', 'kDelete', 'clear', 'get'], 'Operation type not defined');
if (op.type == 'put')
- store.put(op.value, op.key);
+ request = store.put(op.value, op.key);
else if (op.type == 'add')
- store.add(op.value, op.key);
- else if (op.type == 'delete')
- store.delete(IDBKeyRange.bound(op.key.lower, op.key.upper));
+ request = store.add(op.value, op.key);
+ else if (op.type == 'kDelete')
+ request = store.delete(IDBKeyRange.bound(op.key.lower, op.key.upper));
else if (op.type == 'clear')
- store.clear();
+ request = store.clear();
else
- store.get(op.key)
+ request = store.get(op.key)
+ request.onerror = function() {
+ console.log(op.type + ' operation should not fail')
+ }
}
}

Powered by Google App Engine
This is Rietveld 408576698