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

Unified Diff: ui/views/cocoa/bridged_native_widget_unittest.mm

Issue 2180873002: MacViews: Change insertTextInternal to correctly handle IME character input. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix compile. 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/views/cocoa/bridged_content_view.mm ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/cocoa/bridged_native_widget_unittest.mm
diff --git a/ui/views/cocoa/bridged_native_widget_unittest.mm b/ui/views/cocoa/bridged_native_widget_unittest.mm
index 6977ee80215d93ae4939a9767f33e1623d5f3703..200006c2c8666f1b911305ecfd003e6a0d9cb67a 100644
--- a/ui/views/cocoa/bridged_native_widget_unittest.mm
+++ b/ui/views/cocoa/bridged_native_widget_unittest.mm
@@ -19,6 +19,7 @@
#import "testing/gtest_mac.h"
#import "ui/base/cocoa/window_size_constants.h"
#include "ui/base/ime/input_method.h"
+#include "ui/events/test/cocoa_test_event_utils.h"
#import "ui/gfx/mac/coordinate_conversion.h"
#import "ui/gfx/test/ui_cocoa_test_helper.h"
#import "ui/views/cocoa/bridged_content_view.h"
@@ -191,6 +192,20 @@ - (void)toggleFullScreen:(id)sender {
@end
+// A category on BridgedContentView to set the private |keyDownEvent_| variable
+// for tests.
+@interface BridgedContentView (Test)
+- (void)setKeyDownEvent:(NSEvent*)event;
+@end
+
+@implementation BridgedContentView (Test)
+
+- (void)setKeyDownEvent:(NSEvent*)event {
+ [self setValue:event forKey:@"keyDownEvent_"];
karandeepb 2016/07/27 04:47:32 On my workstation, even directly modifying keyDown
+}
+
+@end
+
namespace views {
namespace test {
@@ -868,9 +883,13 @@ void PerformInit() {
InstallTextField("abc");
// Simulate action messages generated when the key 'a' is pressed repeatedly
- // and leads to the showing of an IME candidate window.
+ // and leads to the showing of an IME candidate window. To simulate an event,
+ // set the private keyDownEvent field on the BridgedContentView.
// First an insertText: message with key 'a' is generated.
+ [ns_view_
+ setKeyDownEvent:cocoa_test_event_utils::SynthesizeKeyEvent(
+ widget_->GetNativeWindow(), true, ui::VKEY_A, 0)];
[ns_view_ insertText:@"a" replacementRange:EmptyRange()];
[dummy_text_view_ insertText:@"a" replacementRange:EmptyRange()];
EXPECT_EQ_3(NO, [dummy_text_view_ hasMarkedText], [ns_view_ hasMarkedText]);
@@ -879,6 +898,9 @@ void PerformInit() {
// Next the IME popup appears. On selecting the accented character using arrow
// keys, setMarkedText action message is generated which replaces the earlier
// inserted 'a'.
+ [ns_view_
+ setKeyDownEvent:cocoa_test_event_utils::SynthesizeKeyEvent(
+ widget_->GetNativeWindow(), true, ui::VKEY_RIGHT, 0)];
[ns_view_ setMarkedText:@"à"
selectedRange:NSMakeRange(0, 1)
replacementRange:NSMakeRange(3, 1)];
@@ -891,6 +913,17 @@ void PerformInit() {
EXPECT_EQ_RANGE_3(NSMakeRange(3, 1), GetExpectedSelectionRange(),
GetActualSelectionRange());
EXPECT_NSEQ_3(@"abcà", GetExpectedText(), GetActualText());
+
+ // On pressing enter, the marked text is confirmed.
+ [ns_view_ setKeyDownEvent:cocoa_test_event_utils::SynthesizeKeyEvent(
+ widget_->GetNativeWindow(), true,
+ ui::VKEY_RETURN, 0)];
+ [ns_view_ insertText:@"à" replacementRange:EmptyRange()];
+ [dummy_text_view_ insertText:@"à" replacementRange:EmptyRange()];
+ EXPECT_EQ_3(NO, [dummy_text_view_ hasMarkedText], [ns_view_ hasMarkedText]);
+ EXPECT_EQ_RANGE_3(NSMakeRange(4, 0), GetExpectedSelectionRange(),
+ GetActualSelectionRange());
+ EXPECT_NSEQ_3(@"abcà", GetExpectedText(), GetActualText());
}
// Test moving the caret left and right using text input protocol.
« 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