Chromium Code Reviews| Index: third_party/WebKit/LayoutTests/storage/indexeddb/resources/observer-removal.js |
| diff --git a/third_party/WebKit/LayoutTests/storage/indexeddb/resources/observer-removal.js b/third_party/WebKit/LayoutTests/storage/indexeddb/resources/observer-removal.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..fc8883ebdd3ca5fb54e5fa14a71d9c39c4262985 |
| --- /dev/null |
| +++ b/third_party/WebKit/LayoutTests/storage/indexeddb/resources/observer-removal.js |
| @@ -0,0 +1,144 @@ |
| +if (this.importScripts) { |
| + importScripts('../../../resources/testharness.js'); |
| + importScripts('../../../resources/generic-idb-operations.js'); |
| +} |
| + |
| +async_test(function(t) { |
| + var dbname = location.pathname + ' - ' + 'unobserve before tx completes'; |
| + var openRequest = indexedDB.open(dbname); |
| + var obs = new IDBObserver(t.unreached_func('Observer callback should not be fired'), { operationTypes: ['put'] }); |
| + |
| + openRequest.onupgradeneeded = t.step_func(function() { |
| + createDatabase(openRequest.result, ['store']); |
| + }); |
| + openRequest.onsuccess = t.step_func(function() { |
|
cmumford
2016/07/21 15:00:56
Add onerror.
|
| + var db = openRequest.result; |
| + var tx1 = db.transaction('store'); |
| + var tx2 = db.transaction('store', 'readwrite'); |
| + tx1.objectStore('store').get(1); |
| + tx2.objectStore('store').put(1, 1); |
| + obs.observe(db, tx1); |
| + |
| + tx1.onerror = t.unreached_func('transaction should not fail'); |
| + tx2.oncomplete = t.step_func(function() { |
| + t.done(); |
| + }); |
| + tx2.onerror = t.unreached_func('transaction should not fail') |
| + obs.unobserve(db); |
| + }); |
| +}, 'Unobserve before associated transaction completes'); |
| + |
| +async_test(function(t) { |
| + var dbname = location.pathname + ' - ' + 'unobserve after tx completes'; |
| + var openRequest = indexedDB.open(dbname); |
| + var obs = new IDBObserver(t.unreached_func('Observer callback should not be fired'), { operationTypes: ['put'] }); |
| + |
| + openRequest.onupgradeneeded = t.step_func(function() { |
| + createDatabase(openRequest.result, ['store']); |
| + }); |
| + openRequest.onsuccess = t.step_func(function() { |
| + var db = openRequest.result; |
| + var tx1 = db.transaction('store'); |
| + var tx2 = db.transaction('store', 'readwrite'); |
| + tx1.objectStore('store').get(1); |
| + tx2.objectStore('store').put(1, 1); |
| + obs.observe(db, tx1); |
| + |
| + tx1.oncomplete = t.step_func(function() { |
| + obs.unobserve(db); |
| + }); |
| + tx1.onerror = t.unreached_func('transaction should not fail'); |
| + tx2.oncomplete = t.step_func(function() { |
| + t.done(); |
| + }); |
| + tx2.onerror = t.unreached_func('transaction should not fail'); |
| + }); |
| +}, 'Unobserve after associated transaction completes'); |
| + |
| +async_test(function(t) { |
| + var dbname = location.pathname + ' - ' + 'unobserve multiple observers'; |
| + var openRequest = indexedDB.open(dbname); |
| + var obs = new IDBObserver(t.unreached_func('Observer callback should not be fired'), { operationTypes: ['put'] }); |
| + openRequest.onupgradeneeded = t.step_func(function() { |
| + createDatabase(openRequest.result, ['store']); |
| + }); |
| + openRequest.onsuccess = t.step_func(function() { |
| + var db = openRequest.result; |
| + var tx1 = db.transaction('store'); |
| + var tx2 = db.transaction('store', 'readwrite'); |
| + |
| + tx2.objectStore('store').put(1, 1); |
| + obs.observe(db, tx1); |
| + obs.observe(db, tx1); // Multiple observe calls registered. |
| + obs.observe(db, tx2); // Multiple observe calls registered. |
| + obs.unobserve(db); |
| + |
| + tx1.onerror = t.unreached_func('transaction should not fail'); |
| + tx2.onerror = t.unreached_func('transaction should not fail'); |
| + tx2.oncomplete = t.step_func(function() { |
| + t.done(); |
| + }) |
| + }); |
| +}, 'Unobserve multiple observe calls on same database'); |
| + |
| +async_test(function(t) { |
| + var dbname = location.pathname + ' - ' + 'unobserve non existant observers'; |
| + var openRequest = indexedDB.open(dbname); |
| + var obs = new IDBObserver(t.unreached_func('Observer callback should not be fired'), { operationTypes: ['put'] }); |
| + openRequest.onupgradeneeded = t.step_func(function() { |
| + createDatabase(openRequest.result, ['store']); |
| + }); |
| + openRequest.onsuccess = t.step_func(function() { |
| + var db = openRequest.result; |
| + obs.unobserve(db); |
| + t.done(); |
| + }); |
| +}, 'Unobserve non existant observer'); |
| + |
| +async_test(function(t) { |
| + var dbname = location.pathname + ' - ' + 'connection close'; |
| + var cnt1 = 0, cnt2 = 0; |
| + var openRequest1 = indexedDB.open(dbname); |
| + var obs1 = new IDBObserver(t.step_func(function() { cnt1++; }), { operationTypes: ['put'] }); |
| + var obs2 = new IDBObserver(t.step_func(function() { cnt2++; }), { operationTypes: ['put'] }); |
| + |
| + openRequest1.onupgradeneeded = t.step_func(function() { |
| + createDatabase(openRequest1.result, ['store']); |
| + }); |
| + openRequest1.onsuccess = t.step_func(function() { |
| + var db1 = openRequest1.result; |
| + var tx1 = db1.transaction('store', 'readwrite'); |
| + var tx2 = db1.transaction('store', 'readwrite'); |
| + tx1.objectStore('store').get(1); |
| + tx2.objectStore('store').put(1, 1); |
| + obs1.observe(db1, tx1); |
| + obs2.observe(db1, tx2); |
| + |
| + tx1.oncomplete = t.step_func(function() { |
| + countCallbacks(cnt1, 0); |
| + countCallbacks(cnt2, 0); |
| + }) |
| + tx2.oncomplete = t.step_func(function() { |
| + countCallbacks(cnt1, 1); |
| + countCallbacks(cnt2, 0); |
| + |
| + db1.close(); |
| + var openRequest2 = indexedDB.open(dbname); |
| + openRequest2.onsuccess = t.step_func(function() { |
| + var db2 = openRequest2.result; |
| + var tx3 = db2.transaction('store', 'readwrite'); |
| + tx3.objectStore('store').put(1, 1); |
| + tx3.oncomplete = t.step_func(function() { |
| + countCallbacks(cnt1, 1); |
| + countCallbacks(cnt2, 0); |
| + t.done(); |
| + }); |
| + tx3.onerror = t.unreached_func('transaction should not fail'); |
| + }); |
| + }); |
| + tx1.onerror = t.unreached_func('transaction should not fail'); |
| + tx2.onerror = t.unreached_func('transaction should not fail'); |
| + }); |
| +}, 'Remove observers on database close'); |
| + |
| +done(); |