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/plugin/protocol/protocol.dart'; | 9 import 'package:analysis_server/plugin/protocol/protocol.dart'; |
10 import 'package:analysis_server/src/analysis_server.dart'; | 10 import 'package:analysis_server/src/analysis_server.dart'; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 // TODO(brianwilkerson) It isn't currently specified to be an error if a | 86 // TODO(brianwilkerson) It isn't currently specified to be an error if a |
87 // client attempts to delete a context that doesn't exist. Should it be? | 87 // client attempts to delete a context that doesn't exist. Should it be? |
88 // expect(response, isResponseFailure('0')); | 88 // expect(response, isResponseFailure('0')); |
89 expect(response, isResponseSuccess('0')); | 89 expect(response, isResponseSuccess('0')); |
90 }); | 90 }); |
91 }); | 91 }); |
92 | 92 |
93 group('mapUri', () { | 93 group('mapUri', () { |
94 String contextId; | 94 String contextId; |
95 | 95 |
96 void createExecutionContextIdForFile(String zzz) { | 96 void createExecutionContextIdForFile(String path) { |
97 Request request = new ExecutionCreateContextParams(zzz).toRequest('0'); | 97 Request request = new ExecutionCreateContextParams(path).toRequest('0'); |
98 Response response = handler.handleRequest(request); | 98 Response response = handler.handleRequest(request); |
99 expect(response, isResponseSuccess('0')); | 99 expect(response, isResponseSuccess('0')); |
100 ExecutionCreateContextResult result = | 100 ExecutionCreateContextResult result = |
101 new ExecutionCreateContextResult.fromResponse(response); | 101 new ExecutionCreateContextResult.fromResponse(response); |
102 contextId = result.id; | 102 contextId = result.id; |
103 } | 103 } |
104 | 104 |
105 setUp(() { | 105 setUp(() { |
106 Folder folder = provider.newFile('/a/b.dart', '').parent; | 106 Folder folder = provider.newFile('/a/b.dart', '').parent; |
107 server.folderMap.putIfAbsent(folder, () { | 107 server.folderMap.putIfAbsent(folder, () { |
(...skipping 22 matching lines...) Expand all Loading... |
130 expect(response, isResponseFailure('2')); | 130 expect(response, isResponseFailure('2')); |
131 }); | 131 }); |
132 | 132 |
133 test('directory', () { | 133 test('directory', () { |
134 provider.newFolder('/a/d'); | 134 provider.newFolder('/a/d'); |
135 Request request = | 135 Request request = |
136 new ExecutionMapUriParams(contextId, file: '/a/d').toRequest('2'); | 136 new ExecutionMapUriParams(contextId, file: '/a/d').toRequest('2'); |
137 Response response = handler.handleRequest(request); | 137 Response response = handler.handleRequest(request); |
138 expect(response, isResponseFailure('2')); | 138 expect(response, isResponseFailure('2')); |
139 }); | 139 }); |
140 | |
141 test('valid', () { | |
142 Request request = new ExecutionMapUriParams(contextId, | |
143 file: '/a/b.dart').toRequest('2'); | |
144 Response response = handler.handleRequest(request); | |
145 expect(response, isResponseSuccess('2')); | |
146 ExecutionMapUriResult result = | |
147 new ExecutionMapUriResult.fromResponse(response); | |
148 expect(result.file, isNull); | |
149 expect(result.uri, 'file:///a/b.dart'); | |
150 }); | |
151 }); | 140 }); |
152 | 141 |
153 group('URI to file', () { | 142 group('URI to file', () { |
154 test('invalid', () { | 143 test('invalid', () { |
155 Request request = new ExecutionMapUriParams(contextId, | 144 Request request = new ExecutionMapUriParams(contextId, |
156 uri: 'foo:///a/b.dart').toRequest('2'); | 145 uri: 'foo:///a/b.dart').toRequest('2'); |
157 Response response = handler.handleRequest(request); | 146 Response response = handler.handleRequest(request); |
158 expect(response, isResponseFailure('2')); | 147 expect(response, isResponseFailure('2')); |
159 }); | 148 }); |
160 | |
161 test('valid', () { | |
162 Request request = new ExecutionMapUriParams(contextId, | |
163 uri: 'file:///a/b.dart').toRequest('2'); | |
164 Response response = handler.handleRequest(request); | |
165 expect(response, isResponseSuccess('2')); | |
166 ExecutionMapUriResult result = | |
167 new ExecutionMapUriResult.fromResponse(response); | |
168 expect(result.file, '/a/b.dart'); | |
169 expect(result.uri, isNull); | |
170 }); | |
171 }); | 149 }); |
172 | 150 |
173 test('invalid context id', () { | 151 test('invalid context id', () { |
174 Request request = | 152 Request request = |
175 new ExecutionMapUriParams('xxx', uri: '').toRequest('4'); | 153 new ExecutionMapUriParams('xxx', uri: '').toRequest('4'); |
176 Response response = handler.handleRequest(request); | 154 Response response = handler.handleRequest(request); |
177 expect(response, isResponseFailure('4')); | 155 expect(response, isResponseFailure('4')); |
178 }); | 156 }); |
179 | 157 |
180 test('both file and uri', () { | 158 test('both file and uri', () { |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 handler = new ExecutionDomainHandler(server); | 282 handler = new ExecutionDomainHandler(server); |
305 _createExecutionContext(testFile); | 283 _createExecutionContext(testFile); |
306 } | 284 } |
307 | 285 |
308 @override | 286 @override |
309 void tearDown() { | 287 void tearDown() { |
310 super.tearDown(); | 288 super.tearDown(); |
311 _disposeExecutionContext(); | 289 _disposeExecutionContext(); |
312 } | 290 } |
313 | 291 |
314 void test_mapUri_file_dart() { | 292 void test_mapUri_file() { |
| 293 String path = '/a/b.dart'; |
| 294 resourceProvider.newFile(path, ''); |
| 295 // map the file |
| 296 ExecutionMapUriResult result = _mapUri(file: path); |
| 297 expect(result.file, isNull); |
| 298 expect(result.uri, 'file:///a/b.dart'); |
| 299 } |
| 300 |
| 301 void test_mapUri_file_dartUriKind() { |
315 String path = server.defaultSdk.mapDartUri('dart:async').fullName; | 302 String path = server.defaultSdk.mapDartUri('dart:async').fullName; |
316 // hack - pretend that the SDK file exists in the project FS | 303 // hack - pretend that the SDK file exists in the project FS |
317 resourceProvider.newFile(path, '// hack'); | 304 resourceProvider.newFile(path, '// hack'); |
318 // map file | 305 // map file |
319 ExecutionMapUriResult result = _mapUri(file: path); | 306 ExecutionMapUriResult result = _mapUri(file: path); |
320 expect(result.file, isNull); | 307 expect(result.file, isNull); |
321 expect(result.uri, 'dart:async'); | 308 expect(result.uri, 'dart:async'); |
322 } | 309 } |
323 | 310 |
| 311 void test_mapUri_uri() { |
| 312 String path = '/a/b.dart'; |
| 313 resourceProvider.newFile(path, ''); |
| 314 // map the uri |
| 315 ExecutionMapUriResult result = _mapUri(uri: 'file://$path'); |
| 316 expect(result.file, '/a/b.dart'); |
| 317 expect(result.uri, isNull); |
| 318 } |
| 319 |
324 void _createExecutionContext(String path) { | 320 void _createExecutionContext(String path) { |
325 Request request = new ExecutionCreateContextParams(path).toRequest('0'); | 321 Request request = new ExecutionCreateContextParams(path).toRequest('0'); |
326 Response response = handler.handleRequest(request); | 322 Response response = handler.handleRequest(request); |
327 expect(response, isResponseSuccess('0')); | 323 expect(response, isResponseSuccess('0')); |
328 ExecutionCreateContextResult result = | 324 ExecutionCreateContextResult result = |
329 new ExecutionCreateContextResult.fromResponse(response); | 325 new ExecutionCreateContextResult.fromResponse(response); |
330 contextId = result.id; | 326 contextId = result.id; |
331 } | 327 } |
332 | 328 |
333 void _disposeExecutionContext() { | 329 void _disposeExecutionContext() { |
(...skipping 16 matching lines...) Expand all Loading... |
350 * A [Source] that knows it's [fullName]. | 346 * A [Source] that knows it's [fullName]. |
351 */ | 347 */ |
352 class TestSource implements Source { | 348 class TestSource implements Source { |
353 String fullName; | 349 String fullName; |
354 | 350 |
355 TestSource(this.fullName); | 351 TestSource(this.fullName); |
356 | 352 |
357 @override | 353 @override |
358 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 354 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
359 } | 355 } |
OLD | NEW |