| 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.domain.execution; | 5 library test.domain.execution; |
| 6 | 6 |
| 7 import 'dart:async'; | |
| 8 | |
| 9 import 'package:analysis_server/plugin/protocol/protocol.dart'; | 7 import 'package:analysis_server/plugin/protocol/protocol.dart'; |
| 10 import 'package:analysis_server/src/analysis_server.dart'; | 8 import 'package:analysis_server/src/analysis_server.dart'; |
| 11 import 'package:analysis_server/src/constants.dart'; | 9 import 'package:analysis_server/src/constants.dart'; |
| 12 import 'package:analysis_server/src/context_manager.dart'; | |
| 13 import 'package:analysis_server/src/domain_execution.dart'; | 10 import 'package:analysis_server/src/domain_execution.dart'; |
| 14 import 'package:analysis_server/src/plugin/server_plugin.dart'; | 11 import 'package:analysis_server/src/plugin/server_plugin.dart'; |
| 15 import 'package:analyzer/file_system/file_system.dart'; | 12 import 'package:analyzer/file_system/file_system.dart'; |
| 16 import 'package:analyzer/file_system/memory_file_system.dart'; | 13 import 'package:analyzer/file_system/memory_file_system.dart'; |
| 17 import 'package:analyzer/instrumentation/instrumentation.dart'; | 14 import 'package:analyzer/instrumentation/instrumentation.dart'; |
| 18 import 'package:analyzer/src/generated/engine.dart'; | 15 import 'package:analyzer/src/generated/engine.dart'; |
| 19 import 'package:analyzer/src/generated/sdk.dart'; | 16 import 'package:analyzer/src/generated/sdk.dart'; |
| 20 import 'package:analyzer/src/generated/source.dart'; | 17 import 'package:analyzer/src/generated/source.dart'; |
| 21 import 'package:analyzer/src/generated/source_io.dart'; | 18 import 'package:analyzer/src/generated/source_io.dart'; |
| 22 import 'package:plugin/manager.dart'; | 19 import 'package:plugin/manager.dart'; |
| 23 import 'package:test/test.dart'; | 20 import 'package:test/test.dart'; |
| 24 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 21 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| 25 import 'package:typed_mock/typed_mock.dart'; | |
| 26 | 22 |
| 27 import 'analysis_abstract.dart'; | 23 import 'analysis_abstract.dart'; |
| 28 import 'mocks.dart'; | 24 import 'mocks.dart'; |
| 29 import 'operation/operation_queue_test.dart'; | |
| 30 | 25 |
| 31 main() { | 26 main() { |
| 32 defineReflectiveSuite(() { | 27 defineReflectiveSuite(() { |
| 33 defineReflectiveTests(ExecutionDomainTest); | 28 defineReflectiveTests(ExecutionDomainTest); |
| 34 }); | 29 }); |
| 35 group('ExecutionDomainHandler', () { | 30 group('ExecutionDomainHandler', () { |
| 36 MemoryResourceProvider provider = new MemoryResourceProvider(); | 31 MemoryResourceProvider provider = new MemoryResourceProvider(); |
| 37 AnalysisServer server; | 32 AnalysisServer server; |
| 38 ExecutionDomainHandler handler; | 33 ExecutionDomainHandler handler; |
| 39 | 34 |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 Response response = handler.handleRequest(request); | 187 Response response = handler.handleRequest(request); |
| 193 expect(response, isResponseSuccess('0')); | 188 expect(response, isResponseSuccess('0')); |
| 194 expect(handler.onFileAnalyzed, isNotNull); | 189 expect(handler.onFileAnalyzed, isNotNull); |
| 195 | 190 |
| 196 request = new ExecutionSetSubscriptionsParams([]).toRequest('0'); | 191 request = new ExecutionSetSubscriptionsParams([]).toRequest('0'); |
| 197 response = handler.handleRequest(request); | 192 response = handler.handleRequest(request); |
| 198 expect(response, isResponseSuccess('0')); | 193 expect(response, isResponseSuccess('0')); |
| 199 expect(handler.onFileAnalyzed, isNull); | 194 expect(handler.onFileAnalyzed, isNull); |
| 200 }); | 195 }); |
| 201 }); | 196 }); |
| 202 | |
| 203 test('onAnalysisComplete - success - setting and clearing', () { | |
| 204 Source source1 = new TestSource('/a.dart'); | |
| 205 Source source2 = new TestSource('/b.dart'); | |
| 206 Source source3 = new TestSource('/c.dart'); | |
| 207 Source source4 = new TestSource('/d.dart'); | |
| 208 Source source5 = new TestSource('/e.html'); | |
| 209 Source source6 = new TestSource('/f.html'); | |
| 210 Source source7 = new TestSource('/g.html'); | |
| 211 | |
| 212 AnalysisContext context = new AnalysisContextMock(); | |
| 213 when(context.launchableClientLibrarySources) | |
| 214 .thenReturn([source1, source2]); | |
| 215 when(context.launchableServerLibrarySources) | |
| 216 .thenReturn([source2, source3]); | |
| 217 when(context.librarySources).thenReturn([source4]); | |
| 218 when(context.htmlSources).thenReturn([source5]); | |
| 219 when(context.getLibrariesReferencedFromHtml(anyObject)) | |
| 220 .thenReturn([source6, source7]); | |
| 221 | |
| 222 ContextManager manager = new ServerContextManagerMock(); | |
| 223 when(manager.isInAnalysisRoot(anyString)).thenReturn(true); | |
| 224 | |
| 225 AnalysisServer server = new AnalysisServerMock(); | |
| 226 when(server.analysisContexts).thenReturn([context]); | |
| 227 when(server.contextManager).thenReturn(manager); | |
| 228 | |
| 229 StreamController controller = new StreamController.broadcast(sync: true); | |
| 230 when(server.onFileAnalyzed).thenReturn(controller.stream); | |
| 231 | |
| 232 List<String> unsentNotifications = <String>[ | |
| 233 source1.fullName, | |
| 234 source2.fullName, | |
| 235 source3.fullName, | |
| 236 source4.fullName, | |
| 237 source5.fullName | |
| 238 ]; | |
| 239 when(server.sendNotification(anyObject)) | |
| 240 .thenInvoke((Notification notification) { | |
| 241 ExecutionLaunchDataParams params = | |
| 242 new ExecutionLaunchDataParams.fromNotification(notification); | |
| 243 | |
| 244 String fileName = params.file; | |
| 245 expect(unsentNotifications.remove(fileName), isTrue); | |
| 246 | |
| 247 if (fileName == source1.fullName) { | |
| 248 expect(params.kind, ExecutableKind.CLIENT); | |
| 249 } else if (fileName == source2.fullName) { | |
| 250 expect(params.kind, ExecutableKind.EITHER); | |
| 251 } else if (fileName == source3.fullName) { | |
| 252 expect(params.kind, ExecutableKind.SERVER); | |
| 253 } else if (fileName == source4.fullName) { | |
| 254 expect(params.kind, ExecutableKind.NOT_EXECUTABLE); | |
| 255 } else if (fileName == source5.fullName) { | |
| 256 var referencedFiles = params.referencedFiles; | |
| 257 expect(referencedFiles, isNotNull); | |
| 258 expect(referencedFiles.length, equals(2)); | |
| 259 expect(referencedFiles[0], equals(source6.fullName)); | |
| 260 expect(referencedFiles[1], equals(source7.fullName)); | |
| 261 } | |
| 262 }); | |
| 263 | |
| 264 ExecutionDomainHandler handler = new ExecutionDomainHandler(server); | |
| 265 Request request = | |
| 266 new ExecutionSetSubscriptionsParams([ExecutionService.LAUNCH_DATA]) | |
| 267 .toRequest('0'); | |
| 268 handler.handleRequest(request); | |
| 269 | |
| 270 // controller.add(null); | |
| 271 expect(unsentNotifications, isEmpty); | |
| 272 }); | |
| 273 }); | 197 }); |
| 274 } | 198 } |
| 275 | 199 |
| 276 @reflectiveTest | 200 @reflectiveTest |
| 277 class ExecutionDomainTest extends AbstractAnalysisTest { | 201 class ExecutionDomainTest extends AbstractAnalysisTest { |
| 278 String contextId; | 202 String contextId; |
| 279 | 203 |
| 280 @override | 204 @override |
| 281 void setUp() { | 205 void setUp() { |
| 282 super.setUp(); | 206 super.setUp(); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 * A [Source] that knows it's [fullName]. | 272 * A [Source] that knows it's [fullName]. |
| 349 */ | 273 */ |
| 350 class TestSource implements Source { | 274 class TestSource implements Source { |
| 351 String fullName; | 275 String fullName; |
| 352 | 276 |
| 353 TestSource(this.fullName); | 277 TestSource(this.fullName); |
| 354 | 278 |
| 355 @override | 279 @override |
| 356 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 280 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 357 } | 281 } |
| OLD | NEW |