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 "content/browser/renderer_host/input/tap_suppression_controller.h" | 5 #include "content/browser/renderer_host/input/tap_suppression_controller.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "content/browser/renderer_host/input/tap_suppression_controller_client.
h" | 10 #include "content/browser/renderer_host/input/tap_suppression_controller_client.
h" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 | 64 |
65 void SendTapUp() { | 65 void SendTapUp() { |
66 last_actions_ = NONE; | 66 last_actions_ = NONE; |
67 if (ShouldSuppressTapEnd()) | 67 if (ShouldSuppressTapEnd()) |
68 last_actions_ |= TAP_UP_SUPPRESSED; | 68 last_actions_ |= TAP_UP_SUPPRESSED; |
69 else | 69 else |
70 last_actions_ |= TAP_UP_FORWARDED; | 70 last_actions_ |= TAP_UP_FORWARDED; |
71 } | 71 } |
72 | 72 |
73 void SendTapCancel() { | 73 void SendTapCancel() { |
| 74 bool stashed_tap_down_forwarded = |
| 75 last_actions_ & STASHED_TAP_DOWN_FORWARDED; |
74 last_actions_ = NONE; | 76 last_actions_ = NONE; |
75 if (ShouldSuppressTapEnd()) | 77 if (!stashed_tap_down_forwarded && ShouldSuppressTapEnd()) |
76 last_actions_ |= TAP_CANCEL_SUPPRESSED; | 78 last_actions_ |= TAP_CANCEL_SUPPRESSED; |
77 else | 79 else |
78 last_actions_ |= TAP_CANCEL_FORWARDED; | 80 last_actions_ |= TAP_CANCEL_FORWARDED; |
79 } | 81 } |
80 | 82 |
81 void AdvanceTime(const base::TimeDelta& delta) { | 83 void AdvanceTime(const base::TimeDelta& delta) { |
82 last_actions_ = NONE; | 84 last_actions_ = NONE; |
83 time_ += delta; | 85 time_ += delta; |
84 if (timer_started_ && time_ >= timer_expiry_time_) { | 86 if (timer_started_ && time_ >= timer_expiry_time_) { |
85 timer_started_ = false; | 87 timer_started_ = false; |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 EXPECT_EQ(MockTapSuppressionController::GFC_IN_PROGRESS, | 240 EXPECT_EQ(MockTapSuppressionController::GFC_IN_PROGRESS, |
239 tap_suppression_controller_->state()); | 241 tap_suppression_controller_->state()); |
240 | 242 |
241 // Send processed GestureFlingCancel Ack. | 243 // Send processed GestureFlingCancel Ack. |
242 tap_suppression_controller_->SendGestureFlingCancelAck(true); | 244 tap_suppression_controller_->SendGestureFlingCancelAck(true); |
243 EXPECT_EQ(MockTapSuppressionController::NONE, | 245 EXPECT_EQ(MockTapSuppressionController::NONE, |
244 tap_suppression_controller_->last_actions()); | 246 tap_suppression_controller_->last_actions()); |
245 EXPECT_EQ(MockTapSuppressionController::LAST_CANCEL_STOPPED_FLING, | 247 EXPECT_EQ(MockTapSuppressionController::LAST_CANCEL_STOPPED_FLING, |
246 tap_suppression_controller_->state()); | 248 tap_suppression_controller_->state()); |
247 | 249 |
248 // Send MouseDown. This MouseDown should be suppressed, for now. | 250 // Send TapDown. This TapDown should be suppressed, for now. |
249 tap_suppression_controller_->SendTapDown(); | 251 tap_suppression_controller_->SendTapDown(); |
250 EXPECT_EQ(MockTapSuppressionController::TAP_DOWN_DEFERRED, | 252 EXPECT_EQ(MockTapSuppressionController::TAP_DOWN_DEFERRED, |
251 tap_suppression_controller_->last_actions()); | 253 tap_suppression_controller_->last_actions()); |
252 EXPECT_EQ(MockTapSuppressionController::TAP_DOWN_STASHED, | 254 EXPECT_EQ(MockTapSuppressionController::TAP_DOWN_STASHED, |
253 tap_suppression_controller_->state()); | 255 tap_suppression_controller_->state()); |
254 | 256 |
255 // Wait more than allowed delay between TapDown and TapUp, so they are not | 257 // Wait more than allowed delay between TapDown and TapUp, so they are not |
256 // considered a tap. This should release the previously suppressed TapDown. | 258 // considered a tap. This should release the previously suppressed TapDown. |
257 tap_suppression_controller_->AdvanceTime(TimeDelta::FromMilliseconds(13)); | 259 tap_suppression_controller_->AdvanceTime(TimeDelta::FromMilliseconds(13)); |
258 EXPECT_EQ(MockTapSuppressionController::STASHED_TAP_DOWN_FORWARDED, | 260 EXPECT_EQ(MockTapSuppressionController::STASHED_TAP_DOWN_FORWARDED, |
259 tap_suppression_controller_->last_actions()); | 261 tap_suppression_controller_->last_actions()); |
260 EXPECT_EQ(MockTapSuppressionController::SUPPRESSING_TAPS, | 262 EXPECT_EQ(MockTapSuppressionController::SUPPRESSING_TAPS, |
261 tap_suppression_controller_->state()); | 263 tap_suppression_controller_->state()); |
262 | 264 |
263 // Send TapUp. This TapUp should be still suppressed. | 265 // Send TapUp. This TapUp should be still suppressed. |
264 // LongTap should be suppressed when the previously suppressed TapDown is | 266 // LongTap should be suppressed when the previously suppressed TapDown is |
265 // forwarded because of the timer expiration. | 267 // forwarded because of the timer expiration. |
266 tap_suppression_controller_->SendTapUp(); | 268 tap_suppression_controller_->SendTapUp(); |
267 EXPECT_EQ(MockTapSuppressionController::TAP_UP_SUPPRESSED, | 269 EXPECT_EQ(MockTapSuppressionController::TAP_UP_SUPPRESSED, |
268 tap_suppression_controller_->last_actions()); | 270 tap_suppression_controller_->last_actions()); |
269 EXPECT_EQ(MockTapSuppressionController::SUPPRESSING_TAPS, | 271 EXPECT_EQ(MockTapSuppressionController::SUPPRESSING_TAPS, |
270 tap_suppression_controller_->state()); | 272 tap_suppression_controller_->state()); |
271 } | 273 } |
272 | 274 |
| 275 // Test TapSuppressionController for when stashed TapDown gets forwarded. |
| 276 // The next TapCancel should be forwarded as well to maintain a valid input |
| 277 // stream. |
| 278 TEST_F(TapSuppressionControllerTest, GFCAckBeforeTapSufficientlyLateTapCancel) { |
| 279 // Send GestureFlingCancel. |
| 280 tap_suppression_controller_->SendGestureFlingCancel(); |
| 281 EXPECT_EQ(MockTapSuppressionController::NONE, |
| 282 tap_suppression_controller_->last_actions()); |
| 283 EXPECT_EQ(MockTapSuppressionController::GFC_IN_PROGRESS, |
| 284 tap_suppression_controller_->state()); |
| 285 |
| 286 // Send processed GestureFlingCancel Ack. |
| 287 tap_suppression_controller_->SendGestureFlingCancelAck(true); |
| 288 EXPECT_EQ(MockTapSuppressionController::NONE, |
| 289 tap_suppression_controller_->last_actions()); |
| 290 EXPECT_EQ(MockTapSuppressionController::LAST_CANCEL_STOPPED_FLING, |
| 291 tap_suppression_controller_->state()); |
| 292 |
| 293 // Send TapDown. This TapDown should be suppressed, for now. |
| 294 tap_suppression_controller_->SendTapDown(); |
| 295 EXPECT_EQ(MockTapSuppressionController::TAP_DOWN_DEFERRED, |
| 296 tap_suppression_controller_->last_actions()); |
| 297 EXPECT_EQ(MockTapSuppressionController::TAP_DOWN_STASHED, |
| 298 tap_suppression_controller_->state()); |
| 299 |
| 300 // Wait more than the delay for TapDown timer. This should release the |
| 301 // previously stashed TapDown. |
| 302 tap_suppression_controller_->AdvanceTime(TimeDelta::FromMilliseconds(13)); |
| 303 EXPECT_EQ(MockTapSuppressionController::STASHED_TAP_DOWN_FORWARDED, |
| 304 tap_suppression_controller_->last_actions()); |
| 305 EXPECT_EQ(MockTapSuppressionController::SUPPRESSING_TAPS, |
| 306 tap_suppression_controller_->state()); |
| 307 |
| 308 // Send TapCancel. This TapCancel should be forwarded. |
| 309 // When a TapDown is forwarded because of the timer expiration, the next |
| 310 // TapCancel should get forwarded as well to maintain a valid input stream. |
| 311 tap_suppression_controller_->SendTapCancel(); |
| 312 EXPECT_EQ(MockTapSuppressionController::TAP_CANCEL_FORWARDED, |
| 313 tap_suppression_controller_->last_actions()); |
| 314 EXPECT_EQ(MockTapSuppressionController::SUPPRESSING_TAPS, |
| 315 tap_suppression_controller_->state()); |
| 316 } |
| 317 |
273 // Test TapSuppressionController for when GestureFlingCancel Ack comes before | 318 // Test TapSuppressionController for when GestureFlingCancel Ack comes before |
274 // TapDown, but there is a small delay between the Ack and TapDown. | 319 // TapDown, but there is a small delay between the Ack and TapDown. |
275 TEST_F(TapSuppressionControllerTest, GFCAckBeforeTapInsufficientlyLateTapDown) { | 320 TEST_F(TapSuppressionControllerTest, GFCAckBeforeTapInsufficientlyLateTapDown) { |
276 // Send GestureFlingCancel. | 321 // Send GestureFlingCancel. |
277 tap_suppression_controller_->SendGestureFlingCancel(); | 322 tap_suppression_controller_->SendGestureFlingCancel(); |
278 EXPECT_EQ(MockTapSuppressionController::NONE, | 323 EXPECT_EQ(MockTapSuppressionController::NONE, |
279 tap_suppression_controller_->last_actions()); | 324 tap_suppression_controller_->last_actions()); |
280 EXPECT_EQ(MockTapSuppressionController::GFC_IN_PROGRESS, | 325 EXPECT_EQ(MockTapSuppressionController::GFC_IN_PROGRESS, |
281 tap_suppression_controller_->state()); | 326 tap_suppression_controller_->state()); |
282 | 327 |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
530 | 575 |
531 // Send TapUp. This TapUp should not be suppressed. | 576 // Send TapUp. This TapUp should not be suppressed. |
532 tap_suppression_controller_->SendTapUp(); | 577 tap_suppression_controller_->SendTapUp(); |
533 EXPECT_EQ(MockTapSuppressionController::TAP_UP_FORWARDED, | 578 EXPECT_EQ(MockTapSuppressionController::TAP_UP_FORWARDED, |
534 tap_suppression_controller_->last_actions()); | 579 tap_suppression_controller_->last_actions()); |
535 EXPECT_EQ(MockTapSuppressionController::DISABLED, | 580 EXPECT_EQ(MockTapSuppressionController::DISABLED, |
536 tap_suppression_controller_->state()); | 581 tap_suppression_controller_->state()); |
537 } | 582 } |
538 | 583 |
539 } // namespace content | 584 } // namespace content |
OLD | NEW |