Commit ff3c1bc9 authored by Shu Chen's avatar Shu Chen Committed by Commit Bot

Removes the ash dependency in TextInputTestHelper.

Bug: 756059
Change-Id: Ieeea588c60e51a95cf89f86ee13cc77b2eba3883
Reviewed-on: https://chromium-review.googlesource.com/1179114
Commit-Queue: Shu Chen <shuchen@chromium.org>
Reviewed-by: default avatarJames Cook <jamescook@chromium.org>
Cr-Commit-Position: refs/heads/master@{#584287}
parent 8482b53d
...@@ -29,7 +29,7 @@ typedef TextInputTestBase TextInput_TextInputStateChangedTest; ...@@ -29,7 +29,7 @@ typedef TextInputTestBase TextInput_TextInputStateChangedTest;
IN_PROC_BROWSER_TEST_F(TextInput_TextInputStateChangedTest, IN_PROC_BROWSER_TEST_F(TextInput_TextInputStateChangedTest,
SwitchToPasswordFieldTest) { SwitchToPasswordFieldTest) {
TextInputTestHelper helper; TextInputTestHelper helper(GetInputMethod());
GURL url = ui_test_utils::GetTestUrl( GURL url = ui_test_utils::GetTestUrl(
base::FilePath(FILE_PATH_LITERAL("textinput")), base::FilePath(FILE_PATH_LITERAL("textinput")),
base::FilePath(FILE_PATH_LITERAL("ime_enable_disable_test.html"))); base::FilePath(FILE_PATH_LITERAL("ime_enable_disable_test.html")));
...@@ -59,7 +59,7 @@ IN_PROC_BROWSER_TEST_F(TextInput_TextInputStateChangedTest, ...@@ -59,7 +59,7 @@ IN_PROC_BROWSER_TEST_F(TextInput_TextInputStateChangedTest,
} }
IN_PROC_BROWSER_TEST_F(TextInput_TextInputStateChangedTest, FocusOnLoadTest) { IN_PROC_BROWSER_TEST_F(TextInput_TextInputStateChangedTest, FocusOnLoadTest) {
TextInputTestHelper helper; TextInputTestHelper helper(GetInputMethod());
EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE, helper.GetTextInputType()); EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE, helper.GetTextInputType());
GURL url = ui_test_utils::GetTestUrl( GURL url = ui_test_utils::GetTestUrl(
...@@ -73,7 +73,7 @@ IN_PROC_BROWSER_TEST_F(TextInput_TextInputStateChangedTest, FocusOnLoadTest) { ...@@ -73,7 +73,7 @@ IN_PROC_BROWSER_TEST_F(TextInput_TextInputStateChangedTest, FocusOnLoadTest) {
IN_PROC_BROWSER_TEST_F(TextInput_TextInputStateChangedTest, IN_PROC_BROWSER_TEST_F(TextInput_TextInputStateChangedTest,
FocusOnContentJSTest) { FocusOnContentJSTest) {
TextInputTestHelper helper; TextInputTestHelper helper(GetInputMethod());
EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE, helper.GetTextInputType()); EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE, helper.GetTextInputType());
GURL url = ui_test_utils::GetTestUrl( GURL url = ui_test_utils::GetTestUrl(
...@@ -87,7 +87,7 @@ IN_PROC_BROWSER_TEST_F(TextInput_TextInputStateChangedTest, ...@@ -87,7 +87,7 @@ IN_PROC_BROWSER_TEST_F(TextInput_TextInputStateChangedTest,
IN_PROC_BROWSER_TEST_F(TextInput_TextInputStateChangedTest, IN_PROC_BROWSER_TEST_F(TextInput_TextInputStateChangedTest,
MouseClickChange) { MouseClickChange) {
TextInputTestHelper helper; TextInputTestHelper helper(GetInputMethod());
EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE, helper.GetTextInputType()); EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE, helper.GetTextInputType());
GURL url = ui_test_utils::GetTestUrl( GURL url = ui_test_utils::GetTestUrl(
...@@ -112,7 +112,7 @@ IN_PROC_BROWSER_TEST_F(TextInput_TextInputStateChangedTest, ...@@ -112,7 +112,7 @@ IN_PROC_BROWSER_TEST_F(TextInput_TextInputStateChangedTest,
IN_PROC_BROWSER_TEST_F(TextInput_TextInputStateChangedTest, IN_PROC_BROWSER_TEST_F(TextInput_TextInputStateChangedTest,
FocusChangeOnFocus) { FocusChangeOnFocus) {
TextInputTestHelper helper; TextInputTestHelper helper(GetInputMethod());
EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE, helper.GetTextInputType()); EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE, helper.GetTextInputType());
GURL url = ui_test_utils::GetTestUrl( GURL url = ui_test_utils::GetTestUrl(
...@@ -144,7 +144,7 @@ IN_PROC_BROWSER_TEST_F(TextInput_TextInputStateChangedTest, ...@@ -144,7 +144,7 @@ IN_PROC_BROWSER_TEST_F(TextInput_TextInputStateChangedTest,
IN_PROC_BROWSER_TEST_F(TextInput_TextInputStateChangedTest, IN_PROC_BROWSER_TEST_F(TextInput_TextInputStateChangedTest,
NodeEliminationCase) { NodeEliminationCase) {
TextInputTestHelper helper; TextInputTestHelper helper(GetInputMethod());
EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE, helper.GetTextInputType()); EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE, helper.GetTextInputType());
GURL url = ui_test_utils::GetTestUrl( GURL url = ui_test_utils::GetTestUrl(
...@@ -173,7 +173,7 @@ IN_PROC_BROWSER_TEST_F(TextInput_TextInputStateChangedTest, ...@@ -173,7 +173,7 @@ IN_PROC_BROWSER_TEST_F(TextInput_TextInputStateChangedTest,
IN_PROC_BROWSER_TEST_F(TextInput_TextInputStateChangedTest, IN_PROC_BROWSER_TEST_F(TextInput_TextInputStateChangedTest,
TextInputTypeChangedByJavaScript) { TextInputTypeChangedByJavaScript) {
TextInputTestHelper helper; TextInputTestHelper helper(GetInputMethod());
EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE, helper.GetTextInputType()); EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE, helper.GetTextInputType());
GURL url = ui_test_utils::GetTestUrl( GURL url = ui_test_utils::GetTestUrl(
...@@ -202,7 +202,7 @@ IN_PROC_BROWSER_TEST_F(TextInput_TextInputStateChangedTest, ...@@ -202,7 +202,7 @@ IN_PROC_BROWSER_TEST_F(TextInput_TextInputStateChangedTest,
IN_PROC_BROWSER_TEST_F(TextInput_TextInputStateChangedTest, IN_PROC_BROWSER_TEST_F(TextInput_TextInputStateChangedTest,
ChangingToContentEditableCase) { ChangingToContentEditableCase) {
TextInputTestHelper helper; TextInputTestHelper helper(GetInputMethod());
EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE, helper.GetTextInputType()); EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE, helper.GetTextInputType());
GURL url = ui_test_utils::GetTestUrl( GURL url = ui_test_utils::GetTestUrl(
...@@ -234,7 +234,7 @@ IN_PROC_BROWSER_TEST_F(TextInput_TextInputStateChangedTest, ...@@ -234,7 +234,7 @@ IN_PROC_BROWSER_TEST_F(TextInput_TextInputStateChangedTest,
IN_PROC_BROWSER_TEST_F(TextInput_TextInputStateChangedTest, IN_PROC_BROWSER_TEST_F(TextInput_TextInputStateChangedTest,
DISABLED_SwitchingAllTextInputTest) { DISABLED_SwitchingAllTextInputTest) {
TextInputTestHelper helper; TextInputTestHelper helper(GetInputMethod());
EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE, helper.GetTextInputType()); EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE, helper.GetTextInputType());
GURL url = ui_test_utils::GetTestUrl( GURL url = ui_test_utils::GetTestUrl(
...@@ -275,7 +275,7 @@ IN_PROC_BROWSER_TEST_F(TextInput_TextInputStateChangedTest, ...@@ -275,7 +275,7 @@ IN_PROC_BROWSER_TEST_F(TextInput_TextInputStateChangedTest,
// Flaky on chromeos. http://crbug.com/391582 // Flaky on chromeos. http://crbug.com/391582
IN_PROC_BROWSER_TEST_F(TextInput_TextInputStateChangedTest, IN_PROC_BROWSER_TEST_F(TextInput_TextInputStateChangedTest,
DISABLED_OpenNewTabOnloadTest) { DISABLED_OpenNewTabOnloadTest) {
TextInputTestHelper helper; TextInputTestHelper helper(GetInputMethod());
EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE, helper.GetTextInputType()); EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE, helper.GetTextInputType());
GURL base_url = ui_test_utils::GetTestUrl( GURL base_url = ui_test_utils::GetTestUrl(
......
...@@ -17,7 +17,7 @@ typedef TextInputTestBase TextInput_SurroundingTextChangedTest; ...@@ -17,7 +17,7 @@ typedef TextInputTestBase TextInput_SurroundingTextChangedTest;
IN_PROC_BROWSER_TEST_F(TextInput_SurroundingTextChangedTest, IN_PROC_BROWSER_TEST_F(TextInput_SurroundingTextChangedTest,
SurroundingTextChangedWithInsertText) { SurroundingTextChangedWithInsertText) {
TextInputTestHelper helper; TextInputTestHelper helper(GetInputMethod());
GURL url = ui_test_utils::GetTestUrl( GURL url = ui_test_utils::GetTestUrl(
base::FilePath(FILE_PATH_LITERAL("textinput")), base::FilePath(FILE_PATH_LITERAL("textinput")),
base::FilePath(FILE_PATH_LITERAL("simple_textarea.html"))); base::FilePath(FILE_PATH_LITERAL("simple_textarea.html")));
...@@ -54,7 +54,7 @@ IN_PROC_BROWSER_TEST_F(TextInput_SurroundingTextChangedTest, ...@@ -54,7 +54,7 @@ IN_PROC_BROWSER_TEST_F(TextInput_SurroundingTextChangedTest,
IN_PROC_BROWSER_TEST_F(TextInput_SurroundingTextChangedTest, IN_PROC_BROWSER_TEST_F(TextInput_SurroundingTextChangedTest,
SurroundingTextChangedWithComposition) { SurroundingTextChangedWithComposition) {
TextInputTestHelper helper; TextInputTestHelper helper(GetInputMethod());
GURL url = ui_test_utils::GetTestUrl( GURL url = ui_test_utils::GetTestUrl(
base::FilePath(FILE_PATH_LITERAL("textinput")), base::FilePath(FILE_PATH_LITERAL("textinput")),
base::FilePath(FILE_PATH_LITERAL("simple_textarea.html"))); base::FilePath(FILE_PATH_LITERAL("simple_textarea.html")));
...@@ -93,7 +93,7 @@ IN_PROC_BROWSER_TEST_F(TextInput_SurroundingTextChangedTest, ...@@ -93,7 +93,7 @@ IN_PROC_BROWSER_TEST_F(TextInput_SurroundingTextChangedTest,
IN_PROC_BROWSER_TEST_F(TextInput_SurroundingTextChangedTest, IN_PROC_BROWSER_TEST_F(TextInput_SurroundingTextChangedTest,
FocusToTextContainingTextAreaByClickingCase) { FocusToTextContainingTextAreaByClickingCase) {
TextInputTestHelper helper; TextInputTestHelper helper(GetInputMethod());
GURL url = ui_test_utils::GetTestUrl( GURL url = ui_test_utils::GetTestUrl(
base::FilePath(FILE_PATH_LITERAL("textinput")), base::FilePath(FILE_PATH_LITERAL("textinput")),
base::FilePath(FILE_PATH_LITERAL("textarea_with_preset_text.html"))); base::FilePath(FILE_PATH_LITERAL("textarea_with_preset_text.html")));
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/threading/platform_thread.h" #include "base/threading/platform_thread.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/test/base/interactive_test_utils.h" #include "chrome/test/base/interactive_test_utils.h"
#include "content/public/browser/render_view_host.h" #include "content/public/browser/render_view_host.h"
#include "content/public/browser/render_widget_host.h" #include "content/public/browser/render_widget_host.h"
...@@ -21,29 +22,26 @@ ...@@ -21,29 +22,26 @@
#include "ui/base/ime/input_method_factory.h" #include "ui/base/ime/input_method_factory.h"
namespace chromeos { namespace chromeos {
namespace {
ui::MockInputMethod* GetInputMethod() {
ui::MockInputMethod* input_method = static_cast<ui::MockInputMethod*>(
ash::Shell::GetPrimaryRootWindow()->GetHost()->GetInputMethod());
CHECK(input_method);
return input_method;
}
} // namespace
void TextInputTestBase::SetUpInProcessBrowserTestFixture() { void TextInputTestBase::SetUpInProcessBrowserTestFixture() {
ui::SetUpInputMethodFactoryForTesting(); ui::SetUpInputMethodFactoryForTesting();
} }
TextInputTestHelper::TextInputTestHelper() ui::InputMethod* TextInputTestBase::GetInputMethod() const {
: waiting_type_(NO_WAIT), return browser()->window()->GetNativeWindow()->GetHost()->GetInputMethod();
selection_range_(gfx::Range::InvalidRange()), }
focus_state_(false),
latest_text_input_type_(ui::TEXT_INPUT_TYPE_NONE) { TextInputTestHelper::TextInputTestHelper(ui::InputMethod* input_method)
GetInputMethod()->AddObserver(this); : waiting_type_(NO_WAIT),
selection_range_(gfx::Range::InvalidRange()),
focus_state_(false),
latest_text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
input_method_(input_method) {
input_method_->AddObserver(this);
} }
TextInputTestHelper::~TextInputTestHelper() { TextInputTestHelper::~TextInputTestHelper() {
GetInputMethod()->RemoveObserver(this); input_method_->RemoveObserver(this);
} }
base::string16 TextInputTestHelper::GetSurroundingText() const { base::string16 TextInputTestHelper::GetSurroundingText() const {
...@@ -71,7 +69,7 @@ ui::TextInputType TextInputTestHelper::GetTextInputType() const { ...@@ -71,7 +69,7 @@ ui::TextInputType TextInputTestHelper::GetTextInputType() const {
} }
ui::TextInputClient* TextInputTestHelper::GetTextInputClient() const { ui::TextInputClient* TextInputTestHelper::GetTextInputClient() const {
return GetInputMethod()->GetTextInputClient(); return input_method_->GetTextInputClient();
} }
void TextInputTestHelper::OnShowVirtualKeyboardIfEnabled() {} void TextInputTestHelper::OnShowVirtualKeyboardIfEnabled() {}
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "chrome/test/base/in_process_browser_test.h" #include "chrome/test/base/in_process_browser_test.h"
#include "ui/base/ime/input_method.h"
#include "ui/base/ime/mock_input_method.h" #include "ui/base/ime/mock_input_method.h"
#include "ui/base/ime/text_input_client.h" #include "ui/base/ime/text_input_client.h"
#include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect.h"
...@@ -26,6 +27,8 @@ class TextInputTestBase : public InProcessBrowserTest { ...@@ -26,6 +27,8 @@ class TextInputTestBase : public InProcessBrowserTest {
void SetUpInProcessBrowserTestFixture() override; void SetUpInProcessBrowserTestFixture() override;
ui::InputMethod* GetInputMethod() const;
private: private:
DISALLOW_COPY_AND_ASSIGN(TextInputTestBase); DISALLOW_COPY_AND_ASSIGN(TextInputTestBase);
}; };
...@@ -33,7 +36,7 @@ class TextInputTestBase : public InProcessBrowserTest { ...@@ -33,7 +36,7 @@ class TextInputTestBase : public InProcessBrowserTest {
// Provides text input test utilities. // Provides text input test utilities.
class TextInputTestHelper : public ui::InputMethodObserver { class TextInputTestHelper : public ui::InputMethodObserver {
public: public:
TextInputTestHelper(); explicit TextInputTestHelper(ui::InputMethod* input_method);
~TextInputTestHelper() override; ~TextInputTestHelper() override;
// Returns the latest status notified to ui::InputMethod // Returns the latest status notified to ui::InputMethod
...@@ -91,6 +94,7 @@ class TextInputTestHelper : public ui::InputMethodObserver { ...@@ -91,6 +94,7 @@ class TextInputTestHelper : public ui::InputMethodObserver {
gfx::Range selection_range_; gfx::Range selection_range_;
bool focus_state_; bool focus_state_;
ui::TextInputType latest_text_input_type_; ui::TextInputType latest_text_input_type_;
ui::InputMethod* input_method_;
DISALLOW_COPY_AND_ASSIGN(TextInputTestHelper); DISALLOW_COPY_AND_ASSIGN(TextInputTestHelper);
}; };
......
...@@ -47,7 +47,7 @@ void ClickElementWithId(content::WebContents* web_contents, ...@@ -47,7 +47,7 @@ void ClickElementWithId(content::WebContents* web_contents,
namespace keyboard { namespace keyboard {
class KeyboardEndToEndTest : public InProcessBrowserTest { class KeyboardEndToEndTest : public chromeos::TextInputTestBase {
public: public:
KeyboardEndToEndTest() {} KeyboardEndToEndTest() {}
~KeyboardEndToEndTest() override {} ~KeyboardEndToEndTest() override {}
...@@ -91,7 +91,7 @@ IN_PROC_BROWSER_TEST_F(KeyboardEndToEndTest, OpenOnlyOnSyncFocus) { ...@@ -91,7 +91,7 @@ IN_PROC_BROWSER_TEST_F(KeyboardEndToEndTest, OpenOnlyOnSyncFocus) {
auto* controller = keyboard::KeyboardController::Get(); auto* controller = keyboard::KeyboardController::Get();
EXPECT_FALSE(IsKeyboardVisible()); EXPECT_FALSE(IsKeyboardVisible());
chromeos::TextInputTestHelper helper; chromeos::TextInputTestHelper helper(GetInputMethod());
ClickElementWithId(web_contents, "blur"); ClickElementWithId(web_contents, "blur");
helper.WaitForTextInputStateChanged(ui::TEXT_INPUT_TYPE_NONE); helper.WaitForTextInputStateChanged(ui::TEXT_INPUT_TYPE_NONE);
......
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