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 e5ddf39b7593f4fb96c6dde5352fe83cc1dbe07c..284421685c06eab308a6ca416bad5a57020d2b91 100644 |
| --- a/ui/views/controls/textfield/textfield_unittest.cc |
| +++ b/ui/views/controls/textfield/textfield_unittest.cc |
| @@ -1069,17 +1069,19 @@ TEST_F(TextfieldTest, DragAndDrop_ToTheRight) { |
| textfield_->OnDragDone(); |
| // Undo/Redo the drag&drop change. |
| - SendKeyEvent(ui::VKEY_Z, false, true); |
| + bool shift = false; |
|
msw
2015/02/19 02:56:21
nit: I vastly prefer inline true/false to adding |
tapted
2015/02/19 03:19:10
Done.
|
| + SendKeyEvent(ui::VKEY_Z, shift, true); |
| EXPECT_STR_EQ("hello world", textfield_->text()); |
| - SendKeyEvent(ui::VKEY_Z, false, true); |
| + SendKeyEvent(ui::VKEY_Z, shift, true); |
| EXPECT_STR_EQ("", textfield_->text()); |
| - SendKeyEvent(ui::VKEY_Z, false, true); |
| + SendKeyEvent(ui::VKEY_Z, shift, true); |
| EXPECT_STR_EQ("", textfield_->text()); |
| - SendKeyEvent(ui::VKEY_Y, false, true); |
| + shift = true; // Use Ctrl+Shift+Z for Redo. |
| + SendKeyEvent(ui::VKEY_Z, shift, true); |
| EXPECT_STR_EQ("hello world", textfield_->text()); |
| - SendKeyEvent(ui::VKEY_Y, false, true); |
| + SendKeyEvent(ui::VKEY_Z, shift, true); |
| EXPECT_STR_EQ("h welloorld", textfield_->text()); |
| - SendKeyEvent(ui::VKEY_Y, false, true); |
| + SendKeyEvent(ui::VKEY_Z, shift, true); |
| EXPECT_STR_EQ("h welloorld", textfield_->text()); |
| } |
| @@ -1122,17 +1124,19 @@ TEST_F(TextfieldTest, DragAndDrop_ToTheLeft) { |
| textfield_->OnDragDone(); |
| // Undo/Redo the drag&drop change. |
| - SendKeyEvent(ui::VKEY_Z, false, true); |
| + bool shift = false; |
| + SendKeyEvent(ui::VKEY_Z, shift, true); |
| EXPECT_STR_EQ("hello world", textfield_->text()); |
| - SendKeyEvent(ui::VKEY_Z, false, true); |
| + SendKeyEvent(ui::VKEY_Z, shift, true); |
| EXPECT_STR_EQ("", textfield_->text()); |
| - SendKeyEvent(ui::VKEY_Z, false, true); |
| + SendKeyEvent(ui::VKEY_Z, shift, true); |
| EXPECT_STR_EQ("", textfield_->text()); |
| - SendKeyEvent(ui::VKEY_Y, false, true); |
| + shift = true; // Use Ctrl+Shift+Z for Redo. |
| + SendKeyEvent(ui::VKEY_Z, shift, true); |
| EXPECT_STR_EQ("hello world", textfield_->text()); |
| - SendKeyEvent(ui::VKEY_Y, false, true); |
| + SendKeyEvent(ui::VKEY_Z, shift, true); |
| EXPECT_STR_EQ("h worlellod", textfield_->text()); |
| - SendKeyEvent(ui::VKEY_Y, false, true); |
| + SendKeyEvent(ui::VKEY_Z, shift, true); |
| EXPECT_STR_EQ("h worlellod", textfield_->text()); |
| } |
| @@ -1345,23 +1349,29 @@ TEST_F(TextfieldTest, UndoRedoTest) { |
| InitTextfield(); |
| SendKeyEvent(ui::VKEY_A); |
| EXPECT_STR_EQ("a", textfield_->text()); |
| - SendKeyEvent(ui::VKEY_Z, false, true); |
| + |
| + bool shift = false; |
| + SendKeyEvent(ui::VKEY_Z, shift, true); |
| EXPECT_STR_EQ("", textfield_->text()); |
| - SendKeyEvent(ui::VKEY_Z, false, true); |
| + SendKeyEvent(ui::VKEY_Z, shift, true); |
| EXPECT_STR_EQ("", textfield_->text()); |
| - SendKeyEvent(ui::VKEY_Y, false, true); |
| + shift = true; // Use Ctrl+Shift+Z for Redo. |
| + SendKeyEvent(ui::VKEY_Z, shift, true); |
| EXPECT_STR_EQ("a", textfield_->text()); |
| - SendKeyEvent(ui::VKEY_Y, false, true); |
| + SendKeyEvent(ui::VKEY_Z, shift, true); |
| EXPECT_STR_EQ("a", textfield_->text()); |
| + shift = false; |
| // AppendText |
| textfield_->AppendText(ASCIIToUTF16("b")); |
| last_contents_.clear(); // AppendText doesn't call ContentsChanged. |
| EXPECT_STR_EQ("ab", textfield_->text()); |
| - SendKeyEvent(ui::VKEY_Z, false, true); |
| + SendKeyEvent(ui::VKEY_Z, shift, true); |
| EXPECT_STR_EQ("a", textfield_->text()); |
| - SendKeyEvent(ui::VKEY_Y, false, true); |
| + shift = true; |
| + SendKeyEvent(ui::VKEY_Z, shift, true); |
| EXPECT_STR_EQ("ab", textfield_->text()); |
| + shift = false; |
| // SetText |
| SendKeyEvent(ui::VKEY_C); |
| @@ -1370,71 +1380,105 @@ TEST_F(TextfieldTest, UndoRedoTest) { |
| EXPECT_STR_EQ("abc", textfield_->text()); |
| textfield_->SetText(ASCIIToUTF16("abc")); |
| EXPECT_STR_EQ("abc", textfield_->text()); |
| - SendKeyEvent(ui::VKEY_Z, false, true); |
| + SendKeyEvent(ui::VKEY_Z, shift, true); |
| EXPECT_STR_EQ("ab", textfield_->text()); |
| - SendKeyEvent(ui::VKEY_Y, false, true); |
| + shift = true; |
| + SendKeyEvent(ui::VKEY_Z, shift, true); |
| EXPECT_STR_EQ("abc", textfield_->text()); |
| - SendKeyEvent(ui::VKEY_Y, false, true); |
| + SendKeyEvent(ui::VKEY_Z, shift, true); |
| EXPECT_STR_EQ("abc", textfield_->text()); |
| + shift = false; |
| + |
| textfield_->SetText(ASCIIToUTF16("123")); |
| textfield_->SetText(ASCIIToUTF16("123")); |
| EXPECT_STR_EQ("123", textfield_->text()); |
| - SendKeyEvent(ui::VKEY_END, false, false); |
| - SendKeyEvent(ui::VKEY_4, false, false); |
| + SendKeyEvent(ui::VKEY_END, shift, false); |
| + SendKeyEvent(ui::VKEY_4, shift, false); |
| EXPECT_STR_EQ("1234", textfield_->text()); |
| last_contents_.clear(); |
| - SendKeyEvent(ui::VKEY_Z, false, true); |
| + SendKeyEvent(ui::VKEY_Z, shift, true); |
| EXPECT_STR_EQ("123", textfield_->text()); |
| - SendKeyEvent(ui::VKEY_Z, false, true); |
| + SendKeyEvent(ui::VKEY_Z, shift, true); |
| // the insert edit "c" and set edit "123" are merged to single edit, |
| // so text becomes "ab" after undo. |
| EXPECT_STR_EQ("ab", textfield_->text()); |
| - SendKeyEvent(ui::VKEY_Z, false, true); |
| + SendKeyEvent(ui::VKEY_Z, shift, true); |
| EXPECT_STR_EQ("a", textfield_->text()); |
| - SendKeyEvent(ui::VKEY_Y, false, true); |
| + shift = true; |
| + SendKeyEvent(ui::VKEY_Z, shift, true); |
| EXPECT_STR_EQ("ab", textfield_->text()); |
| - SendKeyEvent(ui::VKEY_Y, false, true); |
| + SendKeyEvent(ui::VKEY_Z, shift, true); |
| EXPECT_STR_EQ("123", textfield_->text()); |
| - SendKeyEvent(ui::VKEY_Y, false, true); |
| + SendKeyEvent(ui::VKEY_Z, shift, true); |
| EXPECT_STR_EQ("1234", textfield_->text()); |
| + shift = false; |
| // Undoing to the same text shouldn't call ContentsChanged. |
| - SendKeyEvent(ui::VKEY_A, false, true); // select all |
| + SendKeyEvent(ui::VKEY_A, shift, true); // select all |
| SendKeyEvent(ui::VKEY_A); |
| EXPECT_STR_EQ("a", textfield_->text()); |
| SendKeyEvent(ui::VKEY_B); |
| SendKeyEvent(ui::VKEY_C); |
| EXPECT_STR_EQ("abc", textfield_->text()); |
| - SendKeyEvent(ui::VKEY_Z, false, true); |
| + SendKeyEvent(ui::VKEY_Z, shift, true); |
| EXPECT_STR_EQ("1234", textfield_->text()); |
| - SendKeyEvent(ui::VKEY_Y, false, true); |
| + shift = true; |
| + SendKeyEvent(ui::VKEY_Z, shift, true); |
| EXPECT_STR_EQ("abc", textfield_->text()); |
| + shift = false; |
| // Delete/Backspace |
| SendKeyEvent(ui::VKEY_BACK); |
| EXPECT_STR_EQ("ab", textfield_->text()); |
| - SendKeyEvent(ui::VKEY_HOME); |
| + SendHomeEvent(shift); |
| SendKeyEvent(ui::VKEY_DELETE); |
| EXPECT_STR_EQ("b", textfield_->text()); |
| - SendKeyEvent(ui::VKEY_A, false, true); |
| + SendKeyEvent(ui::VKEY_A, shift, true); |
| SendKeyEvent(ui::VKEY_DELETE); |
| EXPECT_STR_EQ("", textfield_->text()); |
| - SendKeyEvent(ui::VKEY_Z, false, true); |
| + SendKeyEvent(ui::VKEY_Z, shift, true); |
| EXPECT_STR_EQ("b", textfield_->text()); |
| - SendKeyEvent(ui::VKEY_Z, false, true); |
| + SendKeyEvent(ui::VKEY_Z, shift, true); |
| EXPECT_STR_EQ("ab", textfield_->text()); |
| - SendKeyEvent(ui::VKEY_Z, false, true); |
| + SendKeyEvent(ui::VKEY_Z, shift, true); |
| EXPECT_STR_EQ("abc", textfield_->text()); |
| - SendKeyEvent(ui::VKEY_Y, false, true); |
| + shift = true; |
| + SendKeyEvent(ui::VKEY_Z, shift, true); |
| EXPECT_STR_EQ("ab", textfield_->text()); |
| - SendKeyEvent(ui::VKEY_Y, false, true); |
| + SendKeyEvent(ui::VKEY_Z, shift, true); |
| EXPECT_STR_EQ("b", textfield_->text()); |
| - SendKeyEvent(ui::VKEY_Y, false, true); |
| + SendKeyEvent(ui::VKEY_Z, shift, true); |
| EXPECT_STR_EQ("", textfield_->text()); |
| - SendKeyEvent(ui::VKEY_Y, false, true); |
| + SendKeyEvent(ui::VKEY_Z, shift, true); |
| EXPECT_STR_EQ("", textfield_->text()); |
| } |
| +// 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. |
| +#if defined(OS_MACOSX) |
|
msw
2015/02/19 02:56:22
nit: I'd just put the test in a !OS_MACOSX block i
tapted
2015/02/19 03:19:10
Done.
|
| +#define MAYBE_RedoWithCtrlY DISABLED_RedoWithCtrlY |
| +#else |
| +#define MAYBE_RedoWithCtrlY RedoWithCtrlY |
| +#endif |
| + |
| +// Test that Ctrl+Y works for Redo, as well as Ctrl+Shift+Z. |
| +TEST_F(TextfieldTest, MAYBE_RedoWithCtrlY) { |
| + InitTextfield(); |
| + SendKeyEvent(ui::VKEY_A); |
| + EXPECT_STR_EQ("a", textfield_->text()); |
| + bool shift = false; |
| + SendKeyEvent(ui::VKEY_Z, shift, true); |
| + EXPECT_STR_EQ("", textfield_->text()); |
| + SendKeyEvent(ui::VKEY_Y, shift, true); |
| + EXPECT_STR_EQ("a", textfield_->text()); |
| + SendKeyEvent(ui::VKEY_Z, shift, true); |
| + EXPECT_STR_EQ("", textfield_->text()); |
| + shift = true; |
| + SendKeyEvent(ui::VKEY_Z, shift, true); |
| + EXPECT_STR_EQ("a", textfield_->text()); |
| +} |
| + |
| TEST_F(TextfieldTest, CutCopyPaste) { |
| InitTextfield(); |