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

Side by Side Diff: tests/html/indexeddb_2_test.dart

Issue 12040059: Converting tests over to using event streams. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 10 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 | Annotate | Revision Log
OLDNEW
1 library IndexedDB1Test; 1 library IndexedDB1Test;
2 import '../../pkg/unittest/lib/unittest.dart'; 2 import '../../pkg/unittest/lib/unittest.dart';
3 import '../../pkg/unittest/lib/html_config.dart'; 3 import '../../pkg/unittest/lib/html_config.dart';
4 import 'dart:html' as html; 4 import 'dart:html' as html;
5 import 'dart:indexed_db' as idb; 5 import 'dart:indexed_db' as idb;
6 import 'dart:collection'; 6 import 'dart:collection';
7 import 'utils.dart'; 7 import 'utils.dart';
8 8
9 // Write and re-read Maps: simple Maps; Maps with DAGs; Maps with cycles. 9 // Write and re-read Maps: simple Maps; Maps with DAGs; Maps with cycles.
10 10
(...skipping 14 matching lines...) Expand all
25 } 25 }
26 26
27 createObjectStore(db) { 27 createObjectStore(db) {
28 var store = db.createObjectStore(storeName); 28 var store = db.createObjectStore(storeName);
29 expect(store, isNotNull); 29 expect(store, isNotNull);
30 } 30 }
31 31
32 step2(e) { 32 step2(e) {
33 var transaction = db.transaction(storeName, 'readonly'); 33 var transaction = db.transaction(storeName, 'readonly');
34 var request = transaction.objectStore(storeName).getObject(key); 34 var request = transaction.objectStore(storeName).getObject(key);
35 request.on.success.add(expectAsync1((e) { 35 request.onSuccess.listen(expectAsync1((e) {
36 var object = e.target.result; 36 var object = e.target.result;
37 db.close(); 37 db.close();
38 check(value, object); 38 check(value, object);
39 })); 39 }));
40 request.on.error.add(fail); 40 request.onError.listen(fail);
41 } 41 }
42 42
43 step1() { 43 step1() {
44 var transaction = db.transaction([storeName], 'readwrite'); 44 var transaction = db.transaction([storeName], 'readwrite');
45 var request = transaction.objectStore(storeName).put(value, key); 45 var request = transaction.objectStore(storeName).put(value, key);
46 request.on.success.add(expectAsync1(step2)); 46 request.onSuccess.listen(expectAsync1(step2));
47 request.on.error.add(fail); 47 request.onError.listen(fail);
48 } 48 }
49 49
50 initDb(e) { 50 initDb(e) {
51 db = e.target.result; 51 db = e.target.result;
52 if (version != db.version) { 52 if (version != db.version) {
53 // Legacy 'setVersion' upgrade protocol. 53 // Legacy 'setVersion' upgrade protocol.
54 var request = db.setVersion('$version'); 54 var request = db.setVersion('$version');
55 request.on.success.add( 55 request.onSuccess.listen(
56 expectAsync1((e) { 56 expectAsync1((e) {
57 createObjectStore(db); 57 createObjectStore(db);
58 var transaction = e.target.result; 58 var transaction = e.target.result;
59 transaction.on.complete.add(expectAsync1((e) => step1())); 59 transaction.onComplete.listen(expectAsync1((e) => step1()));
60 transaction.on.error.add(fail); 60 transaction.onError.listen(fail);
61 }) 61 })
62 ); 62 );
63 request.on.error.add(fail); 63 request.onError.listen(fail);
64 } else { 64 } else {
65 step1(); 65 step1();
66 } 66 }
67 } 67 }
68 68
69 openDb(e) { 69 openDb(e) {
70 var request = html.window.indexedDB.open(dbName, version); 70 var request = html.window.indexedDB.open(dbName, version);
71 expect(request, isNotNull); 71 expect(request, isNotNull);
72 request.on.success.add(expectAsync1(initDb)); 72 request.onSuccess.listen(expectAsync1(initDb));
73 request.on.error.add(fail); 73 request.onError.listen(fail);
74 if (request is idb.OpenDBRequest) { 74 if (request is idb.OpenDBRequest) {
75 // New upgrade protocol. Old API has no 'upgradeNeeded' and uses 75 // New upgrade protocol. Old API has no 'upgradeNeeded' and uses
76 // setVersion instead. 76 // setVersion instead.
77 request.on.upgradeNeeded.add((e) { 77 request.onUpgradeNeeded.listen((e) {
78 guardAsync(() { 78 guardAsync(() {
79 createObjectStore(e.target.result); 79 createObjectStore(e.target.result);
80 }); 80 });
81 }); 81 });
82 } 82 }
83 } 83 }
84 84
85 // Delete any existing DB. 85 // Delete any existing DB.
86 var deleteRequest = html.window.indexedDB.deleteDatabase(dbName); 86 var deleteRequest = html.window.indexedDB.deleteDatabase(dbName);
87 deleteRequest.on.success.add(expectAsync1(openDb)); 87 deleteRequest.onSuccess.listen(expectAsync1(openDb));
88 deleteRequest.on.error.add(fail); 88 deleteRequest.onError.listen(fail);
89 }; 89 };
90 90
91 91
92 main() { 92 main() {
93 useHtmlConfiguration(); 93 useHtmlConfiguration();
94 94
95 var obj1 = {'a': 100, 'b': 's'}; 95 var obj1 = {'a': 100, 'b': 's'};
96 var obj2 = {'x': obj1, 'y': obj1}; // DAG. 96 var obj2 = {'x': obj1, 'y': obj1}; // DAG.
97 97
98 var obj3 = {}; 98 var obj3 = {};
(...skipping 30 matching lines...) Expand all
129 go('test_DAG', obj2); 129 go('test_DAG', obj2);
130 go('test_cycle', obj3); 130 go('test_cycle', obj3);
131 go('test_simple_splay', obj4); 131 go('test_simple_splay', obj4);
132 go('const_array_1', const [const [1], const [2]]); 132 go('const_array_1', const [const [1], const [2]]);
133 go('const_array_dag', const [const [1], const [1]]); 133 go('const_array_dag', const [const [1], const [1]]);
134 go('array_deferred_copy', [1,2,3, obj3, obj3, 6]); 134 go('array_deferred_copy', [1,2,3, obj3, obj3, 6]);
135 go('array_deferred_copy_2', [1,2,3, [4, 5, obj3], [obj3, 6]]); 135 go('array_deferred_copy_2', [1,2,3, [4, 5, obj3], [obj3, 6]]);
136 go('cyclic_list', cyclic_list); 136 go('cyclic_list', cyclic_list);
137 } 137 }
138 } 138 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698