Commit ef2500c5 authored by Yuichiro Hanada's avatar Yuichiro Hanada Committed by Commit Bot

Introduce ScopedTestInputMethodFactory class.

to make it easier to clean up the environment.

Bug: 994083
Test: exo_unittests keyboard_unittests
Change-Id: I90c24548ef3a49a1ed783645dee8c168451b147c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1761881
Commit-Queue: Yuichiro Hanada <yhanada@chromium.org>
Reviewed-by: default avatarShu Chen <shuchen@chromium.org>
Reviewed-by: default avatarMitsuru Oshima <oshima@chromium.org>
Cr-Commit-Position: refs/heads/master@{#692396}
parent 4ad2798e
...@@ -146,7 +146,6 @@ class KeyboardUIControllerTest : public aura::test::AuraTestBase, ...@@ -146,7 +146,6 @@ class KeyboardUIControllerTest : public aura::test::AuraTestBase,
~KeyboardUIControllerTest() override = default; ~KeyboardUIControllerTest() override = default;
void SetUp() override { void SetUp() override {
ui::SetUpInputMethodFactoryForTesting();
aura::test::AuraTestBase::SetUp(); aura::test::AuraTestBase::SetUp();
new wm::DefaultActivationClient(root_window()); new wm::DefaultActivationClient(root_window());
focus_controller_ = std::make_unique<TestFocusController>(root_window()); focus_controller_ = std::make_unique<TestFocusController>(root_window());
...@@ -272,6 +271,7 @@ class KeyboardUIControllerTest : public aura::test::AuraTestBase, ...@@ -272,6 +271,7 @@ class KeyboardUIControllerTest : public aura::test::AuraTestBase,
std::unique_ptr<ui::TextInputClient> test_text_input_client_; std::unique_ptr<ui::TextInputClient> test_text_input_client_;
bool keyboard_disabled_ = false; bool keyboard_disabled_ = false;
wm::DefaultScreenPositionClient screen_position_client_; wm::DefaultScreenPositionClient screen_position_client_;
ui::ScopedTestInputMethodFactory scoped_test_input_method_factory_;
DISALLOW_COPY_AND_ASSIGN(KeyboardUIControllerTest); DISALLOW_COPY_AND_ASSIGN(KeyboardUIControllerTest);
}; };
......
...@@ -24,9 +24,8 @@ ...@@ -24,9 +24,8 @@
namespace chromeos { namespace chromeos {
void TextInputTestBase::SetUpInProcessBrowserTestFixture() { TextInputTestBase::TextInputTestBase() = default;
ui::SetUpInputMethodFactoryForTesting(); TextInputTestBase::~TextInputTestBase() = default;
}
ui::InputMethod* TextInputTestBase::GetInputMethod() const { ui::InputMethod* TextInputTestBase::GetInputMethod() const {
return browser()->window()->GetNativeWindow()->GetHost()->GetInputMethod(); return browser()->window()->GetNativeWindow()->GetHost()->GetInputMethod();
......
...@@ -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/init/input_method_factory.h"
#include "ui/base/ime/input_method.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"
...@@ -22,14 +23,14 @@ namespace chromeos { ...@@ -22,14 +23,14 @@ namespace chromeos {
// The base class of text input testing. // The base class of text input testing.
class TextInputTestBase : public InProcessBrowserTest { class TextInputTestBase : public InProcessBrowserTest {
public: public:
TextInputTestBase() {} TextInputTestBase();
~TextInputTestBase() override {} ~TextInputTestBase() override;
void SetUpInProcessBrowserTestFixture() override;
ui::InputMethod* GetInputMethod() const; ui::InputMethod* GetInputMethod() const;
private: private:
ui::ScopedTestInputMethodFactory scoped_test_input_method_factory_;
DISALLOW_COPY_AND_ASSIGN(TextInputTestBase); DISALLOW_COPY_AND_ASSIGN(TextInputTestBase);
}; };
......
...@@ -126,7 +126,6 @@ class KeyboardControllerWebContentTest : public InProcessBrowserTest { ...@@ -126,7 +126,6 @@ class KeyboardControllerWebContentTest : public InProcessBrowserTest {
~KeyboardControllerWebContentTest() override {} ~KeyboardControllerWebContentTest() override {}
void SetUp() override { void SetUp() override {
ui::SetUpInputMethodFactoryForTesting();
InProcessBrowserTest::SetUp(); InProcessBrowserTest::SetUp();
} }
...@@ -170,6 +169,7 @@ class KeyboardControllerWebContentTest : public InProcessBrowserTest { ...@@ -170,6 +169,7 @@ class KeyboardControllerWebContentTest : public InProcessBrowserTest {
private: private:
std::unique_ptr<ui::DummyTextInputClient> client; std::unique_ptr<ui::DummyTextInputClient> client;
ui::ScopedTestInputMethodFactory scoped_test_input_method_factory_;
DISALLOW_COPY_AND_ASSIGN(KeyboardControllerWebContentTest); DISALLOW_COPY_AND_ASSIGN(KeyboardControllerWebContentTest);
}; };
......
...@@ -102,7 +102,6 @@ ExoTestBaseViews::ExoTestBaseViews() {} ...@@ -102,7 +102,6 @@ ExoTestBaseViews::ExoTestBaseViews() {}
ExoTestBaseViews::~ExoTestBaseViews() {} ExoTestBaseViews::~ExoTestBaseViews() {}
void ExoTestBaseViews::SetUp() { void ExoTestBaseViews::SetUp() {
ui::SetUpInputMethodFactoryForTesting();
views::ViewsTestBase::SetUp(); views::ViewsTestBase::SetUp();
// Takes care of its own lifetime. // Takes care of its own lifetime.
new wm::DefaultActivationClient(root_window()); new wm::DefaultActivationClient(root_window());
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#define COMPONENTS_EXO_TEST_EXO_TEST_BASE_VIEWS_H_ #define COMPONENTS_EXO_TEST_EXO_TEST_BASE_VIEWS_H_
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/ime/init/input_method_factory.h"
#include "ui/views/test/views_test_base.h" #include "ui/views/test/views_test_base.h"
namespace exo { namespace exo {
...@@ -27,6 +28,7 @@ class ExoTestBaseViews : public views::ViewsTestBase { ...@@ -27,6 +28,7 @@ class ExoTestBaseViews : public views::ViewsTestBase {
private: private:
std::unique_ptr<WMHelper> wm_helper_; std::unique_ptr<WMHelper> wm_helper_;
ui::ScopedTestInputMethodFactory scoped_test_input_method_factory_;
}; };
} // namespace test } // namespace test
......
...@@ -72,20 +72,27 @@ std::unique_ptr<InputMethod> CreateInputMethod( ...@@ -72,20 +72,27 @@ std::unique_ptr<InputMethod> CreateInputMethod(
#endif #endif
} }
void SetUpInputMethodFactoryForTesting() { void SetUpInputMethodForTesting(InputMethod* input_method) {
if (g_input_method_set_for_testing) g_input_method_for_testing = input_method;
return; }
CHECK(!g_create_input_method_called) ScopedTestInputMethodFactory::ScopedTestInputMethodFactory() {
<< "ui::SetUpInputMethodFactoryForTesting was called after use of " CHECK(!g_input_method_set_for_testing)
<< "ui::CreateInputMethod. You must call " << "ScopedTestInputMethodFactory was created after calling "
<< "ui::SetUpInputMethodFactoryForTesting earlier."; "ui::SetUpInputMethodFactoryForTesting or inside another "
"ScopedTestInputMethodFactory lifetime.";
DLOG_IF(WARNING, g_create_input_method_called)
<< "ui::CreateInputMethod was already called. That can happen when other "
"tests in the same process uses normal ui::InputMethod instance.";
g_input_method_set_for_testing = true; g_input_method_set_for_testing = true;
g_create_input_method_called = false;
} }
void SetUpInputMethodForTesting(InputMethod* input_method) { ScopedTestInputMethodFactory::~ScopedTestInputMethodFactory() {
g_input_method_for_testing = input_method; g_input_method_set_for_testing = false;
g_create_input_method_called = false;
} }
} // namespace ui } // namespace ui
...@@ -26,10 +26,18 @@ std::unique_ptr<InputMethod> CreateInputMethod( ...@@ -26,10 +26,18 @@ std::unique_ptr<InputMethod> CreateInputMethod(
gfx::AcceleratedWidget widget); gfx::AcceleratedWidget widget);
// Makes CreateInputMethod return a MockInputMethod. // Makes CreateInputMethod return a MockInputMethod.
COMPONENT_EXPORT(UI_BASE_IME_INIT) void SetUpInputMethodFactoryForTesting();
COMPONENT_EXPORT(UI_BASE_IME_INIT) COMPONENT_EXPORT(UI_BASE_IME_INIT)
void SetUpInputMethodForTesting(InputMethod* input_method); void SetUpInputMethodForTesting(InputMethod* input_method);
class COMPONENT_EXPORT(UI_BASE_IME_INIT) ScopedTestInputMethodFactory {
public:
ScopedTestInputMethodFactory();
~ScopedTestInputMethodFactory();
private:
DISALLOW_COPY_AND_ASSIGN(ScopedTestInputMethodFactory);
};
} // namespace ui; } // namespace ui;
#endif // UI_BASE_IME_INIT_INPUT_METHOD_FACTORY_H_ #endif // UI_BASE_IME_INIT_INPUT_METHOD_FACTORY_H_
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