summaryrefslogtreecommitdiffstats
path: root/ui/views/touchui/touch_selection_controller_impl_unittest.cc
diff options
context:
space:
mode:
authormsw@chromium.org <msw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-01-12 00:53:19 +0000
committermsw@chromium.org <msw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-01-12 00:53:19 +0000
commitcaca4b3c63d9b6fcc9ce5f7758fba8a0b35e76d9 (patch)
treebcd308c570907ffad819e738ef471fc52ee15e98 /ui/views/touchui/touch_selection_controller_impl_unittest.cc
parentb41484c21eca827a76df316d19439a3bc1148201 (diff)
downloadchromium_src-caca4b3c63d9b6fcc9ce5f7758fba8a0b35e76d9.zip
chromium_src-caca4b3c63d9b6fcc9ce5f7758fba8a0b35e76d9.tar.gz
chromium_src-caca4b3c63d9b6fcc9ce5f7758fba8a0b35e76d9.tar.bz2
Revert of https://codereview.chromium.org/120503005/
Reason for revert: views_unittest failures... :-( TBR=sky@chromium.org NOTREECHECKS=true NOTRY=true BUG=131660 Review URL: https://codereview.chromium.org/135813002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@244402 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/views/touchui/touch_selection_controller_impl_unittest.cc')
-rw-r--r--ui/views/touchui/touch_selection_controller_impl_unittest.cc61
1 files changed, 33 insertions, 28 deletions
diff --git a/ui/views/touchui/touch_selection_controller_impl_unittest.cc b/ui/views/touchui/touch_selection_controller_impl_unittest.cc
index 729e20f..67882bf 100644
--- a/ui/views/touchui/touch_selection_controller_impl_unittest.cc
+++ b/ui/views/touchui/touch_selection_controller_impl_unittest.cc
@@ -8,10 +8,10 @@
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/touch/touch_editing_controller.h"
#include "ui/base/ui_base_switches.h"
-#include "ui/gfx/canvas.h"
#include "ui/gfx/point.h"
#include "ui/gfx/rect.h"
#include "ui/gfx/render_text.h"
+#include "ui/views/controls/textfield/native_textfield_views.h"
#include "ui/views/controls/textfield/textfield.h"
#include "ui/views/test/views_test_base.h"
#include "ui/views/touchui/touch_selection_controller_impl.h"
@@ -51,6 +51,7 @@ class TouchSelectionControllerImplTest : public ViewsTestBase {
TouchSelectionControllerImplTest()
: widget_(NULL),
textfield_(NULL),
+ textfield_view_(NULL),
views_tsc_factory_(new ViewsTouchSelectionControllerFactory) {
CommandLine::ForCurrentProcess()->AppendSwitch(
switches::kEnableTouchEditing);
@@ -77,23 +78,26 @@ class TouchSelectionControllerImplTest : public ViewsTestBase {
widget_->SetContentsView(container);
container->AddChildView(textfield_);
+ textfield_view_ = textfield_->GetTextfieldViewForTesting();
textfield_->SetBoundsRect(params.bounds);
+ textfield_view_->SetBoundsRect(params.bounds);
textfield_->set_id(1);
widget_->Show();
+ DCHECK(textfield_view_);
textfield_->RequestFocus();
}
protected:
gfx::Point GetCursorPosition(const gfx::SelectionModel& sel) {
- gfx::RenderText* render_text = textfield_->GetRenderText();
+ gfx::RenderText* render_text = textfield_view_->GetRenderText();
gfx::Rect cursor_bounds = render_text->GetCursorBounds(sel, true);
return gfx::Point(cursor_bounds.x(), cursor_bounds.y());
}
TouchSelectionControllerImpl* GetSelectionController() {
return static_cast<TouchSelectionControllerImpl*>(
- textfield_->touch_selection_controller_.get());
+ textfield_view_->touch_selection_controller_.get());
}
void SimulateSelectionHandleDrag(gfx::Point p, int selection_handle) {
@@ -138,12 +142,13 @@ class TouchSelectionControllerImplTest : public ViewsTestBase {
}
gfx::RenderText* GetRenderText() {
- return textfield_->GetRenderText();
+ return textfield_view_->GetRenderText();
}
Widget* widget_;
Textfield* textfield_;
+ NativeTextfieldViews* textfield_view_;
scoped_ptr<ViewsTouchSelectionControllerFactory> views_tsc_factory_;
private:
@@ -156,7 +161,7 @@ class TouchSelectionControllerImplTest : public ViewsTestBase {
// handle 1's position is matched against the start of selection or the end.
#define VERIFY_HANDLE_POSITIONS(cursor_at_selection_handle_1) \
{ \
- gfx::SelectionModel sel = textfield_->GetSelectionModel(); \
+ gfx::SelectionModel sel = textfield_view_->GetSelectionModel(); \
if (textfield_->HasSelection()) { \
EXPECT_TRUE(IsSelectionHandle1Visible()); \
EXPECT_TRUE(IsSelectionHandle2Visible()); \
@@ -195,7 +200,7 @@ TEST_F(TouchSelectionControllerImplTest, SelectionInTextfieldTest) {
// Tap the textfield to invoke touch selection.
ui::GestureEvent tap(ui::ET_GESTURE_TAP, 0, 0, 0, base::TimeDelta(),
ui::GestureEventDetails(ui::ET_GESTURE_TAP, 1.0f, 0.0f), 0);
- textfield_->OnGestureEvent(&tap);
+ textfield_view_->OnGestureEvent(&tap);
// Test selecting a range.
textfield_->SelectRange(gfx::Range(3, 7));
@@ -216,7 +221,7 @@ TEST_F(TouchSelectionControllerImplTest, SelectionInTextfieldTest) {
// Test with focus re-gained.
widget_->GetFocusManager()->SetFocusedView(textfield_);
EXPECT_FALSE(GetSelectionController());
- textfield_->OnGestureEvent(&tap);
+ textfield_view_->OnGestureEvent(&tap);
VERIFY_HANDLE_POSITIONS(false);
}
@@ -227,7 +232,7 @@ TEST_F(TouchSelectionControllerImplTest, SelectionInBidiTextfieldTest) {
// Tap the textfield to invoke touch selection.
ui::GestureEvent tap(ui::ET_GESTURE_TAP, 0, 0, 0, base::TimeDelta(),
ui::GestureEventDetails(ui::ET_GESTURE_TAP, 1.0f, 0.0f), 0);
- textfield_->OnGestureEvent(&tap);
+ textfield_view_->OnGestureEvent(&tap);
// Test cursor at run boundary and with empty selection.
textfield_->SelectSelectionModel(
@@ -275,15 +280,15 @@ TEST_F(TouchSelectionControllerImplTest, SelectRectCallbackTest) {
// Tap the textfield to invoke touch selection.
ui::GestureEvent tap(ui::ET_GESTURE_TAP, 0, 0, 0, base::TimeDelta(),
ui::GestureEventDetails(ui::ET_GESTURE_TAP, 1.0f, 0.0f), 0);
- textfield_->OnGestureEvent(&tap);
+ textfield_view_->OnGestureEvent(&tap);
textfield_->SelectRange(gfx::Range(3, 7));
EXPECT_EQ(UTF16ToUTF8(textfield_->GetSelectedText()), "tfie");
VERIFY_HANDLE_POSITIONS(false);
// Drag selection handle 2 to right by 3 chars.
- const gfx::FontList& font_list = textfield_->GetFontList();
- int x = gfx::Canvas::GetStringWidth(ASCIIToUTF16("ld "), font_list);
+ const gfx::Font& font = textfield_->GetPrimaryFont();
+ int x = font.GetStringWidth(ASCIIToUTF16("ld "));
SimulateSelectionHandleDrag(gfx::Point(x, 0), 2);
EXPECT_EQ(UTF16ToUTF8(textfield_->GetSelectedText()), "tfield ");
VERIFY_HANDLE_POSITIONS(false);
@@ -295,13 +300,13 @@ TEST_F(TouchSelectionControllerImplTest, SelectRectCallbackTest) {
VERIFY_HANDLE_POSITIONS(true);
// Drag selection handle 1 across selection handle 2.
- x = gfx::Canvas::GetStringWidth(ASCIIToUTF16("textfield with "), font_list);
+ x = font.GetStringWidth(ASCIIToUTF16("textfield with "));
SimulateSelectionHandleDrag(gfx::Point(x, 0), 1);
EXPECT_EQ(UTF16ToUTF8(textfield_->GetSelectedText()), "with ");
VERIFY_HANDLE_POSITIONS(true);
// Drag selection handle 2 across selection handle 1.
- x = gfx::Canvas::GetStringWidth(ASCIIToUTF16("with selected "), font_list);
+ x = font.GetStringWidth(ASCIIToUTF16("with selected "));
SimulateSelectionHandleDrag(gfx::Point(x, 0), 2);
EXPECT_EQ(UTF16ToUTF8(textfield_->GetSelectedText()), "selected ");
VERIFY_HANDLE_POSITIONS(false);
@@ -313,7 +318,7 @@ TEST_F(TouchSelectionControllerImplTest, SelectRectInBidiCallbackTest) {
// Tap the textfield to invoke touch selection.
ui::GestureEvent tap(ui::ET_GESTURE_TAP, 0, 0, 0, base::TimeDelta(),
ui::GestureEventDetails(ui::ET_GESTURE_TAP, 1.0f, 0.0f), 0);
- textfield_->OnGestureEvent(&tap);
+ textfield_view_->OnGestureEvent(&tap);
// Select [c] from left to right.
textfield_->SelectRange(gfx::Range(2, 3));
@@ -321,14 +326,14 @@ TEST_F(TouchSelectionControllerImplTest, SelectRectInBidiCallbackTest) {
VERIFY_HANDLE_POSITIONS(false);
// Drag selection handle 2 to right by 1 char.
- const gfx::FontList& font_list = textfield_->GetFontList();
- int x = gfx::Canvas::GetStringWidth(WideToUTF16(L"\x05e3"), font_list);
+ const gfx::Font& font = textfield_->GetPrimaryFont();
+ int x = font.GetStringWidth(WideToUTF16(L"\x05e3"));
SimulateSelectionHandleDrag(gfx::Point(x, 0), 2);
EXPECT_EQ(WideToUTF16(L"c\x05e1\x05e2"), textfield_->GetSelectedText());
VERIFY_HANDLE_POSITIONS(false);
// Drag selection handle 1 to left by 1 char.
- x = gfx::Canvas::GetStringWidth(WideToUTF16(L"b"), font_list);
+ x = font.GetStringWidth(WideToUTF16(L"b"));
SimulateSelectionHandleDrag(gfx::Point(-x, 0), 1);
EXPECT_EQ(WideToUTF16(L"bc\x05e1\x05e2"), textfield_->GetSelectedText());
VERIFY_HANDLE_POSITIONS(true);
@@ -339,13 +344,13 @@ TEST_F(TouchSelectionControllerImplTest, SelectRectInBidiCallbackTest) {
VERIFY_HANDLE_POSITIONS(false);
// Drag selection handle 1 to right by 1 char.
- x = gfx::Canvas::GetStringWidth(WideToUTF16(L"\x05e3"), font_list);
+ x = font.GetStringWidth(WideToUTF16(L"\x05e3"));
SimulateSelectionHandleDrag(gfx::Point(x, 0), 1);
EXPECT_EQ(WideToUTF16(L"c\x05e1\x05e2"), textfield_->GetSelectedText());
VERIFY_HANDLE_POSITIONS(true);
// Drag selection handle 2 to left by 1 char.
- x = gfx::Canvas::GetStringWidth(WideToUTF16(L"b"), font_list);
+ x = font.GetStringWidth(WideToUTF16(L"b"));
SimulateSelectionHandleDrag(gfx::Point(-x, 0), 2);
EXPECT_EQ(WideToUTF16(L"bc\x05e1\x05e2"), textfield_->GetSelectedText());
VERIFY_HANDLE_POSITIONS(false);
@@ -364,14 +369,14 @@ TEST_F(TouchSelectionControllerImplTest, SelectRectInBidiCallbackTest) {
Need further investigation on whether this is a bug in Pango and how to
work around it.
// Drag selection handle 2 to left by 1 char.
- x = gfx::Canvas::GetStringWidth(WideToUTF16(L"\x05e2"), font_list);
+ x = font.GetStringWidth(WideToUTF16(L"\x05e2"));
SimulateSelectionHandleDrag(gfx::Point(-x, 0), 2);
EXPECT_EQ(WideToUTF16(L"\x05e1\x05e2"), textfield_->GetSelectedText());
VERIFY_HANDLE_POSITIONS(false);
*/
// Drag selection handle 1 to right by 1 char.
- x = gfx::Canvas::GetStringWidth(WideToUTF16(L"d"), font_list);
+ x = font.GetStringWidth(WideToUTF16(L"d"));
SimulateSelectionHandleDrag(gfx::Point(x, 0), 1);
EXPECT_EQ(WideToUTF16(L"\x05e2\x05e3" L"d"), textfield_->GetSelectedText());
VERIFY_HANDLE_POSITIONS(true);
@@ -383,14 +388,14 @@ TEST_F(TouchSelectionControllerImplTest, SelectRectInBidiCallbackTest) {
/* TODO(xji): see detail of above commented out test case.
// Drag selection handle 1 to left by 1 char.
- x = gfx::Canvas::GetStringWidth(WideToUTF16(L"\x05e2"), font_list);
+ x = font.GetStringWidth(WideToUTF16(L"\x05e2"));
SimulateSelectionHandleDrag(gfx::Point(-x, 0), 1);
EXPECT_EQ(WideToUTF16(L"\x05e1\x05e2"), textfield_->GetSelectedText());
VERIFY_HANDLE_POSITIONS(true);
*/
// Drag selection handle 2 to right by 1 char.
- x = gfx::Canvas::GetStringWidth(WideToUTF16(L"d"), font_list);
+ x = font.GetStringWidth(WideToUTF16(L"d"));
SimulateSelectionHandleDrag(gfx::Point(x, 0), 2);
EXPECT_EQ(WideToUTF16(L"\x05e2\x05e3" L"d"), textfield_->GetSelectedText());
VERIFY_HANDLE_POSITIONS(false);
@@ -401,13 +406,13 @@ TEST_F(TouchSelectionControllerImplTest, SelectRectInBidiCallbackTest) {
VERIFY_HANDLE_POSITIONS(false);
// Drag selection handle 2 to left by 1 char.
- x = gfx::Canvas::GetStringWidth(WideToUTF16(L"c"), font_list);
+ x = font.GetStringWidth(WideToUTF16(L"c"));
SimulateSelectionHandleDrag(gfx::Point(-x, 0), 2);
EXPECT_EQ(WideToUTF16(L"c\x05e1\x05e2"), textfield_->GetSelectedText());
VERIFY_HANDLE_POSITIONS(false);
// Drag selection handle 1 to right by 1 char.
- x = gfx::Canvas::GetStringWidth(WideToUTF16(L"\x05e2"), font_list);
+ x = font.GetStringWidth(WideToUTF16(L"\x05e2"));
SimulateSelectionHandleDrag(gfx::Point(x, 0), 1);
EXPECT_EQ(WideToUTF16(L"c\x05e1"), textfield_->GetSelectedText());
VERIFY_HANDLE_POSITIONS(true);
@@ -418,13 +423,13 @@ TEST_F(TouchSelectionControllerImplTest, SelectRectInBidiCallbackTest) {
VERIFY_HANDLE_POSITIONS(false);
// Drag selection handle 1 to left by 1 char.
- x = gfx::Canvas::GetStringWidth(WideToUTF16(L"c"), font_list);
+ x = font.GetStringWidth(WideToUTF16(L"c"));
SimulateSelectionHandleDrag(gfx::Point(-x, 0), 1);
EXPECT_EQ(WideToUTF16(L"c\x05e1\x05e2"), textfield_->GetSelectedText());
VERIFY_HANDLE_POSITIONS(true);
// Drag selection handle 2 to right by 1 char.
- x = gfx::Canvas::GetStringWidth(WideToUTF16(L"\x05e2"), font_list);
+ x = font.GetStringWidth(WideToUTF16(L"\x05e2"));
SimulateSelectionHandleDrag(gfx::Point(x, 0), 2);
EXPECT_EQ(WideToUTF16(L"c\x05e1"), textfield_->GetSelectedText());
VERIFY_HANDLE_POSITIONS(false);
@@ -442,7 +447,7 @@ TEST_F(TouchSelectionControllerImplTest,
// Tap the textfield to invoke selection.
ui::GestureEvent tap(ui::ET_GESTURE_TAP, 0, 0, 0, base::TimeDelta(),
ui::GestureEventDetails(ui::ET_GESTURE_TAP, 1.0f, 0.0f), 0);
- textfield_->OnGestureEvent(&tap);
+ textfield_view_->OnGestureEvent(&tap);
// Select some text such that one handle is hidden.
textfield_->SelectRange(gfx::Range(10, textfield_text.length()));