OLD | NEW |
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 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 // Test delete to beginning of line or paragraph based on |sel|. |sel| can be | 254 // Test delete to beginning of line or paragraph based on |sel|. |sel| can be |
255 // either deleteToBeginningOfLine: or deleteToBeginningOfParagraph:. | 255 // either deleteToBeginningOfLine: or deleteToBeginningOfParagraph:. |
256 void TestDeleteBeginning(SEL sel); | 256 void TestDeleteBeginning(SEL sel); |
257 | 257 |
258 // Test delete to end of line or paragraph based on |sel|. |sel| can be | 258 // Test delete to end of line or paragraph based on |sel|. |sel| can be |
259 // either deleteToEndOfLine: or deleteToEndOfParagraph:. | 259 // either deleteToEndOfLine: or deleteToEndOfParagraph:. |
260 void TestDeleteEnd(SEL sel); | 260 void TestDeleteEnd(SEL sel); |
261 | 261 |
262 // Test editing commands in |selectors| against the expectations set by | 262 // Test editing commands in |selectors| against the expectations set by |
263 // |dummy_text_view_|. This is done by selecting every substring within a set | 263 // |dummy_text_view_|. This is done by selecting every substring within a set |
264 // of test strings (both RTL and non-RTL) and performing every selector on | 264 // of test strings and performing every selector on both the NSTextView and |
265 // both the NSTextView and the BridgedContentView hosting a focused | 265 // the BridgedContentView hosting a focused views::TextField to ensure the |
266 // views::TextField to ensure the resulting text and selection ranges match. | 266 // resulting text and selection ranges match. |selectors| is an NSArray of |
267 // |selectors| is an NSArray of NSStrings. | 267 // NSStrings. If |test_rtl| is false, no RTL test string is used for testing. |
268 void TestEditingCommands(NSArray* selectors); | 268 void TestEditingCommands(NSArray* selectors, bool test_rtl); |
269 | 269 |
270 std::unique_ptr<views::View> view_; | 270 std::unique_ptr<views::View> view_; |
271 | 271 |
272 // Weak. Owned by bridge(). | 272 // Weak. Owned by bridge(). |
273 BridgedContentView* ns_view_; | 273 BridgedContentView* ns_view_; |
274 | 274 |
275 // An NSTextView which helps set the expectations for our tests. | 275 // An NSTextView which helps set the expectations for our tests. |
276 base::scoped_nsobject<NSTextView> dummy_text_view_; | 276 base::scoped_nsobject<NSTextView> dummy_text_view_; |
277 | 277 |
278 base::MessageLoopForUI message_loop_; | 278 base::MessageLoopForUI message_loop_; |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
446 | 446 |
447 // Make a selection as- "|foo |bar". | 447 // Make a selection as- "|foo |bar". |
448 SetSelectionRange(NSMakeRange(0, 4)); | 448 SetSelectionRange(NSMakeRange(0, 4)); |
449 PerformCommand(sel); | 449 PerformCommand(sel); |
450 // Verify only the selection is deleted so that the state is "|bar". | 450 // Verify only the selection is deleted so that the state is "|bar". |
451 EXPECT_NSEQ_3(@"bar", GetExpectedText(), GetActualText()); | 451 EXPECT_NSEQ_3(@"bar", GetExpectedText(), GetActualText()); |
452 EXPECT_EQ_RANGE_3(NSMakeRange(0, 0), GetExpectedSelectionRange(), | 452 EXPECT_EQ_RANGE_3(NSMakeRange(0, 0), GetExpectedSelectionRange(), |
453 GetActualSelectionRange()); | 453 GetActualSelectionRange()); |
454 } | 454 } |
455 | 455 |
456 void BridgedNativeWidgetTest::TestEditingCommands(NSArray* selectors) { | 456 void BridgedNativeWidgetTest::TestEditingCommands(NSArray* selectors, |
457 const base::string16 test_strings[] = { | 457 bool test_rtl) { |
| 458 std::vector<base::string16> test_strings = { |
458 base::WideToUTF16(L"ab c"), | 459 base::WideToUTF16(L"ab c"), |
459 base::WideToUTF16(L"\x0634\x0632 \x064A") // RTL string. | |
460 }; | 460 }; |
461 | 461 |
| 462 if (test_rtl) |
| 463 test_strings.push_back(base::WideToUTF16(L"\x0634\x0632 \x064A")); |
| 464 |
462 for (const base::string16& test_string : test_strings) { | 465 for (const base::string16& test_string : test_strings) { |
463 for (NSString* selector_string in selectors) { | 466 for (NSString* selector_string in selectors) { |
464 SEL sel = NSSelectorFromString(selector_string); | 467 SEL sel = NSSelectorFromString(selector_string); |
465 const int len = test_string.length(); | 468 const int len = test_string.length(); |
466 for (int i = 0; i <= len; i++) { | 469 for (int i = 0; i <= len; i++) { |
467 for (int j = 0; j <= len; j++) { | 470 for (int j = 0; j <= len; j++) { |
468 SCOPED_TRACE(base::StringPrintf( | 471 SCOPED_TRACE(base::StringPrintf( |
469 "Testing range [%d-%d] for case %s and selector %s\n", i, j, | 472 "Testing range [%d-%d] for case %s and selector %s\n", i, j, |
470 base::UTF16ToUTF8(test_string).c_str(), | 473 base::UTF16ToUTF8(test_string).c_str(), |
471 base::SysNSStringToUTF8(selector_string).c_str())); | 474 base::SysNSStringToUTF8(selector_string).c_str())); |
(...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
959 @"moveToEndOfParagraph:", | 962 @"moveToEndOfParagraph:", |
960 @"moveToEndOfDocument:", | 963 @"moveToEndOfDocument:", |
961 @"moveToBeginningOfDocument:", | 964 @"moveToBeginningOfDocument:", |
962 @"pageDown:", | 965 @"pageDown:", |
963 @"pageUp:", | 966 @"pageUp:", |
964 @"moveWordRight:", | 967 @"moveWordRight:", |
965 @"moveWordLeft:", | 968 @"moveWordLeft:", |
966 @"moveToLeftEndOfLine:", | 969 @"moveToLeftEndOfLine:", |
967 @"moveToRightEndOfLine:" | 970 @"moveToRightEndOfLine:" |
968 ]; | 971 ]; |
969 TestEditingCommands(selectors); | 972 TestEditingCommands(selectors, true); |
970 } | 973 } |
971 | 974 |
972 // Todo(karandeepb): Enable this test once the behavior of all move and select | |
973 // commands are fixed. | |
974 // Test move and select commands against expectations set by |dummy_text_view_|. | 975 // Test move and select commands against expectations set by |dummy_text_view_|. |
975 TEST_F(BridgedNativeWidgetTest, | 976 TEST_F(BridgedNativeWidgetTest, TextInput_MoveAndSelectEditingCommands_1) { |
976 TextInput_MoveAndSelectEditingCommands_DISABLED) { | |
977 NSArray* selectors = @[ | 977 NSArray* selectors = @[ |
978 @"moveBackwardAndModifySelection:", | 978 @"moveBackwardAndModifySelection:", |
979 @"moveForwardAndModifySelection:", | 979 @"moveForwardAndModifySelection:", |
980 @"moveWordForwardAndModifySelection:", | 980 @"moveWordForwardAndModifySelection:", |
981 @"moveWordBackwardAndModifySelection:", | 981 @"moveWordBackwardAndModifySelection:", |
982 @"moveUpAndModifySelection:", | 982 @"moveUpAndModifySelection:", |
983 @"moveDownAndModifySelection:", | 983 @"moveDownAndModifySelection:", |
984 @"moveToBeginningOfLineAndModifySelection:", | 984 @"moveToBeginningOfLineAndModifySelection:", |
985 @"moveToEndOfLineAndModifySelection:", | 985 @"moveToEndOfLineAndModifySelection:", |
986 @"moveToBeginningOfParagraphAndModifySelection:", | 986 @"moveToBeginningOfParagraphAndModifySelection:", |
987 @"moveToEndOfParagraphAndModifySelection:", | 987 @"moveToEndOfParagraphAndModifySelection:", |
988 @"moveToEndOfDocumentAndModifySelection:", | 988 @"moveToEndOfDocumentAndModifySelection:", |
989 @"moveToBeginningOfDocumentAndModifySelection:", | 989 @"moveToBeginningOfDocumentAndModifySelection:", |
990 @"pageDownAndModifySelection:", | 990 @"pageDownAndModifySelection:", |
991 @"pageUpAndModifySelection:", | 991 @"pageUpAndModifySelection:", |
992 @"moveParagraphForwardAndModifySelection:", | 992 @"moveParagraphForwardAndModifySelection:", |
993 @"moveParagraphBackwardAndModifySelection:", | 993 @"moveParagraphBackwardAndModifySelection:", |
994 @"moveRightAndModifySelection:", | 994 ]; |
995 @"moveLeftAndModifySelection:", | 995 TestEditingCommands(selectors, true); |
996 @"moveWordRightAndModifySelection:", | 996 } |
997 @"moveWordLeftAndModifySelection:", | 997 |
| 998 // Test move and select commands against expectations set by |dummy_text_view_|. |
| 999 TEST_F(BridgedNativeWidgetTest, TextInput_MoveAndSelectEditingCommands_2) { |
| 1000 NSArray* selectors = @[ |
| 1001 @"moveRightAndModifySelection:", @"moveLeftAndModifySelection:", |
| 1002 @"moveWordRightAndModifySelection:", @"moveWordLeftAndModifySelection:", |
998 @"moveToLeftEndOfLineAndModifySelection:", | 1003 @"moveToLeftEndOfLineAndModifySelection:", |
999 @"moveToRightEndOfLineAndModifySelection:" | 1004 @"moveToRightEndOfLineAndModifySelection:" |
1000 ]; | 1005 ]; |
1001 TestEditingCommands(selectors); | 1006 |
| 1007 // The behavior of move and select commands with visual direction on |
| 1008 // NSTextView is a bit buggy for RTL text and is not consistent with LTR |
| 1009 // behavior Hence don't test RTL string. |
| 1010 TestEditingCommands(selectors, false); |
1002 } | 1011 } |
1003 | 1012 |
1004 // Test delete commands against expectations set by |dummy_text_view_|. | 1013 // Test delete commands against expectations set by |dummy_text_view_|. |
1005 TEST_F(BridgedNativeWidgetTest, TextInput_DeleteCommands) { | 1014 TEST_F(BridgedNativeWidgetTest, TextInput_DeleteCommands) { |
1006 NSArray* selectors = @[ | 1015 NSArray* selectors = @[ |
1007 @"deleteForward:", @"deleteBackward:", @"deleteWordForward:", | 1016 @"deleteForward:", @"deleteBackward:", @"deleteWordForward:", |
1008 @"deleteWordBackward:", @"deleteToBeginningOfLine:", @"deleteToEndOfLine:", | 1017 @"deleteWordBackward:", @"deleteToBeginningOfLine:", @"deleteToEndOfLine:", |
1009 @"deleteToBeginningOfParagraph:", @"deleteToEndOfParagraph:" | 1018 @"deleteToBeginningOfParagraph:", @"deleteToEndOfParagraph:" |
1010 ]; | 1019 ]; |
1011 TestEditingCommands(selectors); | 1020 TestEditingCommands(selectors, true); |
1012 } | 1021 } |
1013 | 1022 |
1014 // Test firstRectForCharacterRange:actualRange for cases where query range is | 1023 // Test firstRectForCharacterRange:actualRange for cases where query range is |
1015 // empty or outside composition range. | 1024 // empty or outside composition range. |
1016 TEST_F(BridgedNativeWidgetTest, TextInput_FirstRectForCharacterRange_Caret) { | 1025 TEST_F(BridgedNativeWidgetTest, TextInput_FirstRectForCharacterRange_Caret) { |
1017 InstallTextField(""); | 1026 InstallTextField(""); |
1018 ui::TextInputClient* client = [ns_view_ textInputClient]; | 1027 ui::TextInputClient* client = [ns_view_ textInputClient]; |
1019 | 1028 |
1020 // No composition. Ensure bounds and range corresponding to the current caret | 1029 // No composition. Ensure bounds and range corresponding to the current caret |
1021 // position are returned. | 1030 // position are returned. |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1168 [center postNotificationName:NSWindowDidExitFullScreenNotification | 1177 [center postNotificationName:NSWindowDidExitFullScreenNotification |
1169 object:window]; | 1178 object:window]; |
1170 EXPECT_EQ(1, [window ignoredToggleFullScreenCount]); // No change. | 1179 EXPECT_EQ(1, [window ignoredToggleFullScreenCount]); // No change. |
1171 EXPECT_FALSE(bridge()->target_fullscreen_state()); | 1180 EXPECT_FALSE(bridge()->target_fullscreen_state()); |
1172 | 1181 |
1173 widget_->CloseNow(); | 1182 widget_->CloseNow(); |
1174 } | 1183 } |
1175 | 1184 |
1176 } // namespace test | 1185 } // namespace test |
1177 } // namespace views | 1186 } // namespace views |
OLD | NEW |