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 cf5959d5d97e45c26f92206c4238f25ba6ccbe0a..249cb33110a6bc1d63891c189ce968950745b072 100644 |
| --- a/ui/views/controls/textfield/textfield_unittest.cc |
| +++ b/ui/views/controls/textfield/textfield_unittest.cc |
| @@ -42,6 +42,8 @@ |
| #if defined(OS_WIN) |
| #include "base/win/windows_version.h" |
| +#elif defined(OS_LINUX) && !defined(OS_CHROMEOS) |
|
oshima
2014/06/04 00:56:15
I somehow thought we recommend if/endif for each c
msw
2014/06/04 01:02:54
Changed to match that pattern.
|
| +#include "ui/events/linux/text_edit_key_bindings_delegate_auralinux.h" |
| #endif |
| using base::ASCIIToUTF16; |
| @@ -163,12 +165,6 @@ class TextfieldTest : public ViewsTestBase, public TextfieldController { |
| last_contents_ = new_contents; |
| } |
| - virtual bool HandleKeyEvent(Textfield* sender, |
| - const ui::KeyEvent& key_event) OVERRIDE { |
| - // TODO(oshima): figure out how to test the keystroke. |
| - return false; |
| - } |
| - |
| virtual void OnBeforeUserAction(Textfield* sender) OVERRIDE { |
| ++on_before_user_action_; |
| } |
| @@ -532,7 +528,7 @@ TEST_F(TextfieldTest, TextInputType) { |
| EXPECT_EQ(ui::TEXT_INPUT_TYPE_PASSWORD, textfield_->GetTextInputType()); |
| } |
| -TEST_F(TextfieldTest, OnKeyPressReturnValueTest) { |
| +TEST_F(TextfieldTest, OnKeyPress) { |
| InitTextfield(); |
| // Character keys are handled by the input method. |
| @@ -579,6 +575,53 @@ TEST_F(TextfieldTest, OnKeyPressReturnValueTest) { |
| textfield_->clear(); |
| } |
| +// Tests that default key bindings are handled even with a delegate installed. |
| +TEST_F(TextfieldTest, OnKeyPressBinding) { |
| + InitTextfield(); |
| + |
| +#if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| + // Install a TextEditKeyBindingsDelegateAuraLinux that does nothing. |
| + class TestDelegate : public ui::TextEditKeyBindingsDelegateAuraLinux { |
| + public: |
| + TestDelegate() {} |
| + virtual ~TestDelegate() {} |
| + |
| + virtual bool MatchEvent( |
| + const ui::Event& event, |
| + std::vector<ui::TextEditCommandAuraLinux>* commands) OVERRIDE { |
| + return false; |
| + } |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(TestDelegate); |
| + }; |
| + |
| + TestDelegate delegate; |
| + ui::SetTextEditKeyBindingsDelegate(&delegate); |
| +#endif |
| + |
| + SendKeyEvent(ui::VKEY_A, false, false); |
| + EXPECT_STR_EQ("a", textfield_->text()); |
| + textfield_->clear(); |
| + |
| + // Undo/Redo command keys are handled by the textfield. |
| + SendKeyEvent(ui::VKEY_Z, false, true); |
| + EXPECT_TRUE(textfield_->key_received()); |
| + EXPECT_TRUE(textfield_->key_handled()); |
| + EXPECT_TRUE(textfield_->text().empty()); |
| + textfield_->clear(); |
| + |
| + SendKeyEvent(ui::VKEY_Z, true, true); |
| + EXPECT_TRUE(textfield_->key_received()); |
| + EXPECT_TRUE(textfield_->key_handled()); |
| + EXPECT_STR_EQ("a", textfield_->text()); |
| + textfield_->clear(); |
| + |
| +#if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| + ui::SetTextEditKeyBindingsDelegate(NULL); |
|
oshima
2014/06/04 00:56:15
optional: consider using scoped object to set/rese
msw
2014/06/04 01:02:54
Not worth it for one test, IMO.
|
| +#endif |
| +} |
| + |
| TEST_F(TextfieldTest, CursorMovement) { |
| InitTextfield(); |