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

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,16 +43,18 @@
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) {
+ 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() {
@@ -60,22 +64,21 @@
int itemCount = 0;
int sumKeys = 0;
int lastKey = null;
- cursorRequest.on.success.add((e) {
- var cursor = e.target.result;
- if (cursor != null) {
- lastKey = cursor.key;
- itemCount += 1;
- sumKeys += cursor.key;
- Expect.equals('Item ${cursor.key.toStringAsFixed(0)}', cursor.value);
- cursor.continueFunction();
- } else {
- // Done
- Expect.equals(99, lastKey);
- Expect.equals(100, itemCount);
- Expect.equals((100 * 99) ~/ 2, sumKeys);
- callbackDone();
- }
- });
+ cursorRequest.on.success.add(expectAsync1((e) {
+ var cursor = e.target.result;
+ if (cursor != null) {
+ lastKey = cursor.key;
+ itemCount += 1;
+ sumKeys += cursor.key;
+ Expect.equals('Item ${cursor.key.toStringAsFixed(0)}', cursor.value);
+ cursor.continueFunction();
+ } else {
+ // Done
+ Expect.equals(99, lastKey);
+ Expect.equals(100, itemCount);
+ Expect.equals((100 * 99) ~/ 2, sumKeys);
+ }
+ }, 101));
cursorRequest.on.error.add(fail('openCursor'));
}
@@ -87,22 +90,21 @@
int itemCount = 0;
int sumKeys = 0;
int lastKey = null;
- cursorRequest.on.success.add((e) {
- var cursor = e.target.result;
- if (cursor != null) {
- lastKey = cursor.key;
- itemCount += 1;
- sumKeys += cursor.key;
- Expect.equals('Item ${cursor.key}', cursor.value);
- cursor.continueFunction();
- } else {
- // Done
- Expect.equals(0, lastKey); // i.e. first key (scanned in reverse).
- Expect.equals(100, itemCount);
- Expect.equals((100 * 99) ~/ 2, sumKeys);
- callbackDone();
- }
- });
+ cursorRequest.on.success.add(expectAsync1((e) {
+ var cursor = e.target.result;
+ if (cursor != null) {
+ lastKey = cursor.key;
+ itemCount += 1;
+ sumKeys += cursor.key;
+ Expect.equals('Item ${cursor.key}', cursor.value);
+ cursor.continueFunction();
+ } else {
+ // Done
+ Expect.equals(0, lastKey); // i.e. first key (scanned in reverse).
+ Expect.equals(100, itemCount);
+ Expect.equals((100 * 99) ~/ 2, sumKeys);
+ }
+ }, 101));
cursorRequest.on.error.add(fail('openCursor'));
}
}
@@ -110,8 +112,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