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

Unified Diff: ui/touch_selection/touch_selection_controller_unittest.cc

Issue 1046783002: wip: Aura-specific implementation of unified touch selection: touch_selection (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Moving the responsibility for showing the menu into the client. 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
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 49d858037e50bf26841953f981c89ca762353d77..77bfcc3f52ef163faefd6c03af1027bc51036df6 100644
--- a/ui/touch_selection/touch_selection_controller_unittest.cc
+++ b/ui/touch_selection/touch_selection_controller_unittest.cc
@@ -36,45 +36,95 @@ class MockTouchHandleDrawable : public TouchHandleDrawable {
private:
bool* intersects_rect_;
-};
-} // namespace
+ DISALLOW_COPY_AND_ASSIGN(MockTouchHandleDrawable);
+};
-class TouchSelectionControllerTest : public testing::Test,
+class MockTouchSelectionController : public TouchSelectionController,
public TouchSelectionControllerClient {
public:
- TouchSelectionControllerTest()
- : caret_moved_(false),
- selection_moved_(false),
- selection_points_swapped_(false),
- needs_animate_(false),
+ explicit MockTouchSelectionController(bool show_on_tap_for_empty_editable)
+ : TouchSelectionController(
+ this,
+ base::TimeDelta::FromMicroseconds(kDefaultTapTimeoutMs),
+ kDefaulTapSlop,
+ show_on_tap_for_empty_editable),
animation_enabled_(true),
- dragging_enabled_(false) {}
+ dragging_enabled_(false),
+ needs_animate_(false),
+ caret_moved_(false),
+ selection_moved_(false),
+ selection_points_swapped_(false) {}
- ~TouchSelectionControllerTest() override {}
+ ~MockTouchSelectionController() override {}
- // testing::Test implementation.
+ void set_animation_enabled(bool enabled) { animation_enabled_ = enabled; }
- void SetUp() override {
- // Default touch selection controller is created with
- // |show_on_tap_for_empty_editable| flag set to false. Use
- // |AllowShowingOnTapForEmptyEditable()| function to override it.
- bool show_on_tap_for_empty_editable = false;
- controller_.reset(new TouchSelectionController(
- this,
- base::TimeDelta::FromMilliseconds(kDefaultTapTimeoutMs),
- kDefaulTapSlop,
- show_on_tap_for_empty_editable));
+ void set_dragging_enabled(bool enabled) { dragging_enabled_ = enabled; }
+
+ const gfx::PointF& GetLastEventAnchor() const { return last_event_start_; }
+
+ std::vector<SelectionEventType> GetAndResetEvents() {
+ std::vector<SelectionEventType> events;
+ events.swap(events_);
+ return events;
}
- void TearDown() override { controller_.reset(); }
+ bool GetAndResetNeedsAnimate() {
+ bool needs_animate = needs_animate_;
+ RunAnimation();
+ return needs_animate;
+ }
- // TouchSelectionControllerClient implementation.
+ bool GetAndResetCaretMoved() {
+ bool moved = caret_moved_;
+ caret_moved_ = false;
+ return moved;
+ }
+
+ bool GetAndResetSelectionMoved() {
+ bool moved = selection_moved_;
+ selection_moved_ = false;
+ return moved;
+ }
+
+ bool GetAndResetSelectionPointsSwapped() {
+ bool swapped = selection_points_swapped_;
+ selection_points_swapped_ = false;
+ return swapped;
+ }
+
+ const gfx::PointF& GetLastCaretPosition() const { return caret_position_; }
+ const gfx::PointF& GetLastSelectionStart() const { return selection_start_; }
+ const gfx::PointF& GetLastSelectionEnd() const { return selection_end_; }
+
+ private:
+ void RunAnimation() {
+ base::TimeTicks now = base::TimeTicks::Now();
+ while (needs_animate_) {
+ needs_animate_ = Animate(now);
+ now += base::TimeDelta::FromMilliseconds(16);
+ }
+ }
+
+ // TouchSelectionController implementation.
+
+ void OnSelectionEvent(SelectionEventType event,
+ const gfx::PointF& position) override {
+ events_.push_back(event);
+ last_event_start_ = position;
+ }
bool SupportsAnimation() const override { return animation_enabled_; }
void SetNeedsAnimate() override { needs_animate_ = true; }
+ scoped_ptr<TouchHandleDrawable> CreateDrawable() override {
+ return make_scoped_ptr(new MockTouchHandleDrawable(&dragging_enabled_));
+ }
+
+ // TouchSelectionControllerClient implementation.
+
void MoveCaret(const gfx::PointF& position) override {
caret_moved_ = true;
caret_position_ = position;
@@ -94,44 +144,51 @@ class TouchSelectionControllerTest : public testing::Test,
selection_end_ = extent;
}
- void OnSelectionEvent(SelectionEventType event,
- const gfx::PointF& end_position) override {
- events_.push_back(event);
- last_event_start_ = end_position;
- }
+ bool animation_enabled_;
+ bool dragging_enabled_;
+ bool needs_animate_;
+ gfx::PointF last_event_start_;
+ std::vector<SelectionEventType> events_;
+ gfx::PointF caret_position_;
+ gfx::PointF selection_start_;
+ gfx::PointF selection_end_;
+ bool caret_moved_;
+ bool selection_moved_;
+ bool selection_points_swapped_;
- scoped_ptr<TouchHandleDrawable> CreateDrawable() override {
- return make_scoped_ptr(new MockTouchHandleDrawable(&dragging_enabled_));
- }
+ DISALLOW_COPY_AND_ASSIGN(MockTouchSelectionController);
+};
+} // namespace
+
+class TouchSelectionControllerTest : public testing::Test {
+ public:
+ TouchSelectionControllerTest() {}
+ ~TouchSelectionControllerTest() override {}
+
+ protected:
void AllowShowingOnTapForEmptyEditable() {
bool show_on_tap_for_empty_editable = true;
- controller_.reset(new TouchSelectionController(
- this,
- base::TimeDelta::FromMilliseconds(kDefaultTapTimeoutMs),
- kDefaulTapSlop,
- show_on_tap_for_empty_editable));
+ controller_.reset(
+ new MockTouchSelectionController(show_on_tap_for_empty_editable));
}
- void SetAnimationEnabled(bool enabled) { animation_enabled_ = enabled; }
- void SetDraggingEnabled(bool enabled) { dragging_enabled_ = enabled; }
-
- void ClearSelection() {
- controller_->OnSelectionBoundsChanged(SelectionBound(),
- SelectionBound());
+ bool ClearSelection() {
+ return controller_->OnSelectionBoundsUpdated(SelectionBound(),
+ SelectionBound());
}
- void ClearInsertion() { ClearSelection(); }
+ bool ClearInsertion() { return ClearSelection(); }
- void ChangeInsertion(const gfx::RectF& rect, bool visible) {
+ bool ChangeInsertion(const gfx::RectF& rect, bool visible) {
SelectionBound bound;
bound.set_type(SelectionBound::CENTER);
bound.SetEdge(rect.origin(), rect.bottom_left());
bound.set_visible(visible);
- controller_->OnSelectionBoundsChanged(bound, bound);
+ return controller_->OnSelectionBoundsUpdated(bound, bound);
}
- void ChangeSelection(const gfx::RectF& start_rect,
+ bool ChangeSelection(const gfx::RectF& start_rect,
bool start_visible,
const gfx::RectF& end_rect,
bool end_visible) {
@@ -142,67 +199,28 @@ class TouchSelectionControllerTest : public testing::Test,
end_bound.SetEdge(end_rect.origin(), end_rect.bottom_left());
start_bound.set_visible(start_visible);
end_bound.set_visible(end_visible);
- controller_->OnSelectionBoundsChanged(start_bound, end_bound);
- }
-
- void Animate() {
- base::TimeTicks now = base::TimeTicks::Now();
- while (needs_animate_) {
- needs_animate_ = controller_->Animate(now);
- now += base::TimeDelta::FromMilliseconds(16);
- }
- }
-
- bool GetAndResetNeedsAnimate() {
- bool needs_animate = needs_animate_;
- Animate();
- return needs_animate;
+ return controller_->OnSelectionBoundsUpdated(start_bound, end_bound);
}
- bool GetAndResetCaretMoved() {
- bool moved = caret_moved_;
- caret_moved_ = false;
- return moved;
- }
+ MockTouchSelectionController& controller() { return *controller_; }
- bool GetAndResetSelectionMoved() {
- bool moved = selection_moved_;
- selection_moved_ = false;
- return moved;
- }
+ private:
+ // testing::Test implementation.
- bool GetAndResetSelectionPointsSwapped() {
- bool swapped = selection_points_swapped_;
- selection_points_swapped_ = false;
- return swapped;
+ void SetUp() override {
+ // Default touch selection controller is created with
+ // |show_on_tap_for_empty_editable| flag set to false. Use
+ // |AllowShowingOnTapForEmptyEditable()| function to override it.
+ bool show_on_tap_for_empty_editable = false;
+ controller_.reset(
+ new MockTouchSelectionController(show_on_tap_for_empty_editable));
}
- const gfx::PointF& GetLastCaretPosition() const { return caret_position_; }
- const gfx::PointF& GetLastSelectionStart() const { return selection_start_; }
- const gfx::PointF& GetLastSelectionEnd() const { return selection_end_; }
- const gfx::PointF& GetLastEventAnchor() const { return last_event_start_; }
-
- std::vector<SelectionEventType> GetAndResetEvents() {
- std::vector<SelectionEventType> events;
- events.swap(events_);
- return events;
- }
+ void TearDown() override { controller_.reset(); }
- TouchSelectionController& controller() { return *controller_; }
+ scoped_ptr<MockTouchSelectionController> controller_;
- private:
- gfx::PointF last_event_start_;
- gfx::PointF caret_position_;
- gfx::PointF selection_start_;
- gfx::PointF selection_end_;
- std::vector<SelectionEventType> events_;
- bool caret_moved_;
- bool selection_moved_;
- bool selection_points_swapped_;
- bool needs_animate_;
- bool animation_enabled_;
- bool dragging_enabled_;
- scoped_ptr<TouchSelectionController> controller_;
+ DISALLOW_COPY_AND_ASSIGN(TouchSelectionControllerTest);
};
TEST_F(TouchSelectionControllerTest, InsertionBasic) {
@@ -210,34 +228,34 @@ TEST_F(TouchSelectionControllerTest, InsertionBasic) {
bool visible = true;
// Insertion events are ignored until automatic showing is enabled.
- ChangeInsertion(insertion_rect, visible);
- EXPECT_THAT(GetAndResetEvents(), IsEmpty());
- EXPECT_EQ(gfx::PointF(), GetLastEventAnchor());
+ EXPECT_FALSE(ChangeInsertion(insertion_rect, visible));
+ EXPECT_THAT(controller().GetAndResetEvents(), IsEmpty());
+ EXPECT_EQ(gfx::PointF(), controller().GetLastEventAnchor());
controller().OnTapEvent();
// Insertion events are ignored until the selection region is marked editable.
- ChangeInsertion(insertion_rect, visible);
- EXPECT_THAT(GetAndResetEvents(), IsEmpty());
- EXPECT_EQ(gfx::PointF(), GetLastEventAnchor());
+ EXPECT_TRUE(ChangeInsertion(insertion_rect, visible));
+ EXPECT_THAT(controller().GetAndResetEvents(), IsEmpty());
+ EXPECT_EQ(gfx::PointF(), controller().GetLastEventAnchor());
controller().OnTapEvent();
controller().OnSelectionEditable(true);
- ChangeInsertion(insertion_rect, visible);
- EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_SHOWN));
- EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventAnchor());
+ EXPECT_TRUE(ChangeInsertion(insertion_rect, visible));
+ EXPECT_THAT(controller().GetAndResetEvents(), ElementsAre(INSERTION_SHOWN));
+ EXPECT_EQ(insertion_rect.bottom_left(), controller().GetLastEventAnchor());
insertion_rect.Offset(1, 0);
- ChangeInsertion(insertion_rect, visible);
- EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_MOVED));
- EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventAnchor());
+ EXPECT_TRUE(ChangeInsertion(insertion_rect, visible));
+ EXPECT_THAT(controller().GetAndResetEvents(), ElementsAre(INSERTION_MOVED));
+ EXPECT_EQ(insertion_rect.bottom_left(), controller().GetLastEventAnchor());
insertion_rect.Offset(0, 1);
- ChangeInsertion(insertion_rect, visible);
- EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_MOVED));
- EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventAnchor());
+ EXPECT_TRUE(ChangeInsertion(insertion_rect, visible));
+ EXPECT_THAT(controller().GetAndResetEvents(), ElementsAre(INSERTION_MOVED));
+ EXPECT_EQ(insertion_rect.bottom_left(), controller().GetLastEventAnchor());
- ClearInsertion();
- EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_CLEARED));
+ EXPECT_TRUE(ClearInsertion());
+ EXPECT_THAT(controller().GetAndResetEvents(), ElementsAre(INSERTION_CLEARED));
}
TEST_F(TouchSelectionControllerTest, InsertionClearedWhenNoLongerEditable) {
@@ -246,12 +264,12 @@ TEST_F(TouchSelectionControllerTest, InsertionClearedWhenNoLongerEditable) {
controller().OnTapEvent();
controller().OnSelectionEditable(true);
- ChangeInsertion(insertion_rect, visible);
- EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_SHOWN));
- EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventAnchor());
+ EXPECT_TRUE(ChangeInsertion(insertion_rect, visible));
+ EXPECT_THAT(controller().GetAndResetEvents(), ElementsAre(INSERTION_SHOWN));
+ EXPECT_EQ(insertion_rect.bottom_left(), controller().GetLastEventAnchor());
controller().OnSelectionEditable(false);
- EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_CLEARED));
+ EXPECT_THAT(controller().GetAndResetEvents(), ElementsAre(INSERTION_CLEARED));
}
TEST_F(TouchSelectionControllerTest, InsertionWithNoShowOnTapForEmptyEditable) {
@@ -263,31 +281,31 @@ TEST_F(TouchSelectionControllerTest, InsertionWithNoShowOnTapForEmptyEditable) {
// created with |show_on_tap_for_empty_editable| set to false.
controller().OnTapEvent();
controller().OnSelectionEmpty(true);
- ChangeInsertion(insertion_rect, visible);
- EXPECT_EQ(gfx::PointF(), GetLastEventAnchor());
+ EXPECT_TRUE(ChangeInsertion(insertion_rect, visible));
+ EXPECT_EQ(gfx::PointF(), controller().GetLastEventAnchor());
// Once the region becomes non-empty, taps should show the insertion handle.
controller().OnTapEvent();
controller().OnSelectionEmpty(false);
- ChangeInsertion(insertion_rect, visible);
- EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_SHOWN));
- EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventAnchor());
+ EXPECT_TRUE(ChangeInsertion(insertion_rect, visible));
+ EXPECT_THAT(controller().GetAndResetEvents(), ElementsAre(INSERTION_SHOWN));
+ EXPECT_EQ(insertion_rect.bottom_left(), controller().GetLastEventAnchor());
// Reset the selection.
controller().HideAndDisallowShowingAutomatically();
- EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_CLEARED));
+ EXPECT_THAT(controller().GetAndResetEvents(), ElementsAre(INSERTION_CLEARED));
// Long-pressing should show the handle even if the editable region is empty.
insertion_rect.Offset(2, -2);
controller().OnLongPressEvent();
controller().OnSelectionEmpty(true);
- ChangeInsertion(insertion_rect, visible);
- EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_SHOWN));
- EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventAnchor());
+ EXPECT_TRUE(ChangeInsertion(insertion_rect, visible));
+ EXPECT_THAT(controller().GetAndResetEvents(), ElementsAre(INSERTION_SHOWN));
+ EXPECT_EQ(insertion_rect.bottom_left(), controller().GetLastEventAnchor());
// Single Tap on an empty edit field should clear insertion handle.
controller().OnTapEvent();
- EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_CLEARED));
+ EXPECT_THAT(controller().GetAndResetEvents(), ElementsAre(INSERTION_CLEARED));
}
TEST_F(TouchSelectionControllerTest, InsertionWithShowOnTapForEmptyEditable) {
@@ -301,14 +319,14 @@ TEST_F(TouchSelectionControllerTest, InsertionWithShowOnTapForEmptyEditable) {
// controller is created with |show_on_tap_for_empty_editable| set to true.
controller().OnTapEvent();
controller().OnSelectionEmpty(true);
- ChangeInsertion(insertion_rect, visible);
- EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_SHOWN));
- EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventAnchor());
+ EXPECT_TRUE(ChangeInsertion(insertion_rect, visible));
+ EXPECT_THAT(controller().GetAndResetEvents(), ElementsAre(INSERTION_SHOWN));
+ EXPECT_EQ(insertion_rect.bottom_left(), controller().GetLastEventAnchor());
// Additional taps should not hide the insertion handle in this case.
controller().OnTapEvent();
- ChangeInsertion(insertion_rect, visible);
- EXPECT_THAT(GetAndResetEvents(), IsEmpty());
+ EXPECT_FALSE(ChangeInsertion(insertion_rect, visible));
+ EXPECT_THAT(controller().GetAndResetEvents(), IsEmpty());
}
TEST_F(TouchSelectionControllerTest, InsertionAppearsAfterTapFollowingTyping) {
@@ -319,21 +337,21 @@ TEST_F(TouchSelectionControllerTest, InsertionAppearsAfterTapFollowingTyping) {
controller().OnTapEvent();
controller().OnSelectionEditable(true);
controller().OnSelectionEmpty(true);
- ChangeInsertion(insertion_rect, visible);
- EXPECT_EQ(gfx::PointF(), GetLastEventAnchor());
+ EXPECT_TRUE(ChangeInsertion(insertion_rect, visible));
+ EXPECT_EQ(gfx::PointF(), controller().GetLastEventAnchor());
// Simulate the cursor moving while a user is typing.
insertion_rect.Offset(10, 0);
controller().OnSelectionEmpty(false);
- ChangeInsertion(insertion_rect, visible);
- EXPECT_EQ(gfx::PointF(), GetLastEventAnchor());
+ EXPECT_FALSE(ChangeInsertion(insertion_rect, visible));
+ EXPECT_EQ(gfx::PointF(), controller().GetLastEventAnchor());
// If the user taps the *same* position as the cursor at the end of the text
// entry, the handle should appear.
controller().OnTapEvent();
- ChangeInsertion(insertion_rect, visible);
- EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_SHOWN));
- EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventAnchor());
+ EXPECT_TRUE(ChangeInsertion(insertion_rect, visible));
+ EXPECT_THAT(controller().GetAndResetEvents(), ElementsAre(INSERTION_SHOWN));
+ EXPECT_EQ(insertion_rect.bottom_left(), controller().GetLastEventAnchor());
}
TEST_F(TouchSelectionControllerTest, InsertionToSelectionTransition) {
@@ -344,27 +362,27 @@ TEST_F(TouchSelectionControllerTest, InsertionToSelectionTransition) {
gfx::RectF end_rect(50, 5, 0, 10);
bool visible = true;
- ChangeInsertion(start_rect, visible);
- EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_SHOWN));
- EXPECT_EQ(start_rect.bottom_left(), GetLastEventAnchor());
+ EXPECT_TRUE(ChangeInsertion(start_rect, visible));
+ EXPECT_THAT(controller().GetAndResetEvents(), ElementsAre(INSERTION_SHOWN));
+ EXPECT_EQ(start_rect.bottom_left(), controller().GetLastEventAnchor());
- ChangeSelection(start_rect, visible, end_rect, visible);
- EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_CLEARED,
- SELECTION_SHOWN));
- EXPECT_EQ(start_rect.bottom_left(), GetLastEventAnchor());
+ EXPECT_TRUE(ChangeSelection(start_rect, visible, end_rect, visible));
+ EXPECT_THAT(controller().GetAndResetEvents(),
+ ElementsAre(INSERTION_CLEARED, SELECTION_SHOWN));
+ EXPECT_EQ(start_rect.bottom_left(), controller().GetLastEventAnchor());
- ChangeInsertion(end_rect, visible);
- EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_CLEARED,
- INSERTION_SHOWN));
- EXPECT_EQ(end_rect.bottom_left(), GetLastEventAnchor());
+ EXPECT_TRUE(ChangeInsertion(end_rect, visible));
+ EXPECT_THAT(controller().GetAndResetEvents(),
+ ElementsAre(SELECTION_CLEARED, INSERTION_SHOWN));
+ EXPECT_EQ(end_rect.bottom_left(), controller().GetLastEventAnchor());
controller().HideAndDisallowShowingAutomatically();
- EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_CLEARED));
+ EXPECT_THAT(controller().GetAndResetEvents(), ElementsAre(INSERTION_CLEARED));
controller().OnTapEvent();
- ChangeInsertion(end_rect, visible);
- EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_SHOWN));
- EXPECT_EQ(end_rect.bottom_left(), GetLastEventAnchor());
+ EXPECT_TRUE(ChangeInsertion(end_rect, visible));
+ EXPECT_THAT(controller().GetAndResetEvents(), ElementsAre(INSERTION_SHOWN));
+ EXPECT_EQ(end_rect.bottom_left(), controller().GetLastEventAnchor());
}
TEST_F(TouchSelectionControllerTest, InsertionDragged) {
@@ -379,39 +397,44 @@ TEST_F(TouchSelectionControllerTest, InsertionDragged) {
float line_height = 10.f;
gfx::RectF start_rect(10, 0, 0, line_height);
bool visible = true;
- ChangeInsertion(start_rect, visible);
- EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_SHOWN));
- EXPECT_EQ(start_rect.bottom_left(), GetLastEventAnchor());
+ EXPECT_TRUE(ChangeInsertion(start_rect, visible));
+ EXPECT_THAT(controller().GetAndResetEvents(), ElementsAre(INSERTION_SHOWN));
+ EXPECT_EQ(start_rect.bottom_left(), controller().GetLastEventAnchor());
// The touch sequence should be handled only if the drawable reports a hit.
EXPECT_FALSE(controller().WillHandleTouchEvent(event));
- SetDraggingEnabled(true);
+ controller().set_dragging_enabled(true);
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
- EXPECT_FALSE(GetAndResetCaretMoved());
- EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_DRAG_STARTED));
+ EXPECT_FALSE(controller().GetAndResetCaretMoved());
+ EXPECT_THAT(controller().GetAndResetEvents(),
+ ElementsAre(INSERTION_DRAG_STARTED));
// The MoveCaret() result should reflect the movement.
// The reported position is offset from the center of |start_rect|.
gfx::PointF start_offset = start_rect.CenterPoint();
event = MockMotionEvent(MockMotionEvent::ACTION_MOVE, event_time, 0, 5);
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
- EXPECT_TRUE(GetAndResetCaretMoved());
- EXPECT_EQ(start_offset + gfx::Vector2dF(0, 5), GetLastCaretPosition());
+ EXPECT_TRUE(controller().GetAndResetCaretMoved());
+ EXPECT_EQ(start_offset + gfx::Vector2dF(0, 5),
+ controller().GetLastCaretPosition());
event = MockMotionEvent(MockMotionEvent::ACTION_MOVE, event_time, 5, 5);
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
- EXPECT_TRUE(GetAndResetCaretMoved());
- EXPECT_EQ(start_offset + gfx::Vector2dF(5, 5), GetLastCaretPosition());
+ EXPECT_TRUE(controller().GetAndResetCaretMoved());
+ EXPECT_EQ(start_offset + gfx::Vector2dF(5, 5),
+ controller().GetLastCaretPosition());
event = MockMotionEvent(MockMotionEvent::ACTION_MOVE, event_time, 10, 10);
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
- EXPECT_TRUE(GetAndResetCaretMoved());
- EXPECT_EQ(start_offset + gfx::Vector2dF(10, 10), GetLastCaretPosition());
+ EXPECT_TRUE(controller().GetAndResetCaretMoved());
+ EXPECT_EQ(start_offset + gfx::Vector2dF(10, 10),
+ controller().GetLastCaretPosition());
event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 10, 5);
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
- EXPECT_FALSE(GetAndResetCaretMoved());
- EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_DRAG_STOPPED));
+ EXPECT_FALSE(controller().GetAndResetCaretMoved());
+ EXPECT_THAT(controller().GetAndResetEvents(),
+ ElementsAre(INSERTION_DRAG_STOPPED));
// Once the drag is complete, no more touch events should be consumed until
// the next ACTION_DOWN.
@@ -422,29 +445,30 @@ TEST_F(TouchSelectionControllerTest, InsertionTapped) {
base::TimeTicks event_time = base::TimeTicks::Now();
controller().OnTapEvent();
controller().OnSelectionEditable(true);
- SetDraggingEnabled(true);
+ controller().set_dragging_enabled(true);
gfx::RectF start_rect(10, 0, 0, 10);
bool visible = true;
- ChangeInsertion(start_rect, visible);
- EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_SHOWN));
+ EXPECT_TRUE(ChangeInsertion(start_rect, visible));
+ EXPECT_THAT(controller().GetAndResetEvents(), ElementsAre(INSERTION_SHOWN));
MockMotionEvent event(MockMotionEvent::ACTION_DOWN, event_time, 0, 0);
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
//TODO(AKV): this test case has to be modified once crbug.com/394093 is fixed.
- EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_DRAG_STARTED));
+ EXPECT_THAT(controller().GetAndResetEvents(),
+ ElementsAre(INSERTION_DRAG_STARTED));
event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 0, 0);
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
- EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_TAPPED,
- INSERTION_DRAG_STOPPED));
+ EXPECT_THAT(controller().GetAndResetEvents(),
+ ElementsAre(INSERTION_TAPPED, INSERTION_DRAG_STOPPED));
// Reset the insertion.
- ClearInsertion();
+ EXPECT_TRUE(ClearInsertion());
controller().OnTapEvent();
- ChangeInsertion(start_rect, visible);
- EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_CLEARED,
- INSERTION_SHOWN));
+ EXPECT_TRUE(ChangeInsertion(start_rect, visible));
+ EXPECT_THAT(controller().GetAndResetEvents(),
+ ElementsAre(INSERTION_CLEARED, INSERTION_SHOWN));
// No tap should be signalled if the time between DOWN and UP was too long.
event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time, 0, 0);
@@ -454,15 +478,15 @@ TEST_F(TouchSelectionControllerTest, InsertionTapped) {
0,
0);
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
- EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_DRAG_STARTED,
- INSERTION_DRAG_STOPPED));
+ EXPECT_THAT(controller().GetAndResetEvents(),
+ ElementsAre(INSERTION_DRAG_STARTED, INSERTION_DRAG_STOPPED));
// Reset the insertion.
- ClearInsertion();
+ EXPECT_TRUE(ClearInsertion());
controller().OnTapEvent();
- ChangeInsertion(start_rect, visible);
- EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_CLEARED,
- INSERTION_SHOWN));
+ EXPECT_TRUE(ChangeInsertion(start_rect, visible));
+ EXPECT_THAT(controller().GetAndResetEvents(),
+ ElementsAre(INSERTION_CLEARED, INSERTION_SHOWN));
// No tap should be signalled if the drag was too long.
event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time, 0, 0);
@@ -471,68 +495,70 @@ TEST_F(TouchSelectionControllerTest, InsertionTapped) {
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 100, 0);
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
- EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_DRAG_STARTED,
- INSERTION_DRAG_STOPPED));
+ EXPECT_THAT(controller().GetAndResetEvents(),
+ ElementsAre(INSERTION_DRAG_STARTED, INSERTION_DRAG_STOPPED));
// Reset the insertion.
- ClearInsertion();
+ EXPECT_TRUE(ClearInsertion());
controller().OnTapEvent();
- ChangeInsertion(start_rect, visible);
- EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_CLEARED,
- INSERTION_SHOWN));
+ EXPECT_TRUE(ChangeInsertion(start_rect, visible));
+ EXPECT_THAT(controller().GetAndResetEvents(),
+ ElementsAre(INSERTION_CLEARED, INSERTION_SHOWN));
// No tap should be signalled if the touch sequence is cancelled.
event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time, 0, 0);
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
event = MockMotionEvent(MockMotionEvent::ACTION_CANCEL, event_time, 0, 0);
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
- EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_DRAG_STARTED,
- INSERTION_DRAG_STOPPED));
+ EXPECT_THAT(controller().GetAndResetEvents(),
+ ElementsAre(INSERTION_DRAG_STARTED, INSERTION_DRAG_STOPPED));
}
TEST_F(TouchSelectionControllerTest, InsertionNotResetByRepeatedTapOrPress) {
base::TimeTicks event_time = base::TimeTicks::Now();
controller().OnTapEvent();
controller().OnSelectionEditable(true);
- SetDraggingEnabled(true);
+ controller().set_dragging_enabled(true);
gfx::RectF anchor_rect(10, 0, 0, 10);
bool visible = true;
- ChangeInsertion(anchor_rect, visible);
- EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_SHOWN));
- EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventAnchor());
+ EXPECT_TRUE(ChangeInsertion(anchor_rect, visible));
+ EXPECT_THAT(controller().GetAndResetEvents(), ElementsAre(INSERTION_SHOWN));
+ EXPECT_EQ(anchor_rect.bottom_left(), controller().GetLastEventAnchor());
// Tapping again shouldn't reset the active insertion point.
controller().OnTapEvent();
MockMotionEvent event(MockMotionEvent::ACTION_DOWN, event_time, 0, 0);
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
- EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_DRAG_STARTED));
- EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventAnchor());
+ EXPECT_THAT(controller().GetAndResetEvents(),
+ ElementsAre(INSERTION_DRAG_STARTED));
+ EXPECT_EQ(anchor_rect.bottom_left(), controller().GetLastEventAnchor());
event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 0, 0);
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
- EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_TAPPED,
- INSERTION_DRAG_STOPPED));
- EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventAnchor());
+ EXPECT_THAT(controller().GetAndResetEvents(),
+ ElementsAre(INSERTION_TAPPED, INSERTION_DRAG_STOPPED));
+ EXPECT_EQ(anchor_rect.bottom_left(), controller().GetLastEventAnchor());
anchor_rect.Offset(5, 15);
- ChangeInsertion(anchor_rect, visible);
- EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_MOVED));
- EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventAnchor());
+ EXPECT_TRUE(ChangeInsertion(anchor_rect, visible));
+ EXPECT_THAT(controller().GetAndResetEvents(), ElementsAre(INSERTION_MOVED));
+ EXPECT_EQ(anchor_rect.bottom_left(), controller().GetLastEventAnchor());
// Pressing shouldn't reset the active insertion point.
controller().OnLongPressEvent();
controller().OnSelectionEmpty(true);
event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time, 0, 0);
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
- EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_DRAG_STARTED));
- EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventAnchor());
+ EXPECT_THAT(controller().GetAndResetEvents(),
+ ElementsAre(INSERTION_DRAG_STARTED));
+ EXPECT_EQ(anchor_rect.bottom_left(), controller().GetLastEventAnchor());
event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 0, 0);
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
- EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_TAPPED,
- INSERTION_DRAG_STOPPED));
- EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventAnchor());
+ EXPECT_THAT(controller().GetAndResetEvents(),
+ ElementsAre(INSERTION_TAPPED, INSERTION_DRAG_STOPPED));
+ EXPECT_EQ(anchor_rect.bottom_left(), controller().GetLastEventAnchor());
}
TEST_F(TouchSelectionControllerTest, SelectionBasic) {
@@ -541,22 +567,22 @@ TEST_F(TouchSelectionControllerTest, SelectionBasic) {
bool visible = true;
// Selection events are ignored until automatic showing is enabled.
- ChangeSelection(start_rect, visible, end_rect, visible);
- EXPECT_EQ(gfx::PointF(), GetLastEventAnchor());
+ EXPECT_FALSE(ChangeSelection(start_rect, visible, end_rect, visible));
+ EXPECT_EQ(gfx::PointF(), controller().GetLastEventAnchor());
controller().OnLongPressEvent();
- ChangeSelection(start_rect, visible, end_rect, visible);
- EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_SHOWN));
- EXPECT_EQ(start_rect.bottom_left(), GetLastEventAnchor());
+ EXPECT_TRUE(ChangeSelection(start_rect, visible, end_rect, visible));
+ EXPECT_THAT(controller().GetAndResetEvents(), ElementsAre(SELECTION_SHOWN));
+ EXPECT_EQ(start_rect.bottom_left(), controller().GetLastEventAnchor());
start_rect.Offset(1, 0);
- ChangeSelection(start_rect, visible, end_rect, visible);
+ EXPECT_TRUE(ChangeSelection(start_rect, visible, end_rect, visible));
// Selection movement does not currently trigger a separate event.
- EXPECT_THAT(GetAndResetEvents(), IsEmpty());
+ EXPECT_THAT(controller().GetAndResetEvents(), IsEmpty());
- ClearSelection();
- EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_CLEARED));
- EXPECT_EQ(gfx::PointF(), GetLastEventAnchor());
+ EXPECT_TRUE(ClearSelection());
+ EXPECT_THAT(controller().GetAndResetEvents(), ElementsAre(SELECTION_CLEARED));
+ EXPECT_EQ(gfx::PointF(), controller().GetLastEventAnchor());
}
TEST_F(TouchSelectionControllerTest, SelectionRepeatedLongPress) {
@@ -565,17 +591,17 @@ TEST_F(TouchSelectionControllerTest, SelectionRepeatedLongPress) {
bool visible = true;
controller().OnLongPressEvent();
- ChangeSelection(start_rect, visible, end_rect, visible);
- EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_SHOWN));
- EXPECT_EQ(start_rect.bottom_left(), GetLastEventAnchor());
+ EXPECT_TRUE(ChangeSelection(start_rect, visible, end_rect, visible));
+ EXPECT_THAT(controller().GetAndResetEvents(), ElementsAre(SELECTION_SHOWN));
+ EXPECT_EQ(start_rect.bottom_left(), controller().GetLastEventAnchor());
// A long press triggering a new selection should re-send the SELECTION_SHOWN
// event notification.
start_rect.Offset(10, 10);
controller().OnLongPressEvent();
- ChangeSelection(start_rect, visible, end_rect, visible);
- EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_SHOWN));
- EXPECT_EQ(start_rect.bottom_left(), GetLastEventAnchor());
+ EXPECT_TRUE(ChangeSelection(start_rect, visible, end_rect, visible));
+ EXPECT_THAT(controller().GetAndResetEvents(), ElementsAre(SELECTION_SHOWN));
+ EXPECT_EQ(start_rect.bottom_left(), controller().GetLastEventAnchor());
}
TEST_F(TouchSelectionControllerTest, SelectionDragged) {
@@ -590,15 +616,15 @@ TEST_F(TouchSelectionControllerTest, SelectionDragged) {
gfx::RectF start_rect(0, 0, 0, line_height);
gfx::RectF end_rect(50, 0, 0, line_height);
bool visible = true;
- ChangeSelection(start_rect, visible, end_rect, visible);
- EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_SHOWN));
- EXPECT_EQ(start_rect.bottom_left(), GetLastEventAnchor());
+ EXPECT_TRUE(ChangeSelection(start_rect, visible, end_rect, visible));
+ EXPECT_THAT(controller().GetAndResetEvents(), ElementsAre(SELECTION_SHOWN));
+ EXPECT_EQ(start_rect.bottom_left(), controller().GetLastEventAnchor());
// The touch sequence should be handled only if the drawable reports a hit.
EXPECT_FALSE(controller().WillHandleTouchEvent(event));
- SetDraggingEnabled(true);
+ controller().set_dragging_enabled(true);
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
- EXPECT_FALSE(GetAndResetSelectionMoved());
+ EXPECT_FALSE(controller().GetAndResetSelectionMoved());
// The SelectBetweenCoordinates() result should reflect the movement. Note
// that the start coordinate will always reflect the "fixed" handle's
@@ -609,27 +635,32 @@ TEST_F(TouchSelectionControllerTest, SelectionDragged) {
gfx::PointF start_offset = start_rect.CenterPoint();
event = MockMotionEvent(MockMotionEvent::ACTION_MOVE, event_time, 0, 5);
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
- EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_DRAG_STARTED));
- EXPECT_TRUE(GetAndResetSelectionMoved());
- EXPECT_EQ(fixed_offset, GetLastSelectionStart());
- EXPECT_EQ(start_offset + gfx::Vector2dF(0, 5), GetLastSelectionEnd());
+ EXPECT_THAT(controller().GetAndResetEvents(),
+ ElementsAre(SELECTION_DRAG_STARTED));
+ EXPECT_TRUE(controller().GetAndResetSelectionMoved());
+ EXPECT_EQ(fixed_offset, controller().GetLastSelectionStart());
+ EXPECT_EQ(start_offset + gfx::Vector2dF(0, 5),
+ controller().GetLastSelectionEnd());
event = MockMotionEvent(MockMotionEvent::ACTION_MOVE, event_time, 5, 5);
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
- EXPECT_TRUE(GetAndResetSelectionMoved());
- EXPECT_EQ(fixed_offset, GetLastSelectionStart());
- EXPECT_EQ(start_offset + gfx::Vector2dF(5, 5), GetLastSelectionEnd());
+ EXPECT_TRUE(controller().GetAndResetSelectionMoved());
+ EXPECT_EQ(fixed_offset, controller().GetLastSelectionStart());
+ EXPECT_EQ(start_offset + gfx::Vector2dF(5, 5),
+ controller().GetLastSelectionEnd());
event = MockMotionEvent(MockMotionEvent::ACTION_MOVE, event_time, 10, 5);
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
- EXPECT_TRUE(GetAndResetSelectionMoved());
- EXPECT_EQ(fixed_offset, GetLastSelectionStart());
- EXPECT_EQ(start_offset + gfx::Vector2dF(10, 5), GetLastSelectionEnd());
+ EXPECT_TRUE(controller().GetAndResetSelectionMoved());
+ EXPECT_EQ(fixed_offset, controller().GetLastSelectionStart());
+ EXPECT_EQ(start_offset + gfx::Vector2dF(10, 5),
+ controller().GetLastSelectionEnd());
event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 10, 5);
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
- EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_DRAG_STOPPED));
- EXPECT_FALSE(GetAndResetSelectionMoved());
+ EXPECT_THAT(controller().GetAndResetEvents(),
+ ElementsAre(SELECTION_DRAG_STOPPED));
+ EXPECT_FALSE(controller().GetAndResetSelectionMoved());
// Once the drag is complete, no more touch events should be consumed until
// the next ACTION_DOWN.
@@ -644,34 +675,36 @@ TEST_F(TouchSelectionControllerTest, SelectionDraggedWithOverlap) {
gfx::RectF start_rect(0, 0, 0, line_height);
gfx::RectF end_rect(50, 0, 0, line_height);
bool visible = true;
- ChangeSelection(start_rect, visible, end_rect, visible);
- EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_SHOWN));
- EXPECT_EQ(start_rect.bottom_left(), GetLastEventAnchor());
+ EXPECT_TRUE(ChangeSelection(start_rect, visible, end_rect, visible));
+ EXPECT_THAT(controller().GetAndResetEvents(), ElementsAre(SELECTION_SHOWN));
+ EXPECT_EQ(start_rect.bottom_left(), controller().GetLastEventAnchor());
// The ACTION_DOWN should lock to the closest handle.
gfx::PointF end_offset = end_rect.CenterPoint();
gfx::PointF fixed_offset = start_rect.CenterPoint();
float touch_down_x = (end_offset.x() + fixed_offset.x()) / 2 + 1.f;
- MockMotionEvent event(
- MockMotionEvent::ACTION_DOWN, event_time, touch_down_x, 0);
- SetDraggingEnabled(true);
+ MockMotionEvent event(MockMotionEvent::ACTION_DOWN, event_time, touch_down_x,
+ 0);
+ controller().set_dragging_enabled(true);
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
- EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_DRAG_STARTED));
- EXPECT_FALSE(GetAndResetSelectionMoved());
+ EXPECT_THAT(controller().GetAndResetEvents(),
+ ElementsAre(SELECTION_DRAG_STARTED));
+ EXPECT_FALSE(controller().GetAndResetSelectionMoved());
// Even though the ACTION_MOVE is over the start handle, it should continue
// targetting the end handle that consumed the ACTION_DOWN.
event = MockMotionEvent(MockMotionEvent::ACTION_MOVE, event_time, 0, 0);
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
- EXPECT_TRUE(GetAndResetSelectionMoved());
- EXPECT_EQ(fixed_offset, GetLastSelectionStart());
+ EXPECT_TRUE(controller().GetAndResetSelectionMoved());
+ EXPECT_EQ(fixed_offset, controller().GetLastSelectionStart());
EXPECT_EQ(end_offset - gfx::Vector2dF(touch_down_x, 0),
- GetLastSelectionEnd());
+ controller().GetLastSelectionEnd());
event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 0, 0);
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
- EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_DRAG_STOPPED));
- EXPECT_FALSE(GetAndResetSelectionMoved());
+ EXPECT_THAT(controller().GetAndResetEvents(),
+ ElementsAre(SELECTION_DRAG_STOPPED));
+ EXPECT_FALSE(controller().GetAndResetSelectionMoved());
}
TEST_F(TouchSelectionControllerTest, SelectionDraggedToSwitchBaseAndExtent) {
@@ -682,112 +715,124 @@ TEST_F(TouchSelectionControllerTest, SelectionDraggedToSwitchBaseAndExtent) {
gfx::RectF start_rect(50, line_height, 0, line_height);
gfx::RectF end_rect(100, line_height, 0, line_height);
bool visible = true;
- ChangeSelection(start_rect, visible, end_rect, visible);
- EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_SHOWN));
- EXPECT_EQ(start_rect.bottom_left(), GetLastEventAnchor());
+ EXPECT_TRUE(ChangeSelection(start_rect, visible, end_rect, visible));
+ EXPECT_THAT(controller().GetAndResetEvents(), ElementsAre(SELECTION_SHOWN));
+ EXPECT_EQ(start_rect.bottom_left(), controller().GetLastEventAnchor());
- SetDraggingEnabled(true);
+ controller().set_dragging_enabled(true);
// Move the extent, not triggering a swap of points.
MockMotionEvent event(MockMotionEvent::ACTION_DOWN, event_time,
end_rect.x(), end_rect.bottom());
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
- EXPECT_FALSE(GetAndResetSelectionMoved());
- EXPECT_FALSE(GetAndResetSelectionPointsSwapped());
+ EXPECT_FALSE(controller().GetAndResetSelectionMoved());
+ EXPECT_FALSE(controller().GetAndResetSelectionPointsSwapped());
gfx::PointF base_offset = start_rect.CenterPoint();
gfx::PointF extent_offset = end_rect.CenterPoint();
event = MockMotionEvent(MockMotionEvent::ACTION_MOVE, event_time,
end_rect.x(), end_rect.bottom() + 5);
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
- EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_DRAG_STARTED));
- EXPECT_TRUE(GetAndResetSelectionMoved());
- EXPECT_FALSE(GetAndResetSelectionPointsSwapped());
- EXPECT_EQ(base_offset, GetLastSelectionStart());
- EXPECT_EQ(extent_offset + gfx::Vector2dF(0, 5), GetLastSelectionEnd());
+ EXPECT_THAT(controller().GetAndResetEvents(),
+ ElementsAre(SELECTION_DRAG_STARTED));
+ EXPECT_TRUE(controller().GetAndResetSelectionMoved());
+ EXPECT_FALSE(controller().GetAndResetSelectionPointsSwapped());
+ EXPECT_EQ(base_offset, controller().GetLastSelectionStart());
+ EXPECT_EQ(extent_offset + gfx::Vector2dF(0, 5),
+ controller().GetLastSelectionEnd());
event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 10, 5);
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
- EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_DRAG_STOPPED));
- EXPECT_FALSE(GetAndResetSelectionMoved());
+ EXPECT_THAT(controller().GetAndResetEvents(),
+ ElementsAre(SELECTION_DRAG_STOPPED));
+ EXPECT_FALSE(controller().GetAndResetSelectionMoved());
end_rect += gfx::Vector2dF(0, 5);
- ChangeSelection(start_rect, visible, end_rect, visible);
+ EXPECT_TRUE(ChangeSelection(start_rect, visible, end_rect, visible));
// Move the base, triggering a swap of points.
event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time,
start_rect.x(), start_rect.bottom());
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
- EXPECT_FALSE(GetAndResetSelectionMoved());
- EXPECT_TRUE(GetAndResetSelectionPointsSwapped());
+ EXPECT_FALSE(controller().GetAndResetSelectionMoved());
+ EXPECT_TRUE(controller().GetAndResetSelectionPointsSwapped());
base_offset = end_rect.CenterPoint();
extent_offset = start_rect.CenterPoint();
event = MockMotionEvent(MockMotionEvent::ACTION_MOVE, event_time,
start_rect.x(), start_rect.bottom() + 5);
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
- EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_DRAG_STARTED));
- EXPECT_TRUE(GetAndResetSelectionMoved());
- EXPECT_FALSE(GetAndResetSelectionPointsSwapped());
- EXPECT_EQ(base_offset, GetLastSelectionStart());
- EXPECT_EQ(extent_offset + gfx::Vector2dF(0, 5), GetLastSelectionEnd());
+ EXPECT_THAT(controller().GetAndResetEvents(),
+ ElementsAre(SELECTION_DRAG_STARTED));
+ EXPECT_TRUE(controller().GetAndResetSelectionMoved());
+ EXPECT_FALSE(controller().GetAndResetSelectionPointsSwapped());
+ EXPECT_EQ(base_offset, controller().GetLastSelectionStart());
+ EXPECT_EQ(extent_offset + gfx::Vector2dF(0, 5),
+ controller().GetLastSelectionEnd());
event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 10, 5);
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
- EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_DRAG_STOPPED));
- EXPECT_FALSE(GetAndResetSelectionMoved());
+ EXPECT_THAT(controller().GetAndResetEvents(),
+ ElementsAre(SELECTION_DRAG_STOPPED));
+ EXPECT_FALSE(controller().GetAndResetSelectionMoved());
start_rect += gfx::Vector2dF(0, 5);
- ChangeSelection(start_rect, visible, end_rect, visible);
+ EXPECT_TRUE(ChangeSelection(start_rect, visible, end_rect, visible));
// Move the same point again, not triggering a swap of points.
event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time,
start_rect.x(), start_rect.bottom());
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
- EXPECT_FALSE(GetAndResetSelectionMoved());
- EXPECT_FALSE(GetAndResetSelectionPointsSwapped());
+ EXPECT_FALSE(controller().GetAndResetSelectionMoved());
+ EXPECT_FALSE(controller().GetAndResetSelectionPointsSwapped());
base_offset = end_rect.CenterPoint();
extent_offset = start_rect.CenterPoint();
event = MockMotionEvent(MockMotionEvent::ACTION_MOVE, event_time,
start_rect.x(), start_rect.bottom() + 5);
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
- EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_DRAG_STARTED));
- EXPECT_TRUE(GetAndResetSelectionMoved());
- EXPECT_FALSE(GetAndResetSelectionPointsSwapped());
- EXPECT_EQ(base_offset, GetLastSelectionStart());
- EXPECT_EQ(extent_offset + gfx::Vector2dF(0, 5), GetLastSelectionEnd());
+ EXPECT_THAT(controller().GetAndResetEvents(),
+ ElementsAre(SELECTION_DRAG_STARTED));
+ EXPECT_TRUE(controller().GetAndResetSelectionMoved());
+ EXPECT_FALSE(controller().GetAndResetSelectionPointsSwapped());
+ EXPECT_EQ(base_offset, controller().GetLastSelectionStart());
+ EXPECT_EQ(extent_offset + gfx::Vector2dF(0, 5),
+ controller().GetLastSelectionEnd());
event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 10, 5);
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
- EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_DRAG_STOPPED));
- EXPECT_FALSE(GetAndResetSelectionMoved());
+ EXPECT_THAT(controller().GetAndResetEvents(),
+ ElementsAre(SELECTION_DRAG_STOPPED));
+ EXPECT_FALSE(controller().GetAndResetSelectionMoved());
start_rect += gfx::Vector2dF(0, 5);
- ChangeSelection(start_rect, visible, end_rect, visible);
+ EXPECT_TRUE(ChangeSelection(start_rect, visible, end_rect, visible));
// Move the base, triggering a swap of points.
event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time,
end_rect.x(), end_rect.bottom());
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
- EXPECT_FALSE(GetAndResetSelectionMoved());
- EXPECT_TRUE(GetAndResetSelectionPointsSwapped());
+ EXPECT_FALSE(controller().GetAndResetSelectionMoved());
+ EXPECT_TRUE(controller().GetAndResetSelectionPointsSwapped());
base_offset = start_rect.CenterPoint();
extent_offset = end_rect.CenterPoint();
event = MockMotionEvent(MockMotionEvent::ACTION_MOVE, event_time,
end_rect.x(), end_rect.bottom() + 5);
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
- EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_DRAG_STARTED));
- EXPECT_TRUE(GetAndResetSelectionMoved());
- EXPECT_FALSE(GetAndResetSelectionPointsSwapped());
- EXPECT_EQ(base_offset, GetLastSelectionStart());
- EXPECT_EQ(extent_offset + gfx::Vector2dF(0, 5), GetLastSelectionEnd());
+ EXPECT_THAT(controller().GetAndResetEvents(),
+ ElementsAre(SELECTION_DRAG_STARTED));
+ EXPECT_TRUE(controller().GetAndResetSelectionMoved());
+ EXPECT_FALSE(controller().GetAndResetSelectionPointsSwapped());
+ EXPECT_EQ(base_offset, controller().GetLastSelectionStart());
+ EXPECT_EQ(extent_offset + gfx::Vector2dF(0, 5),
+ controller().GetLastSelectionEnd());
event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 10, 5);
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
- EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_DRAG_STOPPED));
- EXPECT_FALSE(GetAndResetSelectionMoved());
+ EXPECT_THAT(controller().GetAndResetEvents(),
+ ElementsAre(SELECTION_DRAG_STOPPED));
+ EXPECT_FALSE(controller().GetAndResetSelectionMoved());
}
TEST_F(TouchSelectionControllerTest, SelectionDragExtremeLineSize) {
@@ -799,30 +844,32 @@ TEST_F(TouchSelectionControllerTest, SelectionDragExtremeLineSize) {
gfx::RectF small_line_rect(0, 0, 0, small_line_height);
gfx::RectF large_line_rect(50, 50, 0, large_line_height);
bool visible = true;
- ChangeSelection(small_line_rect, visible, large_line_rect, visible);
- EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_SHOWN));
- EXPECT_EQ(small_line_rect.bottom_left(), GetLastEventAnchor());
+ EXPECT_TRUE(
+ ChangeSelection(small_line_rect, visible, large_line_rect, visible));
+ EXPECT_THAT(controller().GetAndResetEvents(), ElementsAre(SELECTION_SHOWN));
+ EXPECT_EQ(small_line_rect.bottom_left(), controller().GetLastEventAnchor());
// Start dragging the handle on the small line.
MockMotionEvent event(MockMotionEvent::ACTION_DOWN, event_time,
small_line_rect.x(), small_line_rect.y());
- SetDraggingEnabled(true);
+ controller().set_dragging_enabled(true);
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
- EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_DRAG_STARTED));
+ EXPECT_THAT(controller().GetAndResetEvents(),
+ ElementsAre(SELECTION_DRAG_STARTED));
// The drag coordinate for large lines should be capped to a reasonable
// offset, allowing seamless transition to neighboring lines with different
// sizes. The drag coordinate for small lines should have an offset
// commensurate with the small line size.
EXPECT_EQ(large_line_rect.bottom_left() - gfx::Vector2dF(0, 5.f),
- GetLastSelectionStart());
- EXPECT_EQ(small_line_rect.CenterPoint(), GetLastSelectionEnd());
+ controller().GetLastSelectionStart());
+ EXPECT_EQ(small_line_rect.CenterPoint(), controller().GetLastSelectionEnd());
small_line_rect += gfx::Vector2dF(25.f, 0);
event = MockMotionEvent(MockMotionEvent::ACTION_MOVE, event_time,
small_line_rect.x(), small_line_rect.y());
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
- EXPECT_TRUE(GetAndResetSelectionMoved());
- EXPECT_EQ(small_line_rect.CenterPoint(), GetLastSelectionEnd());
+ EXPECT_TRUE(controller().GetAndResetSelectionMoved());
+ EXPECT_EQ(small_line_rect.CenterPoint(), controller().GetLastSelectionEnd());
}
TEST_F(TouchSelectionControllerTest, Animation) {
@@ -832,27 +879,27 @@ TEST_F(TouchSelectionControllerTest, Animation) {
gfx::RectF insertion_rect(5, 5, 0, 10);
bool visible = true;
- ChangeInsertion(insertion_rect, visible);
- EXPECT_FALSE(GetAndResetNeedsAnimate());
+ EXPECT_TRUE(ChangeInsertion(insertion_rect, visible));
+ EXPECT_FALSE(controller().GetAndResetNeedsAnimate());
visible = false;
- ChangeInsertion(insertion_rect, visible);
- EXPECT_TRUE(GetAndResetNeedsAnimate());
+ EXPECT_TRUE(ChangeInsertion(insertion_rect, visible));
+ EXPECT_TRUE(controller().GetAndResetNeedsAnimate());
visible = true;
- ChangeInsertion(insertion_rect, visible);
- EXPECT_TRUE(GetAndResetNeedsAnimate());
+ EXPECT_TRUE(ChangeInsertion(insertion_rect, visible));
+ EXPECT_TRUE(controller().GetAndResetNeedsAnimate());
// If the handles are explicity hidden, no animation should be triggered.
controller().HideAndDisallowShowingAutomatically();
- EXPECT_FALSE(GetAndResetNeedsAnimate());
+ EXPECT_FALSE(controller().GetAndResetNeedsAnimate());
// If the client doesn't support animation, no animation should be triggered.
- SetAnimationEnabled(false);
+ controller().set_animation_enabled(false);
controller().OnTapEvent();
visible = true;
- ChangeInsertion(insertion_rect, visible);
- EXPECT_FALSE(GetAndResetNeedsAnimate());
+ EXPECT_TRUE(ChangeInsertion(insertion_rect, visible));
+ EXPECT_FALSE(controller().GetAndResetNeedsAnimate());
}
TEST_F(TouchSelectionControllerTest, TemporarilyHidden) {
@@ -862,22 +909,22 @@ TEST_F(TouchSelectionControllerTest, TemporarilyHidden) {
gfx::RectF insertion_rect(5, 5, 0, 10);
bool visible = true;
- ChangeInsertion(insertion_rect, visible);
- EXPECT_FALSE(GetAndResetNeedsAnimate());
+ EXPECT_TRUE(ChangeInsertion(insertion_rect, visible));
+ EXPECT_FALSE(controller().GetAndResetNeedsAnimate());
controller().SetTemporarilyHidden(true);
- EXPECT_TRUE(GetAndResetNeedsAnimate());
+ EXPECT_TRUE(controller().GetAndResetNeedsAnimate());
visible = false;
- ChangeInsertion(insertion_rect, visible);
- EXPECT_FALSE(GetAndResetNeedsAnimate());
+ EXPECT_TRUE(ChangeInsertion(insertion_rect, visible));
+ EXPECT_FALSE(controller().GetAndResetNeedsAnimate());
visible = true;
- ChangeInsertion(insertion_rect, visible);
- EXPECT_FALSE(GetAndResetNeedsAnimate());
+ EXPECT_TRUE(ChangeInsertion(insertion_rect, visible));
+ EXPECT_FALSE(controller().GetAndResetNeedsAnimate());
controller().SetTemporarilyHidden(false);
- EXPECT_TRUE(GetAndResetNeedsAnimate());
+ EXPECT_TRUE(controller().GetAndResetNeedsAnimate());
}
TEST_F(TouchSelectionControllerTest, SelectionClearOnTap) {
@@ -886,18 +933,18 @@ TEST_F(TouchSelectionControllerTest, SelectionClearOnTap) {
bool visible = true;
controller().OnLongPressEvent();
- ChangeSelection(start_rect, visible, end_rect, visible);
- EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_SHOWN));
+ EXPECT_TRUE(ChangeSelection(start_rect, visible, end_rect, visible));
+ EXPECT_THAT(controller().GetAndResetEvents(), ElementsAre(SELECTION_SHOWN));
// Selection should not be cleared if the selection bounds have not changed.
controller().OnTapEvent();
- EXPECT_THAT(GetAndResetEvents(), IsEmpty());
- EXPECT_EQ(start_rect.bottom_left(), GetLastEventAnchor());
+ EXPECT_THAT(controller().GetAndResetEvents(), IsEmpty());
+ EXPECT_EQ(start_rect.bottom_left(), controller().GetLastEventAnchor());
controller().OnTapEvent();
- ClearSelection();
- EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_CLEARED));
- EXPECT_EQ(gfx::PointF(), GetLastEventAnchor());
+ EXPECT_TRUE(ClearSelection());
+ EXPECT_THAT(controller().GetAndResetEvents(), ElementsAre(SELECTION_CLEARED));
+ EXPECT_EQ(gfx::PointF(), controller().GetLastEventAnchor());
}
TEST_F(TouchSelectionControllerTest, AllowShowingFromCurrentSelection) {
@@ -906,34 +953,34 @@ TEST_F(TouchSelectionControllerTest, AllowShowingFromCurrentSelection) {
bool visible = true;
// The selection should not be activated, as it wasn't yet allowed.
- ChangeSelection(start_rect, visible, end_rect, visible);
- EXPECT_EQ(gfx::PointF(), GetLastEventAnchor());
+ EXPECT_FALSE(ChangeSelection(start_rect, visible, end_rect, visible));
+ EXPECT_EQ(gfx::PointF(), controller().GetLastEventAnchor());
// Now explicitly allow showing from the previously supplied bounds.
controller().AllowShowingFromCurrentSelection();
- EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_SHOWN));
- EXPECT_EQ(start_rect.bottom_left(), GetLastEventAnchor());
+ EXPECT_THAT(controller().GetAndResetEvents(), ElementsAre(SELECTION_SHOWN));
+ EXPECT_EQ(start_rect.bottom_left(), controller().GetLastEventAnchor());
// Repeated calls to show from the current selection should be ignored.
controller().AllowShowingFromCurrentSelection();
- EXPECT_THAT(GetAndResetEvents(), IsEmpty());
- EXPECT_EQ(start_rect.bottom_left(), GetLastEventAnchor());
+ EXPECT_THAT(controller().GetAndResetEvents(), IsEmpty());
+ EXPECT_EQ(start_rect.bottom_left(), controller().GetLastEventAnchor());
// Trying to show from an empty selection will have no result.
- ClearSelection();
- EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_CLEARED));
+ EXPECT_TRUE(ClearSelection());
+ EXPECT_THAT(controller().GetAndResetEvents(), ElementsAre(SELECTION_CLEARED));
controller().AllowShowingFromCurrentSelection();
- EXPECT_THAT(GetAndResetEvents(), IsEmpty());
+ EXPECT_THAT(controller().GetAndResetEvents(), IsEmpty());
// Showing the insertion handle should also be supported.
controller().OnSelectionEditable(true);
controller().OnSelectionEmpty(false);
controller().HideAndDisallowShowingAutomatically();
gfx::RectF insertion_rect(5, 5, 0, 10);
- ChangeInsertion(insertion_rect, visible);
+ EXPECT_FALSE(ChangeInsertion(insertion_rect, visible));
controller().AllowShowingFromCurrentSelection();
- EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_SHOWN));
- EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventAnchor());
+ EXPECT_THAT(controller().GetAndResetEvents(), ElementsAre(INSERTION_SHOWN));
+ EXPECT_EQ(insertion_rect.bottom_left(), controller().GetLastEventAnchor());
}
} // namespace ui
« no previous file with comments | « ui/touch_selection/touch_selection_controller_impl.cc ('k') | ui/touch_selection/touch_selection_menu_runner.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698