summaryrefslogtreecommitdiffstats
path: root/ui/base
diff options
context:
space:
mode:
authornona@chromium.org <nona@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-10 09:11:42 +0000
committernona@chromium.org <nona@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-10 09:11:42 +0000
commit69df6ccb26f6db8f4470e70c8551c8a149b05330 (patch)
treeef72356a511f1725bc09949d075d9e2ee3e325af /ui/base
parent1a3bc36d7c43f5f10867fd8f2571f89bceb3ed82 (diff)
downloadchromium_src-69df6ccb26f6db8f4470e70c8551c8a149b05330.zip
chromium_src-69df6ccb26f6db8f4470e70c8551c8a149b05330.tar.gz
chromium_src-69df6ccb26f6db8f4470e70c8551c8a149b05330.tar.bz2
Fix ibus-m17n crash due to wrong parameter from Chrome.
The argument of SetSurroundingText is relative position from passing surrounding text. Here selection_range or text_range is absolute position from document root, thus we need conversion. BUG=222392 TEST=type "a" 140 times with Thai input and made sure not crashing. Review URL: https://chromiumcodereview.appspot.com/13812013 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@193353 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/base')
-rw-r--r--ui/base/ime/input_method_ibus.cc10
-rw-r--r--ui/base/ime/input_method_ibus_unittest.cc39
2 files changed, 38 insertions, 11 deletions
diff --git a/ui/base/ime/input_method_ibus.cc b/ui/base/ime/input_method_ibus.cc
index cce1f3d..9bbee01 100644
--- a/ui/base/ime/input_method_ibus.cc
+++ b/ui/base/ime/input_method_ibus.cc
@@ -267,13 +267,13 @@ void InputMethodIBus::OnCaretBoundsChanged(const TextInputClient* client) {
previous_selection_range_ = selection_range;
previous_surrounding_text_ = surrounding_text;
- // In the original meaning of SetSurroundingText is not just selection text,
- // but currently there are no way to retrieve surrounding text in
- // TextInputClient.
+ // Here SetSurroundingText accepts relative position of |surrounding_text|, so
+ // we have to convert |selection_range| from node coordinates to
+ // |surrounding_text| coordinates.
GetInputContextClient()->SetSurroundingText(
UTF16ToUTF8(surrounding_text),
- selection_range.start(), /* cursor position. */
- selection_range.end()); /* selection anchor position. */
+ selection_range.start() - text_range.start(),
+ selection_range.end() - text_range.start());
}
void InputMethodIBus::CancelComposition(const TextInputClient* client) {
diff --git a/ui/base/ime/input_method_ibus_unittest.cc b/ui/base/ime/input_method_ibus_unittest.cc
index 0ed4086..7fa10f9 100644
--- a/ui/base/ime/input_method_ibus_unittest.cc
+++ b/ui/base/ime/input_method_ibus_unittest.cc
@@ -1147,9 +1147,8 @@ TEST_F(InputMethodIBusTest, SurroundingText_NoSelectionTest) {
selection_range_ = ui::Range(3, 3);
// Set the verifier for SetSurroundingText mock call.
- SetSurroundingTextVerifier verifier(UTF16ToUTF8(surrounding_text_),
- selection_range_.start(),
- selection_range_.end());
+ SetSurroundingTextVerifier verifier(UTF16ToUTF8(surrounding_text_), 3, 3);
+
mock_ibus_input_context_client_->set_set_surrounding_text_handler(
base::Bind(&SetSurroundingTextVerifier::Verify,
@@ -1178,9 +1177,37 @@ TEST_F(InputMethodIBusTest, SurroundingText_SelectionTest) {
selection_range_ = ui::Range(2, 5);
// Set the verifier for SetSurroundingText mock call.
- SetSurroundingTextVerifier verifier(UTF16ToUTF8(surrounding_text_),
- selection_range_.start(),
- selection_range_.end());
+ SetSurroundingTextVerifier verifier(UTF16ToUTF8(surrounding_text_), 2, 5);
+
+ mock_ibus_input_context_client_->set_set_surrounding_text_handler(
+ base::Bind(&SetSurroundingTextVerifier::Verify,
+ base::Unretained(&verifier)));
+ ime_->OnCaretBoundsChanged(this);
+
+ // Check the call count.
+ EXPECT_EQ(1,
+ mock_ibus_input_context_client_->set_surrounding_text_call_count());
+}
+
+TEST_F(InputMethodIBusTest, SurroundingText_PartialText) {
+ SetCreateContextSuccessHandler();
+ ime_->Init(true);
+ // Click a text input form.
+ input_type_ = TEXT_INPUT_TYPE_TEXT;
+ ime_->OnTextInputTypeChanged(this);
+ // Start the daemon.
+ chromeos::DBusThreadManager::Get()->InitIBusBus("dummy address",
+ base::Bind(&base::DoNothing));
+ mock_ibus_daemon_controller_->EmulateConnect();
+
+ // Set the TextInputClient behaviors.
+ surrounding_text_ = UTF8ToUTF16("abcdefghij");
+ text_range_ = ui::Range(5, 10);
+ selection_range_ = ui::Range(7, 9);
+
+ // Set the verifier for SetSurroundingText mock call.
+ // Here (2, 4) is selection range in expected surrounding text coordinates.
+ SetSurroundingTextVerifier verifier("fghij", 2, 4);
mock_ibus_input_context_client_->set_set_surrounding_text_handler(
base::Bind(&SetSurroundingTextVerifier::Verify,