OLD | NEW |
(Empty) | |
| 1 if (this.importScripts) { |
| 2 importScripts('../../../resources/testharness.js'); |
| 3 } |
| 4 |
| 5 function compareChanges(actual, expected) { |
| 6 assert_equals(actual.database.name, expected.dbName, 'The change record databa
se should be the same as the database being acted on'); |
| 7 assert_equals(actual.records.size, expected.records.size, 'Incorrect number of
objectStores recorded by observer'); |
| 8 for (var key in expected.records) { |
| 9 assert_true(actual.records.has(key)); |
| 10 var actual_observation = actual.records.get(key); |
| 11 var expected_observation = expected.records[key]; |
| 12 assert_equals(actual_observation.length, expected_observation.length, 'Numbe
r of observations recorded for objectStore '+key+ ' should match observed operat
ions'); |
| 13 for (var i in expected_observation) |
| 14 compareObservations(actual_observation[i], expected_observation[i]); |
| 15 } |
| 16 } |
| 17 |
| 18 function compareObservations(actual, expected) { |
| 19 assert_equals(actual.type, expected.type); |
| 20 if (actual.type == 'clear') { |
| 21 assert_equals(actual.key, undefined, 'clear operation has no key'); |
| 22 assert_equals(actual.value, null, 'clear operation has no value'); |
| 23 return; |
| 24 } |
| 25 // TODO(palakj): Type should return 'delete' instead of 'kDelete', once fixed.
Issue crbug.com/609934. |
| 26 if (actual.type == 'kDelete') { |
| 27 assert_equals(actual.key.lower, expected.key.lower, 'Observed operation key
lower bound should match operation performed'); |
| 28 assert_equals(actual.key.upper, expected.key.upper, 'Observed operation key
upper bound should match operation performed'); |
| 29 assert_equals(actual.key.lower_open, expected.key.lower_open, 'Observed oper
ation key lower open should match operation performed'); |
| 30 assert_equals(actual.key.upper_open, expected.key.upper_open, 'Observed oper
ation key upper open should match operation performed'); |
| 31 // TODO(palakj): Value needs to be updated, once returned correctly. Issue c
rbug.com/609934. |
| 32 assert_equals(actual.value, null, 'Delete operation has no value'); |
| 33 return; |
| 34 } |
| 35 assert_equals(actual.key.lower, expected.key, 'Observed operation key lower bo
und should match operation performed'); |
| 36 assert_equals(actual.key.upper, expected.key, 'Observed operation key upper bo
und should match operation performed'); |
| 37 // TODO(palakj): Value needs to be updated, once returned correctly. Issue crb
ug.com/609934. |
| 38 assert_equals(actual.value, null, 'Put/Add operation value should be nil'); |
| 39 } |
| 40 |
| 41 function countCallbacks(actual, expected) { |
| 42 assert_equals(actual, expected, 'Number of callbacks fired for observer should
match number of transactions it observed') |
| 43 } |
| 44 |
| 45 function createDatabase(db, stores) { |
| 46 for (var i in stores) |
| 47 db.createObjectStore(stores[i]); |
| 48 } |
| 49 |
| 50 function operateOnStore(store, operations) { |
| 51 for (var i in operations ) { |
| 52 var op = operations[i]; |
| 53 assert_in_array(op.type, ['put', 'add', 'delete', 'clear', 'get'], 'Operatio
n type not defined'); |
| 54 if (op.type == 'put') |
| 55 store.put(op.value, op.key); |
| 56 else if (op.type == 'add') |
| 57 store.add(op.value, op.key); |
| 58 else if (op.type == 'delete') |
| 59 store.delete(IDBKeyRange.bound(op.key.lower, op.key.upper)); |
| 60 else if (op.type == 'clear') |
| 61 store.clear(); |
| 62 else |
| 63 store.get(op.key) |
| 64 } |
| 65 } |
OLD | NEW |