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 } | 4 } |
| 4 | 5 |
| 5 function callback(){}; | 6 async_test(function(t) { |
| 7 var dbname = location.pathname + ' - ' + 'empty transaction'; | |
| 8 var openRequest = indexedDB.open(dbname); | |
| 9 var callback_count = 0; | |
| 10 var obs = new IDBObserver(t.step_func(function() { callback_count++; }), {oper ationTypes: ['put']}); | |
| 11 | |
| 12 openRequest.onupgradeneeded = t.step_func(function() { | |
| 13 createDatabase(openRequest.result, ['store']); | |
| 14 }); | |
| 15 openRequest.onsuccess = t.step_func(function() { | |
| 16 var db = openRequest.result; | |
| 17 var tx1 = db.transaction('store', 'readwrite'); | |
| 18 var tx2 = db.transaction('store', 'readwrite'); | |
|
cmumford
2016/07/20 00:25:12
Should probably also have:
tx1.onerror = t.unre
palakj1
2016/07/20 01:33:36
thanks for pointing this out.
| |
| 19 obs.observe(db, tx1); | |
| 20 tx2.objectStore('store').put(1,1); | |
|
cmumford
2016/07/20 00:25:12
Nit: space before second param.
palakj1
2016/07/20 01:33:36
done
| |
| 21 tx1.oncomplete = t.step_func(function() { | |
| 22 countCallbacks(callback_count, 0); | |
| 23 }); | |
| 24 tx2.oncomplete = t.step_func(function() { | |
| 25 countCallbacks(callback_count, 1); | |
| 26 t.done(); | |
| 27 }); | |
| 28 }); | |
| 29 }, 'Registering observe call with empty transaction'); | |
| 6 | 30 |
| 7 async_test(function(t) { | 31 async_test(function(t) { |
| 8 var description = 'observer addition and removal test'; | 32 var dbname = location.pathname + ' - ' + 'observer in version change'; |
| 9 var dbname = location.pathname + ' - ' + description; | |
| 10 var openRequest = indexedDB.open(dbname); | 33 var openRequest = indexedDB.open(dbname); |
| 11 var obs1 = new IDBObserver(callback, {transaction: true, values: true}); | 34 var callback_count = 0; |
| 12 var obs2 = new IDBObserver(callback, {transaction: true, values: true}); | 35 var obs; |
| 36 openRequest.onupgradeneeded = t.step_func(function() { | |
| 37 createDatabase(openRequest.result, ['store']); | |
| 38 obs = new IDBObserver(t.step_func(function() { callback_count++; }), { ope rationTypes: ['put'] }); | |
| 39 }); | |
| 40 openRequest.onsuccess = t.step_func(function() { | |
| 41 var db = openRequest.result; | |
| 42 var tx1 = db.transaction('store', 'readwrite'); | |
| 43 var tx2 = db.transaction('store', 'readwrite'); | |
| 44 tx1.objectStore('store').get(1); | |
| 45 tx2.objectStore('store').put(1,1); | |
|
cmumford
2016/07/20 00:25:12
space.
palakj1
2016/07/20 01:33:36
done
| |
| 46 obs.observe(db, tx1); | |
| 47 tx1.oncomplete = t.step_func(function() { | |
| 48 countCallbacks(callback_count, 0); | |
| 49 }); | |
| 50 tx2.oncomplete = t.step_func(function() { | |
| 51 countCallbacks(callback_count, 1); | |
| 52 t.done(); | |
| 53 }); | |
| 54 }); | |
| 55 }, 'Create IDBObserver during version change'); | |
| 13 | 56 |
| 57 async_test(function(t) { | |
| 58 var dbname = location.pathname + ' - ' + 'ignore observe call'; | |
| 59 var openRequest = indexedDB.open(dbname); | |
| 60 var callback_count = 0; | |
| 61 var obs = new IDBObserver(t.step_func(function() { callback_count++; }), { ope rationTypes: ['put'] }); | |
| 14 openRequest.onupgradeneeded = t.step_func(function() { | 62 openRequest.onupgradeneeded = t.step_func(function() { |
| 15 var db = openRequest.result; | 63 var db = openRequest.result; |
| 16 db.createObjectStore('store'); | 64 db.createObjectStore('store'); |
| 65 obs.observe(db, openRequest.transaction); | |
| 17 }); | 66 }); |
| 18 openRequest.onsuccess = t.step_func(function() { | 67 openRequest.onsuccess = t.step_func(function() { |
| 19 var db = openRequest.result; | 68 var db = openRequest.result; |
| 20 var tx = db.transaction('store', 'readwrite'); | 69 var tx = db.transaction('store', 'readwrite'); |
| 21 var store = tx.objectStore('store'); | 70 tx.objectStore('store').put(1,1); |
| 22 var put_request = store.put(1,1); | 71 tx.oncomplete = t.step_func(function() { |
| 23 obs1.observe(db, tx); | 72 countCallbacks(callback_count, 0); |
| 24 obs1.unobserve(db); | 73 t.done(); |
| 25 obs1.observe(db, tx); | 74 }); |
| 26 obs2.observe(db, tx); | 75 }); |
| 27 tx.oncomplete = t.step_func(function(){ | 76 }, 'Observe call during version change ignored'); |
| 28 obs1.unobserve(db); | |
| 29 t.done(); | |
| 30 }); | |
| 31 }); | |
| 32 }, 'observer addition and removal test'); | |
| 33 | 77 |
| 34 done(); | 78 async_test(function(t) { |
| 79 var dbname = location.pathname + ' - ' + 'abort associated transaction'; | |
| 80 var openRequest = indexedDB.open(dbname); | |
| 81 var callback_count = 0; | |
| 82 var obs = new IDBObserver(t.step_func(function() { callback_count++; }), { ope rationTypes: ['put'] }); | |
| 83 openRequest.onupgradeneeded = t.step_func(function() { | |
| 84 createDatabase(openRequest.result, ['store']); | |
| 85 }); | |
| 86 openRequest.onsuccess = t.step_func(function() { | |
| 87 var db = openRequest.result; | |
| 88 var tx1 = db.transaction('store', 'readwrite'); | |
| 89 var tx2 = db.transaction('store', 'readwrite'); | |
| 90 tx1.objectStore('store').get(1); | |
| 91 tx2.objectStore('store').put(1,1); | |
| 92 obs.observe(db, tx1); | |
| 93 tx1.abort(); | |
| 94 tx1.oncomplete = t.step_func(function() { | |
| 95 countCallbacks(callback_count, 0); | |
| 96 }); | |
| 97 tx2.oncomplete = t.step_func(function() { | |
| 98 countCallbacks(callback_count, 0); | |
| 99 t.done(); | |
| 100 }); | |
| 101 }); | |
| 102 }, 'Abort transaction associated with observer'); | |
| 35 | 103 |
| 104 async_test(function(t) { | |
| 105 var dbname = location.pathname + ' - ' + 'abort transaction'; | |
| 106 var openRequest = indexedDB.open(dbname); | |
| 107 var callback_count = 0; | |
| 108 var obs = new IDBObserver(t.step_func(function() { callback_count++; }), { ope rationTypes: ['put'] }); | |
| 109 openRequest.onupgradeneeded = t.step_func(function() { | |
| 110 createDatabase(openRequest.result, ['store']); | |
| 111 }); | |
| 112 openRequest.onsuccess = t.step_func(function() { | |
| 113 var db = openRequest.result; | |
| 114 var tx1 = db.transaction('store', 'readwrite'); | |
| 115 var tx2 = db.transaction('store', 'readwrite'); | |
| 116 var tx3 = db.transaction('store', 'readwrite'); | |
| 117 tx1.objectStore('store').get(1); | |
| 118 tx2.objectStore('store').put(1,1); | |
| 119 tx3.objectStore('store').put(1,1); | |
| 120 obs.observe(db, tx1); | |
| 121 tx2.abort(); | |
| 122 tx1.oncomplete = t.step_func(function() { | |
| 123 countCallbacks(callback_count, 0); | |
| 124 }); | |
| 125 tx2.oncomplete = t.unreached_func('transaction should not complete'); | |
| 126 tx2.onabort = t.step_func(function() { | |
| 127 countCallbacks(callback_count, 0); | |
| 128 }); | |
| 129 tx3.oncomplete = t.step_func(function() { | |
| 130 countCallbacks(callback_count, 1); | |
| 131 t.done(); | |
| 132 }); | |
| 133 }); | |
| 134 }, 'Abort transaction observer is recording'); | |
|
cmumford
2016/07/20 00:25:12
Nit: slightly odd title.
palakj1
2016/07/20 01:33:36
changed
| |
| 135 | |
| 136 done(); | |
| OLD | NEW |