| 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 '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'; |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 // test('both file and uri', () { | 125 // test('both file and uri', () { |
| 126 // Request request = | 126 // Request request = |
| 127 // new ExecutionMapUriParams('xxx', file: '', uri: '').toRequest('5')
; | 127 // new ExecutionMapUriParams('xxx', file: '', uri: '').toRequest('5')
; |
| 128 // Response response = handler.handleRequest(request); | 128 // Response response = handler.handleRequest(request); |
| 129 // expect(response, isResponseFailure('5')); | 129 // expect(response, isResponseFailure('5')); |
| 130 // }); | 130 // }); |
| 131 // }); | 131 // }); |
| 132 | 132 |
| 133 group('setSubscriptions', () { | 133 group('setSubscriptions', () { |
| 134 test('failure - invalid service name', () { | 134 test('failure - invalid service name', () { |
| 135 expect(handler.onAnalysisSubscription, isNull); | 135 expect(handler.onFileAnalyzed, isNull); |
| 136 | 136 |
| 137 Request request = new Request('0', EXECUTION_SET_SUBSCRIPTIONS, { | 137 Request request = new Request('0', EXECUTION_SET_SUBSCRIPTIONS, { |
| 138 SUBSCRIPTIONS: ['noSuchService'] | 138 SUBSCRIPTIONS: ['noSuchService'] |
| 139 }); | 139 }); |
| 140 Response response = handler.handleRequest(request); | 140 Response response = handler.handleRequest(request); |
| 141 expect(response, isResponseFailure('0')); | 141 expect(response, isResponseFailure('0')); |
| 142 expect(handler.onAnalysisSubscription, isNull); | 142 expect(handler.onFileAnalyzed, isNull); |
| 143 }); | 143 }); |
| 144 | 144 |
| 145 test('success - setting and clearing', () { | 145 test('success - setting and clearing', () { |
| 146 expect(handler.onAnalysisSubscription, isNull); | 146 expect(handler.onFileAnalyzed, isNull); |
| 147 | 147 |
| 148 Request request = new ExecutionSetSubscriptionsParams( | 148 Request request = new ExecutionSetSubscriptionsParams( |
| 149 [ExecutionService.LAUNCH_DATA]).toRequest('0'); | 149 [ExecutionService.LAUNCH_DATA]).toRequest('0'); |
| 150 Response response = handler.handleRequest(request); | 150 Response response = handler.handleRequest(request); |
| 151 expect(response, isResponseSuccess('0')); | 151 expect(response, isResponseSuccess('0')); |
| 152 expect(handler.onAnalysisSubscription, isNotNull); | 152 expect(handler.onFileAnalyzed, isNotNull); |
| 153 | 153 |
| 154 request = new ExecutionSetSubscriptionsParams([]).toRequest('0'); | 154 request = new ExecutionSetSubscriptionsParams([]).toRequest('0'); |
| 155 response = handler.handleRequest(request); | 155 response = handler.handleRequest(request); |
| 156 expect(response, isResponseSuccess('0')); | 156 expect(response, isResponseSuccess('0')); |
| 157 expect(handler.onAnalysisSubscription, isNull); | 157 expect(handler.onFileAnalyzed, isNull); |
| 158 }); | 158 }); |
| 159 }); | 159 }); |
| 160 | 160 |
| 161 test('onAnalysisComplete - success - setting and clearing', () { | 161 test('onAnalysisComplete - success - setting and clearing', () { |
| 162 Source source1 = new TestSource('/a.dart'); | 162 Source source1 = new TestSource('/a.dart'); |
| 163 Source source2 = new TestSource('/b.dart'); | 163 Source source2 = new TestSource('/b.dart'); |
| 164 Source source3 = new TestSource('/c.dart'); | 164 Source source3 = new TestSource('/c.dart'); |
| 165 Source source4 = new TestSource('/d.dart'); | 165 Source source4 = new TestSource('/d.dart'); |
| 166 Source source5 = new TestSource('/e.html'); | 166 Source source5 = new TestSource('/e.html'); |
| 167 Source source6 = new TestSource('/f.html'); | 167 Source source6 = new TestSource('/f.html'); |
| 168 Source source7 = new TestSource('/g.html'); | 168 Source source7 = new TestSource('/g.html'); |
| 169 Source source8 = new TestSource('/h.dart'); | |
| 170 Source source9 = new TestSource('/i.dart'); | |
| 171 | 169 |
| 172 AnalysisContext context = new AnalysisContextMock(); | 170 AnalysisContext context = new AnalysisContextMock(); |
| 173 when(context.launchableClientLibrarySources) | 171 when(context.launchableClientLibrarySources) |
| 174 .thenReturn([source1, source2]); | 172 .thenReturn([source1, source2]); |
| 175 when(context.launchableServerLibrarySources) | 173 when(context.launchableServerLibrarySources) |
| 176 .thenReturn([source2, source3]); | 174 .thenReturn([source2, source3]); |
| 177 when(context.librarySources).thenReturn([source4]); | 175 when(context.librarySources).thenReturn([source4]); |
| 178 when(context.getHtmlFilesReferencing(anyObject)) | 176 when(context.htmlSources).thenReturn([source5]); |
| 179 .thenReturn([source5, source6]); | |
| 180 when(context.htmlSources).thenReturn([source7]); | |
| 181 when(context.getLibrariesReferencedFromHtml(anyObject)) | 177 when(context.getLibrariesReferencedFromHtml(anyObject)) |
| 182 .thenReturn([source8, source9]); | 178 .thenReturn([source6, source7]); |
| 183 | 179 |
| 184 AnalysisServer server = new AnalysisServerMock(); | 180 AnalysisServer server = new AnalysisServerMock(); |
| 185 when(server.getAnalysisContexts()).thenReturn([context]); | 181 when(server.getAnalysisContexts()).thenReturn([context]); |
| 186 when(server.isAnalysisComplete()).thenReturn(false); | 182 when(server.isAnalysisComplete()).thenReturn(false); |
| 187 | 183 |
| 188 StreamController controller = new StreamController.broadcast(sync: true); | 184 StreamController controller = new StreamController.broadcast(sync: true); |
| 189 when(server.onAnalysisComplete).thenReturn(controller.stream); | 185 when(server.onFileAnalyzed).thenReturn(controller.stream); |
| 186 |
| 187 List<String> unsentNotifications = <String>[ |
| 188 source1.fullName, source2.fullName, source3.fullName, |
| 189 source4.fullName, source5.fullName]; |
| 190 when(server.sendNotification(anyObject)) |
| 191 .thenInvoke((Notification notification) { |
| 192 ExecutionLaunchDataParams params = |
| 193 new ExecutionLaunchDataParams.fromNotification(notification); |
| 194 |
| 195 String fileName = params.file; |
| 196 expect(unsentNotifications.remove(fileName), isTrue); |
| 197 |
| 198 if (fileName == source1.fullName) { |
| 199 expect(params.kind, ExecutableKind.CLIENT); |
| 200 } else if (fileName == source2.fullName) { |
| 201 expect(params.kind, ExecutableKind.EITHER); |
| 202 } else if (fileName == source3.fullName) { |
| 203 expect(params.kind, ExecutableKind.SERVER); |
| 204 } else if (fileName == source4.fullName) { |
| 205 expect(params.kind, ExecutableKind.NOT_EXECUTABLE); |
| 206 } else if (fileName == source5.fullName) { |
| 207 var referencedFiles = params.referencedFiles; |
| 208 expect(referencedFiles, isNotNull); |
| 209 expect(referencedFiles.length, equals(2)); |
| 210 expect(referencedFiles[0], equals(source6.fullName)); |
| 211 expect(referencedFiles[1], equals(source7.fullName)); |
| 212 } |
| 213 }); |
| 190 | 214 |
| 191 ExecutionDomainHandler handler = new ExecutionDomainHandler(server); | 215 ExecutionDomainHandler handler = new ExecutionDomainHandler(server); |
| 192 Request request = new ExecutionSetSubscriptionsParams( | 216 Request request = new ExecutionSetSubscriptionsParams( |
| 193 [ExecutionService.LAUNCH_DATA]).toRequest('0'); | 217 [ExecutionService.LAUNCH_DATA]).toRequest('0'); |
| 194 Response response = handler.handleRequest(request); | 218 Response response = handler.handleRequest(request); |
| 195 | 219 |
| 196 bool notificationSent = false; | 220 // controller.add(null); |
| 197 when(server.sendNotification(anyObject)) | 221 expect(unsentNotifications, isEmpty); |
| 198 .thenInvoke((Notification notification) { | |
| 199 ExecutionLaunchDataParams params = | |
| 200 new ExecutionLaunchDataParams.fromNotification(notification); | |
| 201 | |
| 202 List<ExecutableFile> executables = params.executables; | |
| 203 expect(executables.length, equals(3)); | |
| 204 expect( | |
| 205 executables[0], | |
| 206 isExecutableFile(source1, ExecutableKind.CLIENT)); | |
| 207 expect( | |
| 208 executables[1], | |
| 209 isExecutableFile(source2, ExecutableKind.EITHER)); | |
| 210 expect( | |
| 211 executables[2], | |
| 212 isExecutableFile(source3, ExecutableKind.SERVER)); | |
| 213 | |
| 214 Map<String, List<String>> dartToHtml = params.dartToHtml; | |
| 215 expect(dartToHtml.length, equals(1)); | |
| 216 List<String> htmlFiles = dartToHtml[source4.fullName]; | |
| 217 expect(htmlFiles, isNotNull); | |
| 218 expect(htmlFiles.length, equals(2)); | |
| 219 expect(htmlFiles[0], equals(source5.fullName)); | |
| 220 expect(htmlFiles[1], equals(source6.fullName)); | |
| 221 | |
| 222 Map<String, List<String>> htmlToDart = params.htmlToDart; | |
| 223 expect(htmlToDart.length, equals(1)); | |
| 224 List<String> dartFiles = htmlToDart[source7.fullName]; | |
| 225 expect(dartFiles, isNotNull); | |
| 226 expect(dartFiles.length, equals(2)); | |
| 227 expect(dartFiles[0], equals(source8.fullName)); | |
| 228 expect(dartFiles[1], equals(source9.fullName)); | |
| 229 | |
| 230 notificationSent = true; | |
| 231 }); | |
| 232 controller.add(null); | |
| 233 expect(notificationSent, isTrue); | |
| 234 }); | 222 }); |
| 235 }); | 223 }); |
| 236 } | 224 } |
| 237 | 225 |
| 238 /** | 226 /** |
| 239 * A [Source] that knows it's [fullName]. | 227 * A [Source] that knows it's [fullName]. |
| 240 */ | 228 */ |
| 241 class TestSource implements Source { | 229 class TestSource implements Source { |
| 242 String fullName; | 230 String fullName; |
| 243 | 231 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 272 | 260 |
| 273 @override | 261 @override |
| 274 bool matches(item, Map matchState) { | 262 bool matches(item, Map matchState) { |
| 275 if (item is! ExecutableFile) { | 263 if (item is! ExecutableFile) { |
| 276 return false; | 264 return false; |
| 277 } | 265 } |
| 278 ExecutableFile file = item; | 266 ExecutableFile file = item; |
| 279 return item.file == expectedFile && item.kind == expectedKind; | 267 return item.file == expectedFile && item.kind == expectedKind; |
| 280 } | 268 } |
| 281 } | 269 } |
| OLD | NEW |