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

Side by Side Diff: pkg/analyzer/test/src/task/html_work_manager_test.dart

Issue 2454233003: Ensure HtmlWorkManager is subscribed to the right stream for invalidations in the presence of Sourc… (Closed)
Patch Set: Move new html work manager test class into existing test file (plus capitalize comment and add peri… Created 4 years, 1 month 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/lib/src/task/html_work_manager.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) 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/error/codes.dart' show HtmlErrorCode; 11 import 'package:analyzer/src/error/codes.dart' show HtmlErrorCode;
11 import 'package:analyzer/src/generated/engine.dart' 12 import 'package:analyzer/src/generated/engine.dart'
12 show 13 show
13 AnalysisEngine, 14 AnalysisEngine,
14 AnalysisErrorInfo, 15 AnalysisErrorInfo,
15 AnalysisErrorInfoImpl, 16 AnalysisErrorInfoImpl,
16 CacheState, 17 CacheState,
17 ChangeNoticeImpl, 18 ChangeNoticeImpl,
18 InternalAnalysisContext; 19 InternalAnalysisContext;
19 import 'package:analyzer/src/generated/source.dart'; 20 import 'package:analyzer/src/generated/source.dart';
20 import 'package:analyzer/src/task/html.dart'; 21 import 'package:analyzer/src/task/html.dart';
21 import 'package:analyzer/src/task/html_work_manager.dart'; 22 import 'package:analyzer/src/task/html_work_manager.dart';
22 import 'package:analyzer/task/dart.dart'; 23 import 'package:analyzer/task/dart.dart';
23 import 'package:analyzer/task/general.dart'; 24 import 'package:analyzer/task/general.dart';
24 import 'package:analyzer/task/html.dart'; 25 import 'package:analyzer/task/html.dart';
25 import 'package:analyzer/task/model.dart'; 26 import 'package:analyzer/task/model.dart';
26 import 'package:test/test.dart'; 27 import 'package:test/test.dart';
27 import 'package:test_reflective_loader/test_reflective_loader.dart'; 28 import 'package:test_reflective_loader/test_reflective_loader.dart';
28 import 'package:typed_mock/typed_mock.dart'; 29 import 'package:typed_mock/typed_mock.dart';
29 30
30 import '../../generated/test_support.dart'; 31 import '../../generated/test_support.dart';
31 32
32 main() { 33 main() {
33 defineReflectiveSuite(() { 34 defineReflectiveSuite(() {
34 defineReflectiveTests(HtmlWorkManagerTest); 35 defineReflectiveTests(HtmlWorkManagerTest);
36 defineReflectiveTests(HtmlWorkManagerIntegrationTest);
35 }); 37 });
36 } 38 }
37 39
38 @reflectiveTest 40 @reflectiveTest
39 class HtmlWorkManagerTest { 41 class HtmlWorkManagerTest {
40 InternalAnalysisContext context = new _InternalAnalysisContextMock(); 42 InternalAnalysisContext context = new _InternalAnalysisContextMock();
41 AnalysisCache cache; 43 AnalysisCache cache;
42 HtmlWorkManager manager; 44 HtmlWorkManager manager;
43 45
44 CaughtException caughtException = new CaughtException(null, null); 46 CaughtException caughtException = new CaughtException(null, null);
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 entry1.setValue(HTML_ERRORS, <AnalysisError>[error1, error2], []); 298 entry1.setValue(HTML_ERRORS, <AnalysisError>[error1, error2], []);
297 // RESOLVED_UNIT is ready, set errors 299 // RESOLVED_UNIT is ready, set errors
298 manager.resultsComputed(source1, {HTML_ERRORS: null}); 300 manager.resultsComputed(source1, {HTML_ERRORS: null});
299 // all of the errors are included 301 // all of the errors are included
300 ChangeNoticeImpl notice = context.getNotice(source1); 302 ChangeNoticeImpl notice = context.getNotice(source1);
301 expect(notice.errors, unorderedEquals([error1, error2])); 303 expect(notice.errors, unorderedEquals([error1, error2]));
302 expect(notice.lineInfo, lineInfo); 304 expect(notice.lineInfo, lineInfo);
303 } 305 }
304 } 306 }
305 307
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 test_onResultInvalidated_scheduleInvalidatedLibrariesAfterSetSourceFactor y() {
329 // Change the source factory, changing the analysis cache from when
330 // the work manager was constructed. This used to create a failure
331 // case for test_onResultInvalidated_scheduleInvalidLibraries so its
332 // tested here.
333 context.sourceFactory = new _SourceFactoryMock();
334
335 // now just do the same checks as
336 // test_onResultInvalidated_scheduleInvalidLibraries
337
338 // set HTML_ERRORS for source1 and source2
339 entry1.setValue(HTML_ERRORS, [], []);
340 entry2.setValue(HTML_ERRORS, [], []);
341 // invalidate HTML_ERRORS for source1, schedule it
342 entry1.setState(HTML_ERRORS, CacheState.INVALID);
343 expect_sourceQueue([source1]);
344 // invalidate HTML_ERRORS for source2, schedule it
345 entry2.setState(HTML_ERRORS, CacheState.INVALID);
346 expect_sourceQueue([source1, source2]);
347 }
348
349 }
350
351 class _SourceFactoryMock extends TypedMock
352 implements SourceFactory {
353 }
354
306 class _InternalAnalysisContextMock extends TypedMock 355 class _InternalAnalysisContextMock extends TypedMock
307 implements InternalAnalysisContext { 356 implements InternalAnalysisContext {
308 @override 357 @override
309 CachePartition privateAnalysisCachePartition; 358 CachePartition privateAnalysisCachePartition;
310 359
311 @override 360 @override
312 AnalysisCache analysisCache; 361 AnalysisCache analysisCache;
313 362
363 // The production version is a stream that carries messages from the cache
364 // since the cache changes. Here, we can just pass the inner stream because
365 // it doesn't change.
366 @override
367 get onResultInvalidated => analysisCache.onResultInvalidated;
368
314 Map<Source, ChangeNoticeImpl> _pendingNotices = <Source, ChangeNoticeImpl>{}; 369 Map<Source, ChangeNoticeImpl> _pendingNotices = <Source, ChangeNoticeImpl>{};
315 370
316 _InternalAnalysisContextMock() { 371 _InternalAnalysisContextMock() {
317 privateAnalysisCachePartition = new UniversalCachePartition(this); 372 privateAnalysisCachePartition = new UniversalCachePartition(this);
318 analysisCache = new AnalysisCache([privateAnalysisCachePartition]); 373 analysisCache = new AnalysisCache([privateAnalysisCachePartition]);
319 } 374 }
320 375
321 @override 376 @override
322 CacheEntry getCacheEntry(AnalysisTarget target) { 377 CacheEntry getCacheEntry(AnalysisTarget target) {
323 CacheEntry entry = analysisCache.get(target); 378 CacheEntry entry = analysisCache.get(target);
(...skipping 16 matching lines...) Expand all
340 return new AnalysisErrorInfoImpl( 395 return new AnalysisErrorInfoImpl(
341 errors, getCacheEntry(source).getValue(LINE_INFO)); 396 errors, getCacheEntry(source).getValue(LINE_INFO));
342 } 397 }
343 398
344 @override 399 @override
345 ChangeNoticeImpl getNotice(Source source) { 400 ChangeNoticeImpl getNotice(Source source) {
346 return _pendingNotices.putIfAbsent( 401 return _pendingNotices.putIfAbsent(
347 source, () => new ChangeNoticeImpl(source)); 402 source, () => new ChangeNoticeImpl(source));
348 } 403 }
349 } 404 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/task/html_work_manager.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698