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_handle.h" | 5 #include "ui/touch_selection/touch_handle.h" |
6 | 6 |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 #include "ui/events/test/motion_event_test_utils.h" | 8 #include "ui/events/test/motion_event_test_utils.h" |
9 #include "ui/gfx/geometry/rect_f.h" | 9 #include "ui/gfx/geometry/rect_f.h" |
| 10 #include "ui/touch_selection/touch_handle_orientation.h" |
10 | 11 |
11 using ui::test::MockMotionEvent; | 12 using ui::test::MockMotionEvent; |
12 | 13 |
13 namespace ui { | 14 namespace ui { |
14 namespace { | 15 namespace { |
15 | 16 |
16 const int kDefaultTapTimeoutMs = 200; | 17 const int kDefaultTapTimeoutMs = 200; |
17 const float kDefaultTapSlop = 10.f; | 18 const float kDefaultTapSlop = 10.f; |
18 const float kDefaultDrawableSize = 10.f; | 19 const float kDefaultDrawableSize = 10.f; |
19 | 20 |
20 struct MockDrawableData { | 21 struct MockDrawableData { |
21 MockDrawableData() | 22 MockDrawableData() |
22 : orientation(TOUCH_HANDLE_ORIENTATION_UNDEFINED), | 23 : orientation(TouchHandleOrientation::UNDEFINED), |
23 alpha(0.f), | 24 alpha(0.f), |
24 enabled(false), | 25 enabled(false), |
25 visible(false), | 26 visible(false), |
26 rect(0, 0, kDefaultDrawableSize, kDefaultDrawableSize) {} | 27 rect(0, 0, kDefaultDrawableSize, kDefaultDrawableSize) {} |
27 TouchHandleOrientation orientation; | 28 TouchHandleOrientation orientation; |
28 float alpha; | 29 float alpha; |
29 bool enabled; | 30 bool enabled; |
30 bool visible; | 31 bool visible; |
31 gfx::RectF rect; | 32 gfx::RectF rect; |
32 }; | 33 }; |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 gfx::PointF drag_position_; | 137 gfx::PointF drag_position_; |
137 bool dragging_; | 138 bool dragging_; |
138 bool dragged_; | 139 bool dragged_; |
139 bool tapped_; | 140 bool tapped_; |
140 bool needs_animate_; | 141 bool needs_animate_; |
141 | 142 |
142 MockDrawableData drawable_data_; | 143 MockDrawableData drawable_data_; |
143 }; | 144 }; |
144 | 145 |
145 TEST_F(TouchHandleTest, Visibility) { | 146 TEST_F(TouchHandleTest, Visibility) { |
146 TouchHandle handle(this, TOUCH_HANDLE_CENTER); | 147 TouchHandle handle(this, TouchHandleOrientation::CENTER); |
147 EXPECT_FALSE(drawable().visible); | 148 EXPECT_FALSE(drawable().visible); |
148 | 149 |
149 handle.SetVisible(true, TouchHandle::ANIMATION_NONE); | 150 handle.SetVisible(true, TouchHandle::ANIMATION_NONE); |
150 EXPECT_TRUE(drawable().visible); | 151 EXPECT_TRUE(drawable().visible); |
151 EXPECT_EQ(1.f, drawable().alpha); | 152 EXPECT_EQ(1.f, drawable().alpha); |
152 | 153 |
153 handle.SetVisible(false, TouchHandle::ANIMATION_NONE); | 154 handle.SetVisible(false, TouchHandle::ANIMATION_NONE); |
154 EXPECT_FALSE(drawable().visible); | 155 EXPECT_FALSE(drawable().visible); |
155 | 156 |
156 handle.SetVisible(true, TouchHandle::ANIMATION_NONE); | 157 handle.SetVisible(true, TouchHandle::ANIMATION_NONE); |
157 EXPECT_TRUE(drawable().visible); | 158 EXPECT_TRUE(drawable().visible); |
158 EXPECT_EQ(1.f, drawable().alpha); | 159 EXPECT_EQ(1.f, drawable().alpha); |
159 } | 160 } |
160 | 161 |
161 TEST_F(TouchHandleTest, VisibilityAnimation) { | 162 TEST_F(TouchHandleTest, VisibilityAnimation) { |
162 TouchHandle handle(this, TOUCH_HANDLE_CENTER); | 163 TouchHandle handle(this, TouchHandleOrientation::CENTER); |
163 ASSERT_FALSE(NeedsAnimate()); | 164 ASSERT_FALSE(NeedsAnimate()); |
164 ASSERT_FALSE(drawable().visible); | 165 ASSERT_FALSE(drawable().visible); |
165 ASSERT_EQ(0.f, drawable().alpha); | 166 ASSERT_EQ(0.f, drawable().alpha); |
166 | 167 |
167 handle.SetVisible(true, TouchHandle::ANIMATION_SMOOTH); | 168 handle.SetVisible(true, TouchHandle::ANIMATION_SMOOTH); |
168 EXPECT_TRUE(NeedsAnimate()); | 169 EXPECT_TRUE(NeedsAnimate()); |
169 EXPECT_FALSE(drawable().visible); | 170 EXPECT_FALSE(drawable().visible); |
170 EXPECT_EQ(0.f, drawable().alpha); | 171 EXPECT_EQ(0.f, drawable().alpha); |
171 | 172 |
172 Animate(handle); | 173 Animate(handle); |
(...skipping 15 matching lines...) Expand all Loading... |
188 EXPECT_FALSE(GetAndResetNeedsAnimate()); | 189 EXPECT_FALSE(GetAndResetNeedsAnimate()); |
189 handle.SetVisible(false, TouchHandle::ANIMATION_SMOOTH); | 190 handle.SetVisible(false, TouchHandle::ANIMATION_SMOOTH); |
190 EXPECT_EQ(1.f, drawable().alpha); | 191 EXPECT_EQ(1.f, drawable().alpha); |
191 EXPECT_TRUE(GetAndResetNeedsAnimate()); | 192 EXPECT_TRUE(GetAndResetNeedsAnimate()); |
192 handle.SetVisible(true, TouchHandle::ANIMATION_SMOOTH); | 193 handle.SetVisible(true, TouchHandle::ANIMATION_SMOOTH); |
193 EXPECT_EQ(1.f, drawable().alpha); | 194 EXPECT_EQ(1.f, drawable().alpha); |
194 EXPECT_FALSE(GetAndResetNeedsAnimate()); | 195 EXPECT_FALSE(GetAndResetNeedsAnimate()); |
195 } | 196 } |
196 | 197 |
197 TEST_F(TouchHandleTest, Orientation) { | 198 TEST_F(TouchHandleTest, Orientation) { |
198 TouchHandle handle(this, TOUCH_HANDLE_CENTER); | 199 TouchHandle handle(this, TouchHandleOrientation::CENTER); |
199 EXPECT_EQ(TOUCH_HANDLE_CENTER, drawable().orientation); | 200 EXPECT_EQ(TouchHandleOrientation::CENTER, drawable().orientation); |
200 | 201 |
201 handle.SetOrientation(TOUCH_HANDLE_LEFT); | 202 handle.SetOrientation(TouchHandleOrientation::LEFT); |
202 EXPECT_EQ(TOUCH_HANDLE_LEFT, drawable().orientation); | 203 EXPECT_EQ(TouchHandleOrientation::LEFT, drawable().orientation); |
203 | 204 |
204 handle.SetOrientation(TOUCH_HANDLE_RIGHT); | 205 handle.SetOrientation(TouchHandleOrientation::RIGHT); |
205 EXPECT_EQ(TOUCH_HANDLE_RIGHT, drawable().orientation); | 206 EXPECT_EQ(TouchHandleOrientation::RIGHT, drawable().orientation); |
206 | 207 |
207 handle.SetOrientation(TOUCH_HANDLE_CENTER); | 208 handle.SetOrientation(TouchHandleOrientation::CENTER); |
208 EXPECT_EQ(TOUCH_HANDLE_CENTER, drawable().orientation); | 209 EXPECT_EQ(TouchHandleOrientation::CENTER, drawable().orientation); |
209 } | 210 } |
210 | 211 |
211 TEST_F(TouchHandleTest, Position) { | 212 TEST_F(TouchHandleTest, Position) { |
212 TouchHandle handle(this, TOUCH_HANDLE_CENTER); | 213 TouchHandle handle(this, TouchHandleOrientation::CENTER); |
213 handle.SetVisible(true, TouchHandle::ANIMATION_NONE); | 214 handle.SetVisible(true, TouchHandle::ANIMATION_NONE); |
214 | 215 |
215 gfx::PointF position; | 216 gfx::PointF position; |
216 EXPECT_EQ(gfx::PointF(), drawable().rect.origin()); | 217 EXPECT_EQ(gfx::PointF(), drawable().rect.origin()); |
217 | 218 |
218 position = gfx::PointF(7.3f, -3.7f); | 219 position = gfx::PointF(7.3f, -3.7f); |
219 handle.SetPosition(position); | 220 handle.SetPosition(position); |
220 EXPECT_EQ(position, drawable().rect.origin()); | 221 EXPECT_EQ(position, drawable().rect.origin()); |
221 | 222 |
222 position = gfx::PointF(-7.3f, 3.7f); | 223 position = gfx::PointF(-7.3f, 3.7f); |
223 handle.SetPosition(position); | 224 handle.SetPosition(position); |
224 EXPECT_EQ(position, drawable().rect.origin()); | 225 EXPECT_EQ(position, drawable().rect.origin()); |
225 } | 226 } |
226 | 227 |
227 TEST_F(TouchHandleTest, PositionNotUpdatedWhileFadingOrInvisible) { | 228 TEST_F(TouchHandleTest, PositionNotUpdatedWhileFadingOrInvisible) { |
228 TouchHandle handle(this, TOUCH_HANDLE_CENTER); | 229 TouchHandle handle(this, TouchHandleOrientation::CENTER); |
229 | 230 |
230 handle.SetVisible(true, TouchHandle::ANIMATION_NONE); | 231 handle.SetVisible(true, TouchHandle::ANIMATION_NONE); |
231 ASSERT_TRUE(drawable().visible); | 232 ASSERT_TRUE(drawable().visible); |
232 ASSERT_FALSE(NeedsAnimate()); | 233 ASSERT_FALSE(NeedsAnimate()); |
233 | 234 |
234 gfx::PointF old_position(7.3f, -3.7f); | 235 gfx::PointF old_position(7.3f, -3.7f); |
235 handle.SetPosition(old_position); | 236 handle.SetPosition(old_position); |
236 ASSERT_EQ(old_position, drawable().rect.origin()); | 237 ASSERT_EQ(old_position, drawable().rect.origin()); |
237 | 238 |
238 handle.SetVisible(false, TouchHandle::ANIMATION_SMOOTH); | 239 handle.SetVisible(false, TouchHandle::ANIMATION_SMOOTH); |
(...skipping 14 matching lines...) Expand all Loading... |
253 // Even after the animation terminates, the new position will not be pushed. | 254 // Even after the animation terminates, the new position will not be pushed. |
254 EXPECT_EQ(old_position, drawable().rect.origin()); | 255 EXPECT_EQ(old_position, drawable().rect.origin()); |
255 | 256 |
256 // As soon as the handle becomes visible, the new position will be pushed. | 257 // As soon as the handle becomes visible, the new position will be pushed. |
257 handle.SetVisible(true, TouchHandle::ANIMATION_SMOOTH); | 258 handle.SetVisible(true, TouchHandle::ANIMATION_SMOOTH); |
258 EXPECT_EQ(new_position, drawable().rect.origin()); | 259 EXPECT_EQ(new_position, drawable().rect.origin()); |
259 } | 260 } |
260 | 261 |
261 TEST_F(TouchHandleTest, Enabled) { | 262 TEST_F(TouchHandleTest, Enabled) { |
262 // A newly created handle defaults to enabled. | 263 // A newly created handle defaults to enabled. |
263 TouchHandle handle(this, TOUCH_HANDLE_CENTER); | 264 TouchHandle handle(this, TouchHandleOrientation::CENTER); |
264 EXPECT_TRUE(drawable().enabled); | 265 EXPECT_TRUE(drawable().enabled); |
265 | 266 |
266 handle.SetVisible(true, TouchHandle::ANIMATION_SMOOTH); | 267 handle.SetVisible(true, TouchHandle::ANIMATION_SMOOTH); |
267 EXPECT_TRUE(GetAndResetNeedsAnimate()); | 268 EXPECT_TRUE(GetAndResetNeedsAnimate()); |
268 EXPECT_EQ(0.f, drawable().alpha); | 269 EXPECT_EQ(0.f, drawable().alpha); |
269 handle.SetEnabled(false); | 270 handle.SetEnabled(false); |
270 EXPECT_FALSE(drawable().enabled); | 271 EXPECT_FALSE(drawable().enabled); |
271 | 272 |
272 // Dragging should not be allowed while the handle is disabled. | 273 // Dragging should not be allowed while the handle is disabled. |
273 base::TimeTicks event_time = base::TimeTicks::Now(); | 274 base::TimeTicks event_time = base::TimeTicks::Now(); |
(...skipping 16 matching lines...) Expand all Loading... |
290 handle.SetEnabled(true); | 291 handle.SetEnabled(true); |
291 handle.SetVisible(true, TouchHandle::ANIMATION_NONE); | 292 handle.SetVisible(true, TouchHandle::ANIMATION_NONE); |
292 EXPECT_TRUE(handle.WillHandleTouchEvent(event)); | 293 EXPECT_TRUE(handle.WillHandleTouchEvent(event)); |
293 EXPECT_TRUE(IsDragging()); | 294 EXPECT_TRUE(IsDragging()); |
294 handle.SetEnabled(false); | 295 handle.SetEnabled(false); |
295 EXPECT_FALSE(IsDragging()); | 296 EXPECT_FALSE(IsDragging()); |
296 EXPECT_FALSE(handle.WillHandleTouchEvent(event)); | 297 EXPECT_FALSE(handle.WillHandleTouchEvent(event)); |
297 } | 298 } |
298 | 299 |
299 TEST_F(TouchHandleTest, Drag) { | 300 TEST_F(TouchHandleTest, Drag) { |
300 TouchHandle handle(this, TOUCH_HANDLE_CENTER); | 301 TouchHandle handle(this, TouchHandleOrientation::CENTER); |
301 | 302 |
302 base::TimeTicks event_time = base::TimeTicks::Now(); | 303 base::TimeTicks event_time = base::TimeTicks::Now(); |
303 const float kOffset = kDefaultDrawableSize / 2.f; | 304 const float kOffset = kDefaultDrawableSize / 2.f; |
304 | 305 |
305 // The handle must be visible to trigger drag. | 306 // The handle must be visible to trigger drag. |
306 MockMotionEvent event( | 307 MockMotionEvent event( |
307 MockMotionEvent::ACTION_DOWN, event_time, kOffset, kOffset); | 308 MockMotionEvent::ACTION_DOWN, event_time, kOffset, kOffset); |
308 EXPECT_FALSE(handle.WillHandleTouchEvent(event)); | 309 EXPECT_FALSE(handle.WillHandleTouchEvent(event)); |
309 EXPECT_FALSE(IsDragging()); | 310 EXPECT_FALSE(IsDragging()); |
310 handle.SetVisible(true, TouchHandle::ANIMATION_NONE); | 311 handle.SetVisible(true, TouchHandle::ANIMATION_NONE); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 EXPECT_TRUE(handle.WillHandleTouchEvent(event)); | 345 EXPECT_TRUE(handle.WillHandleTouchEvent(event)); |
345 EXPECT_FALSE(GetAndResetHandleDragged()); | 346 EXPECT_FALSE(GetAndResetHandleDragged()); |
346 EXPECT_FALSE(IsDragging()); | 347 EXPECT_FALSE(IsDragging()); |
347 | 348 |
348 // Non-ACTION_DOWN events after the drag has terminated should not be handled. | 349 // Non-ACTION_DOWN events after the drag has terminated should not be handled. |
349 event = MockMotionEvent(MockMotionEvent::ACTION_CANCEL); | 350 event = MockMotionEvent(MockMotionEvent::ACTION_CANCEL); |
350 EXPECT_FALSE(handle.WillHandleTouchEvent(event)); | 351 EXPECT_FALSE(handle.WillHandleTouchEvent(event)); |
351 } | 352 } |
352 | 353 |
353 TEST_F(TouchHandleTest, DragDefersOrientationChange) { | 354 TEST_F(TouchHandleTest, DragDefersOrientationChange) { |
354 TouchHandle handle(this, TOUCH_HANDLE_RIGHT); | 355 TouchHandle handle(this, TouchHandleOrientation::RIGHT); |
355 ASSERT_EQ(drawable().orientation, TOUCH_HANDLE_RIGHT); | 356 ASSERT_EQ(drawable().orientation, TouchHandleOrientation::RIGHT); |
356 handle.SetVisible(true, TouchHandle::ANIMATION_NONE); | 357 handle.SetVisible(true, TouchHandle::ANIMATION_NONE); |
357 | 358 |
358 MockMotionEvent event(MockMotionEvent::ACTION_DOWN); | 359 MockMotionEvent event(MockMotionEvent::ACTION_DOWN); |
359 EXPECT_TRUE(handle.WillHandleTouchEvent(event)); | 360 EXPECT_TRUE(handle.WillHandleTouchEvent(event)); |
360 EXPECT_TRUE(IsDragging()); | 361 EXPECT_TRUE(IsDragging()); |
361 | 362 |
362 // Orientation changes will be deferred until the drag ends. | 363 // Orientation changes will be deferred until the drag ends. |
363 handle.SetOrientation(TOUCH_HANDLE_LEFT); | 364 handle.SetOrientation(TouchHandleOrientation::LEFT); |
364 EXPECT_EQ(TOUCH_HANDLE_RIGHT, drawable().orientation); | 365 EXPECT_EQ(TouchHandleOrientation::RIGHT, drawable().orientation); |
365 | 366 |
366 event = MockMotionEvent(MockMotionEvent::ACTION_MOVE); | 367 event = MockMotionEvent(MockMotionEvent::ACTION_MOVE); |
367 EXPECT_TRUE(handle.WillHandleTouchEvent(event)); | 368 EXPECT_TRUE(handle.WillHandleTouchEvent(event)); |
368 EXPECT_TRUE(GetAndResetHandleDragged()); | 369 EXPECT_TRUE(GetAndResetHandleDragged()); |
369 EXPECT_TRUE(IsDragging()); | 370 EXPECT_TRUE(IsDragging()); |
370 EXPECT_EQ(TOUCH_HANDLE_RIGHT, drawable().orientation); | 371 EXPECT_EQ(TouchHandleOrientation::RIGHT, drawable().orientation); |
371 | 372 |
372 event = MockMotionEvent(MockMotionEvent::ACTION_UP); | 373 event = MockMotionEvent(MockMotionEvent::ACTION_UP); |
373 EXPECT_TRUE(handle.WillHandleTouchEvent(event)); | 374 EXPECT_TRUE(handle.WillHandleTouchEvent(event)); |
374 EXPECT_FALSE(GetAndResetHandleDragged()); | 375 EXPECT_FALSE(GetAndResetHandleDragged()); |
375 EXPECT_FALSE(IsDragging()); | 376 EXPECT_FALSE(IsDragging()); |
376 EXPECT_EQ(TOUCH_HANDLE_LEFT, drawable().orientation); | 377 EXPECT_EQ(TouchHandleOrientation::LEFT, drawable().orientation); |
377 } | 378 } |
378 | 379 |
379 TEST_F(TouchHandleTest, DragDefersFade) { | 380 TEST_F(TouchHandleTest, DragDefersFade) { |
380 TouchHandle handle(this, TOUCH_HANDLE_CENTER); | 381 TouchHandle handle(this, TouchHandleOrientation::CENTER); |
381 handle.SetVisible(true, TouchHandle::ANIMATION_NONE); | 382 handle.SetVisible(true, TouchHandle::ANIMATION_NONE); |
382 | 383 |
383 MockMotionEvent event(MockMotionEvent::ACTION_DOWN); | 384 MockMotionEvent event(MockMotionEvent::ACTION_DOWN); |
384 EXPECT_TRUE(handle.WillHandleTouchEvent(event)); | 385 EXPECT_TRUE(handle.WillHandleTouchEvent(event)); |
385 EXPECT_TRUE(IsDragging()); | 386 EXPECT_TRUE(IsDragging()); |
386 | 387 |
387 // Fade will be deferred until the drag ends. | 388 // Fade will be deferred until the drag ends. |
388 handle.SetVisible(false, TouchHandle::ANIMATION_SMOOTH); | 389 handle.SetVisible(false, TouchHandle::ANIMATION_SMOOTH); |
389 EXPECT_FALSE(NeedsAnimate()); | 390 EXPECT_FALSE(NeedsAnimate()); |
390 EXPECT_TRUE(drawable().visible); | 391 EXPECT_TRUE(drawable().visible); |
391 EXPECT_EQ(1.f, drawable().alpha); | 392 EXPECT_EQ(1.f, drawable().alpha); |
392 | 393 |
393 event = MockMotionEvent(MockMotionEvent::ACTION_MOVE); | 394 event = MockMotionEvent(MockMotionEvent::ACTION_MOVE); |
394 EXPECT_TRUE(handle.WillHandleTouchEvent(event)); | 395 EXPECT_TRUE(handle.WillHandleTouchEvent(event)); |
395 EXPECT_FALSE(NeedsAnimate()); | 396 EXPECT_FALSE(NeedsAnimate()); |
396 EXPECT_TRUE(drawable().visible); | 397 EXPECT_TRUE(drawable().visible); |
397 | 398 |
398 event = MockMotionEvent(MockMotionEvent::ACTION_UP); | 399 event = MockMotionEvent(MockMotionEvent::ACTION_UP); |
399 EXPECT_TRUE(handle.WillHandleTouchEvent(event)); | 400 EXPECT_TRUE(handle.WillHandleTouchEvent(event)); |
400 EXPECT_FALSE(IsDragging()); | 401 EXPECT_FALSE(IsDragging()); |
401 EXPECT_TRUE(NeedsAnimate()); | 402 EXPECT_TRUE(NeedsAnimate()); |
402 | 403 |
403 Animate(handle); | 404 Animate(handle); |
404 EXPECT_FALSE(drawable().visible); | 405 EXPECT_FALSE(drawable().visible); |
405 EXPECT_EQ(0.f, drawable().alpha); | 406 EXPECT_EQ(0.f, drawable().alpha); |
406 } | 407 } |
407 | 408 |
408 TEST_F(TouchHandleTest, DragTargettingUsesTouchSize) { | 409 TEST_F(TouchHandleTest, DragTargettingUsesTouchSize) { |
409 TouchHandle handle(this, TOUCH_HANDLE_CENTER); | 410 TouchHandle handle(this, TouchHandleOrientation::CENTER); |
410 handle.SetVisible(true, TouchHandle::ANIMATION_NONE); | 411 handle.SetVisible(true, TouchHandle::ANIMATION_NONE); |
411 | 412 |
412 base::TimeTicks event_time = base::TimeTicks::Now(); | 413 base::TimeTicks event_time = base::TimeTicks::Now(); |
413 const float kTouchSize = 24.f; | 414 const float kTouchSize = 24.f; |
414 const float kOffset = kDefaultDrawableSize + kTouchSize / 2.001f; | 415 const float kOffset = kDefaultDrawableSize + kTouchSize / 2.001f; |
415 | 416 |
416 MockMotionEvent event( | 417 MockMotionEvent event( |
417 MockMotionEvent::ACTION_DOWN, event_time, kOffset, 0); | 418 MockMotionEvent::ACTION_DOWN, event_time, kOffset, 0); |
418 event.SetTouchMajor(0.f); | 419 event.SetTouchMajor(0.f); |
419 EXPECT_FALSE(handle.WillHandleTouchEvent(event)); | 420 EXPECT_FALSE(handle.WillHandleTouchEvent(event)); |
(...skipping 30 matching lines...) Expand all Loading... |
450 event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, | 451 event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, |
451 event_time, | 452 event_time, |
452 kDefaultDrawableSize / 2.f, | 453 kDefaultDrawableSize / 2.f, |
453 kDefaultDrawableSize / 2.f); | 454 kDefaultDrawableSize / 2.f); |
454 event.SetTouchMajor(0); | 455 event.SetTouchMajor(0); |
455 EXPECT_TRUE(handle.WillHandleTouchEvent(event)); | 456 EXPECT_TRUE(handle.WillHandleTouchEvent(event)); |
456 EXPECT_TRUE(IsDragging()); | 457 EXPECT_TRUE(IsDragging()); |
457 } | 458 } |
458 | 459 |
459 TEST_F(TouchHandleTest, Tap) { | 460 TEST_F(TouchHandleTest, Tap) { |
460 TouchHandle handle(this, TOUCH_HANDLE_CENTER); | 461 TouchHandle handle(this, TouchHandleOrientation::CENTER); |
461 handle.SetVisible(true, TouchHandle::ANIMATION_NONE); | 462 handle.SetVisible(true, TouchHandle::ANIMATION_NONE); |
462 | 463 |
463 base::TimeTicks event_time = base::TimeTicks::Now(); | 464 base::TimeTicks event_time = base::TimeTicks::Now(); |
464 | 465 |
465 // ACTION_CANCEL shouldn't trigger a tap. | 466 // ACTION_CANCEL shouldn't trigger a tap. |
466 MockMotionEvent event(MockMotionEvent::ACTION_DOWN, event_time, 0, 0); | 467 MockMotionEvent event(MockMotionEvent::ACTION_DOWN, event_time, 0, 0); |
467 EXPECT_TRUE(handle.WillHandleTouchEvent(event)); | 468 EXPECT_TRUE(handle.WillHandleTouchEvent(event)); |
468 event_time += base::TimeDelta::FromMilliseconds(50); | 469 event_time += base::TimeDelta::FromMilliseconds(50); |
469 event = MockMotionEvent(MockMotionEvent::ACTION_CANCEL, event_time, 0, 0); | 470 event = MockMotionEvent(MockMotionEvent::ACTION_CANCEL, event_time, 0, 0); |
470 EXPECT_TRUE(handle.WillHandleTouchEvent(event)); | 471 EXPECT_TRUE(handle.WillHandleTouchEvent(event)); |
(...skipping 26 matching lines...) Expand all Loading... |
497 event = MockMotionEvent( | 498 event = MockMotionEvent( |
498 MockMotionEvent::ACTION_MOVE, event_time, kDefaultTapSlop * 2.f, 0); | 499 MockMotionEvent::ACTION_MOVE, event_time, kDefaultTapSlop * 2.f, 0); |
499 EXPECT_TRUE(handle.WillHandleTouchEvent(event)); | 500 EXPECT_TRUE(handle.WillHandleTouchEvent(event)); |
500 event = MockMotionEvent( | 501 event = MockMotionEvent( |
501 MockMotionEvent::ACTION_UP, event_time, kDefaultTapSlop * 2.f, 0); | 502 MockMotionEvent::ACTION_UP, event_time, kDefaultTapSlop * 2.f, 0); |
502 EXPECT_TRUE(handle.WillHandleTouchEvent(event)); | 503 EXPECT_TRUE(handle.WillHandleTouchEvent(event)); |
503 EXPECT_FALSE(GetAndResetHandleTapped()); | 504 EXPECT_FALSE(GetAndResetHandleTapped()); |
504 } | 505 } |
505 | 506 |
506 } // namespace ui | 507 } // namespace ui |
OLD | NEW |