OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 import 'dart:html'; | 5 import 'dart:html'; |
6 import 'dart:isolate'; | 6 import 'dart:isolate'; |
7 | 7 |
8 import 'package:unittest/unittest.dart'; | 8 import 'package:unittest/unittest.dart'; |
9 import 'package:unittest/html_config.dart'; | 9 import 'package:unittest/html_config.dart'; |
10 | 10 |
11 worker() { | 11 worker(message) { |
12 port.receive((String uri, SendPort replyTo) { | 12 var uri = message[0]; |
13 try { | 13 var replyTo = message[1]; |
14 var url = Url.createObjectUrl(new Blob([''], 'application/javascript')); | 14 try { |
15 Url.revokeObjectUrl(url); | 15 var url = Url.createObjectUrl(new Blob([''], 'application/javascript')); |
16 replyTo.send('Hello from Worker'); | 16 Url.revokeObjectUrl(url); |
17 } catch (e) { | 17 replyTo.send('Hello from Worker'); |
18 replyTo.send('Error: $e'); | 18 } catch (e) { |
19 } | 19 replyTo.send('Error: $e'); |
20 port.close(); | 20 } |
21 }); | |
22 } | 21 } |
23 | 22 |
24 main() { | 23 main() { |
25 useHtmlConfiguration(); | 24 useHtmlConfiguration(); |
26 | 25 |
27 test('Use Worker API in Worker', () { | 26 test('Use Worker API in Worker', () { |
28 spawnFunction(worker).call('').then( | 27 var response = new ReceivePort(); |
29 expectAsync1((reply) => expect(reply, equals('Hello from Worker')))); | 28 var remote = Isolate.spawn(worker, ['', response.sendPort]); |
| 29 remote.then((_) => response.first) |
| 30 .then(expectAsync1((reply) => expect(reply, equals('Hello from Worker'))
)); |
30 }); | 31 }); |
31 } | 32 } |
OLD | NEW |