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

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

Issue 2125213002: [IndexedDB] Propogating changes to observers : Renderer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lifetime
Patch Set: Test added Created 4 years, 5 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 unified diff | Download patch
OLDNEW
1 if (this.importScripts) { 1 if (this.importScripts) {
2 importScripts('../../../resources/testharness.js'); 2 importScripts('../../../resources/testharness.js');
3 importScripts('../../../resources/generic-idb-operations.js');
3 } 4 }
4 5
5 function callback(){}; 6 (function() {
7 var dbname = location.pathname + ' - ' + 'changes';
8 var ops = [{type: 'put', key : 1, value: 1 },
9 {type: 'put', key : 2, value: 2 },
10 {type: 'delete', key: {lower : 1, upper : 3} },
11 {type: 'add', key : 1, value: 1 },
12 {type: 'clear'} ];
13 var stores = ['store', 'store2'];
6 14
7 async_test(function(t) { 15 var callback_count1 = [0, 0];
8 var description = 'observer addition and removal test'; 16 var observed_ops1 = [ops[0], ops[1], ops[3]];
9 var dbname = location.pathname + ' - ' + description; 17 var records_map1 = new Map();
10 var openRequest = indexedDB.open(dbname); 18 records_map1.set(stores[0], observed_ops1);
11 var obs1 = new IDBObserver(callback, {transaction: true, values: true}); 19 var expected_changes1 = { dbName: dbname, records: records_map1 };
12 var obs2 = new IDBObserver(callback, {transaction: true, values: true});
13 20
14 openRequest.onupgradeneeded = t.step_func(function() { 21 function callback1(observed_changes) {
22 compareChanges(observed_changes, expected_changes1);
23 callback_count1[0]++;
24 };
25
26 function callback2(observed_changes) {
27 callback_count1[1]++;
28 };
29
30 async_test(function(t) {
31 var openRequest = indexedDB.open(dbname,1);
32 var obs1 = new IDBObserver(t.step_func(callback1), { operationTypes: ['add', 'put'] });
33 var obs2 = new IDBObserver(t.step_func(callback2));
34
35 openRequest.onupgradeneeded = t.step_func(function() {
36 createDatabase(openRequest.result, stores);
37 });
38 openRequest.onsuccess = t.step_func(function() {
15 var db = openRequest.result; 39 var db = openRequest.result;
16 db.createObjectStore('store'); 40 var storeName = stores[0];
17 }); 41 var tx1 = db.transaction(storeName, 'readwrite');
18 openRequest.onsuccess = t.step_func(function() { 42 var tx2 = db.transaction(storeName, 'readwrite');
19 var db = openRequest.result; 43 obs1.observe(db, tx1);
20 var tx = db.transaction('store', 'readwrite'); 44 obs2.observe(db, tx1);
21 var store = tx.objectStore('store'); 45 var store = tx2.objectStore(storeName);
22 var put_request = store.put(1,1); 46 operateOnStore(store, ops);
23 obs1.observe(db, tx); 47
24 obs1.unobserve(db); 48 tx1.oncomplete = t.step_func(function() {
25 obs1.observe(db, tx); 49 countCallbacks(callback_count1, [0, 0]);
26 obs2.observe(db, tx);
27 tx.oncomplete = t.step_func(function(){
28 obs1.unobserve(db);
29 t.done();
30 });
31 }); 50 });
32 }, 'observer addition and removal test'); 51 tx2.oncomplete = t.step_func(function() {
52 countCallbacks(callback_count1, [1, 0]);
53 t.done();
54 });
55 });
56 }, 'Observer: Operation type filtering');
33 57
34 done(); 58 var callback_count2 = [0];
59 var records_map2 = new Map();
60 var ops2 = [ops[0]];
61 records_map2.set(stores[0], ops2);
35 62
63 var expected_changes2 = { dbName: dbname+'2', records: records_map2 };
64
65 function callback3(changes){
66 compareChanges(changes, expected_changes2);
67 callback_count2[0]++;
68 }
69
70 async_test(function(t) {
71 var openRequest = indexedDB.open(dbname+'2');
72 var obs = new IDBObserver(t.step_func(callback3), { operationTypes: ['put'] });
73
74 openRequest.onupgradeneeded = t.step_func(function() {
75 createDatabase(openRequest.result, stores);
76 });
77 openRequest.onsuccess = t.step_func(function() {
78 var db = openRequest.result;
79 var tx1 = db.transaction(stores[0], 'readwrite');
80 var tx2 = db.transaction(stores, 'readwrite');
81 obs.observe(db, tx1);
82 var store1 = tx2.objectStore(stores[0]);
83 var store2 = tx2.objectStore(stores[1]);
84 operateOnStore(store1, ops2);
85 operateOnStore(store2, ops2);
86
87 tx1.oncomplete = t.step_func(function() {
88 countCallbacks(callback_count2, [0]);
89 });
90 tx2.oncomplete = t.step_func(function() {
91 countCallbacks(callback_count2, [1]);
92 t.done();
93 });
94 });
95 }, 'Observer: ObjectStore filtering');
96
97 done();
98 })();
99
100
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698