| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library test.channel; | 5 library test.channel; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:convert'; | 8 import 'dart:convert'; |
| 9 import 'dart:io'; | 9 import 'dart:io'; |
| 10 | 10 |
| 11 import 'package:analysis_server/src/channel.dart'; | 11 import 'package:analysis_server/src/channel.dart'; |
| 12 import 'package:analysis_server/src/protocol.dart'; | 12 import 'package:analysis_server/src/protocol.dart' hide Error; |
| 13 import 'package:unittest/unittest.dart'; | 13 import 'package:unittest/unittest.dart'; |
| 14 | 14 |
| 15 import 'mocks.dart'; | 15 import 'mocks.dart'; |
| 16 | 16 |
| 17 main() { | 17 main() { |
| 18 group('WebSocketChannel', () { | 18 group('WebSocketChannel', () { |
| 19 setUp(WebSocketChannelTest.setUp); | 19 setUp(WebSocketChannelTest.setUp); |
| 20 test('close', WebSocketChannelTest.close); | 20 test('close', WebSocketChannelTest.close); |
| 21 test('invalidJsonToClient', WebSocketChannelTest.invalidJsonToClient); | 21 test('invalidJsonToClient', WebSocketChannelTest.invalidJsonToClient); |
| 22 test('invalidJsonToServer', WebSocketChannelTest.invalidJsonToServer); | 22 test('invalidJsonToServer', WebSocketChannelTest.invalidJsonToServer); |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 return pumpEventQueue().then((_) { | 243 return pumpEventQueue().then((_) { |
| 244 expect(responses.length, equals(1)); | 244 expect(responses.length, equals(1)); |
| 245 expect(responses[0].id, equals('72')); | 245 expect(responses[0].id, equals('72')); |
| 246 }); | 246 }); |
| 247 } | 247 } |
| 248 | 248 |
| 249 static Future sendRequest() { | 249 static Future sendRequest() { |
| 250 int assertCount = 0; | 250 int assertCount = 0; |
| 251 Request request = new Request('72', 'foo.bar'); | 251 Request request = new Request('72', 'foo.bar'); |
| 252 outputLineStream.first | 252 outputLineStream.first |
| 253 .then((line) => new JsonDecoder().convert(line)) | 253 .then((line) => JSON.decode(line)) |
| 254 .then((json) { | 254 .then((json) { |
| 255 expect(json[Request.ID], equals('72')); | 255 expect(json[Request.ID], equals('72')); |
| 256 expect(json[Request.METHOD], equals('foo.bar')); | 256 expect(json[Request.METHOD], equals('foo.bar')); |
| 257 inputSink.writeln('{"id":"73"}'); | 257 inputSink.writeln('{"id":"73"}'); |
| 258 inputSink.writeln('{"id":"72"}'); | 258 inputSink.writeln('{"id":"72"}'); |
| 259 assertCount++; | 259 assertCount++; |
| 260 }); | 260 }); |
| 261 channel.sendRequest(request) | 261 channel.sendRequest(request) |
| 262 .then((Response response) { | 262 .then((Response response) { |
| 263 expect(response.id, equals('72')); | 263 expect(response.id, equals('72')); |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 channel.sendResponse(new Response('foo')); | 386 channel.sendResponse(new Response('foo')); |
| 387 return outputLineStream.first.timeout(new Duration(seconds: 1)).then((String | 387 return outputLineStream.first.timeout(new Duration(seconds: 1)).then((String |
| 388 response) { | 388 response) { |
| 389 var jsonResponse = new JsonCodec().decode(response); | 389 var jsonResponse = new JsonCodec().decode(response); |
| 390 expect(jsonResponse, isMap); | 390 expect(jsonResponse, isMap); |
| 391 expect(jsonResponse, contains('id')); | 391 expect(jsonResponse, contains('id')); |
| 392 expect(jsonResponse['id'], equals('foo')); | 392 expect(jsonResponse['id'], equals('foo')); |
| 393 }); | 393 }); |
| 394 } | 394 } |
| 395 } | 395 } |
| OLD | NEW |