Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(139)

Unified Diff: ui/views/controls/textfield/textfield_unittest.cc

Issue 2903193003: MacViews: Tweak kDragToEndIfOutsideVerticalBounds for single line fields. (Closed)
Patch Set: such testing Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« ui/views/controls/label_unittest.cc ('K') | « ui/views/controls/label_unittest.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 998dad06cfd6499d0e5f5ad40a70fb2cf73912cd..8cdf2a5fe2394dcc713b834f1f52b6bdd9b29cf5 100644
--- a/ui/views/controls/textfield/textfield_unittest.cc
+++ b/ui/views/controls/textfield/textfield_unittest.cc
@@ -1564,41 +1564,43 @@ TEST_F(TextfieldTest, DragToSelect) {
EXPECT_EQ(textfield_->text(), textfield_->GetSelectedText());
}
-// This test checks that dragging above the textfield selects to the beginning
-// and dragging below the textfield selects to the end, but only on platforms
-// where that is the expected behavior.
+// Ensures dragging above or below the textfield extends a selection to either
+// end, depending on the relative x offsets of the text and mouse cursors.
TEST_F(TextfieldTest, DragUpOrDownSelectsToEnd) {
InitTextfield();
textfield_->SetText(ASCIIToUTF16("hello world"));
- const base::string16 expected_up = base::ASCIIToUTF16(
+ const base::string16 expected_left = base::ASCIIToUTF16(
gfx::RenderText::kDragToEndIfOutsideVerticalBounds ? "hello" : "lo");
- const base::string16 expected_down = base::ASCIIToUTF16(
+ const base::string16 expected_right = base::ASCIIToUTF16(
gfx::RenderText::kDragToEndIfOutsideVerticalBounds ? " world" : " w");
const int kStartX = GetCursorPositionX(5);
msw 2017/05/25 18:11:56 optional nit: inline this?
tapted 2017/05/26 06:53:40 Done.
- const int kDownX = GetCursorPositionX(7);
- const int kUpX = GetCursorPositionX(3);
- gfx::Point start_point(kStartX, GetCursorYForTesting());
- gfx::Point down_point(kDownX, 500);
- gfx::Point up_point(kUpX, -500);
-
- MoveMouseTo(start_point);
- PressLeftMouseButton();
- DragMouseTo(up_point);
- ReleaseLeftMouseButton();
- EXPECT_EQ(textfield_->GetSelectedText(), expected_up);
-
- // Click at |up_point|. This is important because drags do not count as clicks
- // for the purpose of double-click detection, so if this test doesn't click
- // somewhere other than |start_point| before the code below runs, the second
- // click at |start_point| will be interpreted as a double-click instead of the
- // start of a drag.
- ClickLeftMouseButton();
+ const int kRightX = GetCursorPositionX(7);
msw 2017/05/25 18:11:56 optional nit: unix_hacker naming style to match ot
tapted 2017/05/26 06:53:40 Done.
+ const int kLeftX = GetCursorPositionX(3);
+ const gfx::Point start_point(kStartX, GetCursorYForTesting());
+ const gfx::Point end_point[] = {
+ {kLeftX, -500}, {kRightX, -500}, {kRightX, 500}, {kLeftX, 500}};
+
+ auto SelectionAfterDrag = [&, this](const gfx::Point& end) -> base::string16 {
msw 2017/05/25 18:11:56 nifty!
+ MoveMouseTo(start_point);
+ PressLeftMouseButton();
+ DragMouseTo(end);
+ ReleaseLeftMouseButton();
+ base::string16 selection = textfield_->GetSelectedText();
+
+ // Click at |end|. This is important because drags do not count as clicks
msw 2017/05/25 18:11:56 Since these all have the same start point, we shou
tapted 2017/05/26 06:53:40 Done.
+ // for the purpose of double-click detection, so if this test doesn't click
+ // somewhere other than |start_point| before the code below runs, the second
+ // click at |start_point| will be interpreted as a double-click instead of
+ // the start of a drag.
+ ClickLeftMouseButton();
+ return selection;
+ };
- MoveMouseTo(start_point);
- PressLeftMouseButton();
- DragMouseTo(down_point);
- ReleaseLeftMouseButton();
- EXPECT_EQ(textfield_->GetSelectedText(), expected_down);
+ enum { NW, NE, SE, SW };
+ EXPECT_EQ(expected_left, SelectionAfterDrag(end_point[NW]));
msw 2017/05/25 18:11:56 nit: I'd rather have the coordinates inlined here
tapted 2017/05/26 06:53:40 Done.
+ EXPECT_EQ(expected_right, SelectionAfterDrag(end_point[NE]));
+ EXPECT_EQ(expected_right, SelectionAfterDrag(end_point[SE]));
+ EXPECT_EQ(expected_left, SelectionAfterDrag(end_point[SW]));
}
#if defined(OS_WIN)
« ui/views/controls/label_unittest.cc ('K') | « ui/views/controls/label_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698