OLD | NEW |
(Empty) | |
| 1 if (this.importScripts) { |
| 2 importScripts('../../../resources/testharness.js'); |
| 3 importScripts('../../../resources/generic-idb-operations.js'); |
| 4 } |
| 5 |
| 6 async_test(function(t) { |
| 7 var dbname = location.pathname + ' - ' + 'unobserve before tx completes'; |
| 8 var openRequest = indexedDB.open(dbname); |
| 9 var obs = new IDBObserver(t.unreached_func('Observer callback should not be fi
red'), { operationTypes: ['put'] }); |
| 10 |
| 11 openRequest.onupgradeneeded = t.step_func(function() { |
| 12 createObjectStores(openRequest.result, ['store']); |
| 13 }); |
| 14 openRequest.onsuccess = t.step_func(function() { |
| 15 var db = openRequest.result; |
| 16 var tx1 = db.transaction('store'); |
| 17 var tx2 = db.transaction('store', 'readwrite'); |
| 18 tx1.objectStore('store').get(1); |
| 19 tx2.objectStore('store').put(1, 1); |
| 20 obs.observe(db, tx1); |
| 21 |
| 22 tx1.onerror = t.unreached_func('transaction should not fail'); |
| 23 tx2.oncomplete = t.step_func(function() { |
| 24 t.done(); |
| 25 }); |
| 26 tx2.onerror = t.unreached_func('transaction should not fail') |
| 27 obs.unobserve(db); |
| 28 }); |
| 29 openRequest.onerror = t.unreached_func('opening database should not fail'); |
| 30 }, 'Unobserve before associated transaction completes'); |
| 31 |
| 32 async_test(function(t) { |
| 33 var dbname = location.pathname + ' - ' + 'unobserve after tx completes'; |
| 34 var openRequest = indexedDB.open(dbname); |
| 35 var obs = new IDBObserver(t.unreached_func('Observer callback should not be fi
red'), { operationTypes: ['put'] }); |
| 36 |
| 37 openRequest.onupgradeneeded = t.step_func(function() { |
| 38 createObjectStores(openRequest.result, ['store']); |
| 39 }); |
| 40 openRequest.onsuccess = t.step_func(function() { |
| 41 var db = openRequest.result; |
| 42 var tx1 = db.transaction('store'); |
| 43 var tx2 = db.transaction('store', 'readwrite'); |
| 44 tx1.objectStore('store').get(1); |
| 45 tx2.objectStore('store').put(1, 1); |
| 46 obs.observe(db, tx1); |
| 47 |
| 48 tx1.oncomplete = t.step_func(function() { |
| 49 obs.unobserve(db); |
| 50 }); |
| 51 tx1.onerror = t.unreached_func('transaction should not fail'); |
| 52 tx2.oncomplete = t.step_func(function() { |
| 53 t.done(); |
| 54 }); |
| 55 tx2.onerror = t.unreached_func('transaction should not fail'); |
| 56 }); |
| 57 openRequest.onerror = t.unreached_func('opening database should not fail'); |
| 58 }, 'Unobserve after associated transaction completes'); |
| 59 |
| 60 async_test(function(t) { |
| 61 var dbname = location.pathname + ' - ' + 'unobserve multiple observers'; |
| 62 var openRequest = indexedDB.open(dbname); |
| 63 var obs = new IDBObserver(t.unreached_func('Observer callback should not be fi
red'), { operationTypes: ['put'] }); |
| 64 openRequest.onupgradeneeded = t.step_func(function() { |
| 65 createObjectStores(openRequest.result, ['store']); |
| 66 }); |
| 67 openRequest.onsuccess = t.step_func(function() { |
| 68 var db = openRequest.result; |
| 69 var tx1 = db.transaction('store'); |
| 70 var tx2 = db.transaction('store', 'readwrite'); |
| 71 |
| 72 tx2.objectStore('store').put(1, 1); |
| 73 obs.observe(db, tx1); |
| 74 obs.observe(db, tx1); // Multiple observe calls registered. |
| 75 obs.observe(db, tx2); // Multiple observe calls registered. |
| 76 obs.unobserve(db); |
| 77 |
| 78 tx1.onerror = t.unreached_func('transaction should not fail'); |
| 79 tx2.onerror = t.unreached_func('transaction should not fail'); |
| 80 tx2.oncomplete = t.step_func(function() { |
| 81 t.done(); |
| 82 }) |
| 83 }); |
| 84 openRequest.onerror = t.unreached_func('opening database should not fail'); |
| 85 }, 'Unobserve multiple observe calls on same database'); |
| 86 |
| 87 async_test(function(t) { |
| 88 var dbname = location.pathname + ' - ' + 'unobserve non existant observers'; |
| 89 var openRequest = indexedDB.open(dbname); |
| 90 var obs = new IDBObserver(t.unreached_func('Observer callback should not be fi
red'), { operationTypes: ['put'] }); |
| 91 openRequest.onupgradeneeded = t.step_func(function() { |
| 92 createObjectStores(openRequest.result, ['store']); |
| 93 }); |
| 94 openRequest.onsuccess = t.step_func(function() { |
| 95 var db = openRequest.result; |
| 96 obs.unobserve(db); |
| 97 t.done(); |
| 98 }); |
| 99 openRequest.onerror = t.unreached_func('opening database should not fail'); |
| 100 }, 'Unobserve non existant observer'); |
| 101 |
| 102 async_test(function(t) { |
| 103 var dbname = location.pathname + ' - ' + 'connection close'; |
| 104 var cnt1 = 0, cnt2 = 0; |
| 105 var openRequest1 = indexedDB.open(dbname); |
| 106 var obs1 = new IDBObserver(t.step_func(function() { cnt1++; }), { operationTyp
es: ['put'] }); |
| 107 var obs2 = new IDBObserver(t.step_func(function() { cnt2++; }), { operationTyp
es: ['put'] }); |
| 108 |
| 109 openRequest1.onupgradeneeded = t.step_func(function() { |
| 110 createObjectStores(openRequest1.result, ['store']); |
| 111 }); |
| 112 openRequest1.onsuccess = t.step_func(function() { |
| 113 var db1 = openRequest1.result; |
| 114 var tx1 = db1.transaction('store', 'readwrite'); |
| 115 var tx2 = db1.transaction('store', 'readwrite'); |
| 116 tx1.objectStore('store').get(1); |
| 117 tx2.objectStore('store').put(1, 1); |
| 118 obs1.observe(db1, tx1); |
| 119 obs2.observe(db1, tx2); |
| 120 |
| 121 tx1.oncomplete = t.step_func(function() { |
| 122 countCallbacks(cnt1, 0); |
| 123 countCallbacks(cnt2, 0); |
| 124 }) |
| 125 tx2.oncomplete = t.step_func(function() { |
| 126 countCallbacks(cnt1, 1); |
| 127 countCallbacks(cnt2, 0); |
| 128 |
| 129 db1.close(); |
| 130 var openRequest2 = indexedDB.open(dbname); |
| 131 openRequest2.onsuccess = t.step_func(function() { |
| 132 var db2 = openRequest2.result; |
| 133 var tx3 = db2.transaction('store', 'readwrite'); |
| 134 tx3.objectStore('store').put(1, 1); |
| 135 tx3.oncomplete = t.step_func(function() { |
| 136 countCallbacks(cnt1, 1); |
| 137 countCallbacks(cnt2, 0); |
| 138 t.done(); |
| 139 }); |
| 140 tx3.onerror = t.unreached_func('transaction should not fail'); |
| 141 }); |
| 142 openRequest2.onerror = t.unreached_func('opening database should not fail'
); |
| 143 }); |
| 144 tx1.onerror = t.unreached_func('transaction should not fail'); |
| 145 tx2.onerror = t.unreached_func('transaction should not fail'); |
| 146 }); |
| 147 openRequest1.onerror = t.unreached_func('opening database should not fail'); |
| 148 }, 'Remove observers on database close'); |
| 149 |
| 150 done(); |
OLD | NEW |