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

Unified Diff: ui/views/controls/textfield/textfield_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 comments. 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
Index: ui/views/controls/textfield/textfield_unittest.cc
diff --git a/ui/views/controls/textfield/textfield_unittest.cc b/ui/views/controls/textfield/textfield_unittest.cc
index c6e4fba368c5df158a3a96dcd860b39c0e45603f..a9fabf73181b7063a63243b28db7c2016ea5b6bd 100644
--- a/ui/views/controls/textfield/textfield_unittest.cc
+++ b/ui/views/controls/textfield/textfield_unittest.cc
@@ -1838,8 +1838,9 @@ TEST_F(TextfieldTest, UndoRedoTest) {
}
// Most platforms support Ctrl+Y as an alternative to Ctrl+Shift+Z, but on Mac
-// that is bound to "Show full history", so is not mapped as an editing
-// command. So, on Mac, send Cmd+Shift+Z.
+// Ctrl+Y is bound to "Yank" and Cmd+Y is bound to "Show full history". So, on
+// Mac, Cmd+Shift+Z is sent for the tests above and the Ctrl+Y test below is
+// skipped.
#if !defined(OS_MACOSX)
// Test that Ctrl+Y works for Redo, as well as Ctrl+Shift+Z.
@@ -1859,6 +1860,56 @@ TEST_F(TextfieldTest, RedoWithCtrlY) {
#endif // !defined(OS_MACOSX)
+// Non-Mac platforms don't have a key binding for Yank. Since this test is only
+// run on Mac, it uses some Mac specific key bindings.
+#if defined(OS_MACOSX)
+
+TEST_F(TextfieldTest, Yank) {
+ InitTextfields(2);
+ textfield_->SetText(ASCIIToUTF16("abcdef"));
+ textfield_->SelectRange(gfx::Range(2, 4));
+
+ // Press Ctrl+Y to yank.
+ SendKeyPress(ui::VKEY_Y, ui::EF_CONTROL_DOWN);
+
+ // Initially the kill buffer should be empty. Hence yanking should delete the
+ // selected text.
+ EXPECT_STR_EQ("abef", textfield_->text());
+ EXPECT_EQ(gfx::Range(2), textfield_->GetSelectedRange());
+
+ // Press Ctrl+K to delete to end of paragraph. This should place the deleted
+ // text in the kill buffer.
+ SendKeyPress(ui::VKEY_K, ui::EF_CONTROL_DOWN);
+
+ EXPECT_STR_EQ("ab", textfield_->text());
+ EXPECT_EQ(gfx::Range(2), textfield_->GetSelectedRange());
+
+ // Yank twice.
+ SendKeyPress(ui::VKEY_Y, ui::EF_CONTROL_DOWN);
+ SendKeyPress(ui::VKEY_Y, ui::EF_CONTROL_DOWN);
+ EXPECT_STR_EQ("abefef", textfield_->text());
+ EXPECT_EQ(gfx::Range(6), textfield_->GetSelectedRange());
+
+ // Verify pressing backspace does not modify the kill buffer.
+ SendKeyEvent(ui::VKEY_BACK);
+ SendKeyPress(ui::VKEY_Y, ui::EF_CONTROL_DOWN);
+ EXPECT_STR_EQ("abefeef", textfield_->text());
+ EXPECT_EQ(gfx::Range(7), textfield_->GetSelectedRange());
+
+ // Move focus to next textfield.
+ widget_->GetFocusManager()->AdvanceFocus(false);
+ EXPECT_EQ(2, GetFocusedView()->id());
+ Textfield* textfield2 = static_cast<Textfield*>(GetFocusedView());
+ EXPECT_STR_EQ("", textfield2->text());
+
+ // Verify yanked text persists across multiple textfields.
+ SendKeyPress(ui::VKEY_Y, ui::EF_CONTROL_DOWN);
+ EXPECT_STR_EQ("ef", textfield2->text());
+ EXPECT_EQ(gfx::Range(2), textfield2->GetSelectedRange());
+}
+
+#endif // defined(OS_MACOSX)
tapted 2016/07/20 06:32:21 nit: extra space before //
karandeepb 2016/07/20 07:51:30 Done.
+
TEST_F(TextfieldTest, CutCopyPaste) {
InitTextfield();

Powered by Google App Engine
This is Rietveld 408576698