| 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..fff551ffd484cf3c69af200b6dfec338d5251f36 100644
|
| --- a/third_party/WebKit/LayoutTests/storage/indexeddb/resources/observer.js
|
| +++ b/third_party/WebKit/LayoutTests/storage/indexeddb/resources/observer.js
|
| @@ -1,35 +1,130 @@
|
| +/* This test checks the following
|
| + * Create observer during version change
|
| + * Ignore observe call during version change
|
| + * All operations {add, put, delete, clear} recorded
|
| + * Filtering object stores
|
| + * Add observer with an empty transaction.
|
| + * Observer Callback fired before transaction oncomplete.
|
| + * Multiple observer callbacks.
|
| + */
|
| +
|
| if (this.importScripts) {
|
| importScripts('../../../resources/testharness.js');
|
| }
|
|
|
| -function callback(){};
|
| +(function(){
|
| + var callback1_count = 0, callback2_count = 0;
|
| + var dbname = location.pathname + ' - ' + 'changes';
|
| + var operations = [{type: 'put', key : {lower : 1, upper : 1} },
|
| + {type: 'put', key : {lower : 2, upper : 2} },
|
| + {type: 'put', key : {lower : 3, upper : 3} },
|
| + {type: 'put', key : {lower : 4, upper : 4} },
|
| + {type: 'kDelete', key: {lower : 1, upper : 3} },
|
| + {type: 'add', key : {lower : 1, upper : 1} },
|
| + {type: 'clear'} ];
|
| +
|
| + function observation_equals(actual, expected){
|
| + assert_equals(actual.type, expected.type);
|
| + if(actual.type == 'clear') {
|
| + assert_equals(actual.key, undefined, 'clear operation has no key');
|
| + assert_equals(actual.value, null, 'clear operation has no value');
|
| + return;
|
| + }
|
| + assert_equals(actual.key.lower, expected.key.lower, 'key lower bound');
|
| + assert_equals(actual.key.upper, expected.key.upper, 'key upper bound');
|
| + assert_equals(actual.key.lower_open, expected.key.lower_open, 'key lower open');
|
| + assert_equals(actual.key.upper_open, expected.key.upper_open, 'key upper open');
|
| + if(actual.type == 'kDelete') {
|
| + assert_equals(actual.value, null, 'delete operation has no value');
|
| + return;
|
| + }
|
| + assert_equals(actual.value, null , 'observation value');
|
| + }
|
| +
|
| + function callback1(changes){
|
| + assert_equals(changes.database.name, dbname, 'database');
|
| + assert_equals(changes.records.size, 1, 'observer records #objstore');
|
| + assert_true(changes.records.has('store'));
|
| +
|
| + var obsv = changes.records.get('store');
|
| + if(callback1_count == 0)
|
| + assert_equals(obsv.length, 7, '#observations');
|
| + else
|
| + assert_equals(obsv.length, 1, '#observations');
|
| + for(i in obsv)
|
| + observation_equals(obsv[i], operations[i]);
|
| +
|
| + callback1_count++;
|
| + };
|
|
|
| -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});
|
| + function callback2(changes) {
|
| + assert_equals(changes.database.name, dbname, 'database');
|
| + assert_equals(changes.records.size, 2, 'observer records #objstores');
|
| + assert_true(changes.records.has('store'));
|
| + assert_true(changes.records.has('store2'));
|
|
|
| - openRequest.onupgradeneeded = t.step_func(function() {
|
| + var obsv1 = changes.records.get('store');
|
| + assert_equals(obsv1.length, 1, '#observations');
|
| + observation_equals(obsv1[0], operations[0]);
|
| +
|
| + var obsv2 = changes.records.get('store2');
|
| + assert_equals(obsv2.length, 1, '#observations');
|
| + observation_equals(obsv2[0], operations[0]);
|
| +
|
| + callback2_count++;
|
| + };
|
| +
|
| + async_test(function(t) {
|
| + var description = 'observer changes test';
|
| + var openRequest = indexedDB.open(dbname);
|
| + var obs1 = new IDBObserver(t.step_func(callback1));
|
| + openRequest.onupgradeneeded = t.step_func(function() {
|
| + var db = openRequest.result;
|
| + db.createObjectStore('store');
|
| + db.createObjectStore('store2');
|
| + var obs2 = new IDBObserver(t.step_func(callback2));
|
| + // observe call in version change transaction is ignored
|
| + obs2.observe(db, openRequest.transaction);
|
| + });
|
| + 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 tx = db.transaction('store', 'readwrite'); // Empty transaction to add the obs1.
|
| + var tx2 = db.transaction(['store', 'store2'], 'readwrite');
|
| + obs1.observe(db, tx);
|
| + obs2.observe(db, tx2);
|
| +
|
| + var store = tx2.objectStore('store');
|
| + var store2 = tx2.objectStore('store2');
|
| + for(i = 1; i <= 4; i++)
|
| + store.put(i,i);
|
| + store.delete(IDBKeyRange.bound(1,3));
|
| + store.add(1,1);
|
| + store.clear();
|
| +
|
| + // This operation would not be observed.
|
| + store2.put(2,2);
|
| + tx.oncomplete = t.step_func(function(){
|
| + assert_equals(callback1_count, 0, 'callback1 count');
|
| + assert_equals(callback2_count, 0, 'callback1 count');
|
| + });
|
| + tx2.oncomplete = t.step_func(function(){
|
| + assert_equals(callback1_count, 1, 'callback1 count');
|
| + assert_equals(callback2_count, 0, 'callback1 count');
|
| + });
|
| +
|
| + var tx3 = db.transaction(['store', 'store2'], 'readwrite');
|
| + var store3 = tx3.objectStore('store', 'readwrite');
|
| + var store4 = tx3.objectStore('store2', 'readwrite');
|
| + store3.put(1,1);
|
| + store4.put(1,1);
|
| +
|
| + tx3.oncomplete = t.step_func(function(){
|
| + assert_equals(callback1_count, 2, 'callback1 count');
|
| + assert_equals(callback2_count, 1, 'callback1 count');
|
| + t.done();
|
| });
|
| -}, 'observer addition and removal test');
|
| + });
|
| + }, 'observer changes test');
|
| +})();
|
|
|
| -done();
|
|
|
|
|