| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_chromeos.h" | 5 #include "ui/base/ime/input_method_chromeos.h" |
| 6 | 6 |
| 7 #include <X11/Xlib.h> | 7 #include <X11/Xlib.h> |
| 8 #undef Bool | 8 #undef Bool |
| 9 #undef FocusIn | 9 #undef FocusIn |
| 10 #undef FocusOut | 10 #undef FocusOut |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 const uint32 expected_anchor_position_; | 191 const uint32 expected_anchor_position_; |
| 192 | 192 |
| 193 DISALLOW_COPY_AND_ASSIGN(SetSurroundingTextVerifier); | 193 DISALLOW_COPY_AND_ASSIGN(SetSurroundingTextVerifier); |
| 194 }; | 194 }; |
| 195 | 195 |
| 196 class InputMethodChromeOSTest : public internal::InputMethodDelegate, | 196 class InputMethodChromeOSTest : public internal::InputMethodDelegate, |
| 197 public testing::Test, | 197 public testing::Test, |
| 198 public DummyTextInputClient { | 198 public DummyTextInputClient { |
| 199 public: | 199 public: |
| 200 InputMethodChromeOSTest() | 200 InputMethodChromeOSTest() |
| 201 : dispatched_key_event_(ui::ET_UNKNOWN, ui::VKEY_UNKNOWN, ui::EF_NONE) { | 201 : dispatched_key_event_(ui::ET_UNKNOWN, ui::VKEY_UNKNOWN, ui::EF_NONE), |
| 202 stop_propagation_post_ime(false) { |
| 202 ResetFlags(); | 203 ResetFlags(); |
| 203 } | 204 } |
| 204 | 205 |
| 205 ~InputMethodChromeOSTest() override {} | 206 ~InputMethodChromeOSTest() override {} |
| 206 | 207 |
| 207 void SetUp() override { | 208 void SetUp() override { |
| 208 chromeos::IMEBridge::Initialize(); | 209 chromeos::IMEBridge::Initialize(); |
| 209 | 210 |
| 210 mock_ime_engine_handler_.reset( | 211 mock_ime_engine_handler_.reset( |
| 211 new chromeos::MockIMEEngineHandler()); | 212 new chromeos::MockIMEEngineHandler()); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 230 mock_ime_engine_handler_.reset(); | 231 mock_ime_engine_handler_.reset(); |
| 231 mock_ime_candidate_window_handler_.reset(); | 232 mock_ime_candidate_window_handler_.reset(); |
| 232 chromeos::IMEBridge::Shutdown(); | 233 chromeos::IMEBridge::Shutdown(); |
| 233 | 234 |
| 234 ResetFlags(); | 235 ResetFlags(); |
| 235 } | 236 } |
| 236 | 237 |
| 237 // Overridden from ui::internal::InputMethodDelegate: | 238 // Overridden from ui::internal::InputMethodDelegate: |
| 238 bool DispatchKeyEventPostIME(const ui::KeyEvent& event) override { | 239 bool DispatchKeyEventPostIME(const ui::KeyEvent& event) override { |
| 239 dispatched_key_event_ = event; | 240 dispatched_key_event_ = event; |
| 240 return false; | 241 return stop_propagation_post_ime; |
| 241 } | 242 } |
| 242 | 243 |
| 243 // Overridden from ui::TextInputClient: | 244 // Overridden from ui::TextInputClient: |
| 244 void SetCompositionText(const CompositionText& composition) override { | 245 void SetCompositionText(const CompositionText& composition) override { |
| 245 composition_text_ = composition; | 246 composition_text_ = composition; |
| 246 } | 247 } |
| 247 void ConfirmCompositionText() override { | 248 void ConfirmCompositionText() override { |
| 248 confirmed_text_ = composition_text_; | 249 confirmed_text_ = composition_text_; |
| 249 composition_text_.Clear(); | 250 composition_text_.Clear(); |
| 250 } | 251 } |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 bool can_compose_inline_; | 323 bool can_compose_inline_; |
| 323 gfx::Rect caret_bounds_; | 324 gfx::Rect caret_bounds_; |
| 324 gfx::Range text_range_; | 325 gfx::Range text_range_; |
| 325 gfx::Range selection_range_; | 326 gfx::Range selection_range_; |
| 326 base::string16 surrounding_text_; | 327 base::string16 surrounding_text_; |
| 327 | 328 |
| 328 scoped_ptr<chromeos::MockIMEEngineHandler> mock_ime_engine_handler_; | 329 scoped_ptr<chromeos::MockIMEEngineHandler> mock_ime_engine_handler_; |
| 329 scoped_ptr<chromeos::MockIMECandidateWindowHandler> | 330 scoped_ptr<chromeos::MockIMECandidateWindowHandler> |
| 330 mock_ime_candidate_window_handler_; | 331 mock_ime_candidate_window_handler_; |
| 331 | 332 |
| 333 bool stop_propagation_post_ime; |
| 334 |
| 332 DISALLOW_COPY_AND_ASSIGN(InputMethodChromeOSTest); | 335 DISALLOW_COPY_AND_ASSIGN(InputMethodChromeOSTest); |
| 333 }; | 336 }; |
| 334 | 337 |
| 335 // Tests public APIs in ui::InputMethod first. | 338 // Tests public APIs in ui::InputMethod first. |
| 336 | 339 |
| 337 TEST_F(InputMethodChromeOSTest, GetInputLocale) { | 340 TEST_F(InputMethodChromeOSTest, GetInputLocale) { |
| 338 // ui::InputMethodChromeOS does not support the API. | 341 // ui::InputMethodChromeOS does not support the API. |
| 339 ime_->OnFocus(); | 342 ime_->OnFocus(); |
| 340 EXPECT_EQ("", ime_->GetInputLocale()); | 343 EXPECT_EQ("", ime_->GetInputLocale()); |
| 341 } | 344 } |
| (...skipping 632 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 974 // Check the results for second key event. | 977 // Check the results for second key event. |
| 975 EXPECT_EQ(2, ime_->process_key_event_post_ime_call_count()); | 978 EXPECT_EQ(2, ime_->process_key_event_post_ime_call_count()); |
| 976 stored_event = ime_->process_key_event_post_ime_args().event; | 979 stored_event = ime_->process_key_event_post_ime_args().event; |
| 977 EXPECT_EQ(ui::VKEY_C, stored_event->key_code()); | 980 EXPECT_EQ(ui::VKEY_C, stored_event->key_code()); |
| 978 EXPECT_EQ(kFlags, stored_event->flags()); | 981 EXPECT_EQ(kFlags, stored_event->flags()); |
| 979 EXPECT_FALSE(ime_->process_key_event_post_ime_args().handled); | 982 EXPECT_FALSE(ime_->process_key_event_post_ime_args().handled); |
| 980 | 983 |
| 981 EXPECT_EQ(L'C', inserted_char_); | 984 EXPECT_EQ(L'C', inserted_char_); |
| 982 } | 985 } |
| 983 | 986 |
| 984 // TODO(nona): Introduce ProcessKeyEventPostIME tests(crbug.com/156593). | 987 TEST_F(InputMethodChromeOSKeyEventTest, StopPropagationTest) { |
| 988 // Preparation |
| 989 input_type_ = TEXT_INPUT_TYPE_TEXT; |
| 990 ime_->OnTextInputTypeChanged(this); |
| 991 |
| 992 // Do key event with event being stopped propagation. |
| 993 stop_propagation_post_ime = true; |
| 994 ui::KeyEvent eventA(ui::ET_KEY_PRESSED, ui::VKEY_A, EF_NONE); |
| 995 eventA.set_character(L'A'); |
| 996 ime_->DispatchKeyEvent(eventA); |
| 997 mock_ime_engine_handler_->last_passed_callback().Run(false); |
| 998 |
| 999 const ui::KeyEvent* key_event = |
| 1000 mock_ime_engine_handler_->last_processed_key_event(); |
| 1001 EXPECT_EQ(ui::VKEY_A, key_event->key_code()); |
| 1002 EXPECT_EQ(0, inserted_char_); |
| 1003 |
| 1004 // Do key event with event not being stopped propagation. |
| 1005 stop_propagation_post_ime = false; |
| 1006 ime_->DispatchKeyEvent(eventA); |
| 1007 mock_ime_engine_handler_->last_passed_callback().Run(false); |
| 1008 |
| 1009 key_event = mock_ime_engine_handler_->last_processed_key_event(); |
| 1010 EXPECT_EQ(ui::VKEY_A, key_event->key_code()); |
| 1011 EXPECT_EQ(L'A', inserted_char_); |
| 1012 } |
| 985 | 1013 |
| 986 } // namespace ui | 1014 } // namespace ui |
| OLD | NEW |