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

Unified Diff: ui/touch_selection/touch_selection_controller_unittest.cc

Issue 1102933003: [Contextual Search] Add support for tap on the selection. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 1st cut at unit tests Created 5 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/touch_selection/touch_selection_controller.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/touch_selection/touch_selection_controller_unittest.cc
diff --git a/ui/touch_selection/touch_selection_controller_unittest.cc b/ui/touch_selection/touch_selection_controller_unittest.cc
index 22059588abd45c65a02b3ab6a58d1c6100edd77d..23dc33380964e525f5869c0b952eea173e2abdcd 100644
--- a/ui/touch_selection/touch_selection_controller_unittest.cc
+++ b/ui/touch_selection/touch_selection_controller_unittest.cc
@@ -19,6 +19,7 @@ namespace {
const int kDefaultTapTimeoutMs = 200;
const float kDefaulTapSlop = 10.f;
+const gfx::PointF kIgnoredPoint(0, 0);
class MockTouchHandleDrawable : public TouchHandleDrawable {
public:
@@ -145,6 +146,14 @@ class TouchSelectionControllerTest : public testing::Test,
controller_->OnSelectionBoundsChanged(start_bound, end_bound);
}
+ void OnLongPressEvent() {
+ ASSERT_FALSE(controller().WillHandleLongPressEvent(kIgnoredPoint));
+ }
+
+ void OnTapEvent() {
+ ASSERT_FALSE(controller().WillHandleTapEvent(kIgnoredPoint));
+ }
+
void Animate() {
base::TimeTicks now = base::TimeTicks::Now();
while (needs_animate_) {
@@ -215,14 +224,14 @@ TEST_F(TouchSelectionControllerTest, InsertionBasic) {
ChangeInsertion(insertion_rect, visible);
EXPECT_THAT(GetAndResetEvents(), IsEmpty());
EXPECT_EQ(gfx::PointF(), GetLastEventStart());
- controller().OnTapEvent();
+ OnTapEvent();
// Insertion events are ignored until the selection region is marked editable.
ChangeInsertion(insertion_rect, visible);
EXPECT_THAT(GetAndResetEvents(), IsEmpty());
EXPECT_EQ(gfx::PointF(), GetLastEventStart());
- controller().OnTapEvent();
+ OnTapEvent();
controller().OnSelectionEditable(true);
ChangeInsertion(insertion_rect, visible);
EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_SHOWN));
@@ -245,7 +254,7 @@ TEST_F(TouchSelectionControllerTest, InsertionBasic) {
TEST_F(TouchSelectionControllerTest, InsertionClearedWhenNoLongerEditable) {
gfx::RectF insertion_rect(5, 5, 0, 10);
bool visible = true;
- controller().OnTapEvent();
+ OnTapEvent();
controller().OnSelectionEditable(true);
ChangeInsertion(insertion_rect, visible);
@@ -263,13 +272,13 @@ TEST_F(TouchSelectionControllerTest, InsertionWithNoShowOnTapForEmptyEditable) {
// Taps on an empty editable region should be ignored if the controller is
// created with |show_on_tap_for_empty_editable| set to false.
- controller().OnTapEvent();
+ OnTapEvent();
controller().OnSelectionEmpty(true);
ChangeInsertion(insertion_rect, visible);
EXPECT_EQ(gfx::PointF(), GetLastEventStart());
// Once the region becomes non-empty, taps should show the insertion handle.
- controller().OnTapEvent();
+ OnTapEvent();
controller().OnSelectionEmpty(false);
ChangeInsertion(insertion_rect, visible);
EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_SHOWN));
@@ -281,14 +290,14 @@ TEST_F(TouchSelectionControllerTest, InsertionWithNoShowOnTapForEmptyEditable) {
// Long-pressing should show the handle even if the editable region is empty.
insertion_rect.Offset(2, -2);
- controller().OnLongPressEvent();
+ OnLongPressEvent();
controller().OnSelectionEmpty(true);
ChangeInsertion(insertion_rect, visible);
EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_SHOWN));
EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventStart());
// Single Tap on an empty edit field should clear insertion handle.
- controller().OnTapEvent();
+ OnTapEvent();
EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_CLEARED));
}
@@ -301,14 +310,14 @@ TEST_F(TouchSelectionControllerTest, InsertionWithShowOnTapForEmptyEditable) {
// Taps on an empty editable region should show the insertion handle if the
// controller is created with |show_on_tap_for_empty_editable| set to true.
- controller().OnTapEvent();
+ OnTapEvent();
controller().OnSelectionEmpty(true);
ChangeInsertion(insertion_rect, visible);
EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_SHOWN));
EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventStart());
// Additional taps should not hide the insertion handle in this case.
- controller().OnTapEvent();
+ OnTapEvent();
ChangeInsertion(insertion_rect, visible);
EXPECT_THAT(GetAndResetEvents(), IsEmpty());
}
@@ -318,7 +327,7 @@ TEST_F(TouchSelectionControllerTest, InsertionAppearsAfterTapFollowingTyping) {
bool visible = true;
// Simulate the user tapping an empty text field.
- controller().OnTapEvent();
+ OnTapEvent();
controller().OnSelectionEditable(true);
controller().OnSelectionEmpty(true);
ChangeInsertion(insertion_rect, visible);
@@ -332,14 +341,14 @@ TEST_F(TouchSelectionControllerTest, InsertionAppearsAfterTapFollowingTyping) {
// If the user taps the *same* position as the cursor at the end of the text
// entry, the handle should appear.
- controller().OnTapEvent();
+ OnTapEvent();
ChangeInsertion(insertion_rect, visible);
EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_SHOWN));
EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventStart());
}
TEST_F(TouchSelectionControllerTest, InsertionToSelectionTransition) {
- controller().OnLongPressEvent();
+ OnLongPressEvent();
controller().OnSelectionEditable(true);
gfx::RectF start_rect(5, 5, 0, 10);
@@ -363,7 +372,7 @@ TEST_F(TouchSelectionControllerTest, InsertionToSelectionTransition) {
controller().HideAndDisallowShowingAutomatically();
EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_CLEARED));
- controller().OnTapEvent();
+ OnTapEvent();
ChangeInsertion(end_rect, visible);
EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_SHOWN));
EXPECT_EQ(end_rect.bottom_left(), GetLastEventStart());
@@ -371,7 +380,7 @@ TEST_F(TouchSelectionControllerTest, InsertionToSelectionTransition) {
TEST_F(TouchSelectionControllerTest, InsertionDragged) {
base::TimeTicks event_time = base::TimeTicks::Now();
- controller().OnTapEvent();
+ OnTapEvent();
controller().OnSelectionEditable(true);
// The touch sequence should not be handled if insertion is not active.
@@ -422,7 +431,7 @@ TEST_F(TouchSelectionControllerTest, InsertionDragged) {
TEST_F(TouchSelectionControllerTest, InsertionTapped) {
base::TimeTicks event_time = base::TimeTicks::Now();
- controller().OnTapEvent();
+ OnTapEvent();
controller().OnSelectionEditable(true);
SetDraggingEnabled(true);
@@ -443,7 +452,7 @@ TEST_F(TouchSelectionControllerTest, InsertionTapped) {
// Reset the insertion.
ClearInsertion();
- controller().OnTapEvent();
+ OnTapEvent();
ChangeInsertion(start_rect, visible);
EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_CLEARED,
INSERTION_SHOWN));
@@ -461,7 +470,7 @@ TEST_F(TouchSelectionControllerTest, InsertionTapped) {
// Reset the insertion.
ClearInsertion();
- controller().OnTapEvent();
+ OnTapEvent();
ChangeInsertion(start_rect, visible);
EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_CLEARED,
INSERTION_SHOWN));
@@ -478,7 +487,7 @@ TEST_F(TouchSelectionControllerTest, InsertionTapped) {
// Reset the insertion.
ClearInsertion();
- controller().OnTapEvent();
+ OnTapEvent();
ChangeInsertion(start_rect, visible);
EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_CLEARED,
INSERTION_SHOWN));
@@ -494,7 +503,7 @@ TEST_F(TouchSelectionControllerTest, InsertionTapped) {
TEST_F(TouchSelectionControllerTest, InsertionNotResetByRepeatedTapOrPress) {
base::TimeTicks event_time = base::TimeTicks::Now();
- controller().OnTapEvent();
+ OnTapEvent();
controller().OnSelectionEditable(true);
SetDraggingEnabled(true);
@@ -505,7 +514,7 @@ TEST_F(TouchSelectionControllerTest, InsertionNotResetByRepeatedTapOrPress) {
EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventStart());
// Tapping again shouldn't reset the active insertion point.
- controller().OnTapEvent();
+ OnTapEvent();
MockMotionEvent event(MockMotionEvent::ACTION_DOWN, event_time, 0, 0);
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_DRAG_STARTED));
@@ -523,7 +532,7 @@ TEST_F(TouchSelectionControllerTest, InsertionNotResetByRepeatedTapOrPress) {
EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventStart());
// Pressing shouldn't reset the active insertion point.
- controller().OnLongPressEvent();
+ OnLongPressEvent();
controller().OnSelectionEmpty(true);
event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time, 0, 0);
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
@@ -546,7 +555,7 @@ TEST_F(TouchSelectionControllerTest, SelectionBasic) {
ChangeSelection(start_rect, visible, end_rect, visible);
EXPECT_EQ(gfx::PointF(), GetLastEventStart());
- controller().OnLongPressEvent();
+ OnLongPressEvent();
ChangeSelection(start_rect, visible, end_rect, visible);
EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_SHOWN));
EXPECT_EQ(start_rect.bottom_left(), GetLastEventStart());
@@ -568,7 +577,7 @@ TEST_F(TouchSelectionControllerTest, SelectionRepeatedLongPress) {
gfx::RectF end_rect(50, 5, 0, 10);
bool visible = true;
- controller().OnLongPressEvent();
+ OnLongPressEvent();
ChangeSelection(start_rect, visible, end_rect, visible);
EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_SHOWN));
EXPECT_EQ(start_rect.bottom_left(), GetLastEventStart());
@@ -577,7 +586,7 @@ TEST_F(TouchSelectionControllerTest, SelectionRepeatedLongPress) {
// A long press triggering a new selection should re-send the SELECTION_SHOWN
// event notification.
start_rect.Offset(10, 10);
- controller().OnLongPressEvent();
+ OnLongPressEvent();
ChangeSelection(start_rect, visible, end_rect, visible);
EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_SHOWN));
EXPECT_EQ(start_rect.bottom_left(), GetLastEventStart());
@@ -586,7 +595,7 @@ TEST_F(TouchSelectionControllerTest, SelectionRepeatedLongPress) {
TEST_F(TouchSelectionControllerTest, SelectionDragged) {
base::TimeTicks event_time = base::TimeTicks::Now();
- controller().OnLongPressEvent();
+ OnLongPressEvent();
// The touch sequence should not be handled if selection is not active.
MockMotionEvent event(MockMotionEvent::ACTION_DOWN, event_time, 0, 0);
@@ -644,7 +653,7 @@ TEST_F(TouchSelectionControllerTest, SelectionDragged) {
TEST_F(TouchSelectionControllerTest, SelectionDraggedWithOverlap) {
base::TimeTicks event_time = base::TimeTicks::Now();
- controller().OnLongPressEvent();
+ OnLongPressEvent();
float line_height = 10.f;
gfx::RectF start_rect(0, 0, 0, line_height);
@@ -682,7 +691,7 @@ TEST_F(TouchSelectionControllerTest, SelectionDraggedWithOverlap) {
TEST_F(TouchSelectionControllerTest, SelectionDraggedToSwitchBaseAndExtent) {
base::TimeTicks event_time = base::TimeTicks::Now();
- controller().OnLongPressEvent();
+ OnLongPressEvent();
float line_height = 10.f;
gfx::RectF start_rect(50, line_height, 0, line_height);
@@ -801,7 +810,7 @@ TEST_F(TouchSelectionControllerTest, SelectionDraggedToSwitchBaseAndExtent) {
TEST_F(TouchSelectionControllerTest, SelectionDragExtremeLineSize) {
base::TimeTicks event_time = base::TimeTicks::Now();
- controller().OnLongPressEvent();
+ OnLongPressEvent();
float small_line_height = 1.f;
float large_line_height = 50.f;
@@ -835,7 +844,7 @@ TEST_F(TouchSelectionControllerTest, SelectionDragExtremeLineSize) {
}
TEST_F(TouchSelectionControllerTest, Animation) {
- controller().OnTapEvent();
+ OnTapEvent();
controller().OnSelectionEditable(true);
gfx::RectF insertion_rect(5, 5, 0, 10);
@@ -858,14 +867,14 @@ TEST_F(TouchSelectionControllerTest, Animation) {
// If the client doesn't support animation, no animation should be triggered.
SetAnimationEnabled(false);
- controller().OnTapEvent();
+ OnTapEvent();
visible = true;
ChangeInsertion(insertion_rect, visible);
EXPECT_FALSE(GetAndResetNeedsAnimate());
}
TEST_F(TouchSelectionControllerTest, TemporarilyHidden) {
- controller().OnTapEvent();
+ OnTapEvent();
controller().OnSelectionEditable(true);
gfx::RectF insertion_rect(5, 5, 0, 10);
@@ -894,16 +903,16 @@ TEST_F(TouchSelectionControllerTest, SelectionClearOnTap) {
gfx::RectF end_rect(50, 5, 0, 10);
bool visible = true;
- controller().OnLongPressEvent();
+ OnLongPressEvent();
ChangeSelection(start_rect, visible, end_rect, visible);
EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_SHOWN));
// Selection should not be cleared if the selection bounds have not changed.
- controller().OnTapEvent();
+ OnTapEvent();
EXPECT_THAT(GetAndResetEvents(), IsEmpty());
EXPECT_EQ(start_rect.bottom_left(), GetLastEventStart());
- controller().OnTapEvent();
+ OnTapEvent();
ClearSelection();
EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_CLEARED));
EXPECT_EQ(gfx::PointF(), GetLastEventStart());
@@ -915,13 +924,13 @@ TEST_F(TouchSelectionControllerTest, NoSelectionAfterLongpressThenTap) {
bool visible = true;
// Tap-triggered selections should not be allowed.
- controller().OnLongPressEvent();
- controller().OnTapEvent();
+ OnLongPressEvent();
+ OnTapEvent();
ChangeSelection(start_rect, visible, end_rect, visible);
EXPECT_THAT(GetAndResetEvents(), IsEmpty());
// Subsequent longpress selections will be allowed.
- controller().OnLongPressEvent();
+ OnLongPressEvent();
ChangeSelection(start_rect, visible, end_rect, visible);
EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_SHOWN));
}
@@ -962,4 +971,25 @@ TEST_F(TouchSelectionControllerTest, AllowShowingFromCurrentSelection) {
EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventStart());
}
+TEST_F(TouchSelectionControllerTest, SelectionHandlesShowOnTap) {
+ gfx::RectF start_rect(5, 5, 0, 10);
+ gfx::RectF end_rect(50, 5, 0, 10);
+ gfx::PointF inner_point(25, 10);
+ gfx::PointF outer_point(100, 100);
+ bool visible = false;
+
+ // Establish a selection without handles.
+ OnLongPressEvent();
jdduke (slow) 2015/05/05 17:37:16 Remove this call to |OnLongPressEvent()|, this wil
Donn Denman 2015/05/08 22:00:30 Done.
+ ChangeSelection(start_rect, visible, end_rect, visible);
+ EXPECT_THAT(GetAndResetEvents(), IsEmpty()); // not working
+
+ // A point outside the rect should not be handled.
+ EXPECT_FALSE(controller().WillHandleLongPressEvent(outer_point));
+
+ // A point inside the rect should be handled.
+ EXPECT_TRUE(controller().WillHandleLongPressEvent(inner_point)); // not working
+ EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_SHOWN)); // not working
+}
+
+
} // namespace ui
« no previous file with comments | « ui/touch_selection/touch_selection_controller.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698