Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(531)

Unified Diff: views/controls/textfield/native_textfield_views_unittest.cc

Issue 5972008: views: Improve cursor movements on word boundaries. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Add a test with leading whitespace. Created 9 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: views/controls/textfield/native_textfield_views_unittest.cc
diff --git a/views/controls/textfield/native_textfield_views_unittest.cc b/views/controls/textfield/native_textfield_views_unittest.cc
index 08ad9ab50b119916d52846f08fce68372a065a20..b571ed39e3bbb02d90d09b58e7fa87f9aca61cc2 100644
--- a/views/controls/textfield/native_textfield_views_unittest.cc
+++ b/views/controls/textfield/native_textfield_views_unittest.cc
@@ -249,4 +249,54 @@ TEST_F(NativeTextfieldViewsTest, TestOnKeyPressReturnValue) {
EXPECT_FALSE(SendKeyEventToTextfieldViews(app::VKEY_DOWN));
}
+TEST_F(NativeTextfieldViewsTest, CursorMovement) {
+ InitTextfield(Textfield::STYLE_DEFAULT);
+
+ // Test with trailing whitespace.
+ textfield_->SetText(ASCIIToUTF16("one two hre "));
+
+ // Send the cursor at the end.
+ SendKeyEventToTextfieldViews(app::VKEY_END);
+
+ // Ctrl+Left should move the cursor just before the last word.
+ SendKeyEventToTextfieldViews(app::VKEY_LEFT, false, true);
+ SendKeyEventToTextfieldViews(app::VKEY_T);
+ EXPECT_STR_EQ("one two thre ", textfield_->text());
+ EXPECT_STR_EQ("one two thre ", last_contents_);
+
+ // Ctrl+Right should move the cursor to the end of the last word.
+ SendKeyEventToTextfieldViews(app::VKEY_RIGHT, false, true);
+ SendKeyEventToTextfieldViews(app::VKEY_E);
+ EXPECT_STR_EQ("one two three ", textfield_->text());
+ EXPECT_STR_EQ("one two three ", last_contents_);
+
+ // Ctrl+Right again should move the cursor to the end.
+ SendKeyEventToTextfieldViews(app::VKEY_RIGHT, false, true);
+ SendKeyEventToTextfieldViews(app::VKEY_BACK);
+ EXPECT_STR_EQ("one two three", textfield_->text());
+ EXPECT_STR_EQ("one two three", last_contents_);
+
+ // Test with leading whitespace.
+ textfield_->SetText(ASCIIToUTF16(" ne two"));
+
+ // Send the cursor at the beginning.
+ SendKeyEventToTextfieldViews(app::VKEY_HOME);
+
+ // Ctrl+Right, then Ctrl+Left should move the cursor to the beginning of the
+ // first word.
+ SendKeyEventToTextfieldViews(app::VKEY_RIGHT, false, true);
+ SendKeyEventToTextfieldViews(app::VKEY_LEFT, false, true);
+ SendKeyEventToTextfieldViews(app::VKEY_O);
+ EXPECT_STR_EQ(" one two", textfield_->text());
+ EXPECT_STR_EQ(" one two", last_contents_);
+
+ // Ctrl+Left to move the cursor to the beginning of the first word.
+ SendKeyEventToTextfieldViews(app::VKEY_LEFT, false, true);
+ // Ctrl+Left again should move the cursor back to the very beginning.
+ SendKeyEventToTextfieldViews(app::VKEY_LEFT, false, true);
+ SendKeyEventToTextfieldViews(app::VKEY_DELETE);
+ EXPECT_STR_EQ("one two", textfield_->text());
+ EXPECT_STR_EQ("one two", last_contents_);
+}
+
} // namespace views
« no previous file with comments | « views/controls/textfield/native_textfield_views.cc ('k') | views/controls/textfield/textfield_views_model.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698