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

Side by Side Diff: third_party/WebKit/LayoutTests/storage/indexeddb/resources/generic-idb-operations.js

Issue 2125213002: [IndexedDB] Propogating changes to observers : Renderer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lifetime
Patch Set: Options constrcutor modified 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 }
4
5 function compareChanges(actual, expected) {
6 assert_equals(actual.database.name, expected.dbName, 'The change record databa se should be the same as the database being acted on');
7 assert_equals(actual.records.size, expected.records.size, 'Incorrect number of objectStores recorded by observer');
8 expected.records.forEach(function(obsv, key) {
9 assert_true(actual.records.has(key));
10 var actual_obsv = actual.records.get(key);
11 assert_equals(actual_obsv.length, obsv.length, 'Number of observations recor ded for objectStore '+key+ 'should match observed operations');
12 for (i in obsv)
13 compareObservations(actual_obsv[i], obsv[i]);
14 });
15 }
16
17 function compareObservations(actual, expected) {
18 assert_equals(actual.type, expected.type);
19 if (actual.type == 'clear') {
20 assert_equals(actual.key, undefined, 'clear operation has no key');
21 assert_equals(actual.value, null, 'clear operation has no value');
22 return;
23 }
24 // TODO(palakj): Type should return 'delete' instead of 'kDelete', once fixed. Issue crbug.com/609934.
25 if (actual.type == 'kDelete') {
26 assert_equals(actual.key.lower, expected.key.lower, 'Observed operation key lower bound should match operation performed');
27 assert_equals(actual.key.upper, expected.key.upper, 'Observed operation key upper bound should match operation performed');
28 assert_equals(actual.key.lower_open, expected.key.lower_open, 'Observed oper ation key lower open should match operation performed');
29 assert_equals(actual.key.upper_open, expected.key.upper_open, 'Observed oper ation key upper open should match operation performed');
30 // TODO(palakj): Value needs to be updated, once returned correctly. Issue c rbug.com/609934.
31 assert_equals(actual.value, null, 'Delete operation has no value');
32 return;
33 }
34 assert_equals(actual.key.lower, expected.key, 'Observed operation key lower bo und should match operation performed');
35 assert_equals(actual.key.upper, expected.key, 'Observed operation key upper bo und should match operation performed');
36 // TODO(palakj): Value needs to be updated, once returned correctly. Issue crb ug.com/609934.
37 assert_equals(actual.value, null, 'Put/Add operation value does not match');
38 }
39
40 function countCallbacks(actual, expected){
41 assert_equals(actual, expected, 'Number of callbacks fired for observer should match number of transactions it observed')
42 }
43
44 function createDatabase(db, stores) {
45 for (i in stores)
46 db.createObjectStore(stores[i]);
47 }
48
49 function operateOnDbName(dbName, stores, operations) {
50 var openRequest = indexedDB.open(dbName);
51 openRequest.onsuccess = function() {
52 var db = openRequest.result;
53 operateOnDb(db, stores, operations);
54 }
55 }
56
57 function operateOnDb(db, stores, operations) {
58 var tx = db.transaction(stores, 'readwrite');
59 for(var i in stores){
60 var store = tx.objectStore(stores[i]);
61 operateOnStore(store, operations);
62 }
63 }
64
65 function operateOnStore(store, operations) {
66 for (i in operations ) {
67 var op = operations[i];
68 assert_in_array(op.type, ['put', 'add', 'delete', 'clear', 'get'], 'Operatio n type not defined');
69 if (op.type == 'put')
70 store.put(op.value, op.key);
71 else if (op.type == 'add')
72 store.add(op.value, op.key);
73 else if (op.type == 'delete')
74 store.delete(IDBKeyRange.bound(op.key.lower, op.key.upper));
75 else if (op.type == 'clear')
76 store.clear();
77 else
78 store.get(op.key)
79 }
80 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698