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

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 464 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 EXPECT_EQ_RANGE_3(NSMakeRange(0, 0), GetExpectedSelectionRange(), 475 EXPECT_EQ_RANGE_3(NSMakeRange(0, 0), GetExpectedSelectionRange(),
476 GetActualSelectionRange()); 476 GetActualSelectionRange());
477 477
478 // Make a selection as- " bar |baz|". 478 // Make a selection as- " bar |baz|".
479 SetSelectionRange(NSMakeRange(5, 3)); 479 SetSelectionRange(NSMakeRange(5, 3));
480 PerformCommand(sel); 480 PerformCommand(sel);
481 // Verify only the selection is deleted so that the state is " bar |". 481 // Verify only the selection is deleted so that the state is " bar |".
482 EXPECT_NSEQ_3(@" bar ", GetExpectedText(), GetActualText()); 482 EXPECT_NSEQ_3(@" bar ", GetExpectedText(), GetActualText());
483 EXPECT_EQ_RANGE_3(NSMakeRange(5, 0), GetExpectedSelectionRange(), 483 EXPECT_EQ_RANGE_3(NSMakeRange(5, 0), GetExpectedSelectionRange(),
484 GetActualSelectionRange()); 484 GetActualSelectionRange());
485
486 // Verify yanking inserts the deleted text.
487 PerformCommand(@selector(yank:));
488 EXPECT_NSEQ_3(@" bar baz", GetExpectedText(), GetActualText());
489 EXPECT_EQ_RANGE_3(NSMakeRange(8, 0), GetExpectedSelectionRange(),
490 GetActualSelectionRange());
485 } 491 }
486 492
487 void BridgedNativeWidgetTest::TestDeleteEnd(SEL sel) { 493 void BridgedNativeWidgetTest::TestDeleteEnd(SEL sel) {
488 InstallTextField("foo bar baz"); 494 InstallTextField("foo bar baz");
489 EXPECT_EQ_RANGE_3(NSMakeRange(11, 0), GetExpectedSelectionRange(), 495 EXPECT_EQ_RANGE_3(NSMakeRange(11, 0), GetExpectedSelectionRange(),
490 GetActualSelectionRange()); 496 GetActualSelectionRange());
491 497
492 // Caret is at the end of the line. Verify no deletion takes place. 498 // Caret is at the end of the line. Verify no deletion takes place.
493 PerformCommand(sel); 499 PerformCommand(sel);
494 EXPECT_NSEQ_3(@"foo bar baz", GetExpectedText(), GetActualText()); 500 EXPECT_NSEQ_3(@"foo bar baz", GetExpectedText(), GetActualText());
495 EXPECT_EQ_RANGE_3(NSMakeRange(11, 0), GetExpectedSelectionRange(), 501 EXPECT_EQ_RANGE_3(NSMakeRange(11, 0), GetExpectedSelectionRange(),
496 GetActualSelectionRange()); 502 GetActualSelectionRange());
497 503
498 // Move the caret as- "foo bar| baz". 504 // Move the caret as- "foo bar| baz".
499 SetSelectionRange(NSMakeRange(7, 0)); 505 SetSelectionRange(NSMakeRange(7, 0));
500 PerformCommand(sel); 506 PerformCommand(sel);
501 // Verify state is "foo bar|". 507 // Verify state is "foo bar|".
502 EXPECT_NSEQ_3(@"foo bar", GetExpectedText(), GetActualText()); 508 EXPECT_NSEQ_3(@"foo bar", GetExpectedText(), GetActualText());
503 EXPECT_EQ_RANGE_3(NSMakeRange(7, 0), GetExpectedSelectionRange(), 509 EXPECT_EQ_RANGE_3(NSMakeRange(7, 0), GetExpectedSelectionRange(),
504 GetActualSelectionRange()); 510 GetActualSelectionRange());
505 511
506 // Make a selection as- "|foo |bar". 512 // Make a selection as- "|foo |bar".
507 SetSelectionRange(NSMakeRange(0, 4)); 513 SetSelectionRange(NSMakeRange(0, 4));
508 PerformCommand(sel); 514 PerformCommand(sel);
509 // Verify only the selection is deleted so that the state is "|bar". 515 // Verify only the selection is deleted so that the state is "|bar".
510 EXPECT_NSEQ_3(@"bar", GetExpectedText(), GetActualText()); 516 EXPECT_NSEQ_3(@"bar", GetExpectedText(), GetActualText());
511 EXPECT_EQ_RANGE_3(NSMakeRange(0, 0), GetExpectedSelectionRange(), 517 EXPECT_EQ_RANGE_3(NSMakeRange(0, 0), GetExpectedSelectionRange(),
512 GetActualSelectionRange()); 518 GetActualSelectionRange());
519
520 // Verify yanking inserts the deleted text.
521 PerformCommand(@selector(yank:));
522 EXPECT_NSEQ_3(@"foo bar", GetExpectedText(), GetActualText());
523 EXPECT_EQ_RANGE_3(NSMakeRange(4, 0), GetExpectedSelectionRange(),
524 GetActualSelectionRange());
513 } 525 }
514 526
515 void BridgedNativeWidgetTest::TestEditingCommands(NSArray* selectors) { 527 void BridgedNativeWidgetTest::TestEditingCommands(NSArray* selectors) {
516 const base::string16 test_strings[] = { 528 const base::string16 test_strings[] = {
517 base::WideToUTF16(L"ab c"), 529 base::WideToUTF16(L"ab c"),
518 base::WideToUTF16(L"\x0634\x0632 \x064A") // RTL string. 530 base::WideToUTF16(L"\x0634\x0632 \x064A") // RTL string.
519 }; 531 };
520 532
521 for (const base::string16& test_string : test_strings) { 533 for (const base::string16& test_string : test_strings) {
522 for (NSString* selector_string in selectors) { 534 for (NSString* selector_string in selectors) {
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
889 InstallTextField("a"); 901 InstallTextField("a");
890 EXPECT_EQ_RANGE_3(NSMakeRange(1, 0), GetExpectedSelectionRange(), 902 EXPECT_EQ_RANGE_3(NSMakeRange(1, 0), GetExpectedSelectionRange(),
891 GetActualSelectionRange()); 903 GetActualSelectionRange());
892 904
893 // Delete one character. 905 // Delete one character.
894 PerformCommand(@selector(deleteBackward:)); 906 PerformCommand(@selector(deleteBackward:));
895 EXPECT_NSEQ_3(nil, GetExpectedText(), GetActualText()); 907 EXPECT_NSEQ_3(nil, GetExpectedText(), GetActualText());
896 EXPECT_EQ_RANGE_3(NSMakeRange(0, 0), GetExpectedSelectionRange(), 908 EXPECT_EQ_RANGE_3(NSMakeRange(0, 0), GetExpectedSelectionRange(),
897 GetActualSelectionRange()); 909 GetActualSelectionRange());
898 910
911 // Verify that deletion did not modify the kill buffer.
912 PerformCommand(@selector(yank:));
913 EXPECT_NSEQ_3(nil, GetExpectedText(), GetActualText());
914 EXPECT_EQ_RANGE_3(NSMakeRange(0, 0), GetExpectedSelectionRange(),
915 GetActualSelectionRange());
916
899 // Try to delete again on an empty string. 917 // Try to delete again on an empty string.
900 PerformCommand(@selector(deleteBackward:)); 918 PerformCommand(@selector(deleteBackward:));
901 EXPECT_NSEQ_3(nil, GetExpectedText(), GetActualText()); 919 EXPECT_NSEQ_3(nil, GetExpectedText(), GetActualText());
902 EXPECT_EQ_RANGE_3(NSMakeRange(0, 0), GetExpectedSelectionRange(), 920 EXPECT_EQ_RANGE_3(NSMakeRange(0, 0), GetExpectedSelectionRange(),
903 GetActualSelectionRange()); 921 GetActualSelectionRange());
904 } 922 }
905 923
906 // Test forward delete using text input protocol. 924 // Test forward delete using text input protocol.
907 TEST_F(BridgedNativeWidgetTest, TextInput_DeleteForward) { 925 TEST_F(BridgedNativeWidgetTest, TextInput_DeleteForward) {
908 InstallTextField("a"); 926 InstallTextField("a");
909 EXPECT_EQ_RANGE_3(NSMakeRange(1, 0), GetExpectedSelectionRange(), 927 EXPECT_EQ_RANGE_3(NSMakeRange(1, 0), GetExpectedSelectionRange(),
910 GetActualSelectionRange()); 928 GetActualSelectionRange());
911 929
912 // At the end of the string, can't delete forward. 930 // At the end of the string, can't delete forward.
913 PerformCommand(@selector(deleteForward:)); 931 PerformCommand(@selector(deleteForward:));
914 EXPECT_NSEQ_3(@"a", GetExpectedText(), GetActualText()); 932 EXPECT_NSEQ_3(@"a", GetExpectedText(), GetActualText());
915 EXPECT_EQ_RANGE_3(NSMakeRange(1, 0), GetExpectedSelectionRange(), 933 EXPECT_EQ_RANGE_3(NSMakeRange(1, 0), GetExpectedSelectionRange(),
916 GetActualSelectionRange()); 934 GetActualSelectionRange());
917 935
918 // Should succeed after moving left first. 936 // Should succeed after moving left first.
919 PerformCommand(@selector(moveLeft:)); 937 PerformCommand(@selector(moveLeft:));
920 PerformCommand(@selector(deleteForward:)); 938 PerformCommand(@selector(deleteForward:));
921 EXPECT_NSEQ_3(nil, GetExpectedText(), GetActualText()); 939 EXPECT_NSEQ_3(nil, GetExpectedText(), GetActualText());
922 EXPECT_EQ_RANGE_3(NSMakeRange(0, 0), GetExpectedSelectionRange(), 940 EXPECT_EQ_RANGE_3(NSMakeRange(0, 0), GetExpectedSelectionRange(),
923 GetActualSelectionRange()); 941 GetActualSelectionRange());
942
943 // Verify that deletion did not modify the kill buffer.
944 PerformCommand(@selector(yank:));
945 EXPECT_NSEQ_3(nil, GetExpectedText(), GetActualText());
946 EXPECT_EQ_RANGE_3(NSMakeRange(0, 0), GetExpectedSelectionRange(),
947 GetActualSelectionRange());
924 } 948 }
925 949
926 // Test forward word deletion using text input protocol. 950 // Test forward word deletion using text input protocol.
927 TEST_F(BridgedNativeWidgetTest, TextInput_DeleteWordForward) { 951 TEST_F(BridgedNativeWidgetTest, TextInput_DeleteWordForward) {
928 InstallTextField("foo bar baz"); 952 InstallTextField("foo bar baz");
929 EXPECT_EQ_RANGE_3(NSMakeRange(11, 0), GetExpectedSelectionRange(), 953 EXPECT_EQ_RANGE_3(NSMakeRange(11, 0), GetExpectedSelectionRange(),
930 GetActualSelectionRange()); 954 GetActualSelectionRange());
931 955
932 // Caret is at the end of the line. Verify no deletion takes place. 956 // Caret is at the end of the line. Verify no deletion takes place.
933 PerformCommand(@selector(deleteWordForward:)); 957 PerformCommand(@selector(deleteWordForward:));
934 EXPECT_NSEQ_3(@"foo bar baz", GetExpectedText(), GetActualText()); 958 EXPECT_NSEQ_3(@"foo bar baz", GetExpectedText(), GetActualText());
935 EXPECT_EQ_RANGE_3(NSMakeRange(11, 0), GetExpectedSelectionRange(), 959 EXPECT_EQ_RANGE_3(NSMakeRange(11, 0), GetExpectedSelectionRange(),
936 GetActualSelectionRange()); 960 GetActualSelectionRange());
937 961
938 // Move the caret as- "foo b|ar baz". 962 // Move the caret as- "foo b|ar baz".
939 SetSelectionRange(NSMakeRange(5, 0)); 963 SetSelectionRange(NSMakeRange(5, 0));
940 PerformCommand(@selector(deleteWordForward:)); 964 PerformCommand(@selector(deleteWordForward:));
941 // Verify state is "foo b| baz" 965 // Verify state is "foo b| baz"
942 EXPECT_NSEQ_3(@"foo b baz", GetExpectedText(), GetActualText()); 966 EXPECT_NSEQ_3(@"foo b baz", GetExpectedText(), GetActualText());
943 EXPECT_EQ_RANGE_3(NSMakeRange(5, 0), GetExpectedSelectionRange(), 967 EXPECT_EQ_RANGE_3(NSMakeRange(5, 0), GetExpectedSelectionRange(),
944 GetActualSelectionRange()); 968 GetActualSelectionRange());
945 969
946 // Make a selection as- "|fo|o b baz". 970 // Make a selection as- "|fo|o b baz".
947 SetSelectionRange(NSMakeRange(0, 2)); 971 SetSelectionRange(NSMakeRange(0, 2));
948 PerformCommand(@selector(deleteWordForward:)); 972 PerformCommand(@selector(deleteWordForward:));
949 // Verify only the selection is deleted and state is "|o b baz". 973 // Verify only the selection is deleted and state is "|o b baz".
950 EXPECT_NSEQ_3(@"o b baz", GetExpectedText(), GetActualText()); 974 EXPECT_NSEQ_3(@"o b baz", GetExpectedText(), GetActualText());
951 EXPECT_EQ_RANGE_3(NSMakeRange(0, 0), GetExpectedSelectionRange(), 975 EXPECT_EQ_RANGE_3(NSMakeRange(0, 0), GetExpectedSelectionRange(),
952 GetActualSelectionRange()); 976 GetActualSelectionRange());
977
978 // Verify that deletion did not modify the kill buffer.
979 PerformCommand(@selector(yank:));
980 EXPECT_NSEQ_3(@"o b baz", GetExpectedText(), GetActualText());
981 EXPECT_EQ_RANGE_3(NSMakeRange(0, 0), GetExpectedSelectionRange(),
982 GetActualSelectionRange());
953 } 983 }
954 984
955 // Test backward word deletion using text input protocol. 985 // Test backward word deletion using text input protocol.
956 TEST_F(BridgedNativeWidgetTest, TextInput_DeleteWordBackward) { 986 TEST_F(BridgedNativeWidgetTest, TextInput_DeleteWordBackward) {
957 InstallTextField("foo bar baz"); 987 InstallTextField("foo bar baz");
958 EXPECT_EQ_RANGE_3(NSMakeRange(11, 0), GetExpectedSelectionRange(), 988 EXPECT_EQ_RANGE_3(NSMakeRange(11, 0), GetExpectedSelectionRange(),
959 GetActualSelectionRange()); 989 GetActualSelectionRange());
960 990
961 // Move the caret to the beginning of the line. 991 // Move the caret to the beginning of the line.
962 SetSelectionRange(NSMakeRange(0, 0)); 992 SetSelectionRange(NSMakeRange(0, 0));
(...skipping 11 matching lines...) Expand all
974 EXPECT_EQ_RANGE_3(NSMakeRange(4, 0), GetExpectedSelectionRange(), 1004 EXPECT_EQ_RANGE_3(NSMakeRange(4, 0), GetExpectedSelectionRange(),
975 GetActualSelectionRange()); 1005 GetActualSelectionRange());
976 1006
977 // Make a selection as- "f|oo r b|az". 1007 // Make a selection as- "f|oo r b|az".
978 SetSelectionRange(NSMakeRange(1, 6)); 1008 SetSelectionRange(NSMakeRange(1, 6));
979 PerformCommand(@selector(deleteWordBackward:)); 1009 PerformCommand(@selector(deleteWordBackward:));
980 // Verify only the selection is deleted and state is "f|az" 1010 // Verify only the selection is deleted and state is "f|az"
981 EXPECT_NSEQ_3(@"faz", GetExpectedText(), GetActualText()); 1011 EXPECT_NSEQ_3(@"faz", GetExpectedText(), GetActualText());
982 EXPECT_EQ_RANGE_3(NSMakeRange(1, 0), GetExpectedSelectionRange(), 1012 EXPECT_EQ_RANGE_3(NSMakeRange(1, 0), GetExpectedSelectionRange(),
983 GetActualSelectionRange()); 1013 GetActualSelectionRange());
1014
1015 // Verify that deletion did not modify the kill buffer.
1016 PerformCommand(@selector(yank:));
1017 EXPECT_NSEQ_3(@"faz", GetExpectedText(), GetActualText());
1018 EXPECT_EQ_RANGE_3(NSMakeRange(1, 0), GetExpectedSelectionRange(),
1019 GetActualSelectionRange());
984 } 1020 }
985 1021
986 // Test deleting to beginning/end of line/paragraph using text input protocol. 1022 // Test deleting to beginning/end of line/paragraph using text input protocol.
987 1023
988 TEST_F(BridgedNativeWidgetTest, TextInput_DeleteToBeginningOfLine) { 1024 TEST_F(BridgedNativeWidgetTest, TextInput_DeleteToBeginningOfLine) {
989 TestDeleteBeginning(@selector(deleteToBeginningOfLine:)); 1025 TestDeleteBeginning(@selector(deleteToBeginningOfLine:));
990 } 1026 }
991 1027
992 TEST_F(BridgedNativeWidgetTest, TextInput_DeleteToEndOfLine) { 1028 TEST_F(BridgedNativeWidgetTest, TextInput_DeleteToEndOfLine) {
993 TestDeleteEnd(@selector(deleteToEndOfLine:)); 1029 TestDeleteEnd(@selector(deleteToEndOfLine:));
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
1190 [center postNotificationName:NSWindowDidExitFullScreenNotification 1226 [center postNotificationName:NSWindowDidExitFullScreenNotification
1191 object:window]; 1227 object:window];
1192 EXPECT_EQ(1, [window ignoredToggleFullScreenCount]); // No change. 1228 EXPECT_EQ(1, [window ignoredToggleFullScreenCount]); // No change.
1193 EXPECT_FALSE(bridge()->target_fullscreen_state()); 1229 EXPECT_FALSE(bridge()->target_fullscreen_state());
1194 1230
1195 widget_->CloseNow(); 1231 widget_->CloseNow();
1196 } 1232 }
1197 1233
1198 } // namespace test 1234 } // namespace test
1199 } // namespace views 1235 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698