OLD | NEW |
| (Empty) |
1 #import('../../../../../dart/client/testing/unittest/unittest.dart'); | |
2 #import('dart:dom'); | |
3 #import('dart:json'); | |
4 | |
5 class PingPongIsolate extends Isolate { | |
6 PingPongIsolate() : super.heavy(); | |
7 | |
8 void main() { | |
9 bool wasThrown = false; | |
10 try { | |
11 window.alert('Test'); | |
12 } catch(final e) { | |
13 wasThrown = true; | |
14 } | |
15 // If wasn't thrown, do not listen to messages to make test fail. | |
16 if (!wasThrown) { | |
17 return; | |
18 } | |
19 | |
20 // Check that JSON library was loaded to isolate. | |
21 JSON.stringify([1, 2, 3]); | |
22 | |
23 port.receive((message, replyTo) { | |
24 replyTo.send(responseFor(message), null); | |
25 }); | |
26 } | |
27 | |
28 static String responseFor(message) => 'response for $message'; | |
29 } | |
30 | |
31 main() { | |
32 forLayoutTests(); | |
33 asyncTest('IsolateSpawn', 1, () { | |
34 new PingPongIsolate().spawn().then((SendPort port) { | |
35 callbackDone(); | |
36 }); | |
37 }); | |
38 asyncTest('NonDOMIsolates', 1, () { | |
39 new PingPongIsolate().spawn().then((SendPort port) { | |
40 final msg1 = 'foo'; | |
41 final msg2 = 'bar'; | |
42 port.call(msg1).receive((response, _) { | |
43 Expect.equals(PingPongIsolate.responseFor(msg1), response); | |
44 port.call(msg2).receive((response, _) { | |
45 Expect.equals(PingPongIsolate.responseFor(msg2), response); | |
46 callbackDone(); | |
47 }); | |
48 }); | |
49 }); | |
50 }); | |
51 } | |
OLD | NEW |