| 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..4cb2051c4f1b2563dbf59d49bbde7d1bb1d22aad 100644
|
| --- a/third_party/WebKit/LayoutTests/storage/indexeddb/resources/observer.js
|
| +++ b/third_party/WebKit/LayoutTests/storage/indexeddb/resources/observer.js
|
| @@ -1,35 +1,100 @@
|
| if (this.importScripts) {
|
| importScripts('../../../resources/testharness.js');
|
| + importScripts('../../../resources/generic-idb-operations.js');
|
| }
|
|
|
| -function callback(){};
|
| +(function() {
|
| + var dbname = location.pathname + ' - ' + 'changes';
|
| + var ops = [{type: 'put', key : 1, value: 1 },
|
| + {type: 'put', key : 2, value: 2 },
|
| + {type: 'delete', key: {lower : 1, upper : 3} },
|
| + {type: 'add', key : 1, value: 1 },
|
| + {type: 'clear'} ];
|
| + var stores = ['store', 'store2'];
|
|
|
| -async_test(function(t) {
|
| - var description = 'observer addition and removal test';
|
| - var dbname = location.pathname + ' - ' + description;
|
| - 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_count1 = [0, 0];
|
| + var observed_ops1 = [ops[0], ops[1], ops[3]];
|
| + var records_map1 = new Map();
|
| + records_map1.set(stores[0], observed_ops1);
|
| + var expected_changes1 = { dbName: dbname, records: records_map1 };
|
|
|
| - openRequest.onupgradeneeded = t.step_func(function() {
|
| + function callback1(observed_changes) {
|
| + compareChanges(observed_changes, expected_changes1);
|
| + callback_count1[0]++;
|
| + };
|
| +
|
| + function callback2(observed_changes) {
|
| + callback_count1[1]++;
|
| + };
|
| +
|
| + async_test(function(t) {
|
| + var openRequest = indexedDB.open(dbname,1);
|
| + var obs1 = new IDBObserver(t.step_func(callback1), { operationTypes: ['add', 'put'] });
|
| + var obs2 = new IDBObserver(t.step_func(callback2));
|
| +
|
| + openRequest.onupgradeneeded = t.step_func(function() {
|
| + createDatabase(openRequest.result, stores);
|
| + });
|
| + openRequest.onsuccess = t.step_func(function() {
|
| var db = openRequest.result;
|
| - db.createObjectStore('store');
|
| - });
|
| - 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();
|
| - });
|
| + var storeName = stores[0];
|
| + var tx1 = db.transaction(storeName, 'readwrite');
|
| + var tx2 = db.transaction(storeName, 'readwrite');
|
| + obs1.observe(db, tx1);
|
| + obs2.observe(db, tx1);
|
| + var store = tx2.objectStore(storeName);
|
| + operateOnStore(store, ops);
|
| +
|
| + tx1.oncomplete = t.step_func(function() {
|
| + countCallbacks(callback_count1, [0, 0]);
|
| });
|
| -}, 'observer addition and removal test');
|
| + tx2.oncomplete = t.step_func(function() {
|
| + countCallbacks(callback_count1, [1, 0]);
|
| + t.done();
|
| + });
|
| + });
|
| + }, 'Observer: Operation type filtering');
|
| +
|
| + var callback_count2 = [0];
|
| + var records_map2 = new Map();
|
| + var ops2 = [ops[0]];
|
| + records_map2.set(stores[0], ops2);
|
| +
|
| + var expected_changes2 = { dbName: dbname+'2', records: records_map2 };
|
| +
|
| + function callback3(changes){
|
| + compareChanges(changes, expected_changes2);
|
| + callback_count2[0]++;
|
| + }
|
| +
|
| + async_test(function(t) {
|
| + var openRequest = indexedDB.open(dbname+'2');
|
| + var obs = new IDBObserver(t.step_func(callback3), { operationTypes: ['put'] });
|
| +
|
| + openRequest.onupgradeneeded = t.step_func(function() {
|
| + createDatabase(openRequest.result, stores);
|
| + });
|
| + openRequest.onsuccess = t.step_func(function() {
|
| + var db = openRequest.result;
|
| + var tx1 = db.transaction(stores[0], 'readwrite');
|
| + var tx2 = db.transaction(stores, 'readwrite');
|
| + obs.observe(db, tx1);
|
| + var store1 = tx2.objectStore(stores[0]);
|
| + var store2 = tx2.objectStore(stores[1]);
|
| + operateOnStore(store1, ops2);
|
| + operateOnStore(store2, ops2);
|
| +
|
| + tx1.oncomplete = t.step_func(function() {
|
| + countCallbacks(callback_count2, [0]);
|
| + });
|
| + tx2.oncomplete = t.step_func(function() {
|
| + countCallbacks(callback_count2, [1]);
|
| + t.done();
|
| + });
|
| + });
|
| + }, 'Observer: ObjectStore filtering');
|
| +
|
| + done();
|
| +})();
|
|
|
| -done();
|
|
|
|
|