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

Unified Diff: ui/views/controls/textfield/textfield_model_unittest.cc

Issue 2119813002: views::Textfield: Implement yank editing command. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address review. Created 4 years, 5 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 | « ui/views/controls/textfield/textfield_model.cc ('k') | ui/views/controls/textfield/textfield_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/controls/textfield/textfield_model_unittest.cc
diff --git a/ui/views/controls/textfield/textfield_model_unittest.cc b/ui/views/controls/textfield/textfield_model_unittest.cc
index 3663816813076c8039b37d1455dad763eb97b0c6..62552abd4ab96db4023dccffe88b653a31262b8c 100644
--- a/ui/views/controls/textfield/textfield_model_unittest.cc
+++ b/ui/views/controls/textfield/textfield_model_unittest.cc
@@ -55,6 +55,14 @@ class TextfieldModelTest : public ViewsTestBase,
composition_text_confirmed_or_cleared_(false) {
}
+ // ::testing::Test:
+ void TearDown() override {
+ // Clear kill buffer used for "Yank" text editing command so that no state
+ // persists between tests.
+ TextfieldModel::ClearKillBuffer();
+ ViewsTestBase::TearDown();
+ }
+
void OnCompositionTextConfirmedOrCleared() override {
composition_text_confirmed_or_cleared_ = true;
}
@@ -1653,4 +1661,52 @@ TEST_F(TextfieldModelTest, Transpose) {
}
}
+TEST_F(TextfieldModelTest, Yank) {
+ TextfieldModel model(nullptr);
+ model.SetText(base::ASCIIToUTF16("abcde"));
+ model.SelectRange(gfx::Range(1, 3));
+
+ // Delete selection but don't add to kill buffer.
+ model.Delete(false);
+ EXPECT_STR_EQ("ade", model.text());
+
+ // Since the kill buffer is empty, yank should cause no change.
+ model.Yank();
+ EXPECT_STR_EQ("ade", model.text());
+
+ // Delete selection and add to kill buffer.
+ model.SelectRange(gfx::Range(0, 1));
+ model.Delete(true);
+ EXPECT_STR_EQ("de", model.text());
+
+ // Yank twice.
+ model.Yank();
+ model.Yank();
+ EXPECT_STR_EQ("aade", model.text());
+
+ // Ensure an empty deletion does not modify the kill buffer.
+ model.SelectRange(gfx::Range(4));
+ model.Delete(true);
+ model.Yank();
+ EXPECT_STR_EQ("aadea", model.text());
+
+ // Backspace twice but don't add to kill buffer.
+ model.Backspace(false);
+ model.Backspace(false);
+ EXPECT_STR_EQ("aad", model.text());
+
+ // Ensure kill buffer is not modified.
+ model.Yank();
+ EXPECT_STR_EQ("aada", model.text());
+
+ // Backspace twice, each time modifying the kill buffer.
+ model.Backspace(true);
+ model.Backspace(true);
+ EXPECT_STR_EQ("aa", model.text());
+
+ // Ensure yanking inserts the modified kill buffer text.
+ model.Yank();
+ EXPECT_STR_EQ("aad", model.text());
+}
+
} // namespace views
« no previous file with comments | « ui/views/controls/textfield/textfield_model.cc ('k') | ui/views/controls/textfield/textfield_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698