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

Unified Diff: tests/html/js_interop_4_test.dart

Issue 10695111: Add support for JS->Dart and Dart->dart via *PortSync. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments Created 8 years, 5 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/js_interop_3_test.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_4_test.dart
diff --git a/tests/html/js_interop_4_test.dart b/tests/html/js_interop_4_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..f161b5df751821fb32f6ba7b786b53770779f289
--- /dev/null
+++ b/tests/html/js_interop_4_test.dart
@@ -0,0 +1,70 @@
+// 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('JsInterop4Test');
+#import('../../lib/unittest/unittest.dart');
+#import('../../lib/unittest/html_config.dart');
+#import('dart:html');
+#import('dart:isolate');
+
+const testData = const [1, '2', 'true'];
+
+class TestIsolate extends Isolate {
+ TestIsolate() : super();
+
+ void main() {
+ var fun1 = window.lookupPort('fun1');
+ var result = fun1.callSync(testData);
+
+ var fun2 = window.lookupPort('fun2');
+ fun2.callSync(result);
+ }
+}
+
+main() {
+ useHtmlConfiguration();
+
+ // Test that our interop scheme also works from Dart to Dart.
+ test('dart-to-dart-same-isolate', () {
+ var fun = expectAsync1((message) {
+ Expect.listEquals(testData, message);
+ return message.length;
+ });
+
+ var port1 = new ReceivePortSync();
+ port1.receive(fun);
+ window.registerPort('fun', port1.toSendPort());
+
+ var port2 = window.lookupPort('fun');
+ var result = port2.callSync(testData);
+ Expect.equals(3, result);
+ });
+
+ // Test across isolate boundary.
+ test('dart-to-dart-cross-isolate', () {
+ var done = expectAsync0(() {});
+
+ var fun1 = (message) {
+ Expect.listEquals(testData, message);
+ return message.length;
+ };
+
+ var port1 = new ReceivePortSync();
+ port1.receive(fun1);
+ window.registerPort('fun1', port1.toSendPort());
+
+ var fun2 = (message) {
+ Expect.equals(3, 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());
+
+ new TestIsolate().spawn().then((p) {});
+ });
+}
« no previous file with comments | « tests/html/js_interop_3_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698