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

Side by Side Diff: pkg/analysis_server/test/edit/refactoring_test.dart

Issue 884453002: Issue 22157. Cancel a pending refactoring request on receiving a new one. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 10 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 test.edit.refactoring; 5 library test.edit.refactoring;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analysis_server/src/edit/edit_domain.dart'; 9 import 'package:analysis_server/src/edit/edit_domain.dart';
10 import 'package:analysis_server/src/protocol.dart'; 10 import 'package:analysis_server/src/protocol.dart';
11 import 'package:analysis_server/src/services/index/index.dart'; 11 import 'package:analysis_server/src/services/index/index.dart';
12 import 'package:analysis_server/src/services/index/local_memory_index.dart'; 12 import 'package:analysis_server/src/services/index/local_memory_index.dart';
13 import 'package:unittest/unittest.dart' hide ERROR; 13 import 'package:unittest/unittest.dart' hide ERROR;
14 14
15 import '../analysis_abstract.dart'; 15 import '../analysis_abstract.dart';
16 import '../mocks.dart';
16 import '../reflective_tests.dart'; 17 import '../reflective_tests.dart';
17 18
18 19
19 main() { 20 main() {
20 groupSep = ' | '; 21 groupSep = ' | ';
21 runReflectiveTests(ConvertGetterMethodToMethodTest); 22 runReflectiveTests(ConvertGetterMethodToMethodTest);
22 runReflectiveTests(ConvertMethodToGetterTest); 23 runReflectiveTests(ConvertMethodToGetterTest);
23 runReflectiveTests(ExtractLocalVariableTest); 24 runReflectiveTests(ExtractLocalVariableTest);
24 runReflectiveTests(ExtractMethodTest); 25 runReflectiveTests(ExtractMethodTest);
25 runReflectiveTests(GetAvailableRefactoringsTest); 26 runReflectiveTests(GetAvailableRefactoringsTest);
(...skipping 996 matching lines...) Expand 10 before | Expand all | Expand 10 after
1022 false, 1023 false,
1023 options: options).toRequest('0'); 1024 options: options).toRequest('0');
1024 return serverChannel.sendRequest(request); 1025 return serverChannel.sendRequest(request);
1025 } 1026 }
1026 } 1027 }
1027 1028
1028 1029
1029 @reflectiveTest 1030 @reflectiveTest
1030 class RenameTest extends _AbstractGetRefactoring_Test { 1031 class RenameTest extends _AbstractGetRefactoring_Test {
1031 Future<Response> sendRenameRequest(String search, String newName, 1032 Future<Response> sendRenameRequest(String search, String newName,
1032 [bool validateOnly = false]) { 1033 {String id: '0', bool validateOnly: false}) {
1033 RenameOptions options = newName != null ? new RenameOptions(newName) : null; 1034 RenameOptions options = newName != null ? new RenameOptions(newName) : null;
1034 Request request = new EditGetRefactoringParams( 1035 Request request = new EditGetRefactoringParams(
1035 RefactoringKind.RENAME, 1036 RefactoringKind.RENAME,
1036 testFile, 1037 testFile,
1037 findOffset(search), 1038 findOffset(search),
1038 0, 1039 0,
1039 validateOnly, 1040 validateOnly,
1040 options: options).toRequest('0'); 1041 options: options).toRequest(id);
1041 return serverChannel.sendRequest(request); 1042 return serverChannel.sendRequest(request);
1042 } 1043 }
1043 1044
1045 test_cancelPendingRequest() async {
1046 addTestFile('''
1047 main() {
1048 int test = 0;
1049 print(test);
1050 }
1051 ''');
1052 // send the "1" request, but don't wait for it
1053 Future<Response> futureA = sendRenameRequest('test =', 'nameA', id: '1');
1054 // send the "2" request and wait for it
1055 Response responseB = await sendRenameRequest('test =', 'nameB', id: '2');
1056 // wait for the (delayed) "1" response
1057 Response responseA = await futureA;
1058 // "1" was cancelled
1059 // "2" is successful
1060 expect(responseA, isResponseFailure('1', RequestErrorCode.REFACTORING_REQUES T_CANCELLED));
1061 expect(responseB, isResponseSuccess('2'));
1062 }
1063
1044 test_class() { 1064 test_class() {
1045 addTestFile(''' 1065 addTestFile('''
1046 class Test { 1066 class Test {
1047 Test() {} 1067 Test() {}
1048 Test.named() {} 1068 Test.named() {}
1049 } 1069 }
1050 main() { 1070 main() {
1051 Test v; 1071 Test v;
1052 new Test(); 1072 new Test();
1053 new Test.named(); 1073 new Test.named();
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1087 } 1107 }
1088 1108
1089 test_class_validateOnly() { 1109 test_class_validateOnly() {
1090 addTestFile(''' 1110 addTestFile('''
1091 class Test {} 1111 class Test {}
1092 main() { 1112 main() {
1093 Test v; 1113 Test v;
1094 } 1114 }
1095 '''); 1115 ''');
1096 return getRefactoringResult(() { 1116 return getRefactoringResult(() {
1097 return sendRenameRequest('Test {}', 'NewName', true); 1117 return sendRenameRequest('Test {}', 'NewName', validateOnly: true);
1098 }).then((result) { 1118 }).then((result) {
1099 RenameFeedback feedback = result.feedback; 1119 RenameFeedback feedback = result.feedback;
1100 assertResultProblemsOK(result); 1120 assertResultProblemsOK(result);
1101 expect(feedback.elementKindName, 'class'); 1121 expect(feedback.elementKindName, 'class');
1102 expect(feedback.oldName, 'Test'); 1122 expect(feedback.oldName, 'Test');
1103 expect(result.change, isNull); 1123 expect(result.change, isNull);
1104 }); 1124 });
1105 } 1125 }
1106 1126
1107 test_class_warning() { 1127 test_class_warning() {
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after
1516 1536
1517 test_localVariable_finalCheck_shadowError() { 1537 test_localVariable_finalCheck_shadowError() {
1518 addTestFile(''' 1538 addTestFile('''
1519 main() { 1539 main() {
1520 var newName; 1540 var newName;
1521 int test = 0; 1541 int test = 0;
1522 print(test); 1542 print(test);
1523 } 1543 }
1524 '''); 1544 ''');
1525 return getRefactoringResult(() { 1545 return getRefactoringResult(() {
1526 return sendRenameRequest('test = 0', 'newName', false); 1546 return sendRenameRequest('test = 0', 'newName');
1527 }).then((result) { 1547 }).then((result) {
1528 List<RefactoringProblem> problems = result.finalProblems; 1548 List<RefactoringProblem> problems = result.finalProblems;
1529 expect(problems, hasLength(1)); 1549 expect(problems, hasLength(1));
1530 assertResultProblemsError( 1550 assertResultProblemsError(
1531 problems, 1551 problems,
1532 "Duplicate local variable 'newName'."); 1552 "Duplicate local variable 'newName'.");
1533 }); 1553 });
1534 } 1554 }
1535 1555
1536 test_resetOnAnalysis() { 1556 test_resetOnAnalysis() {
1537 addTestFile(''' 1557 addTestFile('''
1538 main() { 1558 main() {
1539 int initialName = 0; 1559 int initialName = 0;
1540 print(initialName); 1560 print(initialName);
1541 } 1561 }
1542 '''); 1562 ''');
1543 // send the first request 1563 // send the first request
1544 return getRefactoringResult(() { 1564 return getRefactoringResult(() {
1545 return sendRenameRequest('initialName =', 'newName', true); 1565 return sendRenameRequest('initialName =', 'newName', validateOnly: true);
1546 }).then((result) { 1566 }).then((result) {
1547 RenameFeedback feedback = result.feedback; 1567 RenameFeedback feedback = result.feedback;
1548 expect(feedback.oldName, 'initialName'); 1568 expect(feedback.oldName, 'initialName');
1549 // update the file 1569 // update the file
1550 modifyTestFile(''' 1570 modifyTestFile('''
1551 main() { 1571 main() {
1552 int otherName = 0; 1572 int otherName = 0;
1553 print(otherName); 1573 print(otherName);
1554 } 1574 }
1555 '''); 1575 ''');
1556 // send the second request, with the same kind, file and offset 1576 // send the second request, with the same kind, file and offset
1557 return waitForTasksFinished().then((_) { 1577 return waitForTasksFinished().then((_) {
1558 return getRefactoringResult(() { 1578 return getRefactoringResult(() {
1559 return sendRenameRequest('otherName =', 'newName', true); 1579 return sendRenameRequest('otherName =', 'newName', validateOnly: true) ;
1560 }).then((result) { 1580 }).then((result) {
1561 RenameFeedback feedback = result.feedback; 1581 RenameFeedback feedback = result.feedback;
1562 // the refactoring was reset, so we don't get a stale result 1582 // the refactoring was reset, so we don't get a stale result
1563 expect(feedback.oldName, 'otherName'); 1583 expect(feedback.oldName, 'otherName');
1564 }); 1584 });
1565 }); 1585 });
1566 }); 1586 });
1567 } 1587 }
1568 1588
1569 SourceEdit _findEditWithId(SourceChange change, String id) { 1589 SourceEdit _findEditWithId(SourceChange change, String id) {
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
1691 } 1711 }
1692 1712
1693 @override 1713 @override
1694 void setUp() { 1714 void setUp() {
1695 super.setUp(); 1715 super.setUp();
1696 server.handlers = [new EditDomainHandler(server),]; 1716 server.handlers = [new EditDomainHandler(server),];
1697 createProject(); 1717 createProject();
1698 handler = new EditDomainHandler(server); 1718 handler = new EditDomainHandler(server);
1699 } 1719 }
1700 } 1720 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698