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

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

Issue 1537493006: Allow scrolling a page with selection after long-press on whitespace (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed review comments Created 4 years, 11 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
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/longpress_drag_selector.h" 5 #include "ui/touch_selection/longpress_drag_selector.h"
6 6
7 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "ui/events/test/motion_event_test_utils.h" 8 #include "ui/events/test/motion_event_test_utils.h"
9 9
10 using ui::test::MockMotionEvent; 10 using ui::test::MockMotionEvent;
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 MockMotionEvent event; 80 MockMotionEvent event;
81 81
82 // Start a touch sequence. 82 // Start a touch sequence.
83 EXPECT_FALSE(selector.WillHandleTouchEvent(event.PressPoint(0, 0))); 83 EXPECT_FALSE(selector.WillHandleTouchEvent(event.PressPoint(0, 0)));
84 EXPECT_FALSE(GetAndResetActiveStateChanged()); 84 EXPECT_FALSE(GetAndResetActiveStateChanged());
85 85
86 // Activate a longpress-triggered selection. 86 // Activate a longpress-triggered selection.
87 gfx::PointF selection_start(0, 10); 87 gfx::PointF selection_start(0, 10);
88 gfx::PointF selection_end(10, 10); 88 gfx::PointF selection_end(10, 10);
89 selector.OnLongPressEvent(event.GetEventTime(), gfx::PointF()); 89 selector.OnLongPressEvent(event.GetEventTime(), gfx::PointF());
90 EXPECT_TRUE(GetAndResetActiveStateChanged()); 90 EXPECT_FALSE(GetAndResetActiveStateChanged());
91 91
92 // Motion should not be consumed until a selection is detected. 92 // Motion should not be consumed until a selection is detected.
93 EXPECT_FALSE(selector.WillHandleTouchEvent(event.MovePoint(0, 0, 0))); 93 EXPECT_FALSE(selector.WillHandleTouchEvent(event.MovePoint(0, 0, 0)));
94 SetSelection(selection_start, selection_end); 94 SetSelection(selection_start, selection_end);
95 selector.OnSelectionActivated(); 95 selector.OnSelectionActivated();
96 EXPECT_TRUE(GetAndResetActiveStateChanged());
96 EXPECT_FALSE(IsDragging()); 97 EXPECT_FALSE(IsDragging());
97 98
98 // Initiate drag motion. Note that the first move event after activation is 99 // Initiate drag motion. Note that the first move event after activation is
99 // used to initialize the drag start anchor. 100 // used to initialize the drag start anchor.
100 EXPECT_TRUE(selector.WillHandleTouchEvent(event.MovePoint(0, 0, 0))); 101 EXPECT_TRUE(selector.WillHandleTouchEvent(event.MovePoint(0, 0, 0)));
101 EXPECT_FALSE(IsDragging()); 102 EXPECT_FALSE(IsDragging());
102 103
103 // The first slop exceeding motion will start the drag. As the motion is 104 // The first slop exceeding motion will start the drag. As the motion is
104 // downward, the end selection point should be moved. 105 // downward, the end selection point should be moved.
105 EXPECT_TRUE(selector.WillHandleTouchEvent(event.MovePoint(0, 0, kSlop))); 106 EXPECT_TRUE(selector.WillHandleTouchEvent(event.MovePoint(0, 0, kSlop)));
(...skipping 20 matching lines...) Expand all
126 MockMotionEvent event; 127 MockMotionEvent event;
127 128
128 // Start a touch sequence. 129 // Start a touch sequence.
129 EXPECT_FALSE(selector.WillHandleTouchEvent(event.PressPoint(0, 0))); 130 EXPECT_FALSE(selector.WillHandleTouchEvent(event.PressPoint(0, 0)));
130 EXPECT_FALSE(GetAndResetActiveStateChanged()); 131 EXPECT_FALSE(GetAndResetActiveStateChanged());
131 132
132 // Activate a longpress-triggered selection. 133 // Activate a longpress-triggered selection.
133 gfx::PointF selection_start(0, 10); 134 gfx::PointF selection_start(0, 10);
134 gfx::PointF selection_end(10, 10); 135 gfx::PointF selection_end(10, 10);
135 selector.OnLongPressEvent(event.GetEventTime(), gfx::PointF()); 136 selector.OnLongPressEvent(event.GetEventTime(), gfx::PointF());
136 EXPECT_TRUE(GetAndResetActiveStateChanged()); 137 EXPECT_FALSE(GetAndResetActiveStateChanged());
137 SetSelection(selection_start, selection_end); 138 SetSelection(selection_start, selection_end);
138 selector.OnSelectionActivated(); 139 selector.OnSelectionActivated();
140 EXPECT_TRUE(GetAndResetActiveStateChanged());
139 EXPECT_FALSE(IsDragging()); 141 EXPECT_FALSE(IsDragging());
140 142
141 // Initiate drag motion. 143 // Initiate drag motion.
142 EXPECT_TRUE(selector.WillHandleTouchEvent(event.MovePoint(0, 5, 0))); 144 EXPECT_TRUE(selector.WillHandleTouchEvent(event.MovePoint(0, 5, 0)));
143 EXPECT_FALSE(IsDragging()); 145 EXPECT_FALSE(IsDragging());
144 146
145 // As the initial motion is leftward, toward the selection start, the 147 // As the initial motion is leftward, toward the selection start, the
146 // selection start should be the drag point. 148 // selection start should be the drag point.
147 EXPECT_TRUE(selector.WillHandleTouchEvent(event.MovePoint(0, -kSlop, 0))); 149 EXPECT_TRUE(selector.WillHandleTouchEvent(event.MovePoint(0, -kSlop, 0)));
148 EXPECT_TRUE(IsDragging()); 150 EXPECT_TRUE(IsDragging());
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 } 243 }
242 244
243 TEST_F(LongPressDragSelectorTest, NoSelection) { 245 TEST_F(LongPressDragSelectorTest, NoSelection) {
244 LongPressDragSelector selector(this); 246 LongPressDragSelector selector(this);
245 MockMotionEvent event; 247 MockMotionEvent event;
246 248
247 // Start a touch sequence. 249 // Start a touch sequence.
248 EXPECT_FALSE(selector.WillHandleTouchEvent(event.PressPoint(0, 0))); 250 EXPECT_FALSE(selector.WillHandleTouchEvent(event.PressPoint(0, 0)));
249 EXPECT_FALSE(GetAndResetActiveStateChanged()); 251 EXPECT_FALSE(GetAndResetActiveStateChanged());
250 252
251 // Trigger a longpress. This will notify the client that detection is active, 253 // Trigger a longpress.
252 // but until there's a longpress no drag selection should occur.
253 selector.OnLongPressEvent(event.GetEventTime(), gfx::PointF()); 254 selector.OnLongPressEvent(event.GetEventTime(), gfx::PointF());
254 EXPECT_TRUE(GetAndResetActiveStateChanged()); 255 EXPECT_FALSE(GetAndResetActiveStateChanged());
255 EXPECT_FALSE(IsDragging()); 256 EXPECT_FALSE(IsDragging());
256 257
257 // Touch movement should not initiate selection drag, as there is no active 258 // Touch movement should not initiate selection drag, as there is no active
258 // selection. 259 // selection.
259 EXPECT_FALSE(selector.WillHandleTouchEvent(event.MovePoint(0, 0, 0))); 260 EXPECT_FALSE(selector.WillHandleTouchEvent(event.MovePoint(0, 0, 0)));
260 EXPECT_FALSE(selector.WillHandleTouchEvent(event.MovePoint(0, 0, kSlop))); 261 EXPECT_FALSE(selector.WillHandleTouchEvent(event.MovePoint(0, 0, kSlop)));
261 EXPECT_FALSE(selector.WillHandleTouchEvent(event.MovePoint(0, 0, kSlop * 2))); 262 EXPECT_FALSE(selector.WillHandleTouchEvent(event.MovePoint(0, 0, kSlop * 2)));
262 EXPECT_FALSE(IsDragging()); 263 EXPECT_FALSE(IsDragging());
263 EXPECT_EQ(gfx::PointF(), DragPosition()); 264 EXPECT_EQ(gfx::PointF(), DragPosition());
264 265
265 EXPECT_FALSE(selector.WillHandleTouchEvent(event.ReleasePoint())); 266 EXPECT_FALSE(selector.WillHandleTouchEvent(event.ReleasePoint()));
266 EXPECT_TRUE(GetAndResetActiveStateChanged());
267 } 267 }
268 268
269 TEST_F(LongPressDragSelectorTest, NoDragMotion) { 269 TEST_F(LongPressDragSelectorTest, NoDragMotion) {
270 LongPressDragSelector selector(this); 270 LongPressDragSelector selector(this);
271 MockMotionEvent event; 271 MockMotionEvent event;
272 272
273 // Start a touch sequence. 273 // Start a touch sequence.
274 EXPECT_FALSE(selector.WillHandleTouchEvent(event.PressPoint(0, 0))); 274 EXPECT_FALSE(selector.WillHandleTouchEvent(event.PressPoint(0, 0)));
275 EXPECT_FALSE(GetAndResetActiveStateChanged()); 275 EXPECT_FALSE(GetAndResetActiveStateChanged());
276 276
277 // Activate a longpress-triggered selection. 277 // Activate a longpress-triggered selection.
278 selector.OnLongPressEvent(event.GetEventTime(), gfx::PointF()); 278 selector.OnLongPressEvent(event.GetEventTime(), gfx::PointF());
279 EXPECT_TRUE(GetAndResetActiveStateChanged()); 279 EXPECT_FALSE(GetAndResetActiveStateChanged());
280 gfx::PointF selection_start(0, 10); 280 gfx::PointF selection_start(0, 10);
281 gfx::PointF selection_end(10, 10); 281 gfx::PointF selection_end(10, 10);
282 SetSelection(selection_start, selection_end); 282 SetSelection(selection_start, selection_end);
283 selector.OnSelectionActivated(); 283 selector.OnSelectionActivated();
284 EXPECT_TRUE(GetAndResetActiveStateChanged());
284 EXPECT_FALSE(IsDragging()); 285 EXPECT_FALSE(IsDragging());
285 286
286 // Touch movement within the slop region should not initiate selection drag. 287 // Touch movement within the slop region should not initiate selection drag.
287 EXPECT_TRUE(selector.WillHandleTouchEvent(event.MovePoint(0, 0, 0))); 288 EXPECT_TRUE(selector.WillHandleTouchEvent(event.MovePoint(0, 0, 0)));
288 EXPECT_TRUE(selector.WillHandleTouchEvent(event.MovePoint(0, 0, kSlop / 2))); 289 EXPECT_TRUE(selector.WillHandleTouchEvent(event.MovePoint(0, 0, kSlop / 2)));
289 EXPECT_TRUE(selector.WillHandleTouchEvent(event.MovePoint(0, 0, -kSlop / 2))); 290 EXPECT_TRUE(selector.WillHandleTouchEvent(event.MovePoint(0, 0, -kSlop / 2)));
290 EXPECT_FALSE(IsDragging()); 291 EXPECT_FALSE(IsDragging());
291 EXPECT_EQ(gfx::PointF(), DragPosition()); 292 EXPECT_EQ(gfx::PointF(), DragPosition());
292 293
293 EXPECT_FALSE(selector.WillHandleTouchEvent(event.ReleasePoint())); 294 EXPECT_FALSE(selector.WillHandleTouchEvent(event.ReleasePoint()));
294 EXPECT_TRUE(GetAndResetActiveStateChanged()); 295 EXPECT_TRUE(GetAndResetActiveStateChanged());
295 } 296 }
296 297
297 TEST_F(LongPressDragSelectorTest, SelectionDeactivated) { 298 TEST_F(LongPressDragSelectorTest, SelectionDeactivated) {
298 LongPressDragSelector selector(this); 299 LongPressDragSelector selector(this);
299 MockMotionEvent event; 300 MockMotionEvent event;
300 301
301 // Start a touch sequence. 302 // Start a touch sequence.
302 EXPECT_FALSE(selector.WillHandleTouchEvent(event.PressPoint(0, 0))); 303 EXPECT_FALSE(selector.WillHandleTouchEvent(event.PressPoint(0, 0)));
303 EXPECT_FALSE(GetAndResetActiveStateChanged()); 304 EXPECT_FALSE(GetAndResetActiveStateChanged());
304 305
305 // Activate a longpress-triggered selection. 306 // Activate a longpress-triggered selection.
306 selector.OnLongPressEvent(event.GetEventTime(), gfx::PointF()); 307 selector.OnLongPressEvent(event.GetEventTime(), gfx::PointF());
307 EXPECT_TRUE(GetAndResetActiveStateChanged()); 308 EXPECT_FALSE(GetAndResetActiveStateChanged());
308 gfx::PointF selection_start(0, 10); 309 gfx::PointF selection_start(0, 10);
309 gfx::PointF selection_end(10, 10); 310 gfx::PointF selection_end(10, 10);
310 SetSelection(selection_start, selection_end); 311 SetSelection(selection_start, selection_end);
311 selector.OnSelectionActivated(); 312 selector.OnSelectionActivated();
313 EXPECT_TRUE(GetAndResetActiveStateChanged());
312 EXPECT_FALSE(IsDragging()); 314 EXPECT_FALSE(IsDragging());
313 315
314 // Start a drag selection. 316 // Start a drag selection.
315 EXPECT_TRUE(selector.WillHandleTouchEvent(event.MovePoint(0, 0, 0))); 317 EXPECT_TRUE(selector.WillHandleTouchEvent(event.MovePoint(0, 0, 0)));
316 EXPECT_TRUE(selector.WillHandleTouchEvent(event.MovePoint(0, 0, kSlop))); 318 EXPECT_TRUE(selector.WillHandleTouchEvent(event.MovePoint(0, 0, kSlop)));
317 EXPECT_TRUE(selector.WillHandleTouchEvent(event.MovePoint(0, 0, kSlop * 2))); 319 EXPECT_TRUE(selector.WillHandleTouchEvent(event.MovePoint(0, 0, kSlop * 2)));
318 EXPECT_TRUE(IsDragging()); 320 EXPECT_TRUE(IsDragging());
319 321
320 // Clearing the selection should force an end to the drag. 322 // Clearing the selection should force an end to the drag.
321 selector.OnSelectionDeactivated(); 323 selector.OnSelectionDeactivated();
(...skipping 13 matching lines...) Expand all
335 MockMotionEvent event; 337 MockMotionEvent event;
336 338
337 // Start a touch sequence. 339 // Start a touch sequence.
338 EXPECT_FALSE(selector.WillHandleTouchEvent(event.PressPoint(0, 0))); 340 EXPECT_FALSE(selector.WillHandleTouchEvent(event.PressPoint(0, 0)));
339 EXPECT_FALSE(GetAndResetActiveStateChanged()); 341 EXPECT_FALSE(GetAndResetActiveStateChanged());
340 342
341 // Activate a longpress-triggered selection. 343 // Activate a longpress-triggered selection.
342 gfx::PointF selection_start(0, 10); 344 gfx::PointF selection_start(0, 10);
343 gfx::PointF selection_end(10, 10); 345 gfx::PointF selection_end(10, 10);
344 selector.OnLongPressEvent(event.GetEventTime(), gfx::PointF()); 346 selector.OnLongPressEvent(event.GetEventTime(), gfx::PointF());
345 EXPECT_TRUE(GetAndResetActiveStateChanged()); 347 EXPECT_FALSE(GetAndResetActiveStateChanged());
346 SetSelection(selection_start, selection_end); 348 SetSelection(selection_start, selection_end);
347 selector.OnSelectionActivated(); 349 selector.OnSelectionActivated();
350 EXPECT_TRUE(GetAndResetActiveStateChanged());
348 EXPECT_FALSE(IsDragging()); 351 EXPECT_FALSE(IsDragging());
349 352
350 // Initiate drag motion. 353 // Initiate drag motion.
351 EXPECT_TRUE(selector.WillHandleTouchEvent(event.MovePoint(0, 15, 5))); 354 EXPECT_TRUE(selector.WillHandleTouchEvent(event.MovePoint(0, 15, 5)));
352 EXPECT_FALSE(IsDragging()); 355 EXPECT_FALSE(IsDragging());
353 356
354 // As the initial motion exceeds both endpoints, the closer bound should 357 // As the initial motion exceeds both endpoints, the closer bound should
355 // be used for dragging, in this case the selection end. 358 // be used for dragging, in this case the selection end.
356 EXPECT_TRUE(selector.WillHandleTouchEvent( 359 EXPECT_TRUE(selector.WillHandleTouchEvent(
357 event.MovePoint(0, 15.f + kSlop * 2.f, 5.f + kSlop))); 360 event.MovePoint(0, 15.f + kSlop * 2.f, 5.f + kSlop)));
358 EXPECT_TRUE(IsDragging()); 361 EXPECT_TRUE(IsDragging());
359 EXPECT_EQ(selection_end, DragPosition()); 362 EXPECT_EQ(selection_end, DragPosition());
360 363
361 // Release the touch sequence, ending the drag. 364 // Release the touch sequence, ending the drag.
362 EXPECT_FALSE(selector.WillHandleTouchEvent(event.ReleasePoint())); 365 EXPECT_FALSE(selector.WillHandleTouchEvent(event.ReleasePoint()));
363 EXPECT_FALSE(IsDragging()); 366 EXPECT_FALSE(IsDragging());
364 EXPECT_TRUE(GetAndResetActiveStateChanged()); 367 EXPECT_TRUE(GetAndResetActiveStateChanged());
365 } 368 }
366 369
370 TEST_F(LongPressDragSelectorTest, ScrollAfterLongPress) {
371 LongPressDragSelector selector(this);
372 MockMotionEvent event;
373 gfx::PointF touch_point(0, 0);
374
375 // Start a touch sequence.
376 EXPECT_FALSE(selector.WillHandleTouchEvent(
377 event.PressPoint(touch_point.x(), touch_point.y())));
378
379 // Long-press and hold down.
380 selector.OnLongPressEvent(event.GetEventTime(), touch_point);
381
382 // Scroll the page. This should cancel long-press drag gesture.
383 touch_point.Offset(0, 2 * kSlop);
384 EXPECT_FALSE(selector.WillHandleTouchEvent(
385 event.MovePoint(0, touch_point.x(), touch_point.y())));
386 selector.OnScrollBeginEvent();
387
388 // Now if the selection is activated, because long-press drag gesture was
389 // canceled, active state of the long-press selector should not change.
390 selector.OnSelectionActivated();
391 EXPECT_FALSE(GetAndResetActiveStateChanged());
392
393 // Release the touch sequence.
394 selector.WillHandleTouchEvent(event.ReleasePoint());
395 }
396
367 } // namespace ui 397 } // namespace ui
OLDNEW
« no previous file with comments | « ui/touch_selection/longpress_drag_selector.cc ('k') | ui/touch_selection/touch_selection_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698