mirror of
https://github.com/dart-lang/sdk
synced 2024-10-14 12:58:05 +00:00
4283c3e41e
R=sigmund@google.com Review URL: https://codereview.chromium.org//231413003 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@34890 260f80e4-7a28-3924-810f-c04153c831b5
43 lines
1 KiB
Dart
43 lines
1 KiB
Dart
library WebSocketTest;
|
|
import 'package:unittest/unittest.dart';
|
|
import 'package:unittest/html_individual_config.dart';
|
|
import 'dart:html';
|
|
|
|
main() {
|
|
|
|
useHtmlIndividualConfiguration();
|
|
|
|
group('supported', () {
|
|
test('supported', () {
|
|
expect(WebSocket.supported, true);
|
|
});
|
|
});
|
|
|
|
group('websocket', () {
|
|
var isWebSocket = predicate((x) => x is WebSocket, 'is a WebSocket');
|
|
var expectation = WebSocket.supported ? returnsNormally : throws;
|
|
|
|
test('constructorTest', () {
|
|
expect(() {
|
|
var socket = new WebSocket('ws://localhost/ws', 'chat');
|
|
expect(socket, isNotNull);
|
|
expect(socket, isWebSocket);
|
|
}, expectation);
|
|
});
|
|
|
|
if (WebSocket.supported) {
|
|
test('echo', () {
|
|
var socket = new WebSocket('ws://${window.location.host}/ws');
|
|
|
|
socket.onOpen.first.then((_) {
|
|
socket.send('hello!');
|
|
});
|
|
|
|
return socket.onMessage.first.then((MessageEvent e) {
|
|
expect(e.data, 'hello!');
|
|
});
|
|
});
|
|
}
|
|
});
|
|
}
|