OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "app/keyboard_codes.h" | 5 #include "app/keyboard_codes.h" |
6 #include "base/message_loop.h" | 6 #include "base/message_loop.h" |
7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 #include "views/controls/textfield/native_textfield_views.h" | 9 #include "views/controls/textfield/native_textfield_views.h" |
10 #include "views/controls/textfield/textfield.h" | 10 #include "views/controls/textfield/textfield.h" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 Widget::DeleteOnDestroy, | 64 Widget::DeleteOnDestroy, |
65 Widget::DontMirrorOriginInRTL); | 65 Widget::DontMirrorOriginInRTL); |
66 widget_->Init(NULL, gfx::Rect()); | 66 widget_->Init(NULL, gfx::Rect()); |
67 widget_->SetContentsView(textfield_); | 67 widget_->SetContentsView(textfield_); |
68 textfield_view_ | 68 textfield_view_ |
69 = static_cast<NativeTextfieldViews*>(textfield_->native_wrapper()); | 69 = static_cast<NativeTextfieldViews*>(textfield_->native_wrapper()); |
70 DCHECK(textfield_view_); | 70 DCHECK(textfield_view_); |
71 model_ = textfield_view_->model_.get(); | 71 model_ = textfield_view_->model_.get(); |
72 } | 72 } |
73 | 73 |
74 void SendKeyEventToTextfieldViews(app::KeyboardCode key_code, | 74 bool SendKeyEventToTextfieldViews(app::KeyboardCode key_code, |
75 bool shift, | 75 bool shift, |
76 bool control) { | 76 bool control) { |
77 int flags = (shift ? KeyEvent::EF_SHIFT_DOWN : 0) | | 77 int flags = (shift ? KeyEvent::EF_SHIFT_DOWN : 0) | |
78 (control ? KeyEvent::EF_CONTROL_DOWN : 0); | 78 (control ? KeyEvent::EF_CONTROL_DOWN : 0); |
79 KeyEvent event(KeyEvent::ET_KEY_PRESSED, key_code, flags, 1, 0); | 79 KeyEvent event(KeyEvent::ET_KEY_PRESSED, key_code, flags, 1, 0); |
80 textfield_view_->OnKeyPressed(event); | 80 return textfield_view_->OnKeyPressed(event); |
81 } | 81 } |
82 | 82 |
83 void SendKeyEventToTextfieldViews(app::KeyboardCode key_code) { | 83 bool SendKeyEventToTextfieldViews(app::KeyboardCode key_code) { |
84 SendKeyEventToTextfieldViews(key_code, false, false); | 84 return SendKeyEventToTextfieldViews(key_code, false, false); |
85 } | 85 } |
86 | 86 |
87 protected: | 87 protected: |
88 // We need widget to populate wrapper class. | 88 // We need widget to populate wrapper class. |
89 Widget* widget_; | 89 Widget* widget_; |
90 | 90 |
91 Textfield* textfield_; | 91 Textfield* textfield_; |
92 NativeTextfieldViews* textfield_view_; | 92 NativeTextfieldViews* textfield_view_; |
93 TextfieldViewsModel* model_; | 93 TextfieldViewsModel* model_; |
94 | 94 |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 | 216 |
217 TEST_F(NativeTextfieldViewsTest, PasswordTest) { | 217 TEST_F(NativeTextfieldViewsTest, PasswordTest) { |
218 InitTextfield(Textfield::STYLE_PASSWORD); | 218 InitTextfield(Textfield::STYLE_PASSWORD); |
219 textfield_->SetText(ASCIIToUTF16("my password")); | 219 textfield_->SetText(ASCIIToUTF16("my password")); |
220 // Just to make sure the text() and callback returns | 220 // Just to make sure the text() and callback returns |
221 // the actual text instead of "*". | 221 // the actual text instead of "*". |
222 EXPECT_STR_EQ("my password", textfield_->text()); | 222 EXPECT_STR_EQ("my password", textfield_->text()); |
223 EXPECT_STR_EQ("my password", last_contents_); | 223 EXPECT_STR_EQ("my password", last_contents_); |
224 } | 224 } |
225 | 225 |
| 226 TEST_F(NativeTextfieldViewsTest, TestOnKeyPressReturnValue) { |
| 227 InitTextfield(Textfield::STYLE_DEFAULT); |
| 228 EXPECT_TRUE(SendKeyEventToTextfieldViews(app::VKEY_A)); |
| 229 // F24, up/down key won't be handled. |
| 230 EXPECT_FALSE(SendKeyEventToTextfieldViews(app::VKEY_F24)); |
| 231 EXPECT_FALSE(SendKeyEventToTextfieldViews(app::VKEY_UP)); |
| 232 EXPECT_FALSE(SendKeyEventToTextfieldViews(app::VKEY_DOWN)); |
| 233 } |
| 234 |
226 } // namespace views | 235 } // namespace views |
OLD | NEW |