| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
| 7 #include "content/browser/renderer_host/input/tap_suppression_controller.h" | 7 #include "content/browser/renderer_host/input/tap_suppression_controller.h" |
| 8 #include "content/browser/renderer_host/input/tap_suppression_controller_client.
h" | 8 #include "content/browser/renderer_host/input/tap_suppression_controller_client.
h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 10 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 TAP_CANCEL_FORWARDED = 1 << 6, | 32 TAP_CANCEL_FORWARDED = 1 << 6, |
| 33 STASHED_TAP_DOWN_FORWARDED = 1 << 7, | 33 STASHED_TAP_DOWN_FORWARDED = 1 << 7, |
| 34 }; | 34 }; |
| 35 | 35 |
| 36 MockTapSuppressionController(const TapSuppressionController::Config& config) | 36 MockTapSuppressionController(const TapSuppressionController::Config& config) |
| 37 : TapSuppressionController(this, config), | 37 : TapSuppressionController(this, config), |
| 38 last_actions_(NONE), | 38 last_actions_(NONE), |
| 39 time_(), | 39 time_(), |
| 40 timer_started_(false) {} | 40 timer_started_(false) {} |
| 41 | 41 |
| 42 virtual ~MockTapSuppressionController() {} | 42 ~MockTapSuppressionController() override {} |
| 43 | 43 |
| 44 void SendGestureFlingCancel() { | 44 void SendGestureFlingCancel() { |
| 45 last_actions_ = NONE; | 45 last_actions_ = NONE; |
| 46 GestureFlingCancel(); | 46 GestureFlingCancel(); |
| 47 } | 47 } |
| 48 | 48 |
| 49 void SendGestureFlingCancelAck(bool processed) { | 49 void SendGestureFlingCancelAck(bool processed) { |
| 50 last_actions_ = NONE; | 50 last_actions_ = NONE; |
| 51 GestureFlingCancelAck(processed); | 51 GestureFlingCancelAck(processed); |
| 52 } | 52 } |
| (...skipping 29 matching lines...) Expand all Loading... |
| 82 timer_started_ = false; | 82 timer_started_ = false; |
| 83 TapDownTimerExpired(); | 83 TapDownTimerExpired(); |
| 84 } | 84 } |
| 85 } | 85 } |
| 86 | 86 |
| 87 State state() { return state_; } | 87 State state() { return state_; } |
| 88 | 88 |
| 89 int last_actions() { return last_actions_; } | 89 int last_actions() { return last_actions_; } |
| 90 | 90 |
| 91 protected: | 91 protected: |
| 92 virtual base::TimeTicks Now() override { | 92 base::TimeTicks Now() override { return time_; } |
| 93 return time_; | |
| 94 } | |
| 95 | 93 |
| 96 virtual void StartTapDownTimer(const base::TimeDelta& delay) override { | 94 void StartTapDownTimer(const base::TimeDelta& delay) override { |
| 97 timer_expiry_time_ = time_ + delay; | 95 timer_expiry_time_ = time_ + delay; |
| 98 timer_started_ = true; | 96 timer_started_ = true; |
| 99 } | 97 } |
| 100 | 98 |
| 101 virtual void StopTapDownTimer() override { | 99 void StopTapDownTimer() override { timer_started_ = false; } |
| 102 timer_started_ = false; | |
| 103 } | |
| 104 | 100 |
| 105 private: | 101 private: |
| 106 // TapSuppressionControllerClient implementation | 102 // TapSuppressionControllerClient implementation |
| 107 virtual void DropStashedTapDown() override { | 103 void DropStashedTapDown() override { last_actions_ |= TAP_DOWN_DROPPED; } |
| 108 last_actions_ |= TAP_DOWN_DROPPED; | |
| 109 } | |
| 110 | 104 |
| 111 virtual void ForwardStashedTapDown() override { | 105 void ForwardStashedTapDown() override { |
| 112 last_actions_ |= STASHED_TAP_DOWN_FORWARDED; | 106 last_actions_ |= STASHED_TAP_DOWN_FORWARDED; |
| 113 } | 107 } |
| 114 | 108 |
| 115 // Hiding some derived public methods | 109 // Hiding some derived public methods |
| 116 using TapSuppressionController::GestureFlingCancel; | 110 using TapSuppressionController::GestureFlingCancel; |
| 117 using TapSuppressionController::GestureFlingCancelAck; | 111 using TapSuppressionController::GestureFlingCancelAck; |
| 118 using TapSuppressionController::ShouldDeferTapDown; | 112 using TapSuppressionController::ShouldDeferTapDown; |
| 119 using TapSuppressionController::ShouldSuppressTapEnd; | 113 using TapSuppressionController::ShouldSuppressTapEnd; |
| 120 | 114 |
| 121 int last_actions_; | 115 int last_actions_; |
| 122 | 116 |
| 123 base::TimeTicks time_; | 117 base::TimeTicks time_; |
| 124 bool timer_started_; | 118 bool timer_started_; |
| 125 base::TimeTicks timer_expiry_time_; | 119 base::TimeTicks timer_expiry_time_; |
| 126 | 120 |
| 127 DISALLOW_COPY_AND_ASSIGN(MockTapSuppressionController); | 121 DISALLOW_COPY_AND_ASSIGN(MockTapSuppressionController); |
| 128 }; | 122 }; |
| 129 | 123 |
| 130 class TapSuppressionControllerTest : public testing::Test { | 124 class TapSuppressionControllerTest : public testing::Test { |
| 131 public: | 125 public: |
| 132 TapSuppressionControllerTest() { | 126 TapSuppressionControllerTest() { |
| 133 } | 127 } |
| 134 virtual ~TapSuppressionControllerTest() { | 128 ~TapSuppressionControllerTest() override {} |
| 135 } | |
| 136 | 129 |
| 137 protected: | 130 protected: |
| 138 // testing::Test | 131 // testing::Test |
| 139 virtual void SetUp() { | 132 void SetUp() override { |
| 140 tap_suppression_controller_.reset( | 133 tap_suppression_controller_.reset( |
| 141 new MockTapSuppressionController(GetConfig())); | 134 new MockTapSuppressionController(GetConfig())); |
| 142 } | 135 } |
| 143 | 136 |
| 144 virtual void TearDown() { | 137 void TearDown() override { tap_suppression_controller_.reset(); } |
| 145 tap_suppression_controller_.reset(); | |
| 146 } | |
| 147 | 138 |
| 148 static TapSuppressionController::Config GetConfig() { | 139 static TapSuppressionController::Config GetConfig() { |
| 149 TapSuppressionController::Config config; | 140 TapSuppressionController::Config config; |
| 150 config.enabled = true; | 141 config.enabled = true; |
| 151 config.max_cancel_to_down_time = base::TimeDelta::FromMilliseconds(10); | 142 config.max_cancel_to_down_time = base::TimeDelta::FromMilliseconds(10); |
| 152 config.max_tap_gap_time = base::TimeDelta::FromMilliseconds(10); | 143 config.max_tap_gap_time = base::TimeDelta::FromMilliseconds(10); |
| 153 return config; | 144 return config; |
| 154 } | 145 } |
| 155 | 146 |
| 156 scoped_ptr<MockTapSuppressionController> tap_suppression_controller_; | 147 scoped_ptr<MockTapSuppressionController> tap_suppression_controller_; |
| (...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 528 | 519 |
| 529 // Send TapUp. This TapUp should not be suppressed. | 520 // Send TapUp. This TapUp should not be suppressed. |
| 530 tap_suppression_controller_->SendTapUp(); | 521 tap_suppression_controller_->SendTapUp(); |
| 531 EXPECT_EQ(MockTapSuppressionController::TAP_UP_FORWARDED, | 522 EXPECT_EQ(MockTapSuppressionController::TAP_UP_FORWARDED, |
| 532 tap_suppression_controller_->last_actions()); | 523 tap_suppression_controller_->last_actions()); |
| 533 EXPECT_EQ(MockTapSuppressionController::DISABLED, | 524 EXPECT_EQ(MockTapSuppressionController::DISABLED, |
| 534 tap_suppression_controller_->state()); | 525 tap_suppression_controller_->state()); |
| 535 } | 526 } |
| 536 | 527 |
| 537 } // namespace content | 528 } // namespace content |
| OLD | NEW |