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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tests/html/js_interop_3_test.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file
4
5 #library('JsInterop4Test');
6 #import('../../lib/unittest/unittest.dart');
7 #import('../../lib/unittest/html_config.dart');
8 #import('dart:html');
9 #import('dart:isolate');
10
11 const testData = const [1, '2', 'true'];
12
13 class TestIsolate extends Isolate {
14 TestIsolate() : super();
15
16 void main() {
17 var fun1 = window.lookupPort('fun1');
18 var result = fun1.callSync(testData);
19
20 var fun2 = window.lookupPort('fun2');
21 fun2.callSync(result);
22 }
23 }
24
25 main() {
26 useHtmlConfiguration();
27
28 // Test that our interop scheme also works from Dart to Dart.
29 test('dart-to-dart-same-isolate', () {
30 var fun = expectAsync1((message) {
31 Expect.listEquals(testData, message);
32 return message.length;
33 });
34
35 var port1 = new ReceivePortSync();
36 port1.receive(fun);
37 window.registerPort('fun', port1.toSendPort());
38
39 var port2 = window.lookupPort('fun');
40 var result = port2.callSync(testData);
41 Expect.equals(3, result);
42 });
43
44 // Test across isolate boundary.
45 test('dart-to-dart-cross-isolate', () {
46 var done = expectAsync0(() {});
47
48 var fun1 = (message) {
49 Expect.listEquals(testData, message);
50 return message.length;
51 };
52
53 var port1 = new ReceivePortSync();
54 port1.receive(fun1);
55 window.registerPort('fun1', port1.toSendPort());
56
57 var fun2 = (message) {
58 Expect.equals(3, message);
59
60 // TODO(vsm): Investigate why this needs to be called asynchronously.
61 window.setTimeout(done, 0);
62 };
63
64 var port2 = new ReceivePortSync();
65 port2.receive(fun2);
66 window.registerPort('fun2', port2.toSendPort());
67
68 new TestIsolate().spawn().then((p) {});
69 });
70 }
OLDNEW
« 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