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

Side by Side Diff: pkg/analyzer_plugin/test/plugin/plugin_test.dart

Issue 3003573002: Add minimal support for sending notifications (Closed)
Patch Set: Created 3 years, 3 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
OLDNEW
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2017, 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 import 'dart:async';
6
7 import 'package:analyzer/dart/analysis/results.dart';
5 import 'package:analyzer/file_system/file_system.dart'; 8 import 'package:analyzer/file_system/file_system.dart';
6 import 'package:analyzer/file_system/memory_file_system.dart'; 9 import 'package:analyzer/file_system/memory_file_system.dart';
7 import 'package:analyzer/src/dart/analysis/driver.dart'; 10 import 'package:analyzer/src/dart/analysis/driver.dart';
8 import 'package:analyzer_plugin/protocol/protocol.dart'; 11 import 'package:analyzer_plugin/protocol/protocol.dart';
9 import 'package:analyzer_plugin/protocol/protocol_common.dart'; 12 import 'package:analyzer_plugin/protocol/protocol_common.dart';
10 import 'package:analyzer_plugin/protocol/protocol_generated.dart'; 13 import 'package:analyzer_plugin/protocol/protocol_generated.dart';
11 import 'package:path/src/context.dart'; 14 import 'package:path/src/context.dart';
12 import 'package:test/test.dart'; 15 import 'package:test/test.dart';
13 import 'package:test_reflective_loader/test_reflective_loader.dart'; 16 import 'package:test_reflective_loader/test_reflective_loader.dart';
14 17
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 new PluginVersionCheckParams('byteStorePath', 'sdkPath', '0.1.0'))); 358 new PluginVersionCheckParams('byteStorePath', 'sdkPath', '0.1.0')));
356 PluginVersionCheckResult result = 359 PluginVersionCheckResult result =
357 new PluginVersionCheckResult.fromResponse(response); 360 new PluginVersionCheckResult.fromResponse(response);
358 expect(result, isNotNull); 361 expect(result, isNotNull);
359 expect(result.interestingFiles, ['*.dart']); 362 expect(result.interestingFiles, ['*.dart']);
360 expect(result.isCompatible, isTrue); 363 expect(result.isCompatible, isTrue);
361 expect(result.name, 'Test Plugin'); 364 expect(result.name, 'Test Plugin');
362 expect(result.version, '0.1.0'); 365 expect(result.version, '0.1.0');
363 } 366 }
364 367
368 test_sendNotificationsForFile() {
369 AnalysisService service1 = AnalysisService.FOLDING;
370 AnalysisService service2 = AnalysisService.NAVIGATION;
371 AnalysisService service3 = AnalysisService.OUTLINE;
372 plugin.subscriptionManager.setSubscriptions({
373 service1: [filePath1, filePath2],
374 service2: [filePath1],
375 service3: [filePath2]
376 });
377 plugin.sendNotificationsForFile(filePath1);
378 Map<String, List<AnalysisService>> notifications = plugin.sentNotifications;
379 expect(notifications, hasLength(1));
380 List<AnalysisService> services = notifications[filePath1];
381 expect(services, unorderedEquals([service1, service2]));
382 }
383
384 test_sendNotificationsForSubscriptions() {
385 Map<String, List<AnalysisService>> subscriptions =
386 <String, List<AnalysisService>>{};
387
388 plugin.sendNotificationsForSubscriptions(subscriptions);
389 Map<String, List<AnalysisService>> notifications = plugin.sentNotifications;
390 expect(notifications, hasLength(subscriptions.length));
391 for (String path in subscriptions.keys) {
392 List<AnalysisService> subscribedServices = subscriptions[path];
393 List<AnalysisService> notifiedServices = notifications[path];
394 expect(notifiedServices, isNotNull,
395 reason: 'Not notified for file $path');
396 expect(notifiedServices, unorderedEquals(subscribedServices),
397 reason: 'Wrong notifications for file $path');
398 }
399 }
400
365 AnalysisDriverGeneric _getDriver(ContextRoot targetRoot) { 401 AnalysisDriverGeneric _getDriver(ContextRoot targetRoot) {
366 for (ContextRoot root in plugin.driverMap.keys) { 402 for (ContextRoot root in plugin.driverMap.keys) {
367 if (root.root == targetRoot.root) { 403 if (root.root == targetRoot.root) {
368 return plugin.driverMap[root]; 404 return plugin.driverMap[root];
369 } 405 }
370 } 406 }
371 return null; 407 return null;
372 } 408 }
373 } 409 }
374 410
375 class _TestServerPlugin extends MockServerPlugin { 411 class _TestServerPlugin extends MockServerPlugin {
376 Map<String, List<AnalysisService>> latestSubscriptions; 412 Map<String, List<AnalysisService>> sentNotifications =
413 <String, List<AnalysisService>>{};
377 414
378 _TestServerPlugin(ResourceProvider resourceProvider) 415 _TestServerPlugin(ResourceProvider resourceProvider)
379 : super(resourceProvider); 416 : super(resourceProvider);
380 417
381 @override 418 @override
382 void sendNotificationsForSubscriptions( 419 Future<Null> sendFoldingNotification(String path, {ResolveResult result}) {
383 Map<String, List<AnalysisService>> subscriptions) { 420 _sent(path, AnalysisService.FOLDING);
384 latestSubscriptions = subscriptions; 421 return new Future.value();
422 }
423
424 @override
425 Future<Null> sendHighlightsNotification(String path, {ResolveResult result}) {
426 _sent(path, AnalysisService.HIGHLIGHTS);
427 return new Future.value();
428 }
429
430 @override
431 Future<Null> sendNavigationNotification(String path, {ResolveResult result}) {
432 _sent(path, AnalysisService.NAVIGATION);
433 return new Future.value();
434 }
435
436 @override
437 Future<Null> sendOccurrencesNotification(String path,
438 {ResolveResult result}) {
439 _sent(path, AnalysisService.OCCURRENCES);
440 return new Future.value();
441 }
442
443 @override
444 Future<Null> sendOutlineNotification(String path, {ResolveResult result}) {
445 _sent(path, AnalysisService.OUTLINE);
446 return new Future.value();
447 }
448
449 void _sent(String path, AnalysisService service) {
450 sentNotifications.putIfAbsent(path, () => <AnalysisService>[]).add(service);
385 } 451 }
386 } 452 }
OLDNEW
« pkg/analyzer_plugin/lib/plugin/plugin.dart ('K') | « pkg/analyzer_plugin/test/plugin/mocks.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698