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'; |
11 import 'package:analyzer/src/error/codes.dart' show HtmlErrorCode; | 11 import 'package:analyzer/src/error/codes.dart' show HtmlErrorCode; |
12 import 'package:analyzer/src/generated/engine.dart' | 12 import 'package:analyzer/src/generated/engine.dart' |
13 show | 13 show |
14 AnalysisEngine, | 14 AnalysisEngine, |
15 AnalysisErrorInfo, | 15 AnalysisErrorInfo, |
16 AnalysisErrorInfoImpl, | 16 AnalysisErrorInfoImpl, |
17 CacheState, | 17 CacheState, |
18 ChangeNoticeImpl, | 18 ChangeNoticeImpl, |
19 InternalAnalysisContext; | 19 InternalAnalysisContext; |
20 import 'package:analyzer/src/generated/source.dart'; | 20 import 'package:analyzer/src/generated/source.dart'; |
21 import 'package:analyzer/src/task/html.dart'; | 21 import 'package:analyzer/src/task/html.dart'; |
22 import 'package:analyzer/src/task/html_work_manager.dart'; | 22 import 'package:analyzer/src/task/html_work_manager.dart'; |
23 import 'package:analyzer/task/dart.dart'; | 23 import 'package:analyzer/task/dart.dart'; |
24 import 'package:analyzer/task/general.dart'; | 24 import 'package:analyzer/task/general.dart'; |
25 import 'package:analyzer/task/html.dart'; | 25 import 'package:analyzer/task/html.dart'; |
26 import 'package:analyzer/task/model.dart'; | 26 import 'package:analyzer/task/model.dart'; |
| 27 import 'package:mockito/mockito.dart'; |
27 import 'package:test/test.dart'; | 28 import 'package:test/test.dart'; |
28 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 29 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
29 import 'package:typed_mock/typed_mock.dart'; | |
30 | 30 |
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 |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 void test_getNextResultPriority_hasSource() { | 277 void test_getNextResultPriority_hasSource() { |
278 manager.sourceQueue.addAll([source1]); | 278 manager.sourceQueue.addAll([source1]); |
279 expect(manager.getNextResultPriority(), WorkOrderPriority.NORMAL); | 279 expect(manager.getNextResultPriority(), WorkOrderPriority.NORMAL); |
280 } | 280 } |
281 | 281 |
282 void test_getNextResultPriority_nothingToDo() { | 282 void test_getNextResultPriority_nothingToDo() { |
283 expect(manager.getNextResultPriority(), WorkOrderPriority.NONE); | 283 expect(manager.getNextResultPriority(), WorkOrderPriority.NONE); |
284 } | 284 } |
285 | 285 |
286 void test_onAnalysisOptionsChanged() { | 286 void test_onAnalysisOptionsChanged() { |
287 when(context.exists(anyObject)).thenReturn(true); | 287 when(context.exists(any)).thenReturn(true); |
288 // set cache values | 288 // set cache values |
289 entry1.setValue(DART_SCRIPTS, [], []); | 289 entry1.setValue(DART_SCRIPTS, [], []); |
290 entry1.setValue(HTML_DOCUMENT, null, []); | 290 entry1.setValue(HTML_DOCUMENT, null, []); |
291 entry1.setValue(HTML_DOCUMENT_ERRORS, [], []); | 291 entry1.setValue(HTML_DOCUMENT_ERRORS, [], []); |
292 entry1.setValue(HTML_ERRORS, [], []); | 292 entry1.setValue(HTML_ERRORS, [], []); |
293 entry1.setValue(REFERENCED_LIBRARIES, [], []); | 293 entry1.setValue(REFERENCED_LIBRARIES, [], []); |
294 // notify | 294 // notify |
295 manager.onAnalysisOptionsChanged(); | 295 manager.onAnalysisOptionsChanged(); |
296 // Only resolution-based values are invalidated. | 296 // Only resolution-based values are invalidated. |
297 expect(entry1.getState(DART_SCRIPTS), CacheState.VALID); | 297 expect(entry1.getState(DART_SCRIPTS), CacheState.VALID); |
298 expect(entry1.getState(HTML_DOCUMENT), CacheState.VALID); | 298 expect(entry1.getState(HTML_DOCUMENT), CacheState.VALID); |
299 expect(entry1.getState(HTML_DOCUMENT_ERRORS), CacheState.VALID); | 299 expect(entry1.getState(HTML_DOCUMENT_ERRORS), CacheState.VALID); |
300 expect(entry1.getState(HTML_ERRORS), CacheState.INVALID); | 300 expect(entry1.getState(HTML_ERRORS), CacheState.INVALID); |
301 expect(entry1.getState(REFERENCED_LIBRARIES), CacheState.VALID); | 301 expect(entry1.getState(REFERENCED_LIBRARIES), CacheState.VALID); |
302 } | 302 } |
303 | 303 |
304 void test_onResultInvalidated_scheduleInvalidatedLibraries() { | 304 void test_onResultInvalidated_scheduleInvalidatedLibraries() { |
305 // set HTML_ERRORS for source1 and source3 | 305 // set HTML_ERRORS for source1 and source3 |
306 entry1.setValue(HTML_ERRORS, [], []); | 306 entry1.setValue(HTML_ERRORS, [], []); |
307 entry3.setValue(HTML_ERRORS, [], []); | 307 entry3.setValue(HTML_ERRORS, [], []); |
308 // invalidate HTML_ERRORS for source1, schedule it | 308 // invalidate HTML_ERRORS for source1, schedule it |
309 entry1.setState(HTML_ERRORS, CacheState.INVALID); | 309 entry1.setState(HTML_ERRORS, CacheState.INVALID); |
310 expect_sourceQueue([source1]); | 310 expect_sourceQueue([source1]); |
311 // invalidate HTML_ERRORS for source3, schedule it | 311 // invalidate HTML_ERRORS for source3, schedule it |
312 entry3.setState(HTML_ERRORS, CacheState.INVALID); | 312 entry3.setState(HTML_ERRORS, CacheState.INVALID); |
313 expect_sourceQueue([source1, source3]); | 313 expect_sourceQueue([source1, source3]); |
314 } | 314 } |
315 | 315 |
316 void test_onSourceFactoryChanged() { | 316 void test_onSourceFactoryChanged() { |
317 when(context.exists(anyObject)).thenReturn(true); | 317 when(context.exists(any)).thenReturn(true); |
318 // set cache values | 318 // set cache values |
319 entry1.setValue(DART_SCRIPTS, [], []); | 319 entry1.setValue(DART_SCRIPTS, [], []); |
320 entry1.setValue(HTML_DOCUMENT, null, []); | 320 entry1.setValue(HTML_DOCUMENT, null, []); |
321 entry1.setValue(HTML_DOCUMENT_ERRORS, [], []); | 321 entry1.setValue(HTML_DOCUMENT_ERRORS, [], []); |
322 entry1.setValue(HTML_ERRORS, [], []); | 322 entry1.setValue(HTML_ERRORS, [], []); |
323 entry1.setValue(REFERENCED_LIBRARIES, [], []); | 323 entry1.setValue(REFERENCED_LIBRARIES, [], []); |
324 // notify | 324 // notify |
325 manager.onSourceFactoryChanged(); | 325 manager.onSourceFactoryChanged(); |
326 // Only resolution-based values are invalidated. | 326 // Only resolution-based values are invalidated. |
327 expect(entry1.getState(DART_SCRIPTS), CacheState.VALID); | 327 expect(entry1.getState(DART_SCRIPTS), CacheState.VALID); |
(...skipping 13 matching lines...) Expand all Loading... |
341 entry1.setValue(HTML_ERRORS, <AnalysisError>[error1, error2], []); | 341 entry1.setValue(HTML_ERRORS, <AnalysisError>[error1, error2], []); |
342 // RESOLVED_UNIT is ready, set errors | 342 // RESOLVED_UNIT is ready, set errors |
343 manager.resultsComputed(source1, {HTML_ERRORS: null}); | 343 manager.resultsComputed(source1, {HTML_ERRORS: null}); |
344 // all of the errors are included | 344 // all of the errors are included |
345 ChangeNoticeImpl notice = context.getNotice(source1); | 345 ChangeNoticeImpl notice = context.getNotice(source1); |
346 expect(notice.errors, unorderedEquals([error1, error2])); | 346 expect(notice.errors, unorderedEquals([error1, error2])); |
347 expect(notice.lineInfo, lineInfo); | 347 expect(notice.lineInfo, lineInfo); |
348 } | 348 } |
349 } | 349 } |
350 | 350 |
351 class _InternalAnalysisContextMock extends TypedMock | 351 class _InternalAnalysisContextMock extends Mock |
352 implements InternalAnalysisContext { | 352 implements InternalAnalysisContext { |
353 @override | 353 @override |
354 CachePartition privateAnalysisCachePartition; | 354 CachePartition privateAnalysisCachePartition; |
355 | 355 |
356 @override | 356 @override |
357 AnalysisCache analysisCache; | 357 AnalysisCache analysisCache; |
358 | 358 |
359 // 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 |
360 // 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 |
361 // it doesn't change. | 361 // it doesn't change. |
(...skipping 30 matching lines...) Expand all Loading... |
392 errors, getCacheEntry(source).getValue(LINE_INFO)); | 392 errors, getCacheEntry(source).getValue(LINE_INFO)); |
393 } | 393 } |
394 | 394 |
395 @override | 395 @override |
396 ChangeNoticeImpl getNotice(Source source) { | 396 ChangeNoticeImpl getNotice(Source source) { |
397 return _pendingNotices.putIfAbsent( | 397 return _pendingNotices.putIfAbsent( |
398 source, () => new ChangeNoticeImpl(source)); | 398 source, () => new ChangeNoticeImpl(source)); |
399 } | 399 } |
400 } | 400 } |
401 | 401 |
402 class _SourceFactoryMock extends TypedMock implements SourceFactory {} | 402 class _SourceFactoryMock extends Mock implements SourceFactory {} |
OLD | NEW |