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

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

Issue 2019233003: MacViews: Fix crash caused due to nil TextInputClient. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address review comments. Created 4 years, 6 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
« no previous file with comments | « ui/views/cocoa/bridged_content_view.mm ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 gfx::Rect right_caret = GetCaretBoundsForPosition( 103 gfx::Rect right_caret = GetCaretBoundsForPosition(
104 client, composition_text, query_range.location + query_range.length, 104 client, composition_text, query_range.location + query_range.length,
105 nullptr); 105 nullptr);
106 106
107 // The expected bounds correspond to the area between the left and right caret 107 // The expected bounds correspond to the area between the left and right caret
108 // positions. 108 // positions.
109 return gfx::Rect(left_caret.x(), left_caret.y(), 109 return gfx::Rect(left_caret.x(), left_caret.y(),
110 right_caret.x() - left_caret.x(), left_caret.height()); 110 right_caret.x() - left_caret.x(), left_caret.height());
111 } 111 }
112 112
113 // Implemented NSResponder action messages for use in tests.
tapted 2016/05/31 01:49:14 nit: constants should come before functions in eac
karandeepb 2016/05/31 01:57:33 Done.
114 NSArray* kMoveActions = @[
tapted 2016/05/31 01:49:14 nit: NSArray* const kMoveActions - same below (it'
karandeepb 2016/05/31 01:57:33 Done.
115 @"moveForward:",
116 @"moveRight:",
117 @"moveBackward:",
118 @"moveLeft:",
119 @"moveUp:",
120 @"moveDown:",
121 @"moveWordForward:",
122 @"moveWordBackward:",
123 @"moveToBeginningOfLine:",
124 @"moveToEndOfLine:",
125 @"moveToBeginningOfParagraph:",
126 @"moveToEndOfParagraph:",
127 @"moveToEndOfDocument:",
128 @"moveToBeginningOfDocument:",
129 @"pageDown:",
130 @"pageUp:",
131 @"moveWordRight:",
132 @"moveWordLeft:",
133 @"moveToLeftEndOfLine:",
134 @"moveToRightEndOfLine:"
135 ];
136
137 NSArray* kSelectActions = @[
138 @"moveBackwardAndModifySelection:",
139 @"moveForwardAndModifySelection:",
140 @"moveWordForwardAndModifySelection:",
141 @"moveWordBackwardAndModifySelection:",
142 @"moveUpAndModifySelection:",
143 @"moveDownAndModifySelection:",
144 @"moveToBeginningOfLineAndModifySelection:",
145 @"moveToEndOfLineAndModifySelection:",
146 @"moveToBeginningOfParagraphAndModifySelection:",
147 @"moveToEndOfParagraphAndModifySelection:",
148 @"moveToEndOfDocumentAndModifySelection:",
149 @"moveToBeginningOfDocumentAndModifySelection:",
150 @"pageDownAndModifySelection:",
151 @"pageUpAndModifySelection:",
152 @"moveParagraphForwardAndModifySelection:",
153 @"moveParagraphBackwardAndModifySelection:",
154 @"moveRightAndModifySelection:",
155 @"moveLeftAndModifySelection:",
156 @"moveWordRightAndModifySelection:",
157 @"moveWordLeftAndModifySelection:",
158 @"moveToLeftEndOfLineAndModifySelection:",
159 @"moveToRightEndOfLineAndModifySelection:"
160 ];
161
162 NSArray* kDeleteActions = @[
163 @"deleteForward:", @"deleteBackward:", @"deleteWordForward:",
164 @"deleteWordBackward:", @"deleteToBeginningOfLine:", @"deleteToEndOfLine:",
165 @"deleteToBeginningOfParagraph:", @"deleteToEndOfParagraph:"
166 ];
167
168 NSArray* kMiscActions = @[ @"insertText:", @"cancelOperation:" ];
169
113 } // namespace 170 } // namespace
114 171
115 // Class to override -[NSWindow toggleFullScreen:] to a no-op. This simulates 172 // Class to override -[NSWindow toggleFullScreen:] to a no-op. This simulates
116 // NSWindow's behavior when attempting to toggle fullscreen state again, when 173 // NSWindow's behavior when attempting to toggle fullscreen state again, when
117 // the last attempt failed but Cocoa has not yet sent 174 // the last attempt failed but Cocoa has not yet sent
118 // windowDidFailToEnterFullScreen:. 175 // windowDidFailToEnterFullScreen:.
119 @interface BridgedNativeWidgetTestFullScreenWindow : NativeWidgetMacNSWindow { 176 @interface BridgedNativeWidgetTestFullScreenWindow : NativeWidgetMacNSWindow {
120 @private 177 @private
121 int ignoredToggleFullScreenCount_; 178 int ignoredToggleFullScreenCount_;
122 } 179 }
(...skipping 814 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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
OLDNEW
« no previous file with comments | « ui/views/cocoa/bridged_content_view.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698