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

Side by Side Diff: ui/views/cocoa/bridged_native_widget_unittest.mm

Issue 2119813002: views::Textfield: Implement yank editing command. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import "ui/views/cocoa/bridged_native_widget.h" 5 #import "ui/views/cocoa/bridged_native_widget.h"
6 6
7 #import <Cocoa/Cocoa.h> 7 #import <Cocoa/Cocoa.h>
8 8
9 #include <memory> 9 #include <memory>
10 10
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 @"moveToRightEndOfLineAndModifySelection:" 106 @"moveToRightEndOfLineAndModifySelection:"
107 ]; 107 ];
108 108
109 NSArray* const kDeleteActions = @[ 109 NSArray* const kDeleteActions = @[
110 @"deleteForward:", @"deleteBackward:", @"deleteWordForward:", 110 @"deleteForward:", @"deleteBackward:", @"deleteWordForward:",
111 @"deleteWordBackward:", @"deleteToBeginningOfLine:", @"deleteToEndOfLine:", 111 @"deleteWordBackward:", @"deleteToBeginningOfLine:", @"deleteToEndOfLine:",
112 @"deleteToBeginningOfParagraph:", @"deleteToEndOfParagraph:" 112 @"deleteToBeginningOfParagraph:", @"deleteToEndOfParagraph:"
113 ]; 113 ];
114 114
115 NSArray* const kMiscActions = 115 NSArray* const kMiscActions =
116 @[ @"insertText:", @"cancelOperation:", @"transpose:" ]; 116 @[ @"insertText:", @"cancelOperation:", @"transpose:", @"yank:" ];
117 117
118 // Empty range shortcut for readibility. 118 // Empty range shortcut for readibility.
119 NSRange EmptyRange() { 119 NSRange EmptyRange() {
120 return NSMakeRange(NSNotFound, 0); 120 return NSMakeRange(NSNotFound, 0);
121 } 121 }
122 122
123 // Sets |composition_text| as the composition text with caret placed at 123 // Sets |composition_text| as the composition text with caret placed at
124 // |caret_pos| and updates |caret_range|. 124 // |caret_pos| and updates |caret_range|.
125 void SetCompositionText(ui::TextInputClient* client, 125 void SetCompositionText(ui::TextInputClient* client,
126 const base::string16& composition_text, 126 const base::string16& composition_text,
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 EXPECT_EQ_RANGE_3(NSMakeRange(0, 0), GetExpectedSelectionRange(), 476 EXPECT_EQ_RANGE_3(NSMakeRange(0, 0), GetExpectedSelectionRange(),
477 GetActualSelectionRange()); 477 GetActualSelectionRange());
478 478
479 // Make a selection as- " bar |baz|". 479 // Make a selection as- " bar |baz|".
480 SetSelectionRange(NSMakeRange(5, 3)); 480 SetSelectionRange(NSMakeRange(5, 3));
481 PerformCommand(sel); 481 PerformCommand(sel);
482 // Verify only the selection is deleted so that the state is " bar |". 482 // Verify only the selection is deleted so that the state is " bar |".
483 EXPECT_NSEQ_3(@" bar ", GetExpectedText(), GetActualText()); 483 EXPECT_NSEQ_3(@" bar ", GetExpectedText(), GetActualText());
484 EXPECT_EQ_RANGE_3(NSMakeRange(5, 0), GetExpectedSelectionRange(), 484 EXPECT_EQ_RANGE_3(NSMakeRange(5, 0), GetExpectedSelectionRange(),
485 GetActualSelectionRange()); 485 GetActualSelectionRange());
486
487 // Verify yanking inserts the deleted text.
488 PerformCommand(@selector(yank:));
489 EXPECT_NSEQ_3(@" bar baz", GetExpectedText(), GetActualText());
490 EXPECT_EQ_RANGE_3(NSMakeRange(8, 0), GetExpectedSelectionRange(),
491 GetActualSelectionRange());
486 } 492 }
487 493
488 void BridgedNativeWidgetTest::TestDeleteEnd(SEL sel) { 494 void BridgedNativeWidgetTest::TestDeleteEnd(SEL sel) {
489 InstallTextField("foo bar baz"); 495 InstallTextField("foo bar baz");
490 EXPECT_EQ_RANGE_3(NSMakeRange(11, 0), GetExpectedSelectionRange(), 496 EXPECT_EQ_RANGE_3(NSMakeRange(11, 0), GetExpectedSelectionRange(),
491 GetActualSelectionRange()); 497 GetActualSelectionRange());
492 498
493 // Caret is at the end of the line. Verify no deletion takes place. 499 // Caret is at the end of the line. Verify no deletion takes place.
494 PerformCommand(sel); 500 PerformCommand(sel);
495 EXPECT_NSEQ_3(@"foo bar baz", GetExpectedText(), GetActualText()); 501 EXPECT_NSEQ_3(@"foo bar baz", GetExpectedText(), GetActualText());
496 EXPECT_EQ_RANGE_3(NSMakeRange(11, 0), GetExpectedSelectionRange(), 502 EXPECT_EQ_RANGE_3(NSMakeRange(11, 0), GetExpectedSelectionRange(),
497 GetActualSelectionRange()); 503 GetActualSelectionRange());
498 504
499 // Move the caret as- "foo bar| baz". 505 // Move the caret as- "foo bar| baz".
500 SetSelectionRange(NSMakeRange(7, 0)); 506 SetSelectionRange(NSMakeRange(7, 0));
501 PerformCommand(sel); 507 PerformCommand(sel);
502 // Verify state is "foo bar|". 508 // Verify state is "foo bar|".
503 EXPECT_NSEQ_3(@"foo bar", GetExpectedText(), GetActualText()); 509 EXPECT_NSEQ_3(@"foo bar", GetExpectedText(), GetActualText());
504 EXPECT_EQ_RANGE_3(NSMakeRange(7, 0), GetExpectedSelectionRange(), 510 EXPECT_EQ_RANGE_3(NSMakeRange(7, 0), GetExpectedSelectionRange(),
505 GetActualSelectionRange()); 511 GetActualSelectionRange());
506 512
507 // Make a selection as- "|foo |bar". 513 // Make a selection as- "|foo |bar".
508 SetSelectionRange(NSMakeRange(0, 4)); 514 SetSelectionRange(NSMakeRange(0, 4));
509 PerformCommand(sel); 515 PerformCommand(sel);
510 // Verify only the selection is deleted so that the state is "|bar". 516 // Verify only the selection is deleted so that the state is "|bar".
511 EXPECT_NSEQ_3(@"bar", GetExpectedText(), GetActualText()); 517 EXPECT_NSEQ_3(@"bar", GetExpectedText(), GetActualText());
512 EXPECT_EQ_RANGE_3(NSMakeRange(0, 0), GetExpectedSelectionRange(), 518 EXPECT_EQ_RANGE_3(NSMakeRange(0, 0), GetExpectedSelectionRange(),
513 GetActualSelectionRange()); 519 GetActualSelectionRange());
520
521 // Verify yanking inserts the deleted text.
522 PerformCommand(@selector(yank:));
523 EXPECT_NSEQ_3(@"foo bar", GetExpectedText(), GetActualText());
524 EXPECT_EQ_RANGE_3(NSMakeRange(4, 0), GetExpectedSelectionRange(),
525 GetActualSelectionRange());
514 } 526 }
515 527
516 void BridgedNativeWidgetTest::TestEditingCommands(NSArray* selectors) { 528 void BridgedNativeWidgetTest::TestEditingCommands(NSArray* selectors) {
517 const base::string16 test_strings[] = { 529 const base::string16 test_strings[] = {
518 base::WideToUTF16(L"ab c"), 530 base::WideToUTF16(L"ab c"),
519 base::WideToUTF16(L"\x0634\x0632 \x064A") // RTL string. 531 base::WideToUTF16(L"\x0634\x0632 \x064A") // RTL string.
520 }; 532 };
521 533
522 for (const base::string16& test_string : test_strings) { 534 for (const base::string16& test_string : test_strings) {
523 for (NSString* selector_string in selectors) { 535 for (NSString* selector_string in selectors) {
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
890 InstallTextField("a"); 902 InstallTextField("a");
891 EXPECT_EQ_RANGE_3(NSMakeRange(1, 0), GetExpectedSelectionRange(), 903 EXPECT_EQ_RANGE_3(NSMakeRange(1, 0), GetExpectedSelectionRange(),
892 GetActualSelectionRange()); 904 GetActualSelectionRange());
893 905
894 // Delete one character. 906 // Delete one character.
895 PerformCommand(@selector(deleteBackward:)); 907 PerformCommand(@selector(deleteBackward:));
896 EXPECT_NSEQ_3(nil, GetExpectedText(), GetActualText()); 908 EXPECT_NSEQ_3(nil, GetExpectedText(), GetActualText());
897 EXPECT_EQ_RANGE_3(NSMakeRange(0, 0), GetExpectedSelectionRange(), 909 EXPECT_EQ_RANGE_3(NSMakeRange(0, 0), GetExpectedSelectionRange(),
898 GetActualSelectionRange()); 910 GetActualSelectionRange());
899 911
912 // Verify that deletion did not modify the kill buffer.
913 PerformCommand(@selector(yank:));
914 EXPECT_NSEQ_3(nil, GetExpectedText(), GetActualText());
tapted 2016/07/06 01:46:37 I think this will be flaky depending on the order
karandeepb 2016/07/19 07:04:40 Using ViewsDelegate for storing yanked text should
915 EXPECT_EQ_RANGE_3(NSMakeRange(0, 0), GetExpectedSelectionRange(),
916 GetActualSelectionRange());
917
900 // Try to delete again on an empty string. 918 // Try to delete again on an empty string.
901 PerformCommand(@selector(deleteBackward:)); 919 PerformCommand(@selector(deleteBackward:));
902 EXPECT_NSEQ_3(nil, GetExpectedText(), GetActualText()); 920 EXPECT_NSEQ_3(nil, GetExpectedText(), GetActualText());
903 EXPECT_EQ_RANGE_3(NSMakeRange(0, 0), GetExpectedSelectionRange(), 921 EXPECT_EQ_RANGE_3(NSMakeRange(0, 0), GetExpectedSelectionRange(),
904 GetActualSelectionRange()); 922 GetActualSelectionRange());
905 } 923 }
906 924
907 // Test forward delete using text input protocol. 925 // Test forward delete using text input protocol.
908 TEST_F(BridgedNativeWidgetTest, TextInput_DeleteForward) { 926 TEST_F(BridgedNativeWidgetTest, TextInput_DeleteForward) {
909 InstallTextField("a"); 927 InstallTextField("a");
910 EXPECT_EQ_RANGE_3(NSMakeRange(1, 0), GetExpectedSelectionRange(), 928 EXPECT_EQ_RANGE_3(NSMakeRange(1, 0), GetExpectedSelectionRange(),
911 GetActualSelectionRange()); 929 GetActualSelectionRange());
912 930
913 // At the end of the string, can't delete forward. 931 // At the end of the string, can't delete forward.
914 PerformCommand(@selector(deleteForward:)); 932 PerformCommand(@selector(deleteForward:));
915 EXPECT_NSEQ_3(@"a", GetExpectedText(), GetActualText()); 933 EXPECT_NSEQ_3(@"a", GetExpectedText(), GetActualText());
916 EXPECT_EQ_RANGE_3(NSMakeRange(1, 0), GetExpectedSelectionRange(), 934 EXPECT_EQ_RANGE_3(NSMakeRange(1, 0), GetExpectedSelectionRange(),
917 GetActualSelectionRange()); 935 GetActualSelectionRange());
918 936
919 // Should succeed after moving left first. 937 // Should succeed after moving left first.
920 PerformCommand(@selector(moveLeft:)); 938 PerformCommand(@selector(moveLeft:));
921 PerformCommand(@selector(deleteForward:)); 939 PerformCommand(@selector(deleteForward:));
922 EXPECT_NSEQ_3(nil, GetExpectedText(), GetActualText()); 940 EXPECT_NSEQ_3(nil, GetExpectedText(), GetActualText());
923 EXPECT_EQ_RANGE_3(NSMakeRange(0, 0), GetExpectedSelectionRange(), 941 EXPECT_EQ_RANGE_3(NSMakeRange(0, 0), GetExpectedSelectionRange(),
924 GetActualSelectionRange()); 942 GetActualSelectionRange());
943
944 // Verify that deletion did not modify the kill buffer.
945 PerformCommand(@selector(yank:));
946 EXPECT_NSEQ_3(nil, GetExpectedText(), GetActualText());
947 EXPECT_EQ_RANGE_3(NSMakeRange(0, 0), GetExpectedSelectionRange(),
948 GetActualSelectionRange());
925 } 949 }
926 950
927 // Test forward word deletion using text input protocol. 951 // Test forward word deletion using text input protocol.
928 TEST_F(BridgedNativeWidgetTest, TextInput_DeleteWordForward) { 952 TEST_F(BridgedNativeWidgetTest, TextInput_DeleteWordForward) {
929 InstallTextField("foo bar baz"); 953 InstallTextField("foo bar baz");
930 EXPECT_EQ_RANGE_3(NSMakeRange(11, 0), GetExpectedSelectionRange(), 954 EXPECT_EQ_RANGE_3(NSMakeRange(11, 0), GetExpectedSelectionRange(),
931 GetActualSelectionRange()); 955 GetActualSelectionRange());
932 956
933 // Caret is at the end of the line. Verify no deletion takes place. 957 // Caret is at the end of the line. Verify no deletion takes place.
934 PerformCommand(@selector(deleteWordForward:)); 958 PerformCommand(@selector(deleteWordForward:));
935 EXPECT_NSEQ_3(@"foo bar baz", GetExpectedText(), GetActualText()); 959 EXPECT_NSEQ_3(@"foo bar baz", GetExpectedText(), GetActualText());
936 EXPECT_EQ_RANGE_3(NSMakeRange(11, 0), GetExpectedSelectionRange(), 960 EXPECT_EQ_RANGE_3(NSMakeRange(11, 0), GetExpectedSelectionRange(),
937 GetActualSelectionRange()); 961 GetActualSelectionRange());
938 962
939 // Move the caret as- "foo b|ar baz". 963 // Move the caret as- "foo b|ar baz".
940 SetSelectionRange(NSMakeRange(5, 0)); 964 SetSelectionRange(NSMakeRange(5, 0));
941 PerformCommand(@selector(deleteWordForward:)); 965 PerformCommand(@selector(deleteWordForward:));
942 // Verify state is "foo b| baz" 966 // Verify state is "foo b| baz"
943 EXPECT_NSEQ_3(@"foo b baz", GetExpectedText(), GetActualText()); 967 EXPECT_NSEQ_3(@"foo b baz", GetExpectedText(), GetActualText());
944 EXPECT_EQ_RANGE_3(NSMakeRange(5, 0), GetExpectedSelectionRange(), 968 EXPECT_EQ_RANGE_3(NSMakeRange(5, 0), GetExpectedSelectionRange(),
945 GetActualSelectionRange()); 969 GetActualSelectionRange());
946 970
947 // Make a selection as- "|fo|o b baz". 971 // Make a selection as- "|fo|o b baz".
948 SetSelectionRange(NSMakeRange(0, 2)); 972 SetSelectionRange(NSMakeRange(0, 2));
949 PerformCommand(@selector(deleteWordForward:)); 973 PerformCommand(@selector(deleteWordForward:));
950 // Verify only the selection is deleted and state is "|o b baz". 974 // Verify only the selection is deleted and state is "|o b baz".
951 EXPECT_NSEQ_3(@"o b baz", GetExpectedText(), GetActualText()); 975 EXPECT_NSEQ_3(@"o b baz", GetExpectedText(), GetActualText());
952 EXPECT_EQ_RANGE_3(NSMakeRange(0, 0), GetExpectedSelectionRange(), 976 EXPECT_EQ_RANGE_3(NSMakeRange(0, 0), GetExpectedSelectionRange(),
953 GetActualSelectionRange()); 977 GetActualSelectionRange());
978
979 // Verify that deletion did not modify the kill buffer.
980 PerformCommand(@selector(yank:));
981 EXPECT_NSEQ_3(@"o b baz", GetExpectedText(), GetActualText());
982 EXPECT_EQ_RANGE_3(NSMakeRange(0, 0), GetExpectedSelectionRange(),
983 GetActualSelectionRange());
954 } 984 }
955 985
956 // Test backward word deletion using text input protocol. 986 // Test backward word deletion using text input protocol.
957 TEST_F(BridgedNativeWidgetTest, TextInput_DeleteWordBackward) { 987 TEST_F(BridgedNativeWidgetTest, TextInput_DeleteWordBackward) {
958 InstallTextField("foo bar baz"); 988 InstallTextField("foo bar baz");
959 EXPECT_EQ_RANGE_3(NSMakeRange(11, 0), GetExpectedSelectionRange(), 989 EXPECT_EQ_RANGE_3(NSMakeRange(11, 0), GetExpectedSelectionRange(),
960 GetActualSelectionRange()); 990 GetActualSelectionRange());
961 991
962 // Move the caret to the beginning of the line. 992 // Move the caret to the beginning of the line.
963 SetSelectionRange(NSMakeRange(0, 0)); 993 SetSelectionRange(NSMakeRange(0, 0));
(...skipping 11 matching lines...) Expand all
975 EXPECT_EQ_RANGE_3(NSMakeRange(4, 0), GetExpectedSelectionRange(), 1005 EXPECT_EQ_RANGE_3(NSMakeRange(4, 0), GetExpectedSelectionRange(),
976 GetActualSelectionRange()); 1006 GetActualSelectionRange());
977 1007
978 // Make a selection as- "f|oo r b|az". 1008 // Make a selection as- "f|oo r b|az".
979 SetSelectionRange(NSMakeRange(1, 6)); 1009 SetSelectionRange(NSMakeRange(1, 6));
980 PerformCommand(@selector(deleteWordBackward:)); 1010 PerformCommand(@selector(deleteWordBackward:));
981 // Verify only the selection is deleted and state is "f|az" 1011 // Verify only the selection is deleted and state is "f|az"
982 EXPECT_NSEQ_3(@"faz", GetExpectedText(), GetActualText()); 1012 EXPECT_NSEQ_3(@"faz", GetExpectedText(), GetActualText());
983 EXPECT_EQ_RANGE_3(NSMakeRange(1, 0), GetExpectedSelectionRange(), 1013 EXPECT_EQ_RANGE_3(NSMakeRange(1, 0), GetExpectedSelectionRange(),
984 GetActualSelectionRange()); 1014 GetActualSelectionRange());
1015
1016 // Verify that deletion did not modify the kill buffer.
1017 PerformCommand(@selector(yank:));
1018 EXPECT_NSEQ_3(@"faz", GetExpectedText(), GetActualText());
1019 EXPECT_EQ_RANGE_3(NSMakeRange(1, 0), GetExpectedSelectionRange(),
1020 GetActualSelectionRange());
985 } 1021 }
986 1022
987 // Test deleting to beginning/end of line/paragraph using text input protocol. 1023 // Test deleting to beginning/end of line/paragraph using text input protocol.
988 1024
989 TEST_F(BridgedNativeWidgetTest, TextInput_DeleteToBeginningOfLine) { 1025 TEST_F(BridgedNativeWidgetTest, TextInput_DeleteToBeginningOfLine) {
990 TestDeleteBeginning(@selector(deleteToBeginningOfLine:)); 1026 TestDeleteBeginning(@selector(deleteToBeginningOfLine:));
991 } 1027 }
992 1028
993 TEST_F(BridgedNativeWidgetTest, TextInput_DeleteToEndOfLine) { 1029 TEST_F(BridgedNativeWidgetTest, TextInput_DeleteToEndOfLine) {
994 TestDeleteEnd(@selector(deleteToEndOfLine:)); 1030 TestDeleteEnd(@selector(deleteToEndOfLine:));
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
1196 [center postNotificationName:NSWindowDidExitFullScreenNotification 1232 [center postNotificationName:NSWindowDidExitFullScreenNotification
1197 object:window]; 1233 object:window];
1198 EXPECT_EQ(1, [window ignoredToggleFullScreenCount]); // No change. 1234 EXPECT_EQ(1, [window ignoredToggleFullScreenCount]); // No change.
1199 EXPECT_FALSE(bridge()->target_fullscreen_state()); 1235 EXPECT_FALSE(bridge()->target_fullscreen_state());
1200 1236
1201 widget_->CloseNow(); 1237 widget_->CloseNow();
1202 } 1238 }
1203 1239
1204 } // namespace test 1240 } // namespace test
1205 } // namespace views 1241 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698