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

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

Issue 1358263002: [Android] Support double-tap selection (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix contextual search Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/touch_selection/touch_selection_controller.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/touch_selection/touch_selection_controller.h" 5 #include "ui/touch_selection/touch_selection_controller.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "testing/gmock/include/gmock/gmock.h" 9 #include "testing/gmock/include/gmock/gmock.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 end_bound.set_visible(end_visible); 144 end_bound.set_visible(end_visible);
145 controller_->OnSelectionBoundsChanged(start_bound, end_bound); 145 controller_->OnSelectionBoundsChanged(start_bound, end_bound);
146 } 146 }
147 147
148 void OnLongPressEvent() { 148 void OnLongPressEvent() {
149 ASSERT_FALSE(controller().WillHandleLongPressEvent(base::TimeTicks(), 149 ASSERT_FALSE(controller().WillHandleLongPressEvent(base::TimeTicks(),
150 kIgnoredPoint)); 150 kIgnoredPoint));
151 } 151 }
152 152
153 void OnTapEvent() { 153 void OnTapEvent() {
154 ASSERT_FALSE(controller().WillHandleTapEvent(kIgnoredPoint)); 154 ASSERT_FALSE(controller().WillHandleTapEvent(kIgnoredPoint, 1));
155 }
156
157 void OnDoubleTapEvent() {
158 ASSERT_FALSE(controller().WillHandleTapEvent(kIgnoredPoint, 2));
155 } 159 }
156 160
157 void Animate() { 161 void Animate() {
158 base::TimeTicks now = base::TimeTicks::Now(); 162 base::TimeTicks now = base::TimeTicks::Now();
159 while (needs_animate_) { 163 while (needs_animate_) {
160 needs_animate_ = controller_->Animate(now); 164 needs_animate_ = controller_->Animate(now);
161 now += base::TimeDelta::FromMilliseconds(16); 165 now += base::TimeDelta::FromMilliseconds(16);
162 } 166 }
163 } 167 }
164 168
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after
598 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_HANDLES_MOVED)); 602 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_HANDLES_MOVED));
599 EXPECT_EQ(start_rect.bottom_left(), GetLastEventStart()); 603 EXPECT_EQ(start_rect.bottom_left(), GetLastEventStart());
600 EXPECT_EQ(end_rect.bottom_left(), GetLastEventEnd()); 604 EXPECT_EQ(end_rect.bottom_left(), GetLastEventEnd());
601 605
602 ClearSelection(); 606 ClearSelection();
603 EXPECT_THAT(GetAndResetEvents(), 607 EXPECT_THAT(GetAndResetEvents(),
604 ElementsAre(SELECTION_DISSOLVED, SELECTION_HANDLES_CLEARED)); 608 ElementsAre(SELECTION_DISSOLVED, SELECTION_HANDLES_CLEARED));
605 EXPECT_EQ(gfx::PointF(), GetLastEventStart()); 609 EXPECT_EQ(gfx::PointF(), GetLastEventStart());
606 } 610 }
607 611
612 TEST_F(TouchSelectionControllerTest, SelectionAllowedByDoubleTap) {
613 gfx::RectF start_rect(5, 5, 0, 10);
614 gfx::RectF end_rect(50, 5, 0, 10);
615 bool visible = true;
616
617 OnDoubleTapEvent();
618 ChangeSelection(start_rect, visible, end_rect, visible);
619 EXPECT_THAT(GetAndResetEvents(),
620 ElementsAre(SELECTION_ESTABLISHED, SELECTION_HANDLES_SHOWN));
621 EXPECT_EQ(start_rect.bottom_left(), GetLastEventStart());
622 }
623
624 TEST_F(TouchSelectionControllerTest, SelectionAllowedByDoubleTapOnEditable) {
625 gfx::RectF start_rect(5, 5, 0, 10);
626 gfx::RectF end_rect(50, 5, 0, 10);
627 bool visible = true;
628
629 controller().OnSelectionEditable(true);
630
631 // If the user double tap selects text in an editable region, the first tap
632 // will register insertion and the second tap selection.
633 OnTapEvent();
634 ChangeInsertion(start_rect, visible);
635 EXPECT_THAT(GetAndResetEvents(),
636 ElementsAre(SELECTION_ESTABLISHED, INSERTION_HANDLE_SHOWN));
637
638 OnDoubleTapEvent();
639 ChangeSelection(start_rect, visible, end_rect, visible);
640 EXPECT_THAT(GetAndResetEvents(),
641 ElementsAre(INSERTION_HANDLE_CLEARED, SELECTION_HANDLES_SHOWN));
642 }
643
608 TEST_F(TouchSelectionControllerTest, SelectionAllowsEmptyUpdateAfterLongPress) { 644 TEST_F(TouchSelectionControllerTest, SelectionAllowsEmptyUpdateAfterLongPress) {
609 gfx::RectF start_rect(5, 5, 0, 10); 645 gfx::RectF start_rect(5, 5, 0, 10);
610 gfx::RectF end_rect(50, 5, 0, 10); 646 gfx::RectF end_rect(50, 5, 0, 10);
611 bool visible = true; 647 bool visible = true;
612 648
613 OnLongPressEvent(); 649 OnLongPressEvent();
614 EXPECT_THAT(GetAndResetEvents(), IsEmpty()); 650 EXPECT_THAT(GetAndResetEvents(), IsEmpty());
615 651
616 // There may be several empty updates after a longpress due to the 652 // There may be several empty updates after a longpress due to the
617 // asynchronous response. These empty updates should not prevent the selection 653 // asynchronous response. These empty updates should not prevent the selection
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after
1063 gfx::RectF start_rect(5, 5, 0, 10); 1099 gfx::RectF start_rect(5, 5, 0, 10);
1064 gfx::RectF end_rect(50, 5, 0, 10); 1100 gfx::RectF end_rect(50, 5, 0, 10);
1065 gfx::PointF inner_point(25, 10); 1101 gfx::PointF inner_point(25, 10);
1066 gfx::PointF outer_point(100, 100); 1102 gfx::PointF outer_point(100, 100);
1067 1103
1068 // Establish a selection without handles from 5 to 50 with height 10. 1104 // Establish a selection without handles from 5 to 50 with height 10.
1069 ChangeSelection(start_rect, visible, end_rect, visible); 1105 ChangeSelection(start_rect, visible, end_rect, visible);
1070 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_ESTABLISHED)); 1106 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_ESTABLISHED));
1071 1107
1072 // A point outside the rect should not be handled. 1108 // A point outside the rect should not be handled.
1073 EXPECT_FALSE(controller().WillHandleTapEvent(outer_point)); 1109 EXPECT_FALSE(controller().WillHandleTapEvent(outer_point, 1));
1074 EXPECT_THAT(GetAndResetEvents(), IsEmpty()); 1110 EXPECT_THAT(GetAndResetEvents(), IsEmpty());
1075 1111
1076 // A point inside the rect should be handled. 1112 // A point inside the rect should be handled.
1077 EXPECT_TRUE(controller().WillHandleTapEvent(inner_point)); 1113 EXPECT_TRUE(controller().WillHandleTapEvent(inner_point, 1));
1078 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_HANDLES_SHOWN)); 1114 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_HANDLES_SHOWN));
1079 } 1115 }
1080 1116
1081 TEST_F(TouchSelectionControllerTest, HandlesShowOnLongPressInsideRect) { 1117 TEST_F(TouchSelectionControllerTest, HandlesShowOnLongPressInsideRect) {
1082 bool visible = false; 1118 bool visible = false;
1083 gfx::RectF start_rect(5, 5, 0, 10); 1119 gfx::RectF start_rect(5, 5, 0, 10);
1084 gfx::RectF end_rect(50, 5, 0, 10); 1120 gfx::RectF end_rect(50, 5, 0, 10);
1085 gfx::PointF inner_point(25, 10); 1121 gfx::PointF inner_point(25, 10);
1086 gfx::PointF outer_point(100, 100); 1122 gfx::PointF outer_point(100, 100);
1087 1123
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
1276 EXPECT_EQ(gfx::RectF(6, 5, 44, 10), controller().GetRectBetweenBounds()); 1312 EXPECT_EQ(gfx::RectF(6, 5, 44, 10), controller().GetRectBetweenBounds());
1277 EXPECT_EQ(GetLastEventBoundsRect(), controller().GetRectBetweenBounds()); 1313 EXPECT_EQ(GetLastEventBoundsRect(), controller().GetRectBetweenBounds());
1278 1314
1279 ClearSelection(); 1315 ClearSelection();
1280 ASSERT_THAT(GetAndResetEvents(), 1316 ASSERT_THAT(GetAndResetEvents(),
1281 ElementsAre(SELECTION_DISSOLVED, SELECTION_HANDLES_CLEARED)); 1317 ElementsAre(SELECTION_DISSOLVED, SELECTION_HANDLES_CLEARED));
1282 EXPECT_EQ(gfx::RectF(), controller().GetRectBetweenBounds()); 1318 EXPECT_EQ(gfx::RectF(), controller().GetRectBetweenBounds());
1283 } 1319 }
1284 1320
1285 } // namespace ui 1321 } // 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