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

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

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