Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(352)

Side by Side Diff: pkg/analyzer/test/src/context/context_test.dart

Issue 1200913002: Deprecate old HTML support (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pkg/analyzer/test/generated/engine_test.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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.src.context.context_test; 5 library test.src.context.context_test;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analyzer/src/cancelable_future.dart'; 9 import 'package:analyzer/src/cancelable_future.dart';
10 import 'package:analyzer/src/context/cache.dart'; 10 import 'package:analyzer/src/context/cache.dart';
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 class AnalysisContextImplTest extends AbstractContextTest { 54 class AnalysisContextImplTest extends AbstractContextTest {
55 void fail_applyChanges_empty() { 55 void fail_applyChanges_empty() {
56 context.applyChanges(new ChangeSet()); 56 context.applyChanges(new ChangeSet());
57 expect(context.performAnalysisTask().changeNotices, isNull); 57 expect(context.performAnalysisTask().changeNotices, isNull);
58 // This test appears to be flaky. If it is named "test_" it fails, if it's 58 // This test appears to be flaky. If it is named "test_" it fails, if it's
59 // named "fail_" it doesn't fail. I'm guessing that it's dependent on 59 // named "fail_" it doesn't fail. I'm guessing that it's dependent on
60 // whether some other test is run. 60 // whether some other test is run.
61 fail('Should have failed'); 61 fail('Should have failed');
62 } 62 }
63 63
64 void fail_computeHtmlElement_valid() {
65 Source source = addSource("/test.html", "<html></html>");
66 HtmlElement element = context.computeHtmlElement(source);
67 expect(element, isNotNull);
68 expect(context.computeHtmlElement(source), same(element));
69 }
70
71 void fail_extractContext() { 64 void fail_extractContext() {
72 fail("Implement this"); 65 fail("Implement this");
73 } 66 }
74 67
75 void fail_getHtmlElement_html() {
76 Source source = addSource("/test.html", "<html></html>");
77 HtmlElement element = context.getHtmlElement(source);
78 expect(element, isNull);
79 context.computeHtmlElement(source);
80 element = context.getHtmlElement(source);
81 expect(element, isNotNull);
82 }
83
84 void fail_getResolvedHtmlUnit() {
85 Source source = addSource("/test.html", "<html></html>");
86 expect(context.getResolvedHtmlUnit(source), isNull);
87 context.resolveHtmlUnit(source);
88 expect(context.getResolvedHtmlUnit(source), isNotNull);
89 }
90
91 void fail_mergeContext() { 68 void fail_mergeContext() {
92 fail("Implement this"); 69 fail("Implement this");
93 } 70 }
94 71
95 void fail_parseHtmlUnit_resolveDirectives() { 72 void fail_parseHtmlUnit_resolveDirectives() {
96 Source libSource = addSource("/lib.dart", r''' 73 Source libSource = addSource("/lib.dart", r'''
97 library lib; 74 library lib;
98 class ClassA {}'''); 75 class ClassA {}''');
99 Source source = addSource("/lib.html", r''' 76 Source source = addSource("/lib.html", r'''
100 <!DOCTYPE html> 77 <!DOCTYPE html>
101 <html> 78 <html>
102 <head> 79 <head>
103 <script type='application/dart'> 80 <script type='application/dart'>
104 import 'lib.dart'; 81 import 'lib.dart';
105 ClassA v = null; 82 ClassA v = null;
106 </script> 83 </script>
107 </head> 84 </head>
108 <body> 85 <body>
109 </body> 86 </body>
110 </html>'''); 87 </html>''');
88 // TODO(brianwilkerson) Rewrite this. We need a way to get the AST for the
89 // script.
111 ht.HtmlUnit unit = context.parseHtmlUnit(source); 90 ht.HtmlUnit unit = context.parseHtmlUnit(source);
112 expect(unit, isNotNull); 91 expect(unit, isNotNull);
113 // import directive should be resolved 92 // import directive should be resolved
114 ht.XmlTagNode htmlNode = unit.tagNodes[0]; 93 ht.XmlTagNode htmlNode = unit.tagNodes[0];
115 ht.XmlTagNode headNode = htmlNode.tagNodes[0]; 94 ht.XmlTagNode headNode = htmlNode.tagNodes[0];
116 ht.HtmlScriptTagNode scriptNode = headNode.tagNodes[0]; 95 ht.HtmlScriptTagNode scriptNode = headNode.tagNodes[0];
117 CompilationUnit script = scriptNode.script; 96 CompilationUnit script = scriptNode.script;
118 ImportDirective importNode = script.directives[0] as ImportDirective; 97 ImportDirective importNode = script.directives[0] as ImportDirective;
119 expect(importNode.uriContent, isNotNull); 98 expect(importNode.uriContent, isNotNull);
120 expect(importNode.source, libSource); 99 expect(importNode.source, libSource);
121 } 100 }
122 101
123 void fail_performAnalysisTask_getContentException_dart() { 102 void fail_performAnalysisTask_getContentException_dart() {
124 // add source that throw an exception on "get content" 103 Source source = _addSourceWithException('test.dart');
125 Source source = new _Source_getContent_throwException('test.dart');
126 {
127 ChangeSet changeSet = new ChangeSet();
128 changeSet.addedSource(source);
129 context.applyChanges(changeSet);
130 }
131 // prepare errors 104 // prepare errors
132 _analyzeAll_assertFinished(); 105 _analyzeAll_assertFinished();
133 List<AnalysisError> errors = context.getErrors(source).errors; 106 List<AnalysisError> errors = context.getErrors(source).errors;
134 // validate errors 107 // validate errors
135 expect(errors, hasLength(1)); 108 expect(errors, hasLength(1));
136 AnalysisError error = errors[0]; 109 AnalysisError error = errors[0];
137 expect(error.source, same(source)); 110 expect(error.source, same(source));
138 expect(error.errorCode, ScannerErrorCode.UNABLE_GET_CONTENT); 111 expect(error.errorCode, ScannerErrorCode.UNABLE_GET_CONTENT);
139 } 112 }
140 113
141 void fail_performAnalysisTask_getContentException_html() { 114 void fail_performAnalysisTask_getContentException_html() {
142 // add source that throw an exception on "get content" 115 Source source = _addSourceWithException('test.html');
143 Source source = new _Source_getContent_throwException('test.html');
144 {
145 ChangeSet changeSet = new ChangeSet();
146 changeSet.addedSource(source);
147 context.applyChanges(changeSet);
148 }
149 // prepare errors 116 // prepare errors
150 _analyzeAll_assertFinished(); 117 _analyzeAll_assertFinished();
151 List<AnalysisError> errors = context.getErrors(source).errors; 118 List<AnalysisError> errors = context.getErrors(source).errors;
152 // validate errors 119 // validate errors
153 expect(errors, hasLength(1)); 120 expect(errors, hasLength(1));
154 AnalysisError error = errors[0]; 121 AnalysisError error = errors[0];
155 expect(error.source, same(source)); 122 expect(error.source, same(source));
156 expect(error.errorCode, ScannerErrorCode.UNABLE_GET_CONTENT); 123 expect(error.errorCode, ScannerErrorCode.UNABLE_GET_CONTENT);
157 } 124 }
158 125
159 void fail_performAnalysisTask_importedLibraryAdd_html() { 126 void test_performAnalysisTask_importedLibraryAdd_html() {
160 Source htmlSource = addSource("/page.html", r''' 127 Source htmlSource = addSource("/page.html", r'''
161 <html><body><script type="application/dart"> 128 <html><body><script type="application/dart">
162 import '/libB.dart'; 129 import '/libB.dart';
163 main() {print('hello dart');} 130 main() {print('hello dart');}
164 </script></body></html>'''); 131 </script></body></html>''');
165 _analyzeAll_assertFinished(); 132 _analyzeAll_assertFinished();
166 expect(context.getResolvedHtmlUnit(htmlSource), isNotNull, 133 context.computeErrors(htmlSource);
167 reason: "htmlUnit resolved 1");
168 expect(_hasAnalysisErrorWithErrorSeverity(context.getErrors(htmlSource)), 134 expect(_hasAnalysisErrorWithErrorSeverity(context.getErrors(htmlSource)),
169 isTrue, reason: "htmlSource has an error"); 135 isTrue, reason: "htmlSource has an error");
170 // add libB.dart and analyze 136 // add libB.dart and analyze
171 Source libBSource = addSource("/libB.dart", "library libB;"); 137 Source libBSource = addSource("/libB.dart", "library libB;");
172 _analyzeAll_assertFinished(); 138 _analyzeAll_assertFinished();
173 expect(context.getResolvedHtmlUnit(htmlSource), isNotNull,
174 reason: "htmlUnit resolved 1");
175 expect( 139 expect(
176 context.getResolvedCompilationUnit2(libBSource, libBSource), isNotNull, 140 context.getResolvedCompilationUnit2(libBSource, libBSource), isNotNull,
177 reason: "libB resolved 2"); 141 reason: "libB resolved 2");
178 // TODO (danrubel) commented out to fix red bots 142 // TODO (danrubel) commented out to fix red bots
143 // context.computeErrors(htmlSource);
179 // AnalysisErrorInfo errors = _context.getErrors(htmlSource); 144 // AnalysisErrorInfo errors = _context.getErrors(htmlSource);
180 // expect( 145 // expect(
181 // !_hasAnalysisErrorWithErrorSeverity(errors), 146 // !_hasAnalysisErrorWithErrorSeverity(errors),
182 // isTrue, 147 // isTrue,
183 // reason: "htmlSource doesn't have errors"); 148 // reason: "htmlSource doesn't have errors");
184 } 149 }
185 150
186 void fail_performAnalysisTask_importedLibraryDelete_html() { 151 void fail_performAnalysisTask_importedLibraryDelete_html() {
187 // NOTE: This was failing before converting to the new task model. 152 // NOTE: This was failing before converting to the new task model.
188 Source htmlSource = addSource("/page.html", r''' 153 Source htmlSource = addSource("/page.html", r'''
189 <html><body><script type="application/dart"> 154 <html><body><script type="application/dart">
190 import 'libB.dart'; 155 import 'libB.dart';
191 main() {print('hello dart');} 156 main() {print('hello dart');}
192 </script></body></html>'''); 157 </script></body></html>''');
193 Source libBSource = addSource("/libB.dart", "library libB;"); 158 Source libBSource = addSource("/libB.dart", "library libB;");
194 _analyzeAll_assertFinished(); 159 _analyzeAll_assertFinished();
195 expect(context.getResolvedHtmlUnit(htmlSource), isNotNull, 160 context.computeErrors(htmlSource);
196 reason: "htmlUnit resolved 1");
197 expect( 161 expect(
198 context.getResolvedCompilationUnit2(libBSource, libBSource), isNotNull, 162 context.getResolvedCompilationUnit2(libBSource, libBSource), isNotNull,
199 reason: "libB resolved 1"); 163 reason: "libB resolved 1");
200 expect(!_hasAnalysisErrorWithErrorSeverity(context.getErrors(htmlSource)), 164 expect(!_hasAnalysisErrorWithErrorSeverity(context.getErrors(htmlSource)),
201 isTrue, reason: "htmlSource doesn't have errors"); 165 isTrue, reason: "htmlSource doesn't have errors");
202 // remove libB.dart content and analyze 166 // remove libB.dart content and analyze
203 context.setContents(libBSource, null); 167 context.setContents(libBSource, null);
204 _analyzeAll_assertFinished(); 168 _analyzeAll_assertFinished();
205 expect(context.getResolvedHtmlUnit(htmlSource), isNotNull, 169 context.computeErrors(htmlSource);
206 reason: "htmlUnit resolved 1");
207 AnalysisErrorInfo errors = context.getErrors(htmlSource); 170 AnalysisErrorInfo errors = context.getErrors(htmlSource);
208 expect(_hasAnalysisErrorWithErrorSeverity(errors), isTrue, 171 expect(_hasAnalysisErrorWithErrorSeverity(errors), isTrue,
209 reason: "htmlSource has an error"); 172 reason: "htmlSource has an error");
210 } 173 }
211 174
212 void fail_performAnalysisTask_IOException() { 175 void fail_performAnalysisTask_IOException() {
213 TestSource source = _addSourceWithException2("/test.dart", "library test;"); 176 TestSource source = _addSourceWithException2("/test.dart", "library test;");
214 int oldTimestamp = context.getModificationStamp(source); 177 int oldTimestamp = context.getModificationStamp(source);
215 source.generateExceptionOnRead = false; 178 source.generateExceptionOnRead = false;
216 _analyzeAll_assertFinished(); 179 _analyzeAll_assertFinished();
217 expect(source.readCount, 1); 180 expect(source.readCount, 1);
218 source.generateExceptionOnRead = true; 181 source.generateExceptionOnRead = true;
219 do { 182 do {
220 _changeSource(source, ""); 183 _changeSource(source, "");
221 // Ensure that the timestamp differs, 184 // Ensure that the timestamp differs,
222 // so that analysis engine notices the change 185 // so that analysis engine notices the change
223 } while (oldTimestamp == context.getModificationStamp(source)); 186 } while (oldTimestamp == context.getModificationStamp(source));
224 _analyzeAll_assertFinished(); 187 _analyzeAll_assertFinished();
225 expect(source.readCount, 2); 188 expect(source.readCount, 2);
226 } 189 }
227 190
228 void fail_recordLibraryElements() { 191 void fail_recordLibraryElements() {
229 fail("Implement this"); 192 fail("Implement this");
230 } 193 }
231 194
232 void fail_resolveHtmlUnit() {
233 Source source = addSource("/lib.html", "<html></html>");
234 ht.HtmlUnit unit = context.resolveHtmlUnit(source);
235 expect(unit, isNotNull);
236 }
237
238 void fail_setAnalysisOptions_reduceAnalysisPriorityOrder() { 195 void fail_setAnalysisOptions_reduceAnalysisPriorityOrder() {
239 AnalysisOptionsImpl options = 196 AnalysisOptionsImpl options =
240 new AnalysisOptionsImpl.from(context.analysisOptions); 197 new AnalysisOptionsImpl.from(context.analysisOptions);
241 List<Source> sources = new List<Source>(); 198 List<Source> sources = new List<Source>();
242 for (int index = 0; index < options.cacheSize; index++) { 199 for (int index = 0; index < options.cacheSize; index++) {
243 sources.add(addSource("/lib.dart$index", "")); 200 sources.add(addSource("/lib.dart$index", ""));
244 } 201 }
245 context.analysisPriorityOrder = sources; 202 context.analysisPriorityOrder = sources;
246 int oldPriorityOrderSize = _getPriorityOrder(context).length; 203 int oldPriorityOrderSize = _getPriorityOrder(context).length;
247 options.cacheSize = options.cacheSize - 10; 204 options.cacheSize = options.cacheSize - 10;
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
621 } 578 }
622 579
623 void test_computeExportedLibraries_some() { 580 void test_computeExportedLibraries_some() {
624 // addSource("/lib1.dart", "library lib1;"); 581 // addSource("/lib1.dart", "library lib1;");
625 // addSource("/lib2.dart", "library lib2;"); 582 // addSource("/lib2.dart", "library lib2;");
626 Source source = addSource( 583 Source source = addSource(
627 "/test.dart", "library test; export 'lib1.dart'; export 'lib2.dart';"); 584 "/test.dart", "library test; export 'lib1.dart'; export 'lib2.dart';");
628 expect(context.computeExportedLibraries(source), hasLength(2)); 585 expect(context.computeExportedLibraries(source), hasLength(2));
629 } 586 }
630 587
631 void test_computeHtmlElement_nonHtml() {
632 Source source = addSource("/test.dart", "library test;");
633 expect(context.computeHtmlElement(source), isNull);
634 }
635
636 void test_computeImportedLibraries_none() { 588 void test_computeImportedLibraries_none() {
637 Source source = addSource("/test.dart", "library test;"); 589 Source source = addSource("/test.dart", "library test;");
638 expect(context.computeImportedLibraries(source), hasLength(0)); 590 expect(context.computeImportedLibraries(source), hasLength(0));
639 } 591 }
640 592
641 void test_computeImportedLibraries_some() { 593 void test_computeImportedLibraries_some() {
642 Source source = addSource( 594 Source source = addSource(
643 "/test.dart", "library test; import 'lib1.dart'; import 'lib2.dart';"); 595 "/test.dart", "library test; import 'lib1.dart'; import 'lib2.dart';");
644 expect(context.computeImportedLibraries(source), hasLength(2)); 596 expect(context.computeImportedLibraries(source), hasLength(2));
645 } 597 }
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
1036 <script type='application/dart' src='test.dart'/> 988 <script type='application/dart' src='test.dart'/>
1037 </head></html>'''); 989 </head></html>''');
1038 AnalysisErrorInfo errorInfo = context.getErrors(source); 990 AnalysisErrorInfo errorInfo = context.getErrors(source);
1039 expect(errorInfo, isNotNull); 991 expect(errorInfo, isNotNull);
1040 List<AnalysisError> errors = errorInfo.errors; 992 List<AnalysisError> errors = errorInfo.errors;
1041 expect(errors, hasLength(0)); 993 expect(errors, hasLength(0));
1042 errors = context.computeErrors(source); 994 errors = context.computeErrors(source);
1043 expect(errors, hasLength(3)); 995 expect(errors, hasLength(3));
1044 } 996 }
1045 997
1046 void test_getHtmlElement_dart() {
1047 Source source = addSource("/test.dart", "");
1048 expect(context.getHtmlElement(source), isNull);
1049 expect(context.computeHtmlElement(source), isNull);
1050 expect(context.getHtmlElement(source), isNull);
1051 }
1052
1053 void test_getHtmlFilesReferencing_html() { 998 void test_getHtmlFilesReferencing_html() {
1054 Source htmlSource = addSource("/test.html", r''' 999 Source htmlSource = addSource("/test.html", r'''
1055 <html><head> 1000 <html><head>
1056 <script type='application/dart' src='test.dart'/> 1001 <script type='application/dart' src='test.dart'/>
1057 <script type='application/dart' src='test.js'/> 1002 <script type='application/dart' src='test.js'/>
1058 </head></html>'''); 1003 </head></html>''');
1059 Source librarySource = addSource("/test.dart", "library lib;"); 1004 Source librarySource = addSource("/test.dart", "library lib;");
1060 Source secondHtmlSource = addSource("/test.html", "<html></html>"); 1005 Source secondHtmlSource = addSource("/test.html", "<html></html>");
1061 context.computeLibraryElement(librarySource); 1006 context.computeLibraryElement(librarySource);
1062 List<Source> result = context.getHtmlFilesReferencing(secondHtmlSource); 1007 List<Source> result = context.getHtmlFilesReferencing(secondHtmlSource);
1063 expect(result, hasLength(0)); 1008 expect(result, hasLength(0));
1064 context.parseHtmlDocument(htmlSource); 1009 context.parseHtmlDocument(htmlSource);
1065 result = context.getHtmlFilesReferencing(secondHtmlSource); 1010 result = context.getHtmlFilesReferencing(secondHtmlSource);
1066 expect(result, hasLength(0)); 1011 expect(result, hasLength(0));
1067 } 1012 }
1068 1013
1069 void test_getHtmlFilesReferencing_library() { 1014 void test_getHtmlFilesReferencing_library() {
1070 Source htmlSource = addSource("/test.html", r''' 1015 Source htmlSource = addSource("/test.html", r'''
1071 <!DOCTYPE html> 1016 <!DOCTYPE html>
1072 <html><head> 1017 <html><head>
1073 <script type='application/dart' src='test.dart'/> 1018 <script type='application/dart' src='test.dart'/>
1074 <script type='application/dart' src='test.js'/> 1019 <script type='application/dart' src='test.js'/>
1075 </head></html>'''); 1020 </head></html>''');
1076 Source librarySource = addSource("/test.dart", "library lib;"); 1021 Source librarySource = addSource("/test.dart", "library lib;");
1077 context.computeLibraryElement(librarySource); 1022 context.computeLibraryElement(librarySource);
1078 List<Source> result = context.getHtmlFilesReferencing(librarySource); 1023 List<Source> result = context.getHtmlFilesReferencing(librarySource);
1079 expect(result, hasLength(0)); 1024 expect(result, hasLength(0));
1080 context.computeHtmlElement(htmlSource); 1025 // Indirectly force the data to be computed.
1026 context.computeErrors(htmlSource);
1081 result = context.getHtmlFilesReferencing(librarySource); 1027 result = context.getHtmlFilesReferencing(librarySource);
1082 expect(result, hasLength(1)); 1028 expect(result, hasLength(1));
1083 expect(result[0], htmlSource); 1029 expect(result[0], htmlSource);
1084 } 1030 }
1085 1031
1086 void test_getHtmlFilesReferencing_part() { 1032 void test_getHtmlFilesReferencing_part() {
1087 Source htmlSource = addSource("/test.html", r''' 1033 Source htmlSource = addSource("/test.html", r'''
1088 <!DOCTYPE html> 1034 <!DOCTYPE html>
1089 <html><head> 1035 <html><head>
1090 <script type='application/dart' src='test.dart'/> 1036 <script type='application/dart' src='test.dart'/>
1091 <script type='application/dart' src='test.js'/> 1037 <script type='application/dart' src='test.js'/>
1092 </head></html>'''); 1038 </head></html>''');
1093 Source librarySource = 1039 Source librarySource =
1094 addSource("/test.dart", "library lib; part 'part.dart';"); 1040 addSource("/test.dart", "library lib; part 'part.dart';");
1095 Source partSource = addSource("/part.dart", "part of lib;"); 1041 Source partSource = addSource("/part.dart", "part of lib;");
1096 context.computeLibraryElement(librarySource); 1042 context.computeLibraryElement(librarySource);
1097 List<Source> result = context.getHtmlFilesReferencing(partSource); 1043 List<Source> result = context.getHtmlFilesReferencing(partSource);
1098 expect(result, hasLength(0)); 1044 expect(result, hasLength(0));
1099 context.computeHtmlElement(htmlSource); 1045 // Indirectly force the data to be computed.
1046 context.computeErrors(htmlSource);
1100 result = context.getHtmlFilesReferencing(partSource); 1047 result = context.getHtmlFilesReferencing(partSource);
1101 expect(result, hasLength(1)); 1048 expect(result, hasLength(1));
1102 expect(result[0], htmlSource); 1049 expect(result[0], htmlSource);
1103 } 1050 }
1104 1051
1105 void test_getHtmlSources() { 1052 void test_getHtmlSources() {
1106 List<Source> sources = context.htmlSources; 1053 List<Source> sources = context.htmlSources;
1107 expect(sources, hasLength(0)); 1054 expect(sources, hasLength(0));
1108 Source source = addSource("/test.html", ""); 1055 Source source = addSource("/test.html", "");
1109 sources = context.htmlSources; 1056 sources = context.htmlSources;
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
1248 1195
1249 void test_getLibrariesReferencedFromHtml() { 1196 void test_getLibrariesReferencedFromHtml() {
1250 Source htmlSource = addSource("/test.html", r''' 1197 Source htmlSource = addSource("/test.html", r'''
1251 <!DOCTYPE html> 1198 <!DOCTYPE html>
1252 <html><head> 1199 <html><head>
1253 <script type='application/dart' src='test.dart'/> 1200 <script type='application/dart' src='test.dart'/>
1254 <script type='application/dart' src='test.js'/> 1201 <script type='application/dart' src='test.js'/>
1255 </head></html>'''); 1202 </head></html>''');
1256 Source librarySource = addSource("/test.dart", "library lib;"); 1203 Source librarySource = addSource("/test.dart", "library lib;");
1257 context.computeLibraryElement(librarySource); 1204 context.computeLibraryElement(librarySource);
1258 context.computeHtmlElement(htmlSource); 1205 // Indirectly force the data to be computed.
1206 context.computeErrors(htmlSource);
1259 List<Source> result = context.getLibrariesReferencedFromHtml(htmlSource); 1207 List<Source> result = context.getLibrariesReferencedFromHtml(htmlSource);
1260 expect(result, hasLength(1)); 1208 expect(result, hasLength(1));
1261 expect(result[0], librarySource); 1209 expect(result[0], librarySource);
1262 } 1210 }
1263 1211
1264 void test_getLibrariesReferencedFromHtml_none() { 1212 void test_getLibrariesReferencedFromHtml_none() {
1265 Source htmlSource = addSource("/test.html", r''' 1213 Source htmlSource = addSource("/test.html", r'''
1266 <html><head> 1214 <html><head>
1267 <script type='application/dart' src='test.js'/> 1215 <script type='application/dart' src='test.js'/>
1268 </head></html>'''); 1216 </head></html>''');
(...skipping 829 matching lines...) Expand 10 before | Expand all | Expand 10 after
2098 List<AnalysisError> errors = errorInfo.errors; 2046 List<AnalysisError> errors = errorInfo.errors;
2099 for (AnalysisError analysisError in errors) { 2047 for (AnalysisError analysisError in errors) {
2100 if (analysisError.errorCode.errorSeverity == ErrorSeverity.ERROR) { 2048 if (analysisError.errorCode.errorSeverity == ErrorSeverity.ERROR) {
2101 return true; 2049 return true;
2102 } 2050 }
2103 } 2051 }
2104 return false; 2052 return false;
2105 } 2053 }
2106 } 2054 }
2107 2055
2108 //class FakeSdk extends DirectoryBasedDartSdk {
2109 // FakeSdk(JavaFile arg0) : super(arg0);
2110 //
2111 // @override
2112 // LibraryMap initialLibraryMap(bool useDart2jsPaths) {
2113 // LibraryMap map = new LibraryMap();
2114 // _addLibrary(map, DartSdk.DART_ASYNC, false, "async.dart");
2115 // _addLibrary(map, DartSdk.DART_CORE, false, "core.dart");
2116 // _addLibrary(map, DartSdk.DART_HTML, false, "html_dartium.dart");
2117 // _addLibrary(map, "dart:math", false, "math.dart");
2118 // _addLibrary(map, "dart:_interceptors", true, "_interceptors.dart");
2119 // _addLibrary(map, "dart:_js_helper", true, "_js_helper.dart");
2120 // return map;
2121 // }
2122 //
2123 // void _addLibrary(LibraryMap map, String uri, bool isInternal, String path) {
2124 // SdkLibraryImpl library = new SdkLibraryImpl(uri);
2125 // if (isInternal) {
2126 // library.category = "Internal";
2127 // }
2128 // library.path = path;
2129 // map.setLibrary(uri, library);
2130 // }
2131 //}
2132
2133 class _AnalysisContextImplTest_test_applyChanges_removeContainer 2056 class _AnalysisContextImplTest_test_applyChanges_removeContainer
2134 implements SourceContainer { 2057 implements SourceContainer {
2135 Source libB; 2058 Source libB;
2136 _AnalysisContextImplTest_test_applyChanges_removeContainer(this.libB); 2059 _AnalysisContextImplTest_test_applyChanges_removeContainer(this.libB);
2137 @override 2060 @override
2138 bool contains(Source source) => source == libB; 2061 bool contains(Source source) => source == libB;
2139 } 2062 }
2140
2141 class _Source_getContent_throwException extends NonExistingSource {
2142 _Source_getContent_throwException(String name)
2143 : super(name, pathos.toUri(name), UriKind.FILE_URI);
2144
2145 @override
2146 TimestampedData<String> get contents {
2147 throw 'Read error';
2148 }
2149
2150 @override
2151 bool exists() => true;
2152 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/generated/engine_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698