Files
sdk/tests/html/isolates_test.dart
T
gram@google.com 981c4b11df Restructure pkg/unittest and pkg/webdriver to follow the pub conventions.
This means all imports of unittest in our test code had to change to include 'lib' in the path.
While doing that change I changed the library/imports to the new syntax in the affected files.
Review URL: https://codereview.chromium.org//11301046

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@14443 260f80e4-7a28-3924-810f-c04153c831b5
2012-11-01 23:09:47 +00:00

53 lines
1.2 KiB
Dart

library IsolatesTest;
import '../../pkg/unittest/lib/unittest.dart';
import '../../pkg/unittest/lib/html_config.dart';
import 'dart:html';
import 'dart:json';
import 'dart:isolate' as isolate;
String responseFor(message) => 'response for $message';
void isolateEntry() {
bool wasThrown = false;
try {
window.alert('Test');
} catch (e) {
wasThrown = true;
}
// If wasn't thrown, do not listen to messages to make test fail.
if (!wasThrown) {
return;
}
// Check that JSON library was loaded to isolate.
JSON.stringify([1, 2, 3]);
isolate.port.receive((message, replyTo) {
replyTo.send(responseFor(message), null);
});
}
main() {
useHtmlConfiguration();
test('IsolateSpawn', () {
isolate.spawnFunction(isolateEntry);
});
test('NonDOMIsolates', () {
var callback = expectAsync0((){});
var port = isolate.spawnFunction(isolateEntry);
final msg1 = 'foo';
final msg2 = 'bar';
port.call(msg1).then((response) {
guardAsync(() {
expect(response, equals(responseFor(msg1)));
port.call(msg2).then((response) {
guardAsync(() {
expect(response, equals(responseFor(msg2)));
callback();
});
});
});
});
});
}