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

Unified Diff: tests/dom/indexeddb_4_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/dom/indexeddb_4_test.dart
===================================================================
--- tests/dom/indexeddb_4_test.dart (revision 7823)
+++ tests/dom/indexeddb_4_test.dart (working copy)
@@ -15,7 +15,8 @@
start() {
var request = window.webkitIndexedDB.open(DB_NAME);
Expect.isNotNull(request);
- request.addEventListener('success', initDb);
+ request.addEventListener('success',
+ expectAsync1(initDb));
request.addEventListener('error', fail('open'));
}
@@ -25,14 +26,15 @@
// open call and listening to onversionchange. Can we feature-detect the
// difference and make it work?
var request = db.setVersion(VERSION);
- request.addEventListener('success', (e) {
+ request.addEventListener('success',
+ expectAsync1( (e) {
Siggi Cherem (dart-lang) 2012/05/21 22:20:47 remove extra space ( (
gram 2012/05/22 17:36:36 Done.
try {
// Nuke object store if it already exists.
db.deleteObjectStore(STORE_NAME);
} catch (IDBDatabaseException e) { }
db.createObjectStore(STORE_NAME);
writeItems(0);
- });
+ }));
request.addEventListener('blocked', fail('setVersion blocked'));
request.addEventListener('error', fail('setVersion error'));
}
@@ -42,16 +44,16 @@
var transaction = db.transaction([STORE_NAME], IDBTransaction.READ_WRITE);
var request = transaction.objectStore(STORE_NAME)
.put('Item $index', index);
- request.addEventListener('success', (e) { writeItems(index + 1); });
+ request.addEventListener('success',
+ expectAsync1( (e) { writeItems(index + 1); }));
Siggi Cherem (dart-lang) 2012/05/21 22:20:47 ditto
gram 2012/05/22 17:36:36 Done.
request.addEventListener('error', fail('put'));
- } else {
- callbackDone();
}
}
fail(message) => (e) {
- callbackDone();
- Expect.fail('IndexedDB failure: $message');
+ guardAsync(() {
+ Expect.fail('IndexedDB failure: $message');
+ });
};
testRange(range, expectedFirst, expectedLast) {
@@ -61,26 +63,32 @@
int itemCount = 0;
num firstKey = null;
num lastKey = null;
- cursorRequest.addEventListener("success", (e) {
- var cursor = e.target.result;
- if (cursor != null) {
- if (firstKey == null) firstKey = cursor.key;
- lastKey = cursor.key;
- itemCount += 1;
- Expect.equals('Item ${cursor.key.toStringAsFixed(0)}', cursor.value);
- cursor.continueFunction();
- } else {
- // Done
- Expect.equals(expectedFirst, firstKey);
- Expect.equals(expectedLast, lastKey);
- if (expectedFirst == null) {
- Expect.equals(0, itemCount);
+ var doneCallback = expectAsync0((){});
Siggi Cherem (dart-lang) 2012/05/21 22:20:47 here also you could do without doneCallback: expec
gram 2012/05/22 17:36:36 Done.
+ cursorRequest.addEventListener("success",
+ (e) {
+ guardAsync(() {
+ var cursor = e.target.result;
+ if (cursor != null) {
+ if (firstKey == null) firstKey = cursor.key;
+ lastKey = cursor.key;
+ itemCount += 1;
+ Expect.equals('Item ${cursor.key.toStringAsFixed(0)}',
+ cursor.value);
+ cursor.continueFunction();
} else {
- Expect.equals(expectedLast - expectedFirst + 1, itemCount);
+ // Done
+ Expect.equals(expectedFirst, firstKey);
+ Expect.equals(expectedLast, lastKey);
+ if (expectedFirst == null) {
+ Expect.equals(0, itemCount);
+ } else {
+ Expect.equals(expectedLast - expectedFirst + 1, itemCount);
+ }
+ doneCallback();
}
- callbackDone();
- }
- });
+ });
+ }
+ );
cursorRequest.addEventListener('error', fail('openCursor'));
}
@@ -117,25 +125,25 @@
main() {
useDomConfiguration();
- var test = new Test();
- asyncTest('prepare', 1, test.start);
+ var test_ = new Test();
+ test('prepare', test_.start);
- asyncTest('only1', 1, test.only1);
- asyncTest('only2', 1, test.only2);
- asyncTest('only3', 1, test.only3);
+ test('only1', test_.only1);
+ test('only2', test_.only2);
+ test('only3', test_.only3);
- asyncTest('lower1', 1, test.lower1);
- asyncTest('lower2', 1, test.lower2);
- asyncTest('lower3', 1, test.lower3);
+ test('lower1', test_.lower1);
+ test('lower2', test_.lower2);
+ test('lower3', test_.lower3);
- asyncTest('upper1', 1, test.upper1);
- asyncTest('upper2', 1, test.upper2);
- asyncTest('upper3', 1, test.upper3);
+ test('upper1', test_.upper1);
+ test('upper2', test_.upper2);
+ test('upper3', test_.upper3);
- asyncTest('bound1', 1, test.bound1);
- asyncTest('bound2', 1, test.bound2);
- asyncTest('bound3', 1, test.bound3);
- asyncTest('bound4', 1, test.bound4);
- asyncTest('bound5', 1, test.bound5);
+ test('bound1', test_.bound1);
+ test('bound2', test_.bound2);
+ test('bound3', test_.bound3);
+ test('bound4', test_.bound4);
+ test('bound5', test_.bound5);
}

Powered by Google App Engine
This is Rietveld 408576698