Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(194)

Side by Side Diff: tests/isolate/src/APIv2_unresolvedPortsBrowserNegativeTest.dart

Issue 9521007: isolates: remove Isolate2 interface, add top-level spawn functions, more comments (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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("../../../client/testing/unittest/unittest.dart"); 9 #import('../../../client/testing/unittest/unittest.dart');
10 10
11 // This is similar as SpawnFromCodeAPIv2Test but using 'unittest.dart' so it can 11 // This is similar to APIv2_unresolvedPortsStandaloneNegativeTest but using
12 // run to completion in browsers. 12 // 'unittest.dart' so it can run to completion in browsers.
13 13
14 bethIsolate(ReceivePort port) { 14 bethIsolate() {
15 port.receive((msg, reply) => msg[1].send( 15 port.receive((msg, reply) => msg[1].send(
16 "${msg[0]}\nBeth says: Tim are you coming? And Bob?", reply)); 16 '${msg[0]}\nBeth says: Tim are you coming? And Bob?', reply));
17 } 17 }
18 18
19 timIsolate(ReceivePort port) { 19 timIsolate() {
20 Isolate2 bob = new Isolate2.fromCode(bobIsolate); 20 SendPort bob = spawnFunction(bobIsolate);
21 port.receive((msg, reply) => bob.sendPort.send( 21 port.receive((msg, reply) => bob.send(
22 "$msg\nTim says: Can you tell 'main' that we are all coming?", reply)); 22 '$msg\nTim says: Can you tell "main" that we are all coming?', reply));
23 } 23 }
24 24
25 bobIsolate(ReceivePort port) { 25 bobIsolate() {
26 port.receive((msg, reply) => reply.send( 26 port.receive((msg, reply) => reply.send(
27 "$msg\nBob says: we are all coming!")); 27 '$msg\nBob says: we are all coming!'));
28 } 28 }
29 29
30 main() { 30 main() {
31 asyncTest("Message chain with unresolved ports", 1, () { 31 asyncTest('Message chain with unresolved ports', 1, () {
32 ReceivePort port = new ReceivePort(); 32 ReceivePort port = new ReceivePort();
33 port.receive((msg, _) { 33 port.receive((msg, _) {
34 expect(msg).equals("main says: Beth, find out if Tim is coming." 34 expect(msg).equals('main says: Beth, find out if Tim is coming.'
35 + "\nBeth says: Tim are you coming? And Bob?" 35 + '\nBeth says: Tim are you coming? And Bob?'
36 + "\nTim says: Can you tell 'main' that we are all coming?" 36 + '\nTim says: Can you tell "main" that we are all coming?'
37 + "\nBob says: we are NOT coming!"); // should be 'all', not 'NOT' 37 + '\nBob says: we are NOT coming!'); // should be 'all', not 'NOT'
38 port.close(); 38 port.close();
39 callbackDone(); 39 callbackDone();
40 }); 40 });
41 41
42 Isolate2 tim = new Isolate2.fromCode(timIsolate); 42 SendPort tim = spawnFunction(timIsolate);
43 Isolate2 beth = new Isolate2.fromCode(bethIsolate); 43 SendPort beth = spawnFunction(bethIsolate);
44 44
45 beth.sendPort.send( 45 beth.send(
46 // because tim is created asynchronously, here we are sending an 46 // because tim is created asynchronously, here we are sending an
47 // unresolved port: 47 // unresolved port:
48 ["main says: Beth, find out if Tim is coming.", tim.sendPort], 48 ['main says: Beth, find out if Tim is coming.', tim],
49 port.toSendPort()); 49 port.toSendPort());
50 }); 50 });
51 } 51 }
OLDNEW
« no previous file with comments | « tests/isolate/src/APIv2_spawnUriChildIsolate.dart ('k') | tests/isolate/src/APIv2_unresolvedPortsBrowserTest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698