Chromium Code Reviews| 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 15 matching lines...) Expand all Loading... | |
| 26 } | 26 } |
| 27 }; | 27 }; |
| 28 var connection = null; | 28 var connection = null; |
| 29 var observeFunction = function(changes) { | 29 var observeFunction = function(changes) { |
| 30 compareChanges(changes, expectedChanges); | 30 compareChanges(changes, expectedChanges); |
| 31 assert_true(connection != null); | 31 assert_true(connection != null); |
| 32 obs.unobserve(connection); | 32 obs.unobserve(connection); |
| 33 t.done(); | 33 t.done(); |
| 34 }; | 34 }; |
| 35 | 35 |
| 36 var obs = new IDBObserver( | 36 var obs = new IDBObserver(t.step_func(observeFunction)); |
| 37 t.step_func(observeFunction), | |
| 38 { operationTypes: ['clear', 'put', 'add', 'delete'] }); | |
| 39 | 37 |
| 40 openDB(t, db1_name, t.step_func(function(db) { | 38 openDB(t, db1_name, t.step_func(function(db) { |
| 41 connection = db; | 39 connection = db; |
| 42 var txn = db.transaction(['store1', 'store2'], 'readwrite'); | 40 var txn = db.transaction(['store1', 'store2'], 'readwrite'); |
| 43 | 41 |
| 44 // Verify initial state. | 42 // Verify initial state. |
| 45 var os1 = txn.objectStore('store1'); | 43 var os1 = txn.objectStore('store1'); |
| 46 var readReq1 = os1.get('a'); | 44 var readReq1 = os1.get('a'); |
| 47 readReq1.onsuccess = t.step_func(function() { | 45 readReq1.onsuccess = t.step_func(function() { |
| 48 assert_equals(readReq1.result, 'b', 'Initial state incorrect.'); | 46 assert_equals(readReq1.result, 'b', 'Initial state incorrect.'); |
| 49 }); | 47 }); |
| 50 var os2 = txn.objectStore('store2'); | 48 var os2 = txn.objectStore('store2'); |
| 51 var readReq2 = os2.get('x'); | 49 var readReq2 = os2.get('x'); |
| 52 readReq2.onsuccess = t.step_func(function() { | 50 readReq2.onsuccess = t.step_func(function() { |
| 53 assert_equals(readReq2.result, 'y', 'Initial state incorrect.'); | 51 assert_equals(readReq2.result, 'y', 'Initial state incorrect.'); |
| 54 }); | 52 }); |
| 55 | 53 |
| 56 // Start observing! | 54 // Start observing! |
| 57 obs.observe(db, txn); | 55 obs.observe(db, txn, {operationTypes: ['clear', 'put', 'add', 'delete']}); |
| 58 | 56 |
| 59 txn.oncomplete = observers_added_callback; | 57 txn.oncomplete = observers_added_callback; |
| 60 txn.onerror = t.unreached_func('transaction should not fail'); | 58 txn.onerror = t.unreached_func('transaction should not fail'); |
| 61 })); | 59 })); |
| 62 }, 'IDB Observers: Verify initial state and record all operations'); | 60 }, 'IDB Observers: Verify initial state and record all operations'); |
| 63 | 61 |
| 64 indexeddb_observers_test(function(t, db1_name, db2_name, observers_added_callbac k) { | 62 indexeddb_observers_test(function(t, db1_name, db2_name, observers_added_callbac k) { |
| 65 var expectedChanges = { | 63 var expectedChanges = { |
| 66 dbName: db1_name, | 64 dbName: db1_name, |
| 67 records: { | 65 records: { |
| 68 'store2': [{type: 'add', key: 'z'}] | 66 'store2': [{type: 'add', key: 'z'}] |
| 69 } | 67 } |
| 70 }; | 68 }; |
| 71 | 69 |
| 72 var connection = null; | 70 var connection = null; |
| 73 var observeFunction = function(changes) { | 71 var observeFunction = function(changes) { |
| 74 compareChanges(changes, expectedChanges); | 72 compareChanges(changes, expectedChanges); |
| 75 assert_true(connection != null); | 73 assert_true(connection != null); |
| 76 obs.unobserve(connection); | 74 obs.unobserve(connection); |
| 77 t.done(); | 75 t.done(); |
| 78 }; | 76 }; |
| 79 | 77 |
| 80 var obs = new IDBObserver( | 78 var obs = new IDBObserver(t.step_func(observeFunction)); |
| 81 t.step_func(observeFunction), | |
| 82 { operationTypes: ['add'] }); | |
| 83 | 79 |
| 84 openDB(t, db1_name, t.step_func(function(db) { | 80 openDB(t, db1_name, t.step_func(function(db) { |
| 85 connection = db; | 81 connection = db; |
| 86 var txn = db.transaction(['store2'], 'readonly'); | 82 var txn = db.transaction(['store2'], 'readonly'); |
| 87 obs.observe(db, txn); | 83 obs.observe(db, txn, {operationTypes: ['add']}); |
| 88 txn.oncomplete = observers_added_callback; | 84 txn.oncomplete = observers_added_callback; |
| 89 txn.onerror = t.unreached_func('transaction should not fail') | 85 txn.onerror = t.unreached_func('transaction should not fail') |
| 90 })); | 86 })); |
| 91 }, 'IDB Observers: Operation filtering'); | 87 }, 'IDB Observers: Operation filtering'); |
| 92 | 88 |
| 93 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) { |
| 94 var expectedChanges = { | 90 var expectedChanges = { |
| 95 dbName: db1_name, | 91 dbName: db1_name, |
| 96 records: { | 92 records: { |
| 97 'store2': [{type: 'add', key: 'z'}] | 93 'store2': [{type: 'add', key: 'z'}] |
| 98 } | 94 } |
| 99 }; | 95 }; |
| 100 | 96 |
| 101 var connection = null; | 97 var connection = null; |
| 102 var observeFunction = function(changes) { | 98 var observeFunction = function(changes) { |
| 103 compareChanges(changes, expectedChanges); | 99 compareChanges(changes, expectedChanges); |
| 104 assert_true(connection != null); | 100 assert_true(connection != null); |
| 105 obs.unobserve(connection); | 101 obs.unobserve(connection); |
| 106 t.done(); | 102 t.done(); |
| 107 }; | 103 }; |
| 108 | 104 |
| 109 var obs = new IDBObserver( | 105 var obs = new IDBObserver(t.step_func(observeFunction)); |
| 110 t.step_func(observeFunction), | |
| 111 { operationTypes: ['clear', 'put', 'add', 'delete'] }); | |
| 112 | 106 |
| 113 openDB(t, db1_name, t.step_func(function(db) { | 107 openDB(t, db1_name, t.step_func(function(db) { |
| 114 connection = db; | 108 connection = db; |
| 115 var txn = db.transaction(['store2'], 'readonly'); | 109 var txn = db.transaction(['store2'], 'readonly'); |
| 116 obs.observe(db, txn); | 110 obs.observe(db, txn, {operationTypes: ['clear', 'put', 'add', 'delete']}); |
| 117 txn.oncomplete = observers_added_callback; | 111 txn.oncomplete = observers_added_callback; |
| 118 txn.onerror = t.unreached_func('transaction should not fail') | 112 txn.onerror = t.unreached_func('transaction should not fail') |
| 119 })); | 113 })); |
| 120 }, 'IDB Observers: Object store filtering'); | 114 }, 'IDB Observers: Object store filtering'); |
| 121 | 115 |
| 122 indexeddb_observers_test(function(t, db1_name, db2_name, observers_added_callbac k) { | 116 indexeddb_observers_test(function(t, db1_name, db2_name, observers_added_callbac k) { |
| 123 var expectedChanges1 = { | 117 var expectedChanges1 = { |
| 124 dbName: db1_name, | 118 dbName: db1_name, |
| 125 records: { | 119 records: { |
| 126 'store1': [{type: 'delete', key: {lower: 'a', upper: 'b'}}, | 120 'store1': [{type: 'delete', key: {lower: 'a', upper: 'b'}}, |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 153 assert_true(connection2 != null); | 147 assert_true(connection2 != null); |
| 154 obs.unobserve(connection2); | 148 obs.unobserve(connection2); |
| 155 } | 149 } |
| 156 if (pendingObserves === 0) { | 150 if (pendingObserves === 0) { |
| 157 t.done(); | 151 t.done(); |
| 158 } else if (pendingObserves < 0) { | 152 } else if (pendingObserves < 0) { |
| 159 assert_unreached("incorrect pendingObserves"); | 153 assert_unreached("incorrect pendingObserves"); |
| 160 } | 154 } |
| 161 }; | 155 }; |
| 162 | 156 |
| 163 var obs = new IDBObserver( | 157 var obs = new IDBObserver(t.step_func(observeFunction)); |
| 164 t.step_func(observeFunction), | |
| 165 { operationTypes: ['clear', 'put', 'add', 'delete'] }); | |
| 166 | 158 |
| 167 var cb1 = observers_added_barrier(t); | 159 var cb1 = observers_added_barrier(t); |
| 168 openDB(t, db1_name, t.step_func(function(db) { | 160 openDB(t, db1_name, t.step_func(function(db) { |
| 169 connection1 = db; | 161 connection1 = db; |
| 170 var txn = db.transaction(['store1', 'store2'], 'readonly'); | 162 var txn = db.transaction(['store1', 'store2'], 'readonly'); |
| 171 obs.observe(db, txn); | 163 obs.observe(db, txn, {operationTypes: ['clear', 'put', 'add', 'delete']}); |
| 172 txn.oncomplete = cb1; | 164 txn.oncomplete = cb1; |
| 173 txn.onerror = t.unreached_func('transaction should not fail') | 165 txn.onerror = t.unreached_func('transaction should not fail') |
| 174 })); | 166 })); |
| 175 var cb2 = observers_added_barrier(t); | 167 var cb2 = observers_added_barrier(t); |
| 176 openDB(t, db2_name, t.step_func(function(db) { | 168 openDB(t, db2_name, t.step_func(function(db) { |
| 177 connection2 = db; | 169 connection2 = db; |
| 178 var txn = db.transaction(['store3', 'store4'], 'readonly'); | 170 var txn = db.transaction(['store3', 'store4'], 'readonly'); |
| 179 obs.observe(db, txn); | 171 obs.observe(db, txn, {operationTypes: ['clear', 'put', 'add', 'delete']}); |
| 180 txn.oncomplete = cb2; | 172 txn.oncomplete = cb2; |
| 181 txn.onerror = t.unreached_func('transaction should not fail') | 173 txn.onerror = t.unreached_func('transaction should not fail') |
| 182 })); | 174 })); |
| 183 }, 'IDB Observers: Multiple connections'); | 175 }, 'IDB Observers: Multiple connections'); |
| 184 | 176 |
| 185 indexeddb_observers_test(function(t, db1_name, db2_name, observers_added_callbac k) { | 177 indexeddb_observers_test(function(t, db1_name, db2_name, observers_added_callbac k) { |
| 186 var expectedChanges = { | 178 var expectedChanges = { |
| 187 dbName: db1_name, | 179 dbName: db1_name, |
| 188 records: { | 180 records: { |
| 189 'store1': [{type: 'delete', key: {lower: 'a', upper: 'b'}}, | 181 'store1': [{type: 'delete', key: {lower: 'a', upper: 'b'}}, |
| 190 {type: 'put', key: 'a'}], | 182 {type: 'put', key: 'a'}], |
| 191 'store2': [{type: 'add', key: 'z'}] | 183 'store2': [{type: 'add', key: 'z'}] |
| 192 } | 184 } |
| 193 }; | 185 }; |
| 194 | 186 |
| 195 var connection = null; | 187 var connection = null; |
| 196 var pendingObserves = 2; | 188 var pendingObserves = 2; |
| 197 var observeFunction = function(changes) { | 189 var observeFunction = function(changes) { |
| 198 compareChanges(changes, expectedChanges); | 190 compareChanges(changes, expectedChanges); |
| 199 pendingObserves = pendingObserves - 1; | 191 pendingObserves = pendingObserves - 1; |
| 200 if (pendingObserves === 0) { | 192 if (pendingObserves === 0) { |
| 201 assert_true(connection != null); | 193 assert_true(connection != null); |
| 202 obs.unobserve(connection); | 194 obs.unobserve(connection); |
| 203 t.done(); | 195 t.done(); |
| 204 } else if (pendingObserves < 0) { | 196 } else if (pendingObserves < 0) { |
| 205 assert_unreached("incorrect pendingObserves"); | 197 assert_unreached("incorrect pendingObserves"); |
| 206 } | 198 } |
| 207 }; | 199 }; |
| 208 | 200 |
| 209 var obs = new IDBObserver( | 201 var obs = new IDBObserver(t.step_func(observeFunction)); |
| 210 t.step_func(observeFunction), | |
| 211 { operationTypes: ['clear', 'put', 'add', 'delete'] }); | |
| 212 | 202 |
| 213 openDB(t, db1_name, t.step_func(function(db) { | 203 openDB(t, db1_name, t.step_func(function(db) { |
| 214 connection = db; | 204 connection = db; |
| 215 var txn = db.transaction(['store1', 'store2'], 'readonly'); | 205 var txn = db.transaction(['store1', 'store2'], 'readonly'); |
| 216 obs.observe(db, txn); | 206 obs.observe(db, txn, {operationTypes: ['clear', 'put', 'add', 'delete']}); |
|
cmumford
2016/11/07 21:55:16
Makes me wonder if we should have an "all" type.
dmurph
2016/11/07 22:31:54
Yeah -- I wanted it to directly reflect the functi
| |
| 217 obs.observe(db, txn); | 207 obs.observe(db, txn, {operationTypes: ['clear', 'put', 'add', 'delete']}); |
| 218 txn.oncomplete = observers_added_callback; | 208 txn.oncomplete = observers_added_callback; |
| 219 txn.onerror = t.unreached_func('transaction should not fail'); | 209 txn.onerror = t.unreached_func('transaction should not fail'); |
| 220 })); | 210 })); |
| 221 }, 'IDB Observers: Multiple observer calls'); | 211 }, 'IDB Observers: Multiple observer calls'); |
| 222 | 212 |
| 223 indexeddb_observers_test(function(t, db1_name, db2_name, observers_added_callbac k) { | 213 indexeddb_observers_test(function(t, db1_name, db2_name, observers_added_callbac k) { |
| 214 var expectedChanges1 = { | |
| 215 dbName: db1_name, | |
| 216 records: { | |
| 217 'store1': [{type: 'put', key: 'a'}] | |
| 218 } | |
| 219 }; | |
| 220 var expectedChanges2 = { | |
| 221 dbName: db1_name, | |
| 222 records: { | |
| 223 'store2': [{type: 'add', key: 'z'}] | |
| 224 } | |
| 225 }; | |
| 226 | |
| 227 var connection = null; | |
| 228 var changeNumber = 0; | |
| 229 var observeFunction = function(changes) { | |
| 230 assert_true(connection != null); | |
| 231 if (changeNumber === 0) { | |
| 232 compareChanges(changes, expectedChanges1); | |
| 233 } else if(changeNumber === 1) { | |
| 234 compareChanges(changes, expectedChanges2); | |
| 235 obs.unobserve(connection); | |
| 236 t.done(); | |
| 237 } | |
| 238 ++changeNumber; | |
| 239 if (changeNumber > 1) { | |
|
cmumford
2016/11/07 21:55:15
Nit: How about assert_less_than_equal(changeNumber
dmurph
2016/11/07 22:31:54
I was looking for that assert! ;) thanks!
| |
| 240 assert_unreached("incorrect pendingObserves"); | |
| 241 } | |
| 242 }; | |
| 243 | |
| 244 var obs = new IDBObserver(t.step_func(observeFunction)); | |
| 245 | |
| 246 openDB(t, db1_name, t.step_func(function(db) { | |
| 247 connection = db; | |
| 248 var txn = db.transaction(['store1', 'store2'], 'readonly'); | |
| 249 obs.observe(db, txn, {operationTypes: ['put']}); | |
| 250 obs.observe(db, txn, {operationTypes: ['add']}); | |
| 251 txn.oncomplete = observers_added_callback; | |
| 252 txn.onerror = t.unreached_func('transaction should not fail'); | |
| 253 })); | |
| 254 }, 'IDB Observers: Multiple observer calls with filtering'); | |
| 255 | |
| 256 indexeddb_observers_test(function(t, db1_name, db2_name, observers_added_callbac k) { | |
| 224 var partOneChanges1 = { | 257 var partOneChanges1 = { |
| 225 dbName: db1_name, | 258 dbName: db1_name, |
| 226 records: { | 259 records: { |
| 227 'store1': [{type: 'delete', key: {lower: 'a', upper: 'b'}}, | 260 'store1': [{type: 'delete', key: {lower: 'a', upper: 'b'}}, |
| 228 {type: 'put', key: 'a'}] | 261 {type: 'put', key: 'a'}] |
| 229 } | 262 } |
| 230 }; | 263 }; |
| 231 | 264 |
| 232 var partOneChanges2 = { | 265 var partOneChanges2 = { |
| 233 dbName: db1_name, | 266 dbName: db1_name, |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 277 } else { | 310 } else { |
| 278 assert_unreached('Unknown connection supplied with changes.'); | 311 assert_unreached('Unknown connection supplied with changes.'); |
| 279 } | 312 } |
| 280 if (pendingObserves === 0) { | 313 if (pendingObserves === 0) { |
| 281 t.done(); | 314 t.done(); |
| 282 } else if (pendingObserves < 0) { | 315 } else if (pendingObserves < 0) { |
| 283 assert_unreached("incorrect pendingObserves"); | 316 assert_unreached("incorrect pendingObserves"); |
| 284 } | 317 } |
| 285 }; | 318 }; |
| 286 | 319 |
| 287 var obs = new IDBObserver( | 320 var obs = new IDBObserver(t.step_func(observeFunction)); |
| 288 t.step_func(observeFunction), | |
| 289 { operationTypes: ['clear', 'put', 'add', 'delete'] }); | |
| 290 | 321 |
| 291 var cb1 = observers_added_barrier(t); | 322 var cb1 = observers_added_barrier(t); |
| 292 openDB(t, db1_name, t.step_func(function(db) { | 323 openDB(t, db1_name, t.step_func(function(db) { |
| 293 connection1 = db; | 324 connection1 = db; |
| 294 var txn = db.transaction(['store1'], 'readonly'); | 325 var txn = db.transaction(['store1'], 'readonly'); |
| 295 obs.observe(db, txn); | 326 obs.observe(db, txn, {operationTypes: ['clear', 'put', 'add', 'delete']}); |
| 296 txn.oncomplete = cb1; | 327 txn.oncomplete = cb1; |
| 297 txn.onerror = t.unreached_func('transaction should not fail'); | 328 txn.onerror = t.unreached_func('transaction should not fail'); |
| 298 })); | 329 })); |
| 299 var cb2 = observers_added_barrier(t); | 330 var cb2 = observers_added_barrier(t); |
| 300 openDB(t, db1_name, t.step_func(function(db) { | 331 openDB(t, db1_name, t.step_func(function(db) { |
| 301 connection2 = db; | 332 connection2 = db; |
| 302 var txn = db.transaction(['store2'], 'readonly'); | 333 var txn = db.transaction(['store2'], 'readonly'); |
| 303 obs.observe(db, txn); | 334 obs.observe(db, txn, {operationTypes: ['clear', 'put', 'add', 'delete']}); |
| 304 txn.oncomplete = cb2; | 335 txn.oncomplete = cb2; |
| 305 txn.onerror = t.unreached_func('transaction should not fail'); | 336 txn.onerror = t.unreached_func('transaction should not fail'); |
| 306 })); | 337 })); |
| 307 var cb3 = observers_added_barrier(t); | 338 var cb3 = observers_added_barrier(t); |
| 308 openDB(t, db2_name, t.step_func(function(db) { | 339 openDB(t, db2_name, t.step_func(function(db) { |
| 309 connection3 = db; | 340 connection3 = db; |
| 310 var txn = db.transaction(['store3', 'store4'], 'readonly'); | 341 var txn = db.transaction(['store3', 'store4'], 'readonly'); |
| 311 obs.observe(db, txn); | 342 obs.observe(db, txn, {operationTypes: ['clear', 'put', 'add', 'delete']}); |
| 312 txn.oncomplete = cb3; | 343 txn.oncomplete = cb3; |
| 313 txn.onerror = t.unreached_func('transaction should not fail') | 344 txn.onerror = t.unreached_func('transaction should not fail') |
| 314 })); | 345 })); |
| 315 }, 'IDB Observers: Three connections, unobserve two'); | 346 }, 'IDB Observers: Three connections, unobserve two'); |
| 316 | 347 |
| 317 indexeddb_observers_test(function(t, db1_name, db2_name, observers_added_callbac k) { | 348 indexeddb_observers_test(function(t, db1_name, db2_name, observers_added_callbac k) { |
| 318 var connection1 = null; | 349 var connection1 = null; |
| 319 var connection2 = null; | 350 var connection2 = null; |
| 320 | 351 |
| 321 var observeFunction = function(changes) { | 352 var observeFunction = function(changes) { |
| 322 assert_equals(changes.database, connection2); | 353 assert_equals(changes.database, connection2); |
| 323 obs.unobserve(connection2); | 354 obs.unobserve(connection2); |
| 324 t.done(); | 355 t.done(); |
| 325 }; | 356 }; |
| 326 | 357 |
| 327 var obs = new IDBObserver( | 358 var obs = new IDBObserver(t.step_func(observeFunction)); |
| 328 t.step_func(observeFunction), | |
| 329 { operationTypes: ['clear', 'put', 'add', 'delete'] }); | |
| 330 | 359 |
| 331 openDB(t, db1_name, t.step_func(function(db) { | 360 openDB(t, db1_name, t.step_func(function(db) { |
| 332 connection1 = db; | 361 connection1 = db; |
| 333 var txn = db.transaction(['store1'], 'readonly'); | 362 var txn = db.transaction(['store1'], 'readonly'); |
| 334 obs.observe(db, txn); | 363 obs.observe(db, txn, {operationTypes: ['clear', 'put', 'add', 'delete']}); |
| 335 obs.unobserve(db); | 364 obs.unobserve(db); |
| 336 txn.oncomplete = t.step_func(function() { | 365 txn.oncomplete = t.step_func(function() { |
| 337 openDB(t, db1_name, t.step_func(function(db) { | 366 openDB(t, db1_name, t.step_func(function(db) { |
| 338 connection2 = db; | 367 connection2 = db; |
| 339 var txn = db.transaction(['store2'], 'readonly'); | 368 var txn = db.transaction(['store2'], 'readonly'); |
| 340 obs.observe(db, txn); | 369 obs.observe( |
| 370 db, txn, {operationTypes: ['clear', 'put', 'add', 'delete']}); | |
| 341 txn.oncomplete = observers_added_callback; | 371 txn.oncomplete = observers_added_callback; |
| 342 txn.onerror = t.unreached_func('transaction should not fail'); | 372 txn.onerror = t.unreached_func('transaction should not fail'); |
| 343 })); | 373 })); |
| 344 }); | 374 }); |
| 345 txn.onerror = t.unreached_func('transaction should not fail'); | 375 txn.onerror = t.unreached_func('transaction should not fail'); |
| 346 })); | 376 })); |
| 347 }, 'IDB Observers: Unobserve immediately'); | 377 }, 'IDB Observers: Unobserve immediately'); |
| 348 | 378 |
| 349 indexeddb_observers_test(function(t, db1_name, db2_name, observers_added_callbac k) { | 379 indexeddb_observers_test(function(t, db1_name, db2_name, observers_added_callbac k) { |
| 350 var connection1 = null; | 380 var connection1 = null; |
| 351 var connection2 = null; | 381 var connection2 = null; |
| 352 | 382 |
| 353 var observeFunction = function(changes) { | 383 var observeFunction = function(changes) { |
| 354 assert_equals(changes.database, connection2); | 384 assert_equals(changes.database, connection2); |
| 355 obs.unobserve(connection2); | 385 obs.unobserve(connection2); |
| 356 t.done(); | 386 t.done(); |
| 357 }; | 387 }; |
| 358 | 388 |
| 359 var obs = new IDBObserver( | 389 var obs = new IDBObserver(t.step_func(observeFunction)); |
| 360 t.step_func(observeFunction), | |
| 361 { operationTypes: ['clear', 'put', 'add', 'delete'] }); | |
| 362 | 390 |
| 363 openDB(t, db1_name, t.step_func(function(db) { | 391 openDB(t, db1_name, t.step_func(function(db) { |
| 364 connection1 = db; | 392 connection1 = db; |
| 365 var txn = db.transaction(['store1'], 'readonly'); | 393 var txn = db.transaction(['store1'], 'readonly'); |
| 366 obs.observe(db, txn); | 394 obs.observe(db, txn, {operationTypes: ['clear', 'put', 'add', 'delete']}); |
| 367 obs.observe(db, txn); | 395 obs.observe(db, txn, {operationTypes: ['clear', 'put', 'add', 'delete']}); |
| 368 obs.observe(db, txn); | 396 obs.observe(db, txn, {operationTypes: ['clear', 'put', 'add', 'delete']}); |
| 369 obs.unobserve(db); | 397 obs.unobserve(db); |
| 370 txn.oncomplete = t.step_func(function() { | 398 txn.oncomplete = t.step_func(function() { |
| 371 openDB(t, db1_name, t.step_func(function(db) { | 399 openDB(t, db1_name, t.step_func(function(db) { |
| 372 connection2 = db; | 400 connection2 = db; |
| 373 var txn = db.transaction(['store2'], 'readonly'); | 401 var txn = db.transaction(['store2'], 'readonly'); |
| 374 obs.observe(db, txn); | 402 obs.observe( |
| 403 db, txn, {operationTypes: ['clear', 'put', 'add', 'delete']}); | |
| 375 txn.oncomplete = observers_added_callback; | 404 txn.oncomplete = observers_added_callback; |
| 376 txn.onerror = t.unreached_func('transaction should not fail'); | 405 txn.onerror = t.unreached_func('transaction should not fail'); |
| 377 })); | 406 })); |
| 378 }); | 407 }); |
| 379 txn.onerror = t.unreached_func('transaction should not fail'); | 408 txn.onerror = t.unreached_func('transaction should not fail'); |
| 380 })); | 409 })); |
| 381 }, 'IDB Observers: Unobserve immediately on multiple'); | 410 }, 'IDB Observers: Unobserve immediately on multiple'); |
| 382 | 411 |
| 383 indexeddb_observers_test(function(t, db1_name, db2_name, observers_added_callbac k) { | 412 indexeddb_observers_test(function(t, db1_name, db2_name, observers_added_callbac k) { |
| 384 var expectedChanges1 = { | 413 var expectedChanges1 = { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 418 } else if (changes.database === connection2) { | 447 } else if (changes.database === connection2) { |
| 419 connection2Observes = connection2Observes + 1; | 448 connection2Observes = connection2Observes + 1; |
| 420 if (connection2Observes > 1) { | 449 if (connection2Observes > 1) { |
| 421 t.done(); | 450 t.done(); |
| 422 } | 451 } |
| 423 } else { | 452 } else { |
| 424 assert_unreached("unknown changes"); | 453 assert_unreached("unknown changes"); |
| 425 } | 454 } |
| 426 }; | 455 }; |
| 427 | 456 |
| 428 var obs = new IDBObserver( | 457 var obs = new IDBObserver(t.step_func(observeFunction)); |
| 429 t.step_func(observeFunction), | |
| 430 { operationTypes: ['clear', 'put', 'add', 'delete'] }); | |
| 431 | 458 |
| 432 var cb1 = observers_added_barrier(t); | 459 var cb1 = observers_added_barrier(t); |
| 433 var cb2 = observers_added_barrier(t); | 460 var cb2 = observers_added_barrier(t); |
| 434 openDB(t, db1_name, t.step_func(function(db) { | 461 openDB(t, db1_name, t.step_func(function(db) { |
| 435 connection1 = db; | 462 connection1 = db; |
| 436 var txn1 = db.transaction(['store1'], 'readonly'); | 463 var txn1 = db.transaction(['store1'], 'readonly'); |
| 437 var txn2 = db.transaction(['store2'], 'readonly'); | 464 var txn2 = db.transaction(['store2'], 'readonly'); |
| 438 // Start observing! | 465 // Start observing! |
| 439 obs.observe(db, txn1); | 466 obs.observe(db, txn1, {operationTypes: ['clear', 'put', 'add', 'delete']}); |
| 440 obs.observe(db, txn2); | 467 obs.observe(db, txn2, {operationTypes: ['clear', 'put', 'add', 'delete']}); |
| 441 | 468 |
| 442 txn1.oncomplete = cb1; | 469 txn1.oncomplete = cb1; |
| 443 txn2.oncomplete = cb2; | 470 txn2.oncomplete = cb2; |
| 444 txn1.onerror = t.unreached_func('transaction should not fail'); | 471 txn1.onerror = t.unreached_func('transaction should not fail'); |
| 445 txn2.onerror = t.unreached_func('transaction should not fail'); | 472 txn2.onerror = t.unreached_func('transaction should not fail'); |
| 446 })); | 473 })); |
| 447 var cb3 = observers_added_barrier(t); | 474 var cb3 = observers_added_barrier(t); |
| 448 openDB(t, db2_name, t.step_func(function(db) { | 475 openDB(t, db2_name, t.step_func(function(db) { |
| 449 connection2 = db; | 476 connection2 = db; |
| 450 var txn = db.transaction(['store3'], 'readonly'); | 477 var txn = db.transaction(['store3'], 'readonly'); |
| 451 obs.observe(db, txn); | 478 obs.observe(db, txn, {operationTypes: ['clear', 'put', 'add', 'delete']}); |
| 452 txn.oncomplete = cb3; | 479 txn.oncomplete = cb3; |
| 453 txn.onerror = t.unreached_func('transaction should not fail'); | 480 txn.onerror = t.unreached_func('transaction should not fail'); |
| 454 })); | 481 })); |
| 455 }, 'IDB Observers: Unobserve connection removes observers'); | 482 }, 'IDB Observers: Unobserve connection removes observers'); |
| 456 | 483 |
| 457 indexeddb_observers_test(function(t, db1_name, db2_name, observers_added_callbac k) { | 484 indexeddb_observers_test(function(t, db1_name, db2_name, observers_added_callbac k) { |
| 458 var expectedChanges1 = { | 485 var expectedChanges1 = { |
| 459 dbName: db1_name, | 486 dbName: db1_name, |
| 460 records: { | 487 records: { |
| 461 'store1': [{type: 'delete', key: {lower: 'a', upper: 'b'}}, | 488 'store1': [{type: 'delete', key: {lower: 'a', upper: 'b'}}, |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 492 } else if (changes.database === connection2) { | 519 } else if (changes.database === connection2) { |
| 493 connection2Observes = connection2Observes + 1; | 520 connection2Observes = connection2Observes + 1; |
| 494 if (connection2Observes > 1) { | 521 if (connection2Observes > 1) { |
| 495 t.done(); | 522 t.done(); |
| 496 } | 523 } |
| 497 } else { | 524 } else { |
| 498 assert_unreached("unknown changes"); | 525 assert_unreached("unknown changes"); |
| 499 } | 526 } |
| 500 }; | 527 }; |
| 501 | 528 |
| 502 var obs = new IDBObserver( | 529 var obs = new IDBObserver(t.step_func(observeFunction)); |
| 503 t.step_func(observeFunction), | |
| 504 { operationTypes: ['clear', 'put', 'add', 'delete'] }); | |
| 505 | 530 |
| 506 var cb1 = observers_added_barrier(t); | 531 var cb1 = observers_added_barrier(t); |
| 507 var cb2 = observers_added_barrier(t); | 532 var cb2 = observers_added_barrier(t); |
| 508 openDB(t, db1_name, t.step_func(function(db) { | 533 openDB(t, db1_name, t.step_func(function(db) { |
| 509 connection1 = db; | 534 connection1 = db; |
| 510 var txn1 = db.transaction(['store1'], 'readonly'); | 535 var txn1 = db.transaction(['store1'], 'readonly'); |
| 511 var txn2 = db.transaction(['store2'], 'readonly'); | 536 var txn2 = db.transaction(['store2'], 'readonly'); |
| 512 // Start observing! | 537 // Start observing! |
| 513 obs.observe(db, txn1); | 538 obs.observe(db, txn1, {operationTypes: ['clear', 'put', 'add', 'delete']}); |
| 514 obs.observe(db, txn2); | 539 obs.observe(db, txn2, {operationTypes: ['clear', 'put', 'add', 'delete']}); |
| 515 | 540 |
| 516 txn1.oncomplete = cb1; | 541 txn1.oncomplete = cb1; |
| 517 txn2.oncomplete = cb2; | 542 txn2.oncomplete = cb2; |
| 518 txn1.onerror = t.unreached_func('transaction should not fail'); | 543 txn1.onerror = t.unreached_func('transaction should not fail'); |
| 519 txn2.onerror = t.unreached_func('transaction should not fail'); | 544 txn2.onerror = t.unreached_func('transaction should not fail'); |
| 520 })); | 545 })); |
| 521 var cb3 = observers_added_barrier(t); | 546 var cb3 = observers_added_barrier(t); |
| 522 openDB(t, db2_name, t.step_func(function(db) { | 547 openDB(t, db2_name, t.step_func(function(db) { |
| 523 connection2 = db; | 548 connection2 = db; |
| 524 var txn = db.transaction(['store3'], 'readonly'); | 549 var txn = db.transaction(['store3'], 'readonly'); |
| 525 obs.observe(db, txn); | 550 obs.observe(db, txn, {operationTypes: ['clear', 'put', 'add', 'delete']}); |
| 526 txn.oncomplete = cb3; | 551 txn.oncomplete = cb3; |
| 527 txn.onerror = t.unreached_func('transaction should not fail'); | 552 txn.onerror = t.unreached_func('transaction should not fail'); |
| 528 })); | 553 })); |
| 529 }, 'IDB Observers: Close connection removes observers'); | 554 }, 'IDB Observers: Close connection removes observers'); |
| 530 | 555 |
| 531 done(); | 556 done(); |
| OLD | NEW |