| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 /// Tests that Isolate.spawnUri completes with an error when the given URI | 5 /// Tests that Isolate.spawnUri completes with an error when the given URI |
| 6 /// doesn't resolve to an existing resource. | 6 /// doesn't resolve to an existing resource. |
| 7 /// | 7 /// |
| 8 /// This test is similar to spawn_uri_missing_test.dart, but tests what happens | 8 /// This test is similar to spawn_uri_missing_test.dart, but tests what happens |
| 9 /// when Isolate.spawnUri is called from an a spawned isolate. In dart2js, | 9 /// when Isolate.spawnUri is called from an a spawned isolate. In dart2js, |
| 10 /// these two situations are different. | 10 /// these two situations are different. |
| 11 library test.isolate.spawn_uri_missing_from_isolate_test; | 11 library test.isolate.spawn_uri_missing_from_isolate_test; |
| 12 | 12 |
| 13 import 'dart:isolate'; | 13 import 'dart:isolate'; |
| 14 | 14 |
| 15 import 'dart:async'; | 15 import 'dart:async'; |
| 16 | 16 |
| 17 import 'package:async_helper/async_helper.dart'; | 17 import 'package:async_helper/async_helper.dart'; |
| 18 | 18 |
| 19 import 'spawn_uri_missing_test.dart'; | 19 import 'spawn_uri_missing_test.dart'; |
| 20 | 20 |
| 21 const String SUCCESS = 'Test worked.'; | 21 const String SUCCESS = 'Test worked.'; |
| 22 | 22 |
| 23 void isolate(SendPort port) { | 23 void isolate(SendPort port) { |
| 24 doTest().then( | 24 doTest().then((_) => port.send(SUCCESS), |
| 25 (_) => port.send(SUCCESS), | |
| 26 onError: (error, stack) => port.send('Test failed: $error\n$stack')); | 25 onError: (error, stack) => port.send('Test failed: $error\n$stack')); |
| 27 } | 26 } |
| 28 | 27 |
| 29 main() { | 28 main() { |
| 30 ReceivePort port = new ReceivePort(); | 29 ReceivePort port = new ReceivePort(); |
| 31 Isolate.spawn(isolate, port.sendPort); | 30 Isolate.spawn(isolate, port.sendPort); |
| 32 Completer completer = new Completer(); | 31 Completer completer = new Completer(); |
| 33 port.first.then((message) { | 32 port.first.then((message) { |
| 34 if (message == SUCCESS) { | 33 if (message == SUCCESS) { |
| 35 completer.complete(null); | 34 completer.complete(null); |
| 36 } else { | 35 } else { |
| 37 completer.completeError(message); | 36 completer.completeError(message); |
| 38 } | 37 } |
| 39 }); | 38 }); |
| 40 | 39 |
| 41 asyncTest(() => completer.future); | 40 asyncTest(() => completer.future); |
| 42 } | 41 } |
| OLD | NEW |