Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(27)

Unified Diff: pkg/analysis_server/test/channel_test.dart

Issue 182903005: split client and server channels (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: address comments Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/analysis_server/lib/src/protocol.dart ('k') | pkg/analysis_server/test/mocks.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..0c639ad64a3259b0b3aa50e7120c05d5a776d96c
--- /dev/null
+++ b/pkg/analysis_server/test/channel_test.dart
@@ -0,0 +1,105 @@
+// 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() {
+ group('Channel', () {
+ test('invalidJsonToClient', ChannelTest.invalidJsonToClient);
+ 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'));
+ }
+}
« no previous file with comments | « pkg/analysis_server/lib/src/protocol.dart ('k') | pkg/analysis_server/test/mocks.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698