Commit 6d2b3324 authored by tapted's avatar tapted Committed by Commit bot

MacViews: Allow the BridgedNativeWidgetTest to focus its textfield

Some tests regressed in r316774 because the way edit commands were
dispatched in BridgedContentView changed from going directly to the
TextInputClient to instead go through the InputMethod.

r316774 included a check added to views::Textfield to ensure any
scheduled edit command had been processed before scheduling a new one.
Some tests failed that check: Because the textfield did not have focus,
the dispatch of the event that would commit the edit command was not
being received.

This CL ensures the textfield requests focus in the test.

Fixes (mac-only) views_unittests:
BridgedNativeWidgetTest.TextInput_MoveLeftRight
BridgedNativeWidgetTest.TextInput_DeleteBackward
BridgedNativeWidgetTest.TextInput_DeleteForward

BUG=454353

Review URL: https://codereview.chromium.org/941943003

Cr-Commit-Position: refs/heads/master@{#317715}
parent c3273cc9
......@@ -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];
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment