| 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 } | 46 } |
| 47 | 47 |
| 48 @reflectiveTest | 48 @reflectiveTest |
| 49 class CompletionManagerTest extends AbstractAnalysisTest { | 49 class CompletionManagerTest extends AbstractAnalysisTest { |
| 50 AnalysisDomainHandler analysisDomain; | 50 AnalysisDomainHandler analysisDomain; |
| 51 Test_CompletionDomainHandler completionDomain; | 51 Test_CompletionDomainHandler completionDomain; |
| 52 Request request; | 52 Request request; |
| 53 int requestCount = 0; | 53 int requestCount = 0; |
| 54 String testFile2 = '/project/bin/test2.dart'; | 54 String testFile2 = '/project/bin/test2.dart'; |
| 55 | 55 |
| 56 /// Cached model state in case tests need to set task model to on/off. | |
| 57 bool wasTaskModelEnabled; | |
| 58 | |
| 59 AnalysisServer createAnalysisServer(Index index) { | 56 AnalysisServer createAnalysisServer(Index index) { |
| 60 // | 57 // |
| 61 // Collect plugins | 58 // Collect plugins |
| 62 // | 59 // |
| 63 ServerPlugin serverPlugin = new ServerPlugin(); | 60 ServerPlugin serverPlugin = new ServerPlugin(); |
| 64 List<Plugin> plugins = <Plugin>[]; | 61 List<Plugin> plugins = <Plugin>[]; |
| 65 plugins.addAll(AnalysisEngine.instance.requiredPlugins); | 62 plugins.addAll(AnalysisEngine.instance.requiredPlugins); |
| 66 plugins.add(serverPlugin); | 63 plugins.add(serverPlugin); |
| 67 addServerPlugins(plugins); | 64 addServerPlugins(plugins); |
| 68 // | 65 // |
| (...skipping 23 matching lines...) Expand all Loading... |
| 92 void sendRequest(String path) { | 89 void sendRequest(String path) { |
| 93 String id = (++requestCount).toString(); | 90 String id = (++requestCount).toString(); |
| 94 request = new CompletionGetSuggestionsParams(path, 0).toRequest(id); | 91 request = new CompletionGetSuggestionsParams(path, 0).toRequest(id); |
| 95 Response response = handler.handleRequest(request); | 92 Response response = handler.handleRequest(request); |
| 96 expect(response, isResponseSuccess(id)); | 93 expect(response, isResponseSuccess(id)); |
| 97 } | 94 } |
| 98 | 95 |
| 99 @override | 96 @override |
| 100 void setUp() { | 97 void setUp() { |
| 101 super.setUp(); | 98 super.setUp(); |
| 102 wasTaskModelEnabled = AnalysisEngine.instance.useTaskModel; | |
| 103 AnalysisEngine.instance.useTaskModel = true; | |
| 104 createProject(); | 99 createProject(); |
| 105 analysisDomain = handler; | 100 analysisDomain = handler; |
| 106 completionDomain = new Test_CompletionDomainHandler(server); | 101 completionDomain = new Test_CompletionDomainHandler(server); |
| 107 handler = completionDomain; | 102 handler = completionDomain; |
| 108 addTestFile('^library A; cl'); | 103 addTestFile('^library A; cl'); |
| 109 addFile(testFile2, 'library B; cl'); | 104 addFile(testFile2, 'library B; cl'); |
| 110 } | 105 } |
| 111 | 106 |
| 112 void tearDown() { | 107 void tearDown() { |
| 113 super.tearDown(); | 108 super.tearDown(); |
| 114 analysisDomain = null; | 109 analysisDomain = null; |
| 115 completionDomain = null; | 110 completionDomain = null; |
| 116 AnalysisEngine.instance.useTaskModel = wasTaskModelEnabled; | |
| 117 } | 111 } |
| 118 | 112 |
| 119 /** | 113 /** |
| 120 * Assert different managers are used for different sources | 114 * Assert different managers are used for different sources |
| 121 */ | 115 */ |
| 122 test_2_requests_different_sources() { | 116 test_2_requests_different_sources() { |
| 123 expect(completionDomain.manager, isNull); | 117 expect(completionDomain.manager, isNull); |
| 124 sendRequest(testFile); | 118 sendRequest(testFile); |
| 125 expect(completionDomain.manager, isNotNull); | 119 expect(completionDomain.manager, isNotNull); |
| 126 MockCompletionManager expectedManager = completionDomain.manager; | 120 MockCompletionManager expectedManager = completionDomain.manager; |
| (...skipping 731 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 858 } | 852 } |
| 859 '''); | 853 '''); |
| 860 await waitForTasksFinished(); | 854 await waitForTasksFinished(); |
| 861 Request request = | 855 Request request = |
| 862 new CompletionGetSuggestionsParams(testFile, 0).toRequest('0'); | 856 new CompletionGetSuggestionsParams(testFile, 0).toRequest('0'); |
| 863 Response response = handler.handleRequest(request); | 857 Response response = handler.handleRequest(request); |
| 864 expect(response.error, isNotNull); | 858 expect(response.error, isNotNull); |
| 865 expect(response.error.code, RequestErrorCode.NO_INDEX_GENERATED); | 859 expect(response.error.code, RequestErrorCode.NO_INDEX_GENERATED); |
| 866 } | 860 } |
| 867 } | 861 } |
| OLD | NEW |