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

Unified Diff: tests/html/indexeddb_3_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 side-by-side diff with in-line comments
Download patch
Index: tests/html/indexeddb_3_test.dart
===================================================================
--- tests/html/indexeddb_3_test.dart (revision 7823)
+++ tests/html/indexeddb_3_test.dart (working copy)
@@ -15,7 +15,7 @@
start() {
var request = window.webkitIndexedDB.open(DB_NAME);
Expect.isNotNull(request);
- request.on.success.add(initDb);
+ request.on.success.add(expectAsync1(initDb));
request.on.error.add(fail('open'));
}
@@ -25,14 +25,16 @@
// open call and listening to onversionchange. Can we feature-detect the
// difference and make it work?
var request = db.setVersion(VERSION);
- request.on.success.add((e) {
+ request.on.success.add(
+ expectAsync1((e) {
try {
// Nuke object store if it already exists.
db.deleteObjectStore(STORE_NAME);
} catch (IDBDatabaseException e) { }
db.createObjectStore(STORE_NAME);
writeItems(0);
- });
+ })
+ );
request.on.error.add(fail('setVersion error'));
}
@@ -41,19 +43,23 @@
var transaction = db.transaction([STORE_NAME], IDBTransaction.READ_WRITE);
var request = transaction.objectStore(STORE_NAME)
.put('Item $index', index);
- request.on.success.add((e) { writeItems(index + 1); });
+ request.on.success.add(
+ expectAsync1((e) {
Siggi Cherem (dart-lang) 2012/05/21 22:20:47 remove tab, possibly merge with prev line
gram 2012/05/22 17:36:36 Done.
+ writeItems(index + 1);
+ }
+ ));
request.on.error.add(fail('put'));
- } else {
- callbackDone();
}
}
fail(message) => (e) {
- callbackDone();
- Expect.fail('IndexedDB failure: $message');
+ guardAsync(() {
+ Expect.fail('IndexedDB failure: $message');
+ });
};
readAllViaCursor() {
+ var doneCallback = expectAsync0((){});
IDBTransaction txn = db.transaction(STORE_NAME, IDBTransaction.READ_ONLY);
IDBObjectStore objectStore = txn.objectStore(STORE_NAME);
IDBRequest cursorRequest = objectStore.openCursor();
@@ -61,6 +67,7 @@
int sumKeys = 0;
int lastKey = null;
cursorRequest.on.success.add((e) {
Siggi Cherem (dart-lang) 2012/05/21 22:20:47 replace doneCallback with count:100 here and below
gram 2012/05/22 17:36:36 Done.
+ guardAsync(() {
var cursor = e.target.result;
if (cursor != null) {
lastKey = cursor.key;
@@ -73,13 +80,15 @@
Expect.equals(99, lastKey);
Expect.equals(100, itemCount);
Expect.equals((100 * 99) ~/ 2, sumKeys);
- callbackDone();
+ doneCallback();
}
});
+ });
cursorRequest.on.error.add(fail('openCursor'));
}
readAllReversedViaCursor() {
+ var doneCallback = expectAsync0((){});
IDBTransaction txn = db.transaction(STORE_NAME, IDBTransaction.READ_ONLY);
IDBObjectStore objectStore = txn.objectStore(STORE_NAME);
// TODO: create a IDBKeyRange(0,100)
@@ -88,6 +97,7 @@
int sumKeys = 0;
int lastKey = null;
cursorRequest.on.success.add((e) {
+ guardAsync(() {
var cursor = e.target.result;
if (cursor != null) {
lastKey = cursor.key;
@@ -100,9 +110,10 @@
Expect.equals(0, lastKey); // i.e. first key (scanned in reverse).
Expect.equals(100, itemCount);
Expect.equals((100 * 99) ~/ 2, sumKeys);
- callbackDone();
+ doneCallback();
}
});
+ });
cursorRequest.on.error.add(fail('openCursor'));
}
}
@@ -110,8 +121,8 @@
main() {
useHtmlConfiguration();
- var test = new Test();
- asyncTest('prepare', 1, test.start);
- asyncTest('readAll1', 1, test.readAllViaCursor);
- asyncTest('readAll2', 1, test.readAllReversedViaCursor);
+ var test_ = new Test();
+ test('prepare', test_.start);
+ test('readAll1', test_.readAllViaCursor);
+ test('readAll2', test_.readAllReversedViaCursor);
}

Powered by Google App Engine
This is Rietveld 408576698