OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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, InputTypeSetsObscured) { | |
515 InitTextfield(Textfield::STYLE_DEFAULT); | |
516 | |
517 // Defaults to TEXT | |
518 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, GetTextInputType()); | |
519 | |
520 // Setting to TEXT_INPUT_TYPE_PASSWORD also sets obscured state of textfield. | |
521 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); | |
522 EXPECT_EQ(ui::TEXT_INPUT_TYPE_PASSWORD, GetTextInputType()); | |
523 EXPECT_TRUE(textfield_->IsObscured()); | |
524 } | |
525 | |
526 TEST_F(NativeTextfieldViewsTest, ObscuredSetsInputType) { | |
527 InitTextfield(Textfield::STYLE_DEFAULT); | |
528 | |
529 // Defaults to TEXT | |
530 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, GetTextInputType()); | |
531 | |
532 textfield_->SetObscured(true); | |
533 EXPECT_EQ(ui::TEXT_INPUT_TYPE_PASSWORD, GetTextInputType()); | |
534 | |
535 textfield_->SetObscured(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 555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1104 EXPECT_TRUE(textfield_->key_handled()); | 1079 EXPECT_TRUE(textfield_->key_handled()); |
1105 EXPECT_STR_EQ("0123321456789", textfield_->text()); | 1080 EXPECT_STR_EQ("0123321456789", textfield_->text()); |
1106 EXPECT_EQ(8U, textfield_->GetCursorPosition()); | 1081 EXPECT_EQ(8U, textfield_->GetCursorPosition()); |
1107 EXPECT_EQ(1, on_before_user_action_); | 1082 EXPECT_EQ(1, on_before_user_action_); |
1108 EXPECT_EQ(1, on_after_user_action_); | 1083 EXPECT_EQ(1, on_after_user_action_); |
1109 | 1084 |
1110 input_method_->Clear(); | 1085 input_method_->Clear(); |
1111 textfield_->SetReadOnly(true); | 1086 textfield_->SetReadOnly(true); |
1112 EXPECT_TRUE(input_method_->text_input_type_changed()); | 1087 EXPECT_TRUE(input_method_->text_input_type_changed()); |
1113 EXPECT_FALSE(textfield_->GetTextInputClient()); | 1088 EXPECT_FALSE(textfield_->GetTextInputClient()); |
1114 | |
1115 textfield_->SetReadOnly(false); | |
1116 input_method_->Clear(); | |
1117 textfield_->SetObscured(true); | |
1118 EXPECT_TRUE(input_method_->text_input_type_changed()); | |
1119 EXPECT_TRUE(textfield_->GetTextInputClient()); | |
1120 } | 1089 } |
1121 | 1090 |
1122 TEST_F(NativeTextfieldViewsTest, UndoRedoTest) { | 1091 TEST_F(NativeTextfieldViewsTest, UndoRedoTest) { |
1123 InitTextfield(Textfield::STYLE_DEFAULT); | 1092 InitTextfield(Textfield::STYLE_DEFAULT); |
1124 SendKeyEvent(ui::VKEY_A); | 1093 SendKeyEvent(ui::VKEY_A); |
1125 EXPECT_STR_EQ("a", textfield_->text()); | 1094 EXPECT_STR_EQ("a", textfield_->text()); |
1126 SendKeyEvent(ui::VKEY_Z, false, true); | 1095 SendKeyEvent(ui::VKEY_Z, false, true); |
1127 EXPECT_STR_EQ("", textfield_->text()); | 1096 EXPECT_STR_EQ("", textfield_->text()); |
1128 SendKeyEvent(ui::VKEY_Z, false, true); | 1097 SendKeyEvent(ui::VKEY_Z, false, true); |
1129 EXPECT_STR_EQ("", textfield_->text()); | 1098 EXPECT_STR_EQ("", textfield_->text()); |
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1568 #else | 1537 #else |
1569 EXPECT_EQ(500U, textfield_->GetCursorPosition()); | 1538 EXPECT_EQ(500U, textfield_->GetCursorPosition()); |
1570 #endif | 1539 #endif |
1571 #endif // !defined(OS_WIN) | 1540 #endif // !defined(OS_WIN) |
1572 | 1541 |
1573 // Reset locale. | 1542 // Reset locale. |
1574 base::i18n::SetICUDefaultLocale(locale); | 1543 base::i18n::SetICUDefaultLocale(locale); |
1575 } | 1544 } |
1576 | 1545 |
1577 } // namespace views | 1546 } // namespace views |
OLD | NEW |