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

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

Issue 2163213006: [IndexedDB] Add Observer Tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@changes_renderer
Patch Set: Post cmumford review 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
(Empty)
1 if (this.importScripts) {
2 importScripts('../../../resources/testharness.js');
3 importScripts('../../../resources/generic-idb-operations.js');
4 }
5
6 (function() {
7 var pathname = location.pathname + ' - ' + 'changes';
8 var callback_count = Array(6).fill(0);
9 var dbname = [];
10 for(var i = 1; i <= 6; i++)
11 dbname.push(pathname + i.toString());
12
13 callback_count.fill(0);
14 var putOps = [{type: 'put', key : 1, value: 1 },
15 {type: 'put', key : 2, value: 2 },
16 {type: 'put', key : 3, value: 3 },];
17 var deleteOps = [ {type: 'kDelete', key: {lower : 1, upper : 2} }, {type: 'kDe lete', key: {lower : 3, upper : 3} }];
18 var addOps = [ {type: 'add', key : 3, value: 3 } ];
19 var clearOps = [ {type: 'clear'} ];
20 var put_records = { 'store': putOps };
21
22 var ops0 = putOps.concat(deleteOps, addOps, clearOps);
23 var records0 = { 'store' : ops0 };
24 var observed_records0 = { 'store' : ops0 };
25 var observed_changes0 = { dbName: dbname[0], records: observed_records0 };
26
27 function callback0(changes) {
28 compareChanges(changes, observed_changes0);
29 callback_count[0]++;
30 };
31
32 async_test(function(t) {
33 var openRequest = indexedDB.open(dbname[0]);
34 // TODO(dmurph): operationType should be 'delete' instead of 'kDelete', once fixed. Issue crbug.com/609934.
35 var obs = new IDBObserver(t.step_func(callback0), { operationTypes: [ 'clear ', 'put', 'add', 'kDelete' ] });
36 openRequest.onupgradeneeded = t.step_func(function() {
37 createObjectStores(openRequest.result, ['store']);
38 });
39 openRequest.onsuccess = t.step_func(function() {
40 var db = openRequest.result;
41 var tx1 = db.transaction('store', 'readwrite');
42 var tx2 = db.transaction('store', 'readwrite');
43 obs.observe(db, tx1);
44 operateOnTx(tx2, records0);
45
46 tx1.oncomplete = t.step_func(function() {
47 countCallbacks(callback_count[0], 0);
48 });
49 tx1.onerror = t.unreached_func('transaction should not fail')
50 tx2.oncomplete = t.step_func(function() {
51 countCallbacks(callback_count[0], 1);
52 t.done();
53 });
54 tx2.onerror = t.unreached_func('transaction should not fail')
55 });
56 openRequest.onerror = t.unreached_func('opening database should not fail');
57 }, 'Observer: Record all operations');
58
59 var ops1 = putOps.concat(deleteOps, addOps, clearOps);
60 var records1 = { 'store' : ops1 };
61 var observed_ops1 = putOps.concat(clearOps);
62 var observed_records1 = { 'store' : observed_ops1 };
63 var observed_changes1 = { dbName: dbname[1], records: observed_records1 };
64
65 function callback1(changes) {
66 compareChanges(changes, observed_changes1);
67 callback_count[1]++;
68 };
69
70 async_test(function(t) {
71 var openRequest = indexedDB.open(dbname[1]);
72 var cnt2 = 0;
73 var obs1 = new IDBObserver(t.step_func(callback1), { operationTypes: ['clear ', 'put'] });
74 var obs2 = new IDBObserver(t.step_func(function(){
75 cnt2++;
76 }));
77
78 openRequest.onupgradeneeded = t.step_func(function() {
79 createObjectStores(openRequest.result, ['store']);
80 });
81 openRequest.onsuccess = t.step_func(function() {
82 var db = openRequest.result;
83 var tx1 = db.transaction('store', 'readwrite');
84 var tx2 = db.transaction('store', 'readwrite');
85 obs1.observe(db, tx1);
86 obs2.observe(db, tx1);
87 operateOnTx(tx2, records1);
88
89 tx1.oncomplete = t.step_func(function() {
90 countCallbacks(callback_count[1], 0);
91 countCallbacks(cnt2, 0);
92
93 });
94 tx2.oncomplete = t.step_func(function() {
95 countCallbacks(callback_count[1], 1);
96 countCallbacks(cnt2, 0);
97 t.done();
98 });
99 });
100 openRequest.onerror = t.unreached_func('opening database should not fail');
101 }, 'Observer: Operation type filtering');
102
103 var records2 = { 'store' : putOps, 'store2' : addOps };
104 var observed_records2 = { 'store' : putOps };
105 var observed_changes2 = { dbName: dbname[2], records: observed_records2 };
106
107 function callback2(changes){
108 compareChanges(changes, observed_changes2);
109 callback_count[2]++;
110 }
111 var stores = ['store', 'store2']
112
113 async_test(function(t) {
114 var openRequest = indexedDB.open(dbname[2]);
115 var obs = new IDBObserver(t.step_func(callback2), { operationTypes: ['put', 'add'] });
116
117 openRequest.onupgradeneeded = t.step_func(function() {
118 createObjectStores(openRequest.result, stores);
119 });
120 openRequest.onsuccess = t.step_func(function() {
121 var db = openRequest.result;
122 var tx1 = db.transaction(stores[0], 'readwrite');
123 var tx2 = db.transaction(stores, 'readwrite');
124 obs.observe(db, tx1);
125 operateOnTx(tx2, records2);
126
127 tx1.oncomplete = t.step_func(function() {
128 countCallbacks(callback_count[2], 0);
129 });
130 tx2.oncomplete = t.step_func(function() {
131 countCallbacks(callback_count[2], 1);
132 t.done();
133 });
134 });
135 openRequest.onerror = t.unreached_func('opening database should not fail');
136 }, 'Observer: ObjectStore filtering');
137
138 var records3 = { 'store' : putOps };
139 var put_records = { 'store' : putOps };
140 var observed_changes3 = { dbName: dbname[3], records: put_records };
141
142 function callback3(changes){
143 compareChanges(changes, observed_changes3);
144 callback_count[3]++;
145 }
146 async_test(function(t) {
147 var openRequest = indexedDB.open(dbname[3]);
148 var obs = new IDBObserver(t.step_func(callback3), { operationTypes: ['put'] });
149
150 openRequest.onupgradeneeded = t.step_func(function() {
151 createObjectStores(openRequest.result, ['store']);
152 });
153 openRequest.onsuccess = t.step_func(function() {
154 var db = openRequest.result;
155 var tx1 = db.transaction('store', 'readwrite');
156 // External transaction on same database connection.
157 operateOnDb(db, records3);
158 var tx2 = db.transaction('store', 'readwrite');
159 operateOnTx(tx2, records3);
160 obs.observe(db, tx1);
161
162 tx1.oncomplete = t.step_func(function() {
163 countCallbacks(callback_count[3], 0);
164 });
165 tx2.oncomplete = t.step_func(function() {
166 countCallbacks(callback_count[3], 2);
167 t.done();
168 });
169 tx2.onerror = t.unreached_func('tx should not have error');
170 });
171 openRequest.onerror = t.unreached_func('opening database should not fail');
172 }, 'Observer : Records external transaction');
173
174 var observed_changes4 = { dbName: dbname[4], records: put_records };
175
176 function callback4(changes){
177 compareChanges(changes, observed_changes4);
178 callback_count[4]++;
179 }
180
181 async_test(function(t) {
182 var openRequest = indexedDB.open(dbname[4]);
183 var obs = new IDBObserver(t.step_func(callback4), { operationTypes: ['put'] });
184
185 openRequest.onupgradeneeded = t.step_func(function() {
186 createObjectStores(openRequest.result, ['store']);
187 });
188 openRequest.onsuccess = t.step_func(function() {
189 var db = openRequest.result;
190 var tx1 = db.transaction('store', 'readwrite');
191 obs.observe(db, tx1);
192 tx1.oncomplete = t.step_func(function() {
193 countCallbacks(callback_count[4], 0);
194 });
195 tx1.onerror = t.unreached_func('transaction should not fail');
196
197 var openRequest2 = indexedDB.open(dbname[4]);
198 openRequest2.onsuccess = t.step_func(function(){
199 var db2 = openRequest2.result;
200 var tx2 = db2.transaction('store', 'readwrite');
201 operateOnTx(tx2, put_records);
202 tx2.oncomplete = function(){
203 countCallbacks(callback_count[4], 1);
204 t.done();
205 }
206 tx2.onerror = t.unreached_func('transaction should not fail');
207 });
208 });
209 openRequest.onerror = t.unreached_func('opening database should not fail');
210 }, 'Observer : Record changes on another connection');
211
212 var records5_2 = {'store2' : putOps}
213 var observed_changes5_1 = { dbName: dbname[5], records: put_records };
214 var observed_changes5_2 = { dbName: dbname[5], records: records5_2 };
215
216 function callback5(changes){
217 assert_true(callback_count[5] < 2);
218 if(callback_count[5] == 0)
219 compareChanges(changes, observed_changes5_1);
220 else
221 compareChanges(changes, observed_changes5_2);
222 callback_count[5]++;
223 }
224
225 async_test(function(t) {
226 var openRequest = indexedDB.open(dbname[5]);
227 var obs = new IDBObserver(t.step_func(callback5), { operationTypes: ['put'] });
228
229 openRequest.onupgradeneeded = t.step_func(function() {
230 createObjectStores(openRequest.result, [ 'store', 'store2' ]);
231 });
232 openRequest.onsuccess = t.step_func(function() {
233 var db = openRequest.result;
234 var tx1 = db.transaction([ 'store', 'store2'], 'readwrite');
235 var tx2 = db.transaction('store', 'readwrite');
236
237 obs.observe(db, tx1);
238 tx1.objectStore('store').get(1);
239 t.step_func(operateOnTx(tx2, put_records));
240
241 tx1.oncomplete = t.step_func(function() {
242 countCallbacks(callback_count[5], 0);
243 });
244 tx1.onerror = t.unreached_func('transaction should not fail');
245 tx2.oncomplete = t.step_func(function(){
246 countCallbacks(callback_count[5], 1);
247 var tx3 = db.transaction('store2', 'readwrite');
248 t.step_func(operateOnTx(tx3, records5_2));
249
250 tx3.oncomplete = t.step_func(function(){
251 countCallbacks(callback_count[5], 2);
252 t.done();
253 });
254 tx3.onerror = t.unreached_func('transaction should not fail');
255 });
256 tx2.onerror = t.unreached_func('transaction should not fail');
257 });
258 openRequest.onerror = t.unreached_func('opening database should not fail');
259 }, 'Observer : Record multiple transactions');
260
261 done();
262 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698