OLD | NEW |
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 18 matching lines...) Expand all Loading... |
29 void SetOrientation(TouchHandleOrientation orientation) override {} | 29 void SetOrientation(TouchHandleOrientation orientation) override {} |
30 void SetAlpha(float alpha) override {} | 30 void SetAlpha(float alpha) override {} |
31 void SetFocus(const gfx::PointF& position) override {} | 31 void SetFocus(const gfx::PointF& position) override {} |
32 gfx::RectF GetVisibleBounds() const override { | 32 gfx::RectF GetVisibleBounds() const override { |
33 return *intersects_rect_ ? gfx::RectF(-1000, -1000, 2000, 2000) | 33 return *intersects_rect_ ? gfx::RectF(-1000, -1000, 2000, 2000) |
34 : gfx::RectF(-1000, -1000, 0, 0); | 34 : gfx::RectF(-1000, -1000, 0, 0); |
35 } | 35 } |
36 | 36 |
37 private: | 37 private: |
38 bool* intersects_rect_; | 38 bool* intersects_rect_; |
| 39 |
| 40 DISALLOW_COPY_AND_ASSIGN(MockTouchHandleDrawable); |
39 }; | 41 }; |
40 | 42 |
41 } // namespace | 43 } // namespace |
42 | 44 |
43 class TouchSelectionControllerTest : public testing::Test, | 45 class TouchSelectionControllerTest : public testing::Test, |
44 public TouchSelectionControllerClient { | 46 public TouchSelectionControllerClient { |
45 public: | 47 public: |
46 TouchSelectionControllerTest() | 48 TouchSelectionControllerTest() |
47 : caret_moved_(false), | 49 : caret_moved_(false), |
48 selection_moved_(false), | 50 selection_moved_(false), |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 gfx::PointF selection_start_; | 200 gfx::PointF selection_start_; |
199 gfx::PointF selection_end_; | 201 gfx::PointF selection_end_; |
200 std::vector<SelectionEventType> events_; | 202 std::vector<SelectionEventType> events_; |
201 bool caret_moved_; | 203 bool caret_moved_; |
202 bool selection_moved_; | 204 bool selection_moved_; |
203 bool selection_points_swapped_; | 205 bool selection_points_swapped_; |
204 bool needs_animate_; | 206 bool needs_animate_; |
205 bool animation_enabled_; | 207 bool animation_enabled_; |
206 bool dragging_enabled_; | 208 bool dragging_enabled_; |
207 scoped_ptr<TouchSelectionController> controller_; | 209 scoped_ptr<TouchSelectionController> controller_; |
| 210 |
| 211 DISALLOW_COPY_AND_ASSIGN(TouchSelectionControllerTest); |
208 }; | 212 }; |
209 | 213 |
210 TEST_F(TouchSelectionControllerTest, InsertionBasic) { | 214 TEST_F(TouchSelectionControllerTest, InsertionBasic) { |
211 gfx::RectF insertion_rect(5, 5, 0, 10); | 215 gfx::RectF insertion_rect(5, 5, 0, 10); |
212 bool visible = true; | 216 bool visible = true; |
213 | 217 |
214 // Insertion events are ignored until automatic showing is enabled. | 218 // Insertion events are ignored until automatic showing is enabled. |
215 ChangeInsertion(insertion_rect, visible); | 219 ChangeInsertion(insertion_rect, visible); |
216 EXPECT_THAT(GetAndResetEvents(), IsEmpty()); | 220 EXPECT_THAT(GetAndResetEvents(), IsEmpty()); |
217 EXPECT_EQ(gfx::PointF(), GetLastEventStart()); | 221 EXPECT_EQ(gfx::PointF(), GetLastEventStart()); |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 controller().OnSelectionEditable(true); | 430 controller().OnSelectionEditable(true); |
427 SetDraggingEnabled(true); | 431 SetDraggingEnabled(true); |
428 | 432 |
429 gfx::RectF start_rect(10, 0, 0, 10); | 433 gfx::RectF start_rect(10, 0, 0, 10); |
430 bool visible = true; | 434 bool visible = true; |
431 ChangeInsertion(start_rect, visible); | 435 ChangeInsertion(start_rect, visible); |
432 EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_SHOWN)); | 436 EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_SHOWN)); |
433 | 437 |
434 MockMotionEvent event(MockMotionEvent::ACTION_DOWN, event_time, 0, 0); | 438 MockMotionEvent event(MockMotionEvent::ACTION_DOWN, event_time, 0, 0); |
435 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 439 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
436 //TODO(AKV): this test case has to be modified once crbug.com/394093 is fixed. | |
437 EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_DRAG_STARTED)); | 440 EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_DRAG_STARTED)); |
438 | 441 |
439 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 0, 0); | 442 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 0, 0); |
440 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 443 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
441 EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_TAPPED, | 444 EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_TAPPED, |
442 INSERTION_DRAG_STOPPED)); | 445 INSERTION_DRAG_STOPPED)); |
443 | 446 |
444 // Reset the insertion. | 447 // Reset the insertion. |
445 ClearInsertion(); | 448 ClearInsertion(); |
446 controller().OnTapEvent(); | 449 controller().OnTapEvent(); |
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
964 controller().OnSelectionEmpty(false); | 967 controller().OnSelectionEmpty(false); |
965 controller().HideAndDisallowShowingAutomatically(); | 968 controller().HideAndDisallowShowingAutomatically(); |
966 gfx::RectF insertion_rect(5, 5, 0, 10); | 969 gfx::RectF insertion_rect(5, 5, 0, 10); |
967 ChangeInsertion(insertion_rect, visible); | 970 ChangeInsertion(insertion_rect, visible); |
968 controller().AllowShowingFromCurrentSelection(); | 971 controller().AllowShowingFromCurrentSelection(); |
969 EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_SHOWN)); | 972 EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_SHOWN)); |
970 EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventStart()); | 973 EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventStart()); |
971 } | 974 } |
972 | 975 |
973 } // namespace ui | 976 } // namespace ui |
OLD | NEW |