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

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

Issue 2601983002: [IndexedDB] Adding transaction and value support to observers (Closed)
Patch Set: Replying to comments, disallowed observing from versionchange txn 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-tests.js
diff --git a/third_party/WebKit/LayoutTests/storage/indexeddb/resources/observer-tests.js b/third_party/WebKit/LayoutTests/storage/indexeddb/resources/observer-tests.js
index 8328c2136c8132d7da4e598afd057cb31590176d..3ba535ba6b2b89a5bab0bf0725971720cf29e1b6 100644
--- a/third_party/WebKit/LayoutTests/storage/indexeddb/resources/observer-tests.js
+++ b/third_party/WebKit/LayoutTests/storage/indexeddb/resources/observer-tests.js
@@ -90,6 +90,67 @@ indexeddb_observers_test(function(t, db1_name, db2_name, observers_added_callbac
var expectedChanges = {
dbName: db1_name,
records: {
+ 'store2': [{type: 'add', key: 'z', value: 'z'}]
+ }
+ };
+
+ var connection = null;
+ var observeFunction = function(changes) {
+ compareChanges(changes, expectedChanges);
+ assert_true(connection != null);
pwnall 2017/01/10 01:41:11 Can you add a description for the meaning of this
dmurph 2017/01/10 20:40:06 Done.
+ obs.unobserve(connection);
+ t.done();
+ };
+
+ var obs = new IDBObserver(t.step_func(observeFunction));
+
+ openDB(t, db1_name, t.step_func(function(db) {
+ connection = db;
+ var txn = db.transaction(['store2'], 'readonly');
+ obs.observe(db, txn, {operationTypes: ['add'], values: true});
+ txn.oncomplete = observers_added_callback;
+ txn.onerror = t.unreached_func('transaction should not fail')
+ }));
+}, 'IDB Observers: Values');
+
+
+indexeddb_observers_test(function(t, db1_name, db2_name, observers_added_callback) {
+ var expectedChanges = {
+ dbName: db1_name,
+ records: {
+ 'store2': [{type: 'add', key: 'z'}]
pwnall 2017/01/10 01:41:11 comma at the end of the line, to minimize future c
dmurph 2017/01/10 20:40:06 Done.
+ }
+ };
+
+ var connection = null;
+ var observeFunction = function(changes) {
+ compareChanges(changes, expectedChanges);
+ assert_true(connection != null);
+ obs.unobserve(connection);
+ assert_true(changes.transaction != null);
+ var store2 = changes.transaction.objectStore('store2');
+ var request = store2.get('z');
+ request.onsuccess = t.step_func(function() {
+ assert_equals(request.result, 'z');
+ t.done();
+ });
+ };
+
+ var obs = new IDBObserver(t.step_func(observeFunction));
+
+ openDB(t, db1_name, t.step_func(function(db) {
+ connection = db;
+ var txn = db.transaction(['store2'], 'readonly');
+ obs.observe(db, txn, {operationTypes: ['add'], transaction: true});
+ txn.oncomplete = observers_added_callback;
+ txn.onerror = t.unreached_func('transaction should not fail')
+ }));
+}, 'IDB Observers: Transaction');
+
+indexeddb_observers_test(function(t, db1_name, db2_name, observers_added_callback) {
+ var expectedChanges = {
+ dbName: db1_name,
+ records: {
'store2': [{type: 'add', key: 'z'}]
}
};
@@ -227,16 +288,18 @@ indexeddb_observers_test(function(t, db1_name, db2_name, observers_added_callbac
var connection = null;
var changeNumber = 0;
var observeFunction = function(changes) {
- assert_true(connection != null);
- if (changeNumber === 0) {
+ assert_true(connection != null, "connection is null");
pwnall 2017/01/10 01:41:11 The comment appears to be redundant with the condi
dmurph 2017/01/10 20:40:06 Done.
+ if (changes.records.has('store1')) {
compareChanges(changes, expectedChanges1);
- } else if(changeNumber === 1) {
+ } else if(changes.records.has('store2')) {
compareChanges(changes, expectedChanges2);
+ }
+ ++changeNumber;
+ assert_less_than_equal(changeNumber, 2, "incorrect pendingObserves");
+ if (changeNumber == 2) {
obs.unobserve(connection);
t.done();
}
- ++changeNumber;
- assert_less_than_equal(changeNumber, 1, "incorrect pendingObserves");
};
var obs = new IDBObserver(t.step_func(observeFunction));

Powered by Google App Engine
This is Rietveld 408576698