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

Side by Side Diff: tests/html/dom_isolates_test.dart

Issue 12887009: Support asynchronuous spawnDomFunction. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 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 library DOMIsolatesTest; 5 library DOMIsolatesTest;
6 import '../../pkg/unittest/lib/unittest.dart'; 6 import '../../pkg/unittest/lib/unittest.dart';
7 import '../../pkg/unittest/lib/html_config.dart'; 7 import '../../pkg/unittest/lib/html_config.dart';
8 import 'dart:html'; 8 import 'dart:html';
9 import 'dart:isolate'; 9 import 'dart:isolate';
10 10
11 isolateMain() { 11 isolateMain() {
12 port.receive((msg, replyTo) { 12 port.receive((msg, replyTo) {
13 if (msg != 'check') { 13 if (msg != 'check') {
14 replyTo.send('wrong msg: $msg'); 14 replyTo.send('wrong msg: $msg');
15 } 15 }
16 replyTo.send('${window.location}'); 16 replyTo.send('${window.location}');
17 port.close(); 17 port.close();
18 }); 18 });
19 } 19 }
20 20
21 isolateMainTrampoline() { 21 isolateMainTrampoline() {
22 final childPort = spawnDomFunction(isolateMain); 22 final future = spawnDomFunction(isolateMain);
23 port.receive((msg, parentPort) { 23 port.receive((msg, parentPort) {
24 childPort.call(msg).then((response) { 24 future.then((childPort) {
25 parentPort.send(response); 25 childPort.call(msg).then((response) {
26 port.close(); 26 parentPort.send(response);
27 port.close();
28 });
27 }); 29 });
28 }); 30 });
29 } 31 }
30 32
31 dummy() => print("Bad invocation of top-level function"); 33 dummy() => print("Bad invocation of top-level function");
32 34
33 main() { 35 main() {
34 useHtmlConfiguration(); 36 useHtmlConfiguration();
35 37
36 test('Simple DOM isolate test', () { 38 test('Simple DOM isolate test', () {
37 spawnDomFunction(isolateMain).call('check').then( 39 spawnDomFunction(isolateMain).then((sendPort) {
38 expectAsync1((msg) { 40 sendPort.call('check').then(
39 expect(msg, equals('${window.location}')); 41 expectAsync1((msg) {
40 })); 42 expect(msg, equals('${window.location}'));
43 }));
44 });
41 }); 45 });
42 46
43 test('Nested DOM isolates test', () { 47 test('Nested DOM isolates test', () {
44 spawnDomFunction(isolateMainTrampoline).call('check').then( 48 spawnDomFunction(isolateMainTrampoline).then((sendPort) {
45 expectAsync1((msg) { 49 sendPort.call('check').then(
46 expect(msg, equals('${window.location}')); 50 expectAsync1((msg) {
47 })); 51 expect(msg, equals('${window.location}'));
52 }));
53 });
48 }); 54 });
49 55
50 test('Not function', () { 56 test('Not function', () {
51 expect(() => spawnDomFunction(42), throws); 57 expect(() => spawnDomFunction(42), throws);
52 }); 58 });
53 59
54 test('Not topLevelFunction', () { 60 test('Not topLevelFunction', () {
55 var closure = guardAsync(() {}); 61 var closure = guardAsync(() {});
56 expect(() => spawnDomFunction(closure), throws); 62 expect(() => spawnDomFunction(closure), throws);
57 }); 63 });
58 64
59 test('Masked local function', () { 65 test('Masked local function', () {
60 var local = 42; 66 var local = 42;
61 dummy() => print("Bad invocation of local function: $local"); 67 dummy() => print("Bad invocation of local function: $local");
62 expect(() => spawnDomFunction(dummy), throws); 68 expect(() => spawnDomFunction(dummy), throws);
63 }); 69 });
64 } 70 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698