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 2587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2598 MoveMouseTo(middle); | 2598 MoveMouseTo(middle); |
| 2599 PressLeftMouseButton(); | 2599 PressLeftMouseButton(); |
| 2600 EXPECT_EQ(gfx::Range(4, 7), textfield_->GetSelectedRange()); | 2600 EXPECT_EQ(gfx::Range(4, 7), textfield_->GetSelectedRange()); |
| 2601 | 2601 |
| 2602 // Drag the mouse to the beginning of the textfield. | 2602 // Drag the mouse to the beginning of the textfield. |
| 2603 DragMouseTo(beginning); | 2603 DragMouseTo(beginning); |
| 2604 EXPECT_EQ(gfx::Range(7, 0), textfield_->GetSelectedRange()); | 2604 EXPECT_EQ(gfx::Range(7, 0), textfield_->GetSelectedRange()); |
| 2605 } | 2605 } |
| 2606 | 2606 |
| 2607 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 2607 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 2608 // flaky: http://crbug.com/396477 | 2608 TEST_F(TextfieldTest, SelectionClipboard) { |
| 2609 TEST_F(TextfieldTest, DISABLED_SelectionClipboard) { | |
| 2610 InitTextfield(); | 2609 InitTextfield(); |
| 2611 textfield_->SetText(ASCIIToUTF16("0123")); | 2610 textfield_->SetText(ASCIIToUTF16("0123")); |
| 2612 gfx::Point point_1(GetCursorPositionX(1), 0); | 2611 gfx::Point point_1(GetCursorPositionX(1), 0); |
| 2613 gfx::Point point_2(GetCursorPositionX(2), 0); | 2612 gfx::Point point_2(GetCursorPositionX(2), 0); |
| 2614 gfx::Point point_3(GetCursorPositionX(3), 0); | 2613 gfx::Point point_3(GetCursorPositionX(3), 0); |
| 2615 gfx::Point point_4(GetCursorPositionX(4), 0); | 2614 gfx::Point point_4(GetCursorPositionX(4), 0); |
| 2616 | 2615 |
| 2617 // Text selected by the mouse should be placed on the selection clipboard. | 2616 // Text selected by the mouse should be placed on the selection clipboard. |
| 2618 ui::MouseEvent press(ui::ET_MOUSE_PRESSED, point_1, point_1, | 2617 ui::MouseEvent press(ui::ET_MOUSE_PRESSED, point_1, point_1, |
| 2619 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, | 2618 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2684 // Middle clicking on an unfocused textfield should focus it and paste. | 2683 // Middle clicking on an unfocused textfield should focus it and paste. |
| 2685 textfield_->GetFocusManager()->ClearFocus(); | 2684 textfield_->GetFocusManager()->ClearFocus(); |
| 2686 EXPECT_FALSE(textfield_->HasFocus()); | 2685 EXPECT_FALSE(textfield_->HasFocus()); |
| 2687 textfield_->OnMousePressed(middle); | 2686 textfield_->OnMousePressed(middle); |
| 2688 EXPECT_TRUE(textfield_->HasFocus()); | 2687 EXPECT_TRUE(textfield_->HasFocus()); |
| 2689 EXPECT_STR_EQ("012301230123", textfield_->text()); | 2688 EXPECT_STR_EQ("012301230123", textfield_->text()); |
| 2690 EXPECT_EQ(gfx::Range(8, 8), textfield_->GetSelectedRange()); | 2689 EXPECT_EQ(gfx::Range(8, 8), textfield_->GetSelectedRange()); |
| 2691 EXPECT_STR_EQ("0123", GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION)); | 2690 EXPECT_STR_EQ("0123", GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION)); |
| 2692 | 2691 |
| 2693 // Middle clicking with an empty selection clipboard should still focus. | 2692 // Middle clicking with an empty selection clipboard should still focus. |
| 2694 SetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE, std::string()); | 2693 SetClipboardText(ui::CLIPBOARD_TYPE_SELECTION, std::string()); |
|
karandeepb
2016/11/16 04:16:15
I think this was a mistake/typo.
| |
| 2695 textfield_->GetFocusManager()->ClearFocus(); | 2694 textfield_->GetFocusManager()->ClearFocus(); |
| 2696 EXPECT_FALSE(textfield_->HasFocus()); | 2695 EXPECT_FALSE(textfield_->HasFocus()); |
| 2697 textfield_->OnMousePressed(middle); | 2696 textfield_->OnMousePressed(middle); |
| 2698 EXPECT_TRUE(textfield_->HasFocus()); | 2697 EXPECT_TRUE(textfield_->HasFocus()); |
| 2699 EXPECT_STR_EQ("012301230123", textfield_->text()); | 2698 EXPECT_STR_EQ("012301230123", textfield_->text()); |
| 2700 EXPECT_EQ(gfx::Range(4, 4), textfield_->GetSelectedRange()); | 2699 EXPECT_EQ(gfx::Range(4, 4), textfield_->GetSelectedRange()); |
| 2701 EXPECT_TRUE(GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION).empty()); | 2700 EXPECT_TRUE(GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION).empty()); |
| 2702 | 2701 |
| 2703 // Middle clicking in the selection should clear the clipboard and selection. | 2702 // Middle clicking in the selection should clear the clipboard and selection. |
| 2704 SetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE, "foo"); | 2703 SetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE, "foo"); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2741 EXPECT_STR_EQ("ab cd ef", GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION)); | 2740 EXPECT_STR_EQ("ab cd ef", GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION)); |
| 2742 EXPECT_EQ(ui::CLIPBOARD_TYPE_LAST, GetAndResetCopiedToClipboard()); | 2741 EXPECT_EQ(ui::CLIPBOARD_TYPE_LAST, GetAndResetCopiedToClipboard()); |
| 2743 | 2742 |
| 2744 SetClipboardText(ui::CLIPBOARD_TYPE_SELECTION, "other"); | 2743 SetClipboardText(ui::CLIPBOARD_TYPE_SELECTION, "other"); |
| 2745 textfield_->SelectAll(false); | 2744 textfield_->SelectAll(false); |
| 2746 EXPECT_STR_EQ("other", GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION)); | 2745 EXPECT_STR_EQ("other", GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION)); |
| 2747 EXPECT_EQ(ui::CLIPBOARD_TYPE_LAST, GetAndResetCopiedToClipboard()); | 2746 EXPECT_EQ(ui::CLIPBOARD_TYPE_LAST, GetAndResetCopiedToClipboard()); |
| 2748 } | 2747 } |
| 2749 | 2748 |
| 2750 // Verify that the selection clipboard is not updated for selections on a | 2749 // Verify that the selection clipboard is not updated for selections on a |
| 2751 // password textfield. Disabled due to http://crbug.com/396477. | 2750 // password textfield. |
| 2752 TEST_F(TextfieldTest, DISABLED_SelectionClipboard_Password) { | 2751 TEST_F(TextfieldTest, SelectionClipboard_Password) { |
| 2753 InitTextfields(2); | 2752 InitTextfields(2); |
| 2754 textfield_->SetText(ASCIIToUTF16("abcd")); | 2753 textfield_->SetText(ASCIIToUTF16("abcd")); |
| 2755 | 2754 |
| 2756 // Select-all should update the selection clipboard for a non-password | 2755 // Select-all should update the selection clipboard for a non-password |
| 2757 // textfield. | 2756 // textfield. |
| 2758 SendKeyEvent(ui::VKEY_A, false, true); | 2757 SendKeyEvent(ui::VKEY_A, false, true); |
| 2759 EXPECT_EQ(gfx::Range(0, 4), textfield_->GetSelectedRange()); | 2758 EXPECT_EQ(gfx::Range(0, 4), textfield_->GetSelectedRange()); |
| 2760 EXPECT_STR_EQ("abcd", GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION)); | 2759 EXPECT_STR_EQ("abcd", GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION)); |
| 2761 EXPECT_EQ(ui::CLIPBOARD_TYPE_SELECTION, GetAndResetCopiedToClipboard()); | 2760 EXPECT_EQ(ui::CLIPBOARD_TYPE_SELECTION, GetAndResetCopiedToClipboard()); |
| 2762 | 2761 |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3009 ui::AXNodeData node_data_protected; | 3008 ui::AXNodeData node_data_protected; |
| 3010 node_data_protected.state = 0; | 3009 node_data_protected.state = 0; |
| 3011 textfield_->GetAccessibleNodeData(&node_data_protected); | 3010 textfield_->GetAccessibleNodeData(&node_data_protected); |
| 3012 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, node_data_protected.role); | 3011 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, node_data_protected.role); |
| 3013 EXPECT_EQ(ASCIIToUTF16("********"), | 3012 EXPECT_EQ(ASCIIToUTF16("********"), |
| 3014 node_data_protected.GetString16Attribute(ui::AX_ATTR_VALUE)); | 3013 node_data_protected.GetString16Attribute(ui::AX_ATTR_VALUE)); |
| 3015 EXPECT_TRUE(node_data_protected.HasStateFlag(ui::AX_STATE_PROTECTED)); | 3014 EXPECT_TRUE(node_data_protected.HasStateFlag(ui::AX_STATE_PROTECTED)); |
| 3016 } | 3015 } |
| 3017 | 3016 |
| 3018 } // namespace views | 3017 } // namespace views |
| OLD | NEW |