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