OLD | NEW |
---|---|
(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(palakj): 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 createDatabase(openRequest.result, ['store']); | |
38 }); | |
39 openRequest.onsuccess = t.step_func(function() { | |
cmumford
2016/07/21 15:00:55
Add onerror to avoid having to wait for test to ti
| |
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 1 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 2 should not fail') | |
55 }); | |
56 }, 'Observer: Record all operations'); | |
57 | |
58 var ops1 = putOps.concat(deleteOps, addOps, clearOps); | |
59 var records1 = { 'store' : ops1 }; | |
60 var observed_ops1 = putOps.concat(clearOps); | |
61 var observed_records1 = { 'store' : observed_ops1 }; | |
62 var observed_changes1 = { dbName: dbname[1], records: observed_records1 }; | |
63 | |
64 function callback1(changes) { | |
65 compareChanges(changes, observed_changes1); | |
66 callback_count[1]++; | |
67 }; | |
68 | |
69 async_test(function(t) { | |
70 var openRequest = indexedDB.open(dbname[1]); | |
71 var cnt2 = 0; | |
72 var obs1 = new IDBObserver(t.step_func(callback1), { operationTypes: ['clear ', 'put'] }); | |
73 var obs2 = new IDBObserver(t.step_func(function(){ | |
74 cnt2++; | |
75 })); | |
76 | |
77 openRequest.onupgradeneeded = t.step_func(function() { | |
78 createDatabase(openRequest.result, ['store']); | |
cmumford
2016/07/21 15:00:55
I know |createDatabase| landed in a prior CL, but
| |
79 }); | |
80 openRequest.onsuccess = t.step_func(function() { | |
81 var db = openRequest.result; | |
82 var tx1 = db.transaction('store', 'readwrite'); | |
83 var tx2 = db.transaction('store', 'readwrite'); | |
84 obs1.observe(db, tx1); | |
85 obs2.observe(db, tx1); | |
86 operateOnTx(tx2, records1); | |
87 | |
88 tx1.oncomplete = t.step_func(function() { | |
89 countCallbacks(callback_count[1], 0); | |
90 countCallbacks(cnt2, 0); | |
91 | |
92 }); | |
93 tx2.oncomplete = t.step_func(function() { | |
94 countCallbacks(callback_count[1], 1); | |
95 countCallbacks(cnt2, 0); | |
96 t.done(); | |
97 }); | |
98 }); | |
99 }, 'Observer: Operation type filtering'); | |
100 | |
101 var records2 = { 'store' : putOps, 'store2' : addOps }; | |
102 var observed_records2 = { 'store' : putOps }; | |
103 var observed_changes2 = { dbName: dbname[2], records: observed_records2 }; | |
104 | |
105 function callback2(changes){ | |
106 compareChanges(changes, observed_changes2); | |
107 callback_count[2]++; | |
108 } | |
109 var stores = ['store', 'store2'] | |
110 | |
111 async_test(function(t) { | |
112 var openRequest = indexedDB.open(dbname[2]); | |
113 var obs = new IDBObserver(t.step_func(callback2), { operationTypes: ['put', 'add'] }); | |
114 | |
115 openRequest.onupgradeneeded = t.step_func(function() { | |
116 createDatabase(openRequest.result, stores); | |
117 }); | |
118 openRequest.onsuccess = t.step_func(function() { | |
119 var db = openRequest.result; | |
120 var tx1 = db.transaction(stores[0], 'readwrite'); | |
121 var tx2 = db.transaction(stores, 'readwrite'); | |
122 obs.observe(db, tx1); | |
123 operateOnTx(tx2, records2); | |
124 | |
125 tx1.oncomplete = t.step_func(function() { | |
126 countCallbacks(callback_count[2], 0); | |
127 }); | |
128 tx2.oncomplete = t.step_func(function() { | |
129 countCallbacks(callback_count[2], 1); | |
130 t.done(); | |
131 }); | |
132 }); | |
133 }, 'Observer: ObjectStore filtering'); | |
134 | |
135 var records3 = { 'store' : putOps }; | |
136 var put_records = { 'store' : putOps }; | |
137 var observed_changes3 = { dbName: dbname[3], records: put_records }; | |
138 | |
139 function callback3(changes){ | |
140 compareChanges(changes, observed_changes3); | |
141 callback_count[3]++; | |
142 } | |
143 async_test(function(t) { | |
144 var openRequest = indexedDB.open(dbname[3]); | |
145 var obs = new IDBObserver(t.step_func(callback3), { operationTypes: ['put'] }); | |
146 | |
147 openRequest.onupgradeneeded = t.step_func(function() { | |
148 createDatabase(openRequest.result, ['store']); | |
149 }); | |
150 openRequest.onsuccess = t.step_func(function() { | |
151 var db = openRequest.result; | |
152 var tx1 = db.transaction('store', 'readwrite'); | |
153 // External transaction on same database connection. | |
154 operateOnDb(db, records3); | |
155 var tx2 = db.transaction('store', 'readwrite'); | |
156 operateOnTx(tx2, records3); | |
157 obs.observe(db, tx1); | |
158 | |
159 tx1.oncomplete = t.step_func(function() { | |
160 countCallbacks(callback_count[3], 0); | |
161 }); | |
162 tx2.oncomplete = t.step_func(function() { | |
163 countCallbacks(callback_count[3], 2); | |
164 t.done(); | |
165 }); | |
166 tx2.onerror = t.unreached_func('tx should not have error'); | |
167 }); | |
168 }, 'Observer : Records external transaction'); | |
169 | |
170 var observed_changes4 = { dbName: dbname[4], records: put_records }; | |
171 | |
172 function callback4(changes){ | |
173 compareChanges(changes, observed_changes4); | |
174 callback_count[4]++; | |
175 } | |
176 | |
177 async_test(function(t) { | |
178 var openRequest = indexedDB.open(dbname[4]); | |
179 var obs = new IDBObserver(t.step_func(callback4), { operationTypes: ['put'] }); | |
180 | |
181 openRequest.onupgradeneeded = t.step_func(function() { | |
182 createDatabase(openRequest.result, ['store']); | |
183 }); | |
184 openRequest.onsuccess = t.step_func(function() { | |
185 var db = openRequest.result; | |
186 var tx1 = db.transaction('store', 'readwrite'); | |
187 obs.observe(db, tx1); | |
188 tx1.oncomplete = t.step_func(function() { | |
189 countCallbacks(callback_count[4], 0); | |
190 }); | |
191 tx1.onerror = t.unreached_func('transaction should not fail'); | |
192 | |
193 var openRequest2 = indexedDB.open(dbname[4]); | |
194 openRequest2.onsuccess = t.step_func(function(){ | |
195 var db2 = openRequest2.result; | |
196 var tx2 = db2.transaction('store', 'readwrite'); | |
197 operateOnTx(tx2, put_records); | |
198 tx2.oncomplete = function(){ | |
199 countCallbacks(callback_count[4], 1); | |
200 t.done(); | |
201 } | |
202 tx2.onerror = t.unreached_func('transaction should not fail'); | |
203 }); | |
204 }); | |
205 }, 'Observer : Record changes on another connection'); | |
206 | |
207 var records5_2 = {'store2' : putOps} | |
208 var observed_changes5_1 = { dbName: dbname[5], records: put_records }; | |
209 var observed_changes5_2 = { dbName: dbname[5], records: records5_2 }; | |
210 | |
211 function callback5(changes){ | |
212 assert_true(callback_count[5] < 2); | |
213 if(callback_count[5] == 0) | |
214 compareChanges(changes, observed_changes5_1); | |
215 else | |
216 compareChanges(changes, observed_changes5_2); | |
217 callback_count[5]++; | |
218 } | |
219 | |
220 async_test(function(t) { | |
221 var openRequest = indexedDB.open(dbname[5]); | |
222 var obs = new IDBObserver(t.step_func(callback5), { operationTypes: ['put'] }); | |
223 | |
224 openRequest.onupgradeneeded = t.step_func(function() { | |
225 createDatabase(openRequest.result, [ 'store', 'store2' ]); | |
226 }); | |
227 openRequest.onsuccess = t.step_func(function() { | |
228 var db = openRequest.result; | |
229 var tx1 = db.transaction([ 'store', 'store2'], 'readwrite'); | |
230 var tx2 = db.transaction('store', 'readwrite'); | |
231 | |
232 obs.observe(db, tx1); | |
233 tx1.objectStore('store').get(1); | |
234 t.step_func(operateOnTx(tx2, put_records)); | |
235 | |
236 tx1.oncomplete = t.step_func(function() { | |
237 countCallbacks(callback_count[5], 0); | |
238 }); | |
239 tx1.onerror = t.unreached_func('transaction should not fail'); | |
240 tx2.oncomplete = t.step_func(function(){ | |
241 countCallbacks(callback_count[5], 1); | |
242 var tx3 = db.transaction('store2', 'readwrite'); | |
243 t.step_func(operateOnTx(tx3, records5_2)); | |
244 | |
245 tx3.oncomplete = t.step_func(function(){ | |
246 countCallbacks(callback_count[5], 2); | |
247 t.done(); | |
248 }); | |
249 tx3.onerror = t.unreached_func('transaction should not fail'); | |
250 }); | |
251 tx2.onerror = t.unreached_func('transaction should not fail'); | |
252 | |
253 }); | |
254 }, 'Observer : Record multiple transactions'); | |
255 | |
256 done(); | |
257 })(); | |
OLD | NEW |