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

Side by Side Diff: pkg/analysis_server/test/analysis_server_test.dart

Issue 298823007: add server.status notification (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 7 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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.analysis_server; 5 library test.analysis_server;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analyzer/src/generated/engine.dart'; 9 import 'package:analyzer/src/generated/engine.dart';
10 import 'package:analyzer/src/generated/source_io.dart'; 10 import 'package:analyzer/src/generated/source_io.dart';
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 LineInfo lineInfo = new LineInfo([0]); 72 LineInfo lineInfo = new LineInfo([0]);
73 AnalysisError analysisError = new AnalysisError.con1(source, 73 AnalysisError analysisError = new AnalysisError.con1(source,
74 CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_CONST_SUPER, ['Foo']); 74 CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_CONST_SUPER, ['Foo']);
75 changeNoticeImpl.setErrors([analysisError], lineInfo); 75 changeNoticeImpl.setErrors([analysisError], lineInfo);
76 context.when(callsTo('performAnalysisTask')).thenReturn( 76 context.when(callsTo('performAnalysisTask')).thenReturn(
77 new AnalysisResult([changeNoticeImpl], 0, 'myClass', 0)); 77 new AnalysisResult([changeNoticeImpl], 0, 'myClass', 0));
78 context.when(callsTo('performAnalysisTask')).thenReturn( 78 context.when(callsTo('performAnalysisTask')).thenReturn(
79 new AnalysisResult(null, 0, null, 0)); 79 new AnalysisResult(null, 0, null, 0));
80 return pumpEventQueue().then((_) { 80 return pumpEventQueue().then((_) {
81 context.getLogs(callsTo('performAnalysisTask')).verify(happenedExactly(2)) ; 81 context.getLogs(callsTo('performAnalysisTask')).verify(happenedExactly(2)) ;
82 var notifications = channel.notificationsReceived; 82 List<Notification> notifications = channel.notificationsReceived;
83 expect(notifications, hasLength(2)); 83 expect(notifications, hasLength(4));
84
84 expect(notifications[0].event, equals('server.connected')); 85 expect(notifications[0].event, equals('server.connected'));
85 expect(notifications[1].event, equals('context.errors')); 86
86 expect(notifications[1].params['source'], equals('foo.dart')); 87 assertStatusNotification(notifications[1], true);
87 expect(notifications[1].params['contextId'], equals('context-27')); 88
88 List<AnalysisError> errors = notifications[1].params['errors']; 89 expect(notifications[2].event, equals('context.errors'));
90 expect(notifications[2].params['source'], equals('foo.dart'));
91 expect(notifications[2].params['contextId'], equals('context-27'));
92 List<AnalysisError> errors = notifications[2].params['errors'];
89 expect(errors, hasLength(1)); 93 expect(errors, hasLength(1));
90 expect(errors[0], equals(AnalysisServer.errorToJson(analysisError))); 94 expect(errors[0], equals(AnalysisServer.errorToJson(analysisError)));
95
96 assertStatusNotification(notifications[3], false);
Paul Berry 2014/05/23 15:56:45 Not a problem with this test, but a heads up for l
91 }); 97 });
92 } 98 }
93 99
100 static void assertStatusNotification(Notification notification, bool expectAna lyzing) {
101 expect(notification.event, equals('server.status'));
102 assertNonEmptyString(notification.params['shortMessage']);
103 assertNonEmptyString(notification.params['longMessage']);
104 expect(notification.params['isAnalyzing'], equals(expectAnalyzing));
105 }
106
107 static void assertNonEmptyString(Object message) {
108 if (message is String) {
109 expect(message.length > 0, isTrue);
110 } else {
111 fail('Expected String');
112 }
113 }
114
94 static Future addContextToWorkQueue_twice() { 115 static Future addContextToWorkQueue_twice() {
95 // The context should only be asked to perform its analysis task once. 116 // The context should only be asked to perform its analysis task once.
96 MockAnalysisContext context = new MockAnalysisContext(); 117 MockAnalysisContext context = new MockAnalysisContext();
97 server.addContextToWorkQueue(context); 118 server.addContextToWorkQueue(context);
98 server.addContextToWorkQueue(context); 119 server.addContextToWorkQueue(context);
99 context.when(callsTo('performAnalysisTask')).thenReturn( 120 context.when(callsTo('performAnalysisTask')).thenReturn(
100 new AnalysisResult(null, 0, null, 0)); 121 new AnalysisResult(null, 0, null, 0));
101 return pumpEventQueue().then((_) => 122 return pumpEventQueue().then((_) =>
102 context.getLogs(callsTo('performAnalysisTask')).verify(happenedExactly(1 ))); 123 context.getLogs(callsTo('performAnalysisTask')).verify(happenedExactly(1 )));
103 } 124 }
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 @override 227 @override
207 Response handleRequest(Request request) { 228 Response handleRequest(Request request) {
208 if (request.method == 'echo') { 229 if (request.method == 'echo') {
209 var response = new Response(request.id); 230 var response = new Response(request.id);
210 response.setResult('echo', true); 231 response.setResult('echo', true);
211 return response; 232 return response;
212 } 233 }
213 return null; 234 return null;
214 } 235 }
215 } 236 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698