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

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

Issue 941943003: MacViews: Allow the BridgedNativeWidgetTest to focus its textfield (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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 | « no previous file | 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 0ca3ec10dd4f3df7c4c5dd943ec65b87e514ba39..72bcae623fd121a4fec9f3274244e433e891eb9a 100644
--- a/ui/views/cocoa/bridged_native_widget_unittest.mm
+++ b/ui/views/cocoa/bridged_native_widget_unittest.mm
@@ -84,6 +84,9 @@ class MockNativeWidgetMac : public NativeWidgetMac {
// Usually the bridge gets initialized here. It is skipped to run extra
// checks in tests, and so that a second window isn't created.
delegate()->OnNativeWidgetCreated(true);
+
+ // To allow events to dispatch to a view, it needs a way to get focus.
+ bridge_->SetFocusManager(GetWidget()->GetFocusManager());
}
void ReorderNativeViews() override {
@@ -150,6 +153,7 @@ class BridgedNativeWidgetTest : public BridgedNativeWidgetTestBase {
scoped_ptr<views::View> view_;
scoped_ptr<BridgedNativeWidget> bridge_;
BridgedContentView* ns_view_; // Weak. Owned by bridge_.
+ base::MessageLoopForUI message_loop_;
private:
DISALLOW_COPY_AND_ASSIGN(BridgedNativeWidgetTest);
@@ -165,6 +169,12 @@ void BridgedNativeWidgetTest::InstallTextField(const std::string& text) {
Textfield* textfield = new Textfield();
textfield->SetText(ASCIIToUTF16(text));
view_->AddChildView(textfield);
+
+ // Request focus so the InputMethod can dispatch events to the RootView, and
+ // have them delivered to the textfield. Note that focusing a textfield
+ // schedules a task to flash the cursor, so this requires |message_loop_|.
+ textfield->RequestFocus();
+
[ns_view_ setTextInputClient:textfield];
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698