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

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: 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
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'));
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698