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 // negative test to ensure that APIv2_unresolvedPortsBrowserTest works. | 5 // negative test to ensure that APIv2_unresolvedPortsBrowserTest works. |
6 #library('unresolved_ports'); | 6 #library('unresolved_ports'); |
7 #import('dart:dom'); // import added so test.dart can treat this as a webtest. | 7 #import('dart:dom'); // import added so test.dart can treat this as a webtest. |
8 #import('dart:isolate'); | 8 #import('dart:isolate'); |
9 #import('../../../lib/unittest/unittest_dom.dart'); | 9 #import('../../../lib/unittest/unittest.dart'); |
| 10 #import('../../../lib/unittest/dom_config.dart'); |
10 | 11 |
11 // This is similar to APIv2_unresolvedPortsStandaloneNegativeTest but using | 12 // This is similar to APIv2_unresolvedPortsStandaloneNegativeTest but using |
12 // 'unittest.dart' so it can run to completion in browsers. | 13 // 'unittest.dart' so it can run to completion in browsers. |
13 | 14 |
14 bethIsolate() { | 15 bethIsolate() { |
15 port.receive((msg, reply) => msg[1].send( | 16 port.receive((msg, reply) => msg[1].send( |
16 '${msg[0]}\nBeth says: Tim are you coming? And Bob?', reply)); | 17 '${msg[0]}\nBeth says: Tim are you coming? And Bob?', reply)); |
17 } | 18 } |
18 | 19 |
19 timIsolate() { | 20 timIsolate() { |
20 SendPort bob = spawnFunction(bobIsolate); | 21 SendPort bob = spawnFunction(bobIsolate); |
21 port.receive((msg, reply) => bob.send( | 22 port.receive((msg, reply) => bob.send( |
22 '$msg\nTim says: Can you tell "main" that we are all coming?', reply)); | 23 '$msg\nTim says: Can you tell "main" that we are all coming?', reply)); |
23 } | 24 } |
24 | 25 |
25 bobIsolate() { | 26 bobIsolate() { |
26 port.receive((msg, reply) => reply.send( | 27 port.receive((msg, reply) => reply.send( |
27 '$msg\nBob says: we are all coming!')); | 28 '$msg\nBob says: we are all coming!')); |
28 } | 29 } |
29 | 30 |
30 main() { | 31 main() { |
| 32 useDomConfiguration(); |
31 asyncTest('Message chain with unresolved ports', 1, () { | 33 asyncTest('Message chain with unresolved ports', 1, () { |
32 ReceivePort port = new ReceivePort(); | 34 ReceivePort port = new ReceivePort(); |
33 port.receive((msg, _) { | 35 port.receive((msg, _) { |
34 expect(msg).equals('main says: Beth, find out if Tim is coming.' | 36 expect(msg).equals('main says: Beth, find out if Tim is coming.' |
35 + '\nBeth says: Tim are you coming? And Bob?' | 37 + '\nBeth says: Tim are you coming? And Bob?' |
36 + '\nTim says: Can you tell "main" that we are all coming?' | 38 + '\nTim says: Can you tell "main" that we are all coming?' |
37 + '\nBob says: we are NOT coming!'); // should be 'all', not 'NOT' | 39 + '\nBob says: we are NOT coming!'); // should be 'all', not 'NOT' |
38 port.close(); | 40 port.close(); |
39 callbackDone(); | 41 callbackDone(); |
40 }); | 42 }); |
41 | 43 |
42 SendPort tim = spawnFunction(timIsolate); | 44 SendPort tim = spawnFunction(timIsolate); |
43 SendPort beth = spawnFunction(bethIsolate); | 45 SendPort beth = spawnFunction(bethIsolate); |
44 | 46 |
45 beth.send( | 47 beth.send( |
46 // because tim is created asynchronously, here we are sending an | 48 // because tim is created asynchronously, here we are sending an |
47 // unresolved port: | 49 // unresolved port: |
48 ['main says: Beth, find out if Tim is coming.', tim], | 50 ['main says: Beth, find out if Tim is coming.', tim], |
49 port.toSendPort()); | 51 port.toSendPort()); |
50 }); | 52 }); |
51 } | 53 } |
OLD | NEW |