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

Side by Side Diff: ui/events/gesture_detection/snap_scroll_controller_unittest.cc

Issue 1049383003: Postpone rail application for touch scrolling - chrome side. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 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 "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "testing/gtest/include/gtest/gtest.h" 6 #include "testing/gtest/include/gtest/gtest.h"
7 #include "ui/events/gesture_detection/snap_scroll_controller.h" 7 #include "ui/events/gesture_detection/snap_scroll_controller.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 base::TimeDelta; 10 using base::TimeDelta;
11 using base::TimeTicks; 11 using base::TimeTicks;
12 using ui::test::MockMotionEvent; 12 using ui::test::MockMotionEvent;
13 13
14 namespace ui { 14 namespace ui {
15 namespace { 15 namespace {
16 16
17 const float kSnapBound = 8.f; 17 const float kSnapBound = 8.f;
18 const GestureEventDetails::ScrollRailState kFree =
19 GestureEventDetails::ScrollRailState::Free;
20 const GestureEventDetails::ScrollRailState kHorizontal =
21 GestureEventDetails::ScrollRailState::Horizontal;
22 const GestureEventDetails::ScrollRailState kVertical =
23 GestureEventDetails::ScrollRailState::Vertical;
18 24
19 gfx::SizeF GetDisplayBounds() { 25 gfx::SizeF GetDisplayBounds() {
20 return gfx::SizeF(640, 480); 26 return gfx::SizeF(640, 480);
21 } 27 }
22 28
23 } // namespace 29 } // namespace
24 30
25 TEST(SnapScrollControllerTest, Basic) { 31 TEST(SnapScrollControllerTest, Basic) {
26 SnapScrollController controller(kSnapBound, GetDisplayBounds()); 32 SnapScrollController controller(kSnapBound, GetDisplayBounds());
27 EXPECT_FALSE(controller.IsSnappingScrolls()); 33 EXPECT_EQ(kFree, controller.ScrollRailState());
28 EXPECT_FALSE(controller.IsSnapHorizontal());
29 EXPECT_FALSE(controller.IsSnapVertical());
30 34
31 // Test basic horizontal snapping. 35 // Test basic horizontal snapping.
32 MockMotionEvent event; 36 MockMotionEvent event;
33 event.PressPoint(0, 0); 37 event.PressPoint(0, 0);
34 controller.SetSnapScrollMode(event, false); 38 controller.SetSnapScrollMode(event, false);
35 EXPECT_FALSE(controller.IsSnappingScrolls()); 39 EXPECT_EQ(kFree, controller.ScrollRailState());
36 40
37 event.MovePoint(0, kSnapBound * 2, 0.f); 41 event.MovePoint(0, kSnapBound * 2, 0.f);
38 controller.SetSnapScrollMode(event, false); 42 controller.SetSnapScrollMode(event, false);
39 EXPECT_TRUE(controller.IsSnappingScrolls()); 43 EXPECT_EQ(kHorizontal, controller.ScrollRailState());
40 EXPECT_TRUE(controller.IsSnapHorizontal());
41 EXPECT_FALSE(controller.IsSnapVertical());
42 44
43 event.ReleasePoint(); 45 event.ReleasePoint();
44 controller.SetSnapScrollMode(event, false); 46 controller.SetSnapScrollMode(event, false);
45 47
46 // Test basic vertical snapping. 48 // Test basic vertical snapping.
47 event.PressPoint(0, 0); 49 event.PressPoint(0, 0);
48 controller.SetSnapScrollMode(event, false); 50 controller.SetSnapScrollMode(event, false);
49 EXPECT_FALSE(controller.IsSnappingScrolls()); 51 EXPECT_EQ(kFree, controller.ScrollRailState());
50 52
51 event.MovePoint(0, 0.f, kSnapBound * 2); 53 event.MovePoint(0, 0.f, kSnapBound * 2);
52 controller.SetSnapScrollMode(event, false); 54 controller.SetSnapScrollMode(event, false);
53 EXPECT_TRUE(controller.IsSnappingScrolls()); 55 EXPECT_EQ(kVertical, controller.ScrollRailState());
54 EXPECT_TRUE(controller.IsSnapVertical());
55 EXPECT_FALSE(controller.IsSnapHorizontal());
56 } 56 }
57 57
58 TEST(SnapScrollControllerTest, VerticalScroll) { 58 TEST(SnapScrollControllerTest, VerticalScroll) {
59 SnapScrollController controller(kSnapBound, GetDisplayBounds()); 59 SnapScrollController controller(kSnapBound, GetDisplayBounds());
60 EXPECT_FALSE(controller.IsSnappingScrolls()); 60 EXPECT_EQ(kFree, controller.ScrollRailState());
61 61
62 MockMotionEvent event; 62 MockMotionEvent event;
63 event.PressPoint(0, 0); 63 event.PressPoint(0, 0);
64 controller.SetSnapScrollMode(event, false); 64 controller.SetSnapScrollMode(event, false);
65 EXPECT_FALSE(controller.IsSnappingScrolls()); 65 EXPECT_EQ(kFree, controller.ScrollRailState());
66 66
67 event.MovePoint(0, 0.f, -kSnapBound / 2.f); 67 event.MovePoint(0, 0.f, -kSnapBound / 2.f);
68 controller.SetSnapScrollMode(event, false); 68 controller.SetSnapScrollMode(event, false);
69 EXPECT_FALSE(controller.IsSnappingScrolls()); 69 EXPECT_EQ(kFree, controller.ScrollRailState());
70 70
71 event.MovePoint(0, kSnapBound / 2.f, -kSnapBound * 2.f); 71 event.MovePoint(0, kSnapBound / 2.f, -kSnapBound * 2.f);
72 controller.SetSnapScrollMode(event, false); 72 controller.SetSnapScrollMode(event, false);
73 EXPECT_TRUE(controller.IsSnapVertical()); 73 EXPECT_EQ(kVertical, controller.ScrollRailState());
74 EXPECT_FALSE(controller.IsSnapHorizontal());
75 74
76 // Initial scrolling should be snapped. 75 // Initial scrolling should be snapped.
77 float delta_x = event.GetX(0); 76 float delta_x = event.GetX(0);
78 float delta_y = event.GetY(0); 77 float delta_y = event.GetY(0);
79 controller.UpdateSnapScrollMode(delta_x, delta_y); 78 controller.UpdateSnapScrollMode(delta_x, delta_y);
80 EXPECT_TRUE(controller.IsSnapVertical()); 79 EXPECT_EQ(kVertical, controller.ScrollRailState());
81 EXPECT_FALSE(controller.IsSnapHorizontal());
82 80
83 // Subsequent scrolling should be snapped as long as it's within the rails. 81 // Subsequent scrolling should be snapped as long as it's within the rails.
84 delta_x = 5; 82 delta_x = 5;
85 delta_y = 10; 83 delta_y = 10;
86 controller.UpdateSnapScrollMode(delta_x, delta_y); 84 controller.UpdateSnapScrollMode(delta_x, delta_y);
87 EXPECT_TRUE(controller.IsSnapVertical()); 85 EXPECT_EQ(kVertical, controller.ScrollRailState());
88 EXPECT_FALSE(controller.IsSnapHorizontal());
89 86
90 // Large horizontal movement should end snapping. 87 // Large horizontal movement should end snapping.
91 delta_x = 100; 88 delta_x = 100;
92 delta_y = 10; 89 delta_y = 10;
93 controller.UpdateSnapScrollMode(delta_x, delta_y); 90 controller.UpdateSnapScrollMode(delta_x, delta_y);
94 EXPECT_FALSE(controller.IsSnappingScrolls()); 91 EXPECT_EQ(kFree, controller.ScrollRailState());
95 } 92 }
96 93
97 TEST(SnapScrollControllerTest, HorizontalScroll) { 94 TEST(SnapScrollControllerTest, HorizontalScroll) {
98 SnapScrollController controller(kSnapBound, GetDisplayBounds()); 95 SnapScrollController controller(kSnapBound, GetDisplayBounds());
99 EXPECT_FALSE(controller.IsSnappingScrolls()); 96 EXPECT_EQ(kFree, controller.ScrollRailState());
100 97
101 MockMotionEvent event; 98 MockMotionEvent event;
102 event.PressPoint(0, 0); 99 event.PressPoint(0, 0);
103 controller.SetSnapScrollMode(event, false); 100 controller.SetSnapScrollMode(event, false);
104 EXPECT_FALSE(controller.IsSnappingScrolls()); 101 EXPECT_EQ(kFree, controller.ScrollRailState());
105 102
106 event.MovePoint(0, -kSnapBound / 2.f, 0.f); 103 event.MovePoint(0, -kSnapBound / 2.f, 0.f);
107 controller.SetSnapScrollMode(event, false); 104 controller.SetSnapScrollMode(event, false);
108 EXPECT_FALSE(controller.IsSnappingScrolls()); 105 EXPECT_EQ(kFree, controller.ScrollRailState());
109 106
110 event.MovePoint(0, kSnapBound * 2.f, kSnapBound / 2.f); 107 event.MovePoint(0, kSnapBound * 2.f, kSnapBound / 2.f);
111 controller.SetSnapScrollMode(event, false); 108 controller.SetSnapScrollMode(event, false);
112 EXPECT_TRUE(controller.IsSnapHorizontal()); 109 EXPECT_EQ(kHorizontal, controller.ScrollRailState());
113 EXPECT_FALSE(controller.IsSnapVertical());
114 110
115 // Initial scrolling should be snapped. 111 // Initial scrolling should be snapped.
116 float delta_x = event.GetX(0); 112 float delta_x = event.GetX(0);
117 float delta_y = event.GetY(0); 113 float delta_y = event.GetY(0);
118 controller.UpdateSnapScrollMode(delta_x, delta_y); 114 controller.UpdateSnapScrollMode(delta_x, delta_y);
119 EXPECT_TRUE(controller.IsSnapHorizontal()); 115 EXPECT_EQ(kHorizontal, controller.ScrollRailState());
120 EXPECT_FALSE(controller.IsSnapVertical());
121 116
122 // Subsequent scrolling should be snapped as long as it's within the rails. 117 // Subsequent scrolling should be snapped as long as it's within the rails.
123 delta_x = 10; 118 delta_x = 10;
124 delta_y = 5; 119 delta_y = 5;
125 controller.UpdateSnapScrollMode(delta_x, delta_y); 120 controller.UpdateSnapScrollMode(delta_x, delta_y);
126 EXPECT_TRUE(controller.IsSnapHorizontal()); 121 EXPECT_EQ(kHorizontal, controller.ScrollRailState());
127 EXPECT_FALSE(controller.IsSnapVertical());
128 122
129 // Large vertical movement should end snapping. 123 // Large vertical movement should end snapping.
130 delta_x = 10; 124 delta_x = 10;
131 delta_y = 100; 125 delta_y = 100;
132 controller.UpdateSnapScrollMode(delta_x, delta_y); 126 controller.UpdateSnapScrollMode(delta_x, delta_y);
133 EXPECT_FALSE(controller.IsSnappingScrolls()); 127 EXPECT_EQ(kFree, controller.ScrollRailState());
134 } 128 }
135 129
136 TEST(SnapScrollControllerTest, Diagonal) { 130 TEST(SnapScrollControllerTest, Diagonal) {
137 SnapScrollController controller(kSnapBound, GetDisplayBounds()); 131 SnapScrollController controller(kSnapBound, GetDisplayBounds());
138 EXPECT_FALSE(controller.IsSnappingScrolls()); 132 EXPECT_EQ(kFree, controller.ScrollRailState());
139 133
140 MockMotionEvent event; 134 MockMotionEvent event;
141 event.PressPoint(0, 0); 135 event.PressPoint(0, 0);
142 controller.SetSnapScrollMode(event, false); 136 controller.SetSnapScrollMode(event, false);
143 EXPECT_FALSE(controller.IsSnappingScrolls()); 137 EXPECT_EQ(kFree, controller.ScrollRailState());
144 138
145 // Sufficient initial diagonal motion will prevent any future snapping. 139 // Sufficient initial diagonal motion will prevent any future snapping.
146 event.MovePoint(0, kSnapBound * 3.f, -kSnapBound * 3.f); 140 event.MovePoint(0, kSnapBound * 3.f, -kSnapBound * 3.f);
147 controller.SetSnapScrollMode(event, false); 141 controller.SetSnapScrollMode(event, false);
148 EXPECT_FALSE(controller.IsSnappingScrolls()); 142 EXPECT_EQ(kFree, controller.ScrollRailState());
149 143
150 float delta_x = event.GetX(0); 144 float delta_x = event.GetX(0);
151 float delta_y = event.GetY(0); 145 float delta_y = event.GetY(0);
152 controller.UpdateSnapScrollMode(delta_x, delta_y); 146 controller.UpdateSnapScrollMode(delta_x, delta_y);
153 EXPECT_FALSE(controller.IsSnappingScrolls()); 147 EXPECT_EQ(kFree, controller.ScrollRailState());
154 148
155 event.MovePoint(0, 0, 0); 149 event.MovePoint(0, 0, 0);
156 controller.SetSnapScrollMode(event, false); 150 controller.SetSnapScrollMode(event, false);
157 EXPECT_FALSE(controller.IsSnappingScrolls()); 151 EXPECT_EQ(kFree, controller.ScrollRailState());
158 152
159 event.MovePoint(0, kSnapBound * 5, 0); 153 event.MovePoint(0, kSnapBound * 5, 0);
160 controller.SetSnapScrollMode(event, false); 154 controller.SetSnapScrollMode(event, false);
161 EXPECT_FALSE(controller.IsSnappingScrolls()); 155 EXPECT_EQ(kFree, controller.ScrollRailState());
162 156
163 event.MovePoint(0, 0, -kSnapBound * 5); 157 event.MovePoint(0, 0, -kSnapBound * 5);
164 controller.SetSnapScrollMode(event, false); 158 controller.SetSnapScrollMode(event, false);
165 EXPECT_FALSE(controller.IsSnappingScrolls()); 159 EXPECT_EQ(kFree, controller.ScrollRailState());
166 } 160 }
167 161
168 } // namespace ui 162 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698