Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(71)

Unified Diff: third_party/WebKit/LayoutTests/storage/indexeddb/resources/observer.js

Issue 2601983002: [IndexedDB] Adding transaction and value support to observers (Closed)
Patch Set: Transactions working Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 dfcf7295440e7e2788cec51475714d9e63e9bcbe..da15d26f56656b2616a3b71d1c11be071e6e4c9c 100644
--- a/third_party/WebKit/LayoutTests/storage/indexeddb/resources/observer.js
+++ b/third_party/WebKit/LayoutTests/storage/indexeddb/resources/observer.js
@@ -1,146 +1,87 @@
if (this.importScripts) {
importScripts('../../../resources/testharness.js');
+ importScripts('testharness-helpers.js');
importScripts('generic-idb-operations.js');
}
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++; }));
-
- openRequest.onupgradeneeded = t.step_func(function() {
- openRequest.result.createObjectStore('store');
- });
- openRequest.onsuccess = t.step_func(function() {
- var db = openRequest.result;
+ var obs = new IDBObserver(t.step_func(function() {
+ t.done();
+ }));
+ delete_then_open(t, dbname, function(t, db, request) {
+ db.createObjectStore('store');
+ }, function(t, db) {
var tx1 = db.transaction('store', 'readwrite');
- var tx2 = db.transaction('store', 'readwrite');
obs.observe(db, tx1, {operationTypes: ['put']});
- tx2.objectStore('store').put(1, 1);
- tx1.oncomplete = t.step_func(function() {
- countCallbacks(callback_count, 0);
- });
- tx2.oncomplete = t.step_func(function() {
- countCallbacks(callback_count, 1);
- t.done();
- });
tx1.onerror = t.unreached_func('transaction should not fail');
+ var tx2 = db.transaction('store', 'readwrite');
+ tx2.objectStore('store').put(1, 1);
tx2.onerror = t.unreached_func('transaction should not fail');
});
}, 'Registering observe call with empty transaction');
async_test(function(t) {
- var dbname = location.pathname + ' - ' + 'observer in version change';
- var openRequest = indexedDB.open(dbname);
- var callback_count = 0;
- var obs;
- openRequest.onupgradeneeded = t.step_func(function() {
- openRequest.result.createObjectStore('store');
- obs = new IDBObserver(t.step_func(function(changes) { callback_count++; }));
- });
- 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, { operationTypes: ['put'] });
- tx1.oncomplete = t.step_func(function() {
- countCallbacks(callback_count, 0);
- });
- tx2.oncomplete = t.step_func(function() {
- countCallbacks(callback_count, 1);
+ var dbname = location.pathname + ' - ' + 'observe in version change';
+ var obs = new IDBObserver(t.step_func(function(changes) {
t.done();
- });
- tx1.onerror = t.unreached_func('transaction should not fail');
- tx2.onerror = t.unreached_func('transaction should not fail');
- });
- }, '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++; }));
- openRequest.onupgradeneeded = t.step_func(function() {
- var db = openRequest.result;
- db.createObjectStore('store');
- obs.observe(db, openRequest.transaction, { operationTypes: ['put'] });
+ delete_then_open(t, dbname, function(t, db, request) {
+ request.result.createObjectStore('store');
+ obs.observe(db, request.transaction, { operationTypes: ['put'] });
+ }, function(t, db) {
+ var txn = db.transaction('store', 'readwrite');
+ txn.objectStore('store').put(1, 1);
+ txn.onerror = t.unreached_func('transaction should not fail');
});
- openRequest.onsuccess = t.step_func(function() {
- var db = openRequest.result;
- var tx = db.transaction('store', 'readwrite');
- tx.objectStore('store').put(1, 1);
- tx.oncomplete = t.step_func(function() {
- countCallbacks(callback_count, 0);
- t.done();
- });
- tx.onerror = t.unreached_func('transaction should not fail');
- });
-}, 'Observe call during version change ignored');
+}, 'Observe during version change');
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++; }));
- openRequest.onupgradeneeded = t.step_func(function() {
- openRequest.result.createObjectStore('store');
- });
- openRequest.onsuccess = t.step_func(function() {
- var db = openRequest.result;
+ var obs = new IDBObserver(t.unreached_func('Observe in aborted transaction should be ignored'));
+ delete_then_open(t, dbname, function(t, db, request) {
+ request.result.createObjectStore('store');
+ }, function(t, db) {
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, { operationTypes: ['put'] });
+ tx1.oncomplete = t.unreached_func('transaction should not complete');
tx1.abort();
- tx1.onabort = t.step_func(function(){
- countCallbacks(callback_count, 0);
- });
- tx1.oncomplete = t.unreached_func('transaction should not complete');
+ var tx2 = db.transaction('store', 'readwrite');
+ tx2.objectStore('store').put(1, 1);
+ tx2.onerror = t.unreached_func('transaction error should not fail');
tx2.oncomplete = t.step_func(function() {
- countCallbacks(callback_count, 0);
t.done();
});
- tx2.onerror = t.unreached_func('transaction error should not fail');
});
}, 'Abort transaction associated with observer');
async_test(function(t) {
- var dbname = location.pathname + ' - ' + 'abort transaction';
- var openRequest = indexedDB.open(dbname);
+ var dbname = location.pathname + ' - ' + 'abort transaction not recorded';
var callback_count = 0;
- var obs = new IDBObserver(t.step_func(function() { callback_count++; }));
- openRequest.onupgradeneeded = t.step_func(function() {
- openRequest.result.createObjectStore('store');
- });
- openRequest.onsuccess = t.step_func(function() {
- var db = openRequest.result;
+ var obs = new IDBObserver(t.step_func(function(changes) {
+ assert_equals(changes.records.get('store')[0].key.lower, 1);
+ t.done();
+ }));
+
+ delete_then_open(t, dbname, function(t, db, request) {
+ request.result.createObjectStore('store');
+ }, function(t, db) {
var tx1 = db.transaction('store', 'readwrite');
+ obs.observe(db, tx1, { operationTypes: ['put'] });
+ tx1.onerror = t.unreached_func('transaction should not fail');
+
var tx2 = db.transaction('store', 'readwrite');
+ tx2.objectStore('store').put(2, 2);
+ tx2.oncomplete = t.unreached_func('transaction should not complete');
+ tx2.abort();
+
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, { operationTypes: ['put'] });
- 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();
- });
- tx1.onerror = t.unreached_func('transaction should not fail');
tx3.onerror = t.unreached_func('transaction should not fail');
});
-}, 'Abort transaction recorded by observer');
+}, 'Aborted transaction not recorded by observer');
done();

Powered by Google App Engine
This is Rietveld 408576698