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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 #define EXPECT_EQ_RANGE_3(expected_literal, expected_cocoa, actual_views) \ | 50 #define EXPECT_EQ_RANGE_3(expected_literal, expected_cocoa, actual_views) \ |
51 EXPECT_EQ_RANGE(expected_literal, actual_views); \ | 51 EXPECT_EQ_RANGE(expected_literal, actual_views); \ |
52 EXPECT_EQ_RANGE(expected_cocoa, actual_views); | 52 EXPECT_EQ_RANGE(expected_cocoa, actual_views); |
53 | 53 |
54 #define EXPECT_EQ_3(expected_literal, expected_cocoa, actual_views) \ | 54 #define EXPECT_EQ_3(expected_literal, expected_cocoa, actual_views) \ |
55 EXPECT_EQ(expected_literal, actual_views); \ | 55 EXPECT_EQ(expected_literal, actual_views); \ |
56 EXPECT_EQ(expected_cocoa, actual_views); | 56 EXPECT_EQ(expected_cocoa, actual_views); |
57 | 57 |
58 namespace { | 58 namespace { |
59 | 59 |
| 60 // Implemented NSResponder action messages for use in tests. |
| 61 NSArray* const kMoveActions = @[ |
| 62 @"moveForward:", |
| 63 @"moveRight:", |
| 64 @"moveBackward:", |
| 65 @"moveLeft:", |
| 66 @"moveUp:", |
| 67 @"moveDown:", |
| 68 @"moveWordForward:", |
| 69 @"moveWordBackward:", |
| 70 @"moveToBeginningOfLine:", |
| 71 @"moveToEndOfLine:", |
| 72 @"moveToBeginningOfParagraph:", |
| 73 @"moveToEndOfParagraph:", |
| 74 @"moveToEndOfDocument:", |
| 75 @"moveToBeginningOfDocument:", |
| 76 @"pageDown:", |
| 77 @"pageUp:", |
| 78 @"moveWordRight:", |
| 79 @"moveWordLeft:", |
| 80 @"moveToLeftEndOfLine:", |
| 81 @"moveToRightEndOfLine:" |
| 82 ]; |
| 83 |
| 84 NSArray* const kSelectActions = @[ |
| 85 @"moveBackwardAndModifySelection:", |
| 86 @"moveForwardAndModifySelection:", |
| 87 @"moveWordForwardAndModifySelection:", |
| 88 @"moveWordBackwardAndModifySelection:", |
| 89 @"moveUpAndModifySelection:", |
| 90 @"moveDownAndModifySelection:", |
| 91 @"moveToBeginningOfLineAndModifySelection:", |
| 92 @"moveToEndOfLineAndModifySelection:", |
| 93 @"moveToBeginningOfParagraphAndModifySelection:", |
| 94 @"moveToEndOfParagraphAndModifySelection:", |
| 95 @"moveToEndOfDocumentAndModifySelection:", |
| 96 @"moveToBeginningOfDocumentAndModifySelection:", |
| 97 @"pageDownAndModifySelection:", |
| 98 @"pageUpAndModifySelection:", |
| 99 @"moveParagraphForwardAndModifySelection:", |
| 100 @"moveParagraphBackwardAndModifySelection:", |
| 101 @"moveRightAndModifySelection:", |
| 102 @"moveLeftAndModifySelection:", |
| 103 @"moveWordRightAndModifySelection:", |
| 104 @"moveWordLeftAndModifySelection:", |
| 105 @"moveToLeftEndOfLineAndModifySelection:", |
| 106 @"moveToRightEndOfLineAndModifySelection:" |
| 107 ]; |
| 108 |
| 109 NSArray* const kDeleteActions = @[ |
| 110 @"deleteForward:", @"deleteBackward:", @"deleteWordForward:", |
| 111 @"deleteWordBackward:", @"deleteToBeginningOfLine:", @"deleteToEndOfLine:", |
| 112 @"deleteToBeginningOfParagraph:", @"deleteToEndOfParagraph:" |
| 113 ]; |
| 114 |
| 115 NSArray* const kMiscActions = @[ @"insertText:", @"cancelOperation:" ]; |
| 116 |
60 // Empty range shortcut for readibility. | 117 // Empty range shortcut for readibility. |
61 NSRange EmptyRange() { | 118 NSRange EmptyRange() { |
62 return NSMakeRange(NSNotFound, 0); | 119 return NSMakeRange(NSNotFound, 0); |
63 } | 120 } |
64 | 121 |
65 // Sets |composition_text| as the composition text with caret placed at | 122 // Sets |composition_text| as the composition text with caret placed at |
66 // |caret_pos| and updates |caret_range|. | 123 // |caret_pos| and updates |caret_range|. |
67 void SetCompositionText(ui::TextInputClient* client, | 124 void SetCompositionText(ui::TextInputClient* client, |
68 const base::string16& composition_text, | 125 const base::string16& composition_text, |
69 const int caret_pos, | 126 const int caret_pos, |
(...skipping 867 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
937 TEST_F(BridgedNativeWidgetTest, TextInput_DeleteToBeginningOfParagraph) { | 994 TEST_F(BridgedNativeWidgetTest, TextInput_DeleteToBeginningOfParagraph) { |
938 TestDeleteBeginning(@selector(deleteToBeginningOfParagraph:)); | 995 TestDeleteBeginning(@selector(deleteToBeginningOfParagraph:)); |
939 } | 996 } |
940 | 997 |
941 TEST_F(BridgedNativeWidgetTest, TextInput_DeleteToEndOfParagraph) { | 998 TEST_F(BridgedNativeWidgetTest, TextInput_DeleteToEndOfParagraph) { |
942 TestDeleteEnd(@selector(deleteToEndOfParagraph:)); | 999 TestDeleteEnd(@selector(deleteToEndOfParagraph:)); |
943 } | 1000 } |
944 | 1001 |
945 // Test move commands against expectations set by |dummy_text_view_|. | 1002 // Test move commands against expectations set by |dummy_text_view_|. |
946 TEST_F(BridgedNativeWidgetTest, TextInput_MoveEditingCommands) { | 1003 TEST_F(BridgedNativeWidgetTest, TextInput_MoveEditingCommands) { |
947 NSArray* selectors = @[ | 1004 TestEditingCommands(kMoveActions); |
948 @"moveForward:", | |
949 @"moveRight:", | |
950 @"moveBackward:", | |
951 @"moveLeft:", | |
952 @"moveUp:", | |
953 @"moveDown:", | |
954 @"moveWordForward:", | |
955 @"moveWordBackward:", | |
956 @"moveToBeginningOfLine:", | |
957 @"moveToEndOfLine:", | |
958 @"moveToBeginningOfParagraph:", | |
959 @"moveToEndOfParagraph:", | |
960 @"moveToEndOfDocument:", | |
961 @"moveToBeginningOfDocument:", | |
962 @"pageDown:", | |
963 @"pageUp:", | |
964 @"moveWordRight:", | |
965 @"moveWordLeft:", | |
966 @"moveToLeftEndOfLine:", | |
967 @"moveToRightEndOfLine:" | |
968 ]; | |
969 TestEditingCommands(selectors); | |
970 } | 1005 } |
971 | 1006 |
972 // Todo(karandeepb): Enable this test once the behavior of all move and select | 1007 // Todo(karandeepb): Enable this test once the behavior of all move and select |
973 // commands are fixed. | 1008 // commands are fixed. |
974 // Test move and select commands against expectations set by |dummy_text_view_|. | 1009 // Test move and select commands against expectations set by |dummy_text_view_|. |
975 TEST_F(BridgedNativeWidgetTest, | 1010 TEST_F(BridgedNativeWidgetTest, |
976 TextInput_MoveAndSelectEditingCommands_DISABLED) { | 1011 TextInput_MoveAndSelectEditingCommands_DISABLED) { |
977 NSArray* selectors = @[ | 1012 TestEditingCommands(kSelectActions); |
978 @"moveBackwardAndModifySelection:", | |
979 @"moveForwardAndModifySelection:", | |
980 @"moveWordForwardAndModifySelection:", | |
981 @"moveWordBackwardAndModifySelection:", | |
982 @"moveUpAndModifySelection:", | |
983 @"moveDownAndModifySelection:", | |
984 @"moveToBeginningOfLineAndModifySelection:", | |
985 @"moveToEndOfLineAndModifySelection:", | |
986 @"moveToBeginningOfParagraphAndModifySelection:", | |
987 @"moveToEndOfParagraphAndModifySelection:", | |
988 @"moveToEndOfDocumentAndModifySelection:", | |
989 @"moveToBeginningOfDocumentAndModifySelection:", | |
990 @"pageDownAndModifySelection:", | |
991 @"pageUpAndModifySelection:", | |
992 @"moveParagraphForwardAndModifySelection:", | |
993 @"moveParagraphBackwardAndModifySelection:", | |
994 @"moveRightAndModifySelection:", | |
995 @"moveLeftAndModifySelection:", | |
996 @"moveWordRightAndModifySelection:", | |
997 @"moveWordLeftAndModifySelection:", | |
998 @"moveToLeftEndOfLineAndModifySelection:", | |
999 @"moveToRightEndOfLineAndModifySelection:" | |
1000 ]; | |
1001 TestEditingCommands(selectors); | |
1002 } | 1013 } |
1003 | 1014 |
1004 // Test delete commands against expectations set by |dummy_text_view_|. | 1015 // Test delete commands against expectations set by |dummy_text_view_|. |
1005 TEST_F(BridgedNativeWidgetTest, TextInput_DeleteCommands) { | 1016 TEST_F(BridgedNativeWidgetTest, TextInput_DeleteCommands) { |
1006 NSArray* selectors = @[ | 1017 TestEditingCommands(kDeleteActions); |
1007 @"deleteForward:", @"deleteBackward:", @"deleteWordForward:", | 1018 } |
1008 @"deleteWordBackward:", @"deleteToBeginningOfLine:", @"deleteToEndOfLine:", | 1019 |
1009 @"deleteToBeginningOfParagraph:", @"deleteToEndOfParagraph:" | 1020 // Test that we don't crash during an action message even if the TextInputClient |
1010 ]; | 1021 // is nil. Regression test for crbug.com/615745. |
1011 TestEditingCommands(selectors); | 1022 TEST_F(BridgedNativeWidgetTest, NilTextInputClient) { |
| 1023 [ns_view_ setTextInputClient:nil]; |
| 1024 NSMutableArray* selectors = [NSMutableArray array]; |
| 1025 [selectors addObjectsFromArray:kMoveActions]; |
| 1026 [selectors addObjectsFromArray:kSelectActions]; |
| 1027 [selectors addObjectsFromArray:kDeleteActions]; |
| 1028 [selectors addObjectsFromArray:kMiscActions]; |
| 1029 |
| 1030 for (NSString* selector in selectors) |
| 1031 [ns_view_ doCommandBySelector:NSSelectorFromString(selector)]; |
1012 } | 1032 } |
1013 | 1033 |
1014 // Test firstRectForCharacterRange:actualRange for cases where query range is | 1034 // Test firstRectForCharacterRange:actualRange for cases where query range is |
1015 // empty or outside composition range. | 1035 // empty or outside composition range. |
1016 TEST_F(BridgedNativeWidgetTest, TextInput_FirstRectForCharacterRange_Caret) { | 1036 TEST_F(BridgedNativeWidgetTest, TextInput_FirstRectForCharacterRange_Caret) { |
1017 InstallTextField(""); | 1037 InstallTextField(""); |
1018 ui::TextInputClient* client = [ns_view_ textInputClient]; | 1038 ui::TextInputClient* client = [ns_view_ textInputClient]; |
1019 | 1039 |
1020 // No composition. Ensure bounds and range corresponding to the current caret | 1040 // No composition. Ensure bounds and range corresponding to the current caret |
1021 // position are returned. | 1041 // position are returned. |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1168 [center postNotificationName:NSWindowDidExitFullScreenNotification | 1188 [center postNotificationName:NSWindowDidExitFullScreenNotification |
1169 object:window]; | 1189 object:window]; |
1170 EXPECT_EQ(1, [window ignoredToggleFullScreenCount]); // No change. | 1190 EXPECT_EQ(1, [window ignoredToggleFullScreenCount]); // No change. |
1171 EXPECT_FALSE(bridge()->target_fullscreen_state()); | 1191 EXPECT_FALSE(bridge()->target_fullscreen_state()); |
1172 | 1192 |
1173 widget_->CloseNow(); | 1193 widget_->CloseNow(); |
1174 } | 1194 } |
1175 | 1195 |
1176 } // namespace test | 1196 } // namespace test |
1177 } // namespace views | 1197 } // namespace views |
OLD | NEW |