Chromium Code Reviews| 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 |
| 11 #import "base/mac/foundation_util.h" | 11 #import "base/mac/foundation_util.h" |
| 12 #import "base/mac/mac_util.h" | 12 #import "base/mac/mac_util.h" |
| 13 #import "base/mac/sdk_forward_declarations.h" | 13 #import "base/mac/sdk_forward_declarations.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
| 16 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
| 17 #include "base/strings/sys_string_conversions.h" | 17 #include "base/strings/sys_string_conversions.h" |
| 18 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
| 19 #import "testing/gtest_mac.h" | 19 #import "testing/gtest_mac.h" |
| 20 #import "ui/base/cocoa/window_size_constants.h" | 20 #import "ui/base/cocoa/window_size_constants.h" |
| 21 #include "ui/base/ime/input_method.h" | 21 #include "ui/base/ime/input_method.h" |
| 22 #include "ui/events/test/cocoa_test_event_utils.h" | |
| 22 #import "ui/gfx/mac/coordinate_conversion.h" | 23 #import "ui/gfx/mac/coordinate_conversion.h" |
| 23 #import "ui/gfx/test/ui_cocoa_test_helper.h" | 24 #import "ui/gfx/test/ui_cocoa_test_helper.h" |
| 24 #import "ui/views/cocoa/bridged_content_view.h" | 25 #import "ui/views/cocoa/bridged_content_view.h" |
| 25 #import "ui/views/cocoa/native_widget_mac_nswindow.h" | 26 #import "ui/views/cocoa/native_widget_mac_nswindow.h" |
| 26 #import "ui/views/cocoa/views_nswindow_delegate.h" | 27 #import "ui/views/cocoa/views_nswindow_delegate.h" |
| 27 #include "ui/views/controls/textfield/textfield.h" | 28 #include "ui/views/controls/textfield/textfield.h" |
| 28 #include "ui/views/view.h" | 29 #include "ui/views/view.h" |
| 29 #include "ui/views/widget/native_widget_mac.h" | 30 #include "ui/views/widget/native_widget_mac.h" |
| 30 #include "ui/views/widget/root_view.h" | 31 #include "ui/views/widget/root_view.h" |
| 31 #include "ui/views/widget/widget.h" | 32 #include "ui/views/widget/widget.h" |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 184 @implementation BridgedNativeWidgetTestFullScreenWindow | 185 @implementation BridgedNativeWidgetTestFullScreenWindow |
| 185 | 186 |
| 186 @synthesize ignoredToggleFullScreenCount = ignoredToggleFullScreenCount_; | 187 @synthesize ignoredToggleFullScreenCount = ignoredToggleFullScreenCount_; |
| 187 | 188 |
| 188 - (void)toggleFullScreen:(id)sender { | 189 - (void)toggleFullScreen:(id)sender { |
| 189 ++ignoredToggleFullScreenCount_; | 190 ++ignoredToggleFullScreenCount_; |
| 190 } | 191 } |
| 191 | 192 |
| 192 @end | 193 @end |
| 193 | 194 |
| 195 // A category on BridgedContentView to set the private |keyDownEvent_| variable | |
| 196 // for tests. | |
| 197 @interface BridgedContentView (Test) | |
| 198 - (void)setKeyDownEvent:(NSEvent*)event; | |
| 199 @end | |
| 200 | |
| 201 @implementation BridgedContentView (Test) | |
| 202 | |
| 203 - (void)setKeyDownEvent:(NSEvent*)event { | |
| 204 [self setValue:event forKey:@"keyDownEvent_"]; | |
|
karandeepb
2016/07/27 04:47:32
On my workstation, even directly modifying keyDown
| |
| 205 } | |
| 206 | |
| 207 @end | |
| 208 | |
| 194 namespace views { | 209 namespace views { |
| 195 namespace test { | 210 namespace test { |
| 196 | 211 |
| 197 // Provides the |parent| argument to construct a BridgedNativeWidget. | 212 // Provides the |parent| argument to construct a BridgedNativeWidget. |
| 198 class MockNativeWidgetMac : public NativeWidgetMac { | 213 class MockNativeWidgetMac : public NativeWidgetMac { |
| 199 public: | 214 public: |
| 200 MockNativeWidgetMac(Widget* delegate) : NativeWidgetMac(delegate) {} | 215 MockNativeWidgetMac(Widget* delegate) : NativeWidgetMac(delegate) {} |
| 201 | 216 |
| 202 // Expose a reference, so that it can be reset() independently. | 217 // Expose a reference, so that it can be reset() independently. |
| 203 std::unique_ptr<BridgedNativeWidget>& bridge() { return bridge_; } | 218 std::unique_ptr<BridgedNativeWidget>& bridge() { return bridge_; } |
| (...skipping 657 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 861 EXPECT_NSEQ_3(@"foo bar", GetExpectedText(), GetActualText()); | 876 EXPECT_NSEQ_3(@"foo bar", GetExpectedText(), GetActualText()); |
| 862 EXPECT_EQ_RANGE_3(NSMakeRange([GetActualText() length], 0), | 877 EXPECT_EQ_RANGE_3(NSMakeRange([GetActualText() length], 0), |
| 863 GetExpectedSelectionRange(), GetActualSelectionRange()); | 878 GetExpectedSelectionRange(), GetActualSelectionRange()); |
| 864 } | 879 } |
| 865 | 880 |
| 866 // Test IME composition for accented characters. | 881 // Test IME composition for accented characters. |
| 867 TEST_F(BridgedNativeWidgetTest, TextInput_AccentedCharacter) { | 882 TEST_F(BridgedNativeWidgetTest, TextInput_AccentedCharacter) { |
| 868 InstallTextField("abc"); | 883 InstallTextField("abc"); |
| 869 | 884 |
| 870 // Simulate action messages generated when the key 'a' is pressed repeatedly | 885 // Simulate action messages generated when the key 'a' is pressed repeatedly |
| 871 // and leads to the showing of an IME candidate window. | 886 // and leads to the showing of an IME candidate window. To simulate an event, |
| 887 // set the private keyDownEvent field on the BridgedContentView. | |
| 872 | 888 |
| 873 // First an insertText: message with key 'a' is generated. | 889 // First an insertText: message with key 'a' is generated. |
| 890 [ns_view_ | |
| 891 setKeyDownEvent:cocoa_test_event_utils::SynthesizeKeyEvent( | |
| 892 widget_->GetNativeWindow(), true, ui::VKEY_A, 0)]; | |
| 874 [ns_view_ insertText:@"a" replacementRange:EmptyRange()]; | 893 [ns_view_ insertText:@"a" replacementRange:EmptyRange()]; |
| 875 [dummy_text_view_ insertText:@"a" replacementRange:EmptyRange()]; | 894 [dummy_text_view_ insertText:@"a" replacementRange:EmptyRange()]; |
| 876 EXPECT_EQ_3(NO, [dummy_text_view_ hasMarkedText], [ns_view_ hasMarkedText]); | 895 EXPECT_EQ_3(NO, [dummy_text_view_ hasMarkedText], [ns_view_ hasMarkedText]); |
| 877 EXPECT_NSEQ_3(@"abca", GetExpectedText(), GetActualText()); | 896 EXPECT_NSEQ_3(@"abca", GetExpectedText(), GetActualText()); |
| 878 | 897 |
| 879 // Next the IME popup appears. On selecting the accented character using arrow | 898 // Next the IME popup appears. On selecting the accented character using arrow |
| 880 // keys, setMarkedText action message is generated which replaces the earlier | 899 // keys, setMarkedText action message is generated which replaces the earlier |
| 881 // inserted 'a'. | 900 // inserted 'a'. |
| 901 [ns_view_ | |
| 902 setKeyDownEvent:cocoa_test_event_utils::SynthesizeKeyEvent( | |
| 903 widget_->GetNativeWindow(), true, ui::VKEY_RIGHT, 0)]; | |
| 882 [ns_view_ setMarkedText:@"à" | 904 [ns_view_ setMarkedText:@"à" |
| 883 selectedRange:NSMakeRange(0, 1) | 905 selectedRange:NSMakeRange(0, 1) |
| 884 replacementRange:NSMakeRange(3, 1)]; | 906 replacementRange:NSMakeRange(3, 1)]; |
| 885 [dummy_text_view_ setMarkedText:@"à" | 907 [dummy_text_view_ setMarkedText:@"à" |
| 886 selectedRange:NSMakeRange(0, 1) | 908 selectedRange:NSMakeRange(0, 1) |
| 887 replacementRange:NSMakeRange(3, 1)]; | 909 replacementRange:NSMakeRange(3, 1)]; |
| 888 EXPECT_EQ_3(YES, [dummy_text_view_ hasMarkedText], [ns_view_ hasMarkedText]); | 910 EXPECT_EQ_3(YES, [dummy_text_view_ hasMarkedText], [ns_view_ hasMarkedText]); |
| 889 EXPECT_EQ_RANGE_3(NSMakeRange(3, 1), [dummy_text_view_ markedRange], | 911 EXPECT_EQ_RANGE_3(NSMakeRange(3, 1), [dummy_text_view_ markedRange], |
| 890 [ns_view_ markedRange]); | 912 [ns_view_ markedRange]); |
| 891 EXPECT_EQ_RANGE_3(NSMakeRange(3, 1), GetExpectedSelectionRange(), | 913 EXPECT_EQ_RANGE_3(NSMakeRange(3, 1), GetExpectedSelectionRange(), |
| 892 GetActualSelectionRange()); | 914 GetActualSelectionRange()); |
| 893 EXPECT_NSEQ_3(@"abcà", GetExpectedText(), GetActualText()); | 915 EXPECT_NSEQ_3(@"abcà", GetExpectedText(), GetActualText()); |
| 916 | |
| 917 // On pressing enter, the marked text is confirmed. | |
| 918 [ns_view_ setKeyDownEvent:cocoa_test_event_utils::SynthesizeKeyEvent( | |
| 919 widget_->GetNativeWindow(), true, | |
| 920 ui::VKEY_RETURN, 0)]; | |
| 921 [ns_view_ insertText:@"à" replacementRange:EmptyRange()]; | |
| 922 [dummy_text_view_ insertText:@"à" replacementRange:EmptyRange()]; | |
| 923 EXPECT_EQ_3(NO, [dummy_text_view_ hasMarkedText], [ns_view_ hasMarkedText]); | |
| 924 EXPECT_EQ_RANGE_3(NSMakeRange(4, 0), GetExpectedSelectionRange(), | |
| 925 GetActualSelectionRange()); | |
| 926 EXPECT_NSEQ_3(@"abcà", GetExpectedText(), GetActualText()); | |
| 894 } | 927 } |
| 895 | 928 |
| 896 // Test moving the caret left and right using text input protocol. | 929 // Test moving the caret left and right using text input protocol. |
| 897 TEST_F(BridgedNativeWidgetTest, TextInput_MoveLeftRight) { | 930 TEST_F(BridgedNativeWidgetTest, TextInput_MoveLeftRight) { |
| 898 InstallTextField("foo"); | 931 InstallTextField("foo"); |
| 899 EXPECT_EQ_RANGE_3(NSMakeRange(3, 0), GetExpectedSelectionRange(), | 932 EXPECT_EQ_RANGE_3(NSMakeRange(3, 0), GetExpectedSelectionRange(), |
| 900 GetActualSelectionRange()); | 933 GetActualSelectionRange()); |
| 901 | 934 |
| 902 // Move right not allowed, out of range. | 935 // Move right not allowed, out of range. |
| 903 PerformCommand(@selector(moveRight:)); | 936 PerformCommand(@selector(moveRight:)); |
| (...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1226 [center postNotificationName:NSWindowDidExitFullScreenNotification | 1259 [center postNotificationName:NSWindowDidExitFullScreenNotification |
| 1227 object:window]; | 1260 object:window]; |
| 1228 EXPECT_EQ(1, [window ignoredToggleFullScreenCount]); // No change. | 1261 EXPECT_EQ(1, [window ignoredToggleFullScreenCount]); // No change. |
| 1229 EXPECT_FALSE(bridge()->target_fullscreen_state()); | 1262 EXPECT_FALSE(bridge()->target_fullscreen_state()); |
| 1230 | 1263 |
| 1231 widget_->CloseNow(); | 1264 widget_->CloseNow(); |
| 1232 } | 1265 } |
| 1233 | 1266 |
| 1234 } // namespace test | 1267 } // namespace test |
| 1235 } // namespace views | 1268 } // namespace views |
| OLD | NEW |