| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 762 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 773 #endif | 773 #endif |
| 774 | 774 |
| 775 #if !defined(TOUCH_UI) | 775 #if !defined(TOUCH_UI) |
| 776 TEST_F(NativeTextfieldViewsTest, DragAndDrop_InitiateDrag) { | 776 TEST_F(NativeTextfieldViewsTest, DragAndDrop_InitiateDrag) { |
| 777 InitTextfield(Textfield::STYLE_DEFAULT); | 777 InitTextfield(Textfield::STYLE_DEFAULT); |
| 778 textfield_->SetText(ASCIIToUTF16("hello string world")); | 778 textfield_->SetText(ASCIIToUTF16("hello string world")); |
| 779 | 779 |
| 780 // Ensure the textfield will provide selected text for drag data. | 780 // Ensure the textfield will provide selected text for drag data. |
| 781 string16 string; | 781 string16 string; |
| 782 ui::OSExchangeData data; | 782 ui::OSExchangeData data; |
| 783 textfield_->SelectSelectionModel(gfx::SelectionModel(6, 12)); | 783 const ui::Range kStringRange(6, 12); |
| 784 textfield_->SelectRange(kStringRange); |
| 784 const gfx::Point kStringPoint(GetCursorPositionX(9), 0); | 785 const gfx::Point kStringPoint(GetCursorPositionX(9), 0); |
| 785 textfield_view_->WriteDragDataForView(NULL, kStringPoint, &data); | 786 textfield_view_->WriteDragDataForView(NULL, kStringPoint, &data); |
| 786 EXPECT_TRUE(data.GetString(&string)); | 787 EXPECT_TRUE(data.GetString(&string)); |
| 787 EXPECT_EQ(textfield_->GetSelectedText(), string); | 788 EXPECT_EQ(textfield_->GetSelectedText(), string); |
| 788 | 789 |
| 789 // Ensure that disabled textfields do not support drag operations. | 790 // Ensure that disabled textfields do not support drag operations. |
| 790 textfield_->SetEnabled(false); | 791 textfield_->SetEnabled(false); |
| 791 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, | 792 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, |
| 792 textfield_view_->GetDragOperationsForView(NULL, kStringPoint)); | 793 textfield_view_->GetDragOperationsForView(NULL, kStringPoint)); |
| 793 textfield_->SetEnabled(true); | 794 textfield_->SetEnabled(true); |
| 794 // Ensure that textfields without selections do not support drag operations. | 795 // Ensure that textfields without selections do not support drag operations. |
| 795 textfield_->ClearSelection(); | 796 textfield_->ClearSelection(); |
| 796 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, | 797 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, |
| 797 textfield_view_->GetDragOperationsForView(NULL, kStringPoint)); | 798 textfield_view_->GetDragOperationsForView(NULL, kStringPoint)); |
| 798 textfield_->SelectSelectionModel(gfx::SelectionModel(6, 12)); | 799 textfield_->SelectRange(kStringRange); |
| 799 // Ensure that textfields only initiate drag operations inside the selection. | 800 // Ensure that textfields only initiate drag operations inside the selection. |
| 800 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, | 801 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, |
| 801 textfield_view_->GetDragOperationsForView(NULL, gfx::Point())); | 802 textfield_view_->GetDragOperationsForView(NULL, gfx::Point())); |
| 802 EXPECT_FALSE(textfield_view_->CanStartDragForView(NULL, gfx::Point(), | 803 EXPECT_FALSE(textfield_view_->CanStartDragForView(NULL, gfx::Point(), |
| 803 gfx::Point())); | 804 gfx::Point())); |
| 804 EXPECT_EQ(ui::DragDropTypes::DRAG_COPY, | 805 EXPECT_EQ(ui::DragDropTypes::DRAG_COPY, |
| 805 textfield_view_->GetDragOperationsForView(NULL, kStringPoint)); | 806 textfield_view_->GetDragOperationsForView(NULL, kStringPoint)); |
| 806 EXPECT_TRUE(textfield_view_->CanStartDragForView(NULL, kStringPoint, | 807 EXPECT_TRUE(textfield_view_->CanStartDragForView(NULL, kStringPoint, |
| 807 gfx::Point())); | 808 gfx::Point())); |
| 808 // Ensure that textfields support local moves. | 809 // Ensure that textfields support local moves. |
| 809 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY, | 810 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY, |
| 810 textfield_view_->GetDragOperationsForView(textfield_view_, kStringPoint)); | 811 textfield_view_->GetDragOperationsForView(textfield_view_, kStringPoint)); |
| 811 } | 812 } |
| 812 | 813 |
| 813 TEST_F(NativeTextfieldViewsTest, DragAndDrop_ToTheRight) { | 814 TEST_F(NativeTextfieldViewsTest, DragAndDrop_ToTheRight) { |
| 814 InitTextfield(Textfield::STYLE_DEFAULT); | 815 InitTextfield(Textfield::STYLE_DEFAULT); |
| 815 textfield_->SetText(ASCIIToUTF16("hello world")); | 816 textfield_->SetText(ASCIIToUTF16("hello world")); |
| 816 | 817 |
| 817 string16 string; | 818 string16 string; |
| 818 ui::OSExchangeData data; | 819 ui::OSExchangeData data; |
| 819 int formats = 0; | 820 int formats = 0; |
| 820 int operations = 0; | 821 int operations = 0; |
| 821 std::set<OSExchangeData::CustomFormat> custom_formats; | 822 std::set<OSExchangeData::CustomFormat> custom_formats; |
| 822 | 823 |
| 823 // Start dragging "ello". | 824 // Start dragging "ello". |
| 824 textfield_->SelectSelectionModel(gfx::SelectionModel(1, 5)); | 825 textfield_->SelectRange(ui::Range(1, 5)); |
| 825 MouseEvent click_a(ui::ET_MOUSE_PRESSED, GetCursorPositionX(3), 0, | 826 MouseEvent click_a(ui::ET_MOUSE_PRESSED, GetCursorPositionX(3), 0, |
| 826 ui::EF_LEFT_BUTTON_DOWN); | 827 ui::EF_LEFT_BUTTON_DOWN); |
| 827 textfield_view_->OnMousePressed(click_a); | 828 textfield_view_->OnMousePressed(click_a); |
| 828 EXPECT_TRUE(textfield_view_->CanStartDragForView(textfield_view_, | 829 EXPECT_TRUE(textfield_view_->CanStartDragForView(textfield_view_, |
| 829 click_a.location(), gfx::Point())); | 830 click_a.location(), gfx::Point())); |
| 830 operations = textfield_view_->GetDragOperationsForView(textfield_view_, | 831 operations = textfield_view_->GetDragOperationsForView(textfield_view_, |
| 831 click_a.location()); | 832 click_a.location()); |
| 832 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY, | 833 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY, |
| 833 operations); | 834 operations); |
| 834 textfield_view_->WriteDragDataForView(NULL, click_a.location(), &data); | 835 textfield_view_->WriteDragDataForView(NULL, click_a.location(), &data); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 868 InitTextfield(Textfield::STYLE_DEFAULT); | 869 InitTextfield(Textfield::STYLE_DEFAULT); |
| 869 textfield_->SetText(ASCIIToUTF16("hello world")); | 870 textfield_->SetText(ASCIIToUTF16("hello world")); |
| 870 | 871 |
| 871 string16 string; | 872 string16 string; |
| 872 ui::OSExchangeData data; | 873 ui::OSExchangeData data; |
| 873 int formats = 0; | 874 int formats = 0; |
| 874 int operations = 0; | 875 int operations = 0; |
| 875 std::set<OSExchangeData::CustomFormat> custom_formats; | 876 std::set<OSExchangeData::CustomFormat> custom_formats; |
| 876 | 877 |
| 877 // Start dragging " worl". | 878 // Start dragging " worl". |
| 878 textfield_->SelectSelectionModel(gfx::SelectionModel(5, 10)); | 879 textfield_->SelectRange(ui::Range(5, 10)); |
| 879 MouseEvent click_a(ui::ET_MOUSE_PRESSED, GetCursorPositionX(7), 0, | 880 MouseEvent click_a(ui::ET_MOUSE_PRESSED, GetCursorPositionX(7), 0, |
| 880 ui::EF_LEFT_BUTTON_DOWN); | 881 ui::EF_LEFT_BUTTON_DOWN); |
| 881 textfield_view_->OnMousePressed(click_a); | 882 textfield_view_->OnMousePressed(click_a); |
| 882 EXPECT_TRUE(textfield_view_->CanStartDragForView(textfield_view_, | 883 EXPECT_TRUE(textfield_view_->CanStartDragForView(textfield_view_, |
| 883 click_a.location(), gfx::Point())); | 884 click_a.location(), gfx::Point())); |
| 884 operations = textfield_view_->GetDragOperationsForView(textfield_view_, | 885 operations = textfield_view_->GetDragOperationsForView(textfield_view_, |
| 885 click_a.location()); | 886 click_a.location()); |
| 886 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY, | 887 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY, |
| 887 operations); | 888 operations); |
| 888 textfield_view_->WriteDragDataForView(NULL, click_a.location(), &data); | 889 textfield_view_->WriteDragDataForView(NULL, click_a.location(), &data); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 915 EXPECT_STR_EQ("h worlellod", textfield_->text()); | 916 EXPECT_STR_EQ("h worlellod", textfield_->text()); |
| 916 SendKeyEvent(ui::VKEY_Y, false, true); | 917 SendKeyEvent(ui::VKEY_Y, false, true); |
| 917 EXPECT_STR_EQ("h worlellod", textfield_->text()); | 918 EXPECT_STR_EQ("h worlellod", textfield_->text()); |
| 918 } | 919 } |
| 919 | 920 |
| 920 TEST_F(NativeTextfieldViewsTest, DragAndDrop_Canceled) { | 921 TEST_F(NativeTextfieldViewsTest, DragAndDrop_Canceled) { |
| 921 InitTextfield(Textfield::STYLE_DEFAULT); | 922 InitTextfield(Textfield::STYLE_DEFAULT); |
| 922 textfield_->SetText(ASCIIToUTF16("hello world")); | 923 textfield_->SetText(ASCIIToUTF16("hello world")); |
| 923 | 924 |
| 924 // Start dragging "worl". | 925 // Start dragging "worl". |
| 925 textfield_->SelectSelectionModel(gfx::SelectionModel(6, 10)); | 926 textfield_->SelectRange(ui::Range(6, 10)); |
| 926 MouseEvent click(ui::ET_MOUSE_PRESSED, GetCursorPositionX(8), 0, | 927 MouseEvent click(ui::ET_MOUSE_PRESSED, GetCursorPositionX(8), 0, |
| 927 ui::EF_LEFT_BUTTON_DOWN); | 928 ui::EF_LEFT_BUTTON_DOWN); |
| 928 textfield_view_->OnMousePressed(click); | 929 textfield_view_->OnMousePressed(click); |
| 929 ui::OSExchangeData data; | 930 ui::OSExchangeData data; |
| 930 textfield_view_->WriteDragDataForView(NULL, click.location(), &data); | 931 textfield_view_->WriteDragDataForView(NULL, click.location(), &data); |
| 931 EXPECT_TRUE(textfield_view_->CanDrop(data)); | 932 EXPECT_TRUE(textfield_view_->CanDrop(data)); |
| 932 // Drag the text over somewhere valid, outside the current selection. | 933 // Drag the text over somewhere valid, outside the current selection. |
| 933 DropTargetEvent drop(data, GetCursorPositionX(2), 0, | 934 DropTargetEvent drop(data, GetCursorPositionX(2), 0, |
| 934 ui::DragDropTypes::DRAG_MOVE); | 935 ui::DragDropTypes::DRAG_MOVE); |
| 935 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, textfield_view_->OnDragUpdated(drop)); | 936 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, textfield_view_->OnDragUpdated(drop)); |
| (...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1530 EXPECT_EQ(0U, textfield_->GetCursorPosition()); | 1531 EXPECT_EQ(0U, textfield_->GetCursorPosition()); |
| 1531 #else | 1532 #else |
| 1532 EXPECT_EQ(500U, textfield_->GetCursorPosition()); | 1533 EXPECT_EQ(500U, textfield_->GetCursorPosition()); |
| 1533 #endif | 1534 #endif |
| 1534 | 1535 |
| 1535 // Reset locale. | 1536 // Reset locale. |
| 1536 base::i18n::SetICUDefaultLocale(locale); | 1537 base::i18n::SetICUDefaultLocale(locale); |
| 1537 } | 1538 } |
| 1538 | 1539 |
| 1539 } // namespace views | 1540 } // namespace views |
| OLD | NEW |