| 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 38bf44d2e778898195f4d37a0815eea98db0cb85..8a8f9ace8f5cbff3e873ee1ce109cc0c0cc10c20 100644
|
| --- a/ui/views/controls/textfield/textfield_unittest.cc
|
| +++ b/ui/views/controls/textfield/textfield_unittest.cc
|
| @@ -37,6 +37,10 @@
|
| #include "base/win/windows_version.h"
|
| #endif
|
|
|
| +#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
|
| +#include "ui/events/linux/text_edit_key_bindings_delegate_auralinux.h"
|
| +#endif
|
| +
|
| using base::ASCIIToUTF16;
|
| using base::UTF8ToUTF16;
|
| using base::WideToUTF16;
|
| @@ -142,12 +146,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_;
|
| }
|
| @@ -511,7 +509,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.
|
| @@ -558,6 +556,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);
|
| +#endif
|
| +}
|
| +
|
| TEST_F(TextfieldTest, CursorMovement) {
|
| InitTextfield();
|
|
|
|
|