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

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

Issue 10412015: aChange all asyncTest/callbackDone style tests to use the new expectAsync/ (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 7 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('../../lib/unittest/unittest.dart'); 2 #import('../../lib/unittest/unittest.dart');
3 #import('../../lib/unittest/html_config.dart'); 3 #import('../../lib/unittest/html_config.dart');
4 #import('dart:html'); 4 #import('dart:html');
5 #import('dart:coreimpl'); 5 #import('dart:coreimpl');
6 #import('utils.dart'); 6 #import('utils.dart');
7 7
8 // Write and re-read Maps: simple Maps; Maps with DAGs; Maps with cycles. 8 // Write and re-read Maps: simple Maps; Maps with DAGs; Maps with cycles.
9 9
10 final String DB_NAME = 'Test'; 10 final String DB_NAME = 'Test';
11 final String STORE_NAME = 'TEST'; 11 final String STORE_NAME = 'TEST';
12 final String VERSION = '1'; 12 final String VERSION = '1';
13 13
14 testReadWrite(key, value, check, 14 testReadWrite(key, value, check,
15 [dbName = DB_NAME, 15 [dbName = DB_NAME,
16 storeName = STORE_NAME, 16 storeName = STORE_NAME,
17 version = VERSION]) => () { 17 version = VERSION]) => () {
18 var db; 18 var db;
19 19
20 fail(e) { 20 fail(e) {
21 callbackDone(); 21 guardAsync(() {
22 Expect.fail('IndexedDB failure'); 22 Expect.fail('IndexedDB failure');
23 });
23 } 24 }
24 25
25 createObjectStore() { 26 createObjectStore() {
26 var store = db.createObjectStore(storeName); 27 var store = db.createObjectStore(storeName);
27 Expect.isNotNull(store); 28 Expect.isNotNull(store);
28 } 29 }
29 30
30 step2() { 31 step2(e) {
31 var transaction = db.transaction(storeName, IDBTransaction.READ_ONLY); 32 var transaction = db.transaction(storeName, IDBTransaction.READ_ONLY);
32 var request = transaction.objectStore(storeName).getObject(key); 33 var request = transaction.objectStore(storeName).getObject(key);
33 request.on.success.add((e) { 34 request.on.success.add(
35 expectAsync1((e) {
Siggi Cherem (dart-lang) 2012/05/21 22:20:47 style-nit: I'd keep the expectAsync1((e) { in the
gram 2012/05/22 17:36:36 Done.
34 var object = e.target.result; 36 var object = e.target.result;
35 check(value, object); 37 check(value, object);
36 callbackDone(); 38 })
37 }); 39 );
38 request.on.error.add(fail); 40 request.on.error.add(fail);
39 } 41 }
40 42
41 step1() { 43 step1() {
42 var transaction = db.transaction([storeName], IDBTransaction.READ_WRITE); 44 var transaction = db.transaction([storeName], IDBTransaction.READ_WRITE);
43 var request = transaction.objectStore(storeName).put(value, key); 45 var request = transaction.objectStore(storeName).put(value, key);
44 request.on.success.add((e) { step2(); }); 46 request.on.success.add(expectAsync1(step2));
45 request.on.error.add(fail); 47 request.on.error.add(fail);
46 } 48 }
47 49
48 initDb(e) { 50 initDb(e) {
49 db = e.target.result; 51 db = e.target.result;
50 if (version != db.version) { 52 if (version != db.version) {
51 // TODO. Some browsers do this the w3 way - passing the version to the 53 // TODO. Some browsers do this the w3 way - passing the version to the
52 // open call and listening to onversionchange. Can we feature-detect the 54 // open call and listening to onversionchange. Can we feature-detect the
53 // difference and make it work? 55 // difference and make it work?
54 var request = db.setVersion(version); 56 var request = db.setVersion(version);
55 request.on.success.add((e) { createObjectStore(); step1(); }); 57 request.on.success.add(
58 expectAsync1((e) {
59 createObjectStore();
60 step1();
61 })
62 );
56 request.on.error.add(fail); 63 request.on.error.add(fail);
57 } else { 64 } else {
58 step1(); 65 step1();
59 } 66 }
60 } 67 }
61 68
62 var request = window.webkitIndexedDB.open(dbName); 69 var request = window.webkitIndexedDB.open(dbName);
63 Expect.isNotNull(request); 70 Expect.isNotNull(request);
64 request.on.success.add(initDb); 71 request.on.success.add(expectAsync1(initDb));
65 request.on.error.add(fail); 72 request.on.error.add(fail);
66 }; 73 };
67 74
68 75
69 tests_dynamic() { 76 tests_dynamic() {
70 var obj1 = {'a': 100, 'b': 's'}; 77 var obj1 = {'a': 100, 'b': 's'};
71 var obj2 = {'x': obj1, 'y': obj1}; // DAG. 78 var obj2 = {'x': obj1, 'y': obj1}; // DAG.
72 79
73 var obj3 = {}; 80 var obj3 = {};
74 obj3['a'] = 100; 81 obj3['a'] = 100;
75 obj3['b'] = obj3; // Cycle. 82 obj3['b'] = obj3; // Cycle.
76 83
77 var obj4 = new SplayTreeMap<String, Dynamic>(); // Different implementation. 84 var obj4 = new SplayTreeMap<String, Dynamic>(); // Different implementation.
78 obj4['a'] = 100; 85 obj4['a'] = 100;
79 obj4['b'] = 's'; 86 obj4['b'] = 's';
80 87
81 asyncTest('test_simple', 1, testReadWrite(123, obj1, verifyGraph)); 88 test('test_simple', testReadWrite(123, obj1, verifyGraph));
82 asyncTest('test_DAG', 1, testReadWrite(123, obj2, verifyGraph)); 89 test('test_DAG', testReadWrite(123, obj2, verifyGraph));
83 asyncTest('test_cycle', 1, testReadWrite(123, obj3, verifyGraph)); 90 test('test_cycle', testReadWrite(123, obj3, verifyGraph));
84 asyncTest('test_simple_splay', 1, testReadWrite(123, obj4, verifyGraph)); 91 test('test_simple_splay', testReadWrite(123, obj4, verifyGraph));
85 } 92 }
86 93
87 main() { 94 main() {
88 useHtmlConfiguration(); 95 useHtmlConfiguration();
89 96
90 tests_dynamic(); 97 tests_dynamic();
91 } 98 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698