diff options
author | nona@chromium.org <nona@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-20 13:44:52 +0000 |
---|---|---|
committer | nona@chromium.org <nona@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-20 13:44:52 +0000 |
commit | e017c9c9f321b62adf13051e32fd9d9bcc2d03ac (patch) | |
tree | f4202f3fdff31aa038e9a9f7ee5606b59a21d526 | |
parent | 326ea0d1ee43c5451f9de184b7d3134516aa69ce (diff) | |
download | chromium_src-e017c9c9f321b62adf13051e32fd9d9bcc2d03ac.zip chromium_src-e017c9c9f321b62adf13051e32fd9d9bcc2d03ac.tar.gz chromium_src-e017c9c9f321b62adf13051e32fd9d9bcc2d03ac.tar.bz2 |
Initialize selection_range as InvalidRange.
The initial selection range shuold be InvalidRange which means there is no
selection. Otherwise, the selection update IPC for the first time focus to empty
text area will lost.
BUG=None
TEST=ran --gtest_filter=TextInput_SurroundingTextChangedTest.*
Review URL: https://chromiumcodereview.appspot.com/12294037
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@183512 0039d316-1c4b-4281-b951-d872f2087c98
3 files changed, 48 insertions, 0 deletions
diff --git a/chrome/browser/chromeos/input_method/textinput_surroundingtext_browsertest.cc b/chrome/browser/chromeos/input_method/textinput_surroundingtext_browsertest.cc index 78b8ebc..dc02d4e 100644 --- a/chrome/browser/chromeos/input_method/textinput_surroundingtext_browsertest.cc +++ b/chrome/browser/chromeos/input_method/textinput_surroundingtext_browsertest.cc @@ -92,6 +92,44 @@ IN_PROC_BROWSER_TEST_F(TextInput_SurroundingTextChangedTest, EXPECT_EQ(expected_range, helper.GetSelectionRange()); } +IN_PROC_BROWSER_TEST_F(TextInput_SurroundingTextChangedTest, + FocusToTextContainingTextAreaByClickingCase) { + TextInputTestHelper helper; + GURL url = ui_test_utils::GetTestUrl( + base::FilePath(FILE_PATH_LITERAL("textinput")), + base::FilePath(FILE_PATH_LITERAL("textarea_with_preset_text.html"))); + ui_test_utils::NavigateToURL(browser(), url); + EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE, helper.GetTextInputType()); + + content::WebContents* tab = + browser()->tab_strip_model()->GetActiveWebContents(); + const ui::Range zero_range(0, 0); + + // We expect no surrounding texts. + helper.ClickElement("empty_textarea", tab); + helper.WaitForTextInputStateChanged(ui::TEXT_INPUT_TYPE_TEXT_AREA); + EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT_AREA, helper.GetTextInputType()); + helper.WaitForSurroundingTextChanged(UTF8ToUTF16(""), zero_range); + EXPECT_TRUE(helper.GetSurroundingText().empty()); + EXPECT_EQ(zero_range, helper.GetSelectionRange()); + + // Click textarea containing text, so expecting new surrounding text comes. + helper.ClickElement("filled_textarea", tab); + const string16 expected_text = UTF8ToUTF16("abcde"); + const ui::Range expected_range(5, 5); + helper.WaitForSurroundingTextChanged(expected_text, expected_range); + EXPECT_EQ(expected_text, helper.GetSurroundingText()); + EXPECT_EQ(expected_range, helper.GetSelectionRange()); + + // Then, back to empty text area: expecting empty string. + helper.ClickElement("empty_textarea", tab); + helper.WaitForTextInputStateChanged(ui::TEXT_INPUT_TYPE_TEXT_AREA); + EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT_AREA, helper.GetTextInputType()); + helper.WaitForSurroundingTextChanged(UTF8ToUTF16(""), zero_range); + EXPECT_TRUE(helper.GetSurroundingText().empty()); + EXPECT_EQ(zero_range, helper.GetSelectionRange()); +} + // TODO(nona): Add test for JavaScript focusing to textarea containing text. // TODO(nona): Add test for text changing by JavaScript. // TODO(nona): Add test for onload focusing to textarea containing text. diff --git a/chrome/test/data/textinput/textarea_with_preset_text.html b/chrome/test/data/textinput/textarea_with_preset_text.html new file mode 100644 index 0000000..a0c9cf3 --- /dev/null +++ b/chrome/test/data/textinput/textarea_with_preset_text.html @@ -0,0 +1,9 @@ +<html> + <head> + <script src="textinput_helper.js"></script> + </head> + <body> + <textarea id="empty_textarea"></textarea> + <textarea id="filled_textarea">abcde</textarea> + </body> +</html> diff --git a/content/renderer/render_view_impl.cc b/content/renderer/render_view_impl.cc index 62058bb..23c01cd 100644 --- a/content/renderer/render_view_impl.cc +++ b/content/renderer/render_view_impl.cc @@ -621,6 +621,7 @@ RenderViewImpl::RenderViewImpl(RenderViewImplParams* params) history_list_length_(0), target_url_status_(TARGET_NONE), selection_text_offset_(0), + selection_range_(ui::Range::InvalidRange()), cached_is_main_frame_pinned_to_left_(false), cached_is_main_frame_pinned_to_right_(false), cached_has_main_frame_horizontal_scrollbar_(false), |