Chromium Code Reviews| Index: pkg/analysis_server/test/channel_test.dart |
| diff --git a/pkg/analysis_server/test/channel_test.dart b/pkg/analysis_server/test/channel_test.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..307e94f36e9b7bf31a537a05c6dca3dfd96f7cea |
| --- /dev/null |
| +++ b/pkg/analysis_server/test/channel_test.dart |
| @@ -0,0 +1,103 @@ |
| +// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| + |
| +library test.channel; |
| + |
| +import 'package:analysis_server/src/protocol.dart'; |
| +import 'package:unittest/matcher.dart'; |
| +import 'package:unittest/unittest.dart'; |
| +import 'package:analysis_server/src/channel.dart'; |
| +import 'mocks.dart'; |
| + |
| +main() { |
| + test('invalidJsonToClient', ChannelTest.invalidJsonToClient); |
|
Brian Wilkerson
2014/02/27 19:06:02
Put these in a group? I'm guessing that it will ma
danrubel
2014/02/27 20:21:14
Good point. Done.
|
| + test('invalidJsonToServer', ChannelTest.invalidJsonToServer); |
| + test('notification', ChannelTest.notification); |
| + test('request', ChannelTest.request); |
| + test('response', ChannelTest.response); |
| +} |
| + |
| +class ChannelTest { |
| + |
| + static void invalidJsonToClient() { |
| + InvalidJsonMockSocket mockSocket = new InvalidJsonMockSocket(); |
| + WebSocketClientChannel client = new WebSocketClientChannel(mockSocket); |
| + var responsesReceived = new List(); |
| + var notificationsReceived = new List(); |
| + client.listen((Response response) => responsesReceived.add(response), |
| + (Notification notification) => notificationsReceived.add(notification)); |
| + |
| + mockSocket.addInvalid('"blat"'); |
| + mockSocket.addInvalid('{foo:bar}'); |
| + |
| + expect(responsesReceived.length, equals(0)); |
| + expect(notificationsReceived.length, equals(0)); |
| + expect(mockSocket.responseCount, equals(0)); |
| + } |
| + |
| + static void invalidJsonToServer() { |
| + InvalidJsonMockSocket mockSocket = new InvalidJsonMockSocket(); |
| + WebSocketServerChannel server = new WebSocketServerChannel(mockSocket); |
| + var received = new List(); |
| + server.listen((Request request) => received.add(request)); |
| + |
| + mockSocket.addInvalid('"blat"'); |
| + mockSocket.addInvalid('{foo:bar}'); |
| + |
| + expect(received.length, equals(0)); |
| + expect(mockSocket.responseCount, equals(2)); |
| + } |
| + |
| + static void notification() { |
| + MockSocket mockSocket = new MockSocket(); |
| + WebSocketClientChannel client = new WebSocketClientChannel(mockSocket); |
| + WebSocketServerChannel server = new WebSocketServerChannel(mockSocket); |
| + var responsesReceived = new List(); |
| + var notificationsReceived = new List(); |
| + client.listen((Response response) => responsesReceived.add(response), |
| + (Notification notification) => notificationsReceived.add(notification)); |
| + |
| + server.sendNotification(new Notification('myEvent')); |
| + |
| + expect(responsesReceived.length, equals(0)); |
| + expect(notificationsReceived.length, equals(1)); |
| + expect(notificationsReceived.first.runtimeType, equals(Notification)); |
| + Notification actual = notificationsReceived.first; |
| + expect(actual.event, equals('myEvent')); |
| + } |
| + |
| + static void request() { |
| + MockSocket mockSocket = new MockSocket(); |
| + WebSocketClientChannel client = new WebSocketClientChannel(mockSocket); |
| + WebSocketServerChannel server = new WebSocketServerChannel(mockSocket); |
| + var requestsReceived = new List(); |
| + server.listen((Request request) => requestsReceived.add(request)); |
| + |
| + client.sendRequest(new Request('myId', 'aMethod')); |
| + |
| + expect(requestsReceived.length, equals(1)); |
| + expect(requestsReceived.first.runtimeType, equals(Request)); |
| + Request actual = requestsReceived.first; |
| + expect(actual.id, equals('myId')); |
| + expect(actual.method, equals('aMethod')); |
| + } |
| + |
| + static void response() { |
| + MockSocket mockSocket = new MockSocket(); |
| + WebSocketClientChannel client = new WebSocketClientChannel(mockSocket); |
| + WebSocketServerChannel server = new WebSocketServerChannel(mockSocket); |
| + var responsesReceived = new List(); |
| + var notificationsReceived = new List(); |
| + client.listen((Response response) => responsesReceived.add(response), |
| + (Notification notification) => notificationsReceived.add(notification)); |
| + |
| + server.sendResponse(new Response('myId')); |
| + |
| + expect(responsesReceived.length, equals(1)); |
| + expect(notificationsReceived.length, equals(0)); |
| + expect(responsesReceived.first.runtimeType, equals(Response)); |
| + Response actual = responsesReceived.first; |
| + expect(actual.id, equals('myId')); |
| + } |
| +} |