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

Unified Diff: tests/html/js_interop_func_passing_test.dart

Issue 10834426: Support general serializing of functions between JS and Dart (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address review comments Created 8 years, 4 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 | « lib/isolate/serialization.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/html/js_interop_func_passing_test.dart
diff --git a/tests/html/js_interop_func_passing_test.dart b/tests/html/js_interop_func_passing_test.dart
index 70f8204b87601c73c4be72c205ef8b1d8e7ae4da..74aff0fba9e3aaa52fccffc9506cdceb5b668b80 100644
--- a/tests/html/js_interop_func_passing_test.dart
+++ b/tests/html/js_interop_func_passing_test.dart
@@ -15,25 +15,83 @@ injectSource(code) {
document.body.nodes.add(script);
}
-var isolateTest = """
+var dartToJsTest = """
var port = new ReceivePortSync();
port.receive(function (f) {
return f('fromJS');
});
- window.registerPort('test', port.toSendPort());
+ window.registerPort('test1', port.toSendPort());
+""";
+
+var jsToDartTest = """
+ var port1 = window.lookupPort('test2a');
+ var result = port1.callSync(function (x) {
+ return x*2;
+ });
+
+ var port2 = window.lookupPort('test2b');
+ port2.callSync(result);
+""";
+
+var dartToJsToDartTest = """
+ var port = new ReceivePortSync();
+ port.receive(function (f) {
+ return f;
+ });
+ window.registerPort('test3', port.toSendPort());
""";
main() {
useHtmlConfiguration();
test('dart-to-js-function', () {
- injectSource(isolateTest);
+ injectSource(dartToJsTest);
- SendPortSync port = window.lookupPort('test');
+ SendPortSync port = window.lookupPort('test1');
var result = port.callSync((msg) {
Expect.equals('fromJS', msg);
return 'received';
});
Expect.equals('received', result);
});
+
+ test('js-to-dart-function', () {
+ var port1 = new ReceivePortSync();
+ int invoked1 = 0;
+ port1.receive((f) {
+ ++invoked1;
+ var data = f(21);
+ expect(data, equals(42));
+ return 'fromDart';
+ });
+ window.registerPort('test2a', port1.toSendPort());
+
+ var port2 = new ReceivePortSync();
+ int invoked2 = 0;
+ port2.receive((x) {
+ ++invoked2;
+ expect(x, equals('fromDart'));
+ });
+ window.registerPort('test2b', port2.toSendPort());
+
+ injectSource(jsToDartTest);
+
+ expect(1, equals(invoked1));
+ expect(1, equals(invoked2));
+ });
+
+ test('dart-to-js-to-dart-function', () {
+ injectSource(dartToJsToDartTest);
+
+ validate(x) {
+ expect(x, equals('fromCaller'));
+ return 'fromCallee';
+ }
+
+ SendPortSync port = window.lookupPort('test3');
+ var f = port.callSync(validate);
+ var result = f('fromCaller');
+ Expect.equals('fromCallee', result);
+
+ });
}
« no previous file with comments | « lib/isolate/serialization.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698