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

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

Issue 587783003: Replace AnalysisServerListener with Stream. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 3 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.domain.execution; 5 library test.domain.execution;
6 6
7 import 'package:analyzer/file_system/physical_file_system.dart'; 7 import 'package:analyzer/file_system/physical_file_system.dart';
8 import 'package:analysis_server/src/analysis_server.dart'; 8 import 'package:analysis_server/src/analysis_server.dart';
9 import 'package:analysis_server/src/constants.dart'; 9 import 'package:analysis_server/src/constants.dart';
10 import 'package:analysis_server/src/domain_execution.dart'; 10 import 'package:analysis_server/src/domain_execution.dart';
11 import 'package:analysis_server/src/protocol.dart'; 11 import 'package:analysis_server/src/protocol.dart';
12 import 'mock_sdk.dart'; 12 import 'mock_sdk.dart';
13 import 'package:unittest/unittest.dart'; 13 import 'package:unittest/unittest.dart';
14 14
15 import 'mocks.dart'; 15 import 'mocks.dart';
16 import 'operation/operation_queue_test.dart'; 16 import 'operation/operation_queue_test.dart';
17 import 'package:typed_mock/typed_mock.dart'; 17 import 'package:typed_mock/typed_mock.dart';
18 import 'package:analyzer/src/generated/engine.dart'; 18 import 'package:analyzer/src/generated/engine.dart';
19 import 'package:analyzer/src/generated/source.dart'; 19 import 'package:analyzer/src/generated/source.dart';
20 import 'dart:async';
20 21
21 main() { 22 main() {
22 group('ExecutionDomainHandler', () { 23 group('ExecutionDomainHandler', () {
23 AnalysisServer server; 24 AnalysisServer server;
24 ExecutionDomainHandler handler; 25 ExecutionDomainHandler handler;
25 26
26 setUp(() { 27 setUp(() {
27 server = new AnalysisServer( 28 server = new AnalysisServer(
28 new MockServerChannel(), 29 new MockServerChannel(),
29 PhysicalResourceProvider.INSTANCE, 30 PhysicalResourceProvider.INSTANCE,
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 // test('both file and uri', () { 125 // test('both file and uri', () {
125 // Request request = 126 // Request request =
126 // new ExecutionMapUriParams('xxx', file: '', uri: '').toRequest('5') ; 127 // new ExecutionMapUriParams('xxx', file: '', uri: '').toRequest('5') ;
127 // Response response = handler.handleRequest(request); 128 // Response response = handler.handleRequest(request);
128 // expect(response, isResponseFailure('5')); 129 // expect(response, isResponseFailure('5'));
129 // }); 130 // });
130 // }); 131 // });
131 132
132 group('setSubscriptions', () { 133 group('setSubscriptions', () {
133 test('failure - invalid service name', () { 134 test('failure - invalid service name', () {
134 expect(handler.launchDataListener, isNull); 135 expect(handler.onAnalysisSubscription, isNull);
135 136
136 Request request = new Request('0', EXECUTION_SET_SUBSCRIPTIONS, { 137 Request request = new Request('0', EXECUTION_SET_SUBSCRIPTIONS, {
137 SUBSCRIPTIONS: ['noSuchService'] 138 SUBSCRIPTIONS: ['noSuchService']
138 }); 139 });
139 Response response = handler.handleRequest(request); 140 Response response = handler.handleRequest(request);
140 expect(response, isResponseFailure('0')); 141 expect(response, isResponseFailure('0'));
141 expect(handler.launchDataListener, isNull); 142 expect(handler.onAnalysisSubscription, isNull);
142 }); 143 });
143 144
144 test('success - setting and clearing', () { 145 test('success - setting and clearing', () {
145 expect(handler.launchDataListener, isNull); 146 expect(handler.onAnalysisSubscription, isNull);
146 147
147 Request request = new ExecutionSetSubscriptionsParams( 148 Request request = new ExecutionSetSubscriptionsParams(
148 [ExecutionService.LAUNCH_DATA]).toRequest('0'); 149 [ExecutionService.LAUNCH_DATA]).toRequest('0');
149 Response response = handler.handleRequest(request); 150 Response response = handler.handleRequest(request);
150 expect(response, isResponseSuccess('0')); 151 expect(response, isResponseSuccess('0'));
151 expect(handler.launchDataListener, isNotNull); 152 expect(handler.onAnalysisSubscription, isNotNull);
152 153
153 request = new ExecutionSetSubscriptionsParams([]).toRequest('0'); 154 request = new ExecutionSetSubscriptionsParams([]).toRequest('0');
154 response = handler.handleRequest(request); 155 response = handler.handleRequest(request);
155 expect(response, isResponseSuccess('0')); 156 expect(response, isResponseSuccess('0'));
156 expect(handler.launchDataListener, isNull); 157 expect(handler.onAnalysisSubscription, isNull);
157 }); 158 });
158 }); 159 });
159 });
160 160
161 group('LaunchDataNotificationListener', () { 161 test('onAnalysisComplete - success - setting and clearing', () {
162 test('success - setting and clearing', () {
163 Source source1 = new TestSource('/a.dart'); 162 Source source1 = new TestSource('/a.dart');
164 Source source2 = new TestSource('/b.dart'); 163 Source source2 = new TestSource('/b.dart');
165 Source source3 = new TestSource('/c.dart'); 164 Source source3 = new TestSource('/c.dart');
166 Source source4 = new TestSource('/d.dart'); 165 Source source4 = new TestSource('/d.dart');
167 Source source5 = new TestSource('/e.html'); 166 Source source5 = new TestSource('/e.html');
168 Source source6 = new TestSource('/f.html'); 167 Source source6 = new TestSource('/f.html');
169 Source source7 = new TestSource('/g.html'); 168 Source source7 = new TestSource('/g.html');
170 Source source8 = new TestSource('/h.dart'); 169 Source source8 = new TestSource('/h.dart');
171 Source source9 = new TestSource('/i.dart'); 170 Source source9 = new TestSource('/i.dart');
172 171
173 AnalysisContext context = new AnalysisContextMock(); 172 AnalysisContext context = new AnalysisContextMock();
174 when(context.launchableClientLibrarySources) 173 when(context.launchableClientLibrarySources)
175 .thenReturn([source1, source2]); 174 .thenReturn([source1, source2]);
176 when(context.launchableServerLibrarySources) 175 when(context.launchableServerLibrarySources)
177 .thenReturn([source2, source3]); 176 .thenReturn([source2, source3]);
178 when(context.librarySources).thenReturn([source4]); 177 when(context.librarySources).thenReturn([source4]);
179 when(context.getHtmlFilesReferencing(anyObject)) 178 when(context.getHtmlFilesReferencing(anyObject))
180 .thenReturn([source5, source6]); 179 .thenReturn([source5, source6]);
181 when(context.htmlSources).thenReturn([source7]); 180 when(context.htmlSources).thenReturn([source7]);
182 when(context.getLibrariesReferencedFromHtml(anyObject)) 181 when(context.getLibrariesReferencedFromHtml(anyObject))
183 .thenReturn([source8, source9]); 182 .thenReturn([source8, source9]);
184 183
185 AnalysisServer server = new AnalysisServerMock(); 184 AnalysisServer server = new AnalysisServerMock();
186 when(server.getAnalysisContexts()).thenReturn([context]); 185 when(server.getAnalysisContexts()).thenReturn([context]);
186 when(server.isAnalysisComplete()).thenReturn(false);
187
188 StreamController controller = new StreamController.broadcast(sync: true);
189 when(server.onAnalysisComplete).thenReturn(controller.stream);
190
191 ExecutionDomainHandler handler = new ExecutionDomainHandler(server);
192 Request request = new ExecutionSetSubscriptionsParams(
193 [ExecutionService.LAUNCH_DATA]).toRequest('0');
194 Response response = handler.handleRequest(request);
195
187 bool notificationSent = false; 196 bool notificationSent = false;
188 when(server.sendNotification(anyObject)) 197 when(server.sendNotification(anyObject))
189 .thenInvoke((Notification notification) { 198 .thenInvoke((Notification notification) {
190 ExecutionLaunchDataParams params = 199 ExecutionLaunchDataParams params =
191 new ExecutionLaunchDataParams.fromNotification(notification); 200 new ExecutionLaunchDataParams.fromNotification(notification);
192 201
193 List<ExecutableFile> executables = params.executables; 202 List<ExecutableFile> executables = params.executables;
194 expect(executables.length, equals(3)); 203 expect(executables.length, equals(3));
195 expect( 204 expect(
196 executables[0], 205 executables[0],
(...skipping 16 matching lines...) Expand all
213 Map<String, List<String>> htmlToDart = params.htmlToDart; 222 Map<String, List<String>> htmlToDart = params.htmlToDart;
214 expect(htmlToDart.length, equals(1)); 223 expect(htmlToDart.length, equals(1));
215 List<String> dartFiles = htmlToDart[source7.fullName]; 224 List<String> dartFiles = htmlToDart[source7.fullName];
216 expect(dartFiles, isNotNull); 225 expect(dartFiles, isNotNull);
217 expect(dartFiles.length, equals(2)); 226 expect(dartFiles.length, equals(2));
218 expect(dartFiles[0], equals(source8.fullName)); 227 expect(dartFiles[0], equals(source8.fullName));
219 expect(dartFiles[1], equals(source9.fullName)); 228 expect(dartFiles[1], equals(source9.fullName));
220 229
221 notificationSent = true; 230 notificationSent = true;
222 }); 231 });
223 LaunchDataNotificationListener listener = 232 controller.add(null);
224 new LaunchDataNotificationListener(server);
225 listener.analysisComplete();
226 expect(notificationSent, isTrue); 233 expect(notificationSent, isTrue);
227 }); 234 });
228 }); 235 });
229 } 236 }
230 237
231 /** 238 /**
232 * A [Source] that knows it's [fullName]. 239 * A [Source] that knows it's [fullName].
233 */ 240 */
234 class TestSource implements Source { 241 class TestSource implements Source {
235 String fullName; 242 String fullName;
(...skipping 29 matching lines...) Expand all
265 272
266 @override 273 @override
267 bool matches(item, Map matchState) { 274 bool matches(item, Map matchState) {
268 if (item is! ExecutableFile) { 275 if (item is! ExecutableFile) {
269 return false; 276 return false;
270 } 277 }
271 ExecutableFile file = item; 278 ExecutableFile file = item;
272 return item.file == expectedFile && item.kind == expectedKind; 279 return item.file == expectedFile && item.kind == expectedKind;
273 } 280 }
274 } 281 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698