| 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 1546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1557 EXPECT_EQ(text_right, textfield_->GetSelectedText()); | 1557 EXPECT_EQ(text_right, textfield_->GetSelectedText()); |
| 1558 | 1558 |
| 1559 // Check that dragging from beyond the text length works too. | 1559 // Check that dragging from beyond the text length works too. |
| 1560 MoveMouseTo(end_point); | 1560 MoveMouseTo(end_point); |
| 1561 PressLeftMouseButton(); | 1561 PressLeftMouseButton(); |
| 1562 DragMouseTo(gfx::Point(0, cursor_y)); | 1562 DragMouseTo(gfx::Point(0, cursor_y)); |
| 1563 ReleaseLeftMouseButton(); | 1563 ReleaseLeftMouseButton(); |
| 1564 EXPECT_EQ(textfield_->text(), textfield_->GetSelectedText()); | 1564 EXPECT_EQ(textfield_->text(), textfield_->GetSelectedText()); |
| 1565 } | 1565 } |
| 1566 | 1566 |
| 1567 // This test checks that dragging above the textfield selects to the beginning | 1567 // Ensures dragging above or below the textfield extends a selection to either |
| 1568 // and dragging below the textfield selects to the end, but only on platforms | 1568 // end, depending on the relative x offsets of the text and mouse cursors. |
| 1569 // where that is the expected behavior. | |
| 1570 TEST_F(TextfieldTest, DragUpOrDownSelectsToEnd) { | 1569 TEST_F(TextfieldTest, DragUpOrDownSelectsToEnd) { |
| 1571 InitTextfield(); | 1570 InitTextfield(); |
| 1572 textfield_->SetText(ASCIIToUTF16("hello world")); | 1571 textfield_->SetText(ASCIIToUTF16("hello world")); |
| 1573 const base::string16 expected_up = base::ASCIIToUTF16( | 1572 const base::string16 expected_left = base::ASCIIToUTF16( |
| 1574 gfx::RenderText::kDragToEndIfOutsideVerticalBounds ? "hello" : "lo"); | 1573 gfx::RenderText::kDragToEndIfOutsideVerticalBounds ? "hello" : "lo"); |
| 1575 const base::string16 expected_down = base::ASCIIToUTF16( | 1574 const base::string16 expected_right = base::ASCIIToUTF16( |
| 1576 gfx::RenderText::kDragToEndIfOutsideVerticalBounds ? " world" : " w"); | 1575 gfx::RenderText::kDragToEndIfOutsideVerticalBounds ? " world" : " w"); |
| 1577 const int kStartX = GetCursorPositionX(5); | 1576 const int right_x = GetCursorPositionX(7); |
| 1578 const int kDownX = GetCursorPositionX(7); | 1577 const int left_x = GetCursorPositionX(3); |
| 1579 const int kUpX = GetCursorPositionX(3); | |
| 1580 gfx::Point start_point(kStartX, GetCursorYForTesting()); | |
| 1581 gfx::Point down_point(kDownX, 500); | |
| 1582 gfx::Point up_point(kUpX, -500); | |
| 1583 | 1578 |
| 1584 MoveMouseTo(start_point); | 1579 // All drags start from here. |
| 1580 MoveMouseTo(gfx::Point(GetCursorPositionX(5), GetCursorYForTesting())); |
| 1585 PressLeftMouseButton(); | 1581 PressLeftMouseButton(); |
| 1586 DragMouseTo(up_point); | |
| 1587 ReleaseLeftMouseButton(); | |
| 1588 EXPECT_EQ(textfield_->GetSelectedText(), expected_up); | |
| 1589 | 1582 |
| 1590 // Click at |up_point|. This is important because drags do not count as clicks | 1583 // Perform one continuous drag, checking the selection at various points. |
| 1591 // for the purpose of double-click detection, so if this test doesn't click | 1584 DragMouseTo(gfx::Point(left_x, -500)); |
| 1592 // somewhere other than |start_point| before the code below runs, the second | 1585 EXPECT_EQ(expected_left, textfield_->GetSelectedText()); // NW. |
| 1593 // click at |start_point| will be interpreted as a double-click instead of the | 1586 DragMouseTo(gfx::Point(right_x, -500)); |
| 1594 // start of a drag. | 1587 EXPECT_EQ(expected_right, textfield_->GetSelectedText()); // NE. |
| 1595 ClickLeftMouseButton(); | 1588 DragMouseTo(gfx::Point(right_x, 500)); |
| 1596 | 1589 EXPECT_EQ(expected_right, textfield_->GetSelectedText()); // SE. |
| 1597 MoveMouseTo(start_point); | 1590 DragMouseTo(gfx::Point(left_x, 500)); |
| 1598 PressLeftMouseButton(); | 1591 EXPECT_EQ(expected_left, textfield_->GetSelectedText()); // SW. |
| 1599 DragMouseTo(down_point); | |
| 1600 ReleaseLeftMouseButton(); | |
| 1601 EXPECT_EQ(textfield_->GetSelectedText(), expected_down); | |
| 1602 } | 1592 } |
| 1603 | 1593 |
| 1604 #if defined(OS_WIN) | 1594 #if defined(OS_WIN) |
| 1605 TEST_F(TextfieldTest, DragAndDrop_AcceptDrop) { | 1595 TEST_F(TextfieldTest, DragAndDrop_AcceptDrop) { |
| 1606 InitTextfield(); | 1596 InitTextfield(); |
| 1607 textfield_->SetText(ASCIIToUTF16("hello world")); | 1597 textfield_->SetText(ASCIIToUTF16("hello world")); |
| 1608 | 1598 |
| 1609 ui::OSExchangeData data; | 1599 ui::OSExchangeData data; |
| 1610 base::string16 string(ASCIIToUTF16("string ")); | 1600 base::string16 string(ASCIIToUTF16("string ")); |
| 1611 data.SetString(string); | 1601 data.SetString(string); |
| (...skipping 1550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3162 InitTextfield(); | 3152 InitTextfield(); |
| 3163 | 3153 |
| 3164 textfield_->SetCursorEnabled(false); | 3154 textfield_->SetCursorEnabled(false); |
| 3165 EXPECT_FALSE(test_api_->IsCursorVisible()); | 3155 EXPECT_FALSE(test_api_->IsCursorVisible()); |
| 3166 | 3156 |
| 3167 textfield_->SetCursorEnabled(true); | 3157 textfield_->SetCursorEnabled(true); |
| 3168 EXPECT_TRUE(test_api_->IsCursorVisible()); | 3158 EXPECT_TRUE(test_api_->IsCursorVisible()); |
| 3169 } | 3159 } |
| 3170 | 3160 |
| 3171 } // namespace views | 3161 } // namespace views |
| OLD | NEW |