| 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']}); |
| 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 assert_less_than_equal(changeNumber, 1, "incorrect pendingObserves"); |
| 240 }; |
| 241 |
| 242 var obs = new IDBObserver(t.step_func(observeFunction)); |
| 243 |
| 244 openDB(t, db1_name, t.step_func(function(db) { |
| 245 connection = db; |
| 246 var txn = db.transaction(['store1', 'store2'], 'readonly'); |
| 247 obs.observe(db, txn, {operationTypes: ['put']}); |
| 248 obs.observe(db, txn, {operationTypes: ['add']}); |
| 249 txn.oncomplete = observers_added_callback; |
| 250 txn.onerror = t.unreached_func('transaction should not fail'); |
| 251 })); |
| 252 }, 'IDB Observers: Multiple observer calls with filtering'); |
| 253 |
| 254 indexeddb_observers_test(function(t, db1_name, db2_name, observers_added_callbac
k) { |
| 224 var partOneChanges1 = { | 255 var partOneChanges1 = { |
| 225 dbName: db1_name, | 256 dbName: db1_name, |
| 226 records: { | 257 records: { |
| 227 'store1': [{type: 'delete', key: {lower: 'a', upper: 'b'}}, | 258 'store1': [{type: 'delete', key: {lower: 'a', upper: 'b'}}, |
| 228 {type: 'put', key: 'a'}] | 259 {type: 'put', key: 'a'}] |
| 229 } | 260 } |
| 230 }; | 261 }; |
| 231 | 262 |
| 232 var partOneChanges2 = { | 263 var partOneChanges2 = { |
| 233 dbName: db1_name, | 264 dbName: db1_name, |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 } else { | 308 } else { |
| 278 assert_unreached('Unknown connection supplied with changes.'); | 309 assert_unreached('Unknown connection supplied with changes.'); |
| 279 } | 310 } |
| 280 if (pendingObserves === 0) { | 311 if (pendingObserves === 0) { |
| 281 t.done(); | 312 t.done(); |
| 282 } else if (pendingObserves < 0) { | 313 } else if (pendingObserves < 0) { |
| 283 assert_unreached("incorrect pendingObserves"); | 314 assert_unreached("incorrect pendingObserves"); |
| 284 } | 315 } |
| 285 }; | 316 }; |
| 286 | 317 |
| 287 var obs = new IDBObserver( | 318 var obs = new IDBObserver(t.step_func(observeFunction)); |
| 288 t.step_func(observeFunction), | |
| 289 { operationTypes: ['clear', 'put', 'add', 'delete'] }); | |
| 290 | 319 |
| 291 var cb1 = observers_added_barrier(t); | 320 var cb1 = observers_added_barrier(t); |
| 292 openDB(t, db1_name, t.step_func(function(db) { | 321 openDB(t, db1_name, t.step_func(function(db) { |
| 293 connection1 = db; | 322 connection1 = db; |
| 294 var txn = db.transaction(['store1'], 'readonly'); | 323 var txn = db.transaction(['store1'], 'readonly'); |
| 295 obs.observe(db, txn); | 324 obs.observe(db, txn, {operationTypes: ['clear', 'put', 'add', 'delete']}); |
| 296 txn.oncomplete = cb1; | 325 txn.oncomplete = cb1; |
| 297 txn.onerror = t.unreached_func('transaction should not fail'); | 326 txn.onerror = t.unreached_func('transaction should not fail'); |
| 298 })); | 327 })); |
| 299 var cb2 = observers_added_barrier(t); | 328 var cb2 = observers_added_barrier(t); |
| 300 openDB(t, db1_name, t.step_func(function(db) { | 329 openDB(t, db1_name, t.step_func(function(db) { |
| 301 connection2 = db; | 330 connection2 = db; |
| 302 var txn = db.transaction(['store2'], 'readonly'); | 331 var txn = db.transaction(['store2'], 'readonly'); |
| 303 obs.observe(db, txn); | 332 obs.observe(db, txn, {operationTypes: ['clear', 'put', 'add', 'delete']}); |
| 304 txn.oncomplete = cb2; | 333 txn.oncomplete = cb2; |
| 305 txn.onerror = t.unreached_func('transaction should not fail'); | 334 txn.onerror = t.unreached_func('transaction should not fail'); |
| 306 })); | 335 })); |
| 307 var cb3 = observers_added_barrier(t); | 336 var cb3 = observers_added_barrier(t); |
| 308 openDB(t, db2_name, t.step_func(function(db) { | 337 openDB(t, db2_name, t.step_func(function(db) { |
| 309 connection3 = db; | 338 connection3 = db; |
| 310 var txn = db.transaction(['store3', 'store4'], 'readonly'); | 339 var txn = db.transaction(['store3', 'store4'], 'readonly'); |
| 311 obs.observe(db, txn); | 340 obs.observe(db, txn, {operationTypes: ['clear', 'put', 'add', 'delete']}); |
| 312 txn.oncomplete = cb3; | 341 txn.oncomplete = cb3; |
| 313 txn.onerror = t.unreached_func('transaction should not fail') | 342 txn.onerror = t.unreached_func('transaction should not fail') |
| 314 })); | 343 })); |
| 315 }, 'IDB Observers: Three connections, unobserve two'); | 344 }, 'IDB Observers: Three connections, unobserve two'); |
| 316 | 345 |
| 317 indexeddb_observers_test(function(t, db1_name, db2_name, observers_added_callbac
k) { | 346 indexeddb_observers_test(function(t, db1_name, db2_name, observers_added_callbac
k) { |
| 318 var connection1 = null; | 347 var connection1 = null; |
| 319 var connection2 = null; | 348 var connection2 = null; |
| 320 | 349 |
| 321 var observeFunction = function(changes) { | 350 var observeFunction = function(changes) { |
| 322 assert_equals(changes.database, connection2); | 351 assert_equals(changes.database, connection2); |
| 323 obs.unobserve(connection2); | 352 obs.unobserve(connection2); |
| 324 t.done(); | 353 t.done(); |
| 325 }; | 354 }; |
| 326 | 355 |
| 327 var obs = new IDBObserver( | 356 var obs = new IDBObserver(t.step_func(observeFunction)); |
| 328 t.step_func(observeFunction), | |
| 329 { operationTypes: ['clear', 'put', 'add', 'delete'] }); | |
| 330 | 357 |
| 331 openDB(t, db1_name, t.step_func(function(db) { | 358 openDB(t, db1_name, t.step_func(function(db) { |
| 332 connection1 = db; | 359 connection1 = db; |
| 333 var txn = db.transaction(['store1'], 'readonly'); | 360 var txn = db.transaction(['store1'], 'readonly'); |
| 334 obs.observe(db, txn); | 361 obs.observe(db, txn, {operationTypes: ['clear', 'put', 'add', 'delete']}); |
| 335 obs.unobserve(db); | 362 obs.unobserve(db); |
| 336 txn.oncomplete = t.step_func(function() { | 363 txn.oncomplete = t.step_func(function() { |
| 337 openDB(t, db1_name, t.step_func(function(db) { | 364 openDB(t, db1_name, t.step_func(function(db) { |
| 338 connection2 = db; | 365 connection2 = db; |
| 339 var txn = db.transaction(['store2'], 'readonly'); | 366 var txn = db.transaction(['store2'], 'readonly'); |
| 340 obs.observe(db, txn); | 367 obs.observe( |
| 368 db, txn, {operationTypes: ['clear', 'put', 'add', 'delete']}); |
| 341 txn.oncomplete = observers_added_callback; | 369 txn.oncomplete = observers_added_callback; |
| 342 txn.onerror = t.unreached_func('transaction should not fail'); | 370 txn.onerror = t.unreached_func('transaction should not fail'); |
| 343 })); | 371 })); |
| 344 }); | 372 }); |
| 345 txn.onerror = t.unreached_func('transaction should not fail'); | 373 txn.onerror = t.unreached_func('transaction should not fail'); |
| 346 })); | 374 })); |
| 347 }, 'IDB Observers: Unobserve immediately'); | 375 }, 'IDB Observers: Unobserve immediately'); |
| 348 | 376 |
| 349 indexeddb_observers_test(function(t, db1_name, db2_name, observers_added_callbac
k) { | 377 indexeddb_observers_test(function(t, db1_name, db2_name, observers_added_callbac
k) { |
| 350 var connection1 = null; | 378 var connection1 = null; |
| 351 var connection2 = null; | 379 var connection2 = null; |
| 352 | 380 |
| 353 var observeFunction = function(changes) { | 381 var observeFunction = function(changes) { |
| 354 assert_equals(changes.database, connection2); | 382 assert_equals(changes.database, connection2); |
| 355 obs.unobserve(connection2); | 383 obs.unobserve(connection2); |
| 356 t.done(); | 384 t.done(); |
| 357 }; | 385 }; |
| 358 | 386 |
| 359 var obs = new IDBObserver( | 387 var obs = new IDBObserver(t.step_func(observeFunction)); |
| 360 t.step_func(observeFunction), | |
| 361 { operationTypes: ['clear', 'put', 'add', 'delete'] }); | |
| 362 | 388 |
| 363 openDB(t, db1_name, t.step_func(function(db) { | 389 openDB(t, db1_name, t.step_func(function(db) { |
| 364 connection1 = db; | 390 connection1 = db; |
| 365 var txn = db.transaction(['store1'], 'readonly'); | 391 var txn = db.transaction(['store1'], 'readonly'); |
| 366 obs.observe(db, txn); | 392 obs.observe(db, txn, {operationTypes: ['clear', 'put', 'add', 'delete']}); |
| 367 obs.observe(db, txn); | 393 obs.observe(db, txn, {operationTypes: ['clear', 'put', 'add', 'delete']}); |
| 368 obs.observe(db, txn); | 394 obs.observe(db, txn, {operationTypes: ['clear', 'put', 'add', 'delete']}); |
| 369 obs.unobserve(db); | 395 obs.unobserve(db); |
| 370 txn.oncomplete = t.step_func(function() { | 396 txn.oncomplete = t.step_func(function() { |
| 371 openDB(t, db1_name, t.step_func(function(db) { | 397 openDB(t, db1_name, t.step_func(function(db) { |
| 372 connection2 = db; | 398 connection2 = db; |
| 373 var txn = db.transaction(['store2'], 'readonly'); | 399 var txn = db.transaction(['store2'], 'readonly'); |
| 374 obs.observe(db, txn); | 400 obs.observe( |
| 401 db, txn, {operationTypes: ['clear', 'put', 'add', 'delete']}); |
| 375 txn.oncomplete = observers_added_callback; | 402 txn.oncomplete = observers_added_callback; |
| 376 txn.onerror = t.unreached_func('transaction should not fail'); | 403 txn.onerror = t.unreached_func('transaction should not fail'); |
| 377 })); | 404 })); |
| 378 }); | 405 }); |
| 379 txn.onerror = t.unreached_func('transaction should not fail'); | 406 txn.onerror = t.unreached_func('transaction should not fail'); |
| 380 })); | 407 })); |
| 381 }, 'IDB Observers: Unobserve immediately on multiple'); | 408 }, 'IDB Observers: Unobserve immediately on multiple'); |
| 382 | 409 |
| 383 indexeddb_observers_test(function(t, db1_name, db2_name, observers_added_callbac
k) { | 410 indexeddb_observers_test(function(t, db1_name, db2_name, observers_added_callbac
k) { |
| 384 var expectedChanges1 = { | 411 var expectedChanges1 = { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 } else if (changes.database === connection2) { | 445 } else if (changes.database === connection2) { |
| 419 connection2Observes = connection2Observes + 1; | 446 connection2Observes = connection2Observes + 1; |
| 420 if (connection2Observes > 1) { | 447 if (connection2Observes > 1) { |
| 421 t.done(); | 448 t.done(); |
| 422 } | 449 } |
| 423 } else { | 450 } else { |
| 424 assert_unreached("unknown changes"); | 451 assert_unreached("unknown changes"); |
| 425 } | 452 } |
| 426 }; | 453 }; |
| 427 | 454 |
| 428 var obs = new IDBObserver( | 455 var obs = new IDBObserver(t.step_func(observeFunction)); |
| 429 t.step_func(observeFunction), | |
| 430 { operationTypes: ['clear', 'put', 'add', 'delete'] }); | |
| 431 | 456 |
| 432 var cb1 = observers_added_barrier(t); | 457 var cb1 = observers_added_barrier(t); |
| 433 var cb2 = observers_added_barrier(t); | 458 var cb2 = observers_added_barrier(t); |
| 434 openDB(t, db1_name, t.step_func(function(db) { | 459 openDB(t, db1_name, t.step_func(function(db) { |
| 435 connection1 = db; | 460 connection1 = db; |
| 436 var txn1 = db.transaction(['store1'], 'readonly'); | 461 var txn1 = db.transaction(['store1'], 'readonly'); |
| 437 var txn2 = db.transaction(['store2'], 'readonly'); | 462 var txn2 = db.transaction(['store2'], 'readonly'); |
| 438 // Start observing! | 463 // Start observing! |
| 439 obs.observe(db, txn1); | 464 obs.observe(db, txn1, {operationTypes: ['clear', 'put', 'add', 'delete']}); |
| 440 obs.observe(db, txn2); | 465 obs.observe(db, txn2, {operationTypes: ['clear', 'put', 'add', 'delete']}); |
| 441 | 466 |
| 442 txn1.oncomplete = cb1; | 467 txn1.oncomplete = cb1; |
| 443 txn2.oncomplete = cb2; | 468 txn2.oncomplete = cb2; |
| 444 txn1.onerror = t.unreached_func('transaction should not fail'); | 469 txn1.onerror = t.unreached_func('transaction should not fail'); |
| 445 txn2.onerror = t.unreached_func('transaction should not fail'); | 470 txn2.onerror = t.unreached_func('transaction should not fail'); |
| 446 })); | 471 })); |
| 447 var cb3 = observers_added_barrier(t); | 472 var cb3 = observers_added_barrier(t); |
| 448 openDB(t, db2_name, t.step_func(function(db) { | 473 openDB(t, db2_name, t.step_func(function(db) { |
| 449 connection2 = db; | 474 connection2 = db; |
| 450 var txn = db.transaction(['store3'], 'readonly'); | 475 var txn = db.transaction(['store3'], 'readonly'); |
| 451 obs.observe(db, txn); | 476 obs.observe(db, txn, {operationTypes: ['clear', 'put', 'add', 'delete']}); |
| 452 txn.oncomplete = cb3; | 477 txn.oncomplete = cb3; |
| 453 txn.onerror = t.unreached_func('transaction should not fail'); | 478 txn.onerror = t.unreached_func('transaction should not fail'); |
| 454 })); | 479 })); |
| 455 }, 'IDB Observers: Unobserve connection removes observers'); | 480 }, 'IDB Observers: Unobserve connection removes observers'); |
| 456 | 481 |
| 457 indexeddb_observers_test(function(t, db1_name, db2_name, observers_added_callbac
k) { | 482 indexeddb_observers_test(function(t, db1_name, db2_name, observers_added_callbac
k) { |
| 458 var expectedChanges1 = { | 483 var expectedChanges1 = { |
| 459 dbName: db1_name, | 484 dbName: db1_name, |
| 460 records: { | 485 records: { |
| 461 'store1': [{type: 'delete', key: {lower: 'a', upper: 'b'}}, | 486 'store1': [{type: 'delete', key: {lower: 'a', upper: 'b'}}, |
| (...skipping 30 matching lines...) Expand all Loading... |
| 492 } else if (changes.database === connection2) { | 517 } else if (changes.database === connection2) { |
| 493 connection2Observes = connection2Observes + 1; | 518 connection2Observes = connection2Observes + 1; |
| 494 if (connection2Observes > 1) { | 519 if (connection2Observes > 1) { |
| 495 t.done(); | 520 t.done(); |
| 496 } | 521 } |
| 497 } else { | 522 } else { |
| 498 assert_unreached("unknown changes"); | 523 assert_unreached("unknown changes"); |
| 499 } | 524 } |
| 500 }; | 525 }; |
| 501 | 526 |
| 502 var obs = new IDBObserver( | 527 var obs = new IDBObserver(t.step_func(observeFunction)); |
| 503 t.step_func(observeFunction), | |
| 504 { operationTypes: ['clear', 'put', 'add', 'delete'] }); | |
| 505 | 528 |
| 506 var cb1 = observers_added_barrier(t); | 529 var cb1 = observers_added_barrier(t); |
| 507 var cb2 = observers_added_barrier(t); | 530 var cb2 = observers_added_barrier(t); |
| 508 openDB(t, db1_name, t.step_func(function(db) { | 531 openDB(t, db1_name, t.step_func(function(db) { |
| 509 connection1 = db; | 532 connection1 = db; |
| 510 var txn1 = db.transaction(['store1'], 'readonly'); | 533 var txn1 = db.transaction(['store1'], 'readonly'); |
| 511 var txn2 = db.transaction(['store2'], 'readonly'); | 534 var txn2 = db.transaction(['store2'], 'readonly'); |
| 512 // Start observing! | 535 // Start observing! |
| 513 obs.observe(db, txn1); | 536 obs.observe(db, txn1, {operationTypes: ['clear', 'put', 'add', 'delete']}); |
| 514 obs.observe(db, txn2); | 537 obs.observe(db, txn2, {operationTypes: ['clear', 'put', 'add', 'delete']}); |
| 515 | 538 |
| 516 txn1.oncomplete = cb1; | 539 txn1.oncomplete = cb1; |
| 517 txn2.oncomplete = cb2; | 540 txn2.oncomplete = cb2; |
| 518 txn1.onerror = t.unreached_func('transaction should not fail'); | 541 txn1.onerror = t.unreached_func('transaction should not fail'); |
| 519 txn2.onerror = t.unreached_func('transaction should not fail'); | 542 txn2.onerror = t.unreached_func('transaction should not fail'); |
| 520 })); | 543 })); |
| 521 var cb3 = observers_added_barrier(t); | 544 var cb3 = observers_added_barrier(t); |
| 522 openDB(t, db2_name, t.step_func(function(db) { | 545 openDB(t, db2_name, t.step_func(function(db) { |
| 523 connection2 = db; | 546 connection2 = db; |
| 524 var txn = db.transaction(['store3'], 'readonly'); | 547 var txn = db.transaction(['store3'], 'readonly'); |
| 525 obs.observe(db, txn); | 548 obs.observe(db, txn, {operationTypes: ['clear', 'put', 'add', 'delete']}); |
| 526 txn.oncomplete = cb3; | 549 txn.oncomplete = cb3; |
| 527 txn.onerror = t.unreached_func('transaction should not fail'); | 550 txn.onerror = t.unreached_func('transaction should not fail'); |
| 528 })); | 551 })); |
| 529 }, 'IDB Observers: Close connection removes observers'); | 552 }, 'IDB Observers: Close connection removes observers'); |
| 530 | 553 |
| 531 done(); | 554 done(); |
| OLD | NEW |