| OLD | NEW |
| 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 <string> | 5 #include <string> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/auto_reset.h" | 8 #include "base/auto_reset.h" |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 SendKeyEvent(ui::VKEY_RIGHT, false, true, false); | 492 SendKeyEvent(ui::VKEY_RIGHT, false, true, false); |
| 493 SendKeyEvent(ui::VKEY_DELETE, true, true, false); | 493 SendKeyEvent(ui::VKEY_DELETE, true, true, false); |
| 494 #if defined(OS_WIN) | 494 #if defined(OS_WIN) |
| 495 EXPECT_STR_EQ(" two three four", textfield_->text()); | 495 EXPECT_STR_EQ(" two three four", textfield_->text()); |
| 496 #else | 496 #else |
| 497 EXPECT_STR_EQ(" two", textfield_->text()); | 497 EXPECT_STR_EQ(" two", textfield_->text()); |
| 498 #endif | 498 #endif |
| 499 } | 499 } |
| 500 | 500 |
| 501 TEST_F(NativeTextfieldViewsTest, PasswordTest) { | 501 TEST_F(NativeTextfieldViewsTest, PasswordTest) { |
| 502 InitTextfield(Textfield::STYLE_PASSWORD); | 502 InitTextfield(Textfield::STYLE_OBSCURED); |
| 503 | 503 |
| 504 EXPECT_EQ(ui::TEXT_INPUT_TYPE_PASSWORD, GetTextInputType()); | 504 EXPECT_EQ(ui::TEXT_INPUT_TYPE_PASSWORD, GetTextInputType()); |
| 505 | 505 |
| 506 last_contents_.clear(); | 506 last_contents_.clear(); |
| 507 textfield_->SetText(ASCIIToUTF16("my password")); | 507 textfield_->SetText(ASCIIToUTF16("my password")); |
| 508 // Just to make sure the text() and callback returns | 508 // Just to make sure the text() and callback returns |
| 509 // the actual text instead of "*". | 509 // the actual text instead of "*". |
| 510 EXPECT_STR_EQ("my password", textfield_->text()); | 510 EXPECT_STR_EQ("my password", textfield_->text()); |
| 511 EXPECT_TRUE(last_contents_.empty()); | 511 EXPECT_TRUE(last_contents_.empty()); |
| 512 } | 512 } |
| 513 | 513 |
| 514 TEST_F(NativeTextfieldViewsTest, InputTypeSetsPassword) { | |
| 515 InitTextfield(Textfield::STYLE_DEFAULT); | |
| 516 | |
| 517 // Defaults to TEXT | |
| 518 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, GetTextInputType()); | |
| 519 | |
| 520 // Setting to passwords also sets password state of textfield. | |
| 521 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); | |
| 522 EXPECT_EQ(ui::TEXT_INPUT_TYPE_PASSWORD, GetTextInputType()); | |
| 523 EXPECT_TRUE(textfield_->IsPassword()); | |
| 524 } | |
| 525 | |
| 526 TEST_F(NativeTextfieldViewsTest, PasswordSetsInputType) { | |
| 527 InitTextfield(Textfield::STYLE_DEFAULT); | |
| 528 | |
| 529 // Defaults to TEXT | |
| 530 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, GetTextInputType()); | |
| 531 | |
| 532 textfield_->SetPassword(true); | |
| 533 EXPECT_EQ(ui::TEXT_INPUT_TYPE_PASSWORD, GetTextInputType()); | |
| 534 | |
| 535 textfield_->SetPassword(false); | |
| 536 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, GetTextInputType()); | |
| 537 } | |
| 538 | |
| 539 TEST_F(NativeTextfieldViewsTest, TextInputType) { | 514 TEST_F(NativeTextfieldViewsTest, TextInputType) { |
| 540 InitTextfield(Textfield::STYLE_DEFAULT); | 515 InitTextfield(Textfield::STYLE_DEFAULT); |
| 541 | 516 |
| 542 // Defaults to TEXT | 517 // Defaults to TEXT |
| 543 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, GetTextInputType()); | 518 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, GetTextInputType()); |
| 544 | 519 |
| 545 // And can be set. | 520 // And can be set. |
| 546 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_URL); | 521 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_URL); |
| 547 EXPECT_EQ(ui::TEXT_INPUT_TYPE_URL, GetTextInputType()); | 522 EXPECT_EQ(ui::TEXT_INPUT_TYPE_URL, GetTextInputType()); |
| 548 | 523 |
| (...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1101 EXPECT_TRUE(textfield_->key_handled()); | 1076 EXPECT_TRUE(textfield_->key_handled()); |
| 1102 EXPECT_STR_EQ("0123321456789", textfield_->text()); | 1077 EXPECT_STR_EQ("0123321456789", textfield_->text()); |
| 1103 EXPECT_EQ(8U, textfield_->GetCursorPosition()); | 1078 EXPECT_EQ(8U, textfield_->GetCursorPosition()); |
| 1104 EXPECT_EQ(1, on_before_user_action_); | 1079 EXPECT_EQ(1, on_before_user_action_); |
| 1105 EXPECT_EQ(1, on_after_user_action_); | 1080 EXPECT_EQ(1, on_after_user_action_); |
| 1106 | 1081 |
| 1107 input_method_->Clear(); | 1082 input_method_->Clear(); |
| 1108 textfield_->SetReadOnly(true); | 1083 textfield_->SetReadOnly(true); |
| 1109 EXPECT_TRUE(input_method_->text_input_type_changed()); | 1084 EXPECT_TRUE(input_method_->text_input_type_changed()); |
| 1110 EXPECT_FALSE(textfield_->GetTextInputClient()); | 1085 EXPECT_FALSE(textfield_->GetTextInputClient()); |
| 1111 | |
| 1112 textfield_->SetReadOnly(false); | |
| 1113 input_method_->Clear(); | |
| 1114 textfield_->SetPassword(true); | |
| 1115 EXPECT_TRUE(input_method_->text_input_type_changed()); | |
| 1116 EXPECT_TRUE(textfield_->GetTextInputClient()); | |
| 1117 } | 1086 } |
| 1118 | 1087 |
| 1119 TEST_F(NativeTextfieldViewsTest, UndoRedoTest) { | 1088 TEST_F(NativeTextfieldViewsTest, UndoRedoTest) { |
| 1120 InitTextfield(Textfield::STYLE_DEFAULT); | 1089 InitTextfield(Textfield::STYLE_DEFAULT); |
| 1121 SendKeyEvent(ui::VKEY_A); | 1090 SendKeyEvent(ui::VKEY_A); |
| 1122 EXPECT_STR_EQ("a", textfield_->text()); | 1091 EXPECT_STR_EQ("a", textfield_->text()); |
| 1123 SendKeyEvent(ui::VKEY_Z, false, true); | 1092 SendKeyEvent(ui::VKEY_Z, false, true); |
| 1124 EXPECT_STR_EQ("", textfield_->text()); | 1093 EXPECT_STR_EQ("", textfield_->text()); |
| 1125 SendKeyEvent(ui::VKEY_Z, false, true); | 1094 SendKeyEvent(ui::VKEY_Z, false, true); |
| 1126 EXPECT_STR_EQ("", textfield_->text()); | 1095 EXPECT_STR_EQ("", textfield_->text()); |
| (...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1565 #else | 1534 #else |
| 1566 EXPECT_EQ(500U, textfield_->GetCursorPosition()); | 1535 EXPECT_EQ(500U, textfield_->GetCursorPosition()); |
| 1567 #endif | 1536 #endif |
| 1568 #endif // !defined(OS_WIN) | 1537 #endif // !defined(OS_WIN) |
| 1569 | 1538 |
| 1570 // Reset locale. | 1539 // Reset locale. |
| 1571 base::i18n::SetICUDefaultLocale(locale); | 1540 base::i18n::SetICUDefaultLocale(locale); |
| 1572 } | 1541 } |
| 1573 | 1542 |
| 1574 } // namespace views | 1543 } // namespace views |
| OLD | NEW |