Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(222)

Side by Side Diff: views/controls/textfield/native_textfield_views_unittest.cc

Issue 6068005: views: Fix shifted keyevents in textfield. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Add test Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « views/controls/textfield/native_textfield_views.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 void SendKeyEventToTextfieldViews(app::KeyboardCode key_code,
75 bool shift, 75 bool shift,
76 bool control) { 76 bool control,
77 bool capslock = false) {
oshima 2011/01/04 20:23:41 default argument is not allowed by style guide.
sadrul 2011/01/04 20:29:27 Ah, noted. Fixed.
77 int flags = (shift ? KeyEvent::EF_SHIFT_DOWN : 0) | 78 int flags = (shift ? KeyEvent::EF_SHIFT_DOWN : 0) |
78 (control ? KeyEvent::EF_CONTROL_DOWN : 0); 79 (control ? KeyEvent::EF_CONTROL_DOWN : 0) |
80 (capslock ? KeyEvent::EF_CAPS_LOCK_DOWN : 0);
79 KeyEvent event(KeyEvent::ET_KEY_PRESSED, key_code, flags, 1, 0); 81 KeyEvent event(KeyEvent::ET_KEY_PRESSED, key_code, flags, 1, 0);
80 textfield_view_->OnKeyPressed(event); 82 textfield_view_->OnKeyPressed(event);
81 } 83 }
82 84
83 void SendKeyEventToTextfieldViews(app::KeyboardCode key_code) { 85 void SendKeyEventToTextfieldViews(app::KeyboardCode key_code) {
84 SendKeyEventToTextfieldViews(key_code, false, false); 86 SendKeyEventToTextfieldViews(key_code, false, false);
85 } 87 }
86 88
87 protected: 89 protected:
88 // We need widget to populate wrapper class. 90 // We need widget to populate wrapper class.
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 TEST_F(NativeTextfieldViewsTest, KeyTest) { 135 TEST_F(NativeTextfieldViewsTest, KeyTest) {
134 InitTextfield(Textfield::STYLE_DEFAULT); 136 InitTextfield(Textfield::STYLE_DEFAULT);
135 SendKeyEventToTextfieldViews(app::VKEY_C, true, false); 137 SendKeyEventToTextfieldViews(app::VKEY_C, true, false);
136 EXPECT_STR_EQ("C", textfield_->text()); 138 EXPECT_STR_EQ("C", textfield_->text());
137 EXPECT_STR_EQ("C", last_contents_); 139 EXPECT_STR_EQ("C", last_contents_);
138 last_contents_.clear(); 140 last_contents_.clear();
139 141
140 SendKeyEventToTextfieldViews(app::VKEY_R, false, false); 142 SendKeyEventToTextfieldViews(app::VKEY_R, false, false);
141 EXPECT_STR_EQ("Cr", textfield_->text()); 143 EXPECT_STR_EQ("Cr", textfield_->text());
142 EXPECT_STR_EQ("Cr", last_contents_); 144 EXPECT_STR_EQ("Cr", last_contents_);
145
146 textfield_->SetText(ASCIIToUTF16(""));
147 SendKeyEventToTextfieldViews(app::VKEY_C, true, false, true);
148 SendKeyEventToTextfieldViews(app::VKEY_C, false, false, true);
149 SendKeyEventToTextfieldViews(app::VKEY_1, false, false, true);
150 SendKeyEventToTextfieldViews(app::VKEY_1, true, false, true);
151 SendKeyEventToTextfieldViews(app::VKEY_1, true, false, false);
152 EXPECT_STR_EQ("cC1!!", textfield_->text());
153 EXPECT_STR_EQ("cC1!!", last_contents_);
143 } 154 }
144 155
145 TEST_F(NativeTextfieldViewsTest, ControlAndSelectTest) { 156 TEST_F(NativeTextfieldViewsTest, ControlAndSelectTest) {
146 // Insert a test string in a textfield. 157 // Insert a test string in a textfield.
147 InitTextfield(Textfield::STYLE_DEFAULT); 158 InitTextfield(Textfield::STYLE_DEFAULT);
148 textfield_->SetText(ASCIIToUTF16("one two three")); 159 textfield_->SetText(ASCIIToUTF16("one two three"));
149 SendKeyEventToTextfieldViews(app::VKEY_RIGHT, 160 SendKeyEventToTextfieldViews(app::VKEY_RIGHT,
150 true /* shift */, false /* control */); 161 true /* shift */, false /* control */);
151 SendKeyEventToTextfieldViews(app::VKEY_RIGHT, true, false); 162 SendKeyEventToTextfieldViews(app::VKEY_RIGHT, true, false);
152 SendKeyEventToTextfieldViews(app::VKEY_RIGHT, true, false); 163 SendKeyEventToTextfieldViews(app::VKEY_RIGHT, true, false);
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 TEST_F(NativeTextfieldViewsTest, PasswordTest) { 228 TEST_F(NativeTextfieldViewsTest, PasswordTest) {
218 InitTextfield(Textfield::STYLE_PASSWORD); 229 InitTextfield(Textfield::STYLE_PASSWORD);
219 textfield_->SetText(ASCIIToUTF16("my password")); 230 textfield_->SetText(ASCIIToUTF16("my password"));
220 // Just to make sure the text() and callback returns 231 // Just to make sure the text() and callback returns
221 // the actual text instead of "*". 232 // the actual text instead of "*".
222 EXPECT_STR_EQ("my password", textfield_->text()); 233 EXPECT_STR_EQ("my password", textfield_->text());
223 EXPECT_STR_EQ("my password", last_contents_); 234 EXPECT_STR_EQ("my password", last_contents_);
224 } 235 }
225 236
226 } // namespace views 237 } // namespace views
OLDNEW
« no previous file with comments | « views/controls/textfield/native_textfield_views.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698