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

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: refactor based on comments 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, InputTypeSetsPassword) {
418 InitTextfield(Textfield::STYLE_DEFAULT);
419
420 // Defaults to TEXT
421 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, GetTextInputType());
422
423 // Setting to passwords also sets password state of textfield.
424 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD);
425 EXPECT_EQ(ui::TEXT_INPUT_TYPE_PASSWORD, GetTextInputType());
426 EXPECT_TRUE(textfield_->IsPassword());
427 }
428
429 TEST_F(NativeTextfieldViewsTest, PasswordSetsInputType) {
430 InitTextfield(Textfield::STYLE_DEFAULT);
431
432 // Defaults to TEXT
433 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, GetTextInputType());
434
435 textfield_->SetPassword(true);
436 EXPECT_EQ(ui::TEXT_INPUT_TYPE_PASSWORD, GetTextInputType());
437
438 textfield_->SetPassword(false);
439 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, GetTextInputType());
440 }
441
442 TEST_F(NativeTextfieldViewsTest, TextInputType) {
443 InitTextfield(Textfield::STYLE_DEFAULT);
444
445 // Defaults to TEXT
446 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, GetTextInputType());
447
448 // And can be set.
449 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_URL);
450 EXPECT_EQ(ui::TEXT_INPUT_TYPE_URL, GetTextInputType());
451 }
452
410 TEST_F(NativeTextfieldViewsTest, OnKeyPressReturnValueTest) { 453 TEST_F(NativeTextfieldViewsTest, OnKeyPressReturnValueTest) {
411 InitTextfield(Textfield::STYLE_DEFAULT); 454 InitTextfield(Textfield::STYLE_DEFAULT);
412 455
413 // Character keys will be handled by input method. 456 // Character keys will be handled by input method.
414 SendKeyEvent(ui::VKEY_A); 457 SendKeyEvent(ui::VKEY_A);
415 EXPECT_TRUE(textfield_->key_received()); 458 EXPECT_TRUE(textfield_->key_received());
416 EXPECT_FALSE(textfield_->key_handled()); 459 EXPECT_FALSE(textfield_->key_handled());
417 textfield_->clear(); 460 textfield_->clear();
418 461
419 // Home will be handled. 462 // Home will be handled.
(...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after
1081 EXPECT_STR_EQ("a23", textfield_->text()); 1124 EXPECT_STR_EQ("a23", textfield_->text());
1082 SendKeyEvent(ui::VKEY_B); 1125 SendKeyEvent(ui::VKEY_B);
1083 EXPECT_STR_EQ("ab3", textfield_->text()); 1126 EXPECT_STR_EQ("ab3", textfield_->text());
1084 SendKeyEvent(ui::VKEY_Z, false, true); 1127 SendKeyEvent(ui::VKEY_Z, false, true);
1085 EXPECT_STR_EQ("123", textfield_->text()); 1128 EXPECT_STR_EQ("123", textfield_->text());
1086 SendKeyEvent(ui::VKEY_Y, false, true); 1129 SendKeyEvent(ui::VKEY_Y, false, true);
1087 EXPECT_STR_EQ("ab3", textfield_->text()); 1130 EXPECT_STR_EQ("ab3", textfield_->text());
1088 } 1131 }
1089 1132
1090 } // namespace views 1133 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698