| OLD | NEW |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file |
| 4 |
| 1 #library('DOMIsolatesTest'); | 5 #library('DOMIsolatesTest'); |
| 2 #import('../../lib/unittest/unittest.dart'); | 6 #import('../../lib/unittest/unittest.dart'); |
| 3 #import('../../lib/unittest/html_config.dart'); | 7 #import('../../lib/unittest/html_config.dart'); |
| 4 #import('dart:html'); | 8 #import('dart:html'); |
| 5 #import('dart:isolate'); | 9 #import('dart:isolate'); |
| 6 | 10 |
| 7 isolateMain(port) { | 11 isolateMain() { |
| 8 port.receive((msg, replyTo) { | 12 port.receive((msg, replyTo) { |
| 9 if (msg != 'check') { | 13 if (msg != 'check') { |
| 10 replyTo.send('wrong msg: $msg'); | 14 replyTo.send('wrong msg: $msg'); |
| 11 } | 15 } |
| 12 replyTo.send(window.location.toString()); | 16 replyTo.send('${window.location}'); |
| 13 port.close(); | 17 port.close(); |
| 14 }); | 18 }); |
| 15 } | 19 } |
| 16 | 20 |
| 17 isolateMainTrampoline(port) { | 21 isolateMainTrampoline() { |
| 18 final childPortFuture = spawnDomIsolate(window, 'isolateMain'); | 22 final childPort = spawnDomFunction(isolateMain); |
| 19 port.receive((msg, parentPort) { | 23 port.receive((msg, parentPort) { |
| 20 childPortFuture.then((childPort) { | 24 childPort.call(msg).then((response) { |
| 21 childPort.call(msg).then((response) { | 25 parentPort.send(response); |
| 22 parentPort.send(response); | 26 port.close(); |
| 23 port.close(); | |
| 24 }); | |
| 25 }); | 27 }); |
| 26 }); | 28 }); |
| 27 } | 29 } |
| 28 | 30 |
| 31 dummy() => print("Bad invocation of top-level function"); |
| 32 |
| 29 main() { | 33 main() { |
| 30 useHtmlConfiguration(); | 34 useHtmlConfiguration(); |
| 31 | 35 |
| 32 final iframe = new Element.tag('iframe'); | |
| 33 document.body.nodes.add(iframe); | |
| 34 | |
| 35 test('Simple DOM isolate test', () { | 36 test('Simple DOM isolate test', () { |
| 36 spawnDomIsolate(iframe.contentWindow, 'isolateMain').then( | 37 spawnDomFunction(isolateMain).call('check').then( |
| 37 expectAsync1((sendPort) { | 38 expectAsync1((msg) { |
| 38 sendPort.call('check').then( | 39 expect(msg, equals('${window.location}')); |
| 39 expectAsync1((msg) { | |
| 40 Expect.equals('about:blank', msg); | |
| 41 })); | |
| 42 })); | 40 })); |
| 43 }); | 41 }); |
| 44 | 42 |
| 45 test('Nested DOM isolates test', () { | 43 test('Nested DOM isolates test', () { |
| 46 spawnDomIsolate(iframe.contentWindow, 'isolateMainTrampoline').then( | 44 spawnDomFunction(isolateMainTrampoline).call('check').then( |
| 47 expectAsync1((sendPort) { | 45 expectAsync1((msg) { |
| 48 sendPort.call('check').then( | 46 expect(msg, equals('${window.location}')); |
| 49 expectAsync1((msg) { | |
| 50 Expect.equals('about:blank', msg); | |
| 51 })); | |
| 52 })); | 47 })); |
| 53 }); | 48 }); |
| 54 | 49 |
| 55 test('Null as target window', () { | 50 test('Not function', () { |
| 56 expect(() => spawnDomIsolate(null, 'isolateMain'), throws); | 51 expect(() => spawnDomFunction(42), throws); |
| 57 }); | 52 }); |
| 58 | 53 |
| 59 test('Not window as target window', () { | 54 test('Not topLevelFunction', () { |
| 60 expect(() => spawnDomIsolate(document, 'isolateMain'), throws); | 55 var closure = guardAsync(() {}); |
| 56 expect(() => spawnDomFunction(closure), throws); |
| 57 }); |
| 58 |
| 59 test('Masked local function', () { |
| 60 var local = 42; |
| 61 dummy() => print("Bad invocation of local function: $local"); |
| 62 expect(() => spawnDomFunction(dummy), throws); |
| 61 }); | 63 }); |
| 62 } | 64 } |
| OLD | NEW |