OLD | NEW |
---|---|
1 if (this.importScripts) { | 1 if (this.importScripts) { |
2 importScripts('../../../resources/testharness.js'); | 2 importScripts('../../../resources/testharness.js'); |
3 importScripts('generic-idb-operations.js'); | 3 importScripts('generic-idb-operations.js'); |
4 importScripts('observer-helpers.js'); | 4 importScripts('observer-helpers.js'); |
5 importScripts('testharness-helpers.js'); | 5 importScripts('testharness-helpers.js'); |
6 } | 6 } |
7 | 7 |
8 setup({timeout: 20000}); | 8 setup({timeout: 20000}); |
9 | 9 |
10 var openDB = function(t, dbName, openFunc) { | 10 var openDB = function(t, dbName, openFunc) { |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
83 obs.observe(db, txn, {operationTypes: ['add']}); | 83 obs.observe(db, txn, {operationTypes: ['add']}); |
84 txn.oncomplete = observers_added_callback; | 84 txn.oncomplete = observers_added_callback; |
85 txn.onerror = t.unreached_func('transaction should not fail') | 85 txn.onerror = t.unreached_func('transaction should not fail') |
86 })); | 86 })); |
87 }, 'IDB Observers: Operation filtering'); | 87 }, 'IDB Observers: Operation filtering'); |
88 | 88 |
89 indexeddb_observers_test(function(t, db1_name, db2_name, observers_added_callbac k) { | 89 indexeddb_observers_test(function(t, db1_name, db2_name, observers_added_callbac k) { |
90 var expectedChanges = { | 90 var expectedChanges = { |
91 dbName: db1_name, | 91 dbName: db1_name, |
92 records: { | 92 records: { |
93 'store2': [{type: 'add', key: 'z', value: 'z'}] | |
94 } | |
95 }; | |
96 | |
97 var connection = null; | |
98 var observeFunction = function(changes) { | |
99 compareChanges(changes, expectedChanges); | |
100 assert_true(connection != null); | |
pwnall
2017/01/10 01:41:11
Can you add a description for the meaning of this
dmurph
2017/01/10 20:40:06
Done.
| |
101 obs.unobserve(connection); | |
102 t.done(); | |
103 }; | |
104 | |
105 var obs = new IDBObserver(t.step_func(observeFunction)); | |
106 | |
107 openDB(t, db1_name, t.step_func(function(db) { | |
108 connection = db; | |
109 var txn = db.transaction(['store2'], 'readonly'); | |
110 obs.observe(db, txn, {operationTypes: ['add'], values: true}); | |
111 txn.oncomplete = observers_added_callback; | |
112 txn.onerror = t.unreached_func('transaction should not fail') | |
113 })); | |
114 }, 'IDB Observers: Values'); | |
115 | |
116 | |
117 indexeddb_observers_test(function(t, db1_name, db2_name, observers_added_callbac k) { | |
118 var expectedChanges = { | |
119 dbName: db1_name, | |
120 records: { | |
93 'store2': [{type: 'add', key: 'z'}] | 121 'store2': [{type: 'add', key: 'z'}] |
pwnall
2017/01/10 01:41:11
comma at the end of the line, to minimize future c
dmurph
2017/01/10 20:40:06
Done.
| |
94 } | 122 } |
95 }; | 123 }; |
124 | |
125 var connection = null; | |
126 var observeFunction = function(changes) { | |
127 compareChanges(changes, expectedChanges); | |
128 assert_true(connection != null); | |
129 obs.unobserve(connection); | |
130 assert_true(changes.transaction != null); | |
131 var store2 = changes.transaction.objectStore('store2'); | |
132 var request = store2.get('z'); | |
133 request.onsuccess = t.step_func(function() { | |
134 assert_equals(request.result, 'z'); | |
135 t.done(); | |
136 }); | |
137 }; | |
138 | |
139 var obs = new IDBObserver(t.step_func(observeFunction)); | |
140 | |
141 openDB(t, db1_name, t.step_func(function(db) { | |
142 connection = db; | |
143 var txn = db.transaction(['store2'], 'readonly'); | |
144 obs.observe(db, txn, {operationTypes: ['add'], transaction: true}); | |
145 txn.oncomplete = observers_added_callback; | |
146 txn.onerror = t.unreached_func('transaction should not fail') | |
147 })); | |
148 }, 'IDB Observers: Transaction'); | |
149 | |
150 indexeddb_observers_test(function(t, db1_name, db2_name, observers_added_callbac k) { | |
151 var expectedChanges = { | |
152 dbName: db1_name, | |
153 records: { | |
154 'store2': [{type: 'add', key: 'z'}] | |
155 } | |
156 }; | |
96 | 157 |
97 var connection = null; | 158 var connection = null; |
98 var observeFunction = function(changes) { | 159 var observeFunction = function(changes) { |
99 compareChanges(changes, expectedChanges); | 160 compareChanges(changes, expectedChanges); |
100 assert_true(connection != null); | 161 assert_true(connection != null); |
101 obs.unobserve(connection); | 162 obs.unobserve(connection); |
102 t.done(); | 163 t.done(); |
103 }; | 164 }; |
104 | 165 |
105 var obs = new IDBObserver(t.step_func(observeFunction)); | 166 var obs = new IDBObserver(t.step_func(observeFunction)); |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
220 var expectedChanges2 = { | 281 var expectedChanges2 = { |
221 dbName: db1_name, | 282 dbName: db1_name, |
222 records: { | 283 records: { |
223 'store2': [{type: 'add', key: 'z'}] | 284 'store2': [{type: 'add', key: 'z'}] |
224 } | 285 } |
225 }; | 286 }; |
226 | 287 |
227 var connection = null; | 288 var connection = null; |
228 var changeNumber = 0; | 289 var changeNumber = 0; |
229 var observeFunction = function(changes) { | 290 var observeFunction = function(changes) { |
230 assert_true(connection != null); | 291 assert_true(connection != null, "connection is null"); |
pwnall
2017/01/10 01:41:11
The comment appears to be redundant with the condi
dmurph
2017/01/10 20:40:06
Done.
| |
231 if (changeNumber === 0) { | 292 if (changes.records.has('store1')) { |
232 compareChanges(changes, expectedChanges1); | 293 compareChanges(changes, expectedChanges1); |
233 } else if(changeNumber === 1) { | 294 } else if(changes.records.has('store2')) { |
234 compareChanges(changes, expectedChanges2); | 295 compareChanges(changes, expectedChanges2); |
296 } | |
297 ++changeNumber; | |
298 assert_less_than_equal(changeNumber, 2, "incorrect pendingObserves"); | |
299 if (changeNumber == 2) { | |
235 obs.unobserve(connection); | 300 obs.unobserve(connection); |
236 t.done(); | 301 t.done(); |
237 } | 302 } |
238 ++changeNumber; | |
239 assert_less_than_equal(changeNumber, 1, "incorrect pendingObserves"); | |
240 }; | 303 }; |
241 | 304 |
242 var obs = new IDBObserver(t.step_func(observeFunction)); | 305 var obs = new IDBObserver(t.step_func(observeFunction)); |
243 | 306 |
244 openDB(t, db1_name, t.step_func(function(db) { | 307 openDB(t, db1_name, t.step_func(function(db) { |
245 connection = db; | 308 connection = db; |
246 var txn = db.transaction(['store1', 'store2'], 'readonly'); | 309 var txn = db.transaction(['store1', 'store2'], 'readonly'); |
247 obs.observe(db, txn, {operationTypes: ['put']}); | 310 obs.observe(db, txn, {operationTypes: ['put']}); |
248 obs.observe(db, txn, {operationTypes: ['add']}); | 311 obs.observe(db, txn, {operationTypes: ['add']}); |
249 txn.oncomplete = observers_added_callback; | 312 txn.oncomplete = observers_added_callback; |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
545 openDB(t, db2_name, t.step_func(function(db) { | 608 openDB(t, db2_name, t.step_func(function(db) { |
546 connection2 = db; | 609 connection2 = db; |
547 var txn = db.transaction(['store3'], 'readonly'); | 610 var txn = db.transaction(['store3'], 'readonly'); |
548 obs.observe(db, txn, {operationTypes: ['clear', 'put', 'add', 'delete']}); | 611 obs.observe(db, txn, {operationTypes: ['clear', 'put', 'add', 'delete']}); |
549 txn.oncomplete = cb3; | 612 txn.oncomplete = cb3; |
550 txn.onerror = t.unreached_func('transaction should not fail'); | 613 txn.onerror = t.unreached_func('transaction should not fail'); |
551 })); | 614 })); |
552 }, 'IDB Observers: Close connection removes observers'); | 615 }, 'IDB Observers: Close connection removes observers'); |
553 | 616 |
554 done(); | 617 done(); |
OLD | NEW |