| 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 2063 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2074 SendKeyPress(ui::VKEY_Y, ui::EF_CONTROL_DOWN); | 2074 SendKeyPress(ui::VKEY_Y, ui::EF_CONTROL_DOWN); |
| 2075 EXPECT_STR_EQ("abefeef", textfield_->text()); | 2075 EXPECT_STR_EQ("abefeef", textfield_->text()); |
| 2076 EXPECT_EQ(gfx::Range(7), textfield_->GetSelectedRange()); | 2076 EXPECT_EQ(gfx::Range(7), textfield_->GetSelectedRange()); |
| 2077 | 2077 |
| 2078 // Move focus to next textfield. | 2078 // Move focus to next textfield. |
| 2079 widget_->GetFocusManager()->AdvanceFocus(false); | 2079 widget_->GetFocusManager()->AdvanceFocus(false); |
| 2080 EXPECT_EQ(2, GetFocusedView()->id()); | 2080 EXPECT_EQ(2, GetFocusedView()->id()); |
| 2081 Textfield* textfield2 = static_cast<Textfield*>(GetFocusedView()); | 2081 Textfield* textfield2 = static_cast<Textfield*>(GetFocusedView()); |
| 2082 EXPECT_TRUE(textfield2->text().empty()); | 2082 EXPECT_TRUE(textfield2->text().empty()); |
| 2083 | 2083 |
| 2084 // Verify yanked text persists across multiple textfields. | 2084 // Verify yanked text persists across multiple textfields and that yanking |
| 2085 // into a password textfield works. |
| 2086 textfield2->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); |
| 2085 SendKeyPress(ui::VKEY_Y, ui::EF_CONTROL_DOWN); | 2087 SendKeyPress(ui::VKEY_Y, ui::EF_CONTROL_DOWN); |
| 2086 EXPECT_STR_EQ("ef", textfield2->text()); | 2088 EXPECT_STR_EQ("ef", textfield2->text()); |
| 2087 EXPECT_EQ(gfx::Range(2), textfield2->GetSelectedRange()); | 2089 EXPECT_EQ(gfx::Range(2), textfield2->GetSelectedRange()); |
| 2090 |
| 2091 // Verify deletion in a password textfield does not modify the kill buffer. |
| 2092 textfield2->SetText(ASCIIToUTF16("hello")); |
| 2093 textfield2->SelectRange(gfx::Range(0)); |
| 2094 SendKeyPress(ui::VKEY_K, ui::EF_CONTROL_DOWN); |
| 2095 EXPECT_TRUE(textfield2->text().empty()); |
| 2096 |
| 2097 textfield_->RequestFocus(); |
| 2098 textfield_->SelectRange(gfx::Range(0)); |
| 2099 SendKeyPress(ui::VKEY_Y, ui::EF_CONTROL_DOWN); |
| 2100 EXPECT_STR_EQ("efabefeef", textfield_->text()); |
| 2088 } | 2101 } |
| 2089 | 2102 |
| 2090 #endif // defined(OS_MACOSX) | 2103 #endif // defined(OS_MACOSX) |
| 2091 | 2104 |
| 2092 TEST_F(TextfieldTest, CutCopyPaste) { | 2105 TEST_F(TextfieldTest, CutCopyPaste) { |
| 2093 InitTextfield(); | 2106 InitTextfield(); |
| 2094 | 2107 |
| 2095 // Ensure IDS_APP_CUT cuts. | 2108 // Ensure IDS_APP_CUT cuts. |
| 2096 textfield_->SetText(ASCIIToUTF16("123")); | 2109 textfield_->SetText(ASCIIToUTF16("123")); |
| 2097 textfield_->SelectAll(false); | 2110 textfield_->SelectAll(false); |
| (...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2713 textfield_->SelectRange(gfx::Range(0, 3)); | 2726 textfield_->SelectRange(gfx::Range(0, 3)); |
| 2714 EXPECT_STR_EQ("ab ", textfield_->GetSelectedText()); | 2727 EXPECT_STR_EQ("ab ", textfield_->GetSelectedText()); |
| 2715 EXPECT_STR_EQ("ab cd ef", GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION)); | 2728 EXPECT_STR_EQ("ab cd ef", GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION)); |
| 2716 EXPECT_EQ(ui::CLIPBOARD_TYPE_LAST, GetAndResetCopiedToClipboard()); | 2729 EXPECT_EQ(ui::CLIPBOARD_TYPE_LAST, GetAndResetCopiedToClipboard()); |
| 2717 | 2730 |
| 2718 SetClipboardText(ui::CLIPBOARD_TYPE_SELECTION, "other"); | 2731 SetClipboardText(ui::CLIPBOARD_TYPE_SELECTION, "other"); |
| 2719 textfield_->SelectAll(false); | 2732 textfield_->SelectAll(false); |
| 2720 EXPECT_STR_EQ("other", GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION)); | 2733 EXPECT_STR_EQ("other", GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION)); |
| 2721 EXPECT_EQ(ui::CLIPBOARD_TYPE_LAST, GetAndResetCopiedToClipboard()); | 2734 EXPECT_EQ(ui::CLIPBOARD_TYPE_LAST, GetAndResetCopiedToClipboard()); |
| 2722 } | 2735 } |
| 2736 |
| 2737 // Verify that the selection clipboard is not updated for selections on a |
| 2738 // password textfield. Disabled due to http://crbug.com/396477. |
| 2739 TEST_F(TextfieldTest, DISABLED_SelectionClipboard_Password) { |
| 2740 InitTextfields(2); |
| 2741 textfield_->SetText(ASCIIToUTF16("abcd")); |
| 2742 |
| 2743 // Select-all should update the selection clipboard for a non-password |
| 2744 // textfield. |
| 2745 SendKeyEvent(ui::VKEY_A, false, true); |
| 2746 EXPECT_EQ(gfx::Range(0, 4), textfield_->GetSelectedRange()); |
| 2747 EXPECT_STR_EQ("abcd", GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION)); |
| 2748 EXPECT_EQ(ui::CLIPBOARD_TYPE_SELECTION, GetAndResetCopiedToClipboard()); |
| 2749 |
| 2750 // Move focus to the next textfield. |
| 2751 widget_->GetFocusManager()->AdvanceFocus(false); |
| 2752 EXPECT_EQ(2, GetFocusedView()->id()); |
| 2753 Textfield* textfield2 = static_cast<Textfield*>(GetFocusedView()); |
| 2754 |
| 2755 // Select-all should not modify the selection clipboard for a password |
| 2756 // textfield. |
| 2757 textfield2->SetText(ASCIIToUTF16("1234")); |
| 2758 textfield2->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); |
| 2759 SendKeyEvent(ui::VKEY_A, false, true); |
| 2760 EXPECT_EQ(gfx::Range(0, 4), textfield2->GetSelectedRange()); |
| 2761 EXPECT_STR_EQ("abcd", GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION)); |
| 2762 EXPECT_EQ(ui::CLIPBOARD_TYPE_LAST, GetAndResetCopiedToClipboard()); |
| 2763 |
| 2764 // Shift-Left/Right should not modify the selection clipboard for a password |
| 2765 // textfield. |
| 2766 SendKeyEvent(ui::VKEY_LEFT, true, false); |
| 2767 EXPECT_EQ(gfx::Range(0, 3), textfield2->GetSelectedRange()); |
| 2768 EXPECT_STR_EQ("abcd", GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION)); |
| 2769 EXPECT_EQ(ui::CLIPBOARD_TYPE_LAST, GetAndResetCopiedToClipboard()); |
| 2770 |
| 2771 SendKeyEvent(ui::VKEY_RIGHT, true, false); |
| 2772 EXPECT_EQ(gfx::Range(0, 4), textfield2->GetSelectedRange()); |
| 2773 EXPECT_STR_EQ("abcd", GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION)); |
| 2774 EXPECT_EQ(ui::CLIPBOARD_TYPE_LAST, GetAndResetCopiedToClipboard()); |
| 2775 } |
| 2723 #endif | 2776 #endif |
| 2724 | 2777 |
| 2725 // Long_Press gesture in Textfield can initiate a drag and drop now. | 2778 // Long_Press gesture in Textfield can initiate a drag and drop now. |
| 2726 TEST_F(TextfieldTest, TestLongPressInitiatesDragDrop) { | 2779 TEST_F(TextfieldTest, TestLongPressInitiatesDragDrop) { |
| 2727 InitTextfield(); | 2780 InitTextfield(); |
| 2728 textfield_->SetText(ASCIIToUTF16("Hello string world")); | 2781 textfield_->SetText(ASCIIToUTF16("Hello string world")); |
| 2729 | 2782 |
| 2730 // Ensure the textfield will provide selected text for drag data. | 2783 // Ensure the textfield will provide selected text for drag data. |
| 2731 textfield_->SelectRange(gfx::Range(6, 12)); | 2784 textfield_->SelectRange(gfx::Range(6, 12)); |
| 2732 const gfx::Point kStringPoint(GetCursorPositionX(9), 0); | 2785 const gfx::Point kStringPoint(GetCursorPositionX(9), 0); |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2929 | 2982 |
| 2930 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); | 2983 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); |
| 2931 ui::AXViewState state_protected; | 2984 ui::AXViewState state_protected; |
| 2932 textfield_->GetAccessibleState(&state_protected); | 2985 textfield_->GetAccessibleState(&state_protected); |
| 2933 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, state_protected.role); | 2986 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, state_protected.role); |
| 2934 EXPECT_EQ(ASCIIToUTF16("********"), state_protected.value); | 2987 EXPECT_EQ(ASCIIToUTF16("********"), state_protected.value); |
| 2935 EXPECT_TRUE(state_protected.HasStateFlag(ui::AX_STATE_PROTECTED)); | 2988 EXPECT_TRUE(state_protected.HasStateFlag(ui::AX_STATE_PROTECTED)); |
| 2936 } | 2989 } |
| 2937 | 2990 |
| 2938 } // namespace views | 2991 } // namespace views |
| OLD | NEW |