Chromium Code Reviews| Index: content/renderer/render_widget_browsertest.cc |
| diff --git a/content/renderer/render_widget_browsertest.cc b/content/renderer/render_widget_browsertest.cc |
| index ecf35426f7df016cfc0e353bc6f133ef7a432bdb..45bffdd08dd3413f34d974829af2508b2441df5d 100644 |
| --- a/content/renderer/render_widget_browsertest.cc |
| +++ b/content/renderer/render_widget_browsertest.cc |
| @@ -2,12 +2,14 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| +#include "base/strings/utf_string_conversions.h" |
| #include "content/common/resize_params.h" |
| #include "content/public/test/render_view_test.h" |
| #include "content/renderer/render_view_impl.h" |
| #include "content/renderer/render_widget.h" |
| #include "third_party/WebKit/public/web/WebFrameWidget.h" |
| #include "third_party/WebKit/public/web/WebInputMethodController.h" |
| +#include "ui/base/ime/text_input_type.h" |
| namespace content { |
| @@ -28,6 +30,19 @@ class RenderWidgetTest : public RenderViewTest { |
| bool next_paint_is_resize_ack() { |
| return widget()->next_paint_is_resize_ack(); |
| } |
| + |
| + blink::WebInputMethodController* GetInputMethodController() { |
| + return widget()->GetInputMethodController(); |
| + } |
| + |
| + void CommitText(std::string text) { |
| + widget()->OnImeCommitText(base::UTF8ToUTF16(text), |
| + gfx::Range::InvalidRange(), 0); |
| + } |
| + |
| + ui::TextInputType GetTextInputType() { return widget()->GetTextInputType(); } |
| + |
| + void SetFocus(bool focused) { widget()->OnSetFocus(focused); } |
| }; |
| TEST_F(RenderWidgetTest, OnResize) { |
| @@ -141,4 +156,51 @@ TEST_F(RenderWidgetTest, GetCompositionRangeInvalid) { |
| EXPECT_FALSE(range.IsValid()); |
| } |
| +// This test verifies that WebInputMethodController always exists as long as |
| +// there is a focused frame inside the page, but, IME events are only executed |
| +// if there is also page focus. |
| +TEST_F(RenderWidgetTest, PageFocusIme) { |
| + LoadHTML( |
| + "<input/>" |
| + " <script> document.querySelector('input').focus(); </script>"); |
| + |
| + // Give initial focus to the widget. |
| + SetFocus(true); |
| + |
| + // We must have an active WebInputMethodController. |
| + EXPECT_TRUE(GetInputMethodController()); |
| + |
| + // Verify the text input type. |
| + EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, GetTextInputType()); |
| + |
| + // Commit some text. |
| + std::string text = "hello"; |
| + CommitText(text); |
| + |
| + // The text should be committed since there is page focus in the beginning. |
| + EXPECT_EQ(text, GetInputMethodController()->textInputInfo().value.utf8()); |
| + |
| + // Drop focus. |
| + SetFocus(false); |
| + |
| + // We must still have an active WebInputMethodController. |
| + EXPECT_TRUE(GetInputMethodController()); |
| + |
| + // The text input type should not change. |
| + EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, GetTextInputType()); |
| + |
| + // Commit the text again. |
| + text = " world"; |
| + CommitText(text); |
| + |
| + // This time is should not work since |m_imeAcceptEvents| is not set. |
| + EXPECT_EQ("hello", GetInputMethodController()->textInputInfo().value.utf8()); |
| + |
| + // No give focus back again and commit text. |
|
wjmaclean
2017/01/05 21:24:57
s/No/Now/ ?
EhsanK
2017/01/05 21:46:43
Now. Done. Thanks!
|
| + SetFocus(true); |
| + CommitText(text); |
| + EXPECT_EQ("hello world", |
| + GetInputMethodController()->textInputInfo().value.utf8()); |
| +} |
| + |
| } // namespace content |