OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 analyzer.test.src.task.html_work_manager_test; | 5 library analyzer.test.src.task.html_work_manager_test; |
6 | 6 |
7 import 'package:analyzer/error/error.dart' show AnalysisError; | 7 import 'package:analyzer/error/error.dart' show AnalysisError; |
8 import 'package:analyzer/exception/exception.dart'; | 8 import 'package:analyzer/exception/exception.dart'; |
9 import 'package:analyzer/src/context/cache.dart'; | 9 import 'package:analyzer/src/context/cache.dart'; |
10 import 'package:analyzer/src/context/context.dart'; | 10 import 'package:analyzer/src/context/context.dart'; |
(...skipping 20 matching lines...) Expand all Loading... |
31 import '../../generated/test_support.dart'; | 31 import '../../generated/test_support.dart'; |
32 | 32 |
33 main() { | 33 main() { |
34 defineReflectiveSuite(() { | 34 defineReflectiveSuite(() { |
35 defineReflectiveTests(HtmlWorkManagerTest); | 35 defineReflectiveTests(HtmlWorkManagerTest); |
36 defineReflectiveTests(HtmlWorkManagerIntegrationTest); | 36 defineReflectiveTests(HtmlWorkManagerIntegrationTest); |
37 }); | 37 }); |
38 } | 38 } |
39 | 39 |
40 @reflectiveTest | 40 @reflectiveTest |
| 41 class HtmlWorkManagerIntegrationTest { |
| 42 InternalAnalysisContext context = new AnalysisContextImpl(); |
| 43 HtmlWorkManager manager; |
| 44 |
| 45 Source source1 = new TestSource('1.html'); |
| 46 Source source2 = new TestSource('2.html'); |
| 47 CacheEntry entry1; |
| 48 CacheEntry entry2; |
| 49 |
| 50 void expect_sourceQueue(List<Source> sources) { |
| 51 expect(manager.sourceQueue, unorderedEquals(sources)); |
| 52 } |
| 53 |
| 54 void setUp() { |
| 55 manager = new HtmlWorkManager(context); |
| 56 entry1 = context.getCacheEntry(source1); |
| 57 entry2 = context.getCacheEntry(source2); |
| 58 } |
| 59 |
| 60 void |
| 61 test_onResultInvalidated_scheduleInvalidatedLibrariesAfterSetSourceFactory
() { |
| 62 // Change the source factory, changing the analysis cache from when |
| 63 // the work manager was constructed. This used to create a failure |
| 64 // case for test_onResultInvalidated_scheduleInvalidLibraries so its |
| 65 // tested here. |
| 66 context.sourceFactory = new _SourceFactoryMock(); |
| 67 |
| 68 // now just do the same checks as |
| 69 // test_onResultInvalidated_scheduleInvalidLibraries |
| 70 |
| 71 // set HTML_ERRORS for source1 and source2 |
| 72 entry1.setValue(HTML_ERRORS, [], []); |
| 73 entry2.setValue(HTML_ERRORS, [], []); |
| 74 // invalidate HTML_ERRORS for source1, schedule it |
| 75 entry1.setState(HTML_ERRORS, CacheState.INVALID); |
| 76 expect_sourceQueue([source1]); |
| 77 // invalidate HTML_ERRORS for source2, schedule it |
| 78 entry2.setState(HTML_ERRORS, CacheState.INVALID); |
| 79 expect_sourceQueue([source1, source2]); |
| 80 } |
| 81 } |
| 82 |
| 83 @reflectiveTest |
41 class HtmlWorkManagerTest { | 84 class HtmlWorkManagerTest { |
42 InternalAnalysisContext context = new _InternalAnalysisContextMock(); | 85 InternalAnalysisContext context = new _InternalAnalysisContextMock(); |
43 AnalysisCache cache; | 86 AnalysisCache cache; |
44 HtmlWorkManager manager; | 87 HtmlWorkManager manager; |
45 | 88 |
46 CaughtException caughtException = new CaughtException(null, null); | 89 CaughtException caughtException = new CaughtException(null, null); |
47 | 90 |
48 Source source1 = new TestSource('1.html'); | 91 Source source1 = new TestSource('1.html'); |
49 Source source2 = new TestSource('2.html'); | 92 Source source2 = new TestSource('2.html'); |
50 Source source3 = new TestSource('3.html'); | 93 Source source3 = new TestSource('3.html'); |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 entry1.setValue(HTML_ERRORS, <AnalysisError>[error1, error2], []); | 341 entry1.setValue(HTML_ERRORS, <AnalysisError>[error1, error2], []); |
299 // RESOLVED_UNIT is ready, set errors | 342 // RESOLVED_UNIT is ready, set errors |
300 manager.resultsComputed(source1, {HTML_ERRORS: null}); | 343 manager.resultsComputed(source1, {HTML_ERRORS: null}); |
301 // all of the errors are included | 344 // all of the errors are included |
302 ChangeNoticeImpl notice = context.getNotice(source1); | 345 ChangeNoticeImpl notice = context.getNotice(source1); |
303 expect(notice.errors, unorderedEquals([error1, error2])); | 346 expect(notice.errors, unorderedEquals([error1, error2])); |
304 expect(notice.lineInfo, lineInfo); | 347 expect(notice.lineInfo, lineInfo); |
305 } | 348 } |
306 } | 349 } |
307 | 350 |
308 @reflectiveTest | |
309 class HtmlWorkManagerIntegrationTest { | |
310 InternalAnalysisContext context = new AnalysisContextImpl(); | |
311 HtmlWorkManager manager; | |
312 | |
313 Source source1 = new TestSource('1.html'); | |
314 Source source2 = new TestSource('2.html'); | |
315 CacheEntry entry1; | |
316 CacheEntry entry2; | |
317 | |
318 void expect_sourceQueue(List<Source> sources) { | |
319 expect(manager.sourceQueue, unorderedEquals(sources)); | |
320 } | |
321 | |
322 void setUp() { | |
323 manager = new HtmlWorkManager(context); | |
324 entry1 = context.getCacheEntry(source1); | |
325 entry2 = context.getCacheEntry(source2); | |
326 } | |
327 | |
328 void | |
329 test_onResultInvalidated_scheduleInvalidatedLibrariesAfterSetSourceFactory
() { | |
330 // Change the source factory, changing the analysis cache from when | |
331 // the work manager was constructed. This used to create a failure | |
332 // case for test_onResultInvalidated_scheduleInvalidLibraries so its | |
333 // tested here. | |
334 context.sourceFactory = new _SourceFactoryMock(); | |
335 | |
336 // now just do the same checks as | |
337 // test_onResultInvalidated_scheduleInvalidLibraries | |
338 | |
339 // set HTML_ERRORS for source1 and source2 | |
340 entry1.setValue(HTML_ERRORS, [], []); | |
341 entry2.setValue(HTML_ERRORS, [], []); | |
342 // invalidate HTML_ERRORS for source1, schedule it | |
343 entry1.setState(HTML_ERRORS, CacheState.INVALID); | |
344 expect_sourceQueue([source1]); | |
345 // invalidate HTML_ERRORS for source2, schedule it | |
346 entry2.setState(HTML_ERRORS, CacheState.INVALID); | |
347 expect_sourceQueue([source1, source2]); | |
348 } | |
349 } | |
350 | |
351 class _SourceFactoryMock extends TypedMock implements SourceFactory {} | |
352 | |
353 class _InternalAnalysisContextMock extends TypedMock | 351 class _InternalAnalysisContextMock extends TypedMock |
354 implements InternalAnalysisContext { | 352 implements InternalAnalysisContext { |
355 @override | 353 @override |
356 CachePartition privateAnalysisCachePartition; | 354 CachePartition privateAnalysisCachePartition; |
357 | 355 |
358 @override | 356 @override |
359 AnalysisCache analysisCache; | 357 AnalysisCache analysisCache; |
360 | 358 |
361 // The production version is a stream that carries messages from the cache | 359 // The production version is a stream that carries messages from the cache |
362 // since the cache changes. Here, we can just pass the inner stream because | 360 // since the cache changes. Here, we can just pass the inner stream because |
363 // it doesn't change. | 361 // it doesn't change. |
364 @override | |
365 get onResultInvalidated => analysisCache.onResultInvalidated; | |
366 | |
367 Map<Source, ChangeNoticeImpl> _pendingNotices = <Source, ChangeNoticeImpl>{}; | 362 Map<Source, ChangeNoticeImpl> _pendingNotices = <Source, ChangeNoticeImpl>{}; |
368 | 363 |
369 _InternalAnalysisContextMock() { | 364 _InternalAnalysisContextMock() { |
370 privateAnalysisCachePartition = new UniversalCachePartition(this); | 365 privateAnalysisCachePartition = new UniversalCachePartition(this); |
371 analysisCache = new AnalysisCache([privateAnalysisCachePartition]); | 366 analysisCache = new AnalysisCache([privateAnalysisCachePartition]); |
372 } | 367 } |
373 | 368 |
374 @override | 369 @override |
| 370 get onResultInvalidated => analysisCache.onResultInvalidated; |
| 371 |
| 372 @override |
375 CacheEntry getCacheEntry(AnalysisTarget target) { | 373 CacheEntry getCacheEntry(AnalysisTarget target) { |
376 CacheEntry entry = analysisCache.get(target); | 374 CacheEntry entry = analysisCache.get(target); |
377 if (entry == null) { | 375 if (entry == null) { |
378 entry = new CacheEntry(target); | 376 entry = new CacheEntry(target); |
379 analysisCache.put(entry); | 377 analysisCache.put(entry); |
380 } | 378 } |
381 return entry; | 379 return entry; |
382 } | 380 } |
383 | 381 |
384 @override | 382 @override |
385 AnalysisErrorInfo getErrors(Source source) { | 383 AnalysisErrorInfo getErrors(Source source) { |
386 String name = source.shortName; | 384 String name = source.shortName; |
387 List<AnalysisError> errors = AnalysisError.NO_ERRORS; | 385 List<AnalysisError> errors = AnalysisError.NO_ERRORS; |
388 if (AnalysisEngine.isDartFileName(name) || source is DartScript) { | 386 if (AnalysisEngine.isDartFileName(name) || source is DartScript) { |
389 errors = getCacheEntry(source).getValue(DART_ERRORS); | 387 errors = getCacheEntry(source).getValue(DART_ERRORS); |
390 } else if (AnalysisEngine.isHtmlFileName(name)) { | 388 } else if (AnalysisEngine.isHtmlFileName(name)) { |
391 errors = getCacheEntry(source).getValue(HTML_ERRORS); | 389 errors = getCacheEntry(source).getValue(HTML_ERRORS); |
392 } | 390 } |
393 return new AnalysisErrorInfoImpl( | 391 return new AnalysisErrorInfoImpl( |
394 errors, getCacheEntry(source).getValue(LINE_INFO)); | 392 errors, getCacheEntry(source).getValue(LINE_INFO)); |
395 } | 393 } |
396 | 394 |
397 @override | 395 @override |
398 ChangeNoticeImpl getNotice(Source source) { | 396 ChangeNoticeImpl getNotice(Source source) { |
399 return _pendingNotices.putIfAbsent( | 397 return _pendingNotices.putIfAbsent( |
400 source, () => new ChangeNoticeImpl(source)); | 398 source, () => new ChangeNoticeImpl(source)); |
401 } | 399 } |
402 } | 400 } |
| 401 |
| 402 class _SourceFactoryMock extends TypedMock implements SourceFactory {} |
OLD | NEW |