| OLD | NEW |
| (Empty) |
| 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 | |
| 5 library DOMIsolatesTest; | |
| 6 import '../../pkg/unittest/lib/unittest.dart'; | |
| 7 import '../../pkg/unittest/lib/html_config.dart'; | |
| 8 import 'dart:html'; | |
| 9 import 'dart:isolate'; | |
| 10 | |
| 11 childDomIsolate() { | |
| 12 port.receive((msg, replyTo) { | |
| 13 if (msg != 'check') { | |
| 14 replyTo.send('wrong msg: $msg'); | |
| 15 } | |
| 16 replyTo.send('${window.location}'); | |
| 17 port.close(); | |
| 18 }); | |
| 19 } | |
| 20 | |
| 21 trampolineIsolate() { | |
| 22 final future = spawnDomFunction(childDomIsolate); | |
| 23 port.receive((msg, parentPort) { | |
| 24 future.then((childPort) { | |
| 25 childPort.call(msg).then((response) { | |
| 26 parentPort.send(response); | |
| 27 port.close(); | |
| 28 }); | |
| 29 }); | |
| 30 }); | |
| 31 } | |
| 32 | |
| 33 dummy() => print('Bad invocation of top-level function'); | |
| 34 | |
| 35 main() { | |
| 36 useHtmlConfiguration(); | |
| 37 | |
| 38 test('Simple DOM isolate test', () { | |
| 39 spawnDomFunction(childDomIsolate).then(expectAsync1( | |
| 40 (sendPort) { | |
| 41 expect(sendPort.call('check'), completion('${window.location}')); | |
| 42 } | |
| 43 )); | |
| 44 }); | |
| 45 | |
| 46 test('Nested DOM isolates test', () { | |
| 47 spawnDomFunction(trampolineIsolate).then(expectAsync1( | |
| 48 (sendPort) { | |
| 49 expect(sendPort.call('check'), completion('${window.location}')); | |
| 50 } | |
| 51 )); | |
| 52 }); | |
| 53 | |
| 54 test('Spawn DOM isolate from pure', () { | |
| 55 expect(spawnFunction(trampolineIsolate).call('check'), | |
| 56 completion('${window.location}')); | |
| 57 }); | |
| 58 | |
| 59 test('Spawn DOM by uri', () { | |
| 60 spawnDomUri('dom_isolates_test.dart.child_isolate.dart').then(expectAsync1( | |
| 61 (sendPort) { | |
| 62 expect(sendPort.call('check'), completion('${window.location}')); | |
| 63 } | |
| 64 )); | |
| 65 }); | |
| 66 | |
| 67 test('Not function', () { | |
| 68 expect(() => spawnDomFunction(42), throws); | |
| 69 }); | |
| 70 | |
| 71 test('Not topLevelFunction', () { | |
| 72 var closure = guardAsync(() {}); | |
| 73 expect(() => spawnDomFunction(closure), throws); | |
| 74 }); | |
| 75 | |
| 76 test('Masked local function', () { | |
| 77 var local = 42; | |
| 78 dummy() => print('Bad invocation of local function: $local'); | |
| 79 expect(() => spawnDomFunction(dummy), throws); | |
| 80 }); | |
| 81 } | |
| OLD | NEW |