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

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

Issue 6267002: Implement double/triple click functionality in views textfield. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: refactoring Created 9 years, 11 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
« no previous file with comments | « views/controls/textfield/textfield_views_model.cc ('k') | views/event.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: views/controls/textfield/textfield_views_model_unittest.cc
diff --git a/views/controls/textfield/textfield_views_model_unittest.cc b/views/controls/textfield/textfield_views_model_unittest.cc
index 1c45d74e1c51fa4e0f16efd201501dd0154dd90d..b0a29c49d4d067687cdaf771a281b6972383477b 100644
--- a/views/controls/textfield/textfield_views_model_unittest.cc
+++ b/views/controls/textfield/textfield_views_model_unittest.cc
@@ -361,6 +361,49 @@ TEST_F(TextfieldViewsModelTest, Clipboard) {
EXPECT_EQ(29U, model.cursor_pos());
}
+void SelectWordTestVerifier(TextfieldViewsModel &model,
+ const std::string &expected_selected_string, size_t expected_cursor_pos) {
+ EXPECT_STR_EQ(expected_selected_string, model.GetSelectedText());
+ EXPECT_EQ(expected_cursor_pos, model.cursor_pos());
+}
+
+TEST_F(TextfieldViewsModelTest, SelectWordTest) {
+ TextfieldViewsModel model;
+ model.Append(ASCIIToUTF16(" HELLO !! WO RLD "));
+
+ // Test when cursor is at the beginning.
+ model.MoveCursorToStart(false);
+ model.SelectWord();
+ SelectWordTestVerifier(model, " ", 2U);
+
+ // Test when cursor is at the beginning of a word.
+ model.MoveCursorTo(2U, false);
+ model.SelectWord();
+ SelectWordTestVerifier(model, "HELLO", 7U);
+
+ // Test when cursor is at the end of a word.
+ model.MoveCursorTo(15U, false);
+ model.SelectWord();
+ SelectWordTestVerifier(model, "WO", 15U);
+
+ // Test when cursor is somewhere in a non-alph-numeric fragment.
+ for (size_t cursor_pos = 8; cursor_pos < 13U; cursor_pos++) {
+ model.MoveCursorTo(cursor_pos, false);
+ model.SelectWord();
+ SelectWordTestVerifier(model, " !! ", 13U);
+ }
+
+ // Test when cursor is somewhere in a whitespace fragment.
+ model.MoveCursorTo(17U, false);
+ model.SelectWord();
+ SelectWordTestVerifier(model, " ", 20U);
+
+ // Test when cursor is at the end.
+ model.MoveCursorToEnd(false);
+ model.SelectWord();
+ SelectWordTestVerifier(model, " ", 24U);
+}
+
TEST_F(TextfieldViewsModelTest, RangeTest) {
TextfieldViewsModel model;
model.Append(ASCIIToUTF16("HELLO WORLD"));
« no previous file with comments | « views/controls/textfield/textfield_views_model.cc ('k') | views/event.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698