Index: ui/views/controls/textfield/textfield_unittest.cc |
diff --git a/ui/views/controls/textfield/textfield_unittest.cc b/ui/views/controls/textfield/textfield_unittest.cc |
index b27b90e41a3c9beb95f90336a69129a3b250adbd..b853aac5b2087dc7e99cce4d2e18a0a46fb31b01 100644 |
--- a/ui/views/controls/textfield/textfield_unittest.cc |
+++ b/ui/views/controls/textfield/textfield_unittest.cc |
@@ -598,6 +598,10 @@ class TextfieldTest : public ViewsTestBase, public TextfieldController { |
gfx::SelectionModel(cursor_pos, gfx::CURSOR_FORWARD), false).x(); |
} |
+ int GetCursorYForTesting() { |
+ return test_api_->GetRenderText()->GetLineOffset(0).y() + 1; |
+ } |
+ |
// Get the current cursor bounds. |
gfx::Rect GetCursorBounds() { |
return test_api_->GetRenderText()->GetUpdatedCursorBounds(); |
@@ -1386,7 +1390,7 @@ TEST_F(TextfieldTest, FocusTraversalTest) { |
// Test if clicking on textfield view sets the focus. |
widget_->GetFocusManager()->AdvanceFocus(true); |
EXPECT_EQ(3, GetFocusedView()->id()); |
- MoveMouseTo(gfx::Point()); |
+ MoveMouseTo(gfx::Point(0, GetCursorYForTesting())); |
ClickLeftMouseButton(); |
EXPECT_EQ(1, GetFocusedView()->id()); |
@@ -1438,7 +1442,7 @@ TEST_F(TextfieldTest, DoubleAndTripleClickTest) { |
textfield_->SetText(ASCIIToUTF16("hello world")); |
// Test for double click. |
- MoveMouseTo(gfx::Point()); |
+ MoveMouseTo(gfx::Point(0, GetCursorYForTesting())); |
ClickLeftMouseButton(); |
EXPECT_TRUE(textfield_->GetSelectedText().empty()); |
ClickLeftMouseButton(ui::EF_IS_DOUBLE_CLICK); |
@@ -1458,15 +1462,16 @@ TEST_F(TextfieldTest, DragToSelect) { |
textfield_->SetText(ASCIIToUTF16("hello world")); |
const int kStart = GetCursorPositionX(5); |
const int kEnd = 500; |
- gfx::Point start_point(kStart, 0); |
- gfx::Point end_point(kEnd, 0); |
+ const int cursor_y = GetCursorYForTesting(); |
+ gfx::Point start_point(kStart, cursor_y); |
+ gfx::Point end_point(kEnd, cursor_y); |
MoveMouseTo(start_point); |
PressLeftMouseButton(); |
EXPECT_TRUE(textfield_->GetSelectedText().empty()); |
// Check that dragging left selects the beginning of the string. |
- DragMouseTo(gfx::Point()); |
+ DragMouseTo(gfx::Point(0, cursor_y)); |
base::string16 text_left = textfield_->GetSelectedText(); |
EXPECT_STR_EQ("hello", text_left); |
@@ -1482,7 +1487,7 @@ TEST_F(TextfieldTest, DragToSelect) { |
// Check that dragging from beyond the text length works too. |
MoveMouseTo(end_point); |
PressLeftMouseButton(); |
- DragMouseTo(gfx::Point()); |
+ DragMouseTo(gfx::Point(0, cursor_y)); |
ReleaseLeftMouseButton(); |
EXPECT_EQ(textfield_->text(), textfield_->GetSelectedText()); |
} |
@@ -1491,16 +1496,17 @@ TEST_F(TextfieldTest, DragToSelect) { |
// and dragging below the textfield selects to the end, but only on platforms |
// where that is the expected behavior. |
TEST_F(TextfieldTest, DragUpOrDownSelectsToEnd) { |
+ // TODO add RTL case. |
InitTextfield(); |
textfield_->SetText(ASCIIToUTF16("hello world")); |
const base::string16 expected_up = base::ASCIIToUTF16( |
- PlatformStyle::kTextDragVerticallyDragsToEnd ? "hello" : "lo"); |
+ gfx::RenderText::kDragToEndIfOutsideVerticalBounds ? "hello" : "lo"); |
const base::string16 expected_down = base::ASCIIToUTF16( |
- PlatformStyle::kTextDragVerticallyDragsToEnd ? " world" : " w"); |
+ gfx::RenderText::kDragToEndIfOutsideVerticalBounds ? " world" : " w"); |
const int kStartX = GetCursorPositionX(5); |
const int kDownX = GetCursorPositionX(7); |
const int kUpX = GetCursorPositionX(3); |
- gfx::Point start_point(kStartX, 0); |
+ gfx::Point start_point(kStartX, GetCursorYForTesting()); |
gfx::Point down_point(kDownX, 500); |
gfx::Point up_point(kUpX, -500); |
@@ -1586,7 +1592,7 @@ TEST_F(TextfieldTest, DragAndDrop_InitiateDrag) { |
ui::OSExchangeData data; |
const gfx::Range kStringRange(6, 12); |
textfield_->SelectRange(kStringRange); |
- const gfx::Point kStringPoint(GetCursorPositionX(9), 0); |
+ const gfx::Point kStringPoint(GetCursorPositionX(9), GetCursorYForTesting()); |
textfield_->WriteDragDataForView(NULL, kStringPoint, &data); |
EXPECT_TRUE(data.GetString(&string)); |
EXPECT_EQ(textfield_->GetSelectedText(), string); |
@@ -1625,6 +1631,7 @@ TEST_F(TextfieldTest, DragAndDrop_InitiateDrag) { |
TEST_F(TextfieldTest, DragAndDrop_ToTheRight) { |
InitTextfield(); |
textfield_->SetText(ASCIIToUTF16("hello world")); |
+ const int cursor_y = GetCursorYForTesting(); |
base::string16 string; |
ui::OSExchangeData data; |
@@ -1634,7 +1641,7 @@ TEST_F(TextfieldTest, DragAndDrop_ToTheRight) { |
// Start dragging "ello". |
textfield_->SelectRange(gfx::Range(1, 5)); |
- gfx::Point point(GetCursorPositionX(3), 0); |
+ gfx::Point point(GetCursorPositionX(3), cursor_y); |
MoveMouseTo(point); |
PressLeftMouseButton(); |
EXPECT_TRUE(textfield_->CanStartDragForView(textfield_, point, point)); |
@@ -1649,7 +1656,7 @@ TEST_F(TextfieldTest, DragAndDrop_ToTheRight) { |
EXPECT_TRUE(format_types.empty()); |
// Drop "ello" after "w". |
- const gfx::Point kDropPoint(GetCursorPositionX(7), 0); |
+ const gfx::Point kDropPoint(GetCursorPositionX(7), cursor_y); |
EXPECT_TRUE(textfield_->CanDrop(data)); |
ui::DropTargetEvent drop_a(data, kDropPoint, kDropPoint, operations); |
EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, textfield_->OnDragUpdated(drop_a)); |
@@ -1675,6 +1682,7 @@ TEST_F(TextfieldTest, DragAndDrop_ToTheRight) { |
TEST_F(TextfieldTest, DragAndDrop_ToTheLeft) { |
InitTextfield(); |
textfield_->SetText(ASCIIToUTF16("hello world")); |
+ const int cursor_y = GetCursorYForTesting(); |
base::string16 string; |
ui::OSExchangeData data; |
@@ -1684,7 +1692,7 @@ TEST_F(TextfieldTest, DragAndDrop_ToTheLeft) { |
// Start dragging " worl". |
textfield_->SelectRange(gfx::Range(5, 10)); |
- gfx::Point point(GetCursorPositionX(7), 0); |
+ gfx::Point point(GetCursorPositionX(7), cursor_y); |
MoveMouseTo(point); |
PressLeftMouseButton(); |
EXPECT_TRUE(textfield_->CanStartDragForView(textfield_, point, gfx::Point())); |
@@ -1700,7 +1708,7 @@ TEST_F(TextfieldTest, DragAndDrop_ToTheLeft) { |
// Drop " worl" after "h". |
EXPECT_TRUE(textfield_->CanDrop(data)); |
- gfx::Point drop_point(GetCursorPositionX(1), 0); |
+ gfx::Point drop_point(GetCursorPositionX(1), cursor_y); |
ui::DropTargetEvent drop_a(data, drop_point, drop_point, operations); |
EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, textfield_->OnDragUpdated(drop_a)); |
EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, textfield_->OnPerformDrop(drop_a)); |
@@ -1725,22 +1733,23 @@ TEST_F(TextfieldTest, DragAndDrop_ToTheLeft) { |
TEST_F(TextfieldTest, DragAndDrop_Canceled) { |
InitTextfield(); |
textfield_->SetText(ASCIIToUTF16("hello world")); |
+ const int cursor_y = GetCursorYForTesting(); |
// Start dragging "worl". |
textfield_->SelectRange(gfx::Range(6, 10)); |
- gfx::Point point(GetCursorPositionX(8), 0); |
+ gfx::Point point(GetCursorPositionX(8), cursor_y); |
MoveMouseTo(point); |
PressLeftMouseButton(); |
ui::OSExchangeData data; |
textfield_->WriteDragDataForView(nullptr, point, &data); |
EXPECT_TRUE(textfield_->CanDrop(data)); |
// Drag the text over somewhere valid, outside the current selection. |
- gfx::Point drop_point(GetCursorPositionX(2), 0); |
+ gfx::Point drop_point(GetCursorPositionX(2), cursor_y); |
ui::DropTargetEvent drop(data, drop_point, drop_point, |
ui::DragDropTypes::DRAG_MOVE); |
EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, textfield_->OnDragUpdated(drop)); |
// "Cancel" the drag, via move and release over the selection, and OnDragDone. |
- gfx::Point drag_point(GetCursorPositionX(9), 0); |
+ gfx::Point drag_point(GetCursorPositionX(9), cursor_y); |
DragMouseTo(drag_point); |
ReleaseLeftMouseButton(); |
EXPECT_EQ(ASCIIToUTF16("hello world"), textfield_->text()); |
@@ -2603,10 +2612,11 @@ TEST_F(TextfieldTest, KeepInitiallySelectedWord) { |
TEST_F(TextfieldTest, SelectionClipboard) { |
InitTextfield(); |
textfield_->SetText(ASCIIToUTF16("0123")); |
- gfx::Point point_1(GetCursorPositionX(1), 0); |
- gfx::Point point_2(GetCursorPositionX(2), 0); |
- gfx::Point point_3(GetCursorPositionX(3), 0); |
- gfx::Point point_4(GetCursorPositionX(4), 0); |
+ const int cursor_y = GetCursorYForTesting(); |
+ gfx::Point point_1(GetCursorPositionX(1), cursor_y); |
+ gfx::Point point_2(GetCursorPositionX(2), cursor_y); |
+ gfx::Point point_3(GetCursorPositionX(3), cursor_y); |
+ gfx::Point point_4(GetCursorPositionX(4), cursor_y); |
// Text selected by the mouse should be placed on the selection clipboard. |
ui::MouseEvent press(ui::ET_MOUSE_PRESSED, point_1, point_1, |
@@ -2704,7 +2714,7 @@ TEST_F(TextfieldTest, SelectionClipboard) { |
// Double and triple clicking should update the clipboard contents. |
textfield_->SetText(ASCIIToUTF16("ab cd ef")); |
- gfx::Point word(GetCursorPositionX(4), 0); |
+ gfx::Point word(GetCursorPositionX(4), cursor_y); |
ui::MouseEvent press_word(ui::ET_MOUSE_PRESSED, word, word, |
ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, |
ui::EF_LEFT_MOUSE_BUTTON); |
@@ -2789,7 +2799,7 @@ TEST_F(TextfieldTest, TestLongPressInitiatesDragDrop) { |
// Ensure the textfield will provide selected text for drag data. |
textfield_->SelectRange(gfx::Range(6, 12)); |
- const gfx::Point kStringPoint(GetCursorPositionX(9), 0); |
+ const gfx::Point kStringPoint(GetCursorPositionX(9), GetCursorYForTesting()); |
// Enable touch-drag-drop to make long press effective. |
base::CommandLine::ForCurrentProcess()->AppendSwitch( |