Chromium Code Reviews| 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_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
| |
| 11 var expected_obsv = expected.records[key]; | |
| 12 assert_equals(actual_obsv.length, expected_obsv.length, 'Number of observati ons recorded for objectStore '+key+ ' should match observed operations'); | |
| 13 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
| |
| 14 compareObservations(actual_obsv[i], expected_obsv[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 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
| |
| 39 } | |
| 40 | |
| 41 function countCallbacks(actual, expected){ | |
|
cmumford
2016/07/20 00:25:12
Nit: space before brace.
palakj1
2016/07/20 01:33:35
done
| |
| 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 (i in stores) | |
| 47 db.createObjectStore(stores[i]); | |
| 48 } | |
| 49 | |
| 50 function operateOnStore(store, operations) { | |
| 51 for (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 |