OLD | NEW |
---|---|
(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']; | |
kasperl
2012/07/06 07:48:47
This is really new syntax (I don't think this is s
| |
12 | |
13 class TestIsolate extends Isolate { | |
kasperl
2012/07/06 07:48:47
This way of creating isolates is deprecated. Any r
| |
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); | |
kasperl
2012/07/06 07:48:47
Indentation.
| |
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(() {}); | |
kasperl
2012/07/06 07:48:47
Maybe move this down to the TODO?
| |
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) {}); | |
kasperl
2012/07/06 07:48:47
Hmm. Why do you call 'then' at all?
| |
69 }); | |
70 } | |
OLD | NEW |