| Index: ui/base/ime/input_method_base_unittest.cc
|
| diff --git a/ui/base/ime/input_method_base_unittest.cc b/ui/base/ime/input_method_base_unittest.cc
|
| index 3d06a1a32030f83f2f70f11cbdc06b8f22a16e93..4c24949fdacaee6caeeffcca64373eaf55a984cf 100644
|
| --- a/ui/base/ime/input_method_base_unittest.cc
|
| +++ b/ui/base/ime/input_method_base_unittest.cc
|
| @@ -110,13 +110,11 @@ class ClientChangeVerifier {
|
| DISALLOW_COPY_AND_ASSIGN(ClientChangeVerifier);
|
| };
|
|
|
| -class MockInputMethodBase : public InputMethodBase {
|
| +class SimpleMockInputMethodBase : public InputMethodBase {
|
| public:
|
| - // Note: this class does not take the ownership of |verifier|.
|
| - explicit MockInputMethodBase(ClientChangeVerifier* verifier)
|
| - : verifier_(verifier) {
|
| + SimpleMockInputMethodBase() {
|
| }
|
| - virtual ~MockInputMethodBase() {
|
| + virtual ~SimpleMockInputMethodBase() {
|
| }
|
|
|
| private:
|
| @@ -132,13 +130,9 @@ class MockInputMethodBase : public InputMethodBase {
|
| virtual bool DispatchFabricatedKeyEvent(const ui::KeyEvent&) OVERRIDE {
|
| return false;
|
| }
|
| - virtual void OnCaretBoundsChanged(const TextInputClient* clien) OVERRIDE {
|
| - }
|
| - virtual void CancelComposition(const TextInputClient* clien) OVERRIDE {
|
| + virtual void CancelComposition(const TextInputClient* client) OVERRIDE {
|
| }
|
| - virtual void OnInputLocaleChanged() OVERRIDE {
|
| - }
|
| - virtual std::string GetInputLocale() OVERRIDE {
|
| + virtual std::string GetInputLocale() OVERRIDE{
|
| return "";
|
| }
|
| virtual base::i18n::TextDirection GetInputTextDirection() OVERRIDE {
|
| @@ -150,7 +144,19 @@ class MockInputMethodBase : public InputMethodBase {
|
| virtual bool IsCandidatePopupOpen() const OVERRIDE {
|
| return false;
|
| }
|
| + DISALLOW_COPY_AND_ASSIGN(SimpleMockInputMethodBase);
|
| +};
|
| +
|
| +class MockInputMethodBase : public SimpleMockInputMethodBase {
|
| + public:
|
| + // Note: this class does not take the ownership of |verifier|.
|
| + explicit MockInputMethodBase(ClientChangeVerifier* verifier)
|
| + : verifier_(verifier) {
|
| + }
|
| + virtual ~MockInputMethodBase() {
|
| + }
|
|
|
| + private:
|
| // Overriden from InputMethodBase.
|
| virtual void OnWillChangeFocusedClient(TextInputClient* focused_before,
|
| TextInputClient* focused) OVERRIDE {
|
| @@ -166,33 +172,65 @@ class MockInputMethodBase : public InputMethodBase {
|
| DISALLOW_COPY_AND_ASSIGN(MockInputMethodBase);
|
| };
|
|
|
| -class MockInputMethodObserver : public InputMethodObserver {
|
| +class SimpleMockInputMethodObserver : public InputMethodObserver {
|
| public:
|
| - // Note: this class does not take the ownership of |verifier|.
|
| - explicit MockInputMethodObserver(ClientChangeVerifier* verifier)
|
| - : verifier_(verifier) {
|
| + SimpleMockInputMethodObserver()
|
| + : on_caret_bounds_changed_(0),
|
| + on_input_locale_changed_(0) {
|
| }
|
| - virtual ~MockInputMethodObserver() {
|
| + virtual ~SimpleMockInputMethodObserver() {
|
| + }
|
| + void Reset() {
|
| + on_caret_bounds_changed_ = 0;
|
| + on_input_locale_changed_ = 0;
|
| + }
|
| + size_t on_caret_bounds_changed() const {
|
| + return on_caret_bounds_changed_;
|
| + }
|
| + size_t on_input_locale_changed() const {
|
| + return on_input_locale_changed_;
|
| }
|
|
|
| private:
|
| - virtual void OnTextInputTypeChanged(const TextInputClient* client) OVERRIDE {
|
| + // Overriden from InputMethodObserver.
|
| + virtual void OnTextInputTypeChanged(const TextInputClient* client) OVERRIDE{
|
| }
|
| - virtual void OnFocus() OVERRIDE {
|
| + virtual void OnFocus() OVERRIDE{
|
| }
|
| - virtual void OnBlur() OVERRIDE {
|
| + virtual void OnBlur() OVERRIDE{
|
| }
|
| virtual void OnUntranslatedIMEMessage(
|
| - const base::NativeEvent& event) OVERRIDE {
|
| + const base::NativeEvent& event) OVERRIDE{
|
| }
|
| - virtual void OnCaretBoundsChanged(const TextInputClient* client) OVERRIDE {
|
| + virtual void OnCaretBoundsChanged(const TextInputClient* client) OVERRIDE{
|
| + ++on_caret_bounds_changed_;
|
| }
|
| - virtual void OnInputLocaleChanged() OVERRIDE {
|
| + virtual void OnInputLocaleChanged() OVERRIDE{
|
| + ++on_input_locale_changed_;
|
| }
|
| - virtual void OnTextInputStateChanged(const TextInputClient* client) OVERRIDE {
|
| - verifier_->OnTextInputStateChanged(client);
|
| + virtual void OnTextInputStateChanged(const TextInputClient* client) OVERRIDE{
|
| }
|
| - virtual void OnInputMethodDestroyed(const InputMethod* client) OVERRIDE {
|
| + virtual void OnInputMethodDestroyed(const InputMethod* client) OVERRIDE{
|
| + }
|
| +
|
| + size_t on_caret_bounds_changed_;
|
| + size_t on_input_locale_changed_;
|
| + DISALLOW_COPY_AND_ASSIGN(SimpleMockInputMethodObserver);
|
| +};
|
| +
|
| +class MockInputMethodObserver : public SimpleMockInputMethodObserver {
|
| + public:
|
| + // Note: this class does not take the ownership of |verifier|.
|
| + explicit MockInputMethodObserver(ClientChangeVerifier* verifier)
|
| + : verifier_(verifier) {
|
| + }
|
| + virtual ~MockInputMethodObserver() {
|
| + }
|
| +
|
| + private:
|
| + // Overriden from SimpleMockInputMethodObserver.
|
| + virtual void OnTextInputStateChanged(const TextInputClient* client) OVERRIDE{
|
| + verifier_->OnTextInputStateChanged(client);
|
| }
|
|
|
| ClientChangeVerifier* verifier_;
|
| @@ -392,5 +430,80 @@ TEST(InputMethodBaseTest, SetStickyFocusedTextInputClient) {
|
| }
|
| }
|
|
|
| +TEST(InputMethodBaseTest, OnCaretBoundsChanged) {
|
| + DummyTextInputClient text_input_client;
|
| + DummyTextInputClient text_input_client_the_other;
|
| +
|
| + SimpleMockInputMethodBase input_method;
|
| + SimpleMockInputMethodObserver input_method_observer;
|
| + InputMethodScopedObserver scoped_observer(&input_method_observer);
|
| + scoped_observer.Add(&input_method);
|
| +
|
| + // Assume that the top-level-widget gains focus.
|
| + input_method.OnFocus();
|
| +
|
| + {
|
| + SCOPED_TRACE("OnCaretBoundsChanged callback must not be fired when no text "
|
| + "input client is focused");
|
| + ASSERT_EQ(NULL, input_method.GetTextInputClient());
|
| +
|
| + input_method_observer.Reset();
|
| + input_method.OnCaretBoundsChanged(&text_input_client);
|
| + EXPECT_EQ(0u, input_method_observer.on_caret_bounds_changed());
|
| + input_method.OnCaretBoundsChanged(NULL);
|
| + EXPECT_EQ(0u, input_method_observer.on_caret_bounds_changed());
|
| + }
|
| +
|
| + {
|
| + SCOPED_TRACE("OnCaretBoundsChanged callback must be fired when and only "
|
| + "the event is notified from the focused text input client");
|
| +
|
| + input_method.SetFocusedTextInputClient(&text_input_client);
|
| + ASSERT_EQ(&text_input_client, input_method.GetTextInputClient());
|
| +
|
| + // Must fire the event
|
| + input_method_observer.Reset();
|
| + input_method.OnCaretBoundsChanged(&text_input_client);
|
| + EXPECT_EQ(1u, input_method_observer.on_caret_bounds_changed());
|
| +
|
| + // Must not fire the event
|
| + input_method_observer.Reset();
|
| + input_method.OnCaretBoundsChanged(NULL);
|
| + EXPECT_EQ(0u, input_method_observer.on_caret_bounds_changed());
|
| +
|
| + // Must not fire the event
|
| + input_method_observer.Reset();
|
| + input_method.OnCaretBoundsChanged(&text_input_client_the_other);
|
| + EXPECT_EQ(0u, input_method_observer.on_caret_bounds_changed());
|
| + }
|
| +}
|
| +
|
| +TEST(InputMethodBaseTest, OnInputLocaleChanged) {
|
| + DummyTextInputClient text_input_client;
|
| +
|
| + SimpleMockInputMethodBase input_method;
|
| + SimpleMockInputMethodObserver input_method_observer;
|
| + InputMethodScopedObserver scoped_observer(&input_method_observer);
|
| + scoped_observer.Add(&input_method);
|
| +
|
| + // Assume that the top-level-widget gains focus.
|
| + input_method.OnFocus();
|
| +
|
| + {
|
| + SCOPED_TRACE("OnInputLocaleChanged callback can be fired even when no text "
|
| + "input client is focused");
|
| + ASSERT_EQ(NULL, input_method.GetTextInputClient());
|
| +
|
| + input_method_observer.Reset();
|
| + input_method.OnInputLocaleChanged();
|
| + EXPECT_EQ(1u, input_method_observer.on_input_locale_changed());
|
| +
|
| + input_method.SetFocusedTextInputClient(&text_input_client);
|
| + input_method_observer.Reset();
|
| + input_method.OnInputLocaleChanged();
|
| + EXPECT_EQ(1u, input_method_observer.on_input_locale_changed());
|
| + }
|
| +}
|
| +
|
| } // namespace
|
| } // namespace ui
|
|
|