Index: tests/html/js_interop_3_test.dart |
diff --git a/tests/html/js_interop_3_test.dart b/tests/html/js_interop_3_test.dart |
new file mode 100644 |
index 0000000000000000000000000000000000000000..df40d1e13100dc3d85d3a40ea6844ab9e6657192 |
--- /dev/null |
+++ b/tests/html/js_interop_3_test.dart |
@@ -0,0 +1,57 @@ |
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
+// for details. All rights reserved. Use of this source code is governed by a |
+// BSD-style license that can be found in the LICENSE file |
+ |
+#library('JsInterop3Test'); |
+#import('../../lib/unittest/unittest.dart'); |
+#import('../../lib/unittest/html_config.dart'); |
+#import('dart:html'); |
+#import('dart:isolate'); |
+ |
+injectSource(code) { |
+ final script = new ScriptElement(); |
+ script.type = 'text/javascript'; |
+ script.innerHTML = code; |
+ document.body.nodes.add(script); |
+} |
+ |
+var jsToDart = """ |
+ var fun1 = window.lookupPort('fun1'); |
+ var result = fun1.callSync({'a': 'Hello', 'b': 'World', c: 42}); |
+ |
+ var fun2 = window.lookupPort('fun2'); |
+ fun2.callSync(result); |
+"""; |
+ |
+main() { |
+ useHtmlConfiguration(); |
+ |
+ test('js-to-dart', () { |
+ var done = expectAsync0(() {}); |
+ |
+ var fun1 = (message) { |
+ Expect.equals('Hello', message['a']); |
+ Expect.equals('World', message['b']); |
+ Expect.equals(42, message['c']); |
+ Expect.equals(3, message.getKeys().length); |
+ return 42; |
+ }; |
+ |
+ var port1 = new ReceivePortSync(); |
+ port1.receive(fun1); |
+ window.registerPort('fun1', port1.toSendPort()); |
+ |
+ var fun2 = (message) { |
+ Expect.equals(42, message); |
+ |
+ // TODO(vsm): Investigate why this needs to be called asynchronously. |
+ window.setTimeout(done, 0); |
+ }; |
+ |
+ var port2 = new ReceivePortSync(); |
+ port2.receive(fun2); |
+ window.registerPort('fun2', port2.toSendPort()); |
+ |
+ injectSource(jsToDart); |
+ }); |
+} |