| 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.completion; | 5 library test.domain.completion; |
| 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 } | 47 } |
| 48 | 48 |
| 49 @reflectiveTest | 49 @reflectiveTest |
| 50 class CompletionManagerTest extends AbstractAnalysisTest { | 50 class CompletionManagerTest extends AbstractAnalysisTest { |
| 51 AnalysisDomainHandler analysisDomain; | 51 AnalysisDomainHandler analysisDomain; |
| 52 Test_CompletionDomainHandler completionDomain; | 52 Test_CompletionDomainHandler completionDomain; |
| 53 Request request; | 53 Request request; |
| 54 int requestCount = 0; | 54 int requestCount = 0; |
| 55 String testFile2 = '/project/bin/test2.dart'; | 55 String testFile2 = '/project/bin/test2.dart'; |
| 56 | 56 |
| 57 /// Cached model state in case tests need to set task model to on/off. |
| 58 bool wasTaskModelEnabled; |
| 59 |
| 57 AnalysisServer createAnalysisServer(Index index) { | 60 AnalysisServer createAnalysisServer(Index index) { |
| 58 ExtensionManager manager = new ExtensionManager(); | 61 ExtensionManager manager = new ExtensionManager(); |
| 59 ServerPlugin serverPlugin = new ServerPlugin(); | 62 ServerPlugin serverPlugin = new ServerPlugin(); |
| 60 manager.processPlugins([serverPlugin]); | 63 manager.processPlugins([serverPlugin]); |
| 61 return new Test_AnalysisServer( | 64 return new Test_AnalysisServer( |
| 62 super.serverChannel, | 65 super.serverChannel, |
| 63 super.resourceProvider, | 66 super.resourceProvider, |
| 64 super.packageMapProvider, | 67 super.packageMapProvider, |
| 65 index, | 68 index, |
| 66 serverPlugin, | 69 serverPlugin, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 77 void sendRequest(String path) { | 80 void sendRequest(String path) { |
| 78 String id = (++requestCount).toString(); | 81 String id = (++requestCount).toString(); |
| 79 request = new CompletionGetSuggestionsParams(path, 0).toRequest(id); | 82 request = new CompletionGetSuggestionsParams(path, 0).toRequest(id); |
| 80 Response response = handler.handleRequest(request); | 83 Response response = handler.handleRequest(request); |
| 81 expect(response, isResponseSuccess(id)); | 84 expect(response, isResponseSuccess(id)); |
| 82 } | 85 } |
| 83 | 86 |
| 84 @override | 87 @override |
| 85 void setUp() { | 88 void setUp() { |
| 86 super.setUp(); | 89 super.setUp(); |
| 90 wasTaskModelEnabled = AnalysisEngine.instance.useTaskModel; |
| 91 AnalysisEngine.instance.useTaskModel = true; |
| 87 createProject(); | 92 createProject(); |
| 88 analysisDomain = handler; | 93 analysisDomain = handler; |
| 89 completionDomain = new Test_CompletionDomainHandler(server); | 94 completionDomain = new Test_CompletionDomainHandler(server); |
| 90 handler = completionDomain; | 95 handler = completionDomain; |
| 91 addTestFile('^library A; cl'); | 96 addTestFile('^library A; cl'); |
| 92 addFile(testFile2, 'library B; cl'); | 97 addFile(testFile2, 'library B; cl'); |
| 93 } | 98 } |
| 94 | 99 |
| 95 void tearDown() { | 100 void tearDown() { |
| 96 super.tearDown(); | 101 super.tearDown(); |
| 97 analysisDomain = null; | 102 analysisDomain = null; |
| 98 completionDomain = null; | 103 completionDomain = null; |
| 104 AnalysisEngine.instance.useTaskModel = wasTaskModelEnabled; |
| 99 } | 105 } |
| 100 | 106 |
| 101 /** | 107 /** |
| 102 * Assert different managers are used for different sources | 108 * Assert different managers are used for different sources |
| 103 */ | 109 */ |
| 104 test_2_requests_different_sources() { | 110 test_2_requests_different_sources() { |
| 105 expect(completionDomain.manager, isNull); | 111 expect(completionDomain.manager, isNull); |
| 106 sendRequest(testFile); | 112 sendRequest(testFile); |
| 107 expect(completionDomain.manager, isNotNull); | 113 expect(completionDomain.manager, isNotNull); |
| 108 MockCompletionManager expectedManager = completionDomain.manager; | 114 MockCompletionManager expectedManager = completionDomain.manager; |
| (...skipping 730 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 839 } | 845 } |
| 840 '''); | 846 '''); |
| 841 await waitForTasksFinished(); | 847 await waitForTasksFinished(); |
| 842 Request request = | 848 Request request = |
| 843 new CompletionGetSuggestionsParams(testFile, 0).toRequest('0'); | 849 new CompletionGetSuggestionsParams(testFile, 0).toRequest('0'); |
| 844 Response response = handler.handleRequest(request); | 850 Response response = handler.handleRequest(request); |
| 845 expect(response.error, isNotNull); | 851 expect(response.error, isNotNull); |
| 846 expect(response.error.code, RequestErrorCode.NO_INDEX_GENERATED); | 852 expect(response.error.code, RequestErrorCode.NO_INDEX_GENERATED); |
| 847 } | 853 } |
| 848 } | 854 } |
| OLD | NEW |