Chromium Code Reviews| 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..2c2de73841e50a357bd500da6f7c662998e1fefa 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()); |
|
msw
2016/07/22 17:44:03
nit: EXPECT_TRUE(textfield2->text().empty())
karandeepb
2016/07/25 06:38:11
Done.
|
| + |
| + // 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) |
| + |
| TEST_F(TextfieldTest, CutCopyPaste) { |
| InitTextfield(); |