OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/base/ime/input_method_base.h" | 5 #include "ui/base/ime/input_method_base.h" |
6 | 6 |
7 #include "base/scoped_observer.h" | 7 #include "base/scoped_observer.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 #include "ui/base/ime/dummy_text_input_client.h" | 9 #include "ui/base/ime/dummy_text_input_client.h" |
10 #include "ui/base/ime/input_method_observer.h" | 10 #include "ui/base/ime/input_method_observer.h" |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 virtual bool OnUntranslatedIMEMessage( | 122 virtual bool OnUntranslatedIMEMessage( |
123 const base::NativeEvent& event, | 123 const base::NativeEvent& event, |
124 InputMethod::NativeEventResult* result) OVERRIDE { | 124 InputMethod::NativeEventResult* result) OVERRIDE { |
125 return false; | 125 return false; |
126 } | 126 } |
127 virtual bool DispatchKeyEvent(const ui::KeyEvent&) OVERRIDE { | 127 virtual bool DispatchKeyEvent(const ui::KeyEvent&) OVERRIDE { |
128 return false; | 128 return false; |
129 } | 129 } |
130 virtual void CancelComposition(const TextInputClient* client) OVERRIDE { | 130 virtual void CancelComposition(const TextInputClient* client) OVERRIDE { |
131 } | 131 } |
| 132 virtual void OnInputLocaleChanged() OVERRIDE { |
| 133 } |
132 virtual std::string GetInputLocale() OVERRIDE{ | 134 virtual std::string GetInputLocale() OVERRIDE{ |
133 return ""; | 135 return ""; |
134 } | 136 } |
135 virtual base::i18n::TextDirection GetInputTextDirection() OVERRIDE { | 137 virtual base::i18n::TextDirection GetInputTextDirection() OVERRIDE { |
136 return base::i18n::UNKNOWN_DIRECTION; | 138 return base::i18n::UNKNOWN_DIRECTION; |
137 } | 139 } |
138 virtual bool IsActive() OVERRIDE { | 140 virtual bool IsActive() OVERRIDE { |
139 return false; | 141 return false; |
140 } | 142 } |
141 virtual bool IsCandidatePopupOpen() const OVERRIDE { | 143 virtual bool IsCandidatePopupOpen() const OVERRIDE { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 } | 179 } |
178 virtual ~SimpleMockInputMethodObserver() { | 180 virtual ~SimpleMockInputMethodObserver() { |
179 } | 181 } |
180 void Reset() { | 182 void Reset() { |
181 on_caret_bounds_changed_ = 0; | 183 on_caret_bounds_changed_ = 0; |
182 on_input_locale_changed_ = 0; | 184 on_input_locale_changed_ = 0; |
183 } | 185 } |
184 size_t on_caret_bounds_changed() const { | 186 size_t on_caret_bounds_changed() const { |
185 return on_caret_bounds_changed_; | 187 return on_caret_bounds_changed_; |
186 } | 188 } |
187 size_t on_input_locale_changed() const { | |
188 return on_input_locale_changed_; | |
189 } | |
190 | 189 |
191 private: | 190 private: |
192 // Overriden from InputMethodObserver. | 191 // Overriden from InputMethodObserver. |
193 virtual void OnTextInputTypeChanged(const TextInputClient* client) OVERRIDE{ | 192 virtual void OnTextInputTypeChanged(const TextInputClient* client) OVERRIDE{ |
194 } | 193 } |
195 virtual void OnFocus() OVERRIDE{ | 194 virtual void OnFocus() OVERRIDE{ |
196 } | 195 } |
197 virtual void OnBlur() OVERRIDE{ | 196 virtual void OnBlur() OVERRIDE{ |
198 } | 197 } |
199 virtual void OnUntranslatedIMEMessage( | |
200 const base::NativeEvent& event) OVERRIDE{ | |
201 } | |
202 virtual void OnCaretBoundsChanged(const TextInputClient* client) OVERRIDE{ | 198 virtual void OnCaretBoundsChanged(const TextInputClient* client) OVERRIDE{ |
203 ++on_caret_bounds_changed_; | 199 ++on_caret_bounds_changed_; |
204 } | 200 } |
205 virtual void OnInputLocaleChanged() OVERRIDE{ | |
206 ++on_input_locale_changed_; | |
207 } | |
208 virtual void OnTextInputStateChanged(const TextInputClient* client) OVERRIDE{ | 201 virtual void OnTextInputStateChanged(const TextInputClient* client) OVERRIDE{ |
209 } | 202 } |
210 virtual void OnInputMethodDestroyed(const InputMethod* client) OVERRIDE{ | 203 virtual void OnInputMethodDestroyed(const InputMethod* client) OVERRIDE{ |
211 } | 204 } |
212 | 205 |
213 size_t on_caret_bounds_changed_; | 206 size_t on_caret_bounds_changed_; |
214 size_t on_input_locale_changed_; | 207 size_t on_input_locale_changed_; |
215 DISALLOW_COPY_AND_ASSIGN(SimpleMockInputMethodObserver); | 208 DISALLOW_COPY_AND_ASSIGN(SimpleMockInputMethodObserver); |
216 }; | 209 }; |
217 | 210 |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 input_method.OnCaretBoundsChanged(NULL); | 373 input_method.OnCaretBoundsChanged(NULL); |
381 EXPECT_EQ(0u, input_method_observer.on_caret_bounds_changed()); | 374 EXPECT_EQ(0u, input_method_observer.on_caret_bounds_changed()); |
382 | 375 |
383 // Must not fire the event | 376 // Must not fire the event |
384 input_method_observer.Reset(); | 377 input_method_observer.Reset(); |
385 input_method.OnCaretBoundsChanged(&text_input_client_the_other); | 378 input_method.OnCaretBoundsChanged(&text_input_client_the_other); |
386 EXPECT_EQ(0u, input_method_observer.on_caret_bounds_changed()); | 379 EXPECT_EQ(0u, input_method_observer.on_caret_bounds_changed()); |
387 } | 380 } |
388 } | 381 } |
389 | 382 |
390 TEST(InputMethodBaseTest, OnInputLocaleChanged) { | |
391 DummyTextInputClient text_input_client; | |
392 | |
393 SimpleMockInputMethodBase input_method; | |
394 SimpleMockInputMethodObserver input_method_observer; | |
395 InputMethodScopedObserver scoped_observer(&input_method_observer); | |
396 scoped_observer.Add(&input_method); | |
397 | |
398 // Assume that the top-level-widget gains focus. | |
399 input_method.OnFocus(); | |
400 | |
401 { | |
402 SCOPED_TRACE("OnInputLocaleChanged callback can be fired even when no text " | |
403 "input client is focused"); | |
404 ASSERT_EQ(NULL, input_method.GetTextInputClient()); | |
405 | |
406 input_method_observer.Reset(); | |
407 input_method.OnInputLocaleChanged(); | |
408 EXPECT_EQ(1u, input_method_observer.on_input_locale_changed()); | |
409 | |
410 input_method.SetFocusedTextInputClient(&text_input_client); | |
411 input_method_observer.Reset(); | |
412 input_method.OnInputLocaleChanged(); | |
413 EXPECT_EQ(1u, input_method_observer.on_input_locale_changed()); | |
414 } | |
415 } | |
416 | |
417 } // namespace | 383 } // namespace |
418 } // namespace ui | 384 } // namespace ui |
OLD | NEW |