OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/memory/scoped_vector.h" | 6 #include "base/memory/scoped_vector.h" |
7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
9 #include "base/timer/timer.h" | 9 #include "base/timer/timer.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 swipe_left_(false), | 86 swipe_left_(false), |
87 swipe_right_(false), | 87 swipe_right_(false), |
88 swipe_up_(false), | 88 swipe_up_(false), |
89 swipe_down_(false), | 89 swipe_down_(false), |
90 scroll_x_(0), | 90 scroll_x_(0), |
91 scroll_y_(0), | 91 scroll_y_(0), |
92 scroll_velocity_x_(0), | 92 scroll_velocity_x_(0), |
93 scroll_velocity_y_(0), | 93 scroll_velocity_y_(0), |
94 velocity_x_(0), | 94 velocity_x_(0), |
95 velocity_y_(0), | 95 velocity_y_(0), |
96 scroll_x_ordinal_(0), | |
97 scroll_y_ordinal_(0), | |
98 scroll_velocity_x_ordinal_(0), | |
99 scroll_velocity_y_ordinal_(0), | |
100 velocity_x_ordinal_(0), | |
101 velocity_y_ordinal_(0), | |
102 scroll_x_hint_(0), | 96 scroll_x_hint_(0), |
103 scroll_y_hint_(0), | 97 scroll_y_hint_(0), |
104 tap_count_(0), | 98 tap_count_(0), |
105 wait_until_event_(ui::ET_UNKNOWN) { | 99 wait_until_event_(ui::ET_UNKNOWN) { |
106 } | 100 } |
107 | 101 |
108 virtual ~GestureEventConsumeDelegate() {} | 102 virtual ~GestureEventConsumeDelegate() {} |
109 | 103 |
110 void Reset() { | 104 void Reset() { |
111 events_.clear(); | 105 events_.clear(); |
(...skipping 20 matching lines...) Expand all Loading... |
132 scroll_begin_position_.SetPoint(0, 0); | 126 scroll_begin_position_.SetPoint(0, 0); |
133 tap_location_.SetPoint(0, 0); | 127 tap_location_.SetPoint(0, 0); |
134 gesture_end_location_.SetPoint(0, 0); | 128 gesture_end_location_.SetPoint(0, 0); |
135 | 129 |
136 scroll_x_ = 0; | 130 scroll_x_ = 0; |
137 scroll_y_ = 0; | 131 scroll_y_ = 0; |
138 scroll_velocity_x_ = 0; | 132 scroll_velocity_x_ = 0; |
139 scroll_velocity_y_ = 0; | 133 scroll_velocity_y_ = 0; |
140 velocity_x_ = 0; | 134 velocity_x_ = 0; |
141 velocity_y_ = 0; | 135 velocity_y_ = 0; |
142 scroll_x_ordinal_ = 0; | |
143 scroll_y_ordinal_ = 0; | |
144 scroll_velocity_x_ordinal_ = 0; | |
145 scroll_velocity_y_ordinal_ = 0; | |
146 velocity_x_ordinal_ = 0; | |
147 velocity_y_ordinal_ = 0; | |
148 scroll_x_hint_ = 0; | 136 scroll_x_hint_ = 0; |
149 scroll_y_hint_ = 0; | 137 scroll_y_hint_ = 0; |
150 tap_count_ = 0; | 138 tap_count_ = 0; |
151 scale_ = 0; | 139 scale_ = 0; |
152 } | 140 } |
153 | 141 |
154 const std::vector<ui::EventType>& events() const { return events_; }; | 142 const std::vector<ui::EventType>& events() const { return events_; }; |
155 | 143 |
156 bool tap() const { return tap_; } | 144 bool tap() const { return tap_; } |
157 bool tap_down() const { return tap_down_; } | 145 bool tap_down() const { return tap_down_; } |
(...skipping 27 matching lines...) Expand all Loading... |
185 const gfx::Point& gesture_end_location() const { | 173 const gfx::Point& gesture_end_location() const { |
186 return gesture_end_location_; | 174 return gesture_end_location_; |
187 } | 175 } |
188 | 176 |
189 float scroll_x() const { return scroll_x_; } | 177 float scroll_x() const { return scroll_x_; } |
190 float scroll_y() const { return scroll_y_; } | 178 float scroll_y() const { return scroll_y_; } |
191 float scroll_velocity_x() const { return scroll_velocity_x_; } | 179 float scroll_velocity_x() const { return scroll_velocity_x_; } |
192 float scroll_velocity_y() const { return scroll_velocity_y_; } | 180 float scroll_velocity_y() const { return scroll_velocity_y_; } |
193 float velocity_x() const { return velocity_x_; } | 181 float velocity_x() const { return velocity_x_; } |
194 float velocity_y() const { return velocity_y_; } | 182 float velocity_y() const { return velocity_y_; } |
195 float scroll_x_ordinal() const { return scroll_x_ordinal_; } | |
196 float scroll_y_ordinal() const { return scroll_y_ordinal_; } | |
197 float scroll_velocity_x_ordinal() const { return scroll_velocity_x_ordinal_; } | |
198 float scroll_velocity_y_ordinal() const { return scroll_velocity_y_ordinal_; } | |
199 float velocity_x_ordinal() const { return velocity_x_ordinal_; } | |
200 float velocity_y_ordinal() const { return velocity_y_ordinal_; } | |
201 float scroll_x_hint() const { return scroll_x_hint_; } | 183 float scroll_x_hint() const { return scroll_x_hint_; } |
202 float scroll_y_hint() const { return scroll_y_hint_; } | 184 float scroll_y_hint() const { return scroll_y_hint_; } |
203 float scale() const { return scale_; } | 185 float scale() const { return scale_; } |
204 const gfx::Rect& bounding_box() const { return bounding_box_; } | 186 const gfx::Rect& bounding_box() const { return bounding_box_; } |
205 int tap_count() const { return tap_count_; } | 187 int tap_count() const { return tap_count_; } |
206 | 188 |
207 void WaitUntilReceivedGesture(ui::EventType type) { | 189 void WaitUntilReceivedGesture(ui::EventType type) { |
208 wait_until_event_ = type; | 190 wait_until_event_ = type; |
209 run_loop_.reset(new base::RunLoop()); | 191 run_loop_.reset(new base::RunLoop()); |
210 run_loop_->Run(); | 192 run_loop_->Run(); |
(...skipping 24 matching lines...) Expand all Loading... |
235 case ui::ET_GESTURE_SCROLL_BEGIN: | 217 case ui::ET_GESTURE_SCROLL_BEGIN: |
236 scroll_begin_ = true; | 218 scroll_begin_ = true; |
237 scroll_begin_position_ = gesture->location(); | 219 scroll_begin_position_ = gesture->location(); |
238 scroll_x_hint_ = gesture->details().scroll_x_hint(); | 220 scroll_x_hint_ = gesture->details().scroll_x_hint(); |
239 scroll_y_hint_ = gesture->details().scroll_y_hint(); | 221 scroll_y_hint_ = gesture->details().scroll_y_hint(); |
240 break; | 222 break; |
241 case ui::ET_GESTURE_SCROLL_UPDATE: | 223 case ui::ET_GESTURE_SCROLL_UPDATE: |
242 scroll_update_ = true; | 224 scroll_update_ = true; |
243 scroll_x_ += gesture->details().scroll_x(); | 225 scroll_x_ += gesture->details().scroll_x(); |
244 scroll_y_ += gesture->details().scroll_y(); | 226 scroll_y_ += gesture->details().scroll_y(); |
245 scroll_x_ordinal_ += gesture->details().scroll_x_ordinal(); | |
246 scroll_y_ordinal_ += gesture->details().scroll_y_ordinal(); | |
247 break; | 227 break; |
248 case ui::ET_GESTURE_SCROLL_END: | 228 case ui::ET_GESTURE_SCROLL_END: |
249 EXPECT_TRUE(velocity_x_ == 0 && velocity_y_ == 0); | 229 EXPECT_TRUE(velocity_x_ == 0 && velocity_y_ == 0); |
250 scroll_end_ = true; | 230 scroll_end_ = true; |
251 break; | 231 break; |
252 case ui::ET_GESTURE_PINCH_BEGIN: | 232 case ui::ET_GESTURE_PINCH_BEGIN: |
253 pinch_begin_ = true; | 233 pinch_begin_ = true; |
254 break; | 234 break; |
255 case ui::ET_GESTURE_PINCH_UPDATE: | 235 case ui::ET_GESTURE_PINCH_UPDATE: |
256 pinch_update_ = true; | 236 pinch_update_ = true; |
257 scale_ = gesture->details().scale(); | 237 scale_ = gesture->details().scale(); |
258 break; | 238 break; |
259 case ui::ET_GESTURE_PINCH_END: | 239 case ui::ET_GESTURE_PINCH_END: |
260 pinch_end_ = true; | 240 pinch_end_ = true; |
261 break; | 241 break; |
262 case ui::ET_GESTURE_LONG_PRESS: | 242 case ui::ET_GESTURE_LONG_PRESS: |
263 long_press_ = true; | 243 long_press_ = true; |
264 break; | 244 break; |
265 case ui::ET_GESTURE_LONG_TAP: | 245 case ui::ET_GESTURE_LONG_TAP: |
266 long_tap_ = true; | 246 long_tap_ = true; |
267 break; | 247 break; |
268 case ui::ET_SCROLL_FLING_START: | 248 case ui::ET_SCROLL_FLING_START: |
269 EXPECT_TRUE(gesture->details().velocity_x() != 0 || | 249 EXPECT_TRUE(gesture->details().velocity_x() != 0 || |
270 gesture->details().velocity_y() != 0); | 250 gesture->details().velocity_y() != 0); |
271 EXPECT_FALSE(scroll_end_); | 251 EXPECT_FALSE(scroll_end_); |
272 fling_ = true; | 252 fling_ = true; |
273 velocity_x_ = gesture->details().velocity_x(); | 253 velocity_x_ = gesture->details().velocity_x(); |
274 velocity_y_ = gesture->details().velocity_y(); | 254 velocity_y_ = gesture->details().velocity_y(); |
275 velocity_x_ordinal_ = gesture->details().velocity_x_ordinal(); | |
276 velocity_y_ordinal_ = gesture->details().velocity_y_ordinal(); | |
277 break; | 255 break; |
278 case ui::ET_GESTURE_TWO_FINGER_TAP: | 256 case ui::ET_GESTURE_TWO_FINGER_TAP: |
279 two_finger_tap_ = true; | 257 two_finger_tap_ = true; |
280 break; | 258 break; |
281 case ui::ET_GESTURE_SHOW_PRESS: | 259 case ui::ET_GESTURE_SHOW_PRESS: |
282 show_press_ = true; | 260 show_press_ = true; |
283 break; | 261 break; |
284 case ui::ET_GESTURE_MULTIFINGER_SWIPE: | 262 case ui::ET_GESTURE_MULTIFINGER_SWIPE: |
285 swipe_left_ = gesture->details().swipe_left(); | 263 swipe_left_ = gesture->details().swipe_left(); |
286 swipe_right_ = gesture->details().swipe_right(); | 264 swipe_right_ = gesture->details().swipe_right(); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 gfx::Point scroll_begin_position_; | 303 gfx::Point scroll_begin_position_; |
326 gfx::Point tap_location_; | 304 gfx::Point tap_location_; |
327 gfx::Point gesture_end_location_; | 305 gfx::Point gesture_end_location_; |
328 | 306 |
329 float scroll_x_; | 307 float scroll_x_; |
330 float scroll_y_; | 308 float scroll_y_; |
331 float scroll_velocity_x_; | 309 float scroll_velocity_x_; |
332 float scroll_velocity_y_; | 310 float scroll_velocity_y_; |
333 float velocity_x_; | 311 float velocity_x_; |
334 float velocity_y_; | 312 float velocity_y_; |
335 float scroll_x_ordinal_; | |
336 float scroll_y_ordinal_; | |
337 float scroll_velocity_x_ordinal_; | |
338 float scroll_velocity_y_ordinal_; | |
339 float velocity_x_ordinal_; | |
340 float velocity_y_ordinal_; | |
341 float scroll_x_hint_; | 313 float scroll_x_hint_; |
342 float scroll_y_hint_; | 314 float scroll_y_hint_; |
343 float scale_; | 315 float scale_; |
344 gfx::Rect bounding_box_; | 316 gfx::Rect bounding_box_; |
345 int tap_count_; | 317 int tap_count_; |
346 | 318 |
347 ui::EventType wait_until_event_; | 319 ui::EventType wait_until_event_; |
348 | 320 |
349 DISALLOW_COPY_AND_ASSIGN(GestureEventConsumeDelegate); | 321 DISALLOW_COPY_AND_ASSIGN(GestureEventConsumeDelegate); |
350 }; | 322 }; |
(...skipping 867 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1218 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(5, 0), | 1190 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(5, 0), |
1219 kTouchId, tes.Now()); | 1191 kTouchId, tes.Now()); |
1220 DispatchEventUsingWindowDispatcher(&move); | 1192 DispatchEventUsingWindowDispatcher(&move); |
1221 delegate->Reset(); | 1193 delegate->Reset(); |
1222 | 1194 |
1223 | 1195 |
1224 // Move the touch-point horizontally enough that it is considered a | 1196 // Move the touch-point horizontally enough that it is considered a |
1225 // horizontal scroll. | 1197 // horizontal scroll. |
1226 tes.SendScrollEvent(event_processor(), 25, 1, kTouchId, delegate.get()); | 1198 tes.SendScrollEvent(event_processor(), 25, 1, kTouchId, delegate.get()); |
1227 EXPECT_EQ(0, delegate->scroll_y()); | 1199 EXPECT_EQ(0, delegate->scroll_y()); |
1228 EXPECT_EQ(1, delegate->scroll_y_ordinal()); | |
1229 EXPECT_EQ(20, delegate->scroll_x()); | 1200 EXPECT_EQ(20, delegate->scroll_x()); |
1230 EXPECT_EQ(20, delegate->scroll_x_ordinal()); | |
1231 | 1201 |
1232 // Get a high x velocity, while still staying on the rail | 1202 // Get a high x velocity, while still staying on the rail |
1233 tes.SendScrollEvents(event_processor(), 1, 1, | 1203 tes.SendScrollEvents(event_processor(), 1, 1, |
1234 100, 10, kTouchId, 1, | 1204 100, 10, kTouchId, 1, |
1235 ui::GestureConfiguration::points_buffered_for_velocity(), | 1205 ui::GestureConfiguration::points_buffered_for_velocity(), |
1236 delegate.get()); | 1206 delegate.get()); |
1237 | 1207 |
1238 delegate->Reset(); | 1208 delegate->Reset(); |
1239 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), | 1209 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), |
1240 kTouchId, tes.Now()); | 1210 kTouchId, tes.Now()); |
(...skipping 23 matching lines...) Expand all Loading... |
1264 // Get rid of touch slop. | 1234 // Get rid of touch slop. |
1265 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(0, 5), | 1235 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(0, 5), |
1266 kTouchId, tes.Now()); | 1236 kTouchId, tes.Now()); |
1267 DispatchEventUsingWindowDispatcher(&move); | 1237 DispatchEventUsingWindowDispatcher(&move); |
1268 delegate->Reset(); | 1238 delegate->Reset(); |
1269 | 1239 |
1270 // Move the touch-point vertically enough that it is considered a | 1240 // Move the touch-point vertically enough that it is considered a |
1271 // vertical scroll. | 1241 // vertical scroll. |
1272 tes.SendScrollEvent(event_processor(), 1, 25, kTouchId, delegate.get()); | 1242 tes.SendScrollEvent(event_processor(), 1, 25, kTouchId, delegate.get()); |
1273 EXPECT_EQ(20, delegate->scroll_y()); | 1243 EXPECT_EQ(20, delegate->scroll_y()); |
1274 EXPECT_EQ(20, delegate->scroll_y_ordinal()); | |
1275 EXPECT_EQ(0, delegate->scroll_x()); | 1244 EXPECT_EQ(0, delegate->scroll_x()); |
1276 EXPECT_EQ(1, delegate->scroll_x_ordinal()); | |
1277 EXPECT_EQ(0, delegate->scroll_velocity_x()); | 1245 EXPECT_EQ(0, delegate->scroll_velocity_x()); |
1278 | 1246 |
1279 // Get a high y velocity, while still staying on the rail | 1247 // Get a high y velocity, while still staying on the rail |
1280 tes.SendScrollEvents(event_processor(), 1, 6, | 1248 tes.SendScrollEvents(event_processor(), 1, 6, |
1281 10, 100, kTouchId, 1, | 1249 10, 100, kTouchId, 1, |
1282 ui::GestureConfiguration::points_buffered_for_velocity(), | 1250 ui::GestureConfiguration::points_buffered_for_velocity(), |
1283 delegate.get()); | 1251 delegate.get()); |
1284 EXPECT_EQ(0, delegate->scroll_velocity_x()); | 1252 EXPECT_EQ(0, delegate->scroll_velocity_x()); |
1285 | 1253 |
1286 delegate->Reset(); | 1254 delegate->Reset(); |
(...skipping 2863 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4150 EXPECT_FALSE(delegate->scroll_end()); | 4118 EXPECT_FALSE(delegate->scroll_end()); |
4151 EXPECT_FALSE(delegate->pinch_begin()); | 4119 EXPECT_FALSE(delegate->pinch_begin()); |
4152 EXPECT_FALSE(delegate->pinch_update()); | 4120 EXPECT_FALSE(delegate->pinch_update()); |
4153 EXPECT_FALSE(delegate->pinch_end()); | 4121 EXPECT_FALSE(delegate->pinch_end()); |
4154 delegate->Reset(); | 4122 delegate->Reset(); |
4155 } | 4123 } |
4156 } | 4124 } |
4157 | 4125 |
4158 } // namespace test | 4126 } // namespace test |
4159 } // namespace aura | 4127 } // namespace aura |
OLD | NEW |