Chromium Code Reviews| 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 |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..72ee39ae9369e19af472a32e85510520cae4d086 |
| --- /dev/null |
| +++ b/third_party/WebKit/LayoutTests/storage/indexeddb/resources/generic-idb-operations.js |
| @@ -0,0 +1,65 @@ |
| +if (this.importScripts) { |
| + importScripts('../../../resources/testharness.js'); |
| +} |
| + |
| +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){ |
| + assert_true(actual.records.has(key)); |
| + var actual_obsv = actual.records.get(key); |
|
cmumford
2016/07/20 00:25:12
Nit: "obsv" is a nonstandard abbreviation and does
palakj1
2016/07/20 01:33:35
Changed to observation
|
| + 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 (i in expected_obsv) |
|
cmumford
2016/07/20 00:25:12
Put "var" before "i" to avoid putting in window sc
palakj1
2016/07/20 01:33:35
done
|
| + compareObservations(actual_obsv[i], expected_obsv[i]); |
| + } |
| +} |
| + |
| +function compareObservations(actual, expected) { |
| + assert_equals(actual.type, expected.type); |
| + if (actual.type == 'clear') { |
| + assert_equals(actual.key, undefined, 'clear operation has no key'); |
| + 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. |
| + 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. |
| + 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 does not match'); |
|
cmumford
2016/07/20 00:25:12
Nit: Message is _slightly_ confusing. Maybe someth
palakj1
2016/07/20 01:33:35
done
|
| +} |
| + |
| +function countCallbacks(actual, expected){ |
|
cmumford
2016/07/20 00:25:12
Nit: space before brace.
palakj1
2016/07/20 01:33:35
done
|
| + assert_equals(actual, expected, 'Number of callbacks fired for observer should match number of transactions it observed') |
| +} |
| + |
| +function createDatabase(db, stores) { |
| + for (i in stores) |
| + db.createObjectStore(stores[i]); |
| +} |
| + |
| +function operateOnStore(store, operations) { |
| + for (i in operations ) { |
| + var op = operations[i]; |
| + assert_in_array(op.type, ['put', 'add', 'delete', 'clear', 'get'], 'Operation type not defined'); |
| + if (op.type == 'put') |
| + 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)); |
| + else if (op.type == 'clear') |
| + store.clear(); |
| + else |
| + store.get(op.key) |
| + } |
| +} |