Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #library('DOMIsolatesTest'); | 1 #library('DOMIsolatesTest'); |
| 2 #import('../../lib/unittest/unittest.dart'); | 2 #import('../../lib/unittest/unittest.dart'); |
| 3 #import('../../lib/unittest/html_config.dart'); | 3 #import('../../lib/unittest/html_config.dart'); |
| 4 #import('dart:html'); | 4 #import('dart:html'); |
| 5 #import('dart:isolate'); | 5 #import('dart:isolate'); |
| 6 | 6 |
| 7 isolateMain(port) { | 7 isolateMain() { |
| 8 port.receive((msg, replyTo) { | 8 port.receive((msg, replyTo) { |
| 9 if (msg != 'check') { | 9 if (msg != 'check') { |
| 10 replyTo.send('wrong msg: $msg'); | 10 replyTo.send('wrong msg: $msg'); |
| 11 } | 11 } |
| 12 replyTo.send(window.location.toString()); | 12 replyTo.send(42); |
|
Anton Muhin
2012/08/07 12:55:29
why it's 42? Intent of window.location.toString()
vsm
2012/08/10 00:06:43
Good point. I changed it because it's no longer '
| |
| 13 port.close(); | 13 port.close(); |
| 14 }); | 14 }); |
| 15 } | 15 } |
| 16 | 16 |
| 17 isolateMainTrampoline(port) { | 17 isolateMainTrampoline() { |
| 18 final childPortFuture = spawnDomIsolate(window, 'isolateMain'); | 18 final childPort = spawnDomFunction(isolateMain); |
| 19 port.receive((msg, parentPort) { | 19 port.receive((msg, parentPort) { |
| 20 childPortFuture.then((childPort) { | 20 childPort.call(msg).then((response) { |
| 21 childPort.call(msg).then((response) { | 21 parentPort.send(response); |
| 22 parentPort.send(response); | 22 port.close(); |
| 23 port.close(); | |
| 24 }); | |
| 25 }); | 23 }); |
| 26 }); | 24 }); |
| 27 } | 25 } |
| 28 | 26 |
| 27 dummy() => print("Bad invocation of top-level function"); | |
| 28 | |
| 29 main() { | 29 main() { |
| 30 useHtmlConfiguration(); | 30 useHtmlConfiguration(); |
| 31 | 31 |
| 32 final iframe = new Element.tag('iframe'); | |
| 33 document.body.nodes.add(iframe); | |
| 34 | |
| 35 test('Simple DOM isolate test', () { | 32 test('Simple DOM isolate test', () { |
| 36 spawnDomIsolate(iframe.contentWindow, 'isolateMain').then( | 33 var sendPort = spawnDomFunction(isolateMain); |
| 37 expectAsync1((sendPort) { | 34 sendPort.call('check').then( |
| 38 sendPort.call('check').then( | 35 expectAsync1((msg) { |
| 39 expectAsync1((msg) { | 36 expect(msg, equals(42)); |
| 40 Expect.equals('about:blank', msg); | |
| 41 })); | |
| 42 })); | 37 })); |
| 43 }); | 38 }); |
| 44 | 39 |
| 45 test('Nested DOM isolates test', () { | 40 test('Nested DOM isolates test', () { |
| 46 spawnDomIsolate(iframe.contentWindow, 'isolateMainTrampoline').then( | 41 var sendPort = spawnDomFunction(isolateMainTrampoline); |
|
Anton Muhin
2012/08/07 12:55:29
do you need sendPort at all? spawnDomFunction(iso
vsm
2012/08/10 00:06:43
Done.
| |
| 47 expectAsync1((sendPort) { | 42 sendPort.call('check').then( |
| 48 sendPort.call('check').then( | 43 expectAsync1((msg) { |
| 49 expectAsync1((msg) { | 44 expect(msg, equals(42)); |
| 50 Expect.equals('about:blank', msg); | |
| 51 })); | |
| 52 })); | 45 })); |
| 53 }); | 46 }); |
|
Siggi Cherem (dart-lang)
2012/08/03 17:30:57
one more case to test would be a static method in
vsm
2012/08/10 00:06:43
I'll add in a separate CL.
On 2012/08/03 17:30:57
| |
| 54 | 47 |
| 55 test('Null as target window', () { | 48 test('Not function', () { |
| 56 expectThrow(() => spawnDomIsolate(null, 'isolateMain')); | 49 expect(() => spawnDomFunction(42), throws); |
| 57 }); | 50 }); |
| 58 | 51 |
| 59 test('Not window as target window', () { | 52 test('Not topLevelFunction', () { |
| 60 expectThrow(() => spawnDomIsolate(document, 'isolateMain')); | 53 var closure = guardAsync(() {}); |
| 54 expect(() => spawnDomFunction(closure), throws); | |
| 61 }); | 55 }); |
| 56 | |
| 57 // TODO(vsm): Enable when 4337 is fixed. | |
| 58 if (false) { | |
| 59 test('Masked local function', () { | |
| 60 var local = 42; | |
| 61 dummy() => print("Bad invocation of local function: $local"); | |
| 62 expect(() => spawnDomFunction(dummy), throws); | |
| 63 }); | |
| 64 } | |
| 62 } | 65 } |
| OLD | NEW |