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'; | 7 import 'dart:async'; |
8 | 8 |
9 import 'package:analysis_server/src/analysis_server.dart'; | 9 import 'package:analysis_server/src/analysis_server.dart'; |
10 import 'package:analysis_server/src/constants.dart'; | 10 import 'package:analysis_server/src/constants.dart'; |
(...skipping 20 matching lines...) Expand all Loading... |
31 return new IsExecutableFile(source.fullName, kind); | 31 return new IsExecutableFile(source.fullName, kind); |
32 } | 32 } |
33 | 33 |
34 main() { | 34 main() { |
35 group('ExecutionDomainHandler', () { | 35 group('ExecutionDomainHandler', () { |
36 MemoryResourceProvider provider = new MemoryResourceProvider(); | 36 MemoryResourceProvider provider = new MemoryResourceProvider(); |
37 AnalysisServer server; | 37 AnalysisServer server; |
38 ExecutionDomainHandler handler; | 38 ExecutionDomainHandler handler; |
39 | 39 |
40 setUp(() { | 40 setUp(() { |
41 server = new AnalysisServer( | 41 server = new AnalysisServer(new MockServerChannel(), provider, |
42 new MockServerChannel(), | 42 new MockPackageMapProvider(), null, new AnalysisServerOptions(), |
43 provider, | 43 new MockSdk(), InstrumentationService.NULL_SERVICE); |
44 new MockPackageMapProvider(), | |
45 null, | |
46 new AnalysisServerOptions(), | |
47 new MockSdk(), | |
48 InstrumentationService.NULL_SERVICE); | |
49 handler = new ExecutionDomainHandler(server); | 44 handler = new ExecutionDomainHandler(server); |
50 }); | 45 }); |
51 | 46 |
52 group('createContext/deleteContext', () { | 47 group('createContext/deleteContext', () { |
53 test('create/delete multiple contexts', () { | 48 test('create/delete multiple contexts', () { |
54 Request request = | 49 Request request = |
55 new ExecutionCreateContextParams('/a/b.dart').toRequest('0'); | 50 new ExecutionCreateContextParams('/a/b.dart').toRequest('0'); |
56 Response response = handler.handleRequest(request); | 51 Response response = handler.handleRequest(request); |
57 expect(response, isResponseSuccess('0')); | 52 expect(response, isResponseSuccess('0')); |
58 ExecutionCreateContextResult result = | 53 ExecutionCreateContextResult result = |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 | 105 |
111 tearDown(() { | 106 tearDown(() { |
112 Request request = | 107 Request request = |
113 new ExecutionDeleteContextParams(contextId).toRequest('1'); | 108 new ExecutionDeleteContextParams(contextId).toRequest('1'); |
114 Response response = handler.handleRequest(request); | 109 Response response = handler.handleRequest(request); |
115 expect(response, isResponseSuccess('1')); | 110 expect(response, isResponseSuccess('1')); |
116 }); | 111 }); |
117 | 112 |
118 group('file to URI', () { | 113 group('file to URI', () { |
119 test('does not exist', () { | 114 test('does not exist', () { |
120 Request request = | 115 Request request = new ExecutionMapUriParams(contextId, |
121 new ExecutionMapUriParams(contextId, file: '/a/c.dart').toRequest(
'2'); | 116 file: '/a/c.dart').toRequest('2'); |
122 Response response = handler.handleRequest(request); | 117 Response response = handler.handleRequest(request); |
123 expect(response, isResponseFailure('2')); | 118 expect(response, isResponseFailure('2')); |
124 }); | 119 }); |
125 | 120 |
126 test('directory', () { | 121 test('directory', () { |
127 provider.newFolder('/a/d'); | 122 provider.newFolder('/a/d'); |
128 Request request = | 123 Request request = |
129 new ExecutionMapUriParams(contextId, file: '/a/d').toRequest('2'); | 124 new ExecutionMapUriParams(contextId, file: '/a/d').toRequest('2'); |
130 Response response = handler.handleRequest(request); | 125 Response response = handler.handleRequest(request); |
131 expect(response, isResponseFailure('2')); | 126 expect(response, isResponseFailure('2')); |
132 }); | 127 }); |
133 | 128 |
134 test('valid', () { | 129 test('valid', () { |
135 Request request = | 130 Request request = new ExecutionMapUriParams(contextId, |
136 new ExecutionMapUriParams(contextId, file: '/a/b.dart').toRequest(
'2'); | 131 file: '/a/b.dart').toRequest('2'); |
137 Response response = handler.handleRequest(request); | 132 Response response = handler.handleRequest(request); |
138 expect(response, isResponseSuccess('2')); | 133 expect(response, isResponseSuccess('2')); |
139 ExecutionMapUriResult result = | 134 ExecutionMapUriResult result = |
140 new ExecutionMapUriResult.fromResponse(response); | 135 new ExecutionMapUriResult.fromResponse(response); |
141 expect(result.file, isNull); | 136 expect(result.file, isNull); |
142 expect(result.uri, 'file:///a/b.dart'); | 137 expect(result.uri, 'file:///a/b.dart'); |
143 }); | 138 }); |
144 }); | 139 }); |
145 | 140 |
146 group('URI to file', () { | 141 group('URI to file', () { |
147 test('invalid', () { | 142 test('invalid', () { |
148 Request request = | 143 Request request = new ExecutionMapUriParams(contextId, |
149 new ExecutionMapUriParams(contextId, uri: 'foo:///a/b.dart').toReq
uest('2'); | 144 uri: 'foo:///a/b.dart').toRequest('2'); |
150 Response response = handler.handleRequest(request); | 145 Response response = handler.handleRequest(request); |
151 expect(response, isResponseFailure('2')); | 146 expect(response, isResponseFailure('2')); |
152 }); | 147 }); |
153 | 148 |
154 test('valid', () { | 149 test('valid', () { |
155 Request request = | 150 Request request = new ExecutionMapUriParams(contextId, |
156 new ExecutionMapUriParams(contextId, uri: 'file:///a/b.dart').toRe
quest('2'); | 151 uri: 'file:///a/b.dart').toRequest('2'); |
157 Response response = handler.handleRequest(request); | 152 Response response = handler.handleRequest(request); |
158 expect(response, isResponseSuccess('2')); | 153 expect(response, isResponseSuccess('2')); |
159 ExecutionMapUriResult result = | 154 ExecutionMapUriResult result = |
160 new ExecutionMapUriResult.fromResponse(response); | 155 new ExecutionMapUriResult.fromResponse(response); |
161 expect(result.file, '/a/b.dart'); | 156 expect(result.file, '/a/b.dart'); |
162 expect(result.uri, isNull); | 157 expect(result.uri, isNull); |
163 }); | 158 }); |
164 }); | 159 }); |
165 | 160 |
166 test('invalid context id', () { | 161 test('invalid context id', () { |
(...skipping 25 matching lines...) Expand all Loading... |
192 SUBSCRIPTIONS: ['noSuchService'] | 187 SUBSCRIPTIONS: ['noSuchService'] |
193 }); | 188 }); |
194 Response response = handler.handleRequest(request); | 189 Response response = handler.handleRequest(request); |
195 expect(response, isResponseFailure('0')); | 190 expect(response, isResponseFailure('0')); |
196 expect(handler.onFileAnalyzed, isNull); | 191 expect(handler.onFileAnalyzed, isNull); |
197 }); | 192 }); |
198 | 193 |
199 test('success - setting and clearing', () { | 194 test('success - setting and clearing', () { |
200 expect(handler.onFileAnalyzed, isNull); | 195 expect(handler.onFileAnalyzed, isNull); |
201 | 196 |
202 Request request = new ExecutionSetSubscriptionsParams( | 197 Request request = |
203 [ExecutionService.LAUNCH_DATA]).toRequest('0'); | 198 new ExecutionSetSubscriptionsParams([ExecutionService.LAUNCH_DATA]) |
| 199 .toRequest('0'); |
204 Response response = handler.handleRequest(request); | 200 Response response = handler.handleRequest(request); |
205 expect(response, isResponseSuccess('0')); | 201 expect(response, isResponseSuccess('0')); |
206 expect(handler.onFileAnalyzed, isNotNull); | 202 expect(handler.onFileAnalyzed, isNotNull); |
207 | 203 |
208 request = new ExecutionSetSubscriptionsParams([]).toRequest('0'); | 204 request = new ExecutionSetSubscriptionsParams([]).toRequest('0'); |
209 response = handler.handleRequest(request); | 205 response = handler.handleRequest(request); |
210 expect(response, isResponseSuccess('0')); | 206 expect(response, isResponseSuccess('0')); |
211 expect(handler.onFileAnalyzed, isNull); | 207 expect(handler.onFileAnalyzed, isNull); |
212 }); | 208 }); |
213 }); | 209 }); |
214 | 210 |
215 test('onAnalysisComplete - success - setting and clearing', () { | 211 test('onAnalysisComplete - success - setting and clearing', () { |
216 Source source1 = new TestSource('/a.dart'); | 212 Source source1 = new TestSource('/a.dart'); |
217 Source source2 = new TestSource('/b.dart'); | 213 Source source2 = new TestSource('/b.dart'); |
218 Source source3 = new TestSource('/c.dart'); | 214 Source source3 = new TestSource('/c.dart'); |
219 Source source4 = new TestSource('/d.dart'); | 215 Source source4 = new TestSource('/d.dart'); |
220 Source source5 = new TestSource('/e.html'); | 216 Source source5 = new TestSource('/e.html'); |
221 Source source6 = new TestSource('/f.html'); | 217 Source source6 = new TestSource('/f.html'); |
222 Source source7 = new TestSource('/g.html'); | 218 Source source7 = new TestSource('/g.html'); |
223 | 219 |
224 AnalysisContext context = new AnalysisContextMock(); | 220 AnalysisContext context = new AnalysisContextMock(); |
225 when( | 221 when(context.launchableClientLibrarySources) |
226 context.launchableClientLibrarySources).thenReturn([source1, source2])
; | 222 .thenReturn([source1, source2]); |
227 when( | 223 when(context.launchableServerLibrarySources) |
228 context.launchableServerLibrarySources).thenReturn([source2, source3])
; | 224 .thenReturn([source2, source3]); |
229 when(context.librarySources).thenReturn([source4]); | 225 when(context.librarySources).thenReturn([source4]); |
230 when(context.htmlSources).thenReturn([source5]); | 226 when(context.htmlSources).thenReturn([source5]); |
231 when( | 227 when(context.getLibrariesReferencedFromHtml(anyObject)) |
232 context.getLibrariesReferencedFromHtml( | 228 .thenReturn([source6, source7]); |
233 anyObject)).thenReturn([source6, source7]); | |
234 | 229 |
235 ServerContextManager manager = new ServerContextManagerMock(); | 230 ServerContextManager manager = new ServerContextManagerMock(); |
236 when(manager.isInAnalysisRoot(anyString)).thenReturn(true); | 231 when(manager.isInAnalysisRoot(anyString)).thenReturn(true); |
237 | 232 |
238 AnalysisServer server = new AnalysisServerMock(); | 233 AnalysisServer server = new AnalysisServerMock(); |
239 when(server.getAnalysisContexts()).thenReturn([context]); | 234 when(server.getAnalysisContexts()).thenReturn([context]); |
240 when(server.contextDirectoryManager).thenReturn(manager); | 235 when(server.contextDirectoryManager).thenReturn(manager); |
241 | 236 |
242 StreamController controller = new StreamController.broadcast(sync: true); | 237 StreamController controller = new StreamController.broadcast(sync: true); |
243 when(server.onFileAnalyzed).thenReturn(controller.stream); | 238 when(server.onFileAnalyzed).thenReturn(controller.stream); |
244 | 239 |
245 List<String> unsentNotifications = <String>[ | 240 List<String> unsentNotifications = <String>[ |
246 source1.fullName, | 241 source1.fullName, |
247 source2.fullName, | 242 source2.fullName, |
248 source3.fullName, | 243 source3.fullName, |
249 source4.fullName, | 244 source4.fullName, |
250 source5.fullName]; | 245 source5.fullName |
251 when( | 246 ]; |
252 server.sendNotification(anyObject)).thenInvoke((Notification notificat
ion) { | 247 when(server.sendNotification(anyObject)).thenInvoke( |
| 248 (Notification notification) { |
253 ExecutionLaunchDataParams params = | 249 ExecutionLaunchDataParams params = |
254 new ExecutionLaunchDataParams.fromNotification(notification); | 250 new ExecutionLaunchDataParams.fromNotification(notification); |
255 | 251 |
256 String fileName = params.file; | 252 String fileName = params.file; |
257 expect(unsentNotifications.remove(fileName), isTrue); | 253 expect(unsentNotifications.remove(fileName), isTrue); |
258 | 254 |
259 if (fileName == source1.fullName) { | 255 if (fileName == source1.fullName) { |
260 expect(params.kind, ExecutableKind.CLIENT); | 256 expect(params.kind, ExecutableKind.CLIENT); |
261 } else if (fileName == source2.fullName) { | 257 } else if (fileName == source2.fullName) { |
262 expect(params.kind, ExecutableKind.EITHER); | 258 expect(params.kind, ExecutableKind.EITHER); |
263 } else if (fileName == source3.fullName) { | 259 } else if (fileName == source3.fullName) { |
264 expect(params.kind, ExecutableKind.SERVER); | 260 expect(params.kind, ExecutableKind.SERVER); |
265 } else if (fileName == source4.fullName) { | 261 } else if (fileName == source4.fullName) { |
266 expect(params.kind, ExecutableKind.NOT_EXECUTABLE); | 262 expect(params.kind, ExecutableKind.NOT_EXECUTABLE); |
267 } else if (fileName == source5.fullName) { | 263 } else if (fileName == source5.fullName) { |
268 var referencedFiles = params.referencedFiles; | 264 var referencedFiles = params.referencedFiles; |
269 expect(referencedFiles, isNotNull); | 265 expect(referencedFiles, isNotNull); |
270 expect(referencedFiles.length, equals(2)); | 266 expect(referencedFiles.length, equals(2)); |
271 expect(referencedFiles[0], equals(source6.fullName)); | 267 expect(referencedFiles[0], equals(source6.fullName)); |
272 expect(referencedFiles[1], equals(source7.fullName)); | 268 expect(referencedFiles[1], equals(source7.fullName)); |
273 } | 269 } |
274 }); | 270 }); |
275 | 271 |
276 ExecutionDomainHandler handler = new ExecutionDomainHandler(server); | 272 ExecutionDomainHandler handler = new ExecutionDomainHandler(server); |
277 Request request = new ExecutionSetSubscriptionsParams( | 273 Request request = |
278 [ExecutionService.LAUNCH_DATA]).toRequest('0'); | 274 new ExecutionSetSubscriptionsParams([ExecutionService.LAUNCH_DATA]) |
| 275 .toRequest('0'); |
279 handler.handleRequest(request); | 276 handler.handleRequest(request); |
280 | 277 |
281 // controller.add(null); | 278 // controller.add(null); |
282 expect(unsentNotifications, isEmpty); | 279 expect(unsentNotifications, isEmpty); |
283 }); | 280 }); |
284 }); | 281 }); |
285 } | 282 } |
286 | 283 |
287 /** | 284 /** |
288 * A matcher that will match an [ExecutableFile] if it has a specified [source] | 285 * A matcher that will match an [ExecutableFile] if it has a specified [source] |
(...skipping 23 matching lines...) Expand all Loading... |
312 * A [Source] that knows it's [fullName]. | 309 * A [Source] that knows it's [fullName]. |
313 */ | 310 */ |
314 class TestSource implements Source { | 311 class TestSource implements Source { |
315 String fullName; | 312 String fullName; |
316 | 313 |
317 TestSource(this.fullName); | 314 TestSource(this.fullName); |
318 | 315 |
319 @override | 316 @override |
320 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 317 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
321 } | 318 } |
OLD | NEW |