Index: third_party/WebKit/LayoutTests/storage/indexeddb/resources/observer.js |
diff --git a/third_party/WebKit/LayoutTests/storage/indexeddb/resources/observer.js b/third_party/WebKit/LayoutTests/storage/indexeddb/resources/observer.js |
index 341ab497675544661efaf9699b51aea687819b87..7fa7ff5b38b47d62095a8cb3a450093681a24c2a 100644 |
--- a/third_party/WebKit/LayoutTests/storage/indexeddb/resources/observer.js |
+++ b/third_party/WebKit/LayoutTests/storage/indexeddb/resources/observer.js |
@@ -1,35 +1,136 @@ |
if (this.importScripts) { |
importScripts('../../../resources/testharness.js'); |
+ importScripts('generic-idb-operations.js'); |
} |
-function callback(){}; |
+async_test(function(t) { |
+ var dbname = location.pathname + ' - ' + 'empty transaction'; |
+ var openRequest = indexedDB.open(dbname); |
+ var callback_count = 0; |
+ var obs = new IDBObserver(t.step_func(function() { callback_count++; }), {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', 'readwrite'); |
+ 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.
|
+ obs.observe(db, tx1); |
+ 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
|
+ tx1.oncomplete = t.step_func(function() { |
+ countCallbacks(callback_count, 0); |
+ }); |
+ tx2.oncomplete = t.step_func(function() { |
+ countCallbacks(callback_count, 1); |
+ t.done(); |
+ }); |
+ }); |
+}, 'Registering observe call with empty transaction'); |
async_test(function(t) { |
- var description = 'observer addition and removal test'; |
- var dbname = location.pathname + ' - ' + description; |
+ var dbname = location.pathname + ' - ' + 'observer in version change'; |
var openRequest = indexedDB.open(dbname); |
- var obs1 = new IDBObserver(callback, {transaction: true, values: true}); |
- var obs2 = new IDBObserver(callback, {transaction: true, values: true}); |
+ var callback_count = 0; |
+ var obs; |
+ openRequest.onupgradeneeded = t.step_func(function() { |
+ createDatabase(openRequest.result, ['store']); |
+ obs = new IDBObserver(t.step_func(function() { callback_count++; }), { operationTypes: ['put'] }); |
+ }); |
+ openRequest.onsuccess = t.step_func(function() { |
+ var db = openRequest.result; |
+ var tx1 = db.transaction('store', 'readwrite'); |
+ var tx2 = db.transaction('store', 'readwrite'); |
+ tx1.objectStore('store').get(1); |
+ tx2.objectStore('store').put(1,1); |
cmumford
2016/07/20 00:25:12
space.
palakj1
2016/07/20 01:33:36
done
|
+ obs.observe(db, tx1); |
+ tx1.oncomplete = t.step_func(function() { |
+ countCallbacks(callback_count, 0); |
+ }); |
+ tx2.oncomplete = t.step_func(function() { |
+ countCallbacks(callback_count, 1); |
+ t.done(); |
+ }); |
+ }); |
+ }, 'Create IDBObserver during version change'); |
+async_test(function(t) { |
+ var dbname = location.pathname + ' - ' + 'ignore observe call'; |
+ var openRequest = indexedDB.open(dbname); |
+ var callback_count = 0; |
+ var obs = new IDBObserver(t.step_func(function() { callback_count++; }), { operationTypes: ['put'] }); |
openRequest.onupgradeneeded = t.step_func(function() { |
var db = openRequest.result; |
db.createObjectStore('store'); |
+ obs.observe(db, openRequest.transaction); |
}); |
openRequest.onsuccess = t.step_func(function() { |
var db = openRequest.result; |
var tx = db.transaction('store', 'readwrite'); |
- var store = tx.objectStore('store'); |
- var put_request = store.put(1,1); |
- obs1.observe(db, tx); |
- obs1.unobserve(db); |
- obs1.observe(db, tx); |
- obs2.observe(db, tx); |
- tx.oncomplete = t.step_func(function(){ |
- obs1.unobserve(db); |
- t.done(); |
- }); |
- }); |
-}, 'observer addition and removal test'); |
+ tx.objectStore('store').put(1,1); |
+ tx.oncomplete = t.step_func(function() { |
+ countCallbacks(callback_count, 0); |
+ t.done(); |
+ }); |
+ }); |
+}, 'Observe call during version change ignored'); |
-done(); |
+async_test(function(t) { |
+ var dbname = location.pathname + ' - ' + 'abort associated transaction'; |
+ var openRequest = indexedDB.open(dbname); |
+ var callback_count = 0; |
+ var obs = new IDBObserver(t.step_func(function() { callback_count++; }), { 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', 'readwrite'); |
+ var tx2 = db.transaction('store', 'readwrite'); |
+ tx1.objectStore('store').get(1); |
+ tx2.objectStore('store').put(1,1); |
+ obs.observe(db, tx1); |
+ tx1.abort(); |
+ tx1.oncomplete = t.step_func(function() { |
+ countCallbacks(callback_count, 0); |
+ }); |
+ tx2.oncomplete = t.step_func(function() { |
+ countCallbacks(callback_count, 0); |
+ t.done(); |
+ }); |
+ }); |
+}, 'Abort transaction associated with observer'); |
+ |
+async_test(function(t) { |
+ var dbname = location.pathname + ' - ' + 'abort transaction'; |
+ var openRequest = indexedDB.open(dbname); |
+ var callback_count = 0; |
+ var obs = new IDBObserver(t.step_func(function() { callback_count++; }), { 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', 'readwrite'); |
+ var tx2 = db.transaction('store', 'readwrite'); |
+ var tx3 = db.transaction('store', 'readwrite'); |
+ tx1.objectStore('store').get(1); |
+ tx2.objectStore('store').put(1,1); |
+ tx3.objectStore('store').put(1,1); |
+ obs.observe(db, tx1); |
+ tx2.abort(); |
+ tx1.oncomplete = t.step_func(function() { |
+ countCallbacks(callback_count, 0); |
+ }); |
+ tx2.oncomplete = t.unreached_func('transaction should not complete'); |
+ tx2.onabort = t.step_func(function() { |
+ countCallbacks(callback_count, 0); |
+ }); |
+ tx3.oncomplete = t.step_func(function() { |
+ countCallbacks(callback_count, 1); |
+ t.done(); |
+ }); |
+ }); |
+}, 'Abort transaction observer is recording'); |
cmumford
2016/07/20 00:25:12
Nit: slightly odd title.
palakj1
2016/07/20 01:33:36
changed
|
+done(); |