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