| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <X11/Xlib.h> | 5 #include <X11/Xlib.h> |
| 6 #undef Bool | 6 #undef Bool |
| 7 #undef FocusIn | 7 #undef FocusIn |
| 8 #undef FocusOut | 8 #undef FocusOut |
| 9 #undef None | 9 #undef None |
| 10 | 10 |
| (...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 return caret_bounds_; | 412 return caret_bounds_; |
| 413 } | 413 } |
| 414 virtual bool GetCompositionCharacterBounds(uint32 index, | 414 virtual bool GetCompositionCharacterBounds(uint32 index, |
| 415 gfx::Rect* rect) OVERRIDE { | 415 gfx::Rect* rect) OVERRIDE { |
| 416 return false; | 416 return false; |
| 417 } | 417 } |
| 418 virtual bool HasCompositionText() OVERRIDE { | 418 virtual bool HasCompositionText() OVERRIDE { |
| 419 CompositionText empty; | 419 CompositionText empty; |
| 420 return composition_text_ != empty; | 420 return composition_text_ != empty; |
| 421 } | 421 } |
| 422 virtual bool GetTextRange(Range* range) OVERRIDE { | 422 virtual bool GetTextRange(gfx::Range* range) OVERRIDE { |
| 423 *range = text_range_; | 423 *range = text_range_; |
| 424 return true; | 424 return true; |
| 425 } | 425 } |
| 426 virtual bool GetCompositionTextRange(Range* range) OVERRIDE { return false; } | 426 virtual bool GetCompositionTextRange(gfx::Range* range) OVERRIDE { return fals
e; } |
| 427 virtual bool GetSelectionRange(Range* range) OVERRIDE { | 427 virtual bool GetSelectionRange(gfx::Range* range) OVERRIDE { |
| 428 *range = selection_range_; | 428 *range = selection_range_; |
| 429 return true; | 429 return true; |
| 430 } | 430 } |
| 431 | 431 |
| 432 virtual bool SetSelectionRange(const Range& range) OVERRIDE { return false; } | 432 virtual bool SetSelectionRange(const gfx::Range& range) OVERRIDE { return fals
e; } |
| 433 virtual bool DeleteRange(const Range& range) OVERRIDE { return false; } | 433 virtual bool DeleteRange(const gfx::Range& range) OVERRIDE { return false; } |
| 434 virtual bool GetTextFromRange(const Range& range, string16* text) OVERRIDE { | 434 virtual bool GetTextFromRange(const gfx::Range& range, string16* text) OVERRID
E { |
| 435 *text = surrounding_text_.substr(range.GetMin(), range.length()); | 435 *text = surrounding_text_.substr(range.GetMin(), range.length()); |
| 436 return true; | 436 return true; |
| 437 } | 437 } |
| 438 virtual void OnInputMethodChanged() OVERRIDE { | 438 virtual void OnInputMethodChanged() OVERRIDE { |
| 439 ++on_input_method_changed_call_count_; | 439 ++on_input_method_changed_call_count_; |
| 440 } | 440 } |
| 441 virtual bool ChangeTextDirectionAndLayoutAlignment( | 441 virtual bool ChangeTextDirectionAndLayoutAlignment( |
| 442 base::i18n::TextDirection direction) OVERRIDE { return false; } | 442 base::i18n::TextDirection direction) OVERRIDE { return false; } |
| 443 virtual void ExtendSelectionAndDelete(size_t before, | 443 virtual void ExtendSelectionAndDelete(size_t before, |
| 444 size_t after) OVERRIDE { } | 444 size_t after) OVERRIDE { } |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 494 CompositionText confirmed_text_; | 494 CompositionText confirmed_text_; |
| 495 string16 inserted_text_; | 495 string16 inserted_text_; |
| 496 char16 inserted_char_; | 496 char16 inserted_char_; |
| 497 unsigned int on_input_method_changed_call_count_; | 497 unsigned int on_input_method_changed_call_count_; |
| 498 int inserted_char_flags_; | 498 int inserted_char_flags_; |
| 499 | 499 |
| 500 // Variables that will be returned from the ui::TextInputClient functions. | 500 // Variables that will be returned from the ui::TextInputClient functions. |
| 501 TextInputType input_type_; | 501 TextInputType input_type_; |
| 502 bool can_compose_inline_; | 502 bool can_compose_inline_; |
| 503 gfx::Rect caret_bounds_; | 503 gfx::Rect caret_bounds_; |
| 504 ui::Range text_range_; | 504 gfx::Range text_range_; |
| 505 ui::Range selection_range_; | 505 gfx::Range selection_range_; |
| 506 string16 surrounding_text_; | 506 string16 surrounding_text_; |
| 507 | 507 |
| 508 // Variables for mock dbus connections. | 508 // Variables for mock dbus connections. |
| 509 chromeos::MockDBusThreadManagerWithoutGMock* mock_dbus_thread_manager_; | 509 chromeos::MockDBusThreadManagerWithoutGMock* mock_dbus_thread_manager_; |
| 510 chromeos::MockIBusClient* mock_ibus_client_; | 510 chromeos::MockIBusClient* mock_ibus_client_; |
| 511 chromeos::MockIBusInputContextClient* mock_ibus_input_context_client_; | 511 chromeos::MockIBusInputContextClient* mock_ibus_input_context_client_; |
| 512 chromeos::MockIBusDaemonController* mock_ibus_daemon_controller_; | 512 chromeos::MockIBusDaemonController* mock_ibus_daemon_controller_; |
| 513 | 513 |
| 514 DISALLOW_COPY_AND_ASSIGN(InputMethodIBusTest); | 514 DISALLOW_COPY_AND_ASSIGN(InputMethodIBusTest); |
| 515 }; | 515 }; |
| (...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1121 // Click a text input form. | 1121 // Click a text input form. |
| 1122 input_type_ = TEXT_INPUT_TYPE_TEXT; | 1122 input_type_ = TEXT_INPUT_TYPE_TEXT; |
| 1123 ime_->OnTextInputTypeChanged(this); | 1123 ime_->OnTextInputTypeChanged(this); |
| 1124 // Start the daemon. | 1124 // Start the daemon. |
| 1125 InitIBusBus(); | 1125 InitIBusBus(); |
| 1126 SetCreateContextSuccessHandler(); | 1126 SetCreateContextSuccessHandler(); |
| 1127 mock_ibus_daemon_controller_->EmulateConnect(); | 1127 mock_ibus_daemon_controller_->EmulateConnect(); |
| 1128 | 1128 |
| 1129 // Set the TextInputClient behaviors. | 1129 // Set the TextInputClient behaviors. |
| 1130 surrounding_text_ = UTF8ToUTF16("abcdef"); | 1130 surrounding_text_ = UTF8ToUTF16("abcdef"); |
| 1131 text_range_ = ui::Range(0, 6); | 1131 text_range_ = gfx::Range(0, 6); |
| 1132 selection_range_ = ui::Range(3, 3); | 1132 selection_range_ = gfx::Range(3, 3); |
| 1133 | 1133 |
| 1134 // Set the verifier for SetSurroundingText mock call. | 1134 // Set the verifier for SetSurroundingText mock call. |
| 1135 SetSurroundingTextVerifier verifier(UTF16ToUTF8(surrounding_text_), 3, 3); | 1135 SetSurroundingTextVerifier verifier(UTF16ToUTF8(surrounding_text_), 3, 3); |
| 1136 | 1136 |
| 1137 | 1137 |
| 1138 mock_ibus_input_context_client_->set_set_surrounding_text_handler( | 1138 mock_ibus_input_context_client_->set_set_surrounding_text_handler( |
| 1139 base::Bind(&SetSurroundingTextVerifier::Verify, | 1139 base::Bind(&SetSurroundingTextVerifier::Verify, |
| 1140 base::Unretained(&verifier))); | 1140 base::Unretained(&verifier))); |
| 1141 ime_->OnCaretBoundsChanged(this); | 1141 ime_->OnCaretBoundsChanged(this); |
| 1142 | 1142 |
| 1143 // Check the call count. | 1143 // Check the call count. |
| 1144 EXPECT_EQ(1, | 1144 EXPECT_EQ(1, |
| 1145 mock_ibus_input_context_client_->set_surrounding_text_call_count()); | 1145 mock_ibus_input_context_client_->set_surrounding_text_call_count()); |
| 1146 } | 1146 } |
| 1147 | 1147 |
| 1148 TEST_F(InputMethodIBusTest, SurroundingText_SelectionTest) { | 1148 TEST_F(InputMethodIBusTest, SurroundingText_SelectionTest) { |
| 1149 ime_->Init(true); | 1149 ime_->Init(true); |
| 1150 // Click a text input form. | 1150 // Click a text input form. |
| 1151 input_type_ = TEXT_INPUT_TYPE_TEXT; | 1151 input_type_ = TEXT_INPUT_TYPE_TEXT; |
| 1152 ime_->OnTextInputTypeChanged(this); | 1152 ime_->OnTextInputTypeChanged(this); |
| 1153 // Start the daemon. | 1153 // Start the daemon. |
| 1154 InitIBusBus(); | 1154 InitIBusBus(); |
| 1155 SetCreateContextSuccessHandler(); | 1155 SetCreateContextSuccessHandler(); |
| 1156 mock_ibus_daemon_controller_->EmulateConnect(); | 1156 mock_ibus_daemon_controller_->EmulateConnect(); |
| 1157 | 1157 |
| 1158 // Set the TextInputClient behaviors. | 1158 // Set the TextInputClient behaviors. |
| 1159 surrounding_text_ = UTF8ToUTF16("abcdef"); | 1159 surrounding_text_ = UTF8ToUTF16("abcdef"); |
| 1160 text_range_ = ui::Range(0, 6); | 1160 text_range_ = gfx::Range(0, 6); |
| 1161 selection_range_ = ui::Range(2, 5); | 1161 selection_range_ = gfx::Range(2, 5); |
| 1162 | 1162 |
| 1163 // Set the verifier for SetSurroundingText mock call. | 1163 // Set the verifier for SetSurroundingText mock call. |
| 1164 SetSurroundingTextVerifier verifier(UTF16ToUTF8(surrounding_text_), 2, 5); | 1164 SetSurroundingTextVerifier verifier(UTF16ToUTF8(surrounding_text_), 2, 5); |
| 1165 | 1165 |
| 1166 mock_ibus_input_context_client_->set_set_surrounding_text_handler( | 1166 mock_ibus_input_context_client_->set_set_surrounding_text_handler( |
| 1167 base::Bind(&SetSurroundingTextVerifier::Verify, | 1167 base::Bind(&SetSurroundingTextVerifier::Verify, |
| 1168 base::Unretained(&verifier))); | 1168 base::Unretained(&verifier))); |
| 1169 ime_->OnCaretBoundsChanged(this); | 1169 ime_->OnCaretBoundsChanged(this); |
| 1170 | 1170 |
| 1171 // Check the call count. | 1171 // Check the call count. |
| 1172 EXPECT_EQ(1, | 1172 EXPECT_EQ(1, |
| 1173 mock_ibus_input_context_client_->set_surrounding_text_call_count()); | 1173 mock_ibus_input_context_client_->set_surrounding_text_call_count()); |
| 1174 } | 1174 } |
| 1175 | 1175 |
| 1176 TEST_F(InputMethodIBusTest, SurroundingText_PartialText) { | 1176 TEST_F(InputMethodIBusTest, SurroundingText_PartialText) { |
| 1177 ime_->Init(true); | 1177 ime_->Init(true); |
| 1178 // Click a text input form. | 1178 // Click a text input form. |
| 1179 input_type_ = TEXT_INPUT_TYPE_TEXT; | 1179 input_type_ = TEXT_INPUT_TYPE_TEXT; |
| 1180 ime_->OnTextInputTypeChanged(this); | 1180 ime_->OnTextInputTypeChanged(this); |
| 1181 // Start the daemon. | 1181 // Start the daemon. |
| 1182 InitIBusBus(); | 1182 InitIBusBus(); |
| 1183 SetCreateContextSuccessHandler(); | 1183 SetCreateContextSuccessHandler(); |
| 1184 mock_ibus_daemon_controller_->EmulateConnect(); | 1184 mock_ibus_daemon_controller_->EmulateConnect(); |
| 1185 | 1185 |
| 1186 // Set the TextInputClient behaviors. | 1186 // Set the TextInputClient behaviors. |
| 1187 surrounding_text_ = UTF8ToUTF16("abcdefghij"); | 1187 surrounding_text_ = UTF8ToUTF16("abcdefghij"); |
| 1188 text_range_ = ui::Range(5, 10); | 1188 text_range_ = gfx::Range(5, 10); |
| 1189 selection_range_ = ui::Range(7, 9); | 1189 selection_range_ = gfx::Range(7, 9); |
| 1190 | 1190 |
| 1191 // Set the verifier for SetSurroundingText mock call. | 1191 // Set the verifier for SetSurroundingText mock call. |
| 1192 // Here (2, 4) is selection range in expected surrounding text coordinates. | 1192 // Here (2, 4) is selection range in expected surrounding text coordinates. |
| 1193 SetSurroundingTextVerifier verifier("fghij", 2, 4); | 1193 SetSurroundingTextVerifier verifier("fghij", 2, 4); |
| 1194 | 1194 |
| 1195 mock_ibus_input_context_client_->set_set_surrounding_text_handler( | 1195 mock_ibus_input_context_client_->set_set_surrounding_text_handler( |
| 1196 base::Bind(&SetSurroundingTextVerifier::Verify, | 1196 base::Bind(&SetSurroundingTextVerifier::Verify, |
| 1197 base::Unretained(&verifier))); | 1197 base::Unretained(&verifier))); |
| 1198 ime_->OnCaretBoundsChanged(this); | 1198 ime_->OnCaretBoundsChanged(this); |
| 1199 | 1199 |
| 1200 // Check the call count. | 1200 // Check the call count. |
| 1201 EXPECT_EQ(1, | 1201 EXPECT_EQ(1, |
| 1202 mock_ibus_input_context_client_->set_surrounding_text_call_count()); | 1202 mock_ibus_input_context_client_->set_surrounding_text_call_count()); |
| 1203 } | 1203 } |
| 1204 | 1204 |
| 1205 TEST_F(InputMethodIBusTest, SurroundingText_BecomeEmptyText) { | 1205 TEST_F(InputMethodIBusTest, SurroundingText_BecomeEmptyText) { |
| 1206 ime_->Init(true); | 1206 ime_->Init(true); |
| 1207 // Click a text input form. | 1207 // Click a text input form. |
| 1208 input_type_ = TEXT_INPUT_TYPE_TEXT; | 1208 input_type_ = TEXT_INPUT_TYPE_TEXT; |
| 1209 ime_->OnTextInputTypeChanged(this); | 1209 ime_->OnTextInputTypeChanged(this); |
| 1210 // Start the daemon. | 1210 // Start the daemon. |
| 1211 InitIBusBus(); | 1211 InitIBusBus(); |
| 1212 SetCreateContextSuccessHandler(); | 1212 SetCreateContextSuccessHandler(); |
| 1213 mock_ibus_daemon_controller_->EmulateConnect(); | 1213 mock_ibus_daemon_controller_->EmulateConnect(); |
| 1214 | 1214 |
| 1215 // Set the TextInputClient behaviors. | 1215 // Set the TextInputClient behaviors. |
| 1216 // If the surrounding text becomes empty, text_range become (0, 0) and | 1216 // If the surrounding text becomes empty, text_range become (0, 0) and |
| 1217 // selection range become invalid. | 1217 // selection range become invalid. |
| 1218 surrounding_text_ = UTF8ToUTF16(""); | 1218 surrounding_text_ = UTF8ToUTF16(""); |
| 1219 text_range_ = ui::Range(0, 0); | 1219 text_range_ = gfx::Range(0, 0); |
| 1220 selection_range_ = ui::Range::InvalidRange(); | 1220 selection_range_ = gfx::Range::InvalidRange(); |
| 1221 | 1221 |
| 1222 // Set the verifier for SetSurroundingText mock call. | 1222 // Set the verifier for SetSurroundingText mock call. |
| 1223 SetSurroundingTextVerifier verifier("", 0, 0); | 1223 SetSurroundingTextVerifier verifier("", 0, 0); |
| 1224 | 1224 |
| 1225 mock_ibus_input_context_client_->set_set_surrounding_text_handler( | 1225 mock_ibus_input_context_client_->set_set_surrounding_text_handler( |
| 1226 base::Bind(&SetSurroundingTextVerifier::Verify, | 1226 base::Bind(&SetSurroundingTextVerifier::Verify, |
| 1227 base::Unretained(&verifier))); | 1227 base::Unretained(&verifier))); |
| 1228 ime_->OnCaretBoundsChanged(this); | 1228 ime_->OnCaretBoundsChanged(this); |
| 1229 | 1229 |
| 1230 // Check the call count. | 1230 // Check the call count. |
| (...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1702 | 1702 |
| 1703 // Do callback. | 1703 // Do callback. |
| 1704 success_consume_handler.RunCallback(KEYEVENT_CONSUME); | 1704 success_consume_handler.RunCallback(KEYEVENT_CONSUME); |
| 1705 | 1705 |
| 1706 EXPECT_EQ(0, ime_->process_key_event_post_ime_call_count()); | 1706 EXPECT_EQ(0, ime_->process_key_event_post_ime_call_count()); |
| 1707 } | 1707 } |
| 1708 | 1708 |
| 1709 // TODO(nona): Introduce ProcessKeyEventPostIME tests(crbug.com/156593). | 1709 // TODO(nona): Introduce ProcessKeyEventPostIME tests(crbug.com/156593). |
| 1710 | 1710 |
| 1711 } // namespace ui | 1711 } // namespace ui |
| OLD | NEW |