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