| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ui/views/controls/textfield/textfield.h" | 5 #include "ui/views/controls/textfield/textfield.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <set> | 10 #include <set> |
| (...skipping 937 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 948 | 948 |
| 949 // Paste should work normally. | 949 // Paste should work normally. |
| 950 EXPECT_TRUE(textfield_->IsCommandIdEnabled(IDS_APP_PASTE)); | 950 EXPECT_TRUE(textfield_->IsCommandIdEnabled(IDS_APP_PASTE)); |
| 951 textfield_->ExecuteCommand(IDS_APP_PASTE, 0); | 951 textfield_->ExecuteCommand(IDS_APP_PASTE, 0); |
| 952 SendKeyEvent(ui::VKEY_V, false, true); | 952 SendKeyEvent(ui::VKEY_V, false, true); |
| 953 SendAlternatePaste(); | 953 SendAlternatePaste(); |
| 954 EXPECT_STR_EQ("foo", GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE)); | 954 EXPECT_STR_EQ("foo", GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE)); |
| 955 EXPECT_STR_EQ("foofoofoo", textfield_->text()); | 955 EXPECT_STR_EQ("foofoofoo", textfield_->text()); |
| 956 } | 956 } |
| 957 | 957 |
| 958 // Check that text insertion works appropriately for password and read-only |
| 959 // textfields. |
| 960 TEST_F(TextfieldTest, TextInputType_InsertionTest) { |
| 961 InitTextfield(); |
| 962 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); |
| 963 EXPECT_EQ(ui::TEXT_INPUT_TYPE_PASSWORD, textfield_->GetTextInputType()); |
| 964 |
| 965 SendKeyEvent(ui::VKEY_A); |
| 966 SendKeyEvent(kHebrewLetterSamekh); |
| 967 SendKeyEvent(ui::VKEY_B); |
| 968 |
| 969 EXPECT_EQ(WideToUTF16(L"a\x05E1" |
| 970 L"b"), |
| 971 textfield_->text()); |
| 972 |
| 973 textfield_->SetReadOnly(true); |
| 974 EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE, textfield_->GetTextInputType()); |
| 975 SendKeyEvent(ui::VKEY_C); |
| 976 |
| 977 // No text should be inserted for read only textfields. |
| 978 EXPECT_EQ(WideToUTF16(L"a\x05E1" |
| 979 L"b"), |
| 980 textfield_->text()); |
| 981 } |
| 982 |
| 958 TEST_F(TextfieldTest, TextInputType) { | 983 TEST_F(TextfieldTest, TextInputType) { |
| 959 InitTextfield(); | 984 InitTextfield(); |
| 960 | 985 |
| 961 // Defaults to TEXT | 986 // Defaults to TEXT |
| 962 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, textfield_->GetTextInputType()); | 987 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, textfield_->GetTextInputType()); |
| 963 | 988 |
| 964 // And can be set. | 989 // And can be set. |
| 965 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_URL); | 990 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_URL); |
| 966 EXPECT_EQ(ui::TEXT_INPUT_TYPE_URL, textfield_->GetTextInputType()); | 991 EXPECT_EQ(ui::TEXT_INPUT_TYPE_URL, textfield_->GetTextInputType()); |
| 967 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); | 992 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); |
| (...skipping 1706 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2674 | 2699 |
| 2675 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); | 2700 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); |
| 2676 ui::AXViewState state_protected; | 2701 ui::AXViewState state_protected; |
| 2677 textfield_->GetAccessibleState(&state_protected); | 2702 textfield_->GetAccessibleState(&state_protected); |
| 2678 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, state_protected.role); | 2703 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, state_protected.role); |
| 2679 EXPECT_EQ(ASCIIToUTF16("********"), state_protected.value); | 2704 EXPECT_EQ(ASCIIToUTF16("********"), state_protected.value); |
| 2680 EXPECT_TRUE(state_protected.HasStateFlag(ui::AX_STATE_PROTECTED)); | 2705 EXPECT_TRUE(state_protected.HasStateFlag(ui::AX_STATE_PROTECTED)); |
| 2681 } | 2706 } |
| 2682 | 2707 |
| 2683 } // namespace views | 2708 } // namespace views |
| OLD | NEW |