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

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

Issue 1875003002: Using ui::test::EventGenerator Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Track window offset correctly - expect regressions on mac Created 4 years, 8 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
« no previous file with comments | « ui/views/controls/textfield/textfield.cc ('k') | ui/views/style/platform_style.h » ('j') | 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 97595c57cb4e5b61a1c8569801d43f7724a0607d..91c3f3140e054fdcd4bf73abf91d6eb170f62dd7 100644
--- a/ui/views/controls/textfield/textfield_unittest.cc
+++ b/ui/views/controls/textfield/textfield_unittest.cc
@@ -39,6 +39,7 @@
#include "ui/views/controls/textfield/textfield_model.h"
#include "ui/views/controls/textfield/textfield_test_api.h"
#include "ui/views/focus/focus_manager.h"
+#include "ui/views/style/platform_style.h"
#include "ui/views/test/test_views_delegate.h"
#include "ui/views/test/views_test_base.h"
#include "ui/views/test/widget_test.h"
@@ -416,7 +417,7 @@ class TextfieldTest : public ViewsTestBase, public TextfieldController {
View* container = new View();
widget_->SetContentsView(container);
container->AddChildView(textfield_);
- textfield_->SetBoundsRect(params.bounds);
+ textfield_->SetBoundsRect(gfx::Rect(params.bounds.size()));
textfield_->set_id(1);
test_api_.reset(new TextfieldTestApi(textfield_));
@@ -653,9 +654,10 @@ class TextfieldTest : public ViewsTestBase, public TextfieldController {
// Indicates how many times OnAfterUserAction() is called.
int on_after_user_action_;
+ scoped_ptr<ui::test::EventGenerator> event_generator_;
+
private:
ui::ClipboardType copied_to_clipboard_;
- scoped_ptr<ui::test::EventGenerator> event_generator_;
DISALLOW_COPY_AND_ASSIGN(TextfieldTest);
};
@@ -1195,6 +1197,34 @@ 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.
+TEST_F(TextfieldTest, DragUpOrDownSelectsToEnd) {
+ InitTextfield();
+ textfield_->SetText(ASCIIToUTF16("hello world"));
+ const base::string16 expected_up = base::ASCIIToUTF16(
+ PlatformStyle::kTextfieldDragVerticallyDragsToEnd ? "hello" : "lo");
+ const base::string16 expected_down = base::ASCIIToUTF16(
+ PlatformStyle::kTextfieldDragVerticallyDragsToEnd ? " world" : " w");
+ const int kStartX = GetCursorPositionX(5);
+ const int kDownX = GetCursorPositionX(7);
+ const int kUpX = GetCursorPositionX(3);
+ const gfx::Vector2d offset =
+ widget_->GetWindowBoundsInScreen().OffsetFromOrigin();
+ gfx::Point start_point = gfx::Point(kStartX, 50) + offset;
+ gfx::Point down_point = gfx::Point(kDownX, 500) + offset;
+ gfx::Point up_point = gfx::Point(kUpX, -500) + offset;
+
+ event_generator_->set_current_location(start_point);
+ event_generator_->DragMouseTo(up_point);
+ EXPECT_EQ(expected_up, textfield_->GetSelectedText());
+
+ event_generator_->MoveMouseTo(start_point);
+ event_generator_->DragMouseTo(down_point);
+ EXPECT_EQ(expected_down, textfield_->GetSelectedText());
+}
+
#if defined(OS_WIN)
TEST_F(TextfieldTest, DragAndDrop_AcceptDrop) {
InitTextfield();
« no previous file with comments | « ui/views/controls/textfield/textfield.cc ('k') | ui/views/style/platform_style.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698