| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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_event_queue.h" | 5 #include "content/browser/renderer_host/input/passthrough_touch_event_queue.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/location.h" | 12 #include "base/location.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
| 15 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
| 16 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
| 17 #include "base/threading/thread_task_runner_handle.h" | 17 #include "base/threading/thread_task_runner_handle.h" |
| 18 #include "content/browser/renderer_host/input/legacy_touch_event_queue.h" | |
| 19 #include "content/browser/renderer_host/input/timeout_monitor.h" | 18 #include "content/browser/renderer_host/input/timeout_monitor.h" |
| 20 #include "content/common/input/synthetic_web_input_event_builders.h" | 19 #include "content/common/input/synthetic_web_input_event_builders.h" |
| 21 #include "content/common/input/web_touch_event_traits.h" | 20 #include "content/common/input/web_touch_event_traits.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 23 #include "third_party/WebKit/public/platform/WebInputEvent.h" | 22 #include "third_party/WebKit/public/platform/WebInputEvent.h" |
| 24 #include "ui/events/base_event_utils.h" | 23 #include "ui/events/base_event_utils.h" |
| 25 | 24 |
| 26 using blink::WebGestureEvent; | 25 using blink::WebGestureEvent; |
| 27 using blink::WebInputEvent; | 26 using blink::WebInputEvent; |
| 28 using blink::WebTouchEvent; | 27 using blink::WebTouchEvent; |
| 29 using blink::WebTouchPoint; | 28 using blink::WebTouchPoint; |
| 30 | 29 |
| 31 namespace content { | 30 namespace content { |
| 32 namespace { | 31 namespace { |
| 33 | 32 |
| 34 const double kMinSecondsBetweenThrottledTouchmoves = 0.2; | 33 const double kMinSecondsBetweenThrottledTouchmoves = 0.2; |
| 35 const float kSlopLengthDips = 10; | 34 const float kSlopLengthDips = 10; |
| 36 const float kHalfSlopLengthDips = kSlopLengthDips / 2; | 35 const float kHalfSlopLengthDips = kSlopLengthDips / 2; |
| 37 | 36 |
| 38 base::TimeDelta DefaultTouchTimeoutDelay() { | 37 base::TimeDelta DefaultTouchTimeoutDelay() { |
| 39 return base::TimeDelta::FromMilliseconds(1); | 38 return base::TimeDelta::FromMilliseconds(1); |
| 40 } | 39 } |
| 41 } // namespace | 40 } // namespace |
| 42 | 41 |
| 43 class TouchEventQueueTest : public testing::Test, | 42 class PassthroughTouchEventQueueTest : public testing::Test, |
| 44 public TouchEventQueueClient { | 43 public TouchEventQueueClient { |
| 45 public: | 44 public: |
| 46 TouchEventQueueTest() | 45 PassthroughTouchEventQueueTest() |
| 47 : acked_event_count_(0), | 46 : acked_event_count_(0), |
| 48 last_acked_event_state_(INPUT_EVENT_ACK_STATE_UNKNOWN), | 47 last_acked_event_state_(INPUT_EVENT_ACK_STATE_UNKNOWN), |
| 49 slop_length_dips_(0) {} | 48 slop_length_dips_(0) {} |
| 50 | 49 |
| 51 ~TouchEventQueueTest() override {} | 50 ~PassthroughTouchEventQueueTest() override {} |
| 52 | 51 |
| 53 // testing::Test | 52 // testing::Test |
| 54 void SetUp() override { | 53 void SetUp() override { |
| 55 ResetQueueWithConfig(TouchEventQueue::Config()); | 54 ResetQueueWithConfig(TouchEventQueue::Config()); |
| 56 sent_events_ids_.clear(); | 55 sent_events_ids_.clear(); |
| 57 } | 56 } |
| 58 | 57 |
| 59 void TearDown() override { queue_.reset(); } | 58 void TearDown() override { queue_.reset(); } |
| 60 | 59 |
| 61 // TouchEventQueueClient | 60 // TouchEventQueueClient |
| (...skipping 13 matching lines...) Expand all Loading... |
| 75 last_acked_event_ = event.event; | 74 last_acked_event_ = event.event; |
| 76 last_acked_event_state_ = ack_result; | 75 last_acked_event_state_ = ack_result; |
| 77 if (followup_touch_event_) { | 76 if (followup_touch_event_) { |
| 78 std::unique_ptr<WebTouchEvent> followup_touch_event = | 77 std::unique_ptr<WebTouchEvent> followup_touch_event = |
| 79 std::move(followup_touch_event_); | 78 std::move(followup_touch_event_); |
| 80 SendTouchEvent(*followup_touch_event); | 79 SendTouchEvent(*followup_touch_event); |
| 81 } | 80 } |
| 82 if (followup_gesture_event_) { | 81 if (followup_gesture_event_) { |
| 83 std::unique_ptr<WebGestureEvent> followup_gesture_event = | 82 std::unique_ptr<WebGestureEvent> followup_gesture_event = |
| 84 std::move(followup_gesture_event_); | 83 std::move(followup_gesture_event_); |
| 85 queue_->OnGestureScrollEvent( | 84 queue_->OnGestureScrollEvent(GestureEventWithLatencyInfo( |
| 86 GestureEventWithLatencyInfo(*followup_gesture_event, | 85 *followup_gesture_event, ui::LatencyInfo())); |
| 87 ui::LatencyInfo())); | |
| 88 } | 86 } |
| 89 } | 87 } |
| 90 | 88 |
| 91 void OnFilteringTouchEvent(const blink::WebTouchEvent& touch_event) override { | 89 void OnFilteringTouchEvent(const blink::WebTouchEvent& touch_event) override { |
| 92 } | 90 } |
| 93 | 91 |
| 94 protected: | 92 protected: |
| 95 void SetUpForTouchMoveSlopTesting(double slop_length_dips) { | 93 void SetUpForTouchMoveSlopTesting(double slop_length_dips) { |
| 96 slop_length_dips_ = slop_length_dips; | 94 slop_length_dips_ = slop_length_dips; |
| 97 } | 95 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 GestureEventWithLatencyInfo(event, ui::LatencyInfo())); | 131 GestureEventWithLatencyInfo(event, ui::LatencyInfo())); |
| 134 } | 132 } |
| 135 | 133 |
| 136 void SendTouchEventAck(InputEventAckState ack_result) { | 134 void SendTouchEventAck(InputEventAckState ack_result) { |
| 137 DCHECK(!sent_events_ids_.empty()); | 135 DCHECK(!sent_events_ids_.empty()); |
| 138 queue_->ProcessTouchAck(ack_result, ui::LatencyInfo(), | 136 queue_->ProcessTouchAck(ack_result, ui::LatencyInfo(), |
| 139 sent_events_ids_.front()); | 137 sent_events_ids_.front()); |
| 140 sent_events_ids_.pop_front(); | 138 sent_events_ids_.pop_front(); |
| 141 } | 139 } |
| 142 | 140 |
| 141 void SendTouchEventAckLast(InputEventAckState ack_result) { |
| 142 DCHECK(!sent_events_ids_.empty()); |
| 143 queue_->ProcessTouchAck(ack_result, ui::LatencyInfo(), |
| 144 sent_events_ids_.back()); |
| 145 sent_events_ids_.pop_back(); |
| 146 } |
| 147 |
| 143 void SendTouchEventAckWithID(InputEventAckState ack_result, | 148 void SendTouchEventAckWithID(InputEventAckState ack_result, |
| 144 int unique_event_id) { | 149 int unique_event_id) { |
| 145 queue_->ProcessTouchAck(ack_result, ui::LatencyInfo(), unique_event_id); | 150 queue_->ProcessTouchAck(ack_result, ui::LatencyInfo(), unique_event_id); |
| 146 sent_events_ids_.erase(std::remove(sent_events_ids_.begin(), | 151 sent_events_ids_.erase(std::remove(sent_events_ids_.begin(), |
| 147 sent_events_ids_.end(), unique_event_id), | 152 sent_events_ids_.end(), unique_event_id), |
| 148 sent_events_ids_.end()); | 153 sent_events_ids_.end()); |
| 149 } | 154 } |
| 150 | 155 |
| 151 void SendGestureEventAck(WebInputEvent::Type type, | 156 void SendGestureEventAck(WebInputEvent::Type type, |
| 152 InputEventAckState ack_result) { | 157 InputEventAckState ack_result) { |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 } | 245 } |
| 241 | 246 |
| 242 void PrependTouchScrollNotification() { | 247 void PrependTouchScrollNotification() { |
| 243 queue_->PrependTouchScrollNotification(); | 248 queue_->PrependTouchScrollNotification(); |
| 244 } | 249 } |
| 245 | 250 |
| 246 void AdvanceTouchTime(double seconds) { | 251 void AdvanceTouchTime(double seconds) { |
| 247 touch_event_.setTimeStampSeconds(touch_event_.timeStampSeconds() + seconds); | 252 touch_event_.setTimeStampSeconds(touch_event_.timeStampSeconds() + seconds); |
| 248 } | 253 } |
| 249 | 254 |
| 250 void ResetTouchEvent() { | 255 void ResetTouchEvent() { touch_event_ = SyntheticWebTouchEvent(); } |
| 251 touch_event_ = SyntheticWebTouchEvent(); | |
| 252 } | |
| 253 | 256 |
| 254 size_t GetAndResetAckedEventCount() { | 257 size_t GetAndResetAckedEventCount() { |
| 255 size_t count = acked_event_count_; | 258 size_t count = acked_event_count_; |
| 256 acked_event_count_ = 0; | 259 acked_event_count_ = 0; |
| 257 return count; | 260 return count; |
| 258 } | 261 } |
| 259 | 262 |
| 260 size_t GetAndResetSentEventCount() { | 263 size_t GetAndResetSentEventCount() { |
| 261 size_t count = sent_events_.size(); | 264 size_t count = sent_events_.size(); |
| 262 sent_events_.clear(); | 265 sent_events_.clear(); |
| 263 return count; | 266 return count; |
| 264 } | 267 } |
| 265 | 268 |
| 266 bool IsPendingAckTouchStart() const { | 269 bool IsPendingAckTouchStart() const { |
| 267 return queue_->IsPendingAckTouchStart(); | 270 return queue_->IsPendingAckTouchStart(); |
| 268 } | 271 } |
| 269 | 272 |
| 270 void OnHasTouchEventHandlers(bool has_handlers) { | 273 void OnHasTouchEventHandlers(bool has_handlers) { |
| 271 queue_->OnHasTouchEventHandlers(has_handlers); | 274 queue_->OnHasTouchEventHandlers(has_handlers); |
| 272 } | 275 } |
| 273 | 276 |
| 274 void SetAckTimeoutDisabled() { queue_->SetAckTimeoutEnabled(false); } | 277 void SetAckTimeoutDisabled() { queue_->SetAckTimeoutEnabled(false); } |
| 275 | 278 |
| 276 void SetIsMobileOptimizedSite(bool is_mobile_optimized) { | 279 void SetIsMobileOptimizedSite(bool is_mobile_optimized) { |
| 277 queue_->SetIsMobileOptimizedSite(is_mobile_optimized); | 280 queue_->SetIsMobileOptimizedSite(is_mobile_optimized); |
| 278 } | 281 } |
| 279 | 282 |
| 280 bool IsTimeoutRunning() const { return queue_->IsTimeoutRunningForTesting(); } | 283 bool IsTimeoutRunning() const { return queue_->IsTimeoutRunningForTesting(); } |
| 281 | 284 |
| 282 bool HasPendingAsyncTouchMove() const { | 285 size_t queued_event_count() const { return queue_->SizeForTesting(); } |
| 283 return queue_->HasPendingAsyncTouchMoveForTesting(); | |
| 284 } | |
| 285 | |
| 286 size_t queued_event_count() const { | |
| 287 return queue_->size(); | |
| 288 } | |
| 289 | 286 |
| 290 const WebTouchEvent& latest_event() const { | 287 const WebTouchEvent& latest_event() const { |
| 291 return queue_->GetLatestEventForTesting().event; | 288 return queue_->GetLatestEventForTesting().event; |
| 292 } | 289 } |
| 293 | 290 |
| 294 const WebTouchEvent& acked_event() const { | 291 const WebTouchEvent& acked_event() const { return last_acked_event_; } |
| 295 return last_acked_event_; | |
| 296 } | |
| 297 | 292 |
| 298 const WebTouchEvent& sent_event() const { | 293 const WebTouchEvent& sent_event() const { |
| 299 DCHECK(!sent_events_.empty()); | 294 DCHECK(!sent_events_.empty()); |
| 300 return sent_events_.back(); | 295 return sent_events_.back(); |
| 301 } | 296 } |
| 302 | 297 |
| 303 const std::vector<WebTouchEvent>& all_sent_events() const { | 298 const std::vector<WebTouchEvent>& all_sent_events() const { |
| 304 return sent_events_; | 299 return sent_events_; |
| 305 } | 300 } |
| 306 | 301 |
| 307 InputEventAckState acked_event_state() const { | 302 InputEventAckState acked_event_state() const { |
| 308 return last_acked_event_state_; | 303 return last_acked_event_state_; |
| 309 } | 304 } |
| 310 | 305 |
| 311 static void RunTasksAndWait(base::TimeDelta delay) { | 306 static void RunTasksAndWait(base::TimeDelta delay) { |
| 312 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 307 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 313 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), delay); | 308 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), delay); |
| 314 base::RunLoop().Run(); | 309 base::RunLoop().Run(); |
| 315 } | 310 } |
| 316 | 311 |
| 317 size_t uncancelable_touch_moves_pending_ack_count() const { | |
| 318 return queue_->uncancelable_touch_moves_pending_ack_count(); | |
| 319 } | |
| 320 | |
| 321 int GetUniqueTouchEventID() { return sent_events_ids_.back(); } | 312 int GetUniqueTouchEventID() { return sent_events_ids_.back(); } |
| 322 | 313 |
| 323 private: | 314 private: |
| 324 void SendTouchEvent() { | 315 void SendTouchEvent() { |
| 325 SendTouchEvent(touch_event_); | 316 SendTouchEvent(touch_event_); |
| 326 touch_event_.ResetPoints(); | 317 touch_event_.ResetPoints(); |
| 327 } | 318 } |
| 328 | 319 |
| 329 void ResetQueueWithConfig(const TouchEventQueue::Config& config) { | 320 void ResetQueueWithConfig(const TouchEventQueue::Config& config) { |
| 330 queue_.reset(new LegacyTouchEventQueue(this, config)); | 321 queue_.reset(new PassthroughTouchEventQueue(this, config)); |
| 331 queue_->OnHasTouchEventHandlers(true); | 322 queue_->OnHasTouchEventHandlers(true); |
| 332 } | 323 } |
| 333 | 324 |
| 334 std::unique_ptr<LegacyTouchEventQueue> queue_; | 325 std::unique_ptr<PassthroughTouchEventQueue> queue_; |
| 335 size_t acked_event_count_; | 326 size_t acked_event_count_; |
| 336 WebTouchEvent last_acked_event_; | 327 WebTouchEvent last_acked_event_; |
| 337 std::vector<WebTouchEvent> sent_events_; | 328 std::vector<WebTouchEvent> sent_events_; |
| 338 InputEventAckState last_acked_event_state_; | 329 InputEventAckState last_acked_event_state_; |
| 339 SyntheticWebTouchEvent touch_event_; | 330 SyntheticWebTouchEvent touch_event_; |
| 340 std::unique_ptr<WebTouchEvent> followup_touch_event_; | 331 std::unique_ptr<WebTouchEvent> followup_touch_event_; |
| 341 std::unique_ptr<WebGestureEvent> followup_gesture_event_; | 332 std::unique_ptr<WebGestureEvent> followup_gesture_event_; |
| 342 std::unique_ptr<InputEventAckState> sync_ack_result_; | 333 std::unique_ptr<InputEventAckState> sync_ack_result_; |
| 343 double slop_length_dips_; | 334 double slop_length_dips_; |
| 344 gfx::PointF anchor_; | 335 gfx::PointF anchor_; |
| 345 base::MessageLoopForUI message_loop_; | 336 base::MessageLoopForUI message_loop_; |
| 346 std::deque<int> sent_events_ids_; | 337 std::deque<int> sent_events_ids_; |
| 347 }; | 338 }; |
| 348 | 339 |
| 349 | |
| 350 // Tests that touch-events are queued properly. | 340 // Tests that touch-events are queued properly. |
| 351 TEST_F(TouchEventQueueTest, Basic) { | 341 TEST_F(PassthroughTouchEventQueueTest, Basic) { |
| 352 PressTouchPoint(1, 1); | 342 PressTouchPoint(1, 1); |
| 353 EXPECT_EQ(1U, queued_event_count()); | 343 EXPECT_EQ(1U, queued_event_count()); |
| 354 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 344 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 355 | 345 |
| 356 // The second touch should not be sent since one is already in queue. | 346 // The second touch should be sent right away even though |
| 347 // we haven't received an ack for the touch start. |
| 357 MoveTouchPoint(0, 5, 5); | 348 MoveTouchPoint(0, 5, 5); |
| 358 EXPECT_EQ(2U, queued_event_count()); | 349 EXPECT_EQ(2U, queued_event_count()); |
| 359 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 350 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 360 | 351 |
| 361 // Receive an ACK for the first touch-event. | 352 // Receive an ACK for the first touch-event. |
| 362 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); | 353 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 363 EXPECT_EQ(1U, queued_event_count()); | 354 EXPECT_EQ(1U, queued_event_count()); |
| 364 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 355 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 365 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 356 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 366 EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type()); | 357 EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type()); |
| 367 EXPECT_EQ(WebInputEvent::Blocking, acked_event().dispatchType); | 358 EXPECT_EQ(WebInputEvent::Blocking, acked_event().dispatchType); |
| 368 | 359 |
| 369 // Receive an ACK for the second touch-event. | 360 // Receive an ACK for the second touch-event. |
| 370 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); | 361 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 371 EXPECT_EQ(0U, queued_event_count()); | 362 EXPECT_EQ(0U, queued_event_count()); |
| 372 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 363 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 373 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 364 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 374 EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type()); | 365 EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type()); |
| 375 EXPECT_EQ(WebInputEvent::Blocking, acked_event().dispatchType); | 366 EXPECT_EQ(WebInputEvent::Blocking, acked_event().dispatchType); |
| 376 } | 367 } |
| 377 | 368 |
| 378 // Tests that touch-events with multiple points are queued properly. | 369 // Tests that touch-events with multiple points are queued properly. |
| 379 TEST_F(TouchEventQueueTest, BasicMultiTouch) { | 370 TEST_F(PassthroughTouchEventQueueTest, BasicMultiTouch) { |
| 380 const size_t kPointerCount = 10; | 371 const size_t kPointerCount = 10; |
| 381 for (float i = 0; i < kPointerCount; ++i) | 372 for (float i = 0; i < kPointerCount; ++i) |
| 382 PressTouchPoint(i, i); | 373 PressTouchPoint(i, i); |
| 383 | 374 |
| 384 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 375 EXPECT_EQ(kPointerCount, GetAndResetSentEventCount()); |
| 385 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | 376 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| 386 EXPECT_EQ(kPointerCount, queued_event_count()); | 377 EXPECT_EQ(kPointerCount, queued_event_count()); |
| 387 | 378 |
| 388 for (int i = 0; i < static_cast<int>(kPointerCount); ++i) | 379 for (int i = 0; i < static_cast<int>(kPointerCount); ++i) |
| 389 MoveTouchPoint(i, 1.f + i, 2.f + i); | 380 MoveTouchPoint(i, 1.f + i, 2.f + i); |
| 390 | 381 |
| 391 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 382 EXPECT_EQ(kPointerCount, GetAndResetSentEventCount()); |
| 392 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | 383 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| 393 // All moves should coalesce. | 384 // No coalescing happens in the queue since they are all sent immediately. |
| 394 EXPECT_EQ(kPointerCount + 1, queued_event_count()); | 385 EXPECT_EQ(2 * kPointerCount, queued_event_count()); |
| 395 | 386 |
| 396 for (int i = 0; i < static_cast<int>(kPointerCount); ++i) | 387 for (int i = 0; i < static_cast<int>(kPointerCount); ++i) |
| 397 ReleaseTouchPoint(kPointerCount - 1 - i); | 388 ReleaseTouchPoint(kPointerCount - 1 - i); |
| 398 | 389 |
| 399 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 390 EXPECT_EQ(kPointerCount, GetAndResetSentEventCount()); |
| 400 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | 391 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| 401 EXPECT_EQ(kPointerCount * 2 + 1, queued_event_count()); | 392 EXPECT_EQ(kPointerCount * 3, queued_event_count()); |
| 402 | 393 |
| 403 // Ack all presses. | 394 // Ack all presses. |
| 404 for (size_t i = 0; i < kPointerCount; ++i) | 395 for (size_t i = 0; i < kPointerCount; ++i) |
| 405 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); | 396 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 406 | 397 |
| 407 EXPECT_EQ(kPointerCount, GetAndResetAckedEventCount()); | 398 EXPECT_EQ(kPointerCount, GetAndResetAckedEventCount()); |
| 408 EXPECT_EQ(kPointerCount, GetAndResetSentEventCount()); | 399 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 409 | 400 |
| 410 // Ack the coalesced move. | 401 // Ack the touch moves. |
| 411 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); | 402 for (size_t i = 0; i < kPointerCount; ++i) |
| 403 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 412 EXPECT_EQ(kPointerCount, GetAndResetAckedEventCount()); | 404 EXPECT_EQ(kPointerCount, GetAndResetAckedEventCount()); |
| 413 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 405 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 414 | 406 |
| 415 // Ack all releases. | 407 // Ack all releases. |
| 416 for (size_t i = 0; i < kPointerCount; ++i) | 408 for (size_t i = 0; i < kPointerCount; ++i) |
| 417 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); | 409 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 418 | 410 |
| 419 EXPECT_EQ(kPointerCount, GetAndResetAckedEventCount()); | 411 EXPECT_EQ(kPointerCount, GetAndResetAckedEventCount()); |
| 420 EXPECT_EQ(kPointerCount - 1, GetAndResetSentEventCount()); | 412 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 421 } | 413 } |
| 422 | 414 |
| 423 // Tests that the touch-queue continues delivering events for an active touch | 415 // Tests that the touch-queue continues delivering events for an active touch |
| 424 // sequence after all handlers are removed. | 416 // sequence after all handlers are removed. |
| 425 TEST_F(TouchEventQueueTest, TouchesForwardedIfHandlerRemovedDuringSequence) { | 417 TEST_F(PassthroughTouchEventQueueTest, |
| 418 TouchesForwardedIfHandlerRemovedDuringSequence) { |
| 426 OnHasTouchEventHandlers(true); | 419 OnHasTouchEventHandlers(true); |
| 427 EXPECT_EQ(0U, queued_event_count()); | 420 EXPECT_EQ(0U, queued_event_count()); |
| 428 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 421 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 429 | 422 |
| 430 // Send a touch-press event. | 423 // Send a touch-press event. |
| 431 PressTouchPoint(1, 1); | 424 PressTouchPoint(1, 1); |
| 432 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 425 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 433 EXPECT_EQ(1U, queued_event_count()); | 426 EXPECT_EQ(1U, queued_event_count()); |
| 434 | 427 |
| 435 // Signal that all touch handlers have been removed. | 428 // Signal that all touch handlers have been removed. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 448 PressTouchPoint(2, 2); | 441 PressTouchPoint(2, 2); |
| 449 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 442 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 450 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); | 443 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); |
| 451 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 444 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 452 EXPECT_EQ(0U, queued_event_count()); | 445 EXPECT_EQ(0U, queued_event_count()); |
| 453 | 446 |
| 454 // Further events for any pointer should be forwarded, even for pointers that | 447 // Further events for any pointer should be forwarded, even for pointers that |
| 455 // reported no consumer. | 448 // reported no consumer. |
| 456 MoveTouchPoint(1, 3, 3); | 449 MoveTouchPoint(1, 3, 3); |
| 457 ReleaseTouchPoint(1); | 450 ReleaseTouchPoint(1); |
| 458 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 451 EXPECT_EQ(2U, GetAndResetSentEventCount()); |
| 459 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | 452 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| 460 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); | 453 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); |
| 461 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 454 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 462 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 455 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 463 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); | 456 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); |
| 464 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 457 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 465 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 458 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 466 | 459 |
| 467 // Events for the first pointer, that had a handler, should be forwarded. | 460 // Events for the first pointer, that had a handler, should be forwarded. |
| 468 MoveTouchPoint(0, 4, 4); | 461 MoveTouchPoint(0, 4, 4); |
| 469 ReleaseTouchPoint(0); | 462 ReleaseTouchPoint(0); |
| 470 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 463 EXPECT_EQ(2U, GetAndResetSentEventCount()); |
| 471 EXPECT_EQ(2U, queued_event_count()); | 464 EXPECT_EQ(2U, queued_event_count()); |
| 472 | 465 |
| 473 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); | 466 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 474 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 467 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 475 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 468 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 476 EXPECT_EQ(1U, queued_event_count()); | 469 EXPECT_EQ(1U, queued_event_count()); |
| 477 EXPECT_EQ(INPUT_EVENT_ACK_STATE_CONSUMED, acked_event_state()); | 470 EXPECT_EQ(INPUT_EVENT_ACK_STATE_CONSUMED, acked_event_state()); |
| 478 | 471 |
| 479 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); | 472 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 480 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 473 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 481 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 474 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 482 EXPECT_EQ(0U, queued_event_count()); | 475 EXPECT_EQ(0U, queued_event_count()); |
| 483 EXPECT_EQ(INPUT_EVENT_ACK_STATE_CONSUMED, acked_event_state()); | 476 EXPECT_EQ(INPUT_EVENT_ACK_STATE_CONSUMED, acked_event_state()); |
| 484 } | 477 } |
| 485 | 478 |
| 486 // Tests that addition of a touch handler during a touch sequence will not cause | 479 // Tests that addition of a touch handler during a touch sequence will not cause |
| 487 // the remaining sequence to be forwarded. | 480 // the remaining sequence to be forwarded. |
| 488 TEST_F(TouchEventQueueTest, ActiveSequenceNotForwardedWhenHandlersAdded) { | 481 TEST_F(PassthroughTouchEventQueueTest, |
| 482 ActiveSequenceNotForwardedWhenHandlersAdded) { |
| 489 OnHasTouchEventHandlers(false); | 483 OnHasTouchEventHandlers(false); |
| 490 | 484 |
| 491 // Send a touch-press event while there is no handler. | 485 // Send a touch-press event while there is no handler. |
| 492 PressTouchPoint(1, 1); | 486 PressTouchPoint(1, 1); |
| 493 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 487 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 494 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 488 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 495 EXPECT_EQ(0U, queued_event_count()); | 489 EXPECT_EQ(0U, queued_event_count()); |
| 496 | 490 |
| 497 OnHasTouchEventHandlers(true); | 491 OnHasTouchEventHandlers(true); |
| 498 | 492 |
| 499 // The remaining touch sequence should not be forwarded. | 493 // The remaining touch sequence should not be forwarded. |
| 500 MoveTouchPoint(0, 5, 5); | 494 MoveTouchPoint(0, 5, 5); |
| 501 ReleaseTouchPoint(0); | 495 ReleaseTouchPoint(0); |
| 502 EXPECT_EQ(2U, GetAndResetAckedEventCount()); | 496 EXPECT_EQ(2U, GetAndResetAckedEventCount()); |
| 503 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 497 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 504 EXPECT_EQ(0U, queued_event_count()); | 498 EXPECT_EQ(0U, queued_event_count()); |
| 505 | 499 |
| 506 // A new touch sequence should resume forwarding. | 500 // A new touch sequence should resume forwarding. |
| 507 PressTouchPoint(1, 1); | 501 PressTouchPoint(1, 1); |
| 508 EXPECT_EQ(1U, queued_event_count()); | 502 EXPECT_EQ(1U, queued_event_count()); |
| 509 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 503 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 510 } | 504 } |
| 511 | 505 |
| 512 // Tests that removal of a touch handler during a touch sequence will prevent | 506 // Tests that removal of a touch handler during a touch sequence will prevent |
| 513 // the remaining sequence from being forwarded, even if another touch handler is | 507 // the remaining sequence from being forwarded, even if another touch handler is |
| 514 // registered during the same touch sequence. | 508 // registered during the same touch sequence. |
| 515 TEST_F(TouchEventQueueTest, ActiveSequenceDroppedWhenHandlersRemoved) { | 509 TEST_F(PassthroughTouchEventQueueTest, |
| 510 ActiveSequenceDroppedWhenHandlersRemoved) { |
| 516 // Send a touch-press event. | 511 // Send a touch-press event. |
| 517 PressTouchPoint(1, 1); | 512 PressTouchPoint(1, 1); |
| 518 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 513 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 519 EXPECT_EQ(1U, queued_event_count()); | 514 EXPECT_EQ(1U, queued_event_count()); |
| 520 | 515 |
| 521 // Queue a touch-move event. | 516 // Queue a touch-move event. |
| 522 MoveTouchPoint(0, 5, 5); | 517 MoveTouchPoint(0, 5, 5); |
| 523 EXPECT_EQ(2U, queued_event_count()); | 518 EXPECT_EQ(2U, queued_event_count()); |
| 524 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | 519 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| 525 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 520 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 526 | 521 |
| 527 // Unregister all touch handlers. | 522 // Unregister all touch handlers. |
| 528 OnHasTouchEventHandlers(false); | 523 OnHasTouchEventHandlers(false); |
| 529 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | 524 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| 530 EXPECT_EQ(2U, queued_event_count()); | 525 EXPECT_EQ(2U, queued_event_count()); |
| 531 | 526 |
| 532 // Repeated registration/unregstration of handlers should have no effect as | 527 // Repeated registration/unregstration of handlers should have no effect as |
| 533 // we're still awaiting the ack arrival. | 528 // we're still awaiting the ack arrival. |
| 534 OnHasTouchEventHandlers(true); | 529 OnHasTouchEventHandlers(true); |
| 535 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | 530 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| 536 EXPECT_EQ(2U, queued_event_count()); | 531 EXPECT_EQ(2U, queued_event_count()); |
| 537 OnHasTouchEventHandlers(false); | 532 OnHasTouchEventHandlers(false); |
| 538 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | 533 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| 539 EXPECT_EQ(2U, queued_event_count()); | 534 EXPECT_EQ(2U, queued_event_count()); |
| 540 | 535 |
| 541 // The ack should be flush the queue. | 536 // clear the queue . |
| 537 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); |
| 542 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); | 538 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); |
| 543 EXPECT_EQ(2U, GetAndResetAckedEventCount()); | 539 EXPECT_EQ(2U, GetAndResetAckedEventCount()); |
| 544 EXPECT_EQ(0U, queued_event_count()); | 540 EXPECT_EQ(0U, queued_event_count()); |
| 545 | 541 |
| 546 // Events should be dropped while there is no touch handler. | 542 // Events should be dropped while there is no touch handler. |
| 547 MoveTouchPoint(0, 10, 10); | 543 MoveTouchPoint(0, 10, 10); |
| 548 EXPECT_EQ(0U, queued_event_count()); | 544 EXPECT_EQ(0U, queued_event_count()); |
| 549 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 545 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 550 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 546 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 551 | 547 |
| 552 // Simulate touch handler registration in the middle of a touch sequence. | 548 // Simulate touch handler registration in the middle of a touch sequence. |
| 553 OnHasTouchEventHandlers(true); | 549 OnHasTouchEventHandlers(true); |
| 554 | 550 |
| 555 // The touch end for the interrupted sequence should be dropped. | 551 // The touch end for the interrupted sequence should be dropped. |
| 556 ReleaseTouchPoint(0); | 552 ReleaseTouchPoint(0); |
| 557 EXPECT_EQ(0U, queued_event_count()); | 553 EXPECT_EQ(0U, queued_event_count()); |
| 558 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 554 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 559 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 555 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 560 | 556 |
| 561 // A new touch sequence should be forwarded properly. | 557 // A new touch sequence should be forwarded properly. |
| 562 PressTouchPoint(1, 1); | 558 PressTouchPoint(1, 1); |
| 563 EXPECT_EQ(1U, queued_event_count()); | 559 EXPECT_EQ(1U, queued_event_count()); |
| 564 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 560 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 565 } | 561 } |
| 566 | 562 |
| 567 // Tests that removal/addition of a touch handler without any intervening | 563 // Tests that removal/addition of a touch handler without any intervening |
| 568 // touch activity has no affect on touch forwarding. | 564 // touch activity has no affect on touch forwarding. |
| 569 TEST_F(TouchEventQueueTest, | 565 TEST_F(PassthroughTouchEventQueueTest, |
| 570 ActiveSequenceUnaffectedByRepeatedHandlerRemovalAndAddition) { | 566 ActiveSequenceUnaffectedByRepeatedHandlerRemovalAndAddition) { |
| 571 // Send a touch-press event. | 567 // Send a touch-press event. |
| 572 PressTouchPoint(1, 1); | 568 PressTouchPoint(1, 1); |
| 573 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 569 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 574 EXPECT_EQ(1U, queued_event_count()); | 570 EXPECT_EQ(1U, queued_event_count()); |
| 575 | 571 |
| 576 // Simulate the case where the touchstart handler removes itself, and adds a | 572 // Simulate the case where the touchstart handler removes itself, and adds a |
| 577 // touchmove handler. | 573 // touchmove handler. |
| 578 OnHasTouchEventHandlers(false); | 574 OnHasTouchEventHandlers(false); |
| 579 OnHasTouchEventHandlers(true); | 575 OnHasTouchEventHandlers(true); |
| 580 | 576 |
| 581 // Queue a touch-move event. | 577 // Queue a touch-move event, should be sent right away. |
| 582 MoveTouchPoint(0, 5, 5); | 578 MoveTouchPoint(0, 5, 5); |
| 583 EXPECT_EQ(2U, queued_event_count()); | 579 EXPECT_EQ(2U, queued_event_count()); |
| 584 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | 580 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| 585 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 581 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 586 | 582 |
| 587 // The ack should trigger forwarding of the touchmove, as if no touch | 583 // The ack should trigger forwarding of the touchmove, as if no touch |
| 588 // handler registration changes have occurred. | 584 // handler registration changes have occurred. |
| 589 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 585 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 590 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 586 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 591 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 587 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 592 EXPECT_EQ(1U, queued_event_count()); | 588 EXPECT_EQ(1U, queued_event_count()); |
| 593 } | 589 } |
| 594 | 590 |
| 595 // Tests that touch-events are coalesced properly in the queue. | |
| 596 TEST_F(TouchEventQueueTest, Coalesce) { | |
| 597 // Send a touch-press event. | |
| 598 PressTouchPoint(1, 1); | |
| 599 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 600 | |
| 601 // Send a few touch-move events, followed by a touch-release event. All the | |
| 602 // touch-move events should be coalesced into a single event. | |
| 603 for (float i = 5; i < 15; ++i) | |
| 604 MoveTouchPoint(0, i, i); | |
| 605 | |
| 606 EXPECT_EQ(0U, GetAndResetSentEventCount()); | |
| 607 ReleaseTouchPoint(0); | |
| 608 EXPECT_EQ(0U, GetAndResetSentEventCount()); | |
| 609 EXPECT_EQ(3U, queued_event_count()); | |
| 610 | |
| 611 // ACK the press. Coalesced touch-move events should be sent. | |
| 612 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); | |
| 613 EXPECT_EQ(2U, queued_event_count()); | |
| 614 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 615 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 616 EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type()); | |
| 617 EXPECT_EQ(INPUT_EVENT_ACK_STATE_CONSUMED, acked_event_state()); | |
| 618 | |
| 619 // ACK the moves. | |
| 620 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); | |
| 621 EXPECT_EQ(1U, queued_event_count()); | |
| 622 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 623 EXPECT_EQ(10U, GetAndResetAckedEventCount()); | |
| 624 EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type()); | |
| 625 | |
| 626 // ACK the release. | |
| 627 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); | |
| 628 EXPECT_EQ(0U, queued_event_count()); | |
| 629 EXPECT_EQ(0U, GetAndResetSentEventCount()); | |
| 630 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 631 EXPECT_EQ(WebInputEvent::TouchEnd, acked_event().type()); | |
| 632 } | |
| 633 | |
| 634 // Tests that an event that has already been sent but hasn't been ack'ed yet | |
| 635 // doesn't get coalesced with newer events. | |
| 636 TEST_F(TouchEventQueueTest, SentTouchEventDoesNotCoalesce) { | |
| 637 // Send a touch-press event. | |
| 638 PressTouchPoint(1, 1); | |
| 639 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 640 | |
| 641 // Send a few touch-move events, followed by a touch-release event. All the | |
| 642 // touch-move events should be coalesced into a single event. | |
| 643 for (float i = 5; i < 15; ++i) | |
| 644 MoveTouchPoint(0, i, i); | |
| 645 | |
| 646 EXPECT_EQ(0U, GetAndResetSentEventCount()); | |
| 647 EXPECT_EQ(2U, queued_event_count()); | |
| 648 | |
| 649 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 650 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 651 EXPECT_EQ(1U, queued_event_count()); | |
| 652 | |
| 653 // The coalesced touch-move event has been sent to the renderer. Any new | |
| 654 // touch-move event should not be coalesced with the sent event. | |
| 655 MoveTouchPoint(0, 5, 5); | |
| 656 EXPECT_EQ(2U, queued_event_count()); | |
| 657 | |
| 658 MoveTouchPoint(0, 7, 7); | |
| 659 EXPECT_EQ(2U, queued_event_count()); | |
| 660 } | |
| 661 | |
| 662 // Tests that coalescing works correctly for multi-touch events. | |
| 663 TEST_F(TouchEventQueueTest, MultiTouch) { | |
| 664 // Press the first finger. | |
| 665 PressTouchPoint(1, 1); | |
| 666 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 667 | |
| 668 // Move the finger. | |
| 669 MoveTouchPoint(0, 5, 5); | |
| 670 EXPECT_EQ(2U, queued_event_count()); | |
| 671 | |
| 672 // Now press a second finger. | |
| 673 PressTouchPoint(2, 2); | |
| 674 EXPECT_EQ(3U, queued_event_count()); | |
| 675 | |
| 676 // Move both fingers. | |
| 677 MoveTouchPoints(0, 10, 10, 1, 20, 20); | |
| 678 MoveTouchPoint(1, 20, 20); | |
| 679 EXPECT_EQ(4U, queued_event_count()); | |
| 680 | |
| 681 // Move only one finger now. | |
| 682 MoveTouchPoint(0, 15, 15); | |
| 683 EXPECT_EQ(4U, queued_event_count()); | |
| 684 | |
| 685 // Move the other finger. | |
| 686 MoveTouchPoint(1, 25, 25); | |
| 687 EXPECT_EQ(4U, queued_event_count()); | |
| 688 | |
| 689 // Make sure both fingers are marked as having been moved in the coalesced | |
| 690 // event. | |
| 691 const WebTouchEvent& event = latest_event(); | |
| 692 EXPECT_EQ(WebTouchPoint::StateMoved, event.touches[0].state); | |
| 693 EXPECT_EQ(WebTouchPoint::StateMoved, event.touches[1].state); | |
| 694 } | |
| 695 | |
| 696 // Tests that the touch-event queue is robust to redundant acks. | 591 // Tests that the touch-event queue is robust to redundant acks. |
| 697 TEST_F(TouchEventQueueTest, SpuriousAcksIgnored) { | 592 TEST_F(PassthroughTouchEventQueueTest, SpuriousAcksIgnored) { |
| 698 // Trigger a spurious ack. | 593 // Trigger a spurious ack. |
| 699 SendTouchEventAckWithID(INPUT_EVENT_ACK_STATE_CONSUMED, 0); | 594 SendTouchEventAckWithID(INPUT_EVENT_ACK_STATE_CONSUMED, 0); |
| 700 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | 595 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| 701 | 596 |
| 702 // Send and ack a touch press. | 597 // Send and ack a touch press. |
| 703 PressTouchPoint(1, 1); | 598 PressTouchPoint(1, 1); |
| 704 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 599 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 705 EXPECT_EQ(1U, queued_event_count()); | 600 EXPECT_EQ(1U, queued_event_count()); |
| 706 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); | 601 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 707 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 602 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 708 EXPECT_EQ(0U, queued_event_count()); | 603 EXPECT_EQ(0U, queued_event_count()); |
| 709 | 604 |
| 710 // Trigger a spurious ack. | 605 // Trigger a spurious ack. |
| 711 SendTouchEventAckWithID(INPUT_EVENT_ACK_STATE_CONSUMED, 3); | 606 SendTouchEventAckWithID(INPUT_EVENT_ACK_STATE_CONSUMED, 3); |
| 712 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | 607 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| 713 } | 608 } |
| 714 | 609 |
| 715 // Tests that touch-move events are not sent to the renderer if the preceding | 610 // Tests that touch-move events are not sent to the renderer if the preceding |
| 716 // touch-press event did not have a consumer (and consequently, did not hit the | 611 // touch-press event did not have a consumer (and consequently, did not hit the |
| 717 // main thread in the renderer). Also tests that all queued/coalesced touch | 612 // main thread in the renderer). |
| 718 // events are flushed immediately when the ACK for the touch-press comes back | 613 TEST_F(PassthroughTouchEventQueueTest, NoConsumer) { |
| 719 // with NO_CONSUMER status. | |
| 720 TEST_F(TouchEventQueueTest, NoConsumer) { | |
| 721 // The first touch-press should reach the renderer. | 614 // The first touch-press should reach the renderer. |
| 722 PressTouchPoint(1, 1); | 615 PressTouchPoint(1, 1); |
| 723 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 616 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 724 | 617 |
| 725 // The second touch should not be sent since one is already in queue. | 618 // The second touch should be sent since we don't know if there is |
| 619 // a consumer or not. |
| 726 MoveTouchPoint(0, 5, 5); | 620 MoveTouchPoint(0, 5, 5); |
| 727 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 621 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 728 EXPECT_EQ(2U, queued_event_count()); | 622 EXPECT_EQ(2U, queued_event_count()); |
| 729 | 623 |
| 730 // Receive an ACK for the first touch-event. This should release the queued | 624 // Receive an ACK for the first touch-event and the first touch-move |
| 731 // touch-event, but it should not be sent to the renderer. | 625 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); |
| 732 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); | 626 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); |
| 733 EXPECT_EQ(0U, queued_event_count()); | 627 EXPECT_EQ(0U, queued_event_count()); |
| 734 EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type()); | |
| 735 EXPECT_EQ(2U, GetAndResetAckedEventCount()); | 628 EXPECT_EQ(2U, GetAndResetAckedEventCount()); |
| 736 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 629 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 737 | 630 |
| 738 // Send a release event. This should not reach the renderer. | 631 // Send a release event. This should not reach the renderer. |
| 739 ReleaseTouchPoint(0); | 632 ReleaseTouchPoint(0); |
| 740 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 633 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 741 EXPECT_EQ(WebInputEvent::TouchEnd, acked_event().type()); | 634 EXPECT_EQ(WebInputEvent::TouchEnd, acked_event().type()); |
| 742 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 635 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 743 | 636 |
| 744 // Send a press-event, followed by move and release events, and another press | 637 // Send a press-event, followed by move a following move should not |
| 745 // event, before the ACK for the first press event comes back. All of the | 638 // be sent but held in the queue. |
| 746 // events should be queued first. After the NO_CONSUMER ack for the first | |
| 747 // touch-press, all events upto the second touch-press should be flushed. | |
| 748 PressTouchPoint(10, 10); | 639 PressTouchPoint(10, 10); |
| 749 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 640 MoveTouchPoint(0, 5, 5); |
| 750 | 641 |
| 642 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); |
| 643 EXPECT_EQ(2U, GetAndResetSentEventCount()); |
| 644 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 645 |
| 646 MoveTouchPoint(0, 6, 5); |
| 647 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 648 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| 649 EXPECT_EQ(2U, queued_event_count()); |
| 650 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 651 EXPECT_EQ(2U, GetAndResetAckedEventCount()); |
| 652 } |
| 653 |
| 654 TEST_F(PassthroughTouchEventQueueTest, AckTouchEventInReverse) { |
| 655 PressTouchPoint(1, 1); |
| 751 MoveTouchPoint(0, 5, 5); | 656 MoveTouchPoint(0, 5, 5); |
| 752 MoveTouchPoint(0, 6, 5); | 657 MoveTouchPoint(0, 15, 15); |
| 753 ReleaseTouchPoint(0); | 658 ReleaseTouchPoint(0); |
| 754 | 659 |
| 755 PressTouchPoint(6, 5); | 660 EXPECT_EQ(4U, GetAndResetSentEventCount()); |
| 756 EXPECT_EQ(0U, GetAndResetSentEventCount()); | |
| 757 // The queue should hold the first sent touch-press event, the coalesced | |
| 758 // touch-move event, the touch-end event and the second touch-press event. | |
| 759 EXPECT_EQ(4U, queued_event_count()); | 661 EXPECT_EQ(4U, queued_event_count()); |
| 760 | 662 |
| 761 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); | 663 SendTouchEventAckLast(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 762 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 664 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| 763 EXPECT_EQ(WebInputEvent::TouchEnd, acked_event().type()); | 665 EXPECT_EQ(4U, queued_event_count()); |
| 764 EXPECT_EQ(4U, GetAndResetAckedEventCount()); | |
| 765 EXPECT_EQ(1U, queued_event_count()); | |
| 766 | 666 |
| 767 // ACK the second press event as NO_CONSUMER too. | |
| 768 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); | |
| 769 EXPECT_EQ(0U, GetAndResetSentEventCount()); | |
| 770 EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type()); | |
| 771 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 772 EXPECT_EQ(0U, queued_event_count()); | |
| 773 | |
| 774 // Send a second press event. Even though the first touch press had | |
| 775 // NO_CONSUMER, this press event should reach the renderer. | |
| 776 PressTouchPoint(1, 1); | |
| 777 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 778 EXPECT_EQ(1U, queued_event_count()); | |
| 779 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); | 667 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 780 EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type()); | 668 EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type()); |
| 781 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 669 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 782 } | 670 EXPECT_EQ(3U, queued_event_count()); |
| 783 | 671 |
| 784 TEST_F(TouchEventQueueTest, ConsumerIgnoreMultiFinger) { | 672 SendTouchEventAckLast(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 785 // Interleave three pointer press, move and release events. | 673 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| 786 PressTouchPoint(1, 1); | 674 EXPECT_EQ(3U, queued_event_count()); |
| 787 MoveTouchPoint(0, 5, 5); | |
| 788 PressTouchPoint(10, 10); | |
| 789 MoveTouchPoint(1, 15, 15); | |
| 790 PressTouchPoint(20, 20); | |
| 791 MoveTouchPoint(2, 25, 25); | |
| 792 ReleaseTouchPoint(2); | |
| 793 MoveTouchPoint(1, 20, 20); | |
| 794 ReleaseTouchPoint(1); | |
| 795 MoveTouchPoint(0, 10, 10); | |
| 796 ReleaseTouchPoint(0); | |
| 797 | 675 |
| 798 // Since the first touch-press is still pending ACK, no other event should | 676 SendTouchEventAckLast(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 799 // have been sent to the renderer. | 677 EXPECT_EQ(WebInputEvent::TouchEnd, acked_event().type()); |
| 800 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 678 EXPECT_EQ(3U, GetAndResetAckedEventCount()); |
| 801 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 679 EXPECT_EQ(0U, queued_event_count()); |
| 802 EXPECT_EQ(11U, queued_event_count()); | |
| 803 | |
| 804 // ACK the first press as CONSUMED. This should cause the first touch-move of | |
| 805 // the first touch-point to be dispatched. | |
| 806 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); | |
| 807 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 808 EXPECT_EQ(10U, queued_event_count()); | |
| 809 | |
| 810 // ACK the first move as CONSUMED. | |
| 811 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); | |
| 812 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 813 EXPECT_EQ(9U, queued_event_count()); | |
| 814 | |
| 815 // ACK the second press as NO_CONSUMER_EXISTS. The second pointer's touchmove | |
| 816 // should still be forwarded, despite lacking a direct consumer. | |
| 817 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); | |
| 818 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 819 EXPECT_EQ(8U, queued_event_count()); | |
| 820 | |
| 821 // ACK the coalesced move as NOT_CONSUMED. | |
| 822 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 823 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 824 EXPECT_EQ(7U, queued_event_count()); | |
| 825 | |
| 826 // All remaining touch events should be forwarded, even if the third pointer | |
| 827 // press also reports no consumer. | |
| 828 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); | |
| 829 EXPECT_EQ(6U, queued_event_count()); | |
| 830 | |
| 831 while (queued_event_count()) | |
| 832 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 833 | |
| 834 EXPECT_EQ(6U, GetAndResetSentEventCount()); | |
| 835 } | 680 } |
| 836 | 681 |
| 837 // Tests that touch-event's enqueued via a touch ack are properly handled. | 682 // Tests that touch-event's enqueued via a touch ack are properly handled. |
| 838 TEST_F(TouchEventQueueTest, AckWithFollowupEvents) { | 683 TEST_F(PassthroughTouchEventQueueTest, AckWithFollowupEvents) { |
| 839 // Queue a touch down. | 684 // Queue a touch down. |
| 840 PressTouchPoint(1, 1); | 685 PressTouchPoint(1, 1); |
| 841 EXPECT_EQ(1U, queued_event_count()); | 686 EXPECT_EQ(1U, queued_event_count()); |
| 842 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 687 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 843 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | 688 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| 844 | 689 |
| 845 // Create a touch event that will be queued synchronously by a touch ack. | 690 // Create a touch event that will be queued synchronously by a touch ack. |
| 846 // Note, this will be triggered by all subsequent touch acks. | 691 // Note, this will be triggered by all subsequent touch acks. |
| 847 WebTouchEvent followup_event( | 692 WebTouchEvent followup_event( |
| 848 WebInputEvent::TouchMove, WebInputEvent::NoModifiers, | 693 WebInputEvent::TouchMove, WebInputEvent::NoModifiers, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 867 | 712 |
| 868 // Receive an ACK for the touch-move followup event. This should cause the | 713 // Receive an ACK for the touch-move followup event. This should cause the |
| 869 // subsequent touch move event be sent to the renderer. | 714 // subsequent touch move event be sent to the renderer. |
| 870 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); | 715 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 871 EXPECT_EQ(1U, queued_event_count()); | 716 EXPECT_EQ(1U, queued_event_count()); |
| 872 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 717 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 873 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 718 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 874 } | 719 } |
| 875 | 720 |
| 876 // Tests that touch-events can be synchronously ack'ed. | 721 // Tests that touch-events can be synchronously ack'ed. |
| 877 TEST_F(TouchEventQueueTest, SynchronousAcks) { | 722 TEST_F(PassthroughTouchEventQueueTest, SynchronousAcks) { |
| 878 // TouchStart | 723 // TouchStart |
| 879 SetSyncAckResult(INPUT_EVENT_ACK_STATE_CONSUMED); | 724 SetSyncAckResult(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 880 PressTouchPoint(1, 1); | 725 PressTouchPoint(1, 1); |
| 881 EXPECT_EQ(0U, queued_event_count()); | 726 EXPECT_EQ(0U, queued_event_count()); |
| 882 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 727 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 883 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 728 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 884 | 729 |
| 885 // TouchMove | 730 // TouchMove |
| 886 SetSyncAckResult(INPUT_EVENT_ACK_STATE_CONSUMED); | 731 SetSyncAckResult(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 887 MoveTouchPoint(0, 2, 2); | 732 MoveTouchPoint(0, 2, 2); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 905 | 750 |
| 906 SetSyncAckResult(INPUT_EVENT_ACK_STATE_CONSUMED); | 751 SetSyncAckResult(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 907 CancelTouchPoint(0); | 752 CancelTouchPoint(0); |
| 908 EXPECT_EQ(0U, queued_event_count()); | 753 EXPECT_EQ(0U, queued_event_count()); |
| 909 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 754 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 910 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 755 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 911 } | 756 } |
| 912 | 757 |
| 913 // Tests that followup events triggered by an immediate ack from | 758 // Tests that followup events triggered by an immediate ack from |
| 914 // TouchEventQueue::QueueEvent() are properly handled. | 759 // TouchEventQueue::QueueEvent() are properly handled. |
| 915 TEST_F(TouchEventQueueTest, ImmediateAckWithFollowupEvents) { | 760 TEST_F(PassthroughTouchEventQueueTest, ImmediateAckWithFollowupEvents) { |
| 916 // Create a touch event that will be queued synchronously by a touch ack. | 761 // Create a touch event that will be queued synchronously by a touch ack. |
| 917 WebTouchEvent followup_event( | 762 WebTouchEvent followup_event( |
| 918 WebInputEvent::TouchStart, WebInputEvent::NoModifiers, | 763 WebInputEvent::TouchStart, WebInputEvent::NoModifiers, |
| 919 ui::EventTimeStampToSeconds(ui::EventTimeForNow())); | 764 ui::EventTimeStampToSeconds(ui::EventTimeForNow())); |
| 920 followup_event.touchesLength = 1; | 765 followup_event.touchesLength = 1; |
| 921 followup_event.touches[0].id = 1; | 766 followup_event.touches[0].id = 1; |
| 922 followup_event.touches[0].state = WebTouchPoint::StatePressed; | 767 followup_event.touches[0].state = WebTouchPoint::StatePressed; |
| 923 SetFollowupEvent(followup_event); | 768 SetFollowupEvent(followup_event); |
| 924 | 769 |
| 925 // Now, enqueue a stationary touch that will not be forwarded. This should be | 770 // Now, enqueue a stationary touch that will not be forwarded. This should be |
| 926 // immediately ack'ed with "NO_CONSUMER_EXISTS". The followup event should | 771 // immediately ack'ed with "NO_CONSUMER_EXISTS". The followup event should |
| 927 // then be enqueued and immediately sent to the renderer. | 772 // then be enqueued and immediately sent to the renderer. |
| 928 WebTouchEvent stationary_event( | 773 WebTouchEvent stationary_event( |
| 929 WebInputEvent::TouchMove, WebInputEvent::NoModifiers, | 774 WebInputEvent::TouchMove, WebInputEvent::NoModifiers, |
| 930 ui::EventTimeStampToSeconds(ui::EventTimeForNow())); | 775 ui::EventTimeStampToSeconds(ui::EventTimeForNow())); |
| 931 ; | 776 ; |
| 932 stationary_event.touchesLength = 1; | 777 stationary_event.touchesLength = 1; |
| 933 stationary_event.touches[0].id = 1; | 778 stationary_event.touches[0].id = 1; |
| 934 stationary_event.touches[0].state = WebTouchPoint::StateStationary; | 779 stationary_event.touches[0].state = WebTouchPoint::StateStationary; |
| 935 SendTouchEvent(stationary_event); | 780 SendTouchEvent(stationary_event); |
| 936 | 781 |
| 937 EXPECT_EQ(1U, queued_event_count()); | 782 EXPECT_EQ(1U, queued_event_count()); |
| 938 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 783 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 939 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 784 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 940 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, acked_event_state()); | 785 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, acked_event_state()); |
| 941 EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type()); | 786 EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type()); |
| 942 } | 787 } |
| 943 | 788 |
| 944 // Tests basic TouchEvent forwarding suppression. | 789 // Tests basic TouchEvent forwarding suppression. |
| 945 TEST_F(TouchEventQueueTest, NoTouchBasic) { | 790 TEST_F(PassthroughTouchEventQueueTest, NoTouchBasic) { |
| 946 // Disable TouchEvent forwarding. | 791 // Disable TouchEvent forwarding. |
| 947 OnHasTouchEventHandlers(false); | 792 OnHasTouchEventHandlers(false); |
| 948 PressTouchPoint(30, 5); | 793 PressTouchPoint(30, 5); |
| 949 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 794 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 950 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 795 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 951 | 796 |
| 952 // TouchMove should not be sent to renderer. | 797 // TouchMove should not be sent to renderer. |
| 953 MoveTouchPoint(0, 65, 10); | 798 MoveTouchPoint(0, 65, 10); |
| 954 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 799 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 955 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 800 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 972 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 817 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 973 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 818 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 974 | 819 |
| 975 ReleaseTouchPoint(0); | 820 ReleaseTouchPoint(0); |
| 976 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 821 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 977 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 822 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 978 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 823 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 979 } | 824 } |
| 980 | 825 |
| 981 // Tests that IsTouchStartPendingAck works correctly. | 826 // Tests that IsTouchStartPendingAck works correctly. |
| 982 TEST_F(TouchEventQueueTest, PendingStart) { | 827 TEST_F(PassthroughTouchEventQueueTest, PendingStart) { |
| 983 | |
| 984 EXPECT_FALSE(IsPendingAckTouchStart()); | 828 EXPECT_FALSE(IsPendingAckTouchStart()); |
| 985 | 829 |
| 986 // Send the touchstart for one point (#1). | 830 // Send the touchstart for one point (#1). |
| 987 PressTouchPoint(1, 1); | 831 PressTouchPoint(1, 1); |
| 988 EXPECT_EQ(1U, queued_event_count()); | 832 EXPECT_EQ(1U, queued_event_count()); |
| 989 EXPECT_TRUE(IsPendingAckTouchStart()); | 833 EXPECT_TRUE(IsPendingAckTouchStart()); |
| 990 | 834 |
| 991 // Send a touchmove for that point (#2). | 835 // Send a touchmove for that point (#2). |
| 992 MoveTouchPoint(0, 5, 5); | 836 MoveTouchPoint(0, 5, 5); |
| 993 EXPECT_EQ(2U, queued_event_count()); | 837 EXPECT_EQ(2U, queued_event_count()); |
| 994 EXPECT_TRUE(IsPendingAckTouchStart()); | 838 EXPECT_TRUE(IsPendingAckTouchStart()); |
| 995 | 839 |
| 996 // Ack the touchstart (#1). | 840 // Ack the touchstart (#1). |
| 997 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 841 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 998 EXPECT_EQ(1U, queued_event_count()); | 842 EXPECT_EQ(1U, queued_event_count()); |
| 999 EXPECT_FALSE(IsPendingAckTouchStart()); | 843 EXPECT_FALSE(IsPendingAckTouchStart()); |
| 1000 | 844 |
| 1001 // Send a touchstart for another point (#3). | 845 // Send a touchstart for another point (#3). |
| 1002 PressTouchPoint(10, 10); | 846 PressTouchPoint(10, 10); |
| 1003 EXPECT_EQ(2U, queued_event_count()); | 847 EXPECT_EQ(2U, queued_event_count()); |
| 1004 EXPECT_FALSE(IsPendingAckTouchStart()); | 848 EXPECT_TRUE(IsPendingAckTouchStart()); |
| 1005 | 849 |
| 1006 // Ack the touchmove (#2). | 850 // Ack the touchmove (#2). |
| 1007 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 851 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1008 EXPECT_EQ(1U, queued_event_count()); | 852 EXPECT_EQ(1U, queued_event_count()); |
| 1009 EXPECT_TRUE(IsPendingAckTouchStart()); | 853 EXPECT_TRUE(IsPendingAckTouchStart()); |
| 1010 | 854 |
| 1011 // Send a touchstart for a third point (#4). | 855 // Send a touchstart for a third point (#4). |
| 1012 PressTouchPoint(15, 15); | 856 PressTouchPoint(15, 15); |
| 1013 EXPECT_EQ(2U, queued_event_count()); | 857 EXPECT_EQ(2U, queued_event_count()); |
| 1014 EXPECT_TRUE(IsPendingAckTouchStart()); | 858 EXPECT_TRUE(IsPendingAckTouchStart()); |
| 1015 | 859 |
| 1016 // Ack the touchstart for the second point (#3). | 860 // Ack the touchstart for the second point (#3). |
| 1017 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 861 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1018 EXPECT_EQ(1U, queued_event_count()); | 862 EXPECT_EQ(1U, queued_event_count()); |
| 1019 EXPECT_TRUE(IsPendingAckTouchStart()); | 863 EXPECT_TRUE(IsPendingAckTouchStart()); |
| 1020 | 864 |
| 1021 // Ack the touchstart for the third point (#4). | 865 // Ack the touchstart for the third point (#4). |
| 1022 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 866 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1023 EXPECT_EQ(0U, queued_event_count()); | 867 EXPECT_EQ(0U, queued_event_count()); |
| 1024 EXPECT_FALSE(IsPendingAckTouchStart()); | 868 EXPECT_FALSE(IsPendingAckTouchStart()); |
| 1025 } | 869 } |
| 1026 | 870 |
| 1027 // Tests that the touch timeout is started when sending certain touch types. | 871 // Tests that the touch timeout is started when sending certain touch types. |
| 1028 TEST_F(TouchEventQueueTest, TouchTimeoutTypes) { | 872 TEST_F(PassthroughTouchEventQueueTest, TouchTimeoutTypes) { |
| 1029 SetUpForTimeoutTesting(); | 873 SetUpForTimeoutTesting(); |
| 1030 | 874 |
| 1031 // Sending a TouchStart will start the timeout. | 875 // Sending a TouchStart will start the timeout. |
| 1032 PressTouchPoint(0, 1); | 876 PressTouchPoint(0, 1); |
| 1033 EXPECT_TRUE(IsTimeoutRunning()); | 877 EXPECT_TRUE(IsTimeoutRunning()); |
| 1034 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 878 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1035 EXPECT_FALSE(IsTimeoutRunning()); | 879 EXPECT_FALSE(IsTimeoutRunning()); |
| 1036 | 880 |
| 1037 // A TouchMove should start the timeout. | 881 // A TouchMove should start the timeout. |
| 1038 MoveTouchPoint(0, 5, 5); | 882 MoveTouchPoint(0, 5, 5); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1052 ASSERT_FALSE(IsTimeoutRunning()); | 896 ASSERT_FALSE(IsTimeoutRunning()); |
| 1053 CancelTouchPoint(0); | 897 CancelTouchPoint(0); |
| 1054 EXPECT_FALSE(IsTimeoutRunning()); | 898 EXPECT_FALSE(IsTimeoutRunning()); |
| 1055 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 899 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1056 EXPECT_FALSE(IsTimeoutRunning()); | 900 EXPECT_FALSE(IsTimeoutRunning()); |
| 1057 } | 901 } |
| 1058 | 902 |
| 1059 // Tests that a delayed TouchEvent ack will trigger a TouchCancel timeout, | 903 // Tests that a delayed TouchEvent ack will trigger a TouchCancel timeout, |
| 1060 // disabling touch forwarding until the next TouchStart is received after | 904 // disabling touch forwarding until the next TouchStart is received after |
| 1061 // the timeout events are ack'ed. | 905 // the timeout events are ack'ed. |
| 1062 TEST_F(TouchEventQueueTest, TouchTimeoutBasic) { | 906 TEST_F(PassthroughTouchEventQueueTest, TouchTimeoutBasic) { |
| 1063 SetUpForTimeoutTesting(); | 907 SetUpForTimeoutTesting(); |
| 1064 | 908 |
| 1065 // Queue a TouchStart. | 909 // Queue a TouchStart. |
| 1066 GetAndResetSentEventCount(); | 910 GetAndResetSentEventCount(); |
| 1067 GetAndResetAckedEventCount(); | 911 GetAndResetAckedEventCount(); |
| 1068 PressTouchPoint(0, 1); | 912 PressTouchPoint(0, 1); |
| 1069 ASSERT_EQ(1U, GetAndResetSentEventCount()); | 913 ASSERT_EQ(1U, GetAndResetSentEventCount()); |
| 1070 ASSERT_EQ(0U, GetAndResetAckedEventCount()); | 914 ASSERT_EQ(0U, GetAndResetAckedEventCount()); |
| 1071 EXPECT_TRUE(IsTimeoutRunning()); | 915 EXPECT_TRUE(IsTimeoutRunning()); |
| 1072 | 916 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1106 // Subsequent events should be handled normally. | 950 // Subsequent events should be handled normally. |
| 1107 PressTouchPoint(0, 1); | 951 PressTouchPoint(0, 1); |
| 1108 EXPECT_EQ(WebInputEvent::TouchStart, sent_event().type()); | 952 EXPECT_EQ(WebInputEvent::TouchStart, sent_event().type()); |
| 1109 EXPECT_EQ(WebInputEvent::Blocking, sent_event().dispatchType); | 953 EXPECT_EQ(WebInputEvent::Blocking, sent_event().dispatchType); |
| 1110 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 954 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 1111 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | 955 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| 1112 } | 956 } |
| 1113 | 957 |
| 1114 // Tests that the timeout is never started if the renderer consumes | 958 // Tests that the timeout is never started if the renderer consumes |
| 1115 // a TouchEvent from the current touch sequence. | 959 // a TouchEvent from the current touch sequence. |
| 1116 TEST_F(TouchEventQueueTest, NoTouchTimeoutIfRendererIsConsumingGesture) { | 960 TEST_F(PassthroughTouchEventQueueTest, |
| 961 NoTouchTimeoutIfRendererIsConsumingGesture) { |
| 1117 SetUpForTimeoutTesting(); | 962 SetUpForTimeoutTesting(); |
| 1118 | 963 |
| 1119 // Queue a TouchStart. | 964 // Queue a TouchStart. |
| 1120 PressTouchPoint(0, 1); | 965 PressTouchPoint(0, 1); |
| 1121 ASSERT_TRUE(IsTimeoutRunning()); | 966 ASSERT_TRUE(IsTimeoutRunning()); |
| 1122 | 967 |
| 1123 // Mark the event as consumed. This should prevent the timeout from | 968 // Mark the event as consumed. This should prevent the timeout from |
| 1124 // being activated on subsequent TouchEvents in this gesture. | 969 // being activated on subsequent TouchEvents in this gesture. |
| 1125 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); | 970 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 1126 EXPECT_FALSE(IsTimeoutRunning()); | 971 EXPECT_FALSE(IsTimeoutRunning()); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1140 EXPECT_FALSE(IsTimeoutRunning()); | 985 EXPECT_FALSE(IsTimeoutRunning()); |
| 1141 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 986 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1142 | 987 |
| 1143 // A TouchCancel should not start the timeout. | 988 // A TouchCancel should not start the timeout. |
| 1144 CancelTouchPoint(0); | 989 CancelTouchPoint(0); |
| 1145 EXPECT_FALSE(IsTimeoutRunning()); | 990 EXPECT_FALSE(IsTimeoutRunning()); |
| 1146 } | 991 } |
| 1147 | 992 |
| 1148 // Tests that the timeout is never started if the renderer consumes | 993 // Tests that the timeout is never started if the renderer consumes |
| 1149 // a TouchEvent from the current touch sequence. | 994 // a TouchEvent from the current touch sequence. |
| 1150 TEST_F(TouchEventQueueTest, NoTouchTimeoutIfDisabledAfterTouchStart) { | 995 TEST_F(PassthroughTouchEventQueueTest, |
| 996 NoTouchTimeoutIfDisabledAfterTouchStart) { |
| 1151 SetUpForTimeoutTesting(); | 997 SetUpForTimeoutTesting(); |
| 1152 | 998 |
| 1153 // Queue a TouchStart. | 999 // Queue a TouchStart. |
| 1154 PressTouchPoint(0, 1); | 1000 PressTouchPoint(0, 1); |
| 1155 ASSERT_TRUE(IsTimeoutRunning()); | 1001 ASSERT_TRUE(IsTimeoutRunning()); |
| 1156 | 1002 |
| 1157 // Send the ack immediately. The timeout should not have fired. | 1003 // Send the ack immediately. The timeout should not have fired. |
| 1158 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1004 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1159 EXPECT_FALSE(IsTimeoutRunning()); | 1005 EXPECT_FALSE(IsTimeoutRunning()); |
| 1160 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 1006 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 1161 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 1007 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 1162 | 1008 |
| 1163 // Now explicitly disable the timeout. | 1009 // Now explicitly disable the timeout. |
| 1164 SetAckTimeoutDisabled(); | 1010 SetAckTimeoutDisabled(); |
| 1165 EXPECT_FALSE(IsTimeoutRunning()); | 1011 EXPECT_FALSE(IsTimeoutRunning()); |
| 1166 | 1012 |
| 1167 // A TouchMove should not start or trigger the timeout. | 1013 // A TouchMove should not start or trigger the timeout. |
| 1168 MoveTouchPoint(0, 5, 5); | 1014 MoveTouchPoint(0, 5, 5); |
| 1169 EXPECT_FALSE(IsTimeoutRunning()); | 1015 EXPECT_FALSE(IsTimeoutRunning()); |
| 1170 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 1016 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 1171 RunTasksAndWait(DefaultTouchTimeoutDelay() * 2); | 1017 RunTasksAndWait(DefaultTouchTimeoutDelay() * 2); |
| 1172 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | 1018 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| 1173 } | 1019 } |
| 1174 | 1020 |
| 1175 // Tests that the timeout is never started if the ack is synchronous. | 1021 // Tests that the timeout is never started if the ack is synchronous. |
| 1176 TEST_F(TouchEventQueueTest, NoTouchTimeoutIfAckIsSynchronous) { | 1022 TEST_F(PassthroughTouchEventQueueTest, NoTouchTimeoutIfAckIsSynchronous) { |
| 1177 SetUpForTimeoutTesting(); | 1023 SetUpForTimeoutTesting(); |
| 1178 | 1024 |
| 1179 // Queue a TouchStart. | 1025 // Queue a TouchStart. |
| 1180 SetSyncAckResult(INPUT_EVENT_ACK_STATE_CONSUMED); | 1026 SetSyncAckResult(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 1181 ASSERT_FALSE(IsTimeoutRunning()); | 1027 ASSERT_FALSE(IsTimeoutRunning()); |
| 1182 PressTouchPoint(0, 1); | 1028 PressTouchPoint(0, 1); |
| 1183 EXPECT_FALSE(IsTimeoutRunning()); | 1029 EXPECT_FALSE(IsTimeoutRunning()); |
| 1184 } | 1030 } |
| 1185 | 1031 |
| 1186 // Tests that the timeout does not fire if explicitly disabled while an event | 1032 // Tests that the timeout does not fire if explicitly disabled while an event |
| 1187 // is in-flight. | 1033 // is in-flight. |
| 1188 TEST_F(TouchEventQueueTest, NoTouchTimeoutIfDisabledWhileTimerIsActive) { | 1034 TEST_F(PassthroughTouchEventQueueTest, |
| 1035 NoTouchTimeoutIfDisabledWhileTimerIsActive) { |
| 1189 SetUpForTimeoutTesting(); | 1036 SetUpForTimeoutTesting(); |
| 1190 | 1037 |
| 1191 // Queue a TouchStart. | 1038 // Queue a TouchStart. |
| 1192 PressTouchPoint(0, 1); | 1039 PressTouchPoint(0, 1); |
| 1193 ASSERT_TRUE(IsTimeoutRunning()); | 1040 ASSERT_TRUE(IsTimeoutRunning()); |
| 1194 | 1041 |
| 1195 // Verify that disabling the timeout also turns off the timer. | 1042 // Verify that disabling the timeout also turns off the timer. |
| 1196 SetAckTimeoutDisabled(); | 1043 SetAckTimeoutDisabled(); |
| 1197 EXPECT_FALSE(IsTimeoutRunning()); | 1044 EXPECT_FALSE(IsTimeoutRunning()); |
| 1198 RunTasksAndWait(DefaultTouchTimeoutDelay() * 2); | 1045 RunTasksAndWait(DefaultTouchTimeoutDelay() * 2); |
| 1199 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | 1046 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| 1200 } | 1047 } |
| 1201 | 1048 |
| 1202 // Tests that the timeout does not fire if the delay is zero. | 1049 // Tests that the timeout does not fire if the delay is zero. |
| 1203 TEST_F(TouchEventQueueTest, NoTouchTimeoutIfTimeoutDelayIsZero) { | 1050 TEST_F(PassthroughTouchEventQueueTest, NoTouchTimeoutIfTimeoutDelayIsZero) { |
| 1204 SetUpForTimeoutTesting(base::TimeDelta(), base::TimeDelta()); | 1051 SetUpForTimeoutTesting(base::TimeDelta(), base::TimeDelta()); |
| 1205 | 1052 |
| 1206 // As the delay is zero, timeout behavior should be disabled. | 1053 // As the delay is zero, timeout behavior should be disabled. |
| 1207 PressTouchPoint(0, 1); | 1054 PressTouchPoint(0, 1); |
| 1208 EXPECT_FALSE(IsTimeoutRunning()); | 1055 EXPECT_FALSE(IsTimeoutRunning()); |
| 1209 RunTasksAndWait(DefaultTouchTimeoutDelay() * 2); | 1056 RunTasksAndWait(DefaultTouchTimeoutDelay() * 2); |
| 1210 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | 1057 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| 1211 } | 1058 } |
| 1212 | 1059 |
| 1213 // Tests that timeout delays for mobile sites take effect when appropriate. | 1060 // Tests that timeout delays for mobile sites take effect when appropriate. |
| 1214 TEST_F(TouchEventQueueTest, TouchTimeoutConfiguredForMobile) { | 1061 TEST_F(PassthroughTouchEventQueueTest, TouchTimeoutConfiguredForMobile) { |
| 1215 base::TimeDelta desktop_delay = DefaultTouchTimeoutDelay(); | 1062 base::TimeDelta desktop_delay = DefaultTouchTimeoutDelay(); |
| 1216 base::TimeDelta mobile_delay = base::TimeDelta(); | 1063 base::TimeDelta mobile_delay = base::TimeDelta(); |
| 1217 SetUpForTimeoutTesting(desktop_delay, mobile_delay); | 1064 SetUpForTimeoutTesting(desktop_delay, mobile_delay); |
| 1218 | 1065 |
| 1219 // The desktop delay is non-zero, allowing timeout behavior. | 1066 // The desktop delay is non-zero, allowing timeout behavior. |
| 1220 SetIsMobileOptimizedSite(false); | 1067 SetIsMobileOptimizedSite(false); |
| 1221 | 1068 |
| 1222 PressTouchPoint(0, 1); | 1069 PressTouchPoint(0, 1); |
| 1223 ASSERT_TRUE(IsTimeoutRunning()); | 1070 ASSERT_TRUE(IsTimeoutRunning()); |
| 1224 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); | 1071 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 1225 ReleaseTouchPoint(0); | 1072 ReleaseTouchPoint(0); |
| 1226 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); | 1073 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 1227 EXPECT_EQ(2U, GetAndResetAckedEventCount()); | 1074 EXPECT_EQ(2U, GetAndResetAckedEventCount()); |
| 1228 ASSERT_FALSE(IsTimeoutRunning()); | 1075 ASSERT_FALSE(IsTimeoutRunning()); |
| 1229 | 1076 |
| 1230 // The mobile delay is zero, preventing timeout behavior. | 1077 // The mobile delay is zero, preventing timeout behavior. |
| 1231 SetIsMobileOptimizedSite(true); | 1078 SetIsMobileOptimizedSite(true); |
| 1232 | 1079 |
| 1233 PressTouchPoint(0, 1); | 1080 PressTouchPoint(0, 1); |
| 1234 EXPECT_FALSE(IsTimeoutRunning()); | 1081 EXPECT_FALSE(IsTimeoutRunning()); |
| 1235 RunTasksAndWait(DefaultTouchTimeoutDelay() * 2); | 1082 RunTasksAndWait(DefaultTouchTimeoutDelay() * 2); |
| 1236 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | 1083 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| 1237 } | 1084 } |
| 1238 | 1085 |
| 1239 // Tests that a TouchCancel timeout plays nice when the timed out touch stream | 1086 // Tests that a TouchCancel timeout plays nice when the timed out touch stream |
| 1240 // turns into a scroll gesture sequence. | 1087 // turns into a scroll gesture sequence. |
| 1241 TEST_F(TouchEventQueueTest, TouchTimeoutWithFollowupGesture) { | 1088 TEST_F(PassthroughTouchEventQueueTest, TouchTimeoutWithFollowupGesture) { |
| 1242 SetUpForTimeoutTesting(); | 1089 SetUpForTimeoutTesting(); |
| 1243 | 1090 |
| 1244 // Queue a TouchStart. | 1091 // Queue a TouchStart. |
| 1245 PressTouchPoint(0, 1); | 1092 PressTouchPoint(0, 1); |
| 1246 EXPECT_TRUE(IsTimeoutRunning()); | 1093 EXPECT_TRUE(IsTimeoutRunning()); |
| 1247 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 1094 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 1248 | 1095 |
| 1249 // The cancelled sequence may turn into a scroll gesture. | 1096 // The cancelled sequence may turn into a scroll gesture. |
| 1250 WebGestureEvent followup_scroll( | 1097 WebGestureEvent followup_scroll( |
| 1251 WebInputEvent::GestureScrollBegin, WebInputEvent::NoModifiers, | 1098 WebInputEvent::GestureScrollBegin, WebInputEvent::NoModifiers, |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1287 SendGestureEvent(blink::WebInputEvent::GestureScrollEnd); | 1134 SendGestureEvent(blink::WebInputEvent::GestureScrollEnd); |
| 1288 PressTouchPoint(0, 1); | 1135 PressTouchPoint(0, 1); |
| 1289 EXPECT_TRUE(IsTimeoutRunning()); | 1136 EXPECT_TRUE(IsTimeoutRunning()); |
| 1290 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 1137 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 1291 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | 1138 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| 1292 } | 1139 } |
| 1293 | 1140 |
| 1294 // Tests that a TouchCancel timeout plays nice when the timed out touch stream | 1141 // Tests that a TouchCancel timeout plays nice when the timed out touch stream |
| 1295 // turns into a scroll gesture sequence, but the original event acks are | 1142 // turns into a scroll gesture sequence, but the original event acks are |
| 1296 // significantly delayed. | 1143 // significantly delayed. |
| 1297 TEST_F(TouchEventQueueTest, TouchTimeoutWithFollowupGestureAndDelayedAck) { | 1144 TEST_F(PassthroughTouchEventQueueTest, |
| 1145 TouchTimeoutWithFollowupGestureAndDelayedAck) { |
| 1298 SetUpForTimeoutTesting(); | 1146 SetUpForTimeoutTesting(); |
| 1299 | 1147 |
| 1300 // Queue a TouchStart. | 1148 // Queue a TouchStart. |
| 1301 PressTouchPoint(0, 1); | 1149 PressTouchPoint(0, 1); |
| 1302 EXPECT_TRUE(IsTimeoutRunning()); | 1150 EXPECT_TRUE(IsTimeoutRunning()); |
| 1303 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 1151 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 1304 | 1152 |
| 1305 // The cancelled sequence may turn into a scroll gesture. | 1153 // The cancelled sequence may turn into a scroll gesture. |
| 1306 WebGestureEvent followup_scroll( | 1154 WebGestureEvent followup_scroll( |
| 1307 WebInputEvent::GestureScrollBegin, WebInputEvent::NoModifiers, | 1155 WebInputEvent::GestureScrollBegin, WebInputEvent::NoModifiers, |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1344 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 1192 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 1345 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | 1193 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| 1346 | 1194 |
| 1347 PressTouchPoint(0, 1); | 1195 PressTouchPoint(0, 1); |
| 1348 EXPECT_TRUE(IsTimeoutRunning()); | 1196 EXPECT_TRUE(IsTimeoutRunning()); |
| 1349 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 1197 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 1350 } | 1198 } |
| 1351 | 1199 |
| 1352 // Tests that a delayed TouchEvent ack will not trigger a TouchCancel timeout if | 1200 // Tests that a delayed TouchEvent ack will not trigger a TouchCancel timeout if |
| 1353 // the timed-out event had no consumer. | 1201 // the timed-out event had no consumer. |
| 1354 TEST_F(TouchEventQueueTest, NoCancelOnTouchTimeoutWithoutConsumer) { | 1202 TEST_F(PassthroughTouchEventQueueTest, NoCancelOnTouchTimeoutWithoutConsumer) { |
| 1355 SetUpForTimeoutTesting(); | 1203 SetUpForTimeoutTesting(); |
| 1356 | 1204 |
| 1357 // Queue a TouchStart. | 1205 // Queue a TouchStart. |
| 1358 PressTouchPoint(0, 1); | 1206 PressTouchPoint(0, 1); |
| 1359 ASSERT_EQ(1U, GetAndResetSentEventCount()); | 1207 ASSERT_EQ(1U, GetAndResetSentEventCount()); |
| 1360 ASSERT_EQ(0U, GetAndResetAckedEventCount()); | 1208 ASSERT_EQ(0U, GetAndResetAckedEventCount()); |
| 1361 EXPECT_TRUE(IsTimeoutRunning()); | 1209 EXPECT_TRUE(IsTimeoutRunning()); |
| 1362 | 1210 |
| 1363 // Delay the ack. | 1211 // Delay the ack. |
| 1364 RunTasksAndWait(DefaultTouchTimeoutDelay() * 2); | 1212 RunTasksAndWait(DefaultTouchTimeoutDelay() * 2); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1383 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 1231 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 1384 | 1232 |
| 1385 // Subsequent events should be handled normally. | 1233 // Subsequent events should be handled normally. |
| 1386 PressTouchPoint(0, 1); | 1234 PressTouchPoint(0, 1); |
| 1387 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 1235 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 1388 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | 1236 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| 1389 } | 1237 } |
| 1390 | 1238 |
| 1391 // Tests that TouchMove's movedBeyondSlopRegion is set to false if within the | 1239 // Tests that TouchMove's movedBeyondSlopRegion is set to false if within the |
| 1392 // boundary-inclusive slop region for an unconsumed TouchStart. | 1240 // boundary-inclusive slop region for an unconsumed TouchStart. |
| 1393 TEST_F(TouchEventQueueTest, TouchMovedBeyondSlopRegionCheck) { | 1241 TEST_F(PassthroughTouchEventQueueTest, TouchMovedBeyondSlopRegionCheck) { |
| 1394 SetUpForTouchMoveSlopTesting(kSlopLengthDips); | 1242 SetUpForTouchMoveSlopTesting(kSlopLengthDips); |
| 1395 | 1243 |
| 1396 // Queue a TouchStart. | 1244 // Queue a TouchStart. |
| 1397 PressTouchPoint(0, 0); | 1245 PressTouchPoint(0, 0); |
| 1398 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1246 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1399 ASSERT_EQ(1U, GetAndResetSentEventCount()); | 1247 ASSERT_EQ(1U, GetAndResetSentEventCount()); |
| 1400 ASSERT_EQ(1U, GetAndResetAckedEventCount()); | 1248 ASSERT_EQ(1U, GetAndResetAckedEventCount()); |
| 1401 | 1249 |
| 1402 // TouchMove's movedBeyondSlopRegion within the slop region is set to false. | 1250 // TouchMove's movedBeyondSlopRegion within the slop region is set to false. |
| 1403 MoveTouchPoint(0, 0, kHalfSlopLengthDips); | 1251 MoveTouchPoint(0, 0, kHalfSlopLengthDips); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1433 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1281 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1434 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 1282 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 1435 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 1283 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 1436 EXPECT_FALSE(acked_event().movedBeyondSlopRegion); | 1284 EXPECT_FALSE(acked_event().movedBeyondSlopRegion); |
| 1437 | 1285 |
| 1438 // When a TouchMove exceeds the (Euclidean) distance, the TouchMove's | 1286 // When a TouchMove exceeds the (Euclidean) distance, the TouchMove's |
| 1439 // movedBeyondSlopRegion is set to true. | 1287 // movedBeyondSlopRegion is set to true. |
| 1440 const float kFortyFiveDegreeSlopLengthXY = | 1288 const float kFortyFiveDegreeSlopLengthXY = |
| 1441 kSlopLengthDips * std::sqrt(2.f) / 2; | 1289 kSlopLengthDips * std::sqrt(2.f) / 2; |
| 1442 MoveTouchPoint(0, kFortyFiveDegreeSlopLengthXY + .2f, | 1290 MoveTouchPoint(0, kFortyFiveDegreeSlopLengthXY + .2f, |
| 1443 kFortyFiveDegreeSlopLengthXY + .2f); | 1291 kFortyFiveDegreeSlopLengthXY + .2f); |
| 1444 EXPECT_EQ(1U, queued_event_count()); | 1292 EXPECT_EQ(1U, queued_event_count()); |
| 1445 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 1293 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 1446 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | 1294 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| 1447 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1295 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1448 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 1296 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 1449 EXPECT_TRUE(acked_event().movedBeyondSlopRegion); | 1297 EXPECT_TRUE(acked_event().movedBeyondSlopRegion); |
| 1450 } | 1298 } |
| 1451 | 1299 |
| 1452 // Tests that even very small TouchMove's movedBeyondSlopRegion is set to true | 1300 // Tests that even very small TouchMove's movedBeyondSlopRegion is set to true |
| 1453 // when the slop region's dimension is 0. | 1301 // when the slop region's dimension is 0. |
| 1454 TEST_F(TouchEventQueueTest, MovedBeyondSlopRegionAlwaysTrueIfDimensionZero) { | 1302 TEST_F(PassthroughTouchEventQueueTest, |
| 1303 MovedBeyondSlopRegionAlwaysTrueIfDimensionZero) { |
| 1455 // Queue a TouchStart. | 1304 // Queue a TouchStart. |
| 1456 PressTouchPoint(0, 0); | 1305 PressTouchPoint(0, 0); |
| 1457 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1306 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1458 ASSERT_EQ(1U, GetAndResetSentEventCount()); | 1307 ASSERT_EQ(1U, GetAndResetSentEventCount()); |
| 1459 ASSERT_EQ(1U, GetAndResetAckedEventCount()); | 1308 ASSERT_EQ(1U, GetAndResetAckedEventCount()); |
| 1460 | 1309 |
| 1461 // Small TouchMove's movedBeyondSlopRegion is set to true. | 1310 // Small TouchMove's movedBeyondSlopRegion is set to true. |
| 1462 MoveTouchPoint(0, 0.001f, 0.001f); | 1311 MoveTouchPoint(0, 0.001f, 0.001f); |
| 1463 EXPECT_EQ(1U, queued_event_count()); | 1312 EXPECT_EQ(1U, queued_event_count()); |
| 1464 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 1313 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 1465 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | 1314 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| 1466 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1315 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1467 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 1316 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 1468 EXPECT_TRUE(acked_event().movedBeyondSlopRegion); | 1317 EXPECT_TRUE(acked_event().movedBeyondSlopRegion); |
| 1469 } | 1318 } |
| 1470 | 1319 |
| 1471 // Tests that secondary touch points can be forwarded even if the primary touch | 1320 // Tests that secondary touch points can be forwarded even if the primary touch |
| 1472 // point had no consumer. | 1321 // point had no consumer. |
| 1473 TEST_F(TouchEventQueueTest, SecondaryTouchForwardedAfterPrimaryHadNoConsumer) { | 1322 TEST_F(PassthroughTouchEventQueueTest, |
| 1323 SecondaryTouchForwardedAfterPrimaryHadNoConsumer) { |
| 1474 // Queue a TouchStart. | 1324 // Queue a TouchStart. |
| 1475 PressTouchPoint(0, 0); | 1325 PressTouchPoint(0, 0); |
| 1476 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); | 1326 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); |
| 1477 ASSERT_EQ(1U, GetAndResetSentEventCount()); | 1327 ASSERT_EQ(1U, GetAndResetSentEventCount()); |
| 1478 ASSERT_EQ(1U, GetAndResetAckedEventCount()); | 1328 ASSERT_EQ(1U, GetAndResetAckedEventCount()); |
| 1479 | 1329 |
| 1480 // Events should not be forwarded, as the point had no consumer. | 1330 // Events should not be forwarded, as the point had no consumer. |
| 1481 MoveTouchPoint(0, 0, 15); | 1331 MoveTouchPoint(0, 0, 15); |
| 1482 EXPECT_EQ(0U, queued_event_count()); | 1332 EXPECT_EQ(0U, queued_event_count()); |
| 1483 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 1333 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 1484 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 1334 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 1485 | 1335 |
| 1486 // Simulate a secondary pointer press. | 1336 // Simulate a secondary pointer press. |
| 1487 PressTouchPoint(20, 0); | 1337 PressTouchPoint(20, 0); |
| 1488 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1338 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1489 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 1339 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 1490 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 1340 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 1491 | 1341 |
| 1492 // TouchMove with a secondary pointer should not be suppressed. | 1342 // TouchMove with a secondary pointer should not be suppressed. |
| 1493 MoveTouchPoint(1, 25, 0); | 1343 MoveTouchPoint(1, 25, 0); |
| 1494 EXPECT_EQ(1U, queued_event_count()); | 1344 EXPECT_EQ(1U, queued_event_count()); |
| 1495 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 1345 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 1496 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1346 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1497 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 1347 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 1498 } | 1348 } |
| 1499 | 1349 |
| 1500 // Tests that secondary touch points can be forwarded after scrolling begins | 1350 // Tests that secondary touch points can be forwarded after scrolling begins |
| 1501 // while first touch point has no consumer. | 1351 // while first touch point has no consumer. |
| 1502 TEST_F(TouchEventQueueTest, NoForwardingAfterScrollWithNoTouchConsumers) { | 1352 TEST_F(PassthroughTouchEventQueueTest, |
| 1353 NoForwardingAfterScrollWithNoTouchConsumers) { |
| 1503 // Queue a TouchStart. | 1354 // Queue a TouchStart. |
| 1504 PressTouchPoint(0, 0); | 1355 PressTouchPoint(0, 0); |
| 1505 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); | 1356 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); |
| 1506 ASSERT_EQ(1U, GetAndResetSentEventCount()); | 1357 ASSERT_EQ(1U, GetAndResetSentEventCount()); |
| 1507 ASSERT_EQ(1U, GetAndResetAckedEventCount()); | 1358 ASSERT_EQ(1U, GetAndResetAckedEventCount()); |
| 1508 | 1359 |
| 1509 WebGestureEvent followup_scroll(WebInputEvent::GestureScrollBegin, | 1360 WebGestureEvent followup_scroll(WebInputEvent::GestureScrollBegin, |
| 1510 WebInputEvent::NoModifiers, | 1361 WebInputEvent::NoModifiers, |
| 1511 WebInputEvent::TimeStampForTesting); | 1362 WebInputEvent::TimeStampForTesting); |
| 1512 SetFollowupEvent(followup_scroll); | 1363 SetFollowupEvent(followup_scroll); |
| 1513 MoveTouchPoint(0, 20, 5); | 1364 MoveTouchPoint(0, 20, 5); |
| 1514 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 1365 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 1515 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 1366 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 1516 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, acked_event_state()); | 1367 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, acked_event_state()); |
| 1517 | 1368 |
| 1518 // The secondary pointer press should be forwarded. | 1369 // The secondary pointer press should be forwarded. |
| 1519 PressTouchPoint(20, 0); | 1370 PressTouchPoint(20, 0); |
| 1520 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); | 1371 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 1521 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 1372 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 1522 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 1373 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 1523 | 1374 |
| 1524 // TouchMove with a secondary pointer should also be forwarded. | 1375 // TouchMove with a secondary pointer should also be forwarded. |
| 1525 MoveTouchPoint(1, 25, 0); | 1376 MoveTouchPoint(1, 25, 0); |
| 1526 EXPECT_EQ(1U, queued_event_count()); | 1377 EXPECT_EQ(1U, queued_event_count()); |
| 1527 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 1378 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 1528 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); | 1379 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 1529 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 1380 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 1530 } | 1381 } |
| 1531 | 1382 |
| 1532 TEST_F(TouchEventQueueTest, AsyncTouch) { | 1383 TEST_F(PassthroughTouchEventQueueTest, TouchAbsorptionWithConsumedFirstMove) { |
| 1533 // Queue a TouchStart. | |
| 1534 PressTouchPoint(0, 1); | |
| 1535 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 1536 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 1537 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 1538 | |
| 1539 for (int i = 0; i < 3; ++i) { | |
| 1540 SendGestureEventAck(WebInputEvent::GestureScrollUpdate, | |
| 1541 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 1542 | |
| 1543 MoveTouchPoint(0, 10, 5+i); | |
| 1544 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 1545 EXPECT_FALSE(HasPendingAsyncTouchMove()); | |
| 1546 EXPECT_EQ(WebInputEvent::Blocking, sent_event().dispatchType); | |
| 1547 EXPECT_EQ(0U, queued_event_count()); | |
| 1548 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 1549 | |
| 1550 // Consuming a scroll event will throttle subsequent touchmoves. | |
| 1551 SendGestureEventAck(WebInputEvent::GestureScrollUpdate, | |
| 1552 INPUT_EVENT_ACK_STATE_CONSUMED); | |
| 1553 MoveTouchPoint(0, 10, 7+i); | |
| 1554 EXPECT_TRUE(HasPendingAsyncTouchMove()); | |
| 1555 EXPECT_EQ(0U, queued_event_count()); | |
| 1556 EXPECT_EQ(0U, GetAndResetSentEventCount()); | |
| 1557 } | |
| 1558 } | |
| 1559 | |
| 1560 // Ensure that touchmove's are appropriately throttled during a typical | |
| 1561 // scroll sequences that transitions between scrolls consumed and unconsumed. | |
| 1562 TEST_F(TouchEventQueueTest, AsyncTouchThrottledAfterScroll) { | |
| 1563 // Process a TouchStart | |
| 1564 PressTouchPoint(0, 1); | |
| 1565 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 1566 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 1567 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 1568 | |
| 1569 // Now send the first touch move and associated GestureScrollBegin. | |
| 1570 MoveTouchPoint(0, 0, 5); | |
| 1571 WebGestureEvent followup_scroll(WebInputEvent::GestureScrollBegin, | |
| 1572 WebInputEvent::NoModifiers, | |
| 1573 WebInputEvent::TimeStampForTesting); | |
| 1574 SetFollowupEvent(followup_scroll); | |
| 1575 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 1576 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 1577 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 1578 SendGestureEventAck(WebInputEvent::GestureScrollBegin, | |
| 1579 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 1580 | |
| 1581 // Send the second touch move and associated GestureScrollUpdate, but don't | |
| 1582 // ACK the gesture event yet. | |
| 1583 MoveTouchPoint(0, 0, 50); | |
| 1584 followup_scroll.setType(WebInputEvent::GestureScrollUpdate); | |
| 1585 SetFollowupEvent(followup_scroll); | |
| 1586 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 1587 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 1588 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 1589 | |
| 1590 // Now queue a second touchmove and verify it's not (yet) dispatched. | |
| 1591 MoveTouchPoint(0, 0, 100); | |
| 1592 SetFollowupEvent(followup_scroll); | |
| 1593 EXPECT_TRUE(HasPendingAsyncTouchMove()); | |
| 1594 EXPECT_EQ(0U, queued_event_count()); | |
| 1595 EXPECT_EQ(0U, GetAndResetSentEventCount()); | |
| 1596 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 1597 | |
| 1598 // Queuing the final touchend should flush the pending async touchmove. In | |
| 1599 // this case, we will first dispatch an async touchmove and then a touchend. | |
| 1600 // For the async touchmove, we will not send ack again. | |
| 1601 ReleaseTouchPoint(0); | |
| 1602 followup_scroll.setType(WebInputEvent::GestureScrollEnd); | |
| 1603 SetFollowupEvent(followup_scroll); | |
| 1604 EXPECT_FALSE(HasPendingAsyncTouchMove()); | |
| 1605 EXPECT_EQ(2U, all_sent_events().size()); | |
| 1606 EXPECT_EQ(WebInputEvent::TouchMove, all_sent_events()[0].type()); | |
| 1607 EXPECT_NE(WebInputEvent::Blocking, all_sent_events()[0].dispatchType); | |
| 1608 EXPECT_EQ(WebInputEvent::TouchEnd, all_sent_events()[1].type()); | |
| 1609 EXPECT_NE(WebInputEvent::Blocking, all_sent_events()[1].dispatchType); | |
| 1610 EXPECT_EQ(2U, GetAndResetSentEventCount()); | |
| 1611 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | |
| 1612 EXPECT_EQ(1U, queued_event_count()); | |
| 1613 | |
| 1614 // Ack the touchend. | |
| 1615 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 1616 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 1617 EXPECT_EQ(0U, queued_event_count()); | |
| 1618 EXPECT_EQ(0U, GetAndResetSentEventCount()); | |
| 1619 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 1620 | |
| 1621 // Now mark the scrolls as not consumed (which would cause future touchmoves | |
| 1622 // in the active sequence to be sent if there was one). | |
| 1623 SendGestureEventAck(WebInputEvent::GestureScrollUpdate, | |
| 1624 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 1625 SendGestureEventAck(WebInputEvent::GestureScrollUpdate, | |
| 1626 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 1627 | |
| 1628 // Start a new touch sequence and verify that throttling has been reset. | |
| 1629 // Touch moves after the start of scrolling will again be throttled. | |
| 1630 PressTouchPoint(0, 0); | |
| 1631 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 1632 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 1633 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 1634 MoveTouchPoint(0, 0, 5); | |
| 1635 followup_scroll.setType(WebInputEvent::GestureScrollBegin); | |
| 1636 SetFollowupEvent(followup_scroll); | |
| 1637 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 1638 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 1639 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 1640 | |
| 1641 MoveTouchPoint(0, 0, 6); | |
| 1642 followup_scroll.setType(WebInputEvent::GestureScrollUpdate); | |
| 1643 SetFollowupEvent(followup_scroll); | |
| 1644 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 1645 EXPECT_FALSE(HasPendingAsyncTouchMove()); | |
| 1646 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 1647 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 1648 | |
| 1649 MoveTouchPoint(0, 0, 10); | |
| 1650 EXPECT_TRUE(HasPendingAsyncTouchMove()); | |
| 1651 EXPECT_EQ(0U, queued_event_count()); | |
| 1652 EXPECT_EQ(0U, GetAndResetSentEventCount()); | |
| 1653 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 1654 | |
| 1655 // Subsequent touchmove's should be deferred. | |
| 1656 MoveTouchPoint(0, 0, 25); | |
| 1657 EXPECT_TRUE(HasPendingAsyncTouchMove()); | |
| 1658 EXPECT_EQ(0U, queued_event_count()); | |
| 1659 EXPECT_EQ(0U, GetAndResetSentEventCount()); | |
| 1660 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 1661 EXPECT_EQ(0U, uncancelable_touch_moves_pending_ack_count()); | |
| 1662 | |
| 1663 // The pending touchmove should be flushed with the the new touchmove if | |
| 1664 // sufficient time has passed and ack to the client. | |
| 1665 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1); | |
| 1666 MoveTouchPoint(0, 0, 15); | |
| 1667 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 1668 EXPECT_FALSE(HasPendingAsyncTouchMove()); | |
| 1669 EXPECT_NE(WebInputEvent::Blocking, sent_event().dispatchType); | |
| 1670 EXPECT_EQ(0U, queued_event_count()); | |
| 1671 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 1672 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 1673 | |
| 1674 // Non-touchmove events should always flush any pending touchmove events. In | |
| 1675 // this case, we will first dispatch an async touchmove and then a | |
| 1676 // touchstart. For the async touchmove, we will not send ack again. | |
| 1677 MoveTouchPoint(0, 0, 25); | |
| 1678 EXPECT_TRUE(HasPendingAsyncTouchMove()); | |
| 1679 EXPECT_EQ(0U, queued_event_count()); | |
| 1680 EXPECT_EQ(0U, GetAndResetSentEventCount()); | |
| 1681 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 1682 PressTouchPoint(30, 30); | |
| 1683 EXPECT_FALSE(HasPendingAsyncTouchMove()); | |
| 1684 EXPECT_EQ(2U, all_sent_events().size()); | |
| 1685 EXPECT_EQ(WebInputEvent::TouchMove, all_sent_events()[0].type()); | |
| 1686 EXPECT_NE(WebInputEvent::Blocking, all_sent_events()[0].dispatchType); | |
| 1687 EXPECT_EQ(WebInputEvent::TouchStart, all_sent_events()[1].type()); | |
| 1688 EXPECT_EQ(WebInputEvent::Blocking, all_sent_events()[1].dispatchType); | |
| 1689 EXPECT_EQ(2U, GetAndResetSentEventCount()); | |
| 1690 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | |
| 1691 EXPECT_EQ(1U, queued_event_count()); | |
| 1692 | |
| 1693 // Ack the touchstart. | |
| 1694 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 1695 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 1696 EXPECT_EQ(0U, queued_event_count()); | |
| 1697 EXPECT_EQ(0U, GetAndResetSentEventCount()); | |
| 1698 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 1699 | |
| 1700 // Send a secondary touchmove. | |
| 1701 MoveTouchPoint(1, 0, 25); | |
| 1702 EXPECT_TRUE(HasPendingAsyncTouchMove()); | |
| 1703 EXPECT_EQ(0U, queued_event_count()); | |
| 1704 EXPECT_EQ(0U, GetAndResetSentEventCount()); | |
| 1705 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 1706 | |
| 1707 // An unconsumed scroll should resume synchronous touch handling. | |
| 1708 SendGestureEventAck(WebInputEvent::GestureScrollUpdate, | |
| 1709 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 1710 | |
| 1711 // The pending touchmove should be coalesced with the next (now synchronous) | |
| 1712 // touchmove. | |
| 1713 MoveTouchPoint(0, 0, 26); | |
| 1714 EXPECT_EQ(WebInputEvent::Blocking, sent_event().dispatchType); | |
| 1715 EXPECT_FALSE(HasPendingAsyncTouchMove()); | |
| 1716 EXPECT_EQ(WebInputEvent::TouchMove, sent_event().type()); | |
| 1717 EXPECT_EQ(WebTouchPoint::StateMoved, sent_event().touches[0].state); | |
| 1718 EXPECT_EQ(WebTouchPoint::StateMoved, sent_event().touches[1].state); | |
| 1719 EXPECT_EQ(1U, queued_event_count()); | |
| 1720 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 1721 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | |
| 1722 | |
| 1723 // Subsequent touches will queue until the preceding, synchronous touches are | |
| 1724 // ack'ed. | |
| 1725 ReleaseTouchPoint(1); | |
| 1726 EXPECT_EQ(2U, queued_event_count()); | |
| 1727 ReleaseTouchPoint(0); | |
| 1728 EXPECT_EQ(3U, queued_event_count()); | |
| 1729 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 1730 EXPECT_EQ(WebInputEvent::Blocking, sent_event().dispatchType); | |
| 1731 EXPECT_EQ(WebInputEvent::TouchEnd, sent_event().type()); | |
| 1732 EXPECT_EQ(2U, queued_event_count()); | |
| 1733 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 1734 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 1735 | |
| 1736 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 1737 EXPECT_EQ(WebInputEvent::Blocking, sent_event().dispatchType); | |
| 1738 EXPECT_EQ(WebInputEvent::TouchEnd, sent_event().type()); | |
| 1739 EXPECT_EQ(1U, queued_event_count()); | |
| 1740 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 1741 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 1742 | |
| 1743 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 1744 EXPECT_EQ(0U, queued_event_count()); | |
| 1745 EXPECT_EQ(0U, GetAndResetSentEventCount()); | |
| 1746 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 1747 } | |
| 1748 | |
| 1749 TEST_F(TouchEventQueueTest, AsyncTouchFlushedByTouchEnd) { | |
| 1750 PressTouchPoint(0, 0); | |
| 1751 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 1752 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 1753 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 1754 | |
| 1755 // Initiate async touchmove dispatch after the start of a scroll sequence. | |
| 1756 MoveTouchPoint(0, 0, 5); | |
| 1757 WebGestureEvent followup_scroll(WebInputEvent::GestureScrollBegin, | |
| 1758 WebInputEvent::NoModifiers, | |
| 1759 WebInputEvent::TimeStampForTesting); | |
| 1760 SetFollowupEvent(followup_scroll); | |
| 1761 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 1762 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 1763 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 1764 | |
| 1765 MoveTouchPoint(0, 0, 10); | |
| 1766 followup_scroll.setType(WebInputEvent::GestureScrollUpdate); | |
| 1767 SetFollowupEvent(followup_scroll); | |
| 1768 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 1769 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 1770 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 1771 | |
| 1772 // Now queue a second touchmove and verify it's not (yet) dispatched. | |
| 1773 MoveTouchPoint(0, 0, 100); | |
| 1774 EXPECT_TRUE(HasPendingAsyncTouchMove()); | |
| 1775 EXPECT_EQ(0U, queued_event_count()); | |
| 1776 EXPECT_EQ(0U, GetAndResetSentEventCount()); | |
| 1777 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 1778 | |
| 1779 // Return the touch sequence to the original touchstart position. Note that | |
| 1780 // this (0, 0) touchmove will coalesce with the previous (0, 100) touchmove. | |
| 1781 MoveTouchPoint(0, 0, 0); | |
| 1782 EXPECT_TRUE(HasPendingAsyncTouchMove()); | |
| 1783 EXPECT_EQ(0U, queued_event_count()); | |
| 1784 EXPECT_EQ(0U, GetAndResetSentEventCount()); | |
| 1785 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 1786 | |
| 1787 // Queuing the final touchend should flush the pending, async touchmove. In | |
| 1788 // this case, we will first dispatch an async touchmove and then a touchend. | |
| 1789 // For the async touchmove, we will not send ack again. | |
| 1790 ReleaseTouchPoint(0); | |
| 1791 EXPECT_FALSE(HasPendingAsyncTouchMove()); | |
| 1792 EXPECT_EQ(2U, all_sent_events().size()); | |
| 1793 EXPECT_EQ(WebInputEvent::TouchMove, all_sent_events()[0].type()); | |
| 1794 EXPECT_NE(WebInputEvent::Blocking, all_sent_events()[0].dispatchType); | |
| 1795 EXPECT_EQ(0, all_sent_events()[0].touches[0].position.x); | |
| 1796 EXPECT_EQ(0, all_sent_events()[0].touches[0].position.y); | |
| 1797 EXPECT_EQ(WebInputEvent::TouchEnd, all_sent_events()[1].type()); | |
| 1798 EXPECT_NE(WebInputEvent::Blocking, all_sent_events()[1].dispatchType); | |
| 1799 EXPECT_EQ(2U, GetAndResetSentEventCount()); | |
| 1800 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | |
| 1801 } | |
| 1802 | |
| 1803 // Ensure that async touch dispatch and touch ack timeout interactions work | |
| 1804 // appropriately. | |
| 1805 TEST_F(TouchEventQueueTest, AsyncTouchWithAckTimeout) { | |
| 1806 SetUpForTimeoutTesting(); | |
| 1807 | |
| 1808 // The touchstart should start the timeout. | |
| 1809 PressTouchPoint(0, 0); | |
| 1810 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 1811 EXPECT_TRUE(IsTimeoutRunning()); | |
| 1812 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 1813 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 1814 EXPECT_FALSE(IsTimeoutRunning()); | |
| 1815 | |
| 1816 // The start of a scroll gesture should trigger async touch event dispatch. | |
| 1817 MoveTouchPoint(0, 1, 1); | |
| 1818 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 1819 EXPECT_TRUE(IsTimeoutRunning()); | |
| 1820 WebGestureEvent followup_scroll(WebInputEvent::GestureScrollBegin, | |
| 1821 WebInputEvent::NoModifiers, | |
| 1822 WebInputEvent::TimeStampForTesting); | |
| 1823 SetFollowupEvent(followup_scroll); | |
| 1824 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 1825 EXPECT_FALSE(IsTimeoutRunning()); | |
| 1826 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 1827 | |
| 1828 SendGestureEventAck(WebInputEvent::GestureScrollUpdate, | |
| 1829 INPUT_EVENT_ACK_STATE_CONSUMED); | |
| 1830 | |
| 1831 // An async touch should fire after the throttling interval has expired, but | |
| 1832 // it should not start the touch ack timeout. | |
| 1833 MoveTouchPoint(0, 5, 5); | |
| 1834 EXPECT_TRUE(HasPendingAsyncTouchMove()); | |
| 1835 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 1836 | |
| 1837 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1); | |
| 1838 MoveTouchPoint(0, 5, 5); | |
| 1839 EXPECT_FALSE(IsTimeoutRunning()); | |
| 1840 EXPECT_FALSE(HasPendingAsyncTouchMove()); | |
| 1841 EXPECT_NE(WebInputEvent::Blocking, sent_event().dispatchType); | |
| 1842 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 1843 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 1844 | |
| 1845 // An unconsumed scroll event will resume synchronous touchmoves, which are | |
| 1846 // subject to the ack timeout. | |
| 1847 SendGestureEventAck(WebInputEvent::GestureScrollUpdate, | |
| 1848 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 1849 MoveTouchPoint(0, 20, 5); | |
| 1850 EXPECT_TRUE(IsTimeoutRunning()); | |
| 1851 EXPECT_EQ(WebInputEvent::Blocking, sent_event().dispatchType); | |
| 1852 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 1853 | |
| 1854 // The timeout should fire, disabling touch forwarding until both acks are | |
| 1855 // received and acking the timed out event. | |
| 1856 RunTasksAndWait(DefaultTouchTimeoutDelay() * 2); | |
| 1857 EXPECT_FALSE(IsTimeoutRunning()); | |
| 1858 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 1859 EXPECT_EQ(0U, GetAndResetSentEventCount()); | |
| 1860 | |
| 1861 // Ack'ing the original event should trigger a cancel event. | |
| 1862 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 1863 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 1864 EXPECT_NE(WebInputEvent::Blocking, sent_event().dispatchType); | |
| 1865 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | |
| 1866 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 1867 | |
| 1868 // Subsequent touchmove's should not be forwarded, even as the scroll gesture | |
| 1869 // goes from unconsumed to consumed. | |
| 1870 SendGestureEventAck(WebInputEvent::GestureScrollUpdate, | |
| 1871 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 1872 MoveTouchPoint(0, 20, 5); | |
| 1873 EXPECT_FALSE(HasPendingAsyncTouchMove()); | |
| 1874 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 1875 EXPECT_EQ(0U, GetAndResetSentEventCount()); | |
| 1876 | |
| 1877 SendGestureEventAck(WebInputEvent::GestureScrollUpdate, | |
| 1878 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 1879 MoveTouchPoint(0, 25, 5); | |
| 1880 EXPECT_FALSE(HasPendingAsyncTouchMove()); | |
| 1881 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 1882 EXPECT_EQ(0U, GetAndResetSentEventCount()); | |
| 1883 } | |
| 1884 | |
| 1885 // Ensure that if the touch ack for an async touchmove triggers a follow-up | |
| 1886 // touch event, that follow-up touch will be forwarded appropriately. | |
| 1887 TEST_F(TouchEventQueueTest, AsyncTouchWithTouchCancelAfterAck) { | |
| 1888 PressTouchPoint(0, 0); | |
| 1889 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 1890 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 1891 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 1892 | |
| 1893 // The start of a scroll gesture should trigger async touch event dispatch. | |
| 1894 MoveTouchPoint(0, 1, 1); | |
| 1895 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 1896 WebGestureEvent followup_scroll(WebInputEvent::GestureScrollBegin, | |
| 1897 WebInputEvent::NoModifiers, | |
| 1898 WebInputEvent::TimeStampForTesting); | |
| 1899 SetFollowupEvent(followup_scroll); | |
| 1900 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 1901 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 1902 EXPECT_EQ(0U, queued_event_count()); | |
| 1903 | |
| 1904 SendGestureEvent(WebInputEvent::GestureScrollUpdate); | |
| 1905 | |
| 1906 // The async touchmove should be ack'ed immediately, but not forwarded. | |
| 1907 // However, because the ack triggers a touchcancel, both the pending touch and | |
| 1908 // the queued touchcancel should be flushed. | |
| 1909 WebTouchEvent followup_cancel(WebInputEvent::TouchCancel, | |
| 1910 WebInputEvent::NoModifiers, | |
| 1911 WebInputEvent::TimeStampForTesting); | |
| 1912 followup_cancel.touchesLength = 1; | |
| 1913 followup_cancel.touches[0].state = WebTouchPoint::StateCancelled; | |
| 1914 SetFollowupEvent(followup_cancel); | |
| 1915 MoveTouchPoint(0, 5, 5); | |
| 1916 EXPECT_EQ(1U, queued_event_count()); | |
| 1917 EXPECT_EQ(2U, all_sent_events().size()); | |
| 1918 EXPECT_EQ(WebInputEvent::TouchMove, all_sent_events()[0].type()); | |
| 1919 EXPECT_NE(WebInputEvent::Blocking, all_sent_events()[0].dispatchType); | |
| 1920 EXPECT_EQ(WebInputEvent::TouchCancel, all_sent_events()[1].type()); | |
| 1921 EXPECT_NE(WebInputEvent::Blocking, all_sent_events()[1].dispatchType); | |
| 1922 EXPECT_EQ(2U, GetAndResetSentEventCount()); | |
| 1923 // Sending the ack is because the async touchmove is not ready for | |
| 1924 // dispatching send the ack immediately. | |
| 1925 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 1926 EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type()); | |
| 1927 | |
| 1928 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 1929 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 1930 EXPECT_EQ(0U, queued_event_count()); | |
| 1931 EXPECT_EQ(WebInputEvent::TouchCancel, acked_event().type()); | |
| 1932 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 1933 EXPECT_EQ(0U, GetAndResetSentEventCount()); | |
| 1934 } | |
| 1935 | |
| 1936 // Ensure that the async touch is fully reset if the touch sequence restarts | |
| 1937 // without properly terminating. | |
| 1938 TEST_F(TouchEventQueueTest, AsyncTouchWithHardTouchStartReset) { | |
| 1939 PressTouchPoint(0, 0); | |
| 1940 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 1941 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 1942 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 1943 | |
| 1944 // Trigger async touchmove dispatch. | |
| 1945 MoveTouchPoint(0, 1, 1); | |
| 1946 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 1947 WebGestureEvent followup_scroll(WebInputEvent::GestureScrollBegin, | |
| 1948 WebInputEvent::NoModifiers, | |
| 1949 WebInputEvent::TimeStampForTesting); | |
| 1950 SetFollowupEvent(followup_scroll); | |
| 1951 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 1952 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 1953 EXPECT_EQ(0U, queued_event_count()); | |
| 1954 SendGestureEvent(WebInputEvent::GestureScrollUpdate); | |
| 1955 | |
| 1956 // The async touchmove should be immediately ack'ed but delivery is deferred. | |
| 1957 MoveTouchPoint(0, 2, 2); | |
| 1958 EXPECT_EQ(0U, GetAndResetSentEventCount()); | |
| 1959 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 1960 EXPECT_EQ(0U, queued_event_count()); | |
| 1961 EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type()); | |
| 1962 | |
| 1963 // The queue should be robust to hard touch restarts with a new touch | |
| 1964 // sequence. In this case, the deferred async touch should not be flushed | |
| 1965 // by the new touch sequence. | |
| 1966 SendGestureEvent(WebInputEvent::GestureScrollEnd); | |
| 1967 ResetTouchEvent(); | |
| 1968 | |
| 1969 PressTouchPoint(0, 0); | |
| 1970 EXPECT_EQ(WebInputEvent::TouchStart, sent_event().type()); | |
| 1971 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 1972 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 1973 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 1974 } | |
| 1975 | |
| 1976 // Ensure that even when the interval expires, we still need to wait for the | |
| 1977 // ack sent back from render to send the next async touchmove once the scroll | |
| 1978 // starts. | |
| 1979 TEST_F(TouchEventQueueTest, SendNextThrottledAsyncTouchMoveAfterAck) { | |
| 1980 // Process a TouchStart | |
| 1981 PressTouchPoint(0, 1); | |
| 1982 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 1983 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 1984 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 1985 | |
| 1986 // Initiate async touchmove dispatch after the start of a scroll sequence. | |
| 1987 MoveTouchPoint(0, 0, 5); | |
| 1988 WebGestureEvent followup_scroll(WebInputEvent::GestureScrollBegin, | |
| 1989 WebInputEvent::NoModifiers, | |
| 1990 WebInputEvent::TimeStampForTesting); | |
| 1991 SetFollowupEvent(followup_scroll); | |
| 1992 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 1993 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 1994 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 1995 | |
| 1996 MoveTouchPoint(0, 0, 10); | |
| 1997 followup_scroll.setType(WebInputEvent::GestureScrollUpdate); | |
| 1998 SetFollowupEvent(followup_scroll); | |
| 1999 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 2000 EXPECT_FALSE(HasPendingAsyncTouchMove()); | |
| 2001 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 2002 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 2003 | |
| 2004 // We set the next touch event time to be after the throttled interval. | |
| 2005 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1); | |
| 2006 // Dispatch the touch move event when sufficient time has passed. | |
| 2007 MoveTouchPoint(0, 0, 40); | |
| 2008 EXPECT_FALSE(HasPendingAsyncTouchMove()); | |
| 2009 EXPECT_NE(WebInputEvent::Blocking, sent_event().dispatchType); | |
| 2010 // When we dispatch an async touchmove, we do not put it back to the queue | |
| 2011 // any more and we will ack to client right away. | |
| 2012 EXPECT_EQ(0U, queued_event_count()); | |
| 2013 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 2014 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 2015 EXPECT_EQ(1U, uncancelable_touch_moves_pending_ack_count()); | |
| 2016 | |
| 2017 // Do not dispatch the event until throttledTouchmoves intervals expires and | |
| 2018 // receive an ack from render. | |
| 2019 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1); | |
| 2020 MoveTouchPoint(0, 0, 50); | |
| 2021 EXPECT_TRUE(HasPendingAsyncTouchMove()); | |
| 2022 EXPECT_EQ(0U, queued_event_count()); | |
| 2023 EXPECT_EQ(0U, GetAndResetSentEventCount()); | |
| 2024 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 2025 EXPECT_EQ(1U, uncancelable_touch_moves_pending_ack_count()); | |
| 2026 | |
| 2027 // Send pending_async_touch_move_ when we receive an ack back from render, | |
| 2028 // but we will not send an ack for pending_async_touch_move_ becasue it is | |
| 2029 // been acked before. | |
| 2030 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 2031 EXPECT_FALSE(HasPendingAsyncTouchMove()); | |
| 2032 EXPECT_EQ(0U, queued_event_count()); | |
| 2033 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 2034 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | |
| 2035 EXPECT_EQ(1U, uncancelable_touch_moves_pending_ack_count()); | |
| 2036 } | |
| 2037 | |
| 2038 // Ensure that even when we receive the ack from render, we still need to wait | |
| 2039 // for the interval expires to send the next async touchmove once the scroll | |
| 2040 // starts. | |
| 2041 TEST_F(TouchEventQueueTest, SendNextAsyncTouchMoveAfterAckAndTimeExpire) { | |
| 2042 // Process a TouchStart | |
| 2043 PressTouchPoint(0, 1); | |
| 2044 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 2045 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 2046 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 2047 | |
| 2048 // Initiate async touchmove dispatch after the start of a scroll sequence. | |
| 2049 MoveTouchPoint(0, 0, 5); | |
| 2050 WebGestureEvent followup_scroll(WebInputEvent::GestureScrollBegin, | |
| 2051 WebInputEvent::NoModifiers, | |
| 2052 WebInputEvent::TimeStampForTesting); | |
| 2053 SetFollowupEvent(followup_scroll); | |
| 2054 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 2055 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 2056 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 2057 | |
| 2058 MoveTouchPoint(0, 0, 10); | |
| 2059 followup_scroll.setType(WebInputEvent::GestureScrollUpdate); | |
| 2060 SetFollowupEvent(followup_scroll); | |
| 2061 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 2062 EXPECT_FALSE(HasPendingAsyncTouchMove()); | |
| 2063 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 2064 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 2065 | |
| 2066 // Dispatch the touch move event when sufficient time has passed. | |
| 2067 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1); | |
| 2068 MoveTouchPoint(0, 0, 40); | |
| 2069 EXPECT_FALSE(HasPendingAsyncTouchMove()); | |
| 2070 EXPECT_NE(WebInputEvent::Blocking, sent_event().dispatchType); | |
| 2071 // When we dispatch an async touchmove, we do not put it back to the queue | |
| 2072 // any more and we will ack to client right away. | |
| 2073 EXPECT_EQ(0U, queued_event_count()); | |
| 2074 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 2075 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 2076 EXPECT_EQ(1U, uncancelable_touch_moves_pending_ack_count()); | |
| 2077 | |
| 2078 // We receive an ack back from render but the time interval is not expired, | |
| 2079 // so we do not dispatch the touch move event. | |
| 2080 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 2081 EXPECT_EQ(0U, uncancelable_touch_moves_pending_ack_count()); | |
| 2082 MoveTouchPoint(0, 0, 50); | |
| 2083 EXPECT_TRUE(HasPendingAsyncTouchMove()); | |
| 2084 EXPECT_EQ(0U, queued_event_count()); | |
| 2085 EXPECT_EQ(0U, GetAndResetSentEventCount()); | |
| 2086 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 2087 | |
| 2088 // Dispatch the touch move when sufficient time has passed. | |
| 2089 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1); | |
| 2090 MoveTouchPoint(0, 0, 50); | |
| 2091 EXPECT_FALSE(HasPendingAsyncTouchMove()); | |
| 2092 EXPECT_EQ(WebInputEvent::TouchMove, sent_event().type()); | |
| 2093 EXPECT_NE(WebInputEvent::Blocking, sent_event().dispatchType); | |
| 2094 EXPECT_EQ(0U, queued_event_count()); | |
| 2095 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 2096 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 2097 EXPECT_EQ(1U, uncancelable_touch_moves_pending_ack_count()); | |
| 2098 } | |
| 2099 | |
| 2100 TEST_F(TouchEventQueueTest, AsyncTouchFlushedByNonTouchMove) { | |
| 2101 // Process a TouchStart | |
| 2102 PressTouchPoint(0, 1); | |
| 2103 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 2104 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 2105 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 2106 | |
| 2107 // Initiate async touchmove dispatch after the start of a scroll sequence. | |
| 2108 MoveTouchPoint(0, 0, 5); | |
| 2109 WebGestureEvent followup_scroll(WebInputEvent::GestureScrollBegin, | |
| 2110 WebInputEvent::NoModifiers, | |
| 2111 WebInputEvent::TimeStampForTesting); | |
| 2112 SetFollowupEvent(followup_scroll); | |
| 2113 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 2114 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 2115 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 2116 | |
| 2117 MoveTouchPoint(0, 0, 10); | |
| 2118 followup_scroll.setType(WebInputEvent::GestureScrollUpdate); | |
| 2119 SetFollowupEvent(followup_scroll); | |
| 2120 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 2121 EXPECT_FALSE(HasPendingAsyncTouchMove()); | |
| 2122 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 2123 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 2124 | |
| 2125 // Dispatch the touch move when sufficient time has passed. | |
| 2126 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1); | |
| 2127 MoveTouchPoint(0, 0, 40); | |
| 2128 EXPECT_FALSE(HasPendingAsyncTouchMove()); | |
| 2129 EXPECT_NE(WebInputEvent::Blocking, sent_event().dispatchType); | |
| 2130 // When we dispatch an async touchmove, we do not put it back to the queue | |
| 2131 // any more and we will ack to client right away. | |
| 2132 EXPECT_EQ(0U, queued_event_count()); | |
| 2133 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 2134 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 2135 EXPECT_EQ(1U, uncancelable_touch_moves_pending_ack_count()); | |
| 2136 | |
| 2137 for (int i = 0; i < 3; ++i) { | |
| 2138 // We throttle the touchmoves, put it in the pending_async_touch_move_, | |
| 2139 // do not dispatch it. | |
| 2140 MoveTouchPoint(0, 10 + 10 * i, 10 + 10 * i); | |
| 2141 EXPECT_TRUE(HasPendingAsyncTouchMove()); | |
| 2142 EXPECT_EQ(0U, queued_event_count()); | |
| 2143 EXPECT_EQ(0U, GetAndResetSentEventCount()); | |
| 2144 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 2145 EXPECT_EQ(static_cast<size_t>(i + 1), | |
| 2146 uncancelable_touch_moves_pending_ack_count()); | |
| 2147 | |
| 2148 // Send touchstart will flush pending_async_touch_move_, and increase the | |
| 2149 // count. In this case, we will first dispatch an async touchmove and | |
| 2150 // then a touchstart. For the async touchmove, we will not send ack again. | |
| 2151 PressTouchPoint(30, 30); | |
| 2152 EXPECT_FALSE(HasPendingAsyncTouchMove()); | |
| 2153 EXPECT_EQ(2U, all_sent_events().size()); | |
| 2154 EXPECT_EQ(WebInputEvent::TouchMove, all_sent_events()[0].type()); | |
| 2155 EXPECT_NE(WebInputEvent::Blocking, all_sent_events()[0].dispatchType); | |
| 2156 EXPECT_EQ(10 + 10 * i, all_sent_events()[0].touches[0].position.x); | |
| 2157 EXPECT_EQ(10 + 10 * i, all_sent_events()[0].touches[0].position.y); | |
| 2158 EXPECT_EQ(static_cast<size_t>(i + 2), | |
| 2159 uncancelable_touch_moves_pending_ack_count()); | |
| 2160 EXPECT_EQ(WebInputEvent::TouchStart, all_sent_events()[1].type()); | |
| 2161 EXPECT_EQ(WebInputEvent::Blocking, all_sent_events()[1].dispatchType); | |
| 2162 EXPECT_EQ(2U, GetAndResetSentEventCount()); | |
| 2163 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | |
| 2164 | |
| 2165 SendTouchEventAckWithID(INPUT_EVENT_ACK_STATE_NOT_CONSUMED, | |
| 2166 GetUniqueTouchEventID()); | |
| 2167 EXPECT_EQ(0U, queued_event_count()); | |
| 2168 EXPECT_FALSE(HasPendingAsyncTouchMove()); | |
| 2169 EXPECT_EQ(0U, GetAndResetSentEventCount()); | |
| 2170 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 2171 } | |
| 2172 | |
| 2173 EXPECT_EQ(4U, uncancelable_touch_moves_pending_ack_count()); | |
| 2174 | |
| 2175 // When we receive an ack from render we decrease the count. | |
| 2176 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 2177 EXPECT_EQ(3U, uncancelable_touch_moves_pending_ack_count()); | |
| 2178 EXPECT_EQ(0U, queued_event_count()); | |
| 2179 EXPECT_FALSE(HasPendingAsyncTouchMove()); | |
| 2180 | |
| 2181 // Do not dispatch the next uncancelable touchmove when we have not received | |
| 2182 // all the acks back from render. | |
| 2183 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1); | |
| 2184 MoveTouchPoint(0, 20, 30); | |
| 2185 EXPECT_TRUE(HasPendingAsyncTouchMove()); | |
| 2186 EXPECT_EQ(0U, queued_event_count()); | |
| 2187 EXPECT_EQ(0U, GetAndResetSentEventCount()); | |
| 2188 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 2189 EXPECT_EQ(3U, uncancelable_touch_moves_pending_ack_count()); | |
| 2190 | |
| 2191 // Once we receive the ack from render, we do not dispatch the | |
| 2192 // pending_async_touchmove_ until the count is 0. | |
| 2193 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 2194 EXPECT_EQ(2U, uncancelable_touch_moves_pending_ack_count()); | |
| 2195 EXPECT_EQ(0U, queued_event_count()); | |
| 2196 EXPECT_TRUE(HasPendingAsyncTouchMove()); | |
| 2197 | |
| 2198 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 2199 | |
| 2200 // When we receive this ack from render, and the count is 0, so we can | |
| 2201 // dispatch the pending_async_touchmove_. | |
| 2202 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 2203 EXPECT_EQ(1U, uncancelable_touch_moves_pending_ack_count()); | |
| 2204 EXPECT_FALSE(HasPendingAsyncTouchMove()); | |
| 2205 EXPECT_EQ(0U, queued_event_count()); | |
| 2206 EXPECT_EQ(WebInputEvent::TouchMove, sent_event().type()); | |
| 2207 EXPECT_NE(WebInputEvent::Blocking, sent_event().dispatchType); | |
| 2208 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 2209 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | |
| 2210 } | |
| 2211 | |
| 2212 // Ensure that even when we receive the ack from render, we still need to wait | |
| 2213 // for the interval expires to send the next async touchmove once the scroll | |
| 2214 // starts. | |
| 2215 TEST_F(TouchEventQueueTest, DoNotIncreaseIfClientConsumeAsyncTouchMove) { | |
| 2216 // Process a TouchStart | |
| 2217 PressTouchPoint(0, 1); | |
| 2218 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 2219 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 2220 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 2221 | |
| 2222 // Initiate async touchmove dispatch after the start of a scroll sequence. | |
| 2223 MoveTouchPoint(0, 0, 5); | |
| 2224 WebGestureEvent followup_scroll(WebInputEvent::GestureScrollBegin, | |
| 2225 WebInputEvent::NoModifiers, | |
| 2226 WebInputEvent::TimeStampForTesting); | |
| 2227 SetFollowupEvent(followup_scroll); | |
| 2228 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 2229 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 2230 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 2231 | |
| 2232 MoveTouchPoint(0, 0, 10); | |
| 2233 followup_scroll.setType(WebInputEvent::GestureScrollUpdate); | |
| 2234 SetFollowupEvent(followup_scroll); | |
| 2235 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 2236 EXPECT_FALSE(HasPendingAsyncTouchMove()); | |
| 2237 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 2238 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 2239 | |
| 2240 // Dispatch the touch move event when sufficient time has passed. | |
| 2241 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1); | |
| 2242 MoveTouchPoint(0, 0, 40); | |
| 2243 EXPECT_FALSE(HasPendingAsyncTouchMove()); | |
| 2244 EXPECT_NE(WebInputEvent::Blocking, sent_event().dispatchType); | |
| 2245 // When we dispatch an async touchmove, we do not put it back to the queue | |
| 2246 // any more and we will ack to client right away. | |
| 2247 EXPECT_EQ(0U, queued_event_count()); | |
| 2248 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 2249 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 2250 EXPECT_EQ(1U, uncancelable_touch_moves_pending_ack_count()); | |
| 2251 | |
| 2252 // We receive an ack back from render but the time interval is not expired, | |
| 2253 // so we do not dispatch the touch move event. | |
| 2254 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 2255 EXPECT_EQ(0U, uncancelable_touch_moves_pending_ack_count()); | |
| 2256 MoveTouchPoint(0, 0, 50); | |
| 2257 EXPECT_TRUE(HasPendingAsyncTouchMove()); | |
| 2258 EXPECT_EQ(0U, queued_event_count()); | |
| 2259 EXPECT_EQ(0U, GetAndResetSentEventCount()); | |
| 2260 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 2261 | |
| 2262 // Dispatch the touch move when sufficient time has passed. Becasue the event | |
| 2263 // is consumed by client already, we would not increase the count and ack to | |
| 2264 // client again. | |
| 2265 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1); | |
| 2266 SetSyncAckResult(INPUT_EVENT_ACK_STATE_CONSUMED); | |
| 2267 MoveTouchPoint(0, 0, 50); | |
| 2268 EXPECT_FALSE(HasPendingAsyncTouchMove()); | |
| 2269 EXPECT_EQ(WebInputEvent::TouchMove, sent_event().type()); | |
| 2270 EXPECT_NE(WebInputEvent::Blocking, sent_event().dispatchType); | |
| 2271 EXPECT_EQ(0U, queued_event_count()); | |
| 2272 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 2273 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 2274 EXPECT_EQ(0U, uncancelable_touch_moves_pending_ack_count()); | |
| 2275 } | |
| 2276 | |
| 2277 TEST_F(TouchEventQueueTest, TouchAbsorptionWithConsumedFirstMove) { | |
| 2278 // Queue a TouchStart. | 1384 // Queue a TouchStart. |
| 2279 PressTouchPoint(0, 1); | 1385 PressTouchPoint(0, 1); |
| 2280 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1386 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 2281 EXPECT_EQ(0U, queued_event_count()); | 1387 EXPECT_EQ(0U, queued_event_count()); |
| 2282 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 1388 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 2283 | 1389 |
| 2284 MoveTouchPoint(0, 20, 5); | 1390 MoveTouchPoint(0, 20, 5); |
| 2285 SendGestureEvent(blink::WebInputEvent::GestureScrollBegin); | 1391 SendGestureEvent(blink::WebInputEvent::GestureScrollBegin); |
| 2286 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); | 1392 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 2287 EXPECT_EQ(0U, queued_event_count()); | 1393 EXPECT_EQ(0U, queued_event_count()); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 2300 WebInputEvent::NoModifiers, | 1406 WebInputEvent::NoModifiers, |
| 2301 WebInputEvent::TimeStampForTesting); | 1407 WebInputEvent::TimeStampForTesting); |
| 2302 SetFollowupEvent(followup_scroll); | 1408 SetFollowupEvent(followup_scroll); |
| 2303 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1409 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 2304 SendGestureEventAck(WebInputEvent::GestureScrollUpdate, | 1410 SendGestureEventAck(WebInputEvent::GestureScrollUpdate, |
| 2305 INPUT_EVENT_ACK_STATE_CONSUMED); | 1411 INPUT_EVENT_ACK_STATE_CONSUMED); |
| 2306 EXPECT_EQ(0U, queued_event_count()); | 1412 EXPECT_EQ(0U, queued_event_count()); |
| 2307 EXPECT_EQ(WebInputEvent::Blocking, sent_event().dispatchType); | 1413 EXPECT_EQ(WebInputEvent::Blocking, sent_event().dispatchType); |
| 2308 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 1414 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 2309 | 1415 |
| 2310 // Touch move event is throttled. | 1416 // Touch moves are sent right away. |
| 2311 MoveTouchPoint(0, 60, 5); | 1417 MoveTouchPoint(0, 60, 5); |
| 2312 EXPECT_EQ(0U, queued_event_count()); | 1418 EXPECT_EQ(1U, queued_event_count()); |
| 2313 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 1419 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 2314 } | 1420 } |
| 2315 | 1421 |
| 2316 TEST_F(TouchEventQueueTest, TouchStartCancelableDuringScroll) { | 1422 TEST_F(PassthroughTouchEventQueueTest, TouchStartCancelableDuringScroll) { |
| 2317 // Queue a touchstart and touchmove that go unconsumed, transitioning to an | 1423 // Queue a touchstart and touchmove that go unconsumed, transitioning to an |
| 2318 // active scroll sequence. | 1424 // active scroll sequence. |
| 2319 PressTouchPoint(0, 1); | 1425 PressTouchPoint(0, 1); |
| 2320 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1426 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 2321 EXPECT_EQ(WebInputEvent::Blocking, sent_event().dispatchType); | 1427 EXPECT_EQ(WebInputEvent::Blocking, sent_event().dispatchType); |
| 2322 ASSERT_EQ(1U, GetAndResetSentEventCount()); | 1428 ASSERT_EQ(1U, GetAndResetSentEventCount()); |
| 2323 | 1429 |
| 2324 MoveTouchPoint(0, 20, 5); | 1430 MoveTouchPoint(0, 20, 5); |
| 2325 EXPECT_EQ(WebInputEvent::Blocking, sent_event().dispatchType); | 1431 EXPECT_EQ(WebInputEvent::Blocking, sent_event().dispatchType); |
| 2326 SendGestureEvent(blink::WebInputEvent::GestureScrollBegin); | 1432 SendGestureEvent(blink::WebInputEvent::GestureScrollBegin); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2365 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1471 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 2366 EXPECT_NE(WebInputEvent::Blocking, sent_event().dispatchType); | 1472 EXPECT_NE(WebInputEvent::Blocking, sent_event().dispatchType); |
| 2367 ASSERT_EQ(1U, GetAndResetSentEventCount()); | 1473 ASSERT_EQ(1U, GetAndResetSentEventCount()); |
| 2368 | 1474 |
| 2369 // The touchend will be uncancelable during an active scroll sequence. | 1475 // The touchend will be uncancelable during an active scroll sequence. |
| 2370 ReleaseTouchPoint(0); | 1476 ReleaseTouchPoint(0); |
| 2371 EXPECT_NE(WebInputEvent::Blocking, sent_event().dispatchType); | 1477 EXPECT_NE(WebInputEvent::Blocking, sent_event().dispatchType); |
| 2372 ASSERT_EQ(1U, GetAndResetSentEventCount()); | 1478 ASSERT_EQ(1U, GetAndResetSentEventCount()); |
| 2373 } | 1479 } |
| 2374 | 1480 |
| 2375 TEST_F(TouchEventQueueTest, UnseenTouchPointerIdsNotForwarded) { | 1481 TEST_F(PassthroughTouchEventQueueTest, UnseenTouchPointerIdsNotForwarded) { |
| 2376 SyntheticWebTouchEvent event; | 1482 SyntheticWebTouchEvent event; |
| 2377 event.PressPoint(0, 0); | 1483 event.PressPoint(0, 0); |
| 2378 SendTouchEvent(event); | 1484 SendTouchEvent(event); |
| 2379 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 1485 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 2380 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); | 1486 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 2381 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 1487 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 2382 | 1488 |
| 2383 // Give the touchmove a previously unseen pointer id; it should not be sent. | 1489 // Give the touchmove a previously unseen pointer id; it should not be sent. |
| 2384 int press_id = event.touches[0].id; | 1490 int press_id = event.touches[0].id; |
| 2385 event.MovePoint(0, 1, 1); | 1491 event.MovePoint(0, 1, 1); |
| 2386 event.touches[0].id = 7; | 1492 event.touches[0].id = 7; |
| 2387 SendTouchEvent(event); | 1493 SendTouchEvent(event); |
| 2388 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 1494 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 2389 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 1495 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 2390 | 1496 |
| 2391 // Give the touchmove a valid id; it should be sent. | 1497 // Give the touchmove a valid id; it should be sent. |
| 2392 event.touches[0].id = press_id; | 1498 event.touches[0].id = press_id; |
| 2393 SendTouchEvent(event); | 1499 SendTouchEvent(event); |
| 2394 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 1500 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 2395 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); | 1501 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 2396 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 1502 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 2397 | 1503 |
| 2398 // Do the same for release. | 1504 // Do the same for release. |
| 2399 event.ReleasePoint(0); | 1505 event.ReleasePoint(0); |
| 2400 event.touches[0].id = 11; | 1506 event.touches[0].id = 11; |
| 2401 SendTouchEvent(event); | 1507 SendTouchEvent(event); |
| 2402 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 1508 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 2403 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 1509 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 2404 | 1510 |
| 2405 // Give the touchmove a valid id; it should be sent. | 1511 // Give the touchmove a valid id after release it shouldn't be sent. |
| 2406 event.touches[0].id = press_id; | 1512 event.touches[0].id = press_id; |
| 2407 SendTouchEvent(event); | 1513 SendTouchEvent(event); |
| 2408 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 1514 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 2409 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); | |
| 2410 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 1515 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 2411 } | 1516 } |
| 2412 | 1517 |
| 2413 // Tests that touch points states are correct in TouchMove events. | 1518 // Tests that touch points states are correct in TouchMove events. |
| 2414 TEST_F(TouchEventQueueTest, PointerStatesInTouchMove) { | 1519 TEST_F(PassthroughTouchEventQueueTest, PointerStatesInTouchMove) { |
| 2415 PressTouchPoint(1, 1); | 1520 PressTouchPoint(1, 1); |
| 2416 PressTouchPoint(2, 2); | 1521 PressTouchPoint(2, 2); |
| 2417 PressTouchPoint(3, 3); | 1522 PressTouchPoint(3, 3); |
| 1523 EXPECT_EQ(3U, queued_event_count()); |
| 1524 EXPECT_EQ(3U, GetAndResetSentEventCount()); |
| 2418 PressTouchPoint(4, 4); | 1525 PressTouchPoint(4, 4); |
| 2419 EXPECT_EQ(4U, queued_event_count()); | |
| 2420 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 2421 | 1526 |
| 2422 // Receive ACK for the first three touch-events. | 1527 // Receive ACK for the first three touch-events. |
| 2423 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); | 1528 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 2424 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); | 1529 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 2425 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); | 1530 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 2426 EXPECT_EQ(1U, queued_event_count()); | 1531 EXPECT_EQ(1U, queued_event_count()); |
| 2427 | 1532 |
| 2428 // Test current touches state before sending TouchMoves. | 1533 // Test current touches state before sending TouchMoves. |
| 2429 const WebTouchEvent& event1 = sent_event(); | 1534 const WebTouchEvent& event1 = sent_event(); |
| 2430 EXPECT_EQ(WebInputEvent::TouchStart, event1.type()); | 1535 EXPECT_EQ(WebInputEvent::TouchStart, event1.type()); |
| 2431 EXPECT_EQ(WebTouchPoint::StateStationary, event1.touches[0].state); | 1536 EXPECT_EQ(WebTouchPoint::StateStationary, event1.touches[0].state); |
| 2432 EXPECT_EQ(WebTouchPoint::StateStationary, event1.touches[1].state); | 1537 EXPECT_EQ(WebTouchPoint::StateStationary, event1.touches[1].state); |
| 2433 EXPECT_EQ(WebTouchPoint::StateStationary, event1.touches[2].state); | 1538 EXPECT_EQ(WebTouchPoint::StateStationary, event1.touches[2].state); |
| 2434 EXPECT_EQ(WebTouchPoint::StatePressed, event1.touches[3].state); | 1539 EXPECT_EQ(WebTouchPoint::StatePressed, event1.touches[3].state); |
| 2435 | 1540 |
| 2436 // Move x-position for 1st touch, y-position for 2nd touch | 1541 // Move x-position for 1st touch, y-position for 2nd touch |
| 2437 // and do not move other touches. | 1542 // and do not move other touches. |
| 2438 MoveTouchPoints(0, 1.1f, 1.f, 1, 2.f, 20.001f); | 1543 MoveTouchPoints(0, 1.1f, 1.f, 1, 2.f, 20.001f); |
| 2439 MoveTouchPoints(2, 3.f, 3.f, 3, 4.f, 4.f); | 1544 MoveTouchPoints(2, 3.f, 3.f, 3, 4.f, 4.f); |
| 2440 EXPECT_EQ(2U, queued_event_count()); | 1545 EXPECT_EQ(3U, queued_event_count()); |
| 2441 | 1546 |
| 2442 // Receive an ACK for the last TouchPress event. | 1547 // Receive an ACK for the last TouchPress event. |
| 2443 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); | 1548 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 2444 | 1549 |
| 2445 // 1st TouchMove is sent. Test for touches state. | 1550 // 1st TouchMove is sent. Test for touches state. |
| 2446 const WebTouchEvent& event2 = sent_event(); | 1551 const WebTouchEvent& event2 = sent_event(); |
| 2447 EXPECT_EQ(WebInputEvent::TouchMove, event2.type()); | 1552 EXPECT_EQ(WebInputEvent::TouchMove, event2.type()); |
| 2448 EXPECT_EQ(WebTouchPoint::StateMoved, event2.touches[0].state); | 1553 EXPECT_EQ(WebTouchPoint::StateMoved, event2.touches[0].state); |
| 2449 EXPECT_EQ(WebTouchPoint::StateMoved, event2.touches[1].state); | 1554 EXPECT_EQ(WebTouchPoint::StateMoved, event2.touches[1].state); |
| 2450 EXPECT_EQ(WebTouchPoint::StateStationary, event2.touches[2].state); | 1555 EXPECT_EQ(WebTouchPoint::StateStationary, event2.touches[2].state); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 2461 const WebTouchEvent& event3 = sent_event(); | 1566 const WebTouchEvent& event3 = sent_event(); |
| 2462 EXPECT_EQ(WebInputEvent::TouchMove, event3.type()); | 1567 EXPECT_EQ(WebInputEvent::TouchMove, event3.type()); |
| 2463 EXPECT_EQ(WebTouchPoint::StateStationary, event3.touches[0].state); | 1568 EXPECT_EQ(WebTouchPoint::StateStationary, event3.touches[0].state); |
| 2464 EXPECT_EQ(WebTouchPoint::StateStationary, event3.touches[1].state); | 1569 EXPECT_EQ(WebTouchPoint::StateStationary, event3.touches[1].state); |
| 2465 EXPECT_EQ(WebTouchPoint::StateStationary, event3.touches[2].state); | 1570 EXPECT_EQ(WebTouchPoint::StateStationary, event3.touches[2].state); |
| 2466 EXPECT_EQ(WebTouchPoint::StateMoved, event3.touches[3].state); | 1571 EXPECT_EQ(WebTouchPoint::StateMoved, event3.touches[3].state); |
| 2467 } | 1572 } |
| 2468 | 1573 |
| 2469 // Tests that touch point state is correct in TouchMove events | 1574 // Tests that touch point state is correct in TouchMove events |
| 2470 // when point properties other than position changed. | 1575 // when point properties other than position changed. |
| 2471 TEST_F(TouchEventQueueTest, PointerStatesWhenOtherThanPositionChanged) { | 1576 TEST_F(PassthroughTouchEventQueueTest, |
| 1577 PointerStatesWhenOtherThanPositionChanged) { |
| 2472 PressTouchPoint(1, 1); | 1578 PressTouchPoint(1, 1); |
| 2473 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); | 1579 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 2474 | 1580 |
| 2475 // Default initial radiusX/Y is (1.f, 1.f). | 1581 // Default initial radiusX/Y is (1.f, 1.f). |
| 2476 // Default initial rotationAngle is 1.f. | 1582 // Default initial rotationAngle is 1.f. |
| 2477 // Default initial force is 1.f. | 1583 // Default initial force is 1.f. |
| 2478 | 1584 |
| 2479 // Change touch point radius only. | 1585 // Change touch point radius only. |
| 2480 ChangeTouchPointRadius(0, 1.5f, 1.f); | 1586 ChangeTouchPointRadius(0, 1.5f, 1.f); |
| 2481 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); | 1587 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 2502 const WebTouchEvent& event3 = sent_event(); | 1608 const WebTouchEvent& event3 = sent_event(); |
| 2503 EXPECT_EQ(WebInputEvent::TouchMove, event3.type()); | 1609 EXPECT_EQ(WebInputEvent::TouchMove, event3.type()); |
| 2504 EXPECT_EQ(WebTouchPoint::StateMoved, event3.touches[0].state); | 1610 EXPECT_EQ(WebTouchPoint::StateMoved, event3.touches[0].state); |
| 2505 | 1611 |
| 2506 EXPECT_EQ(0U, queued_event_count()); | 1612 EXPECT_EQ(0U, queued_event_count()); |
| 2507 EXPECT_EQ(4U, GetAndResetSentEventCount()); | 1613 EXPECT_EQ(4U, GetAndResetSentEventCount()); |
| 2508 EXPECT_EQ(4U, GetAndResetAckedEventCount()); | 1614 EXPECT_EQ(4U, GetAndResetAckedEventCount()); |
| 2509 } | 1615 } |
| 2510 | 1616 |
| 2511 // Tests that TouchMoves are filtered when none of the points are changed. | 1617 // Tests that TouchMoves are filtered when none of the points are changed. |
| 2512 TEST_F(TouchEventQueueTest, FilterTouchMovesWhenNoPointerChanged) { | 1618 TEST_F(PassthroughTouchEventQueueTest, FilterTouchMovesWhenNoPointerChanged) { |
| 2513 PressTouchPoint(1, 1); | 1619 PressTouchPoint(1, 1); |
| 2514 PressTouchPoint(2, 2); | 1620 PressTouchPoint(2, 2); |
| 2515 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); | 1621 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 2516 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); | 1622 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 2517 EXPECT_EQ(0U, queued_event_count()); | 1623 EXPECT_EQ(0U, queued_event_count()); |
| 2518 EXPECT_EQ(2U, GetAndResetSentEventCount()); | 1624 EXPECT_EQ(2U, GetAndResetSentEventCount()); |
| 2519 EXPECT_EQ(2U, GetAndResetAckedEventCount()); | 1625 EXPECT_EQ(2U, GetAndResetAckedEventCount()); |
| 2520 | 1626 |
| 2521 // Move 1st touch point. | 1627 // Move 1st touch point. |
| 2522 MoveTouchPoint(0, 10, 10); | 1628 MoveTouchPoint(0, 10, 10); |
| 2523 EXPECT_EQ(1U, queued_event_count()); | 1629 EXPECT_EQ(1U, queued_event_count()); |
| 2524 | 1630 |
| 2525 // TouchMove should be allowed and test for touches state. | 1631 // TouchMove should be allowed and test for touches state. |
| 2526 const WebTouchEvent& event1 = sent_event(); | 1632 const WebTouchEvent& event1 = sent_event(); |
| 2527 EXPECT_EQ(WebInputEvent::TouchMove, event1.type()); | 1633 EXPECT_EQ(WebInputEvent::TouchMove, event1.type()); |
| 2528 EXPECT_EQ(WebTouchPoint::StateMoved, event1.touches[0].state); | 1634 EXPECT_EQ(WebTouchPoint::StateMoved, event1.touches[0].state); |
| 2529 EXPECT_EQ(WebTouchPoint::StateStationary, event1.touches[1].state); | 1635 EXPECT_EQ(WebTouchPoint::StateStationary, event1.touches[1].state); |
| 2530 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 1636 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 2531 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | 1637 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| 2532 | 1638 |
| 2533 // Do not really move any touch points, but use previous values. | 1639 // Do not really move any touch points, but use previous values. |
| 2534 MoveTouchPoint(0, 10, 10); | 1640 MoveTouchPoint(0, 10, 10); |
| 2535 ChangeTouchPointRadius(1, 1, 1); | 1641 ChangeTouchPointRadius(1, 1, 1); |
| 2536 MoveTouchPoint(1, 2, 2); | 1642 MoveTouchPoint(1, 2, 2); |
| 2537 EXPECT_EQ(2U, queued_event_count()); | 1643 EXPECT_EQ(4U, queued_event_count()); |
| 2538 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 1644 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 1645 // The TouchMove but should be filtered when none of the touch points have |
| 1646 // changed but don't get acked right away. |
| 1647 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| 2539 | 1648 |
| 2540 // Receive an ACK for 1st TouchMove. | 1649 // Receive an ACK for 1st TouchMove. |
| 2541 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); | 1650 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 2542 | 1651 |
| 2543 // Tries to forward TouchMove but should be filtered | |
| 2544 // when none of the touch points have changed. | |
| 2545 EXPECT_EQ(0U, queued_event_count()); | 1652 EXPECT_EQ(0U, queued_event_count()); |
| 2546 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 1653 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 2547 EXPECT_EQ(4U, GetAndResetAckedEventCount()); | 1654 EXPECT_EQ(4U, GetAndResetAckedEventCount()); |
| 2548 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, acked_event_state()); | 1655 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, acked_event_state()); |
| 2549 | 1656 |
| 2550 // Move 2nd touch point. | 1657 // Move 2nd touch point. |
| 2551 MoveTouchPoint(1, 3, 3); | 1658 MoveTouchPoint(1, 3, 3); |
| 2552 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); | 1659 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 2553 EXPECT_EQ(0U, queued_event_count()); | 1660 EXPECT_EQ(0U, queued_event_count()); |
| 2554 | 1661 |
| 2555 // TouchMove should be allowed and test for touches state. | 1662 // TouchMove should be allowed and test for touches state. |
| 2556 const WebTouchEvent& event2 = sent_event(); | 1663 const WebTouchEvent& event2 = sent_event(); |
| 2557 EXPECT_EQ(WebInputEvent::TouchMove, event2.type()); | 1664 EXPECT_EQ(WebInputEvent::TouchMove, event2.type()); |
| 2558 EXPECT_EQ(WebTouchPoint::StateStationary, event2.touches[0].state); | 1665 EXPECT_EQ(WebTouchPoint::StateStationary, event2.touches[0].state); |
| 2559 EXPECT_EQ(WebTouchPoint::StateMoved, event2.touches[1].state); | 1666 EXPECT_EQ(WebTouchPoint::StateMoved, event2.touches[1].state); |
| 2560 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 1667 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 2561 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 1668 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 2562 } | 1669 } |
| 2563 | 1670 |
| 2564 // Tests that touch-scroll-notification is not pushed into an empty queue. | 1671 // Tests that touch-scroll-notification is queued normally. |
| 2565 TEST_F(TouchEventQueueTest, TouchScrollNotificationOrder_EmptyQueue) { | 1672 TEST_F(PassthroughTouchEventQueueTest, |
| 1673 TouchScrollNotificationOrder_EmptyQueue) { |
| 2566 PrependTouchScrollNotification(); | 1674 PrependTouchScrollNotification(); |
| 2567 | 1675 |
| 2568 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | 1676 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| 2569 EXPECT_EQ(0U, queued_event_count()); | 1677 EXPECT_EQ(1U, queued_event_count()); |
| 2570 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 1678 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 2571 } | 1679 } |
| 2572 | 1680 |
| 2573 // Tests touch-scroll-notification firing order when the event is placed at the | 1681 // Tests touch-scroll-notification firing is appended to the tail of sent |
| 2574 // end of touch queue because of a pending ack for the head of the queue. | 1682 // events since all events are sent right away. |
| 2575 TEST_F(TouchEventQueueTest, TouchScrollNotificationOrder_EndOfQueue) { | 1683 TEST_F(PassthroughTouchEventQueueTest, |
| 1684 TouchScrollNotificationOrder_EndOfQueue) { |
| 2576 PressTouchPoint(1, 1); | 1685 PressTouchPoint(1, 1); |
| 2577 | 1686 |
| 2578 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | 1687 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| 2579 EXPECT_EQ(1U, queued_event_count()); | 1688 EXPECT_EQ(1U, queued_event_count()); |
| 2580 | 1689 |
| 2581 // Send the touch-scroll-notification when 3 events are in the queue. | 1690 // Send the touch-scroll-notification when 3 events are in the queue. |
| 2582 PrependTouchScrollNotification(); | 1691 PrependTouchScrollNotification(); |
| 2583 | 1692 |
| 2584 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | 1693 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| 2585 EXPECT_EQ(2U, queued_event_count()); | 1694 EXPECT_EQ(2U, queued_event_count()); |
| 2586 | 1695 |
| 2587 // Receive an ACK for the touchstart. | 1696 // Send ACKs. |
| 2588 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); | 1697 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 2589 | |
| 2590 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 2591 EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type()); | |
| 2592 EXPECT_EQ(1U, queued_event_count()); | |
| 2593 | |
| 2594 // Receive an ACK for the touch-scroll-notification. | |
| 2595 SendTouchEventAck(INPUT_EVENT_ACK_STATE_IGNORED); | 1698 SendTouchEventAck(INPUT_EVENT_ACK_STATE_IGNORED); |
| 2596 | 1699 |
| 2597 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | 1700 // Touch-scroll-start Ack is not reported to client. |
| 1701 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 2598 EXPECT_EQ(0U, queued_event_count()); | 1702 EXPECT_EQ(0U, queued_event_count()); |
| 2599 | 1703 |
| 2600 EXPECT_EQ(WebInputEvent::TouchStart, all_sent_events()[0].type()); | 1704 EXPECT_EQ(WebInputEvent::TouchStart, all_sent_events()[0].type()); |
| 2601 EXPECT_EQ(WebInputEvent::TouchScrollStarted, all_sent_events()[1].type()); | 1705 EXPECT_EQ(WebInputEvent::TouchScrollStarted, all_sent_events()[1].type()); |
| 2602 EXPECT_EQ(2U, GetAndResetSentEventCount()); | 1706 EXPECT_EQ(2U, GetAndResetSentEventCount()); |
| 2603 } | 1707 } |
| 2604 | 1708 |
| 2605 // Tests touch-scroll-notification firing order when the event is placed in the | |
| 2606 // 2nd position in the touch queue between two events. | |
| 2607 TEST_F(TouchEventQueueTest, TouchScrollNotificationOrder_SecondPosition) { | |
| 2608 PressTouchPoint(1, 1); | |
| 2609 MoveTouchPoint(0, 5, 5); | |
| 2610 ReleaseTouchPoint(0); | |
| 2611 | |
| 2612 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | |
| 2613 EXPECT_EQ(3U, queued_event_count()); | |
| 2614 | |
| 2615 // Send the touch-scroll-notification when 3 events are in the queue. | |
| 2616 PrependTouchScrollNotification(); | |
| 2617 | |
| 2618 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | |
| 2619 EXPECT_EQ(4U, queued_event_count()); | |
| 2620 | |
| 2621 // Receive an ACK for the touchstart. | |
| 2622 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); | |
| 2623 | |
| 2624 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 2625 EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type()); | |
| 2626 EXPECT_EQ(3U, queued_event_count()); | |
| 2627 | |
| 2628 // Receive an ACK for the touch-scroll-notification. | |
| 2629 SendTouchEventAck(INPUT_EVENT_ACK_STATE_IGNORED); | |
| 2630 | |
| 2631 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | |
| 2632 EXPECT_EQ(2U, queued_event_count()); | |
| 2633 | |
| 2634 // Receive an ACK for the touchmove. | |
| 2635 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); | |
| 2636 | |
| 2637 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 2638 EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type()); | |
| 2639 EXPECT_EQ(1U, queued_event_count()); | |
| 2640 | |
| 2641 // Receive an ACK for the touchend. | |
| 2642 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); | |
| 2643 | |
| 2644 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 2645 EXPECT_EQ(WebInputEvent::TouchEnd, acked_event().type()); | |
| 2646 EXPECT_EQ(0U, queued_event_count()); | |
| 2647 | |
| 2648 EXPECT_EQ(WebInputEvent::TouchStart, all_sent_events()[0].type()); | |
| 2649 EXPECT_EQ(WebInputEvent::TouchScrollStarted, all_sent_events()[1].type()); | |
| 2650 EXPECT_EQ(WebInputEvent::TouchMove, all_sent_events()[2].type()); | |
| 2651 EXPECT_EQ(WebInputEvent::TouchEnd, all_sent_events()[3].type()); | |
| 2652 EXPECT_EQ(4U, GetAndResetSentEventCount()); | |
| 2653 } | |
| 2654 | |
| 2655 // Tests that if touchStartOrFirstTouchMove is correctly set up for touch | 1709 // Tests that if touchStartOrFirstTouchMove is correctly set up for touch |
| 2656 // events. | 1710 // events. |
| 2657 TEST_F(TouchEventQueueTest, TouchStartOrFirstTouchMove) { | 1711 TEST_F(PassthroughTouchEventQueueTest, TouchStartOrFirstTouchMove) { |
| 2658 PressTouchPoint(1, 1); | 1712 PressTouchPoint(1, 1); |
| 2659 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); | 1713 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 2660 EXPECT_EQ(WebInputEvent::TouchStart, sent_event().type()); | 1714 EXPECT_EQ(WebInputEvent::TouchStart, sent_event().type()); |
| 2661 EXPECT_TRUE(sent_event().touchStartOrFirstTouchMove); | 1715 EXPECT_TRUE(sent_event().touchStartOrFirstTouchMove); |
| 2662 | 1716 |
| 2663 MoveTouchPoint(0, 5, 5); | 1717 MoveTouchPoint(0, 5, 5); |
| 2664 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); | 1718 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 2665 EXPECT_EQ(WebInputEvent::TouchMove, sent_event().type()); | 1719 EXPECT_EQ(WebInputEvent::TouchMove, sent_event().type()); |
| 2666 EXPECT_TRUE(sent_event().touchStartOrFirstTouchMove); | 1720 EXPECT_TRUE(sent_event().touchStartOrFirstTouchMove); |
| 2667 | 1721 |
| 2668 MoveTouchPoint(0, 15, 15); | 1722 MoveTouchPoint(0, 15, 15); |
| 2669 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); | 1723 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 2670 EXPECT_EQ(WebInputEvent::TouchMove, sent_event().type()); | 1724 EXPECT_EQ(WebInputEvent::TouchMove, sent_event().type()); |
| 2671 EXPECT_FALSE(sent_event().touchStartOrFirstTouchMove); | 1725 EXPECT_FALSE(sent_event().touchStartOrFirstTouchMove); |
| 2672 | 1726 |
| 2673 ReleaseTouchPoint(0); | 1727 ReleaseTouchPoint(0); |
| 2674 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); | 1728 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 2675 EXPECT_EQ(WebInputEvent::TouchEnd, sent_event().type()); | 1729 EXPECT_EQ(WebInputEvent::TouchEnd, sent_event().type()); |
| 2676 EXPECT_FALSE(sent_event().touchStartOrFirstTouchMove); | 1730 EXPECT_FALSE(sent_event().touchStartOrFirstTouchMove); |
| 2677 } | 1731 } |
| 2678 | 1732 |
| 2679 } // namespace content | 1733 } // namespace content |
| OLD | NEW |