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

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

Issue 13238003: Add a test for spawning DOM isolate from a pure one. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 8 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 childDomIsolate() {
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 trampolineIsolate() {
22 final future = spawnDomFunction(isolateMain); 22 final future = spawnDomFunction(childDomIsolate);
23 port.receive((msg, parentPort) { 23 port.receive((msg, parentPort) {
24 future.then((childPort) { 24 future.then((childPort) {
25 childPort.call(msg).then((response) { 25 childPort.call(msg).then((response) {
26 parentPort.send(response); 26 parentPort.send(response);
27 port.close(); 27 port.close();
28 }); 28 });
29 }); 29 });
30 }); 30 });
31 } 31 }
32 32
33 dummy() => print("Bad invocation of top-level function"); 33 dummy() => print('Bad invocation of top-level function');
34 34
35 main() { 35 main() {
36 useHtmlConfiguration(); 36 useHtmlConfiguration();
37 37
38 test('Simple DOM isolate test', () { 38 test('Simple DOM isolate test', () {
39 spawnDomFunction(isolateMain).then((sendPort) { 39 spawnDomFunction(childDomIsolate).then((sendPort) {
40 sendPort.call('check').then( 40 expect(sendPort.call('check'), completion('${window.location}'));
41 expectAsync1((msg) {
42 expect(msg, equals('${window.location}'));
43 }));
44 }); 41 });
45 }); 42 });
46 43
47 test('Nested DOM isolates test', () { 44 test('Nested DOM isolates test', () {
48 spawnDomFunction(isolateMainTrampoline).then((sendPort) { 45 spawnDomFunction(trampolineIsolate).then((sendPort) {
49 sendPort.call('check').then( 46 expect(sendPort.call('check'), completion('${window.location}'));
50 expectAsync1((msg) {
51 expect(msg, equals('${window.location}'));
52 }));
53 }); 47 });
54 }); 48 });
55 49
50 test('Spawn DOM isolate from pure', () {
51 expect(spawnFunction(trampolineIsolate).call('check'),
52 completion('${window.location}'));
53 });
54
56 test('Not function', () { 55 test('Not function', () {
57 expect(() => spawnDomFunction(42), throws); 56 expect(() => spawnDomFunction(42), throws);
58 }); 57 });
59 58
60 test('Not topLevelFunction', () { 59 test('Not topLevelFunction', () {
61 var closure = guardAsync(() {}); 60 var closure = guardAsync(() {});
62 expect(() => spawnDomFunction(closure), throws); 61 expect(() => spawnDomFunction(closure), throws);
63 }); 62 });
64 63
65 test('Masked local function', () { 64 test('Masked local function', () {
66 var local = 42; 65 var local = 42;
67 dummy() => print("Bad invocation of local function: $local"); 66 dummy() => print('Bad invocation of local function: $local');
68 expect(() => spawnDomFunction(dummy), throws); 67 expect(() => spawnDomFunction(dummy), throws);
69 }); 68 });
70 } 69 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698