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

Side by Side 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, 6 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 unified diff | Download patch
OLDNEW
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
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 kStartX = GetCursorPositionX(5);
msw 2017/05/25 18:11:56 optional nit: inline this?
tapted 2017/05/26 06:53:40 Done.
1578 const int kDownX = GetCursorPositionX(7); 1577 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.
1579 const int kUpX = GetCursorPositionX(3); 1578 const int kLeftX = GetCursorPositionX(3);
1580 gfx::Point start_point(kStartX, GetCursorYForTesting()); 1579 const gfx::Point start_point(kStartX, GetCursorYForTesting());
1581 gfx::Point down_point(kDownX, 500); 1580 const gfx::Point end_point[] = {
1582 gfx::Point up_point(kUpX, -500); 1581 {kLeftX, -500}, {kRightX, -500}, {kRightX, 500}, {kLeftX, 500}};
1583 1582
1584 MoveMouseTo(start_point); 1583 auto SelectionAfterDrag = [&, this](const gfx::Point& end) -> base::string16 {
msw 2017/05/25 18:11:56 nifty!
1585 PressLeftMouseButton(); 1584 MoveMouseTo(start_point);
1586 DragMouseTo(up_point); 1585 PressLeftMouseButton();
1587 ReleaseLeftMouseButton(); 1586 DragMouseTo(end);
1588 EXPECT_EQ(textfield_->GetSelectedText(), expected_up); 1587 ReleaseLeftMouseButton();
1588 base::string16 selection = textfield_->GetSelectedText();
1589 1589
1590 // Click at |up_point|. This is important because drags do not count as clicks 1590 // 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.
1591 // for the purpose of double-click detection, so if this test doesn't click 1591 // for the purpose of double-click detection, so if this test doesn't click
1592 // somewhere other than |start_point| before the code below runs, the second 1592 // somewhere other than |start_point| before the code below runs, the second
1593 // click at |start_point| will be interpreted as a double-click instead of the 1593 // click at |start_point| will be interpreted as a double-click instead of
1594 // start of a drag. 1594 // the start of a drag.
1595 ClickLeftMouseButton(); 1595 ClickLeftMouseButton();
1596 return selection;
1597 };
1596 1598
1597 MoveMouseTo(start_point); 1599 enum { NW, NE, SE, SW };
1598 PressLeftMouseButton(); 1600 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.
1599 DragMouseTo(down_point); 1601 EXPECT_EQ(expected_right, SelectionAfterDrag(end_point[NE]));
1600 ReleaseLeftMouseButton(); 1602 EXPECT_EQ(expected_right, SelectionAfterDrag(end_point[SE]));
1601 EXPECT_EQ(textfield_->GetSelectedText(), expected_down); 1603 EXPECT_EQ(expected_left, SelectionAfterDrag(end_point[SW]));
1602 } 1604 }
1603 1605
1604 #if defined(OS_WIN) 1606 #if defined(OS_WIN)
1605 TEST_F(TextfieldTest, DragAndDrop_AcceptDrop) { 1607 TEST_F(TextfieldTest, DragAndDrop_AcceptDrop) {
1606 InitTextfield(); 1608 InitTextfield();
1607 textfield_->SetText(ASCIIToUTF16("hello world")); 1609 textfield_->SetText(ASCIIToUTF16("hello world"));
1608 1610
1609 ui::OSExchangeData data; 1611 ui::OSExchangeData data;
1610 base::string16 string(ASCIIToUTF16("string ")); 1612 base::string16 string(ASCIIToUTF16("string "));
1611 data.SetString(string); 1613 data.SetString(string);
(...skipping 1550 matching lines...) Expand 10 before | Expand all | Expand 10 after
3162 InitTextfield(); 3164 InitTextfield();
3163 3165
3164 textfield_->SetCursorEnabled(false); 3166 textfield_->SetCursorEnabled(false);
3165 EXPECT_FALSE(test_api_->IsCursorVisible()); 3167 EXPECT_FALSE(test_api_->IsCursorVisible());
3166 3168
3167 textfield_->SetCursorEnabled(true); 3169 textfield_->SetCursorEnabled(true);
3168 EXPECT_TRUE(test_api_->IsCursorVisible()); 3170 EXPECT_TRUE(test_api_->IsCursorVisible());
3169 } 3171 }
3170 3172
3171 } // namespace views 3173 } // namespace views
OLDNEW
« 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