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

Side by Side Diff: content/browser/renderer_host/input/touch_handle_unittest.cc

Issue 516573003: Use platform slop/timeout values for selection handle tap detection (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix build Created 6 years, 3 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 "content/browser/renderer_host/input/touch_handle.h" 5 #include "content/browser/renderer_host/input/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/mock_motion_event.h" 8 #include "ui/events/test/mock_motion_event.h"
9 #include "ui/gfx/geometry/rect_f.h" 9 #include "ui/gfx/geometry/rect_f.h"
10 10
11 using ui::test::MockMotionEvent; 11 using ui::test::MockMotionEvent;
12 12
13 namespace content { 13 namespace content {
14 namespace { 14 namespace {
15 15
16 const int kDefaultTapTimeoutMs = 200;
17 const float kDefaultTapSlop = 10.f;
16 const float kDefaultDrawableSize = 10.f; 18 const float kDefaultDrawableSize = 10.f;
17 19
18 struct MockDrawableData { 20 struct MockDrawableData {
19 MockDrawableData() 21 MockDrawableData()
20 : orientation(TOUCH_HANDLE_ORIENTATION_UNDEFINED), 22 : orientation(TOUCH_HANDLE_ORIENTATION_UNDEFINED),
21 alpha(0.f), 23 alpha(0.f),
22 enabled(false), 24 enabled(false),
23 visible(false), 25 visible(false),
24 rect(0, 0, kDefaultDrawableSize, kDefaultDrawableSize) {} 26 rect(0, 0, kDefaultDrawableSize, kDefaultDrawableSize) {}
25 TouchHandleOrientation orientation; 27 TouchHandleOrientation orientation;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 tapped_ = true; 90 tapped_ = true;
89 } 91 }
90 92
91 virtual void SetNeedsAnimate() OVERRIDE { needs_animate_ = true; } 93 virtual void SetNeedsAnimate() OVERRIDE { needs_animate_ = true; }
92 94
93 virtual scoped_ptr<TouchHandleDrawable> CreateDrawable() OVERRIDE { 95 virtual scoped_ptr<TouchHandleDrawable> CreateDrawable() OVERRIDE {
94 return scoped_ptr<TouchHandleDrawable>( 96 return scoped_ptr<TouchHandleDrawable>(
95 new MockTouchHandleDrawable(&drawable_data_)); 97 new MockTouchHandleDrawable(&drawable_data_));
96 } 98 }
97 99
100 virtual base::TimeDelta GetTapTimeout() const OVERRIDE {
101 return base::TimeDelta::FromMilliseconds(kDefaultTapTimeoutMs);
102 }
103
104 virtual float GetTapSlop() const OVERRIDE { return kDefaultTapSlop; }
105
98 void Animate(TouchHandle& handle) { 106 void Animate(TouchHandle& handle) {
99 needs_animate_ = false; 107 needs_animate_ = false;
100 base::TimeTicks now = base::TimeTicks::Now(); 108 base::TimeTicks now = base::TimeTicks::Now();
101 while (handle.Animate(now)) 109 while (handle.Animate(now))
102 now += base::TimeDelta::FromMilliseconds(16); 110 now += base::TimeDelta::FromMilliseconds(16);
103 } 111 }
104 112
105 bool GetAndResetHandleDragged() { 113 bool GetAndResetHandleDragged() {
106 bool dragged = dragged_; 114 bool dragged = dragged_;
107 dragged_ = false; 115 dragged_ = false;
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 MockMotionEvent event(MockMotionEvent::ACTION_DOWN, event_time, 0, 0); 453 MockMotionEvent event(MockMotionEvent::ACTION_DOWN, event_time, 0, 0);
446 EXPECT_TRUE(handle.WillHandleTouchEvent(event)); 454 EXPECT_TRUE(handle.WillHandleTouchEvent(event));
447 event_time += base::TimeDelta::FromMilliseconds(50); 455 event_time += base::TimeDelta::FromMilliseconds(50);
448 event = MockMotionEvent(MockMotionEvent::ACTION_CANCEL, event_time, 0, 0); 456 event = MockMotionEvent(MockMotionEvent::ACTION_CANCEL, event_time, 0, 0);
449 EXPECT_TRUE(handle.WillHandleTouchEvent(event)); 457 EXPECT_TRUE(handle.WillHandleTouchEvent(event));
450 EXPECT_FALSE(GetAndResetHandleTapped()); 458 EXPECT_FALSE(GetAndResetHandleTapped());
451 459
452 // Long press shouldn't trigger a tap. 460 // Long press shouldn't trigger a tap.
453 event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time, 0, 0); 461 event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time, 0, 0);
454 EXPECT_TRUE(handle.WillHandleTouchEvent(event)); 462 EXPECT_TRUE(handle.WillHandleTouchEvent(event));
455 event_time += base::TimeDelta::FromMilliseconds(500); 463 event_time += 2 * GetTapTimeout();
456 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 0, 0); 464 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 0, 0);
457 EXPECT_TRUE(handle.WillHandleTouchEvent(event)); 465 EXPECT_TRUE(handle.WillHandleTouchEvent(event));
458 EXPECT_FALSE(GetAndResetHandleTapped()); 466 EXPECT_FALSE(GetAndResetHandleTapped());
459 467
460 // Only a brief tap should trigger a tap. 468 // Only a brief tap within the slop region should trigger a tap.
461 event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time, 0, 0); 469 event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time, 0, 0);
462 EXPECT_TRUE(handle.WillHandleTouchEvent(event)); 470 EXPECT_TRUE(handle.WillHandleTouchEvent(event));
463 event_time += base::TimeDelta::FromMilliseconds(50); 471 event_time += GetTapTimeout() / 2;
464 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 0, 0); 472 event = MockMotionEvent(
473 MockMotionEvent::ACTION_MOVE, event_time, kDefaultTapSlop / 2.f, 0);
474 EXPECT_TRUE(handle.WillHandleTouchEvent(event));
475 event = MockMotionEvent(
476 MockMotionEvent::ACTION_UP, event_time, kDefaultTapSlop / 2.f, 0);
465 EXPECT_TRUE(handle.WillHandleTouchEvent(event)); 477 EXPECT_TRUE(handle.WillHandleTouchEvent(event));
466 EXPECT_TRUE(GetAndResetHandleTapped()); 478 EXPECT_TRUE(GetAndResetHandleTapped());
479
480 // Moving beyond the slop region shouldn't trigger a tap.
481 event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time, 0, 0);
482 EXPECT_TRUE(handle.WillHandleTouchEvent(event));
483 event_time += GetTapTimeout() / 2;
484 event = MockMotionEvent(
485 MockMotionEvent::ACTION_MOVE, event_time, kDefaultTapSlop * 2.f, 0);
486 EXPECT_TRUE(handle.WillHandleTouchEvent(event));
487 event = MockMotionEvent(
488 MockMotionEvent::ACTION_UP, event_time, kDefaultTapSlop * 2.f, 0);
489 EXPECT_TRUE(handle.WillHandleTouchEvent(event));
490 EXPECT_FALSE(GetAndResetHandleTapped());
467 } 491 }
468 492
469 } // namespace content 493 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/input/touch_handle.cc ('k') | content/browser/renderer_host/input/touch_selection_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698