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

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

Issue 7826039: Identify the omnibox as a URL field. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 3 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/auto_reset.h" 5 #include "base/auto_reset.h"
6 #include "base/bind.h" 6 #include "base/bind.h"
7 #include "base/bind_helpers.h" 7 #include "base/bind_helpers.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/pickle.h" 10 #include "base/pickle.h"
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 View* GetFocusedView() { 218 View* GetFocusedView() {
219 return widget_->GetFocusManager()->GetFocusedView(); 219 return widget_->GetFocusManager()->GetFocusedView();
220 } 220 }
221 221
222 int GetCursorPositionX(int cursor_pos) { 222 int GetCursorPositionX(int cursor_pos) {
223 gfx::RenderText* render_text = textfield_view_->GetRenderText(); 223 gfx::RenderText* render_text = textfield_view_->GetRenderText();
224 return render_text->GetCursorBounds( 224 return render_text->GetCursorBounds(
225 gfx::SelectionModel(cursor_pos), false).x(); 225 gfx::SelectionModel(cursor_pos), false).x();
226 } 226 }
227 227
228 // Wrap for visibility in test classes.
229 ui::TextInputType GetTextInputType() {
230 return textfield_view_->GetTextInputType();
231 }
232
228 // We need widget to populate wrapper class. 233 // We need widget to populate wrapper class.
229 Widget* widget_; 234 Widget* widget_;
230 235
231 TestTextfield* textfield_; 236 TestTextfield* textfield_;
232 NativeTextfieldViews* textfield_view_; 237 NativeTextfieldViews* textfield_view_;
233 TextfieldViewsModel* model_; 238 TextfieldViewsModel* model_;
234 239
235 // The string from Controller::ContentsChanged callback. 240 // The string from Controller::ContentsChanged callback.
236 string16 last_contents_; 241 string16 last_contents_;
237 242
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 #if defined(OS_WIN) 397 #if defined(OS_WIN)
393 EXPECT_STR_EQ(" two three four", textfield_->text()); 398 EXPECT_STR_EQ(" two three four", textfield_->text());
394 #else 399 #else
395 EXPECT_STR_EQ(" two", textfield_->text()); 400 EXPECT_STR_EQ(" two", textfield_->text());
396 #endif 401 #endif
397 } 402 }
398 403
399 TEST_F(NativeTextfieldViewsTest, PasswordTest) { 404 TEST_F(NativeTextfieldViewsTest, PasswordTest) {
400 InitTextfield(Textfield::STYLE_PASSWORD); 405 InitTextfield(Textfield::STYLE_PASSWORD);
401 406
407 EXPECT_EQ(ui::TEXT_INPUT_TYPE_PASSWORD, GetTextInputType());
408
402 last_contents_.clear(); 409 last_contents_.clear();
403 textfield_->SetText(ASCIIToUTF16("my password")); 410 textfield_->SetText(ASCIIToUTF16("my password"));
404 // Just to make sure the text() and callback returns 411 // Just to make sure the text() and callback returns
405 // the actual text instead of "*". 412 // the actual text instead of "*".
406 EXPECT_STR_EQ("my password", textfield_->text()); 413 EXPECT_STR_EQ("my password", textfield_->text());
407 EXPECT_TRUE(last_contents_.empty()); 414 EXPECT_TRUE(last_contents_.empty());
408 } 415 }
409 416
417 TEST_F(NativeTextfieldViewsTest, UrlTest) {
418 InitTextfield(Textfield::STYLE_URL);
419 EXPECT_EQ(ui::TEXT_INPUT_TYPE_URL, GetTextInputType());
420 }
421
410 TEST_F(NativeTextfieldViewsTest, OnKeyPressReturnValueTest) { 422 TEST_F(NativeTextfieldViewsTest, OnKeyPressReturnValueTest) {
411 InitTextfield(Textfield::STYLE_DEFAULT); 423 InitTextfield(Textfield::STYLE_DEFAULT);
412 424
413 // Character keys will be handled by input method. 425 // Character keys will be handled by input method.
414 SendKeyEvent(ui::VKEY_A); 426 SendKeyEvent(ui::VKEY_A);
415 EXPECT_TRUE(textfield_->key_received()); 427 EXPECT_TRUE(textfield_->key_received());
416 EXPECT_FALSE(textfield_->key_handled()); 428 EXPECT_FALSE(textfield_->key_handled());
417 textfield_->clear(); 429 textfield_->clear();
418 430
419 // Home will be handled. 431 // Home will be handled.
(...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after
1081 EXPECT_STR_EQ("a23", textfield_->text()); 1093 EXPECT_STR_EQ("a23", textfield_->text());
1082 SendKeyEvent(ui::VKEY_B); 1094 SendKeyEvent(ui::VKEY_B);
1083 EXPECT_STR_EQ("ab3", textfield_->text()); 1095 EXPECT_STR_EQ("ab3", textfield_->text());
1084 SendKeyEvent(ui::VKEY_Z, false, true); 1096 SendKeyEvent(ui::VKEY_Z, false, true);
1085 EXPECT_STR_EQ("123", textfield_->text()); 1097 EXPECT_STR_EQ("123", textfield_->text());
1086 SendKeyEvent(ui::VKEY_Y, false, true); 1098 SendKeyEvent(ui::VKEY_Y, false, true);
1087 EXPECT_STR_EQ("ab3", textfield_->text()); 1099 EXPECT_STR_EQ("ab3", textfield_->text());
1088 } 1100 }
1089 1101
1090 } // namespace views 1102 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698