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

Side by Side Diff: ui/touch_selection/touch_selection_controller_unittest.cc

Issue 1129193007: aw: Ensure synchronization of PopupWindow handle visibility/position (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Slightly simpler visibility fix Created 5 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
« no previous file with comments | « ui/touch_selection/touch_selection_controller.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/touch_selection/touch_selection_controller.h" 5 #include "ui/touch_selection/touch_selection_controller.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "testing/gmock/include/gmock/gmock.h" 9 #include "testing/gmock/include/gmock/gmock.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 94
95 void MoveRangeSelectionExtent(const gfx::PointF& extent) override { 95 void MoveRangeSelectionExtent(const gfx::PointF& extent) override {
96 selection_moved_ = true; 96 selection_moved_ = true;
97 selection_end_ = extent; 97 selection_end_ = extent;
98 } 98 }
99 99
100 void OnSelectionEvent(SelectionEventType event) override { 100 void OnSelectionEvent(SelectionEventType event) override {
101 events_.push_back(event); 101 events_.push_back(event);
102 last_event_start_ = controller_->GetStartPosition(); 102 last_event_start_ = controller_->GetStartPosition();
103 last_event_end_ = controller_->GetEndPosition(); 103 last_event_end_ = controller_->GetEndPosition();
104 last_event_bounds_rect_ = controller_->GetRectBetweenBounds();
104 } 105 }
105 106
106 scoped_ptr<TouchHandleDrawable> CreateDrawable() override { 107 scoped_ptr<TouchHandleDrawable> CreateDrawable() override {
107 return make_scoped_ptr(new MockTouchHandleDrawable(&dragging_enabled_)); 108 return make_scoped_ptr(new MockTouchHandleDrawable(&dragging_enabled_));
108 } 109 }
109 110
110 void AllowShowingOnTapForEmptyEditable() { 111 void AllowShowingOnTapForEmptyEditable() {
111 bool show_on_tap_for_empty_editable = true; 112 bool show_on_tap_for_empty_editable = true;
112 controller_.reset(new TouchSelectionController( 113 controller_.reset(new TouchSelectionController(
113 this, 114 this,
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 bool swapped = selection_points_swapped_; 187 bool swapped = selection_points_swapped_;
187 selection_points_swapped_ = false; 188 selection_points_swapped_ = false;
188 return swapped; 189 return swapped;
189 } 190 }
190 191
191 const gfx::PointF& GetLastCaretPosition() const { return caret_position_; } 192 const gfx::PointF& GetLastCaretPosition() const { return caret_position_; }
192 const gfx::PointF& GetLastSelectionStart() const { return selection_start_; } 193 const gfx::PointF& GetLastSelectionStart() const { return selection_start_; }
193 const gfx::PointF& GetLastSelectionEnd() const { return selection_end_; } 194 const gfx::PointF& GetLastSelectionEnd() const { return selection_end_; }
194 const gfx::PointF& GetLastEventStart() const { return last_event_start_; } 195 const gfx::PointF& GetLastEventStart() const { return last_event_start_; }
195 const gfx::PointF& GetLastEventEnd() const { return last_event_end_; } 196 const gfx::PointF& GetLastEventEnd() const { return last_event_end_; }
197 const gfx::RectF& GetLastEventBoundsRect() const {
198 return last_event_bounds_rect_;
199 }
196 200
197 std::vector<SelectionEventType> GetAndResetEvents() { 201 std::vector<SelectionEventType> GetAndResetEvents() {
198 std::vector<SelectionEventType> events; 202 std::vector<SelectionEventType> events;
199 events.swap(events_); 203 events.swap(events_);
200 return events; 204 return events;
201 } 205 }
202 206
203 TouchSelectionController& controller() { return *controller_; } 207 TouchSelectionController& controller() { return *controller_; }
204 208
205 private: 209 private:
206 gfx::PointF last_event_start_; 210 gfx::PointF last_event_start_;
207 gfx::PointF last_event_end_; 211 gfx::PointF last_event_end_;
208 gfx::PointF caret_position_; 212 gfx::PointF caret_position_;
209 gfx::PointF selection_start_; 213 gfx::PointF selection_start_;
210 gfx::PointF selection_end_; 214 gfx::PointF selection_end_;
215 gfx::RectF last_event_bounds_rect_;
211 std::vector<SelectionEventType> events_; 216 std::vector<SelectionEventType> events_;
212 bool caret_moved_; 217 bool caret_moved_;
213 bool selection_moved_; 218 bool selection_moved_;
214 bool selection_points_swapped_; 219 bool selection_points_swapped_;
215 bool needs_animate_; 220 bool needs_animate_;
216 bool animation_enabled_; 221 bool animation_enabled_;
217 bool dragging_enabled_; 222 bool dragging_enabled_;
218 scoped_ptr<TouchSelectionController> controller_; 223 scoped_ptr<TouchSelectionController> controller_;
219 224
220 DISALLOW_COPY_AND_ASSIGN(TouchSelectionControllerTest); 225 DISALLOW_COPY_AND_ASSIGN(TouchSelectionControllerTest);
(...skipping 818 matching lines...) Expand 10 before | Expand all | Expand 10 after
1039 1044
1040 // A point outside the rect should not be handled. 1045 // A point outside the rect should not be handled.
1041 EXPECT_FALSE(controller().WillHandleLongPressEvent(outer_point)); 1046 EXPECT_FALSE(controller().WillHandleLongPressEvent(outer_point));
1042 EXPECT_THAT(GetAndResetEvents(), IsEmpty()); 1047 EXPECT_THAT(GetAndResetEvents(), IsEmpty());
1043 1048
1044 // A point inside the rect should be handled. 1049 // A point inside the rect should be handled.
1045 EXPECT_TRUE(controller().WillHandleLongPressEvent(inner_point)); 1050 EXPECT_TRUE(controller().WillHandleLongPressEvent(inner_point));
1046 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_SHOWN)); 1051 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_SHOWN));
1047 } 1052 }
1048 1053
1054 TEST_F(TouchSelectionControllerTest, RectBetweenBounds) {
1055 gfx::RectF start_rect(5, 5, 0, 10);
1056 gfx::RectF end_rect(50, 5, 0, 10);
1057 bool visible = true;
1058
1059 EXPECT_EQ(gfx::RectF(), controller().GetRectBetweenBounds());
1060
1061 OnLongPressEvent();
1062 ChangeSelection(start_rect, visible, end_rect, visible);
1063 ASSERT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_SHOWN));
1064 EXPECT_EQ(gfx::RectF(5, 5, 45, 10), controller().GetRectBetweenBounds());
1065
1066 // The result of |GetRectBetweenBounds| should be available within the
1067 // |OnSelectionEvent| callback, as stored by |GetLastEventBoundsRect()|.
1068 EXPECT_EQ(GetLastEventBoundsRect(), controller().GetRectBetweenBounds());
1069
1070 start_rect.Offset(1, 0);
1071 ChangeSelection(start_rect, visible, end_rect, visible);
1072 ASSERT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_MOVED));
1073 EXPECT_EQ(gfx::RectF(6, 5, 44, 10), controller().GetRectBetweenBounds());
1074 EXPECT_EQ(GetLastEventBoundsRect(), controller().GetRectBetweenBounds());
1075
1076 // If only one bound is visible, the selection bounding rect should reflect
1077 // only the visible bound.
1078 ChangeSelection(start_rect, visible, end_rect, false);
1079 ASSERT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_MOVED));
1080 EXPECT_EQ(start_rect, controller().GetRectBetweenBounds());
1081 EXPECT_EQ(GetLastEventBoundsRect(), controller().GetRectBetweenBounds());
1082
1083 ChangeSelection(start_rect, false, end_rect, visible);
1084 ASSERT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_MOVED));
1085 EXPECT_EQ(end_rect, controller().GetRectBetweenBounds());
1086 EXPECT_EQ(GetLastEventBoundsRect(), controller().GetRectBetweenBounds());
1087
1088 // If both bounds are visible, the full bounding rect should be returned.
1089 ChangeSelection(start_rect, false, end_rect, false);
1090 ASSERT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_MOVED));
1091 EXPECT_EQ(gfx::RectF(6, 5, 44, 10), controller().GetRectBetweenBounds());
1092 EXPECT_EQ(GetLastEventBoundsRect(), controller().GetRectBetweenBounds());
1093
1094 ClearSelection();
1095 ASSERT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_CLEARED));
1096 EXPECT_EQ(gfx::RectF(), controller().GetRectBetweenBounds());
1097 }
1098
1049 } // namespace ui 1099 } // namespace ui
OLDNEW
« 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