| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2013, 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 import "dart:platform" as platform; | |
| 6 | |
| 7 import "dart:isolate"; | |
| 8 import "package:unittest/unittest.dart"; | |
| 9 | |
| 10 sendReceive(SendPort port, msg) { | |
| 11 var response = new ReceivePort(); | |
| 12 port.send([msg, response.sendPort]); | |
| 13 return response.first; | |
| 14 } | |
| 15 | |
| 16 main() { | |
| 17 test("platform in isolate", () { | |
| 18 var response = new ReceivePort(); | |
| 19 Isolate.spawn(f, response.sendPort); | |
| 20 response.first.then(expectAsync1((sendPort) { | |
| 21 expect(sendReceive(sendPort, "platform.executable"), | |
| 22 completion(platform.executable)); | |
| 23 if (platform.script != null) { | |
| 24 expect(sendReceive(sendPort, "platform.script").then((s) => s.path), | |
| 25 completion(endsWith('tests/lib/platform/isolate_test.dart'))); | |
| 26 } | |
| 27 expect(sendReceive(sendPort, "platform.packageRoot"), | |
| 28 completion(platform.packageRoot)); | |
| 29 expect(sendReceive(sendPort, "platform.executableArguments"), | |
| 30 completion(platform.executableArguments)); | |
| 31 })); | |
| 32 }); | |
| 33 } | |
| 34 | |
| 35 void f(initialReplyTo) { | |
| 36 var port = new ReceivePort(); | |
| 37 initialReplyTo.send(port.sendPort); | |
| 38 int count = 0; | |
| 39 port.listen((msg) { | |
| 40 var data = msg[0]; | |
| 41 var replyTo = msg[1]; | |
| 42 if (data == "platform.executable") { | |
| 43 replyTo.send(platform.executable); | |
| 44 } | |
| 45 if (data == "platform.script") { | |
| 46 replyTo.send(platform.script); | |
| 47 } | |
| 48 if (data == "platform.packageRoot") { | |
| 49 replyTo.send(platform.packageRoot); | |
| 50 } | |
| 51 if (data == "platform.executableArguments") { | |
| 52 replyTo.send(platform.executableArguments); | |
| 53 } | |
| 54 count++; | |
| 55 if (count == 4) { | |
| 56 port.close(); | |
| 57 } | |
| 58 }); | |
| 59 } | |
| OLD | NEW |