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

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

Issue 937773003: Add INSERTION_DRAG_STOPPED to SelectionEventType (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updated insertion drag test Created 5 years, 10 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 <map>
8
7 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
8 #include "ui/events/test/motion_event_test_utils.h" 10 #include "ui/events/test/motion_event_test_utils.h"
9 11
10 using ui::test::MockMotionEvent; 12 using ui::test::MockMotionEvent;
11 13
12 namespace ui { 14 namespace ui {
13 namespace { 15 namespace {
14 16
15 const int kDefaultTapTimeoutMs = 200; 17 const int kDefaultTapTimeoutMs = 200;
16 const float kDefaulTapSlop = 10.f; 18 const float kDefaulTapSlop = 10.f;
(...skipping 15 matching lines...) Expand all
32 private: 34 private:
33 bool* intersects_rect_; 35 bool* intersects_rect_;
34 }; 36 };
35 37
36 } // namespace 38 } // namespace
37 39
38 class TouchSelectionControllerTest : public testing::Test, 40 class TouchSelectionControllerTest : public testing::Test,
39 public TouchSelectionControllerClient { 41 public TouchSelectionControllerClient {
40 public: 42 public:
41 TouchSelectionControllerTest() 43 TouchSelectionControllerTest()
42 : last_event_(SELECTION_CLEARED), 44 : caret_moved_(false),
43 caret_moved_(false),
44 selection_moved_(false), 45 selection_moved_(false),
45 selection_points_swapped_(false), 46 selection_points_swapped_(false),
46 needs_animate_(false), 47 needs_animate_(false),
47 animation_enabled_(true), 48 animation_enabled_(true),
48 dragging_enabled_(false) {} 49 dragging_enabled_(false) {}
49 50
50 ~TouchSelectionControllerTest() override {} 51 ~TouchSelectionControllerTest() override {}
51 52
52 // testing::Test implementation. 53 // testing::Test implementation.
53 54
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 selection_end_ = extent; 86 selection_end_ = extent;
86 } 87 }
87 88
88 void MoveRangeSelectionExtent(const gfx::PointF& extent) override { 89 void MoveRangeSelectionExtent(const gfx::PointF& extent) override {
89 selection_moved_ = true; 90 selection_moved_ = true;
90 selection_end_ = extent; 91 selection_end_ = extent;
91 } 92 }
92 93
93 void OnSelectionEvent(SelectionEventType event, 94 void OnSelectionEvent(SelectionEventType event,
94 const gfx::PointF& end_position) override { 95 const gfx::PointF& end_position) override {
95 last_event_ = event; 96 event_count_[event]++;
jdduke (slow) 2015/02/18 22:03:49 Hmm, you could use a bool + the type, |bool has_re
mohsen 2015/02/18 23:35:22 I ended up adding a total count for events to be a
96 last_event_start_ = end_position; 97 last_event_start_ = end_position;
97 } 98 }
98 99
99 scoped_ptr<TouchHandleDrawable> CreateDrawable() override { 100 scoped_ptr<TouchHandleDrawable> CreateDrawable() override {
100 return scoped_ptr<TouchHandleDrawable>( 101 return scoped_ptr<TouchHandleDrawable>(
101 new MockTouchHandleDrawable(&dragging_enabled_)); 102 new MockTouchHandleDrawable(&dragging_enabled_));
102 } 103 }
103 104
104 void AllowShowingOnTapForEmptyEditable() { 105 void AllowShowingOnTapForEmptyEditable() {
105 bool show_on_tap_for_empty_editable = true; 106 bool show_on_tap_for_empty_editable = true;
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 171
171 bool GetAndResetSelectionPointsSwapped() { 172 bool GetAndResetSelectionPointsSwapped() {
172 bool swapped = selection_points_swapped_; 173 bool swapped = selection_points_swapped_;
173 selection_points_swapped_ = false; 174 selection_points_swapped_ = false;
174 return swapped; 175 return swapped;
175 } 176 }
176 177
177 const gfx::PointF& GetLastCaretPosition() const { return caret_position_; } 178 const gfx::PointF& GetLastCaretPosition() const { return caret_position_; }
178 const gfx::PointF& GetLastSelectionStart() const { return selection_start_; } 179 const gfx::PointF& GetLastSelectionStart() const { return selection_start_; }
179 const gfx::PointF& GetLastSelectionEnd() const { return selection_end_; } 180 const gfx::PointF& GetLastSelectionEnd() const { return selection_end_; }
180 SelectionEventType GetLastEventType() const { return last_event_; }
181 const gfx::PointF& GetLastEventAnchor() const { return last_event_start_; } 181 const gfx::PointF& GetLastEventAnchor() const { return last_event_start_; }
182 182
183 int GetAndResetEventCount(SelectionEventType event) {
184 int count = event_count_[event];
185 event_count_.erase(event);
186 return count;
187 }
188
183 TouchSelectionController& controller() { return *controller_; } 189 TouchSelectionController& controller() { return *controller_; }
184 190
185 private: 191 private:
186 gfx::PointF last_event_start_; 192 gfx::PointF last_event_start_;
187 gfx::PointF caret_position_; 193 gfx::PointF caret_position_;
188 gfx::PointF selection_start_; 194 gfx::PointF selection_start_;
189 gfx::PointF selection_end_; 195 gfx::PointF selection_end_;
190 SelectionEventType last_event_; 196 std::map<SelectionEventType, int> event_count_;
191 bool caret_moved_; 197 bool caret_moved_;
192 bool selection_moved_; 198 bool selection_moved_;
193 bool selection_points_swapped_; 199 bool selection_points_swapped_;
194 bool needs_animate_; 200 bool needs_animate_;
195 bool animation_enabled_; 201 bool animation_enabled_;
196 bool dragging_enabled_; 202 bool dragging_enabled_;
197 scoped_ptr<TouchSelectionController> controller_; 203 scoped_ptr<TouchSelectionController> controller_;
198 }; 204 };
199 205
200 TEST_F(TouchSelectionControllerTest, InsertionBasic) { 206 TEST_F(TouchSelectionControllerTest, InsertionBasic) {
201 gfx::RectF insertion_rect(5, 5, 0, 10); 207 gfx::RectF insertion_rect(5, 5, 0, 10);
202 bool visible = true; 208 bool visible = true;
203 209
204 // Insertion events are ignored until automatic showing is enabled. 210 // Insertion events are ignored until automatic showing is enabled.
205 ChangeInsertion(insertion_rect, visible); 211 ChangeInsertion(insertion_rect, visible);
212 EXPECT_EQ(0, GetAndResetEventCount(INSERTION_SHOWN));
213 EXPECT_EQ(0, GetAndResetEventCount(INSERTION_MOVED));
214 EXPECT_EQ(0, GetAndResetEventCount(INSERTION_CLEARED));
206 EXPECT_EQ(gfx::PointF(), GetLastEventAnchor()); 215 EXPECT_EQ(gfx::PointF(), GetLastEventAnchor());
207 controller().OnTapEvent(); 216 controller().OnTapEvent();
208 217
209 // Insertion events are ignored until the selection region is marked editable. 218 // Insertion events are ignored until the selection region is marked editable.
210 ChangeInsertion(insertion_rect, visible); 219 ChangeInsertion(insertion_rect, visible);
220 EXPECT_EQ(0, GetAndResetEventCount(INSERTION_SHOWN));
221 EXPECT_EQ(0, GetAndResetEventCount(INSERTION_MOVED));
222 EXPECT_EQ(0, GetAndResetEventCount(INSERTION_CLEARED));
211 EXPECT_EQ(gfx::PointF(), GetLastEventAnchor()); 223 EXPECT_EQ(gfx::PointF(), GetLastEventAnchor());
212 224
213 controller().OnTapEvent(); 225 controller().OnTapEvent();
214 controller().OnSelectionEditable(true); 226 controller().OnSelectionEditable(true);
215 ChangeInsertion(insertion_rect, visible); 227 ChangeInsertion(insertion_rect, visible);
216 EXPECT_EQ(INSERTION_SHOWN, GetLastEventType()); 228 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_SHOWN));
229 EXPECT_EQ(0, GetAndResetEventCount(INSERTION_MOVED));
230 EXPECT_EQ(0, GetAndResetEventCount(INSERTION_CLEARED));
jdduke (slow) 2015/02/18 19:09:14 This is a lot of boilerplate for every check. Wha
mohsen 2015/02/18 21:53:36 There are some location where we test more than la
217 EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventAnchor()); 231 EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventAnchor());
218 232
219 insertion_rect.Offset(1, 0); 233 insertion_rect.Offset(1, 0);
220 ChangeInsertion(insertion_rect, visible); 234 ChangeInsertion(insertion_rect, visible);
221 EXPECT_EQ(INSERTION_MOVED, GetLastEventType()); 235 EXPECT_EQ(0, GetAndResetEventCount(INSERTION_SHOWN));
236 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_MOVED));
237 EXPECT_EQ(0, GetAndResetEventCount(INSERTION_CLEARED));
222 EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventAnchor()); 238 EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventAnchor());
223 239
224 insertion_rect.Offset(0, 1); 240 insertion_rect.Offset(0, 1);
225 ChangeInsertion(insertion_rect, visible); 241 ChangeInsertion(insertion_rect, visible);
226 EXPECT_EQ(INSERTION_MOVED, GetLastEventType()); 242 EXPECT_EQ(0, GetAndResetEventCount(INSERTION_SHOWN));
243 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_MOVED));
244 EXPECT_EQ(0, GetAndResetEventCount(INSERTION_CLEARED));
227 EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventAnchor()); 245 EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventAnchor());
228 246
229 ClearInsertion(); 247 ClearInsertion();
230 EXPECT_EQ(INSERTION_CLEARED, GetLastEventType()); 248 EXPECT_EQ(0, GetAndResetEventCount(INSERTION_SHOWN));
249 EXPECT_EQ(0, GetAndResetEventCount(INSERTION_MOVED));
250 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_CLEARED));
231 } 251 }
232 252
233 TEST_F(TouchSelectionControllerTest, InsertionClearedWhenNoLongerEditable) { 253 TEST_F(TouchSelectionControllerTest, InsertionClearedWhenNoLongerEditable) {
234 gfx::RectF insertion_rect(5, 5, 0, 10); 254 gfx::RectF insertion_rect(5, 5, 0, 10);
235 bool visible = true; 255 bool visible = true;
236 controller().OnTapEvent(); 256 controller().OnTapEvent();
237 controller().OnSelectionEditable(true); 257 controller().OnSelectionEditable(true);
238 258
239 ChangeInsertion(insertion_rect, visible); 259 ChangeInsertion(insertion_rect, visible);
240 EXPECT_EQ(INSERTION_SHOWN, GetLastEventType()); 260 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_SHOWN));
261 EXPECT_EQ(0, GetAndResetEventCount(INSERTION_CLEARED));
241 EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventAnchor()); 262 EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventAnchor());
242 263
243 controller().OnSelectionEditable(false); 264 controller().OnSelectionEditable(false);
244 EXPECT_EQ(INSERTION_CLEARED, GetLastEventType()); 265 EXPECT_EQ(0, GetAndResetEventCount(INSERTION_SHOWN));
266 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_CLEARED));
245 } 267 }
246 268
247 TEST_F(TouchSelectionControllerTest, InsertionWithNoShowOnTapForEmptyEditable) { 269 TEST_F(TouchSelectionControllerTest, InsertionWithNoShowOnTapForEmptyEditable) {
248 gfx::RectF insertion_rect(5, 5, 0, 10); 270 gfx::RectF insertion_rect(5, 5, 0, 10);
249 bool visible = true; 271 bool visible = true;
250 controller().OnSelectionEditable(true); 272 controller().OnSelectionEditable(true);
251 273
252 // Taps on an empty editable region should be ignored if the controller is 274 // Taps on an empty editable region should be ignored if the controller is
253 // created with |show_on_tap_for_empty_editable| set to false. 275 // created with |show_on_tap_for_empty_editable| set to false.
254 controller().OnTapEvent(); 276 controller().OnTapEvent();
255 controller().OnSelectionEmpty(true); 277 controller().OnSelectionEmpty(true);
256 ChangeInsertion(insertion_rect, visible); 278 ChangeInsertion(insertion_rect, visible);
257 EXPECT_EQ(gfx::PointF(), GetLastEventAnchor()); 279 EXPECT_EQ(gfx::PointF(), GetLastEventAnchor());
258 280
259 // Once the region becomes non-empty, taps should show the insertion handle. 281 // Once the region becomes non-empty, taps should show the insertion handle.
260 controller().OnTapEvent(); 282 controller().OnTapEvent();
261 controller().OnSelectionEmpty(false); 283 controller().OnSelectionEmpty(false);
262 ChangeInsertion(insertion_rect, visible); 284 ChangeInsertion(insertion_rect, visible);
263 EXPECT_EQ(INSERTION_SHOWN, GetLastEventType()); 285 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_SHOWN));
286 EXPECT_EQ(0, GetAndResetEventCount(INSERTION_CLEARED));
264 EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventAnchor()); 287 EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventAnchor());
265 288
266 // Reset the selection. 289 // Reset the selection.
267 controller().HideAndDisallowShowingAutomatically(); 290 controller().HideAndDisallowShowingAutomatically();
268 EXPECT_EQ(INSERTION_CLEARED, GetLastEventType()); 291 EXPECT_EQ(0, GetAndResetEventCount(INSERTION_SHOWN));
292 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_CLEARED));
269 293
270 // Long-pressing should show the handle even if the editable region is empty. 294 // Long-pressing should show the handle even if the editable region is empty.
271 insertion_rect.Offset(2, -2); 295 insertion_rect.Offset(2, -2);
272 controller().OnLongPressEvent(); 296 controller().OnLongPressEvent();
273 controller().OnSelectionEmpty(true); 297 controller().OnSelectionEmpty(true);
274 ChangeInsertion(insertion_rect, visible); 298 ChangeInsertion(insertion_rect, visible);
275 EXPECT_EQ(INSERTION_SHOWN, GetLastEventType()); 299 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_SHOWN));
300 EXPECT_EQ(0, GetAndResetEventCount(INSERTION_CLEARED));
276 EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventAnchor()); 301 EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventAnchor());
277 302
278 // Single Tap on an empty edit field should clear insertion handle. 303 // Single Tap on an empty edit field should clear insertion handle.
279 controller().OnTapEvent(); 304 controller().OnTapEvent();
280 EXPECT_EQ(INSERTION_CLEARED, GetLastEventType()); 305 EXPECT_EQ(0, GetAndResetEventCount(INSERTION_SHOWN));
306 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_CLEARED));
281 } 307 }
282 308
283 TEST_F(TouchSelectionControllerTest, InsertionWithShowOnTapForEmptyEditable) { 309 TEST_F(TouchSelectionControllerTest, InsertionWithShowOnTapForEmptyEditable) {
284 AllowShowingOnTapForEmptyEditable(); 310 AllowShowingOnTapForEmptyEditable();
285 311
286 gfx::RectF insertion_rect(5, 5, 0, 10); 312 gfx::RectF insertion_rect(5, 5, 0, 10);
287 bool visible = true; 313 bool visible = true;
288 controller().OnSelectionEditable(true); 314 controller().OnSelectionEditable(true);
289 315
290 // Taps on an empty editable region should show the insertion handle if the 316 // Taps on an empty editable region should show the insertion handle if the
291 // controller is created with |show_on_tap_for_empty_editable| set to true. 317 // controller is created with |show_on_tap_for_empty_editable| set to true.
292 controller().OnTapEvent(); 318 controller().OnTapEvent();
293 controller().OnSelectionEmpty(true); 319 controller().OnSelectionEmpty(true);
294 ChangeInsertion(insertion_rect, visible); 320 ChangeInsertion(insertion_rect, visible);
295 EXPECT_EQ(INSERTION_SHOWN, GetLastEventType()); 321 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_SHOWN));
322 EXPECT_EQ(0, GetAndResetEventCount(INSERTION_CLEARED));
296 EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventAnchor()); 323 EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventAnchor());
297 } 324 }
298 325
299 TEST_F(TouchSelectionControllerTest, InsertionAppearsAfterTapFollowingTyping) { 326 TEST_F(TouchSelectionControllerTest, InsertionAppearsAfterTapFollowingTyping) {
300 gfx::RectF insertion_rect(5, 5, 0, 10); 327 gfx::RectF insertion_rect(5, 5, 0, 10);
301 bool visible = true; 328 bool visible = true;
302 329
303 // Simulate the user tapping an empty text field. 330 // Simulate the user tapping an empty text field.
304 controller().OnTapEvent(); 331 controller().OnTapEvent();
305 controller().OnSelectionEditable(true); 332 controller().OnSelectionEditable(true);
306 controller().OnSelectionEmpty(true); 333 controller().OnSelectionEmpty(true);
307 ChangeInsertion(insertion_rect, visible); 334 ChangeInsertion(insertion_rect, visible);
308 EXPECT_EQ(gfx::PointF(), GetLastEventAnchor()); 335 EXPECT_EQ(gfx::PointF(), GetLastEventAnchor());
309 336
310 // Simulate the cursor moving while a user is typing. 337 // Simulate the cursor moving while a user is typing.
311 insertion_rect.Offset(10, 0); 338 insertion_rect.Offset(10, 0);
312 controller().OnSelectionEmpty(false); 339 controller().OnSelectionEmpty(false);
313 ChangeInsertion(insertion_rect, visible); 340 ChangeInsertion(insertion_rect, visible);
314 EXPECT_EQ(gfx::PointF(), GetLastEventAnchor()); 341 EXPECT_EQ(gfx::PointF(), GetLastEventAnchor());
315 342
316 // If the user taps the *same* position as the cursor at the end of the text 343 // If the user taps the *same* position as the cursor at the end of the text
317 // entry, the handle should appear. 344 // entry, the handle should appear.
318 controller().OnTapEvent(); 345 controller().OnTapEvent();
319 ChangeInsertion(insertion_rect, visible); 346 ChangeInsertion(insertion_rect, visible);
320 EXPECT_EQ(INSERTION_SHOWN, GetLastEventType()); 347 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_SHOWN));
321 EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventAnchor()); 348 EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventAnchor());
322 } 349 }
323 350
324 TEST_F(TouchSelectionControllerTest, InsertionToSelectionTransition) { 351 TEST_F(TouchSelectionControllerTest, InsertionToSelectionTransition) {
325 controller().OnLongPressEvent(); 352 controller().OnLongPressEvent();
326 controller().OnSelectionEditable(true); 353 controller().OnSelectionEditable(true);
327 354
328 gfx::RectF start_rect(5, 5, 0, 10); 355 gfx::RectF start_rect(5, 5, 0, 10);
329 gfx::RectF end_rect(50, 5, 0, 10); 356 gfx::RectF end_rect(50, 5, 0, 10);
330 bool visible = true; 357 bool visible = true;
331 358
332 ChangeInsertion(start_rect, visible); 359 ChangeInsertion(start_rect, visible);
333 EXPECT_EQ(INSERTION_SHOWN, GetLastEventType()); 360 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_SHOWN));
361 EXPECT_EQ(0, GetAndResetEventCount(INSERTION_CLEARED));
334 EXPECT_EQ(start_rect.bottom_left(), GetLastEventAnchor()); 362 EXPECT_EQ(start_rect.bottom_left(), GetLastEventAnchor());
335 363
336 ChangeSelection(start_rect, visible, end_rect, visible); 364 ChangeSelection(start_rect, visible, end_rect, visible);
337 EXPECT_EQ(SELECTION_SHOWN, GetLastEventType()); 365 EXPECT_EQ(1, GetAndResetEventCount(SELECTION_SHOWN));
366 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_CLEARED));
338 EXPECT_EQ(start_rect.bottom_left(), GetLastEventAnchor()); 367 EXPECT_EQ(start_rect.bottom_left(), GetLastEventAnchor());
339 368
340 ChangeInsertion(end_rect, visible); 369 ChangeInsertion(end_rect, visible);
341 EXPECT_EQ(INSERTION_SHOWN, GetLastEventType()); 370 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_SHOWN));
371 EXPECT_EQ(0, GetAndResetEventCount(INSERTION_CLEARED));
342 EXPECT_EQ(end_rect.bottom_left(), GetLastEventAnchor()); 372 EXPECT_EQ(end_rect.bottom_left(), GetLastEventAnchor());
343 373
344 controller().HideAndDisallowShowingAutomatically(); 374 controller().HideAndDisallowShowingAutomatically();
345 EXPECT_EQ(INSERTION_CLEARED, GetLastEventType()); 375 EXPECT_EQ(0, GetAndResetEventCount(INSERTION_SHOWN));
376 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_CLEARED));
346 377
347 controller().OnTapEvent(); 378 controller().OnTapEvent();
348 ChangeInsertion(end_rect, visible); 379 ChangeInsertion(end_rect, visible);
349 EXPECT_EQ(INSERTION_SHOWN, GetLastEventType()); 380 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_SHOWN));
381 EXPECT_EQ(0, GetAndResetEventCount(INSERTION_CLEARED));
350 EXPECT_EQ(end_rect.bottom_left(), GetLastEventAnchor()); 382 EXPECT_EQ(end_rect.bottom_left(), GetLastEventAnchor());
351 } 383 }
352 384
353 TEST_F(TouchSelectionControllerTest, InsertionDragged) { 385 TEST_F(TouchSelectionControllerTest, InsertionDragged) {
354 base::TimeTicks event_time = base::TimeTicks::Now(); 386 base::TimeTicks event_time = base::TimeTicks::Now();
355 controller().OnTapEvent(); 387 controller().OnTapEvent();
356 controller().OnSelectionEditable(true); 388 controller().OnSelectionEditable(true);
357 389
358 // The touch sequence should not be handled if insertion is not active. 390 // The touch sequence should not be handled if insertion is not active.
359 MockMotionEvent event(MockMotionEvent::ACTION_DOWN, event_time, 0, 0); 391 MockMotionEvent event(MockMotionEvent::ACTION_DOWN, event_time, 0, 0);
360 EXPECT_FALSE(controller().WillHandleTouchEvent(event)); 392 EXPECT_FALSE(controller().WillHandleTouchEvent(event));
361 393
362 float line_height = 10.f; 394 float line_height = 10.f;
363 gfx::RectF start_rect(10, 0, 0, line_height); 395 gfx::RectF start_rect(10, 0, 0, line_height);
364 bool visible = true; 396 bool visible = true;
365 ChangeInsertion(start_rect, visible); 397 ChangeInsertion(start_rect, visible);
366 EXPECT_EQ(INSERTION_SHOWN, GetLastEventType()); 398 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_SHOWN));
399 EXPECT_EQ(0, GetAndResetEventCount(INSERTION_DRAG_STARTED));
400 EXPECT_EQ(0, GetAndResetEventCount(INSERTION_DRAG_STOPPED));
367 EXPECT_EQ(start_rect.bottom_left(), GetLastEventAnchor()); 401 EXPECT_EQ(start_rect.bottom_left(), GetLastEventAnchor());
368 402
369 // The touch sequence should be handled only if the drawable reports a hit. 403 // The touch sequence should be handled only if the drawable reports a hit.
370 EXPECT_FALSE(controller().WillHandleTouchEvent(event)); 404 EXPECT_FALSE(controller().WillHandleTouchEvent(event));
371 SetDraggingEnabled(true); 405 SetDraggingEnabled(true);
372 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); 406 EXPECT_TRUE(controller().WillHandleTouchEvent(event));
373 EXPECT_FALSE(GetAndResetCaretMoved()); 407 EXPECT_FALSE(GetAndResetCaretMoved());
408 EXPECT_EQ(0, GetAndResetEventCount(INSERTION_SHOWN));
409 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_DRAG_STARTED));
410 EXPECT_EQ(0, GetAndResetEventCount(INSERTION_DRAG_STOPPED));
374 411
375 // The MoveCaret() result should reflect the movement. 412 // The MoveCaret() result should reflect the movement.
376 // The reported position is offset from the center of |start_rect|. 413 // The reported position is offset from the center of |start_rect|.
377 gfx::PointF start_offset = start_rect.CenterPoint(); 414 gfx::PointF start_offset = start_rect.CenterPoint();
378 event = MockMotionEvent(MockMotionEvent::ACTION_MOVE, event_time, 0, 5); 415 event = MockMotionEvent(MockMotionEvent::ACTION_MOVE, event_time, 0, 5);
379 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); 416 EXPECT_TRUE(controller().WillHandleTouchEvent(event));
380 EXPECT_TRUE(GetAndResetCaretMoved()); 417 EXPECT_TRUE(GetAndResetCaretMoved());
381 EXPECT_EQ(start_offset + gfx::Vector2dF(0, 5), GetLastCaretPosition()); 418 EXPECT_EQ(start_offset + gfx::Vector2dF(0, 5), GetLastCaretPosition());
382 419
383 event = MockMotionEvent(MockMotionEvent::ACTION_MOVE, event_time, 5, 5); 420 event = MockMotionEvent(MockMotionEvent::ACTION_MOVE, event_time, 5, 5);
384 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); 421 EXPECT_TRUE(controller().WillHandleTouchEvent(event));
385 EXPECT_TRUE(GetAndResetCaretMoved()); 422 EXPECT_TRUE(GetAndResetCaretMoved());
386 EXPECT_EQ(start_offset + gfx::Vector2dF(5, 5), GetLastCaretPosition()); 423 EXPECT_EQ(start_offset + gfx::Vector2dF(5, 5), GetLastCaretPosition());
387 424
388 event = MockMotionEvent(MockMotionEvent::ACTION_MOVE, event_time, 10, 10); 425 event = MockMotionEvent(MockMotionEvent::ACTION_MOVE, event_time, 10, 10);
389 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); 426 EXPECT_TRUE(controller().WillHandleTouchEvent(event));
390 EXPECT_TRUE(GetAndResetCaretMoved()); 427 EXPECT_TRUE(GetAndResetCaretMoved());
391 EXPECT_EQ(start_offset + gfx::Vector2dF(10, 10), GetLastCaretPosition()); 428 EXPECT_EQ(start_offset + gfx::Vector2dF(10, 10), GetLastCaretPosition());
392 429
393 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 10, 5); 430 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 10, 5);
394 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); 431 EXPECT_TRUE(controller().WillHandleTouchEvent(event));
395 EXPECT_FALSE(GetAndResetCaretMoved()); 432 EXPECT_FALSE(GetAndResetCaretMoved());
433 EXPECT_EQ(0, GetAndResetEventCount(INSERTION_SHOWN));
434 EXPECT_EQ(0, GetAndResetEventCount(INSERTION_DRAG_STARTED));
435 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_DRAG_STOPPED));
396 436
397 // Once the drag is complete, no more touch events should be consumed until 437 // Once the drag is complete, no more touch events should be consumed until
398 // the next ACTION_DOWN. 438 // the next ACTION_DOWN.
399 EXPECT_FALSE(controller().WillHandleTouchEvent(event)); 439 EXPECT_FALSE(controller().WillHandleTouchEvent(event));
400 } 440 }
401 441
402 TEST_F(TouchSelectionControllerTest, InsertionTapped) { 442 TEST_F(TouchSelectionControllerTest, InsertionTapped) {
403 base::TimeTicks event_time = base::TimeTicks::Now(); 443 base::TimeTicks event_time = base::TimeTicks::Now();
404 controller().OnTapEvent(); 444 controller().OnTapEvent();
405 controller().OnSelectionEditable(true); 445 controller().OnSelectionEditable(true);
406 SetDraggingEnabled(true); 446 SetDraggingEnabled(true);
407 447
408 gfx::RectF start_rect(10, 0, 0, 10); 448 gfx::RectF start_rect(10, 0, 0, 10);
409 bool visible = true; 449 bool visible = true;
410 ChangeInsertion(start_rect, visible); 450 ChangeInsertion(start_rect, visible);
411 EXPECT_EQ(INSERTION_SHOWN, GetLastEventType()); 451 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_SHOWN));
452 EXPECT_EQ(0, GetAndResetEventCount(INSERTION_DRAG_STARTED));
453 EXPECT_EQ(0, GetAndResetEventCount(INSERTION_DRAG_STOPPED));
454 EXPECT_EQ(0, GetAndResetEventCount(INSERTION_TAPPED));
412 455
413 MockMotionEvent event(MockMotionEvent::ACTION_DOWN, event_time, 0, 0); 456 MockMotionEvent event(MockMotionEvent::ACTION_DOWN, event_time, 0, 0);
414 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); 457 EXPECT_TRUE(controller().WillHandleTouchEvent(event));
415 //TODO(AKV): this test case has to be modified once crbug.com/394093 is fixed. 458 //TODO(AKV): this test case has to be modified once crbug.com/394093 is fixed.
416 EXPECT_EQ(INSERTION_DRAG_STARTED, GetLastEventType()); 459 EXPECT_EQ(0, GetAndResetEventCount(INSERTION_SHOWN));
460 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_DRAG_STARTED));
461 EXPECT_EQ(0, GetAndResetEventCount(INSERTION_DRAG_STOPPED));
462 EXPECT_EQ(0, GetAndResetEventCount(INSERTION_TAPPED));
417 463
418 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 0, 0); 464 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 0, 0);
419 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); 465 EXPECT_TRUE(controller().WillHandleTouchEvent(event));
420 EXPECT_EQ(INSERTION_TAPPED, GetLastEventType()); 466 EXPECT_EQ(0, GetAndResetEventCount(INSERTION_SHOWN));
467 EXPECT_EQ(0, GetAndResetEventCount(INSERTION_DRAG_STARTED));
468 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_DRAG_STOPPED));
469 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_TAPPED));
421 470
422 // Reset the insertion. 471 // Reset the insertion.
423 ClearInsertion(); 472 ClearInsertion();
424 controller().OnTapEvent(); 473 controller().OnTapEvent();
425 ChangeInsertion(start_rect, visible); 474 ChangeInsertion(start_rect, visible);
426 ASSERT_EQ(INSERTION_SHOWN, GetLastEventType()); 475 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_SHOWN));
476 EXPECT_EQ(0, GetAndResetEventCount(INSERTION_DRAG_STARTED));
477 EXPECT_EQ(0, GetAndResetEventCount(INSERTION_DRAG_STOPPED));
478 EXPECT_EQ(0, GetAndResetEventCount(INSERTION_TAPPED));
427 479
428 // No tap should be signalled if the time between DOWN and UP was too long. 480 // No tap should be signalled if the time between DOWN and UP was too long.
429 event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time, 0, 0); 481 event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time, 0, 0);
430 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); 482 EXPECT_TRUE(controller().WillHandleTouchEvent(event));
431 event = MockMotionEvent(MockMotionEvent::ACTION_UP, 483 event = MockMotionEvent(MockMotionEvent::ACTION_UP,
432 event_time + base::TimeDelta::FromSeconds(1), 484 event_time + base::TimeDelta::FromSeconds(1),
433 0, 485 0,
434 0); 486 0);
435 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); 487 EXPECT_TRUE(controller().WillHandleTouchEvent(event));
436 EXPECT_EQ(INSERTION_DRAG_STARTED, GetLastEventType()); 488 EXPECT_EQ(0, GetAndResetEventCount(INSERTION_SHOWN));
489 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_DRAG_STARTED));
490 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_DRAG_STOPPED));
491 EXPECT_EQ(0, GetAndResetEventCount(INSERTION_TAPPED));
437 492
438 // Reset the insertion. 493 // Reset the insertion.
439 ClearInsertion(); 494 ClearInsertion();
440 controller().OnTapEvent(); 495 controller().OnTapEvent();
441 ChangeInsertion(start_rect, visible); 496 ChangeInsertion(start_rect, visible);
442 ASSERT_EQ(INSERTION_SHOWN, GetLastEventType()); 497 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_SHOWN));
498 EXPECT_EQ(0, GetAndResetEventCount(INSERTION_DRAG_STARTED));
499 EXPECT_EQ(0, GetAndResetEventCount(INSERTION_DRAG_STOPPED));
500 EXPECT_EQ(0, GetAndResetEventCount(INSERTION_TAPPED));
443 501
444 // No tap should be signalled if the drag was too long. 502 // No tap should be signalled if the drag was too long.
445 event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time, 0, 0); 503 event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time, 0, 0);
446 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); 504 EXPECT_TRUE(controller().WillHandleTouchEvent(event));
447 event = MockMotionEvent(MockMotionEvent::ACTION_MOVE, event_time, 100, 0); 505 event = MockMotionEvent(MockMotionEvent::ACTION_MOVE, event_time, 100, 0);
448 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); 506 EXPECT_TRUE(controller().WillHandleTouchEvent(event));
449 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 100, 0); 507 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 100, 0);
450 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); 508 EXPECT_TRUE(controller().WillHandleTouchEvent(event));
451 EXPECT_EQ(INSERTION_DRAG_STARTED, GetLastEventType()); 509 EXPECT_EQ(0, GetAndResetEventCount(INSERTION_SHOWN));
510 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_DRAG_STARTED));
511 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_DRAG_STOPPED));
512 EXPECT_EQ(0, GetAndResetEventCount(INSERTION_TAPPED));
452 513
453 // Reset the insertion. 514 // Reset the insertion.
454 ClearInsertion(); 515 ClearInsertion();
455 controller().OnTapEvent(); 516 controller().OnTapEvent();
456 ChangeInsertion(start_rect, visible); 517 ChangeInsertion(start_rect, visible);
457 ASSERT_EQ(INSERTION_SHOWN, GetLastEventType()); 518 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_SHOWN));
519 EXPECT_EQ(0, GetAndResetEventCount(INSERTION_DRAG_STARTED));
520 EXPECT_EQ(0, GetAndResetEventCount(INSERTION_DRAG_STOPPED));
521 EXPECT_EQ(0, GetAndResetEventCount(INSERTION_TAPPED));
458 522
459 // No tap should be signalled if the touch sequence is cancelled. 523 // No tap should be signalled if the touch sequence is cancelled.
460 event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time, 0, 0); 524 event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time, 0, 0);
461 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); 525 EXPECT_TRUE(controller().WillHandleTouchEvent(event));
462 event = MockMotionEvent(MockMotionEvent::ACTION_CANCEL, event_time, 0, 0); 526 event = MockMotionEvent(MockMotionEvent::ACTION_CANCEL, event_time, 0, 0);
463 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); 527 EXPECT_TRUE(controller().WillHandleTouchEvent(event));
464 EXPECT_EQ(INSERTION_DRAG_STARTED, GetLastEventType()); 528 EXPECT_EQ(0, GetAndResetEventCount(INSERTION_SHOWN));
529 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_DRAG_STARTED));
530 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_DRAG_STOPPED));
531 EXPECT_EQ(0, GetAndResetEventCount(INSERTION_TAPPED));
465 } 532 }
466 533
467 TEST_F(TouchSelectionControllerTest, InsertionNotResetByRepeatedTapOrPress) { 534 TEST_F(TouchSelectionControllerTest, InsertionNotResetByRepeatedTapOrPress) {
468 base::TimeTicks event_time = base::TimeTicks::Now(); 535 base::TimeTicks event_time = base::TimeTicks::Now();
469 controller().OnTapEvent(); 536 controller().OnTapEvent();
470 controller().OnSelectionEditable(true); 537 controller().OnSelectionEditable(true);
471 SetDraggingEnabled(true); 538 SetDraggingEnabled(true);
472 539
473 gfx::RectF anchor_rect(10, 0, 0, 10); 540 gfx::RectF anchor_rect(10, 0, 0, 10);
474 bool visible = true; 541 bool visible = true;
475 ChangeInsertion(anchor_rect, visible); 542 ChangeInsertion(anchor_rect, visible);
476 EXPECT_EQ(INSERTION_SHOWN, GetLastEventType()); 543 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_SHOWN));
544 EXPECT_EQ(0, GetAndResetEventCount(INSERTION_DRAG_STARTED));
545 EXPECT_EQ(0, GetAndResetEventCount(INSERTION_TAPPED));
546 EXPECT_EQ(0, GetAndResetEventCount(INSERTION_MOVED));
477 EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventAnchor()); 547 EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventAnchor());
478 548
479 // Tapping again shouldn't reset the active insertion point. 549 // Tapping again shouldn't reset the active insertion point.
480 controller().OnTapEvent(); 550 controller().OnTapEvent();
481 MockMotionEvent event(MockMotionEvent::ACTION_DOWN, event_time, 0, 0); 551 MockMotionEvent event(MockMotionEvent::ACTION_DOWN, event_time, 0, 0);
482 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); 552 EXPECT_TRUE(controller().WillHandleTouchEvent(event));
483 EXPECT_EQ(INSERTION_DRAG_STARTED, GetLastEventType()); 553 EXPECT_EQ(0, GetAndResetEventCount(INSERTION_SHOWN));
554 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_DRAG_STARTED));
555 EXPECT_EQ(0, GetAndResetEventCount(INSERTION_TAPPED));
556 EXPECT_EQ(0, GetAndResetEventCount(INSERTION_MOVED));
484 EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventAnchor()); 557 EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventAnchor());
485 558
486 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 0, 0); 559 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 0, 0);
487 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); 560 EXPECT_TRUE(controller().WillHandleTouchEvent(event));
488 EXPECT_EQ(INSERTION_TAPPED, GetLastEventType()); 561 EXPECT_EQ(0, GetAndResetEventCount(INSERTION_SHOWN));
562 EXPECT_EQ(0, GetAndResetEventCount(INSERTION_DRAG_STARTED));
563 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_TAPPED));
564 EXPECT_EQ(0, GetAndResetEventCount(INSERTION_MOVED));
489 EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventAnchor()); 565 EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventAnchor());
490 566
491 anchor_rect.Offset(5, 15); 567 anchor_rect.Offset(5, 15);
492 ChangeInsertion(anchor_rect, visible); 568 ChangeInsertion(anchor_rect, visible);
493 EXPECT_EQ(INSERTION_MOVED, GetLastEventType()); 569 EXPECT_EQ(0, GetAndResetEventCount(INSERTION_SHOWN));
570 EXPECT_EQ(0, GetAndResetEventCount(INSERTION_DRAG_STARTED));
571 EXPECT_EQ(0, GetAndResetEventCount(INSERTION_TAPPED));
572 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_MOVED));
494 EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventAnchor()); 573 EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventAnchor());
495 574
496 // Pressing shouldn't reset the active insertion point. 575 // Pressing shouldn't reset the active insertion point.
497 controller().OnLongPressEvent(); 576 controller().OnLongPressEvent();
498 controller().OnSelectionEmpty(true); 577 controller().OnSelectionEmpty(true);
499 event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time, 0, 0); 578 event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time, 0, 0);
500 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); 579 EXPECT_TRUE(controller().WillHandleTouchEvent(event));
501 EXPECT_EQ(INSERTION_DRAG_STARTED, GetLastEventType()); 580 EXPECT_EQ(0, GetAndResetEventCount(INSERTION_SHOWN));
581 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_DRAG_STARTED));
582 EXPECT_EQ(0, GetAndResetEventCount(INSERTION_TAPPED));
583 EXPECT_EQ(0, GetAndResetEventCount(INSERTION_MOVED));
502 EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventAnchor()); 584 EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventAnchor());
503 585
504 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 0, 0); 586 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 0, 0);
505 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); 587 EXPECT_TRUE(controller().WillHandleTouchEvent(event));
506 EXPECT_EQ(INSERTION_TAPPED, GetLastEventType()); 588 EXPECT_EQ(0, GetAndResetEventCount(INSERTION_SHOWN));
589 EXPECT_EQ(0, GetAndResetEventCount(INSERTION_DRAG_STARTED));
590 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_TAPPED));
591 EXPECT_EQ(0, GetAndResetEventCount(INSERTION_MOVED));
507 EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventAnchor()); 592 EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventAnchor());
508 } 593 }
509 594
510 TEST_F(TouchSelectionControllerTest, SelectionBasic) { 595 TEST_F(TouchSelectionControllerTest, SelectionBasic) {
511 gfx::RectF start_rect(5, 5, 0, 10); 596 gfx::RectF start_rect(5, 5, 0, 10);
512 gfx::RectF end_rect(50, 5, 0, 10); 597 gfx::RectF end_rect(50, 5, 0, 10);
513 bool visible = true; 598 bool visible = true;
514 599
515 // Selection events are ignored until automatic showing is enabled. 600 // Selection events are ignored until automatic showing is enabled.
516 ChangeSelection(start_rect, visible, end_rect, visible); 601 ChangeSelection(start_rect, visible, end_rect, visible);
517 EXPECT_EQ(gfx::PointF(), GetLastEventAnchor()); 602 EXPECT_EQ(gfx::PointF(), GetLastEventAnchor());
518 603
519 controller().OnLongPressEvent(); 604 controller().OnLongPressEvent();
520 ChangeSelection(start_rect, visible, end_rect, visible); 605 ChangeSelection(start_rect, visible, end_rect, visible);
521 EXPECT_EQ(SELECTION_SHOWN, GetLastEventType()); 606 EXPECT_EQ(1, GetAndResetEventCount(SELECTION_SHOWN));
607 EXPECT_EQ(0, GetAndResetEventCount(SELECTION_CLEARED));
522 EXPECT_EQ(start_rect.bottom_left(), GetLastEventAnchor()); 608 EXPECT_EQ(start_rect.bottom_left(), GetLastEventAnchor());
523 609
524 start_rect.Offset(1, 0); 610 start_rect.Offset(1, 0);
525 ChangeSelection(start_rect, visible, end_rect, visible); 611 ChangeSelection(start_rect, visible, end_rect, visible);
526 // Selection movement does not currently trigger a separate event. 612 // Selection movement does not currently trigger a separate event.
527 EXPECT_EQ(SELECTION_SHOWN, GetLastEventType()); 613 EXPECT_EQ(0, GetAndResetEventCount(SELECTION_SHOWN));
614 EXPECT_EQ(0, GetAndResetEventCount(SELECTION_CLEARED));
528 615
529 ClearSelection(); 616 ClearSelection();
530 EXPECT_EQ(SELECTION_CLEARED, GetLastEventType()); 617 EXPECT_EQ(0, GetAndResetEventCount(SELECTION_SHOWN));
618 EXPECT_EQ(1, GetAndResetEventCount(SELECTION_CLEARED));
531 EXPECT_EQ(gfx::PointF(), GetLastEventAnchor()); 619 EXPECT_EQ(gfx::PointF(), GetLastEventAnchor());
532 } 620 }
533 621
534 TEST_F(TouchSelectionControllerTest, SelectionRepeatedLongPress) { 622 TEST_F(TouchSelectionControllerTest, SelectionRepeatedLongPress) {
535 gfx::RectF start_rect(5, 5, 0, 10); 623 gfx::RectF start_rect(5, 5, 0, 10);
536 gfx::RectF end_rect(50, 5, 0, 10); 624 gfx::RectF end_rect(50, 5, 0, 10);
537 bool visible = true; 625 bool visible = true;
538 626
539 controller().OnLongPressEvent(); 627 controller().OnLongPressEvent();
540 ChangeSelection(start_rect, visible, end_rect, visible); 628 ChangeSelection(start_rect, visible, end_rect, visible);
541 EXPECT_EQ(SELECTION_SHOWN, GetLastEventType()); 629 EXPECT_EQ(1, GetAndResetEventCount(SELECTION_SHOWN));
542 EXPECT_EQ(start_rect.bottom_left(), GetLastEventAnchor()); 630 EXPECT_EQ(start_rect.bottom_left(), GetLastEventAnchor());
543 631
544 // A long press triggering a new selection should re-send the SELECTION_SHOWN 632 // A long press triggering a new selection should re-send the SELECTION_SHOWN
545 // event notification. 633 // event notification.
546 start_rect.Offset(10, 10); 634 start_rect.Offset(10, 10);
547 controller().OnLongPressEvent(); 635 controller().OnLongPressEvent();
548 ChangeSelection(start_rect, visible, end_rect, visible); 636 ChangeSelection(start_rect, visible, end_rect, visible);
549 EXPECT_EQ(SELECTION_SHOWN, GetLastEventType()); 637 EXPECT_EQ(1, GetAndResetEventCount(SELECTION_SHOWN));
550 EXPECT_EQ(start_rect.bottom_left(), GetLastEventAnchor()); 638 EXPECT_EQ(start_rect.bottom_left(), GetLastEventAnchor());
551 } 639 }
552 640
553 TEST_F(TouchSelectionControllerTest, SelectionDragged) { 641 TEST_F(TouchSelectionControllerTest, SelectionDragged) {
554 base::TimeTicks event_time = base::TimeTicks::Now(); 642 base::TimeTicks event_time = base::TimeTicks::Now();
555 controller().OnLongPressEvent(); 643 controller().OnLongPressEvent();
556 644
557 // The touch sequence should not be handled if selection is not active. 645 // The touch sequence should not be handled if selection is not active.
558 MockMotionEvent event(MockMotionEvent::ACTION_DOWN, event_time, 0, 0); 646 MockMotionEvent event(MockMotionEvent::ACTION_DOWN, event_time, 0, 0);
559 EXPECT_FALSE(controller().WillHandleTouchEvent(event)); 647 EXPECT_FALSE(controller().WillHandleTouchEvent(event));
560 648
561 float line_height = 10.f; 649 float line_height = 10.f;
562 gfx::RectF start_rect(0, 0, 0, line_height); 650 gfx::RectF start_rect(0, 0, 0, line_height);
563 gfx::RectF end_rect(50, 0, 0, line_height); 651 gfx::RectF end_rect(50, 0, 0, line_height);
564 bool visible = true; 652 bool visible = true;
565 ChangeSelection(start_rect, visible, end_rect, visible); 653 ChangeSelection(start_rect, visible, end_rect, visible);
566 EXPECT_EQ(SELECTION_SHOWN, GetLastEventType()); 654 EXPECT_EQ(1, GetAndResetEventCount(SELECTION_SHOWN));
655 EXPECT_EQ(0, GetAndResetEventCount(SELECTION_DRAG_STARTED));
656 EXPECT_EQ(0, GetAndResetEventCount(SELECTION_DRAG_STOPPED));
567 EXPECT_EQ(start_rect.bottom_left(), GetLastEventAnchor()); 657 EXPECT_EQ(start_rect.bottom_left(), GetLastEventAnchor());
568 658
569 // The touch sequence should be handled only if the drawable reports a hit. 659 // The touch sequence should be handled only if the drawable reports a hit.
570 EXPECT_FALSE(controller().WillHandleTouchEvent(event)); 660 EXPECT_FALSE(controller().WillHandleTouchEvent(event));
571 SetDraggingEnabled(true); 661 SetDraggingEnabled(true);
572 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); 662 EXPECT_TRUE(controller().WillHandleTouchEvent(event));
573 EXPECT_FALSE(GetAndResetSelectionMoved()); 663 EXPECT_FALSE(GetAndResetSelectionMoved());
574 664
575 // The SelectBetweenCoordinates() result should reflect the movement. Note 665 // The SelectBetweenCoordinates() result should reflect the movement. Note
576 // that the start coordinate will always reflect the "fixed" handle's 666 // that the start coordinate will always reflect the "fixed" handle's
577 // position, in this case the position from |end_rect|. 667 // position, in this case the position from |end_rect|.
578 // Note that the reported position is offset from the center of the 668 // Note that the reported position is offset from the center of the
579 // input rects (i.e., the middle of the corresponding text line). 669 // input rects (i.e., the middle of the corresponding text line).
580 gfx::PointF fixed_offset = end_rect.CenterPoint(); 670 gfx::PointF fixed_offset = end_rect.CenterPoint();
581 gfx::PointF start_offset = start_rect.CenterPoint(); 671 gfx::PointF start_offset = start_rect.CenterPoint();
582 event = MockMotionEvent(MockMotionEvent::ACTION_MOVE, event_time, 0, 5); 672 event = MockMotionEvent(MockMotionEvent::ACTION_MOVE, event_time, 0, 5);
583 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); 673 EXPECT_TRUE(controller().WillHandleTouchEvent(event));
584 EXPECT_EQ(SELECTION_DRAG_STARTED, GetLastEventType()); 674 EXPECT_EQ(0, GetAndResetEventCount(SELECTION_SHOWN));
675 EXPECT_EQ(1, GetAndResetEventCount(SELECTION_DRAG_STARTED));
676 EXPECT_EQ(0, GetAndResetEventCount(SELECTION_DRAG_STOPPED));
585 EXPECT_TRUE(GetAndResetSelectionMoved()); 677 EXPECT_TRUE(GetAndResetSelectionMoved());
586 EXPECT_EQ(fixed_offset, GetLastSelectionStart()); 678 EXPECT_EQ(fixed_offset, GetLastSelectionStart());
587 EXPECT_EQ(start_offset + gfx::Vector2dF(0, 5), GetLastSelectionEnd()); 679 EXPECT_EQ(start_offset + gfx::Vector2dF(0, 5), GetLastSelectionEnd());
588 680
589 event = MockMotionEvent(MockMotionEvent::ACTION_MOVE, event_time, 5, 5); 681 event = MockMotionEvent(MockMotionEvent::ACTION_MOVE, event_time, 5, 5);
590 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); 682 EXPECT_TRUE(controller().WillHandleTouchEvent(event));
591 EXPECT_TRUE(GetAndResetSelectionMoved()); 683 EXPECT_TRUE(GetAndResetSelectionMoved());
592 EXPECT_EQ(fixed_offset, GetLastSelectionStart()); 684 EXPECT_EQ(fixed_offset, GetLastSelectionStart());
593 EXPECT_EQ(start_offset + gfx::Vector2dF(5, 5), GetLastSelectionEnd()); 685 EXPECT_EQ(start_offset + gfx::Vector2dF(5, 5), GetLastSelectionEnd());
594 686
595 event = MockMotionEvent(MockMotionEvent::ACTION_MOVE, event_time, 10, 5); 687 event = MockMotionEvent(MockMotionEvent::ACTION_MOVE, event_time, 10, 5);
596 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); 688 EXPECT_TRUE(controller().WillHandleTouchEvent(event));
597 EXPECT_TRUE(GetAndResetSelectionMoved()); 689 EXPECT_TRUE(GetAndResetSelectionMoved());
598 EXPECT_EQ(fixed_offset, GetLastSelectionStart()); 690 EXPECT_EQ(fixed_offset, GetLastSelectionStart());
599 EXPECT_EQ(start_offset + gfx::Vector2dF(10, 5), GetLastSelectionEnd()); 691 EXPECT_EQ(start_offset + gfx::Vector2dF(10, 5), GetLastSelectionEnd());
600 692
601 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 10, 5); 693 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 10, 5);
602 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); 694 EXPECT_TRUE(controller().WillHandleTouchEvent(event));
603 EXPECT_EQ(SELECTION_DRAG_STOPPED, GetLastEventType()); 695 EXPECT_EQ(0, GetAndResetEventCount(SELECTION_SHOWN));
696 EXPECT_EQ(0, GetAndResetEventCount(SELECTION_DRAG_STARTED));
697 EXPECT_EQ(1, GetAndResetEventCount(SELECTION_DRAG_STOPPED));
604 EXPECT_FALSE(GetAndResetSelectionMoved()); 698 EXPECT_FALSE(GetAndResetSelectionMoved());
605 699
606 // Once the drag is complete, no more touch events should be consumed until 700 // Once the drag is complete, no more touch events should be consumed until
607 // the next ACTION_DOWN. 701 // the next ACTION_DOWN.
608 EXPECT_FALSE(controller().WillHandleTouchEvent(event)); 702 EXPECT_FALSE(controller().WillHandleTouchEvent(event));
609 } 703 }
610 704
611 TEST_F(TouchSelectionControllerTest, SelectionDraggedWithOverlap) { 705 TEST_F(TouchSelectionControllerTest, SelectionDraggedWithOverlap) {
612 base::TimeTicks event_time = base::TimeTicks::Now(); 706 base::TimeTicks event_time = base::TimeTicks::Now();
613 controller().OnLongPressEvent(); 707 controller().OnLongPressEvent();
614 708
615 float line_height = 10.f; 709 float line_height = 10.f;
616 gfx::RectF start_rect(0, 0, 0, line_height); 710 gfx::RectF start_rect(0, 0, 0, line_height);
617 gfx::RectF end_rect(50, 0, 0, line_height); 711 gfx::RectF end_rect(50, 0, 0, line_height);
618 bool visible = true; 712 bool visible = true;
619 ChangeSelection(start_rect, visible, end_rect, visible); 713 ChangeSelection(start_rect, visible, end_rect, visible);
620 EXPECT_EQ(SELECTION_SHOWN, GetLastEventType()); 714 EXPECT_EQ(1, GetAndResetEventCount(SELECTION_SHOWN));
715 EXPECT_EQ(0, GetAndResetEventCount(SELECTION_DRAG_STARTED));
716 EXPECT_EQ(0, GetAndResetEventCount(SELECTION_DRAG_STOPPED));
621 EXPECT_EQ(start_rect.bottom_left(), GetLastEventAnchor()); 717 EXPECT_EQ(start_rect.bottom_left(), GetLastEventAnchor());
622 718
623 // The ACTION_DOWN should lock to the closest handle. 719 // The ACTION_DOWN should lock to the closest handle.
624 gfx::PointF end_offset = end_rect.CenterPoint(); 720 gfx::PointF end_offset = end_rect.CenterPoint();
625 gfx::PointF fixed_offset = start_rect.CenterPoint(); 721 gfx::PointF fixed_offset = start_rect.CenterPoint();
626 float touch_down_x = (end_offset.x() + fixed_offset.x()) / 2 + 1.f; 722 float touch_down_x = (end_offset.x() + fixed_offset.x()) / 2 + 1.f;
627 MockMotionEvent event( 723 MockMotionEvent event(
628 MockMotionEvent::ACTION_DOWN, event_time, touch_down_x, 0); 724 MockMotionEvent::ACTION_DOWN, event_time, touch_down_x, 0);
629 SetDraggingEnabled(true); 725 SetDraggingEnabled(true);
630 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); 726 EXPECT_TRUE(controller().WillHandleTouchEvent(event));
631 EXPECT_EQ(SELECTION_DRAG_STARTED, GetLastEventType()); 727 EXPECT_EQ(0, GetAndResetEventCount(SELECTION_SHOWN));
728 EXPECT_EQ(1, GetAndResetEventCount(SELECTION_DRAG_STARTED));
729 EXPECT_EQ(0, GetAndResetEventCount(SELECTION_DRAG_STOPPED));
632 EXPECT_FALSE(GetAndResetSelectionMoved()); 730 EXPECT_FALSE(GetAndResetSelectionMoved());
633 731
634 // Even though the ACTION_MOVE is over the start handle, it should continue 732 // Even though the ACTION_MOVE is over the start handle, it should continue
635 // targetting the end handle that consumed the ACTION_DOWN. 733 // targetting the end handle that consumed the ACTION_DOWN.
636 event = MockMotionEvent(MockMotionEvent::ACTION_MOVE, event_time, 0, 0); 734 event = MockMotionEvent(MockMotionEvent::ACTION_MOVE, event_time, 0, 0);
637 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); 735 EXPECT_TRUE(controller().WillHandleTouchEvent(event));
638 EXPECT_TRUE(GetAndResetSelectionMoved()); 736 EXPECT_TRUE(GetAndResetSelectionMoved());
639 EXPECT_EQ(fixed_offset, GetLastSelectionStart()); 737 EXPECT_EQ(fixed_offset, GetLastSelectionStart());
640 EXPECT_EQ(end_offset - gfx::Vector2dF(touch_down_x, 0), 738 EXPECT_EQ(end_offset - gfx::Vector2dF(touch_down_x, 0),
641 GetLastSelectionEnd()); 739 GetLastSelectionEnd());
642 740
643 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 0, 0); 741 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 0, 0);
644 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); 742 EXPECT_TRUE(controller().WillHandleTouchEvent(event));
645 EXPECT_EQ(SELECTION_DRAG_STOPPED, GetLastEventType()); 743 EXPECT_EQ(0, GetAndResetEventCount(SELECTION_SHOWN));
744 EXPECT_EQ(0, GetAndResetEventCount(SELECTION_DRAG_STARTED));
745 EXPECT_EQ(1, GetAndResetEventCount(SELECTION_DRAG_STOPPED));
646 EXPECT_FALSE(GetAndResetSelectionMoved()); 746 EXPECT_FALSE(GetAndResetSelectionMoved());
647 } 747 }
648 748
649 TEST_F(TouchSelectionControllerTest, SelectionDraggedToSwitchBaseAndExtent) { 749 TEST_F(TouchSelectionControllerTest, SelectionDraggedToSwitchBaseAndExtent) {
650 base::TimeTicks event_time = base::TimeTicks::Now(); 750 base::TimeTicks event_time = base::TimeTicks::Now();
651 controller().OnLongPressEvent(); 751 controller().OnLongPressEvent();
652 752
653 float line_height = 10.f; 753 float line_height = 10.f;
654 gfx::RectF start_rect(50, line_height, 0, line_height); 754 gfx::RectF start_rect(50, line_height, 0, line_height);
655 gfx::RectF end_rect(100, line_height, 0, line_height); 755 gfx::RectF end_rect(100, line_height, 0, line_height);
656 bool visible = true; 756 bool visible = true;
657 ChangeSelection(start_rect, visible, end_rect, visible); 757 ChangeSelection(start_rect, visible, end_rect, visible);
658 EXPECT_EQ(SELECTION_SHOWN, GetLastEventType()); 758 EXPECT_EQ(1, GetAndResetEventCount(SELECTION_SHOWN));
759 EXPECT_EQ(0, GetAndResetEventCount(SELECTION_DRAG_STARTED));
760 EXPECT_EQ(0, GetAndResetEventCount(SELECTION_DRAG_STOPPED));
659 EXPECT_EQ(start_rect.bottom_left(), GetLastEventAnchor()); 761 EXPECT_EQ(start_rect.bottom_left(), GetLastEventAnchor());
660 762
661 SetDraggingEnabled(true); 763 SetDraggingEnabled(true);
662 764
663 // Move the extent, not triggering a swap of points. 765 // Move the extent, not triggering a swap of points.
664 MockMotionEvent event(MockMotionEvent::ACTION_DOWN, event_time, 766 MockMotionEvent event(MockMotionEvent::ACTION_DOWN, event_time,
665 end_rect.x(), end_rect.bottom()); 767 end_rect.x(), end_rect.bottom());
666 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); 768 EXPECT_TRUE(controller().WillHandleTouchEvent(event));
667 EXPECT_FALSE(GetAndResetSelectionMoved()); 769 EXPECT_FALSE(GetAndResetSelectionMoved());
668 EXPECT_FALSE(GetAndResetSelectionPointsSwapped()); 770 EXPECT_FALSE(GetAndResetSelectionPointsSwapped());
669 771
670 gfx::PointF base_offset = start_rect.CenterPoint(); 772 gfx::PointF base_offset = start_rect.CenterPoint();
671 gfx::PointF extent_offset = end_rect.CenterPoint(); 773 gfx::PointF extent_offset = end_rect.CenterPoint();
672 event = MockMotionEvent(MockMotionEvent::ACTION_MOVE, event_time, 774 event = MockMotionEvent(MockMotionEvent::ACTION_MOVE, event_time,
673 end_rect.x(), end_rect.bottom() + 5); 775 end_rect.x(), end_rect.bottom() + 5);
674 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); 776 EXPECT_TRUE(controller().WillHandleTouchEvent(event));
675 EXPECT_EQ(SELECTION_DRAG_STARTED, GetLastEventType()); 777 EXPECT_EQ(0, GetAndResetEventCount(SELECTION_SHOWN));
778 EXPECT_EQ(1, GetAndResetEventCount(SELECTION_DRAG_STARTED));
779 EXPECT_EQ(0, GetAndResetEventCount(SELECTION_DRAG_STOPPED));
676 EXPECT_TRUE(GetAndResetSelectionMoved()); 780 EXPECT_TRUE(GetAndResetSelectionMoved());
677 EXPECT_FALSE(GetAndResetSelectionPointsSwapped()); 781 EXPECT_FALSE(GetAndResetSelectionPointsSwapped());
678 EXPECT_EQ(base_offset, GetLastSelectionStart()); 782 EXPECT_EQ(base_offset, GetLastSelectionStart());
679 EXPECT_EQ(extent_offset + gfx::Vector2dF(0, 5), GetLastSelectionEnd()); 783 EXPECT_EQ(extent_offset + gfx::Vector2dF(0, 5), GetLastSelectionEnd());
680 784
681 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 10, 5); 785 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 10, 5);
682 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); 786 EXPECT_TRUE(controller().WillHandleTouchEvent(event));
683 EXPECT_EQ(SELECTION_DRAG_STOPPED, GetLastEventType()); 787 EXPECT_EQ(0, GetAndResetEventCount(SELECTION_SHOWN));
788 EXPECT_EQ(0, GetAndResetEventCount(SELECTION_DRAG_STARTED));
789 EXPECT_EQ(1, GetAndResetEventCount(SELECTION_DRAG_STOPPED));
684 EXPECT_FALSE(GetAndResetSelectionMoved()); 790 EXPECT_FALSE(GetAndResetSelectionMoved());
685 791
686 end_rect += gfx::Vector2dF(0, 5); 792 end_rect += gfx::Vector2dF(0, 5);
687 ChangeSelection(start_rect, visible, end_rect, visible); 793 ChangeSelection(start_rect, visible, end_rect, visible);
688 794
689 // Move the base, triggering a swap of points. 795 // Move the base, triggering a swap of points.
690 event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time, 796 event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time,
691 start_rect.x(), start_rect.bottom()); 797 start_rect.x(), start_rect.bottom());
692 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); 798 EXPECT_TRUE(controller().WillHandleTouchEvent(event));
693 EXPECT_FALSE(GetAndResetSelectionMoved()); 799 EXPECT_FALSE(GetAndResetSelectionMoved());
694 EXPECT_TRUE(GetAndResetSelectionPointsSwapped()); 800 EXPECT_TRUE(GetAndResetSelectionPointsSwapped());
695 801
696 base_offset = end_rect.CenterPoint(); 802 base_offset = end_rect.CenterPoint();
697 extent_offset = start_rect.CenterPoint(); 803 extent_offset = start_rect.CenterPoint();
698 event = MockMotionEvent(MockMotionEvent::ACTION_MOVE, event_time, 804 event = MockMotionEvent(MockMotionEvent::ACTION_MOVE, event_time,
699 start_rect.x(), start_rect.bottom() + 5); 805 start_rect.x(), start_rect.bottom() + 5);
700 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); 806 EXPECT_TRUE(controller().WillHandleTouchEvent(event));
701 EXPECT_EQ(SELECTION_DRAG_STARTED, GetLastEventType()); 807 EXPECT_EQ(0, GetAndResetEventCount(SELECTION_SHOWN));
808 EXPECT_EQ(1, GetAndResetEventCount(SELECTION_DRAG_STARTED));
809 EXPECT_EQ(0, GetAndResetEventCount(SELECTION_DRAG_STOPPED));
702 EXPECT_TRUE(GetAndResetSelectionMoved()); 810 EXPECT_TRUE(GetAndResetSelectionMoved());
703 EXPECT_FALSE(GetAndResetSelectionPointsSwapped()); 811 EXPECT_FALSE(GetAndResetSelectionPointsSwapped());
704 EXPECT_EQ(base_offset, GetLastSelectionStart()); 812 EXPECT_EQ(base_offset, GetLastSelectionStart());
705 EXPECT_EQ(extent_offset + gfx::Vector2dF(0, 5), GetLastSelectionEnd()); 813 EXPECT_EQ(extent_offset + gfx::Vector2dF(0, 5), GetLastSelectionEnd());
706 814
707 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 10, 5); 815 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 10, 5);
708 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); 816 EXPECT_TRUE(controller().WillHandleTouchEvent(event));
709 EXPECT_EQ(SELECTION_DRAG_STOPPED, GetLastEventType()); 817 EXPECT_EQ(0, GetAndResetEventCount(SELECTION_SHOWN));
818 EXPECT_EQ(0, GetAndResetEventCount(SELECTION_DRAG_STARTED));
819 EXPECT_EQ(1, GetAndResetEventCount(SELECTION_DRAG_STOPPED));
710 EXPECT_FALSE(GetAndResetSelectionMoved()); 820 EXPECT_FALSE(GetAndResetSelectionMoved());
711 821
712 start_rect += gfx::Vector2dF(0, 5); 822 start_rect += gfx::Vector2dF(0, 5);
713 ChangeSelection(start_rect, visible, end_rect, visible); 823 ChangeSelection(start_rect, visible, end_rect, visible);
714 824
715 // Move the same point again, not triggering a swap of points. 825 // Move the same point again, not triggering a swap of points.
716 event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time, 826 event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time,
717 start_rect.x(), start_rect.bottom()); 827 start_rect.x(), start_rect.bottom());
718 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); 828 EXPECT_TRUE(controller().WillHandleTouchEvent(event));
719 EXPECT_FALSE(GetAndResetSelectionMoved()); 829 EXPECT_FALSE(GetAndResetSelectionMoved());
720 EXPECT_FALSE(GetAndResetSelectionPointsSwapped()); 830 EXPECT_FALSE(GetAndResetSelectionPointsSwapped());
721 831
722 base_offset = end_rect.CenterPoint(); 832 base_offset = end_rect.CenterPoint();
723 extent_offset = start_rect.CenterPoint(); 833 extent_offset = start_rect.CenterPoint();
724 event = MockMotionEvent(MockMotionEvent::ACTION_MOVE, event_time, 834 event = MockMotionEvent(MockMotionEvent::ACTION_MOVE, event_time,
725 start_rect.x(), start_rect.bottom() + 5); 835 start_rect.x(), start_rect.bottom() + 5);
726 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); 836 EXPECT_TRUE(controller().WillHandleTouchEvent(event));
727 EXPECT_EQ(SELECTION_DRAG_STARTED, GetLastEventType()); 837 EXPECT_EQ(0, GetAndResetEventCount(SELECTION_SHOWN));
838 EXPECT_EQ(1, GetAndResetEventCount(SELECTION_DRAG_STARTED));
839 EXPECT_EQ(0, GetAndResetEventCount(SELECTION_DRAG_STOPPED));
728 EXPECT_TRUE(GetAndResetSelectionMoved()); 840 EXPECT_TRUE(GetAndResetSelectionMoved());
729 EXPECT_FALSE(GetAndResetSelectionPointsSwapped()); 841 EXPECT_FALSE(GetAndResetSelectionPointsSwapped());
730 EXPECT_EQ(base_offset, GetLastSelectionStart()); 842 EXPECT_EQ(base_offset, GetLastSelectionStart());
731 EXPECT_EQ(extent_offset + gfx::Vector2dF(0, 5), GetLastSelectionEnd()); 843 EXPECT_EQ(extent_offset + gfx::Vector2dF(0, 5), GetLastSelectionEnd());
732 844
733 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 10, 5); 845 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 10, 5);
734 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); 846 EXPECT_TRUE(controller().WillHandleTouchEvent(event));
735 EXPECT_EQ(SELECTION_DRAG_STOPPED, GetLastEventType()); 847 EXPECT_EQ(0, GetAndResetEventCount(SELECTION_SHOWN));
848 EXPECT_EQ(0, GetAndResetEventCount(SELECTION_DRAG_STARTED));
849 EXPECT_EQ(1, GetAndResetEventCount(SELECTION_DRAG_STOPPED));
736 EXPECT_FALSE(GetAndResetSelectionMoved()); 850 EXPECT_FALSE(GetAndResetSelectionMoved());
737 851
738 start_rect += gfx::Vector2dF(0, 5); 852 start_rect += gfx::Vector2dF(0, 5);
739 ChangeSelection(start_rect, visible, end_rect, visible); 853 ChangeSelection(start_rect, visible, end_rect, visible);
740 854
741 // Move the base, triggering a swap of points. 855 // Move the base, triggering a swap of points.
742 event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time, 856 event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time,
743 end_rect.x(), end_rect.bottom()); 857 end_rect.x(), end_rect.bottom());
744 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); 858 EXPECT_TRUE(controller().WillHandleTouchEvent(event));
745 EXPECT_FALSE(GetAndResetSelectionMoved()); 859 EXPECT_FALSE(GetAndResetSelectionMoved());
746 EXPECT_TRUE(GetAndResetSelectionPointsSwapped()); 860 EXPECT_TRUE(GetAndResetSelectionPointsSwapped());
747 861
748 base_offset = start_rect.CenterPoint(); 862 base_offset = start_rect.CenterPoint();
749 extent_offset = end_rect.CenterPoint(); 863 extent_offset = end_rect.CenterPoint();
750 event = MockMotionEvent(MockMotionEvent::ACTION_MOVE, event_time, 864 event = MockMotionEvent(MockMotionEvent::ACTION_MOVE, event_time,
751 end_rect.x(), end_rect.bottom() + 5); 865 end_rect.x(), end_rect.bottom() + 5);
752 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); 866 EXPECT_TRUE(controller().WillHandleTouchEvent(event));
753 EXPECT_EQ(SELECTION_DRAG_STARTED, GetLastEventType()); 867 EXPECT_EQ(0, GetAndResetEventCount(SELECTION_SHOWN));
868 EXPECT_EQ(1, GetAndResetEventCount(SELECTION_DRAG_STARTED));
869 EXPECT_EQ(0, GetAndResetEventCount(SELECTION_DRAG_STOPPED));
754 EXPECT_TRUE(GetAndResetSelectionMoved()); 870 EXPECT_TRUE(GetAndResetSelectionMoved());
755 EXPECT_FALSE(GetAndResetSelectionPointsSwapped()); 871 EXPECT_FALSE(GetAndResetSelectionPointsSwapped());
756 EXPECT_EQ(base_offset, GetLastSelectionStart()); 872 EXPECT_EQ(base_offset, GetLastSelectionStart());
757 EXPECT_EQ(extent_offset + gfx::Vector2dF(0, 5), GetLastSelectionEnd()); 873 EXPECT_EQ(extent_offset + gfx::Vector2dF(0, 5), GetLastSelectionEnd());
758 874
759 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 10, 5); 875 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 10, 5);
760 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); 876 EXPECT_TRUE(controller().WillHandleTouchEvent(event));
761 EXPECT_EQ(SELECTION_DRAG_STOPPED, GetLastEventType()); 877 EXPECT_EQ(0, GetAndResetEventCount(SELECTION_SHOWN));
878 EXPECT_EQ(0, GetAndResetEventCount(SELECTION_DRAG_STARTED));
879 EXPECT_EQ(1, GetAndResetEventCount(SELECTION_DRAG_STOPPED));
762 EXPECT_FALSE(GetAndResetSelectionMoved()); 880 EXPECT_FALSE(GetAndResetSelectionMoved());
763 } 881 }
764 882
765 TEST_F(TouchSelectionControllerTest, SelectionDragExtremeLineSize) { 883 TEST_F(TouchSelectionControllerTest, SelectionDragExtremeLineSize) {
766 base::TimeTicks event_time = base::TimeTicks::Now(); 884 base::TimeTicks event_time = base::TimeTicks::Now();
767 controller().OnLongPressEvent(); 885 controller().OnLongPressEvent();
768 886
769 float small_line_height = 1.f; 887 float small_line_height = 1.f;
770 float large_line_height = 50.f; 888 float large_line_height = 50.f;
771 gfx::RectF small_line_rect(0, 0, 0, small_line_height); 889 gfx::RectF small_line_rect(0, 0, 0, small_line_height);
772 gfx::RectF large_line_rect(50, 50, 0, large_line_height); 890 gfx::RectF large_line_rect(50, 50, 0, large_line_height);
773 bool visible = true; 891 bool visible = true;
774 ChangeSelection(small_line_rect, visible, large_line_rect, visible); 892 ChangeSelection(small_line_rect, visible, large_line_rect, visible);
775 EXPECT_EQ(SELECTION_SHOWN, GetLastEventType()); 893 EXPECT_EQ(1, GetAndResetEventCount(SELECTION_SHOWN));
894 EXPECT_EQ(0, GetAndResetEventCount(SELECTION_DRAG_STARTED));
776 EXPECT_EQ(small_line_rect.bottom_left(), GetLastEventAnchor()); 895 EXPECT_EQ(small_line_rect.bottom_left(), GetLastEventAnchor());
777 896
778 // Start dragging the handle on the small line. 897 // Start dragging the handle on the small line.
779 MockMotionEvent event(MockMotionEvent::ACTION_DOWN, event_time, 898 MockMotionEvent event(MockMotionEvent::ACTION_DOWN, event_time,
780 small_line_rect.x(), small_line_rect.y()); 899 small_line_rect.x(), small_line_rect.y());
781 SetDraggingEnabled(true); 900 SetDraggingEnabled(true);
782 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); 901 EXPECT_TRUE(controller().WillHandleTouchEvent(event));
783 EXPECT_EQ(SELECTION_DRAG_STARTED, GetLastEventType()); 902 EXPECT_EQ(0, GetAndResetEventCount(SELECTION_SHOWN));
903 EXPECT_EQ(1, GetAndResetEventCount(SELECTION_DRAG_STARTED));
784 // The drag coordinate for large lines should be capped to a reasonable 904 // The drag coordinate for large lines should be capped to a reasonable
785 // offset, allowing seamless transition to neighboring lines with different 905 // offset, allowing seamless transition to neighboring lines with different
786 // sizes. The drag coordinate for small lines should have an offset 906 // sizes. The drag coordinate for small lines should have an offset
787 // commensurate with the small line size. 907 // commensurate with the small line size.
788 EXPECT_EQ(large_line_rect.bottom_left() - gfx::Vector2dF(0, 5.f), 908 EXPECT_EQ(large_line_rect.bottom_left() - gfx::Vector2dF(0, 5.f),
789 GetLastSelectionStart()); 909 GetLastSelectionStart());
790 EXPECT_EQ(small_line_rect.CenterPoint(), GetLastSelectionEnd()); 910 EXPECT_EQ(small_line_rect.CenterPoint(), GetLastSelectionEnd());
791 911
792 small_line_rect += gfx::Vector2dF(25.f, 0); 912 small_line_rect += gfx::Vector2dF(25.f, 0);
793 event = MockMotionEvent(MockMotionEvent::ACTION_MOVE, event_time, 913 event = MockMotionEvent(MockMotionEvent::ACTION_MOVE, event_time,
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
852 EXPECT_TRUE(GetAndResetNeedsAnimate()); 972 EXPECT_TRUE(GetAndResetNeedsAnimate());
853 } 973 }
854 974
855 TEST_F(TouchSelectionControllerTest, SelectionClearOnTap) { 975 TEST_F(TouchSelectionControllerTest, SelectionClearOnTap) {
856 gfx::RectF start_rect(5, 5, 0, 10); 976 gfx::RectF start_rect(5, 5, 0, 10);
857 gfx::RectF end_rect(50, 5, 0, 10); 977 gfx::RectF end_rect(50, 5, 0, 10);
858 bool visible = true; 978 bool visible = true;
859 979
860 controller().OnLongPressEvent(); 980 controller().OnLongPressEvent();
861 ChangeSelection(start_rect, visible, end_rect, visible); 981 ChangeSelection(start_rect, visible, end_rect, visible);
982 EXPECT_EQ(1, GetAndResetEventCount(SELECTION_SHOWN));
983 EXPECT_EQ(0, GetAndResetEventCount(SELECTION_CLEARED));
862 984
863 // Selection should not be cleared if the selection bounds have not changed. 985 // Selection should not be cleared if the selection bounds have not changed.
864 controller().OnTapEvent(); 986 controller().OnTapEvent();
865 EXPECT_EQ(SELECTION_SHOWN, GetLastEventType()); 987 EXPECT_EQ(0, GetAndResetEventCount(SELECTION_SHOWN));
988 EXPECT_EQ(0, GetAndResetEventCount(SELECTION_CLEARED));
866 EXPECT_EQ(start_rect.bottom_left(), GetLastEventAnchor()); 989 EXPECT_EQ(start_rect.bottom_left(), GetLastEventAnchor());
867 990
868 controller().OnTapEvent(); 991 controller().OnTapEvent();
869 ClearSelection(); 992 ClearSelection();
870 EXPECT_EQ(SELECTION_CLEARED, GetLastEventType()); 993 EXPECT_EQ(0, GetAndResetEventCount(SELECTION_SHOWN));
994 EXPECT_EQ(1, GetAndResetEventCount(SELECTION_CLEARED));
871 EXPECT_EQ(gfx::PointF(), GetLastEventAnchor()); 995 EXPECT_EQ(gfx::PointF(), GetLastEventAnchor());
872 } 996 }
873 997
874 TEST_F(TouchSelectionControllerTest, AllowShowingFromCurrentSelection) { 998 TEST_F(TouchSelectionControllerTest, AllowShowingFromCurrentSelection) {
875 gfx::RectF start_rect(5, 5, 0, 10); 999 gfx::RectF start_rect(5, 5, 0, 10);
876 gfx::RectF end_rect(50, 5, 0, 10); 1000 gfx::RectF end_rect(50, 5, 0, 10);
877 bool visible = true; 1001 bool visible = true;
878 1002
879 // The selection should not have be activated, as it wasn't yet allowed. 1003 // The selection should not be activated, as it wasn't yet allowed.
880 ChangeSelection(start_rect, visible, end_rect, visible); 1004 ChangeSelection(start_rect, visible, end_rect, visible);
881 EXPECT_EQ(gfx::PointF(), GetLastEventAnchor()); 1005 EXPECT_EQ(gfx::PointF(), GetLastEventAnchor());
882 1006
883 // Now explicitly allow showing from the previously supplied bounds. 1007 // Now explicitly allow showing from the previously supplied bounds.
884 controller().AllowShowingFromCurrentSelection(); 1008 controller().AllowShowingFromCurrentSelection();
885 EXPECT_EQ(SELECTION_SHOWN, GetLastEventType()); 1009 EXPECT_EQ(1, GetAndResetEventCount(SELECTION_SHOWN));
1010 EXPECT_EQ(0, GetAndResetEventCount(SELECTION_CLEARED));
1011 EXPECT_EQ(0, GetAndResetEventCount(INSERTION_SHOWN));
886 EXPECT_EQ(start_rect.bottom_left(), GetLastEventAnchor()); 1012 EXPECT_EQ(start_rect.bottom_left(), GetLastEventAnchor());
887 1013
888 // Repeated calls to show from the current selection should be ignored. 1014 // Repeated calls to show from the current selection should be ignored.
889 controller().AllowShowingFromCurrentSelection(); 1015 controller().AllowShowingFromCurrentSelection();
890 EXPECT_EQ(SELECTION_SHOWN, GetLastEventType()); 1016 EXPECT_EQ(0, GetAndResetEventCount(SELECTION_SHOWN));
1017 EXPECT_EQ(0, GetAndResetEventCount(SELECTION_CLEARED));
1018 EXPECT_EQ(0, GetAndResetEventCount(INSERTION_SHOWN));
891 EXPECT_EQ(start_rect.bottom_left(), GetLastEventAnchor()); 1019 EXPECT_EQ(start_rect.bottom_left(), GetLastEventAnchor());
892 1020
893 // Trying to show from an empty selection will have no result. 1021 // Trying to show from an empty selection will have no result.
894 ClearSelection(); 1022 ClearSelection();
895 EXPECT_EQ(SELECTION_CLEARED, GetLastEventType()); 1023 EXPECT_EQ(0, GetAndResetEventCount(SELECTION_SHOWN));
1024 EXPECT_EQ(1, GetAndResetEventCount(SELECTION_CLEARED));
1025 EXPECT_EQ(0, GetAndResetEventCount(INSERTION_SHOWN));
896 controller().AllowShowingFromCurrentSelection(); 1026 controller().AllowShowingFromCurrentSelection();
897 EXPECT_EQ(SELECTION_CLEARED, GetLastEventType()); 1027 EXPECT_EQ(0, GetAndResetEventCount(SELECTION_SHOWN));
1028 EXPECT_EQ(0, GetAndResetEventCount(SELECTION_CLEARED));
1029 EXPECT_EQ(0, GetAndResetEventCount(INSERTION_SHOWN));
898 1030
899 // Showing the insertion handle should also be supported. 1031 // Showing the insertion handle should also be supported.
900 controller().OnSelectionEditable(true); 1032 controller().OnSelectionEditable(true);
901 controller().OnSelectionEmpty(false); 1033 controller().OnSelectionEmpty(false);
902 controller().HideAndDisallowShowingAutomatically(); 1034 controller().HideAndDisallowShowingAutomatically();
903 gfx::RectF insertion_rect(5, 5, 0, 10); 1035 gfx::RectF insertion_rect(5, 5, 0, 10);
904 ChangeInsertion(insertion_rect, visible); 1036 ChangeInsertion(insertion_rect, visible);
905 controller().AllowShowingFromCurrentSelection(); 1037 controller().AllowShowingFromCurrentSelection();
906 EXPECT_EQ(INSERTION_SHOWN, GetLastEventType()); 1038 EXPECT_EQ(0, GetAndResetEventCount(SELECTION_SHOWN));
1039 EXPECT_EQ(0, GetAndResetEventCount(SELECTION_CLEARED));
1040 EXPECT_EQ(1, GetAndResetEventCount(INSERTION_SHOWN));
907 EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventAnchor()); 1041 EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventAnchor());
908 } 1042 }
909 1043
910 } // namespace ui 1044 } // 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