forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtouch_selection_controller_unittest.cc
1782 lines (1476 loc) · 71.7 KB
/
touch_selection_controller_unittest.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/touch_selection/touch_selection_controller.h"
#include <vector>
#include "base/macros.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/events/test/motion_event_test_utils.h"
#include "ui/touch_selection/touch_selection_controller_test_api.h"
using testing::ElementsAre;
using testing::IsEmpty;
using ui::test::MockMotionEvent;
namespace ui {
namespace {
const int kDefaultTapTimeoutMs = 200;
const float kDefaulTapSlop = 10.f;
const gfx::PointF kIgnoredPoint(0, 0);
class MockTouchHandleDrawable : public TouchHandleDrawable {
public:
explicit MockTouchHandleDrawable(bool* contains_point)
: intersects_rect_(contains_point) {}
MockTouchHandleDrawable(const MockTouchHandleDrawable&) = delete;
MockTouchHandleDrawable& operator=(const MockTouchHandleDrawable&) = delete;
~MockTouchHandleDrawable() override {}
void SetEnabled(bool enabled) override {}
void SetOrientation(ui::TouchHandleOrientation orientation,
bool mirror_vertical,
bool mirror_horizontal) override {}
void SetOrigin(const gfx::PointF& origin) override {}
void SetAlpha(float alpha) override {}
gfx::RectF GetVisibleBounds() const override {
return *intersects_rect_ ? gfx::RectF(-1000, -1000, 2000, 2000)
: gfx::RectF(-1000, -1000, 0, 0);
}
float GetDrawableHorizontalPaddingRatio() const override { return 0; }
private:
bool* intersects_rect_;
};
} // namespace
class TouchSelectionControllerTest : public testing::Test,
public TouchSelectionControllerClient {
public:
TouchSelectionControllerTest()
: caret_moved_(false),
selection_moved_(false),
selection_points_swapped_(false),
needs_animate_(false),
animation_enabled_(true),
dragging_enabled_(false) {}
TouchSelectionControllerTest(const TouchSelectionControllerTest&) = delete;
TouchSelectionControllerTest& operator=(const TouchSelectionControllerTest&) =
delete;
~TouchSelectionControllerTest() override {}
// testing::Test implementation.
void SetUp() override {
controller_ =
std::make_unique<TouchSelectionController>(this, DefaultConfig());
// Simulate start of a TouchEvent sequence.
controller_->WillHandleTouchEvent(
MockMotionEvent(MotionEvent::Action::DOWN));
}
void TearDown() override { controller_.reset(); }
// TouchSelectionControllerClient implementation.
bool SupportsAnimation() const override { return animation_enabled_; }
void SetNeedsAnimate() override { needs_animate_ = true; }
void MoveCaret(const gfx::PointF& position) override {
caret_moved_ = true;
caret_position_ = position;
}
void SelectBetweenCoordinates(const gfx::PointF& base,
const gfx::PointF& extent) override {
if (base == selection_end_ && extent == selection_start_)
selection_points_swapped_ = true;
selection_start_ = base;
selection_end_ = extent;
}
void MoveRangeSelectionExtent(const gfx::PointF& extent) override {
selection_moved_ = true;
selection_end_ = extent;
}
void OnSelectionEvent(SelectionEventType event) override {
events_.push_back(event);
last_event_start_ = controller_->GetStartPosition();
last_event_end_ = controller_->GetEndPosition();
last_event_bounds_rect_ = controller_->GetRectBetweenBounds();
}
void OnDragUpdate(const TouchSelectionDraggable::Type type,
const gfx::PointF& position) override {
last_drag_update_position_ = position;
}
std::unique_ptr<TouchHandleDrawable> CreateDrawable() override {
return std::make_unique<MockTouchHandleDrawable>(&dragging_enabled_);
}
void DidScroll() override {}
void EnableLongPressDragSelection() {
TouchSelectionController::Config config = DefaultConfig();
config.enable_longpress_drag_selection = true;
controller_ = std::make_unique<TouchSelectionController>(this, config);
}
void SetHideActiveHandle(bool hide) {
TouchSelectionController::Config config = DefaultConfig();
config.hide_active_handle = hide;
controller_ = std::make_unique<TouchSelectionController>(this, config);
// Simulate start of a TouchEvent sequence.
controller_->WillHandleTouchEvent(
MockMotionEvent(MotionEvent::Action::DOWN));
}
void SetAnimationEnabled(bool enabled) { animation_enabled_ = enabled; }
void SetDraggingEnabled(bool enabled) { dragging_enabled_ = enabled; }
void ClearSelection() {
controller_->OnSelectionBoundsChanged(gfx::SelectionBound(),
gfx::SelectionBound());
}
void ClearInsertion() { ClearSelection(); }
void ChangeInsertion(const gfx::RectF& rect, bool visible) {
gfx::SelectionBound bound;
bound.set_type(gfx::SelectionBound::CENTER);
bound.SetEdge(rect.origin(), rect.bottom_left());
bound.set_visible(visible);
controller_->OnSelectionBoundsChanged(bound, bound);
}
void ChangeSelection(const gfx::RectF& start_rect,
bool start_visible,
const gfx::RectF& end_rect,
bool end_visible) {
gfx::SelectionBound start_bound, end_bound;
start_bound.set_type(gfx::SelectionBound::LEFT);
end_bound.set_type(gfx::SelectionBound::RIGHT);
start_bound.SetEdge(start_rect.origin(), start_rect.bottom_left());
end_bound.SetEdge(end_rect.origin(), end_rect.bottom_left());
start_bound.set_visible(start_visible);
end_bound.set_visible(end_visible);
controller_->OnSelectionBoundsChanged(start_bound, end_bound);
}
void ChangeVerticalSelection(const gfx::RectF& start_rect,
bool start_visible,
const gfx::RectF& end_rect,
bool end_visible) {
gfx::SelectionBound start_bound, end_bound;
start_bound.set_type(gfx::SelectionBound::RIGHT);
end_bound.set_type(gfx::SelectionBound::LEFT);
start_bound.SetEdge(start_rect.origin(), start_rect.bottom_right());
end_bound.SetEdge(end_rect.bottom_right(), end_rect.origin());
start_bound.set_visible(start_visible);
end_bound.set_visible(end_visible);
controller_->OnSelectionBoundsChanged(start_bound, end_bound);
}
void OnLongPressEvent() {
controller().HandleLongPressEvent(base::TimeTicks(),
kIgnoredPoint);
}
void OnTapEvent() {
controller().HandleTapEvent(kIgnoredPoint, 1);
}
void OnDoubleTapEvent() {
controller().HandleTapEvent(kIgnoredPoint, 2);
}
void OnTripleTapEvent() { controller().HandleTapEvent(kIgnoredPoint, 3); }
void Animate() {
base::TimeTicks now = base::TimeTicks::Now();
while (needs_animate_) {
needs_animate_ = controller_->Animate(now);
now += base::Milliseconds(16);
}
}
bool GetAndResetNeedsAnimate() {
bool needs_animate = needs_animate_;
Animate();
return needs_animate;
}
bool GetAndResetCaretMoved() {
bool moved = caret_moved_;
caret_moved_ = false;
return moved;
}
bool GetAndResetSelectionMoved() {
bool moved = selection_moved_;
selection_moved_ = false;
return moved;
}
bool GetAndResetSelectionPointsSwapped() {
bool swapped = selection_points_swapped_;
selection_points_swapped_ = false;
return swapped;
}
const gfx::PointF& GetLastCaretPosition() const { return caret_position_; }
const gfx::PointF& GetLastSelectionStart() const { return selection_start_; }
const gfx::PointF& GetLastSelectionEnd() const { return selection_end_; }
const gfx::PointF& GetLastEventStart() const { return last_event_start_; }
const gfx::PointF& GetLastEventEnd() const { return last_event_end_; }
const gfx::RectF& GetLastEventBoundsRect() const {
return last_event_bounds_rect_;
}
const gfx::PointF& GetLastDragUpdatePosition() const {
return last_drag_update_position_;
}
std::vector<SelectionEventType> GetAndResetEvents() {
std::vector<SelectionEventType> events;
events.swap(events_);
return events;
}
TouchSelectionController& controller() { return *controller_; }
private:
TouchSelectionController::Config DefaultConfig() {
// |enable_longpress_drag_selection| is set to false by default, and should
// be overriden for explicit testing.
TouchSelectionController::Config config;
config.max_tap_duration = base::Milliseconds(kDefaultTapTimeoutMs);
config.tap_slop = kDefaulTapSlop;
config.enable_longpress_drag_selection = false;
return config;
}
gfx::PointF last_event_start_;
gfx::PointF last_event_end_;
gfx::PointF caret_position_;
gfx::PointF selection_start_;
gfx::PointF selection_end_;
gfx::RectF last_event_bounds_rect_;
gfx::PointF last_drag_update_position_;
std::vector<SelectionEventType> events_;
bool caret_moved_;
bool selection_moved_;
bool selection_points_swapped_;
bool needs_animate_;
bool animation_enabled_;
bool dragging_enabled_;
std::unique_ptr<TouchSelectionController> controller_;
};
TEST_F(TouchSelectionControllerTest, InsertionBasic) {
gfx::RectF insertion_rect(5, 5, 0, 10);
bool visible = true;
OnTapEvent();
ChangeInsertion(insertion_rect, visible);
EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_HANDLE_SHOWN));
EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventStart());
insertion_rect.Offset(1, 0);
ChangeInsertion(insertion_rect, visible);
EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_HANDLE_MOVED));
EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventStart());
insertion_rect.Offset(0, 1);
ChangeInsertion(insertion_rect, visible);
EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_HANDLE_MOVED));
EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventStart());
OnTapEvent();
insertion_rect.Offset(1, 0);
ChangeInsertion(insertion_rect, visible);
EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_HANDLE_SHOWN));
EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventStart());
ClearInsertion();
EXPECT_THAT(GetAndResetEvents(),
ElementsAre(INSERTION_HANDLE_CLEARED));
}
TEST_F(TouchSelectionControllerTest, InsertionToSelectionTransition) {
OnLongPressEvent();
gfx::RectF start_rect(5, 5, 0, 10);
gfx::RectF end_rect(50, 5, 0, 10);
bool visible = true;
ChangeInsertion(start_rect, visible);
EXPECT_THAT(GetAndResetEvents(),
ElementsAre(INSERTION_HANDLE_SHOWN));
EXPECT_EQ(start_rect.bottom_left(), GetLastEventStart());
ChangeSelection(start_rect, visible, end_rect, visible);
EXPECT_THAT(GetAndResetEvents(),
ElementsAre(INSERTION_HANDLE_CLEARED, SELECTION_HANDLES_SHOWN));
EXPECT_EQ(start_rect.bottom_left(), GetLastEventStart());
ChangeInsertion(end_rect, visible);
EXPECT_THAT(GetAndResetEvents(),
ElementsAre(SELECTION_HANDLES_CLEARED, INSERTION_HANDLE_SHOWN));
EXPECT_EQ(end_rect.bottom_left(), GetLastEventStart());
ClearInsertion();
EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_HANDLE_CLEARED));
OnTapEvent();
ChangeInsertion(end_rect, visible);
EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_HANDLE_SHOWN));
EXPECT_EQ(end_rect.bottom_left(), GetLastEventStart());
}
TEST_F(TouchSelectionControllerTest, InsertionDragged) {
base::TimeTicks event_time = base::TimeTicks::Now();
OnTapEvent();
// The touch sequence should not be handled if insertion is not active.
MockMotionEvent event(MockMotionEvent::Action::DOWN, event_time, 0, 0);
EXPECT_FALSE(controller().WillHandleTouchEvent(event));
float line_height = 10.f;
gfx::RectF start_rect(10, 0, 0, line_height);
bool visible = true;
ChangeInsertion(start_rect, visible);
EXPECT_THAT(GetAndResetEvents(),
ElementsAre(INSERTION_HANDLE_SHOWN));
EXPECT_EQ(start_rect.bottom_left(), GetLastEventStart());
// The touch sequence should be handled only if the drawable reports a hit.
EXPECT_FALSE(controller().WillHandleTouchEvent(event));
SetDraggingEnabled(true);
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
EXPECT_FALSE(GetAndResetCaretMoved());
EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_HANDLE_DRAG_STARTED));
// The MoveCaret() result should reflect the movement.
// The reported position is offset from the center of |start_rect|.
gfx::PointF start_offset = start_rect.CenterPoint();
event = MockMotionEvent(MockMotionEvent::Action::MOVE, event_time, 0, 5);
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
EXPECT_TRUE(GetAndResetCaretMoved());
EXPECT_EQ(start_offset + gfx::Vector2dF(0, 5), GetLastCaretPosition());
event = MockMotionEvent(MockMotionEvent::Action::MOVE, event_time, 5, 5);
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
EXPECT_TRUE(GetAndResetCaretMoved());
EXPECT_EQ(start_offset + gfx::Vector2dF(5, 5), GetLastCaretPosition());
event = MockMotionEvent(MockMotionEvent::Action::MOVE, event_time, 10, 10);
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
EXPECT_TRUE(GetAndResetCaretMoved());
EXPECT_EQ(start_offset + gfx::Vector2dF(10, 10), GetLastCaretPosition());
event = MockMotionEvent(MockMotionEvent::Action::UP, event_time, 10, 5);
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
EXPECT_FALSE(GetAndResetCaretMoved());
EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_HANDLE_DRAG_STOPPED));
// Following Action::DOWN should not be consumed if it does not start handle
// dragging.
SetDraggingEnabled(false);
event = MockMotionEvent(MotionEvent::Action::DOWN, event_time, 0, 0);
EXPECT_FALSE(controller().WillHandleTouchEvent(event));
}
TEST_F(TouchSelectionControllerTest, InsertionDeactivatedWhileDragging) {
base::TimeTicks event_time = base::TimeTicks::Now();
OnTapEvent();
float line_height = 10.f;
gfx::RectF start_rect(10, 0, 0, line_height);
bool visible = true;
ChangeInsertion(start_rect, visible);
EXPECT_THAT(GetAndResetEvents(),
ElementsAre(INSERTION_HANDLE_SHOWN));
EXPECT_EQ(start_rect.bottom_left(), GetLastEventStart());
// Enable dragging so that the following Action::DOWN starts handle dragging.
SetDraggingEnabled(true);
// Touch down to start dragging.
MockMotionEvent event(MockMotionEvent::Action::DOWN, event_time, 0, 0);
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
EXPECT_FALSE(GetAndResetCaretMoved());
EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_HANDLE_DRAG_STARTED));
// Move the handle.
gfx::PointF start_offset = start_rect.CenterPoint();
event = MockMotionEvent(MockMotionEvent::Action::MOVE, event_time, 0, 5);
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
EXPECT_TRUE(GetAndResetCaretMoved());
EXPECT_EQ(start_offset + gfx::Vector2dF(0, 5), GetLastCaretPosition());
// Deactivate touch selection to end dragging.
controller().HideAndDisallowShowingAutomatically();
EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_HANDLE_DRAG_STOPPED,
INSERTION_HANDLE_CLEARED));
// Move the finger. There is no handle to move, so the cursor is not moved;
// but, the event is still consumed because the touch down that started the
// touch sequence was consumed.
event = MockMotionEvent(MockMotionEvent::Action::MOVE, event_time, 5, 5);
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
EXPECT_FALSE(GetAndResetCaretMoved());
EXPECT_EQ(start_offset + gfx::Vector2dF(0, 5), GetLastCaretPosition());
// Lift the finger to end the touch sequence.
event = MockMotionEvent(MockMotionEvent::Action::UP, event_time, 5, 5);
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
EXPECT_FALSE(GetAndResetCaretMoved());
EXPECT_THAT(GetAndResetEvents(), IsEmpty());
// Following Action::DOWN should not be consumed if it does not start handle
// dragging.
SetDraggingEnabled(false);
event = MockMotionEvent(MotionEvent::Action::DOWN, event_time, 0, 0);
EXPECT_FALSE(controller().WillHandleTouchEvent(event));
}
TEST_F(TouchSelectionControllerTest, InsertionTapped) {
base::TimeTicks event_time = base::TimeTicks::Now();
OnTapEvent();
SetDraggingEnabled(true);
gfx::RectF start_rect(10, 0, 0, 10);
bool visible = true;
ChangeInsertion(start_rect, visible);
EXPECT_THAT(GetAndResetEvents(),
ElementsAre(INSERTION_HANDLE_SHOWN));
MockMotionEvent event(MockMotionEvent::Action::DOWN, event_time, 0, 0);
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_HANDLE_DRAG_STARTED));
event = MockMotionEvent(MockMotionEvent::Action::UP, event_time, 0, 0);
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_HANDLE_TAPPED,
INSERTION_HANDLE_DRAG_STOPPED));
// Reset the insertion.
ClearInsertion();
OnTapEvent();
ChangeInsertion(start_rect, visible);
EXPECT_THAT(GetAndResetEvents(),
ElementsAre(INSERTION_HANDLE_CLEARED, INSERTION_HANDLE_SHOWN));
// No tap should be signalled if the time between DOWN and UP was too long.
event = MockMotionEvent(MockMotionEvent::Action::DOWN, event_time, 0, 0);
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
event = MockMotionEvent(MockMotionEvent::Action::UP,
event_time + base::Seconds(1), 0, 0);
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_HANDLE_DRAG_STARTED,
INSERTION_HANDLE_DRAG_STOPPED));
// Reset the insertion.
ClearInsertion();
OnTapEvent();
ChangeInsertion(start_rect, visible);
EXPECT_THAT(GetAndResetEvents(),
ElementsAre(INSERTION_HANDLE_CLEARED, INSERTION_HANDLE_SHOWN));
// No tap should be signalled if the drag was too long.
event = MockMotionEvent(MockMotionEvent::Action::DOWN, event_time, 0, 0);
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
event = MockMotionEvent(MockMotionEvent::Action::MOVE, event_time, 100, 0);
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
event = MockMotionEvent(MockMotionEvent::Action::UP, event_time, 100, 0);
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_HANDLE_DRAG_STARTED,
INSERTION_HANDLE_DRAG_STOPPED));
// Reset the insertion.
ClearInsertion();
OnTapEvent();
ChangeInsertion(start_rect, visible);
EXPECT_THAT(GetAndResetEvents(),
ElementsAre(INSERTION_HANDLE_CLEARED, INSERTION_HANDLE_SHOWN));
// No tap should be signalled if the touch sequence is cancelled.
event = MockMotionEvent(MockMotionEvent::Action::DOWN, event_time, 0, 0);
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
event = MockMotionEvent(MockMotionEvent::Action::CANCEL, event_time, 0, 0);
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_HANDLE_DRAG_STARTED,
INSERTION_HANDLE_DRAG_STOPPED));
}
TEST_F(TouchSelectionControllerTest, SelectionBasic) {
gfx::RectF start_rect(5, 5, 0, 10);
gfx::RectF end_rect(50, 5, 0, 10);
bool visible = true;
OnLongPressEvent();
ChangeSelection(start_rect, visible, end_rect, visible);
EXPECT_THAT(GetAndResetEvents(),
ElementsAre(SELECTION_HANDLES_SHOWN));
EXPECT_EQ(start_rect.bottom_left(), GetLastEventStart());
start_rect.Offset(1, 0);
ChangeSelection(start_rect, visible, end_rect, visible);
// Selection movement does not currently trigger a separate event.
EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_HANDLES_MOVED));
EXPECT_EQ(start_rect.bottom_left(), GetLastEventStart());
EXPECT_EQ(end_rect.bottom_left(), GetLastEventEnd());
ClearSelection();
EXPECT_THAT(GetAndResetEvents(),
ElementsAre(SELECTION_HANDLES_CLEARED));
}
TEST_F(TouchSelectionControllerTest, SelectionAllowedByDoubleTap) {
gfx::RectF start_rect(5, 5, 0, 10);
gfx::RectF end_rect(50, 5, 0, 10);
bool visible = true;
OnDoubleTapEvent();
ChangeSelection(start_rect, visible, end_rect, visible);
EXPECT_THAT(GetAndResetEvents(),
ElementsAre(SELECTION_HANDLES_SHOWN));
EXPECT_EQ(start_rect.bottom_left(), GetLastEventStart());
}
TEST_F(TouchSelectionControllerTest, SelectionAllowedByDoubleTapOnEditable) {
gfx::RectF start_rect(5, 5, 0, 10);
gfx::RectF end_rect(50, 5, 0, 10);
bool visible = true;
// If the user double tap selects text in an editable region, the first tap
// will register insertion and the second tap selection.
OnTapEvent();
ChangeInsertion(start_rect, visible);
EXPECT_THAT(GetAndResetEvents(),
ElementsAre(INSERTION_HANDLE_SHOWN));
OnDoubleTapEvent();
ChangeSelection(start_rect, visible, end_rect, visible);
EXPECT_THAT(GetAndResetEvents(),
ElementsAre(INSERTION_HANDLE_CLEARED, SELECTION_HANDLES_SHOWN));
}
TEST_F(TouchSelectionControllerTest,
SelectionAllowedByTripleTapOnEditableArabicVowel) {
gfx::RectF start_rect(5, 5, 0, 10);
gfx::RectF end_rect(5, 5, 0, 10);
bool visible = true;
// If the user triple tap selects text in an editable region, the first tap
// will register insertion.
OnTapEvent();
ChangeInsertion(start_rect, visible);
EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_HANDLE_SHOWN));
// The second tap will also not select since the charcter (Arabic/Urdu vowel)
// has zero width, the second tap will maintain insertion.
OnDoubleTapEvent();
ChangeInsertion(start_rect, visible);
EXPECT_THAT(GetAndResetEvents(), ElementsAre());
// The third tap selects everything in the editable text box. Since the only
// text in the editable box is a zero length character the selection has the
// same start and end rect.
OnTripleTapEvent();
ChangeSelection(start_rect, visible, end_rect, visible);
EXPECT_THAT(GetAndResetEvents(),
ElementsAre(INSERTION_HANDLE_CLEARED, SELECTION_HANDLES_SHOWN));
}
TEST_F(TouchSelectionControllerTest, SelectionAllowsEmptyUpdateAfterLongPress) {
gfx::RectF start_rect(5, 5, 0, 10);
gfx::RectF end_rect(50, 5, 0, 10);
bool visible = true;
OnLongPressEvent();
EXPECT_THAT(GetAndResetEvents(), IsEmpty());
// There may be several empty updates after a longpress due to the
// asynchronous response. These empty updates should not prevent the selection
// handles from (eventually) activating.
ClearSelection();
EXPECT_THAT(GetAndResetEvents(), IsEmpty());
ClearSelection();
EXPECT_THAT(GetAndResetEvents(), IsEmpty());
ChangeSelection(start_rect, visible, end_rect, visible);
EXPECT_THAT(GetAndResetEvents(),
ElementsAre(SELECTION_HANDLES_SHOWN));
}
TEST_F(TouchSelectionControllerTest, SelectionRepeatedLongPress) {
gfx::RectF start_rect(5, 5, 0, 10);
gfx::RectF end_rect(50, 5, 0, 10);
bool visible = true;
OnLongPressEvent();
ChangeSelection(start_rect, visible, end_rect, visible);
EXPECT_THAT(GetAndResetEvents(),
ElementsAre(SELECTION_HANDLES_SHOWN));
EXPECT_EQ(start_rect.bottom_left(), GetLastEventStart());
EXPECT_EQ(end_rect.bottom_left(), GetLastEventEnd());
// A long press triggering a new selection should re-send the
// SELECTION_HANDLES_SHOWN
// event notification.
start_rect.Offset(10, 10);
OnLongPressEvent();
ChangeSelection(start_rect, visible, end_rect, visible);
EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_HANDLES_SHOWN));
EXPECT_EQ(start_rect.bottom_left(), GetLastEventStart());
EXPECT_EQ(end_rect.bottom_left(), GetLastEventEnd());
}
TEST_F(TouchSelectionControllerTest, SelectionDragged) {
base::TimeTicks event_time = base::TimeTicks::Now();
OnLongPressEvent();
// The touch sequence should not be handled if selection is not active.
MockMotionEvent event(MockMotionEvent::Action::DOWN, event_time, 0, 0);
EXPECT_FALSE(controller().WillHandleTouchEvent(event));
float line_height = 10.f;
gfx::RectF start_rect(0, 0, 0, line_height);
gfx::RectF end_rect(50, 0, 0, line_height);
bool visible = true;
ChangeSelection(start_rect, visible, end_rect, visible);
EXPECT_THAT(GetAndResetEvents(),
ElementsAre(SELECTION_HANDLES_SHOWN));
EXPECT_EQ(start_rect.bottom_left(), GetLastEventStart());
// The touch sequence should be handled only if the drawable reports a hit.
EXPECT_FALSE(controller().WillHandleTouchEvent(event));
SetDraggingEnabled(true);
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
EXPECT_FALSE(GetAndResetSelectionMoved());
// The SelectBetweenCoordinates() result should reflect the movement. Note
// that the start coordinate will always reflect the "fixed" handle's
// position, in this case the position from |end_rect|.
// Note that the reported position is offset from the center of the
// input rects (i.e., the middle of the corresponding text line).
gfx::PointF fixed_offset = end_rect.CenterPoint();
gfx::PointF start_offset = start_rect.CenterPoint();
event = MockMotionEvent(MockMotionEvent::Action::MOVE, event_time, 0, 5);
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_HANDLE_DRAG_STARTED));
EXPECT_TRUE(GetAndResetSelectionMoved());
EXPECT_EQ(fixed_offset, GetLastSelectionStart());
EXPECT_EQ(start_offset + gfx::Vector2dF(0, 5), GetLastSelectionEnd());
event = MockMotionEvent(MockMotionEvent::Action::MOVE, event_time, 5, 5);
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
EXPECT_TRUE(GetAndResetSelectionMoved());
EXPECT_EQ(fixed_offset, GetLastSelectionStart());
EXPECT_EQ(start_offset + gfx::Vector2dF(5, 5), GetLastSelectionEnd());
event = MockMotionEvent(MockMotionEvent::Action::MOVE, event_time, 10, 5);
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
EXPECT_TRUE(GetAndResetSelectionMoved());
EXPECT_EQ(fixed_offset, GetLastSelectionStart());
EXPECT_EQ(start_offset + gfx::Vector2dF(10, 5), GetLastSelectionEnd());
event = MockMotionEvent(MockMotionEvent::Action::UP, event_time, 10, 5);
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_HANDLE_DRAG_STOPPED));
EXPECT_FALSE(GetAndResetSelectionMoved());
// Following Action::DOWN should not be consumed if it does not start handle
// dragging.
SetDraggingEnabled(false);
event = MockMotionEvent(MotionEvent::Action::DOWN, event_time, 0, 0);
EXPECT_FALSE(controller().WillHandleTouchEvent(event));
}
TEST_F(TouchSelectionControllerTest, SelectionDraggedWithOverlap) {
base::TimeTicks event_time = base::TimeTicks::Now();
OnLongPressEvent();
float line_height = 10.f;
gfx::RectF start_rect(0, 0, 0, line_height);
gfx::RectF end_rect(50, 0, 0, line_height);
bool visible = true;
ChangeSelection(start_rect, visible, end_rect, visible);
EXPECT_THAT(GetAndResetEvents(),
ElementsAre(SELECTION_HANDLES_SHOWN));
EXPECT_EQ(start_rect.bottom_left(), GetLastEventStart());
// The Action::DOWN should lock to the closest handle.
gfx::PointF end_offset = end_rect.CenterPoint();
gfx::PointF fixed_offset = start_rect.CenterPoint();
float touch_down_x = (end_offset.x() + fixed_offset.x()) / 2 + 1.f;
MockMotionEvent event(MockMotionEvent::Action::DOWN, event_time, touch_down_x,
0);
SetDraggingEnabled(true);
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_HANDLE_DRAG_STARTED));
EXPECT_FALSE(GetAndResetSelectionMoved());
// Even though the Action::MOVE is over the start handle, it should continue
// targetting the end handle that consumed the Action::DOWN.
event = MockMotionEvent(MockMotionEvent::Action::MOVE, event_time, 0, 0);
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
EXPECT_TRUE(GetAndResetSelectionMoved());
EXPECT_EQ(fixed_offset, GetLastSelectionStart());
EXPECT_EQ(end_offset - gfx::Vector2dF(touch_down_x, 0),
GetLastSelectionEnd());
event = MockMotionEvent(MockMotionEvent::Action::UP, event_time, 0, 0);
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_HANDLE_DRAG_STOPPED));
EXPECT_FALSE(GetAndResetSelectionMoved());
}
TEST_F(TouchSelectionControllerTest, SelectionDraggedToSwitchBaseAndExtent) {
base::TimeTicks event_time = base::TimeTicks::Now();
OnLongPressEvent();
float line_height = 10.f;
gfx::RectF start_rect(50, line_height, 0, line_height);
gfx::RectF end_rect(100, line_height, 0, line_height);
bool visible = true;
ChangeSelection(start_rect, visible, end_rect, visible);
EXPECT_THAT(GetAndResetEvents(),
ElementsAre(SELECTION_HANDLES_SHOWN));
EXPECT_EQ(start_rect.bottom_left(), GetLastEventStart());
SetDraggingEnabled(true);
// Move the extent, not triggering a swap of points.
MockMotionEvent event(MockMotionEvent::Action::DOWN, event_time, end_rect.x(),
end_rect.bottom());
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
EXPECT_FALSE(GetAndResetSelectionMoved());
EXPECT_FALSE(GetAndResetSelectionPointsSwapped());
gfx::PointF base_offset = start_rect.CenterPoint();
gfx::PointF extent_offset = end_rect.CenterPoint();
event = MockMotionEvent(MockMotionEvent::Action::MOVE, event_time,
end_rect.x(), end_rect.bottom() + 5);
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_HANDLE_DRAG_STARTED));
EXPECT_TRUE(GetAndResetSelectionMoved());
EXPECT_FALSE(GetAndResetSelectionPointsSwapped());
EXPECT_EQ(base_offset, GetLastSelectionStart());
EXPECT_EQ(extent_offset + gfx::Vector2dF(0, 5), GetLastSelectionEnd());
event = MockMotionEvent(MockMotionEvent::Action::UP, event_time, 10, 5);
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_HANDLE_DRAG_STOPPED));
EXPECT_FALSE(GetAndResetSelectionMoved());
end_rect += gfx::Vector2dF(0, 5);
ChangeSelection(start_rect, visible, end_rect, visible);
EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_HANDLES_MOVED));
// Move the base, triggering a swap of points.
event = MockMotionEvent(MockMotionEvent::Action::DOWN, event_time,
start_rect.x(), start_rect.bottom());
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
EXPECT_FALSE(GetAndResetSelectionMoved());
EXPECT_TRUE(GetAndResetSelectionPointsSwapped());
base_offset = end_rect.CenterPoint();
extent_offset = start_rect.CenterPoint();
event = MockMotionEvent(MockMotionEvent::Action::MOVE, event_time,
start_rect.x(), start_rect.bottom() + 5);
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_HANDLE_DRAG_STARTED));
EXPECT_TRUE(GetAndResetSelectionMoved());
EXPECT_FALSE(GetAndResetSelectionPointsSwapped());
EXPECT_EQ(base_offset, GetLastSelectionStart());
EXPECT_EQ(extent_offset + gfx::Vector2dF(0, 5), GetLastSelectionEnd());
event = MockMotionEvent(MockMotionEvent::Action::UP, event_time, 10, 5);
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_HANDLE_DRAG_STOPPED));
EXPECT_FALSE(GetAndResetSelectionMoved());
start_rect += gfx::Vector2dF(0, 5);
ChangeSelection(start_rect, visible, end_rect, visible);
EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_HANDLES_MOVED));
// Move the same point again, not triggering a swap of points.
event = MockMotionEvent(MockMotionEvent::Action::DOWN, event_time,
start_rect.x(), start_rect.bottom());
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
EXPECT_FALSE(GetAndResetSelectionMoved());
EXPECT_FALSE(GetAndResetSelectionPointsSwapped());
base_offset = end_rect.CenterPoint();
extent_offset = start_rect.CenterPoint();
event = MockMotionEvent(MockMotionEvent::Action::MOVE, event_time,
start_rect.x(), start_rect.bottom() + 5);
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_HANDLE_DRAG_STARTED));
EXPECT_TRUE(GetAndResetSelectionMoved());
EXPECT_FALSE(GetAndResetSelectionPointsSwapped());
EXPECT_EQ(base_offset, GetLastSelectionStart());
EXPECT_EQ(extent_offset + gfx::Vector2dF(0, 5), GetLastSelectionEnd());
event = MockMotionEvent(MockMotionEvent::Action::UP, event_time, 10, 5);
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_HANDLE_DRAG_STOPPED));
EXPECT_FALSE(GetAndResetSelectionMoved());
start_rect += gfx::Vector2dF(0, 5);
ChangeSelection(start_rect, visible, end_rect, visible);
EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_HANDLES_MOVED));
// Move the base, triggering a swap of points.
event = MockMotionEvent(MockMotionEvent::Action::DOWN, event_time,
end_rect.x(), end_rect.bottom());
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
EXPECT_FALSE(GetAndResetSelectionMoved());
EXPECT_TRUE(GetAndResetSelectionPointsSwapped());
base_offset = start_rect.CenterPoint();
extent_offset = end_rect.CenterPoint();
event = MockMotionEvent(MockMotionEvent::Action::MOVE, event_time,
end_rect.x(), end_rect.bottom() + 5);
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_HANDLE_DRAG_STARTED));
EXPECT_TRUE(GetAndResetSelectionMoved());
EXPECT_FALSE(GetAndResetSelectionPointsSwapped());
EXPECT_EQ(base_offset, GetLastSelectionStart());
EXPECT_EQ(extent_offset + gfx::Vector2dF(0, 5), GetLastSelectionEnd());
event = MockMotionEvent(MockMotionEvent::Action::UP, event_time, 10, 5);
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_HANDLE_DRAG_STOPPED));
EXPECT_FALSE(GetAndResetSelectionMoved());
}
TEST_F(TouchSelectionControllerTest, SelectionDragExtremeLineSize) {
base::TimeTicks event_time = base::TimeTicks::Now();
OnLongPressEvent();
float small_line_height = 1.f;
float large_line_height = 50.f;
gfx::RectF small_line_rect(0, 0, 0, small_line_height);
gfx::RectF large_line_rect(50, 50, 0, large_line_height);
bool visible = true;
ChangeSelection(small_line_rect, visible, large_line_rect, visible);
EXPECT_THAT(GetAndResetEvents(),
ElementsAre(SELECTION_HANDLES_SHOWN));
EXPECT_EQ(small_line_rect.bottom_left(), GetLastEventStart());
// Start dragging the handle on the small line.
MockMotionEvent event(MockMotionEvent::Action::DOWN, event_time,
small_line_rect.x(), small_line_rect.y());
SetDraggingEnabled(true);
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_HANDLE_DRAG_STARTED));
// The drag coordinate for large lines should be capped to a reasonable
// offset, allowing seamless transition to neighboring lines with different
// sizes. The drag coordinate for small lines should have an offset
// commensurate with the small line size.
EXPECT_EQ(large_line_rect.bottom_left() - gfx::Vector2dF(0, 8.f),
GetLastSelectionStart());
EXPECT_EQ(small_line_rect.CenterPoint(), GetLastSelectionEnd());
small_line_rect += gfx::Vector2dF(25.f, 0);
event = MockMotionEvent(MockMotionEvent::Action::MOVE, event_time,
small_line_rect.x(), small_line_rect.y());
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
EXPECT_TRUE(GetAndResetSelectionMoved());
EXPECT_EQ(small_line_rect.CenterPoint(), GetLastSelectionEnd());
}
TEST_F(TouchSelectionControllerTest, Animation) {
OnTapEvent();
gfx::RectF insertion_rect(5, 5, 0, 10);
bool visible = true;
ChangeInsertion(insertion_rect, visible);
EXPECT_FALSE(GetAndResetNeedsAnimate());
visible = false;
ChangeInsertion(insertion_rect, visible);
EXPECT_TRUE(GetAndResetNeedsAnimate());
visible = true;
ChangeInsertion(insertion_rect, visible);
EXPECT_TRUE(GetAndResetNeedsAnimate());
// If the handles are explicity hidden, no animation should be triggered.
controller().HideAndDisallowShowingAutomatically();
EXPECT_FALSE(GetAndResetNeedsAnimate());
// If the client doesn't support animation, no animation should be triggered.
SetAnimationEnabled(false);
OnTapEvent();
visible = true;
ChangeInsertion(insertion_rect, visible);
EXPECT_FALSE(GetAndResetNeedsAnimate());
}
TEST_F(TouchSelectionControllerTest, TemporarilyHidden) {
TouchSelectionControllerTestApi test_controller(&controller());
OnTapEvent();
gfx::RectF insertion_rect(5, 5, 0, 10);
bool visible = true;
ChangeInsertion(insertion_rect, visible);
EXPECT_FALSE(GetAndResetNeedsAnimate());
EXPECT_TRUE(test_controller.GetStartVisible());
EXPECT_TRUE(test_controller.GetEndVisible());
controller().SetTemporarilyHidden(true);
EXPECT_TRUE(GetAndResetNeedsAnimate());
EXPECT_FALSE(test_controller.GetStartVisible());
EXPECT_FALSE(test_controller.GetEndVisible());
EXPECT_EQ(0.f, test_controller.GetStartAlpha());
EXPECT_EQ(0.f, test_controller.GetEndAlpha());
visible = false;
ChangeInsertion(insertion_rect, visible);
EXPECT_FALSE(GetAndResetNeedsAnimate());
EXPECT_FALSE(test_controller.GetStartVisible());
EXPECT_EQ(0.f, test_controller.GetStartAlpha());
visible = true;
ChangeInsertion(insertion_rect, visible);
EXPECT_FALSE(GetAndResetNeedsAnimate());
EXPECT_FALSE(test_controller.GetStartVisible());
EXPECT_EQ(0.f, test_controller.GetStartAlpha());
controller().SetTemporarilyHidden(false);
EXPECT_TRUE(GetAndResetNeedsAnimate());
EXPECT_TRUE(test_controller.GetStartVisible());
}
TEST_F(TouchSelectionControllerTest, SelectionClearOnTap) {
gfx::RectF start_rect(5, 5, 0, 10);
gfx::RectF end_rect(50, 5, 0, 10);
bool visible = true;
OnLongPressEvent();
ChangeSelection(start_rect, visible, end_rect, visible);
EXPECT_THAT(GetAndResetEvents(),
ElementsAre(SELECTION_HANDLES_SHOWN));
// Selection should not be cleared if the selection bounds have not changed.
OnTapEvent();
EXPECT_THAT(GetAndResetEvents(), IsEmpty());
EXPECT_EQ(start_rect.bottom_left(), GetLastEventStart());
OnTapEvent();
ClearSelection();
EXPECT_THAT(GetAndResetEvents(),
ElementsAre(SELECTION_HANDLES_CLEARED));
}
TEST_F(TouchSelectionControllerTest, LongPressDrag) {
EnableLongPressDragSelection();
TouchSelectionControllerTestApi test_controller(&controller());
gfx::RectF start_rect(-50, 0, 0, 10);
gfx::RectF end_rect(50, 0, 0, 10);
bool visible = true;
// Start a touch sequence.
MockMotionEvent event;
EXPECT_FALSE(controller().WillHandleTouchEvent(event.PressPoint(0, 0)));
// Activate a longpress-triggered selection.
OnLongPressEvent();