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

Unified Diff: content/renderer/render_widget_browsertest.cc

Issue 2608293002: [reland, refactor] - Move textInputInfo() and textInputType() from WebWidget to WebInputMethodContr… (Closed)
Patch Set: Addressing wjmaclean@'s comments Created 3 years, 11 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 | « content/renderer/render_widget.cc ('k') | third_party/WebKit/Source/web/WebFrameWidgetImpl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..e01bab1cdf84d35c7bb62fb3a2f1e44f7fa5b359 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());
+
+ // Now give focus back again and commit text.
+ SetFocus(true);
+ CommitText(text);
+ EXPECT_EQ("hello world",
+ GetInputMethodController()->textInputInfo().value.utf8());
+}
+
} // namespace content
« no previous file with comments | « content/renderer/render_widget.cc ('k') | third_party/WebKit/Source/web/WebFrameWidgetImpl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698