OLD | NEW |
1 if (this.importScripts) { | 1 if (this.importScripts) { |
2 importScripts('../../../resources/testharness.js'); | 2 importScripts('../../../resources/testharness.js'); |
3 } | 3 } |
4 | 4 |
5 function compareChanges(actual, expected) { | 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'); | 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'); | 7 var stores = Object.keys(expected.records); |
8 for (var key in expected.records) { | 8 assert_equals(actual.records.size, stores.length, 'Incorrect number of objectS
tores recorded by observer'); |
| 9 |
| 10 for (var i in stores) { |
| 11 var key = stores[i]; |
9 assert_true(actual.records.has(key)); | 12 assert_true(actual.records.has(key)); |
10 var actual_observation = actual.records.get(key); | 13 var actual_obsv = actual.records.get(key); |
11 var expected_observation = expected.records[key]; | 14 var expected_obsv = 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'); | 15 assert_equals(actual_obsv.length, expected_obsv.length, 'Number of observati
ons recorded for objectStore '+ key + ' should match observed operations'); |
13 for (var i in expected_observation) | 16 for (var j in expected_obsv) |
14 compareObservations(actual_observation[i], expected_observation[i]); | 17 compareObservations(actual_obsv[j], expected_obsv[j]); |
15 } | 18 } |
16 } | 19 } |
17 | 20 |
18 function compareObservations(actual, expected) { | 21 function compareObservations(actual, expected) { |
19 assert_equals(actual.type, expected.type); | 22 assert_equals(actual.type, expected.type); |
20 if (actual.type == 'clear') { | 23 if (actual.type == 'clear') { |
21 assert_equals(actual.key, undefined, 'clear operation has no key'); | 24 assert_equals(actual.key, undefined, 'clear operation has no key'); |
22 assert_equals(actual.value, null, 'clear operation has no value'); | 25 assert_equals(actual.value, null, 'clear operation has no value'); |
23 return; | 26 return; |
24 } | 27 } |
25 // TODO(palakj): Type should return 'delete' instead of 'kDelete', once fixed.
Issue crbug.com/609934. | 28 // TODO(dmurph): Type should return 'delete' instead of 'kDelete', once fixed.
Issue crbug.com/609934. |
26 if (actual.type == 'kDelete') { | 29 if (actual.type == 'kDelete') { |
27 assert_equals(actual.key.lower, expected.key.lower, 'Observed operation key
lower bound should match operation performed'); | 30 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'); | 31 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'); | 32 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'); | 33 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. | 34 // TODO(dmurph): Value needs to be updated, once returned correctly. Issue c
rbug.com/609934. |
32 assert_equals(actual.value, null, 'Delete operation has no value'); | 35 assert_equals(actual.value, null, 'Delete operation has no value'); |
33 return; | 36 return; |
34 } | 37 } |
35 assert_equals(actual.key.lower, expected.key, 'Observed operation key lower bo
und should match operation performed'); | 38 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'); | 39 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. | 40 // TODO(dmurph): 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'); | 41 assert_equals(actual.value, null, 'Put/Add operation value does not match'); |
39 } | 42 } |
40 | 43 |
41 function countCallbacks(actual, expected) { | 44 function countCallbacks(actual, expected) { |
42 assert_equals(actual, expected, 'Number of callbacks fired for observer should
match number of transactions it observed') | 45 assert_equals(actual, expected, 'Number of callbacks fired for observer should
match number of transactions it observed') |
43 } | 46 } |
44 | 47 |
45 function createDatabase(db, stores) { | 48 function createObjectStores(db, stores) { |
46 for (var i in stores) | 49 for (var i in stores) |
47 db.createObjectStore(stores[i]); | 50 db.createObjectStore(stores[i]); |
48 } | 51 } |
49 | 52 |
| 53 function operateOnDb(db, records) { |
| 54 var tx = db.transaction(Object.keys(records), 'readwrite'); |
| 55 operateOnTx(tx, records); |
| 56 tx.onerror = function() { |
| 57 console.log('transaction should not fail') |
| 58 } |
| 59 } |
| 60 |
| 61 function operateOnTx(tx, records) { |
| 62 for (var storeName in records) { |
| 63 var store = tx.objectStore(storeName); |
| 64 operateOnStore(store, records[storeName]); |
| 65 } |
| 66 } |
| 67 |
50 function operateOnStore(store, operations) { | 68 function operateOnStore(store, operations) { |
51 for (var i in operations ) { | 69 for (var i in operations ) { |
52 var op = operations[i]; | 70 var op = operations[i]; |
53 assert_in_array(op.type, ['put', 'add', 'delete', 'clear', 'get'], 'Operatio
n type not defined'); | 71 var request; |
| 72 assert_in_array(op.type, ['put', 'add', 'kDelete', 'clear', 'get'], 'Operati
on type not defined'); |
54 if (op.type == 'put') | 73 if (op.type == 'put') |
55 store.put(op.value, op.key); | 74 request = store.put(op.value, op.key); |
56 else if (op.type == 'add') | 75 else if (op.type == 'add') |
57 store.add(op.value, op.key); | 76 request = store.add(op.value, op.key); |
58 else if (op.type == 'delete') | 77 else if (op.type == 'kDelete') |
59 store.delete(IDBKeyRange.bound(op.key.lower, op.key.upper)); | 78 request = store.delete(IDBKeyRange.bound(op.key.lower, op.key.upper)); |
60 else if (op.type == 'clear') | 79 else if (op.type == 'clear') |
61 store.clear(); | 80 request = store.clear(); |
62 else | 81 else |
63 store.get(op.key) | 82 request = store.get(op.key) |
| 83 request.onerror = function() { |
| 84 console.log(op.type + ' operation should not fail') |
| 85 } |
64 } | 86 } |
65 } | 87 } |
OLD | NEW |