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

Unified Diff: tests/html/postmessage_structured_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, 11 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
« no previous file with comments | « tests/html/native_gc_test.dart ('k') | tests/html/transferables_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/html/postmessage_structured_test.dart
diff --git a/tests/html/postmessage_structured_test.dart b/tests/html/postmessage_structured_test.dart
index 8581dc280ca6c18cf5e7f4f5a90da94fb249aaa2..b52ecc4573d60c0a132aba1ef91806589b82d2ec 100644
--- a/tests/html/postmessage_structured_test.dart
+++ b/tests/html/postmessage_structured_test.dart
@@ -26,20 +26,18 @@ main() {
final JS_CODE = """
window.postMessage({eggs: 3}, '*');
""";
- var callback;
- var onSuccess = expectAsync1((e) {
- window.on.message.remove(callback);
- });
- callback = (e) {
- guardAsync(() {
- var data = e.data;
- if (data is String) return; // Messages from unit test protocol.
- expect(data, isMap);
- expect(data['eggs'], equals(3));
- onSuccess(e);
- });
- };
- window.on.message.add(callback);
+ var completed = false;
+ var subscription = null;
+ subscription = window.onMessage.listen(expectAsyncUntil1(
+ (e) {
+ var data = e.data;
+ if (data is String) return; // Messages from unit test protocol.
+ completed = true;
+ subscription.cancel();
+ expect(data, isMap);
+ expect(data['eggs'], equals(3));
+ },
+ () => completed));
injectSource(JS_CODE);
});
@@ -58,21 +56,19 @@ main() {
window.postMessage(response, '*');
}
""";
- var callback;
- var onSuccess = expectAsync1((e) {
- window.on.message.remove(callback);
- });
- callback = (e) {
- guardAsync(() {
- var data = e.data;
- if (data is String) return; // Messages from unit test protocol.
- expect(data, isMap);
- if (data['recipient'] != 'DART') return; // Hearing the sent message.
- expect(data['peas'], equals(50));
- onSuccess(e);
- });
- };
- window.on.message.add(callback);
+ var completed = false;
+ var subscription = null;
+ subscription = window.onMessage.listen(expectAsyncUntil1(
+ (e) {
+ var data = e.data;
+ if (data is String) return; // Messages from unit test protocol.
+ if (data['recipient'] != 'DART') return; // Hearing the sent message.
+ completed = true;
+ subscription.cancel();
+ expect(data, isMap);
+ expect(data['peas'], equals(50));
+ },
+ () => completed));
injectSource(JS_CODE);
window.postMessage({'recipient': 'JS', 'curry': 'peas'}, '*');
});
@@ -93,22 +89,21 @@ main() {
window.postMessage(response, '*');
}
""";
- var onSuccess = expectAsync0(() {});
- callback(e) {
- guardAsync(() {
- var data = e.data;
- if (data is String) return; // Messages from unit test protocol.
- expect(data, isMap);
- if (data['recipient'] != 'DART') return; // Not for me.
- var returnedValue = data['data'];
-
- window.on.message.remove(callback);
- expect(returnedValue, isNot(same(value)));
- verifyGraph(value, returnedValue);
- onSuccess();
- });
- };
- window.on.message.add(callback);
+ var completed = false;
+ var subscription = null;
+ subscription = window.onMessage.listen(expectAsyncUntil1(
+ (e) {
+ var data = e.data;
+ if (data is String) return; // Messages from unit test protocol.
Emily Fortuna 2013/01/28 23:15:18 delete one space here and you can get this line ba
+ if (data['recipient'] != 'DART') return; // Not for me.
+ completed = true;
+ subscription.cancel();
+ expect(data, isMap);
+ var returnedValue = data['data'];
+ expect(returnedValue, isNot(same(value)));
+ verifyGraph(value, returnedValue);
+ },
+ () => completed));
injectSource(JS_CODE);
window.postMessage({'recipient': 'JS', 'data': value}, '*');
});
« no previous file with comments | « tests/html/native_gc_test.dart ('k') | tests/html/transferables_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698