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

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

Issue 997283002: Coalesce async touch move events until the ack back from render (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use queue to store the IDs for sent async touchmove Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/logging.h" 6 #include "base/logging.h"
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "content/browser/renderer_host/input/timeout_monitor.h" 9 #include "content/browser/renderer_host/input/timeout_monitor.h"
10 #include "content/browser/renderer_host/input/touch_event_queue.h" 10 #include "content/browser/renderer_host/input/touch_event_queue.h"
(...skipping 16 matching lines...) Expand all
27 27
28 base::TimeDelta DefaultTouchTimeoutDelay() { 28 base::TimeDelta DefaultTouchTimeoutDelay() {
29 return base::TimeDelta::FromMilliseconds(1); 29 return base::TimeDelta::FromMilliseconds(1);
30 } 30 }
31 } // namespace 31 } // namespace
32 32
33 class TouchEventQueueTest : public testing::Test, 33 class TouchEventQueueTest : public testing::Test,
34 public TouchEventQueueClient { 34 public TouchEventQueueClient {
35 public: 35 public:
36 TouchEventQueueTest() 36 TouchEventQueueTest()
37 : sent_event_count_(0), 37 : acked_event_count_(0),
38 acked_event_count_(0),
39 last_acked_event_state_(INPUT_EVENT_ACK_STATE_UNKNOWN), 38 last_acked_event_state_(INPUT_EVENT_ACK_STATE_UNKNOWN),
40 slop_length_dips_(0) {} 39 slop_length_dips_(0) {}
41 40
42 ~TouchEventQueueTest() override {} 41 ~TouchEventQueueTest() override {}
43 42
44 // testing::Test 43 // testing::Test
45 void SetUp() override { 44 void SetUp() override {
46 ResetQueueWithConfig(TouchEventQueue::Config()); 45 ResetQueueWithConfig(TouchEventQueue::Config());
46 sent_events_ids_.clear();
47 } 47 }
48 48
49 void TearDown() override { queue_.reset(); } 49 void TearDown() override { queue_.reset(); }
50 50
51 // TouchEventQueueClient 51 // TouchEventQueueClient
52 void SendTouchEventImmediately( 52 void SendTouchEventImmediately(
53 const TouchEventWithLatencyInfo& event) override { 53 const TouchEventWithLatencyInfo& event) override {
54 ++sent_event_count_; 54 sent_events_.push_back(event.event);
55 last_sent_event_ = event.event; 55 sent_events_ids_.push_back(event.event.uniqueTouchEventId);
56 if (sync_ack_result_) { 56 if (sync_ack_result_) {
57 auto sync_ack_result = sync_ack_result_.Pass(); 57 auto sync_ack_result = sync_ack_result_.Pass();
58 SendTouchEventAck(*sync_ack_result); 58 SendTouchEventAck(*sync_ack_result);
59 } 59 }
60 } 60 }
61 61
62 void OnTouchEventAck(const TouchEventWithLatencyInfo& event, 62 void OnTouchEventAck(const TouchEventWithLatencyInfo& event,
63 InputEventAckState ack_result) override { 63 InputEventAckState ack_result) override {
64 ++acked_event_count_; 64 ++acked_event_count_;
65 last_acked_event_ = event.event; 65 last_acked_event_ = event.event;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 } 108 }
109 109
110 void SendGestureEvent(WebInputEvent::Type type) { 110 void SendGestureEvent(WebInputEvent::Type type) {
111 WebGestureEvent event; 111 WebGestureEvent event;
112 event.type = type; 112 event.type = type;
113 queue_->OnGestureScrollEvent( 113 queue_->OnGestureScrollEvent(
114 GestureEventWithLatencyInfo(event, ui::LatencyInfo())); 114 GestureEventWithLatencyInfo(event, ui::LatencyInfo()));
115 } 115 }
116 116
117 void SendTouchEventAck(InputEventAckState ack_result) { 117 void SendTouchEventAck(InputEventAckState ack_result) {
118 queue_->ProcessTouchAck(ack_result, ui::LatencyInfo()); 118 DCHECK(!sent_events_ids_.empty());
119 queue_->ProcessTouchAck(ack_result, ui::LatencyInfo(),
120 sent_events_ids_.front());
121 sent_events_ids_.pop_front();
122 }
123
124 void SendTouchEventAckWithID(InputEventAckState ack_result,
125 int unique_event_id) {
126 queue_->ProcessTouchAck(ack_result, ui::LatencyInfo(), unique_event_id);
127 sent_events_ids_.erase(std::remove(sent_events_ids_.begin(),
128 sent_events_ids_.end(), unique_event_id),
129 sent_events_ids_.end());
119 } 130 }
120 131
121 void SendGestureEventAck(WebInputEvent::Type type, 132 void SendGestureEventAck(WebInputEvent::Type type,
122 InputEventAckState ack_result) { 133 InputEventAckState ack_result) {
123 blink::WebGestureEvent gesture_event; 134 blink::WebGestureEvent gesture_event;
124 gesture_event.type = type; 135 gesture_event.type = type;
125 GestureEventWithLatencyInfo event(gesture_event, ui::LatencyInfo()); 136 GestureEventWithLatencyInfo event(gesture_event, ui::LatencyInfo());
126 queue_->OnGestureEventAck(event, ack_result); 137 queue_->OnGestureEventAck(event, ack_result);
127 } 138 }
128 139
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 touch_event_ = SyntheticWebTouchEvent(); 228 touch_event_ = SyntheticWebTouchEvent();
218 } 229 }
219 230
220 size_t GetAndResetAckedEventCount() { 231 size_t GetAndResetAckedEventCount() {
221 size_t count = acked_event_count_; 232 size_t count = acked_event_count_;
222 acked_event_count_ = 0; 233 acked_event_count_ = 0;
223 return count; 234 return count;
224 } 235 }
225 236
226 size_t GetAndResetSentEventCount() { 237 size_t GetAndResetSentEventCount() {
227 size_t count = sent_event_count_; 238 size_t count = sent_events_.size();
228 sent_event_count_ = 0; 239 sent_events_.clear();
229 return count; 240 return count;
230 } 241 }
231 242
232 bool IsPendingAckTouchStart() const { 243 bool IsPendingAckTouchStart() const {
233 return queue_->IsPendingAckTouchStart(); 244 return queue_->IsPendingAckTouchStart();
234 } 245 }
235 246
236 void OnHasTouchEventHandlers(bool has_handlers) { 247 void OnHasTouchEventHandlers(bool has_handlers) {
237 queue_->OnHasTouchEventHandlers(has_handlers); 248 queue_->OnHasTouchEventHandlers(has_handlers);
238 } 249 }
(...skipping 12 matching lines...) Expand all
251 262
252 const WebTouchEvent& latest_event() const { 263 const WebTouchEvent& latest_event() const {
253 return queue_->GetLatestEventForTesting().event; 264 return queue_->GetLatestEventForTesting().event;
254 } 265 }
255 266
256 const WebTouchEvent& acked_event() const { 267 const WebTouchEvent& acked_event() const {
257 return last_acked_event_; 268 return last_acked_event_;
258 } 269 }
259 270
260 const WebTouchEvent& sent_event() const { 271 const WebTouchEvent& sent_event() const {
261 return last_sent_event_; 272 DCHECK(!sent_events_.empty());
273 return sent_events_.back();
274 }
275
276 const std::vector<WebTouchEvent>& all_sent_events() const {
277 return sent_events_;
262 } 278 }
263 279
264 InputEventAckState acked_event_state() const { 280 InputEventAckState acked_event_state() const {
265 return last_acked_event_state_; 281 return last_acked_event_state_;
266 } 282 }
267 283
268 static void RunTasksAndWait(base::TimeDelta delay) { 284 static void RunTasksAndWait(base::TimeDelta delay) {
269 base::MessageLoop::current()->PostDelayedTask( 285 base::MessageLoop::current()->PostDelayedTask(
270 FROM_HERE, base::MessageLoop::QuitClosure(), delay); 286 FROM_HERE, base::MessageLoop::QuitClosure(), delay);
271 base::MessageLoop::current()->Run(); 287 base::MessageLoop::current()->Run();
272 } 288 }
273 289
290 size_t uncancelable_touch_moves_pending_ack_count() const {
291 return queue_->uncancelable_touch_moves_pending_ack_count();
292 }
293
294 int GetUniqueTouchEventID() { return sent_events_ids_.back(); }
295
274 private: 296 private:
275 void SendTouchEvent() { 297 void SendTouchEvent() {
276 SendTouchEvent(touch_event_); 298 SendTouchEvent(touch_event_);
277 touch_event_.ResetPoints(); 299 touch_event_.ResetPoints();
278 } 300 }
279 301
280 void ResetQueueWithConfig(const TouchEventQueue::Config& config) { 302 void ResetQueueWithConfig(const TouchEventQueue::Config& config) {
281 queue_.reset(new TouchEventQueue(this, config)); 303 queue_.reset(new TouchEventQueue(this, config));
282 queue_->OnHasTouchEventHandlers(true); 304 queue_->OnHasTouchEventHandlers(true);
283 } 305 }
284 306
285 scoped_ptr<TouchEventQueue> queue_; 307 scoped_ptr<TouchEventQueue> queue_;
286 size_t sent_event_count_;
287 size_t acked_event_count_; 308 size_t acked_event_count_;
288 WebTouchEvent last_sent_event_;
289 WebTouchEvent last_acked_event_; 309 WebTouchEvent last_acked_event_;
310 std::vector<WebTouchEvent> sent_events_;
290 InputEventAckState last_acked_event_state_; 311 InputEventAckState last_acked_event_state_;
291 SyntheticWebTouchEvent touch_event_; 312 SyntheticWebTouchEvent touch_event_;
292 scoped_ptr<WebTouchEvent> followup_touch_event_; 313 scoped_ptr<WebTouchEvent> followup_touch_event_;
293 scoped_ptr<WebGestureEvent> followup_gesture_event_; 314 scoped_ptr<WebGestureEvent> followup_gesture_event_;
294 scoped_ptr<InputEventAckState> sync_ack_result_; 315 scoped_ptr<InputEventAckState> sync_ack_result_;
295 double slop_length_dips_; 316 double slop_length_dips_;
296 gfx::PointF anchor_; 317 gfx::PointF anchor_;
297 base::MessageLoopForUI message_loop_; 318 base::MessageLoopForUI message_loop_;
319 std::deque<int> sent_events_ids_;
298 }; 320 };
299 321
300 322
301 // Tests that touch-events are queued properly. 323 // Tests that touch-events are queued properly.
302 TEST_F(TouchEventQueueTest, Basic) { 324 TEST_F(TouchEventQueueTest, Basic) {
303 PressTouchPoint(1, 1); 325 PressTouchPoint(1, 1);
304 EXPECT_EQ(1U, queued_event_count()); 326 EXPECT_EQ(1U, queued_event_count());
305 EXPECT_EQ(1U, GetAndResetSentEventCount()); 327 EXPECT_EQ(1U, GetAndResetSentEventCount());
306 328
307 // The second touch should not be sent since one is already in queue. 329 // The second touch should not be sent since one is already in queue.
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
640 // Make sure both fingers are marked as having been moved in the coalesced 662 // Make sure both fingers are marked as having been moved in the coalesced
641 // event. 663 // event.
642 const WebTouchEvent& event = latest_event(); 664 const WebTouchEvent& event = latest_event();
643 EXPECT_EQ(WebTouchPoint::StateMoved, event.touches[0].state); 665 EXPECT_EQ(WebTouchPoint::StateMoved, event.touches[0].state);
644 EXPECT_EQ(WebTouchPoint::StateMoved, event.touches[1].state); 666 EXPECT_EQ(WebTouchPoint::StateMoved, event.touches[1].state);
645 } 667 }
646 668
647 // Tests that the touch-event queue is robust to redundant acks. 669 // Tests that the touch-event queue is robust to redundant acks.
648 TEST_F(TouchEventQueueTest, SpuriousAcksIgnored) { 670 TEST_F(TouchEventQueueTest, SpuriousAcksIgnored) {
649 // Trigger a spurious ack. 671 // Trigger a spurious ack.
650 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); 672 SendTouchEventAckWithID(INPUT_EVENT_ACK_STATE_CONSUMED, 0);
651 EXPECT_EQ(0U, GetAndResetAckedEventCount()); 673 EXPECT_EQ(0U, GetAndResetAckedEventCount());
652 674
653 // Send and ack a touch press. 675 // Send and ack a touch press.
654 PressTouchPoint(1, 1); 676 PressTouchPoint(1, 1);
655 EXPECT_EQ(1U, GetAndResetSentEventCount()); 677 EXPECT_EQ(1U, GetAndResetSentEventCount());
656 EXPECT_EQ(1U, queued_event_count()); 678 EXPECT_EQ(1U, queued_event_count());
657 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); 679 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
658 EXPECT_EQ(1U, GetAndResetAckedEventCount()); 680 EXPECT_EQ(1U, GetAndResetAckedEventCount());
659 EXPECT_EQ(0U, queued_event_count()); 681 EXPECT_EQ(0U, queued_event_count());
660 682
661 // Trigger a spurious ack. 683 // Trigger a spurious ack.
662 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); 684 SendTouchEventAckWithID(INPUT_EVENT_ACK_STATE_CONSUMED, 3);
663 EXPECT_EQ(0U, GetAndResetAckedEventCount()); 685 EXPECT_EQ(0U, GetAndResetAckedEventCount());
664 } 686 }
665 687
666 // Tests that touch-move events are not sent to the renderer if the preceding 688 // Tests that touch-move events are not sent to the renderer if the preceding
667 // touch-press event did not have a consumer (and consequently, did not hit the 689 // touch-press event did not have a consumer (and consequently, did not hit the
668 // main thread in the renderer). Also tests that all queued/coalesced touch 690 // main thread in the renderer). Also tests that all queued/coalesced touch
669 // events are flushed immediately when the ACK for the touch-press comes back 691 // events are flushed immediately when the ACK for the touch-press comes back
670 // with NO_CONSUMER status. 692 // with NO_CONSUMER status.
671 TEST_F(TouchEventQueueTest, NoConsumer) { 693 TEST_F(TouchEventQueueTest, NoConsumer) {
672 // The first touch-press should reach the renderer. 694 // The first touch-press should reach the renderer.
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
1023 // The timeout should have fired, synthetically ack'ing the timed-out event. 1045 // The timeout should have fired, synthetically ack'ing the timed-out event.
1024 // TouchEvent forwarding is disabled until the ack is received for the 1046 // TouchEvent forwarding is disabled until the ack is received for the
1025 // timed-out event and the future cancel event. 1047 // timed-out event and the future cancel event.
1026 EXPECT_FALSE(IsTimeoutRunning()); 1048 EXPECT_FALSE(IsTimeoutRunning());
1027 EXPECT_EQ(0U, GetAndResetSentEventCount()); 1049 EXPECT_EQ(0U, GetAndResetSentEventCount());
1028 EXPECT_EQ(1U, GetAndResetAckedEventCount()); 1050 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1029 1051
1030 // Ack'ing the original event should trigger a cancel event. 1052 // Ack'ing the original event should trigger a cancel event.
1031 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 1053 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1032 EXPECT_FALSE(IsTimeoutRunning()); 1054 EXPECT_FALSE(IsTimeoutRunning());
1055 EXPECT_EQ(WebInputEvent::TouchCancel, sent_event().type);
1056 EXPECT_FALSE(sent_event().cancelable);
1033 EXPECT_EQ(0U, GetAndResetAckedEventCount()); 1057 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1034 EXPECT_EQ(1U, GetAndResetSentEventCount()); 1058 EXPECT_EQ(1U, GetAndResetSentEventCount());
1035 EXPECT_EQ(WebInputEvent::TouchCancel, sent_event().type);
1036 EXPECT_FALSE(sent_event().cancelable);
1037 1059
1038 // Touch events should not be forwarded until we receive the cancel acks. 1060 // Touch events should not be forwarded until we receive the cancel acks.
1039 MoveTouchPoint(0, 1, 1); 1061 MoveTouchPoint(0, 1, 1);
1040 ASSERT_EQ(0U, GetAndResetSentEventCount()); 1062 ASSERT_EQ(0U, GetAndResetSentEventCount());
1041 ASSERT_EQ(1U, GetAndResetAckedEventCount()); 1063 ASSERT_EQ(1U, GetAndResetAckedEventCount());
1042 1064
1043 ReleaseTouchPoint(0); 1065 ReleaseTouchPoint(0);
1044 ASSERT_EQ(0U, GetAndResetSentEventCount()); 1066 ASSERT_EQ(0U, GetAndResetSentEventCount());
1045 ASSERT_EQ(1U, GetAndResetAckedEventCount()); 1067 ASSERT_EQ(1U, GetAndResetAckedEventCount());
1046 1068
1047 // The synthetic TouchCancel ack should not reach the client, but should 1069 // The synthetic TouchCancel ack should not reach the client, but should
1048 // resume touch forwarding. 1070 // resume touch forwarding.
1049 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 1071 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1050 EXPECT_EQ(0U, GetAndResetSentEventCount()); 1072 EXPECT_EQ(0U, GetAndResetSentEventCount());
1051 EXPECT_EQ(0U, GetAndResetAckedEventCount()); 1073 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1052 1074
1053 // Subsequent events should be handled normally. 1075 // Subsequent events should be handled normally.
1054 PressTouchPoint(0, 1); 1076 PressTouchPoint(0, 1);
1077 EXPECT_EQ(WebInputEvent::TouchStart, sent_event().type);
1078 EXPECT_TRUE(sent_event().cancelable);
1055 EXPECT_EQ(1U, GetAndResetSentEventCount()); 1079 EXPECT_EQ(1U, GetAndResetSentEventCount());
1056 EXPECT_EQ(0U, GetAndResetAckedEventCount()); 1080 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1057 EXPECT_EQ(WebInputEvent::TouchStart, sent_event().type);
1058 EXPECT_TRUE(sent_event().cancelable);
1059 } 1081 }
1060 1082
1061 // Tests that the timeout is never started if the renderer consumes 1083 // Tests that the timeout is never started if the renderer consumes
1062 // a TouchEvent from the current touch sequence. 1084 // a TouchEvent from the current touch sequence.
1063 TEST_F(TouchEventQueueTest, NoTouchTimeoutIfRendererIsConsumingGesture) { 1085 TEST_F(TouchEventQueueTest, NoTouchTimeoutIfRendererIsConsumingGesture) {
1064 SetUpForTimeoutTesting(DefaultTouchTimeoutDelay()); 1086 SetUpForTimeoutTesting(DefaultTouchTimeoutDelay());
1065 1087
1066 // Queue a TouchStart. 1088 // Queue a TouchStart.
1067 PressTouchPoint(0, 1); 1089 PressTouchPoint(0, 1);
1068 ASSERT_TRUE(IsTimeoutRunning()); 1090 ASSERT_TRUE(IsTimeoutRunning());
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after
1533 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 1555 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1534 EXPECT_FALSE(HasPendingAsyncTouchMove()); 1556 EXPECT_FALSE(HasPendingAsyncTouchMove());
1535 EXPECT_TRUE(sent_event().cancelable); 1557 EXPECT_TRUE(sent_event().cancelable);
1536 EXPECT_EQ(0U, queued_event_count()); 1558 EXPECT_EQ(0U, queued_event_count());
1537 EXPECT_EQ(1U, GetAndResetSentEventCount()); 1559 EXPECT_EQ(1U, GetAndResetSentEventCount());
1538 1560
1539 // Consuming a scroll event will throttle subsequent touchmoves. 1561 // Consuming a scroll event will throttle subsequent touchmoves.
1540 SendGestureEventAck(WebInputEvent::GestureScrollUpdate, 1562 SendGestureEventAck(WebInputEvent::GestureScrollUpdate,
1541 INPUT_EVENT_ACK_STATE_CONSUMED); 1563 INPUT_EVENT_ACK_STATE_CONSUMED);
1542 MoveTouchPoint(0, 10, 7+i); 1564 MoveTouchPoint(0, 10, 7+i);
1543 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1544 EXPECT_TRUE(HasPendingAsyncTouchMove()); 1565 EXPECT_TRUE(HasPendingAsyncTouchMove());
1545 EXPECT_EQ(0U, queued_event_count()); 1566 EXPECT_EQ(0U, queued_event_count());
1546 EXPECT_EQ(0U, GetAndResetSentEventCount()); 1567 EXPECT_EQ(0U, GetAndResetSentEventCount());
1547 } 1568 }
1548 } 1569 }
1549 1570
1550 // Ensure that touchmove's are appropriately throttled during a typical 1571 // Ensure that touchmove's are appropriately throttled during a typical
1551 // scroll sequences that transitions between scrolls consumed and unconsumed. 1572 // scroll sequences that transitions between scrolls consumed and unconsumed.
1552 TEST_F(TouchEventQueueTest, AsyncTouchThrottledAfterScroll) { 1573 TEST_F(TouchEventQueueTest, AsyncTouchThrottledAfterScroll) {
1553 // Process a TouchStart 1574 // Process a TouchStart
(...skipping 18 matching lines...) Expand all
1572 MoveTouchPoint(0, 0, 50); 1593 MoveTouchPoint(0, 0, 50);
1573 followup_scroll.type = WebInputEvent::GestureScrollUpdate; 1594 followup_scroll.type = WebInputEvent::GestureScrollUpdate;
1574 SetFollowupEvent(followup_scroll); 1595 SetFollowupEvent(followup_scroll);
1575 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 1596 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1576 EXPECT_EQ(1U, GetAndResetSentEventCount()); 1597 EXPECT_EQ(1U, GetAndResetSentEventCount());
1577 EXPECT_EQ(1U, GetAndResetAckedEventCount()); 1598 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1578 1599
1579 // Now queue a second touchmove and verify it's not (yet) dispatched. 1600 // Now queue a second touchmove and verify it's not (yet) dispatched.
1580 MoveTouchPoint(0, 0, 100); 1601 MoveTouchPoint(0, 0, 100);
1581 SetFollowupEvent(followup_scroll); 1602 SetFollowupEvent(followup_scroll);
1582 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 1603 // SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1583 EXPECT_TRUE(HasPendingAsyncTouchMove()); 1604 EXPECT_TRUE(HasPendingAsyncTouchMove());
1584 EXPECT_EQ(0U, queued_event_count()); 1605 EXPECT_EQ(0U, queued_event_count());
1585 EXPECT_EQ(0U, GetAndResetSentEventCount()); 1606 EXPECT_EQ(0U, GetAndResetSentEventCount());
1586 EXPECT_EQ(1U, GetAndResetAckedEventCount()); 1607 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1587 1608
1588 // Queuing the final touchend should flush the pending, async touchmove. 1609 // Queuing the final touchend should flush the pending async touchmove. In
1610 // this case, we will first dispatch an async touchmove and then a touchend.
1611 // For the async touchmove, we will only ack the client.
1589 ReleaseTouchPoint(0); 1612 ReleaseTouchPoint(0);
1590 followup_scroll.type = WebInputEvent::GestureScrollEnd; 1613 followup_scroll.type = WebInputEvent::GestureScrollEnd;
1591 SetFollowupEvent(followup_scroll); 1614 SetFollowupEvent(followup_scroll);
1592 EXPECT_EQ(WebInputEvent::TouchMove, sent_event().type);
1593 EXPECT_FALSE(HasPendingAsyncTouchMove()); 1615 EXPECT_FALSE(HasPendingAsyncTouchMove());
1594 EXPECT_FALSE(sent_event().cancelable); 1616 EXPECT_EQ(2U, all_sent_events().size());
1595 EXPECT_EQ(1U, GetAndResetSentEventCount()); 1617 EXPECT_EQ(WebInputEvent::TouchMove, all_sent_events()[0].type);
1596 EXPECT_EQ(2U, queued_event_count()); 1618 EXPECT_FALSE(all_sent_events()[0].cancelable);
1597 1619 EXPECT_EQ(WebInputEvent::TouchEnd, all_sent_events()[1].type);
1598 // Ack the flushed, async touchmove. The ack should not reach the client, but 1620 EXPECT_FALSE(all_sent_events()[1].cancelable);
1599 // it should trigger sending of the (now non-cancelable) touchend. 1621 EXPECT_EQ(2U, GetAndResetSentEventCount());
1600 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 1622 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1601 EXPECT_EQ(WebInputEvent::TouchEnd, sent_event().type);
1602 EXPECT_FALSE(sent_event().cancelable);
1603 EXPECT_EQ(1U, GetAndResetSentEventCount());
1604 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1605 EXPECT_EQ(1U, queued_event_count()); 1623 EXPECT_EQ(1U, queued_event_count());
1606 1624
1607 // Ack the touchend. 1625 // Ack the touchend.
1608 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 1626 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1627 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1609 EXPECT_EQ(0U, queued_event_count()); 1628 EXPECT_EQ(0U, queued_event_count());
1610 EXPECT_EQ(0U, GetAndResetSentEventCount()); 1629 EXPECT_EQ(0U, GetAndResetSentEventCount());
1611 EXPECT_EQ(1U, GetAndResetAckedEventCount()); 1630 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1612 1631
1613 // Now mark the scrolls as not consumed (which would cause future touchmoves 1632 // Now mark the scrolls as not consumed (which would cause future touchmoves
1614 // in the active sequence to be sent if there was one). 1633 // in the active sequence to be sent if there was one).
1615 SendGestureEventAck(WebInputEvent::GestureScrollUpdate, 1634 SendGestureEventAck(WebInputEvent::GestureScrollUpdate,
1616 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 1635 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1617 SendGestureEventAck(WebInputEvent::GestureScrollUpdate, 1636 SendGestureEventAck(WebInputEvent::GestureScrollUpdate,
1618 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 1637 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
(...skipping 13 matching lines...) Expand all
1632 1651
1633 MoveTouchPoint(0, 0, 6); 1652 MoveTouchPoint(0, 0, 6);
1634 followup_scroll.type = WebInputEvent::GestureScrollUpdate; 1653 followup_scroll.type = WebInputEvent::GestureScrollUpdate;
1635 SetFollowupEvent(followup_scroll); 1654 SetFollowupEvent(followup_scroll);
1636 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 1655 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1637 EXPECT_FALSE(HasPendingAsyncTouchMove()); 1656 EXPECT_FALSE(HasPendingAsyncTouchMove());
1638 EXPECT_EQ(1U, GetAndResetSentEventCount()); 1657 EXPECT_EQ(1U, GetAndResetSentEventCount());
1639 EXPECT_EQ(1U, GetAndResetAckedEventCount()); 1658 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1640 1659
1641 MoveTouchPoint(0, 0, 10); 1660 MoveTouchPoint(0, 0, 10);
1642 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1643 EXPECT_TRUE(HasPendingAsyncTouchMove()); 1661 EXPECT_TRUE(HasPendingAsyncTouchMove());
1644 EXPECT_EQ(0U, queued_event_count()); 1662 EXPECT_EQ(0U, queued_event_count());
1645 EXPECT_EQ(0U, GetAndResetSentEventCount()); 1663 EXPECT_EQ(0U, GetAndResetSentEventCount());
1646 EXPECT_EQ(1U, GetAndResetAckedEventCount()); 1664 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1647 1665
1648 // Subsequent touchmove's should be deferred. 1666 // Subsequent touchmove's should be deferred.
1649 MoveTouchPoint(0, 0, 25); 1667 MoveTouchPoint(0, 0, 25);
1650 EXPECT_TRUE(HasPendingAsyncTouchMove()); 1668 EXPECT_TRUE(HasPendingAsyncTouchMove());
1651 EXPECT_EQ(0U, queued_event_count()); 1669 EXPECT_EQ(0U, queued_event_count());
1652 EXPECT_EQ(0U, GetAndResetSentEventCount()); 1670 EXPECT_EQ(0U, GetAndResetSentEventCount());
1653 EXPECT_EQ(1U, GetAndResetAckedEventCount()); 1671 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1672 EXPECT_EQ(0U, uncancelable_touch_moves_pending_ack_count());
1654 1673
1655 // The pending touchmove should be flushed with the the new touchmove if 1674 // The pending touchmove should be flushed with the the new touchmove if
1656 // sufficient time has passed. 1675 // sufficient time has passed and ack to the client.
1657 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1); 1676 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1);
1658 MoveTouchPoint(0, 0, 15); 1677 MoveTouchPoint(0, 0, 15);
1678 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1659 EXPECT_FALSE(HasPendingAsyncTouchMove()); 1679 EXPECT_FALSE(HasPendingAsyncTouchMove());
1660 EXPECT_FALSE(sent_event().cancelable); 1680 EXPECT_FALSE(sent_event().cancelable);
1661 EXPECT_EQ(1U, queued_event_count()); 1681 EXPECT_EQ(0U, queued_event_count());
1662 EXPECT_EQ(1U, GetAndResetSentEventCount()); 1682 EXPECT_EQ(1U, GetAndResetSentEventCount());
1663 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1664 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1665 EXPECT_EQ(0U, queued_event_count());
1666 EXPECT_EQ(0U, GetAndResetSentEventCount());
1667 EXPECT_EQ(1U, GetAndResetAckedEventCount()); 1683 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1668 1684
1669 // Non-touchmove events should always flush any pending touchmove events. 1685 // Non-touchmove events should always flush any pending touchmove events. In
1686 // this case, we will first dispatch an async touchmove and then a
1687 // touchstart. For the async touchmove, we will only ack the client.
1670 MoveTouchPoint(0, 0, 25); 1688 MoveTouchPoint(0, 0, 25);
1671 EXPECT_TRUE(HasPendingAsyncTouchMove()); 1689 EXPECT_TRUE(HasPendingAsyncTouchMove());
1672 EXPECT_EQ(0U, queued_event_count()); 1690 EXPECT_EQ(0U, queued_event_count());
1673 EXPECT_EQ(0U, GetAndResetSentEventCount()); 1691 EXPECT_EQ(0U, GetAndResetSentEventCount());
1674 EXPECT_EQ(1U, GetAndResetAckedEventCount()); 1692 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1675 PressTouchPoint(30, 30); 1693 PressTouchPoint(30, 30);
1676 EXPECT_FALSE(HasPendingAsyncTouchMove()); 1694 EXPECT_FALSE(HasPendingAsyncTouchMove());
1677 EXPECT_FALSE(sent_event().cancelable); 1695 EXPECT_EQ(2U, all_sent_events().size());
1678 EXPECT_EQ(WebInputEvent::TouchMove, sent_event().type); 1696 EXPECT_EQ(WebInputEvent::TouchMove, all_sent_events()[0].type);
1679 EXPECT_EQ(1U, GetAndResetSentEventCount()); 1697 EXPECT_FALSE(all_sent_events()[0].cancelable);
1680 EXPECT_EQ(2U, queued_event_count()); 1698 EXPECT_EQ(WebInputEvent::TouchStart, all_sent_events()[1].type);
1681 1699 EXPECT_TRUE(all_sent_events()[1].cancelable);
1682 // Ack'ing the flushed, async touchmove will dispatch the touchstart. Note 1700 EXPECT_EQ(2U, GetAndResetSentEventCount());
1683 // that the flushed touchmove's ack will not reach the client (its 1701 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1684 // constituent events have already been ack'ed).
1685 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1686 EXPECT_TRUE(sent_event().cancelable);
1687 EXPECT_EQ(WebInputEvent::TouchStart, sent_event().type);
1688 EXPECT_EQ(1U, queued_event_count()); 1702 EXPECT_EQ(1U, queued_event_count());
1689 EXPECT_EQ(1U, GetAndResetSentEventCount());
1690 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1691 1703
1692 // Ack the touchstart. 1704 // Ack the touchstart.
1693 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 1705 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1706 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1694 EXPECT_EQ(0U, queued_event_count()); 1707 EXPECT_EQ(0U, queued_event_count());
1695 EXPECT_EQ(0U, GetAndResetSentEventCount()); 1708 EXPECT_EQ(0U, GetAndResetSentEventCount());
1696 EXPECT_EQ(1U, GetAndResetAckedEventCount()); 1709 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1697 1710
1698 // Send a secondary touchmove. 1711 // Send a secondary touchmove.
1699 MoveTouchPoint(1, 0, 25); 1712 MoveTouchPoint(1, 0, 25);
1700 EXPECT_TRUE(HasPendingAsyncTouchMove()); 1713 EXPECT_TRUE(HasPendingAsyncTouchMove());
1701 EXPECT_EQ(0U, queued_event_count()); 1714 EXPECT_EQ(0U, queued_event_count());
1702 EXPECT_EQ(0U, GetAndResetSentEventCount()); 1715 EXPECT_EQ(0U, GetAndResetSentEventCount());
1703 EXPECT_EQ(1U, GetAndResetAckedEventCount()); 1716 EXPECT_EQ(1U, GetAndResetAckedEventCount());
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1774 EXPECT_EQ(1U, GetAndResetAckedEventCount()); 1787 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1775 1788
1776 // Return the touch sequence to the original touchstart position. Note that 1789 // Return the touch sequence to the original touchstart position. Note that
1777 // this (0, 0) touchmove will coalesce with the previous (0, 100) touchmove. 1790 // this (0, 0) touchmove will coalesce with the previous (0, 100) touchmove.
1778 MoveTouchPoint(0, 0, 0); 1791 MoveTouchPoint(0, 0, 0);
1779 EXPECT_TRUE(HasPendingAsyncTouchMove()); 1792 EXPECT_TRUE(HasPendingAsyncTouchMove());
1780 EXPECT_EQ(0U, queued_event_count()); 1793 EXPECT_EQ(0U, queued_event_count());
1781 EXPECT_EQ(0U, GetAndResetSentEventCount()); 1794 EXPECT_EQ(0U, GetAndResetSentEventCount());
1782 EXPECT_EQ(1U, GetAndResetAckedEventCount()); 1795 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1783 1796
1784 // Queuing the final touchend should flush the pending, async touchmove. 1797 // Queuing the final touchend should flush the pending, async touchmove. In
1798 // this case, we will first dispatch an async touchmove and then a touchend.
1799 // For the async touchmove, we will only ack the client.
1785 ReleaseTouchPoint(0); 1800 ReleaseTouchPoint(0);
1786 EXPECT_FALSE(HasPendingAsyncTouchMove()); 1801 EXPECT_FALSE(HasPendingAsyncTouchMove());
1787 EXPECT_EQ(WebInputEvent::TouchMove, sent_event().type); 1802 EXPECT_EQ(2U, all_sent_events().size());
1788 EXPECT_FALSE(sent_event().cancelable); 1803 EXPECT_EQ(WebInputEvent::TouchMove, all_sent_events()[0].type);
1789 EXPECT_EQ(0, sent_event().touches[0].position.x); 1804 EXPECT_FALSE(all_sent_events()[0].cancelable);
1790 EXPECT_EQ(0, sent_event().touches[0].position.y); 1805 EXPECT_EQ(0, all_sent_events()[0].touches[0].position.x);
1791 EXPECT_EQ(1U, GetAndResetSentEventCount()); 1806 EXPECT_EQ(0, all_sent_events()[0].touches[0].position.y);
1792 1807 EXPECT_EQ(WebInputEvent::TouchEnd, all_sent_events()[1].type);
1793 // Touchend is not cancelable during async touch dispatch. 1808 EXPECT_FALSE(all_sent_events()[1].cancelable);
1794 SendTouchEventAck(INPUT_EVENT_ACK_STATE_IGNORED); 1809 EXPECT_EQ(2U, GetAndResetSentEventCount());
1795 EXPECT_EQ(WebInputEvent::TouchEnd, sent_event().type); 1810 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1796 EXPECT_FALSE(sent_event().cancelable);
1797 EXPECT_EQ(1U, GetAndResetSentEventCount());
1798 } 1811 }
1799 1812
1800 // Ensure that async touch dispatch and touch ack timeout interactions work 1813 // Ensure that async touch dispatch and touch ack timeout interactions work
1801 // appropriately. 1814 // appropriately.
1802 TEST_F(TouchEventQueueTest, AsyncTouchWithAckTimeout) { 1815 TEST_F(TouchEventQueueTest, AsyncTouchWithAckTimeout) {
1803 SetUpForTimeoutTesting(DefaultTouchTimeoutDelay()); 1816 SetUpForTimeoutTesting(DefaultTouchTimeoutDelay());
1804 1817
1805 // The touchstart should start the timeout. 1818 // The touchstart should start the timeout.
1806 PressTouchPoint(0, 0); 1819 PressTouchPoint(0, 0);
1807 EXPECT_EQ(1U, GetAndResetSentEventCount()); 1820 EXPECT_EQ(1U, GetAndResetSentEventCount());
(...skipping 20 matching lines...) Expand all
1828 // it should not start the touch ack timeout. 1841 // it should not start the touch ack timeout.
1829 MoveTouchPoint(0, 5, 5); 1842 MoveTouchPoint(0, 5, 5);
1830 EXPECT_TRUE(HasPendingAsyncTouchMove()); 1843 EXPECT_TRUE(HasPendingAsyncTouchMove());
1831 EXPECT_EQ(1U, GetAndResetAckedEventCount()); 1844 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1832 1845
1833 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1); 1846 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1);
1834 MoveTouchPoint(0, 5, 5); 1847 MoveTouchPoint(0, 5, 5);
1835 EXPECT_FALSE(IsTimeoutRunning()); 1848 EXPECT_FALSE(IsTimeoutRunning());
1836 EXPECT_FALSE(HasPendingAsyncTouchMove()); 1849 EXPECT_FALSE(HasPendingAsyncTouchMove());
1837 EXPECT_FALSE(sent_event().cancelable); 1850 EXPECT_FALSE(sent_event().cancelable);
1838 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1839 EXPECT_EQ(1U, GetAndResetAckedEventCount()); 1851 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1840 EXPECT_EQ(1U, GetAndResetSentEventCount()); 1852 EXPECT_EQ(1U, GetAndResetSentEventCount());
1841 1853
1842 // An unconsumed scroll event will resume synchronous touchmoves, which are 1854 // An unconsumed scroll event will resume synchronous touchmoves, which are
1843 // subject to the ack timeout. 1855 // subject to the ack timeout.
1844 SendGestureEventAck(WebInputEvent::GestureScrollUpdate, 1856 SendGestureEventAck(WebInputEvent::GestureScrollUpdate,
1845 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 1857 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1846 MoveTouchPoint(0, 20, 5); 1858 MoveTouchPoint(0, 20, 5);
1847 EXPECT_TRUE(IsTimeoutRunning()); 1859 EXPECT_TRUE(IsTimeoutRunning());
1848 EXPECT_TRUE(sent_event().cancelable); 1860 EXPECT_TRUE(sent_event().cancelable);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1901 1913
1902 // The async touchmove should be ack'ed immediately, but not forwarded. 1914 // The async touchmove should be ack'ed immediately, but not forwarded.
1903 // However, because the ack triggers a touchcancel, both the pending touch and 1915 // However, because the ack triggers a touchcancel, both the pending touch and
1904 // the queued touchcancel should be flushed. 1916 // the queued touchcancel should be flushed.
1905 WebTouchEvent followup_cancel; 1917 WebTouchEvent followup_cancel;
1906 followup_cancel.type = WebInputEvent::TouchCancel; 1918 followup_cancel.type = WebInputEvent::TouchCancel;
1907 followup_cancel.touchesLength = 1; 1919 followup_cancel.touchesLength = 1;
1908 followup_cancel.touches[0].state = WebTouchPoint::StateCancelled; 1920 followup_cancel.touches[0].state = WebTouchPoint::StateCancelled;
1909 SetFollowupEvent(followup_cancel); 1921 SetFollowupEvent(followup_cancel);
1910 MoveTouchPoint(0, 5, 5); 1922 MoveTouchPoint(0, 5, 5);
1911 EXPECT_EQ(2U, queued_event_count()); 1923 EXPECT_EQ(1U, queued_event_count());
1912 EXPECT_FALSE(sent_event().cancelable); 1924 EXPECT_EQ(2U, all_sent_events().size());
1913 EXPECT_FALSE(HasPendingAsyncTouchMove()); 1925 EXPECT_EQ(WebInputEvent::TouchMove, all_sent_events()[0].type);
1926 EXPECT_FALSE(all_sent_events()[0].cancelable);
1927 EXPECT_EQ(WebInputEvent::TouchCancel, all_sent_events()[1].type);
1928 EXPECT_FALSE(all_sent_events()[1].cancelable);
1929 EXPECT_EQ(2U, GetAndResetSentEventCount());
1930 // The first ack is because the async touchmove is not ready for dispatching
1931 // send the ack immediately, the second ack is when flushing the async
1932 // touchmove, ack to client right away.
1933 EXPECT_EQ(2U, GetAndResetAckedEventCount());
1914 EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type); 1934 EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type);
1915 EXPECT_EQ(WebInputEvent::TouchMove, sent_event().type);
1916 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1917 EXPECT_EQ(1U, GetAndResetSentEventCount());
1918 1935
1919 // The ack for the async touchmove should not reach the client, as it has
1920 // already been ack'ed.
1921 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 1936 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1922 EXPECT_FALSE(sent_event().cancelable);
1923 EXPECT_EQ(1U, queued_event_count());
1924 EXPECT_EQ(WebInputEvent::TouchCancel, sent_event().type);
1925 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1926 EXPECT_EQ(1U, GetAndResetSentEventCount());
1927
1928 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 1937 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1929 EXPECT_EQ(0U, queued_event_count()); 1938 EXPECT_EQ(0U, queued_event_count());
1930 EXPECT_EQ(WebInputEvent::TouchCancel, acked_event().type); 1939 EXPECT_EQ(WebInputEvent::TouchCancel, acked_event().type);
1931 EXPECT_EQ(1U, GetAndResetAckedEventCount()); 1940 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1932 EXPECT_EQ(0U, GetAndResetSentEventCount()); 1941 EXPECT_EQ(0U, GetAndResetSentEventCount());
1933 } 1942 }
1934 1943
1935 // Ensure that the async touch is fully reset if the touch sequence restarts 1944 // Ensure that the async touch is fully reset if the touch sequence restarts
1936 // without properly terminating. 1945 // without properly terminating.
1937 TEST_F(TouchEventQueueTest, AsyncTouchWithHardTouchStartReset) { 1946 TEST_F(TouchEventQueueTest, AsyncTouchWithHardTouchStartReset) {
(...skipping 20 matching lines...) Expand all
1958 EXPECT_EQ(0U, queued_event_count()); 1967 EXPECT_EQ(0U, queued_event_count());
1959 EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type); 1968 EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type);
1960 1969
1961 // The queue should be robust to hard touch restarts with a new touch 1970 // The queue should be robust to hard touch restarts with a new touch
1962 // sequence. In this case, the deferred async touch should not be flushed 1971 // sequence. In this case, the deferred async touch should not be flushed
1963 // by the new touch sequence. 1972 // by the new touch sequence.
1964 SendGestureEvent(WebInputEvent::GestureScrollEnd); 1973 SendGestureEvent(WebInputEvent::GestureScrollEnd);
1965 ResetTouchEvent(); 1974 ResetTouchEvent();
1966 1975
1967 PressTouchPoint(0, 0); 1976 PressTouchPoint(0, 0);
1968 EXPECT_EQ(1U, GetAndResetSentEventCount());
1969 EXPECT_EQ(WebInputEvent::TouchStart, sent_event().type); 1977 EXPECT_EQ(WebInputEvent::TouchStart, sent_event().type);
1970 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 1978 EXPECT_EQ(1U, GetAndResetSentEventCount());
1971 EXPECT_EQ(1U, GetAndResetAckedEventCount()); 1979 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1980 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1981 }
1982
1983 // Ensure that even when the interval expires, we still need to wait for the
1984 // ack sent back from render to send the next async touchmove once the scroll
1985 // starts.
1986 TEST_F(TouchEventQueueTest, SendNextThrottledAsyncTouchMoveAfterAck) {
1987 // Process a TouchStart
1988 PressTouchPoint(0, 1);
1989 EXPECT_EQ(1U, GetAndResetSentEventCount());
1990 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1991 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1992
1993 // Initiate async touchmove dispatch after the start of a scroll sequence.
1994 MoveTouchPoint(0, 0, 5);
1995 WebGestureEvent followup_scroll;
1996 followup_scroll.type = WebInputEvent::GestureScrollBegin;
1997 SetFollowupEvent(followup_scroll);
1998 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1999 EXPECT_EQ(1U, GetAndResetSentEventCount());
2000 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2001
2002 MoveTouchPoint(0, 0, 10);
2003 followup_scroll.type = WebInputEvent::GestureScrollUpdate;
2004 SetFollowupEvent(followup_scroll);
2005 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2006 EXPECT_FALSE(HasPendingAsyncTouchMove());
2007 EXPECT_EQ(1U, GetAndResetSentEventCount());
2008 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2009
2010 // We set the next touch event time to be after the throttled interval.
2011 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1);
2012 // Dispatch the touch move event when sufficient time has passed.
2013 MoveTouchPoint(0, 0, 40);
2014 EXPECT_FALSE(HasPendingAsyncTouchMove());
2015 EXPECT_FALSE(sent_event().cancelable);
2016 // When we dispatch an async touchmove, we do not put it back to the queue
2017 // any more and we will ack to client right away.
2018 EXPECT_EQ(0U, queued_event_count());
2019 EXPECT_EQ(1U, GetAndResetSentEventCount());
2020 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2021 EXPECT_EQ(1U, uncancelable_touch_moves_pending_ack_count());
2022
2023 // Do not dispatch the event until throttledTouchmoves intervals expires and
2024 // receive an ack from render.
2025 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1);
2026 MoveTouchPoint(0, 0, 50);
2027 EXPECT_TRUE(HasPendingAsyncTouchMove());
2028 EXPECT_EQ(0U, queued_event_count());
2029 EXPECT_EQ(0U, GetAndResetSentEventCount());
2030 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2031 EXPECT_EQ(1U, uncancelable_touch_moves_pending_ack_count());
2032
2033 // Send pending_async_touch_move_ when we receive an ack back from render.
2034 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2035 EXPECT_FALSE(HasPendingAsyncTouchMove());
2036 EXPECT_EQ(0U, queued_event_count());
2037 EXPECT_EQ(1U, GetAndResetSentEventCount());
2038 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2039 EXPECT_EQ(1U, uncancelable_touch_moves_pending_ack_count());
2040 }
2041
2042 // Ensure that even when we receive the ack from render, we still need to wait
2043 // for the interval expires to send the next async touchmove once the scroll
2044 // starts.
2045 TEST_F(TouchEventQueueTest, SendNextAsyncTouchMoveAfterAckAndTimeExpire) {
2046 // Process a TouchStart
2047 PressTouchPoint(0, 1);
2048 EXPECT_EQ(1U, GetAndResetSentEventCount());
2049 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2050 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2051
2052 // Initiate async touchmove dispatch after the start of a scroll sequence.
2053 MoveTouchPoint(0, 0, 5);
2054 WebGestureEvent followup_scroll;
2055 followup_scroll.type = WebInputEvent::GestureScrollBegin;
2056 SetFollowupEvent(followup_scroll);
2057 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2058 EXPECT_EQ(1U, GetAndResetSentEventCount());
2059 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2060
2061 MoveTouchPoint(0, 0, 10);
2062 followup_scroll.type = WebInputEvent::GestureScrollUpdate;
2063 SetFollowupEvent(followup_scroll);
2064 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2065 EXPECT_FALSE(HasPendingAsyncTouchMove());
2066 EXPECT_EQ(1U, GetAndResetSentEventCount());
2067 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2068
2069 // Dispatch the touch move event when sufficient time has passed.
2070 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1);
2071 MoveTouchPoint(0, 0, 40);
2072 EXPECT_FALSE(HasPendingAsyncTouchMove());
2073 EXPECT_FALSE(sent_event().cancelable);
2074 // When we dispatch an async touchmove, we do not put it back to the queue
2075 // any more and we will ack to client right away.
2076 EXPECT_EQ(0U, queued_event_count());
2077 EXPECT_EQ(1U, GetAndResetSentEventCount());
2078 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2079 EXPECT_EQ(1U, uncancelable_touch_moves_pending_ack_count());
2080
2081 // We receive an ack back from render but the time interval is not expired,
2082 // so we do not dispatch the touch move event.
2083 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2084 EXPECT_EQ(0U, uncancelable_touch_moves_pending_ack_count());
2085 MoveTouchPoint(0, 0, 50);
2086 EXPECT_TRUE(HasPendingAsyncTouchMove());
2087 EXPECT_EQ(0U, queued_event_count());
2088 EXPECT_EQ(0U, GetAndResetSentEventCount());
2089 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2090
2091 // Dispatch the touch move when sufficient time has passed.
2092 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1);
2093 MoveTouchPoint(0, 0, 50);
2094 EXPECT_FALSE(HasPendingAsyncTouchMove());
2095 EXPECT_EQ(WebInputEvent::TouchMove, sent_event().type);
2096 EXPECT_FALSE(sent_event().cancelable);
2097 EXPECT_EQ(0U, queued_event_count());
2098 EXPECT_EQ(1U, GetAndResetSentEventCount());
2099 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2100 EXPECT_EQ(1U, uncancelable_touch_moves_pending_ack_count());
2101 }
2102
2103 TEST_F(TouchEventQueueTest, AsyncTouchFlushedByNonTouchMove) {
2104 // Process a TouchStart
2105 PressTouchPoint(0, 1);
2106 EXPECT_EQ(1U, GetAndResetSentEventCount());
2107 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2108 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2109
2110 // Initiate async touchmove dispatch after the start of a scroll sequence.
2111 MoveTouchPoint(0, 0, 5);
2112 WebGestureEvent followup_scroll;
2113 followup_scroll.type = WebInputEvent::GestureScrollBegin;
2114 SetFollowupEvent(followup_scroll);
2115 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2116 EXPECT_EQ(1U, GetAndResetSentEventCount());
2117 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2118
2119 MoveTouchPoint(0, 0, 10);
2120 followup_scroll.type = WebInputEvent::GestureScrollUpdate;
2121 SetFollowupEvent(followup_scroll);
2122 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2123 EXPECT_FALSE(HasPendingAsyncTouchMove());
2124 EXPECT_EQ(1U, GetAndResetSentEventCount());
2125 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2126
2127 // Dispatch the touch move when sufficient time has passed.
2128 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1);
2129 MoveTouchPoint(0, 0, 40);
2130 EXPECT_FALSE(HasPendingAsyncTouchMove());
2131 EXPECT_FALSE(sent_event().cancelable);
2132 // When we dispatch an async touchmove, we do not put it back to the queue
2133 // any more and we will ack to client right away.
2134 EXPECT_EQ(0U, queued_event_count());
2135 EXPECT_EQ(1U, GetAndResetSentEventCount());
2136 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2137 EXPECT_EQ(1U, uncancelable_touch_moves_pending_ack_count());
2138
2139 for (int i = 0; i < 3; ++i) {
2140 // We throttle the touchmoves, put it in the pending_async_touch_move_,
2141 // do not dispatch it.
2142 MoveTouchPoint(0, 10 + 10 * i, 10 + 10 * i);
2143 EXPECT_TRUE(HasPendingAsyncTouchMove());
2144 EXPECT_EQ(0U, queued_event_count());
2145 EXPECT_EQ(0U, GetAndResetSentEventCount());
2146 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2147 EXPECT_EQ(static_cast<size_t>(i + 1),
2148 uncancelable_touch_moves_pending_ack_count());
2149
2150 // Send touchstart will flush pending_async_touch_move_, and increase the
2151 // count. In this case, we will first dispatch an async touchmove and
2152 // then a touchstart. For the async touchmove, we will only ack the client.
2153 PressTouchPoint(30, 30);
2154 EXPECT_FALSE(HasPendingAsyncTouchMove());
2155 EXPECT_EQ(2U, all_sent_events().size());
2156 EXPECT_EQ(WebInputEvent::TouchMove, all_sent_events()[0].type);
2157 EXPECT_FALSE(all_sent_events()[0].cancelable);
2158 EXPECT_EQ(10 + 10 * i, all_sent_events()[0].touches[0].position.x);
2159 EXPECT_EQ(10 + 10 * i, all_sent_events()[0].touches[0].position.y);
2160 EXPECT_EQ(static_cast<size_t>(i + 2),
2161 uncancelable_touch_moves_pending_ack_count());
2162 EXPECT_EQ(WebInputEvent::TouchStart, all_sent_events()[1].type);
2163 EXPECT_TRUE(all_sent_events()[1].cancelable);
2164 EXPECT_EQ(2U, GetAndResetSentEventCount());
2165 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2166
2167 SendTouchEventAckWithID(INPUT_EVENT_ACK_STATE_NOT_CONSUMED,
2168 GetUniqueTouchEventID());
2169 EXPECT_EQ(0U, queued_event_count());
2170 EXPECT_FALSE(HasPendingAsyncTouchMove());
2171 EXPECT_EQ(0U, GetAndResetSentEventCount());
2172 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2173 }
2174
2175 EXPECT_EQ(4U, uncancelable_touch_moves_pending_ack_count());
2176
2177 // When we receive an ack from render we decrease the count.
2178 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2179 EXPECT_EQ(3U, uncancelable_touch_moves_pending_ack_count());
2180 EXPECT_EQ(0U, queued_event_count());
2181 EXPECT_FALSE(HasPendingAsyncTouchMove());
2182
2183 // Do not dispatch the next uncancelable touchmove when we have not received
2184 // all the acks back from render.
2185 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1);
2186 MoveTouchPoint(0, 20, 30);
2187 EXPECT_TRUE(HasPendingAsyncTouchMove());
2188 EXPECT_EQ(0U, queued_event_count());
2189 EXPECT_EQ(0U, GetAndResetSentEventCount());
2190 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2191 EXPECT_EQ(3U, uncancelable_touch_moves_pending_ack_count());
2192
2193 // Once we receive the ack from render, we do not dispatch the
2194 // pending_async_touchmove_ until the count is 0.
2195 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2196 EXPECT_EQ(2U, uncancelable_touch_moves_pending_ack_count());
2197 EXPECT_EQ(0U, queued_event_count());
2198 EXPECT_TRUE(HasPendingAsyncTouchMove());
2199
2200 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2201
2202 // When we receive this ack from render, and the count is 0, so we can
2203 // dispatch the pending_async_touchmove_.
2204 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2205 EXPECT_EQ(1U, uncancelable_touch_moves_pending_ack_count());
2206 EXPECT_FALSE(HasPendingAsyncTouchMove());
2207 EXPECT_EQ(0U, queued_event_count());
2208 EXPECT_EQ(WebInputEvent::TouchMove, sent_event().type);
2209 EXPECT_FALSE(sent_event().cancelable);
2210 EXPECT_EQ(1U, GetAndResetSentEventCount());
2211 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2212 }
2213
2214 // Ensure that even when we receive the ack from render, we still need to wait
2215 // for the interval expires to send the next async touchmove once the scroll
2216 // starts.
2217 TEST_F(TouchEventQueueTest, DoNotIncreaseIfClientConsumeAsyncTouchMove) {
2218 // Process a TouchStart
2219 PressTouchPoint(0, 1);
2220 EXPECT_EQ(1U, GetAndResetSentEventCount());
2221 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2222 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2223
2224 // Initiate async touchmove dispatch after the start of a scroll sequence.
2225 MoveTouchPoint(0, 0, 5);
2226 WebGestureEvent followup_scroll;
2227 followup_scroll.type = WebInputEvent::GestureScrollBegin;
2228 SetFollowupEvent(followup_scroll);
2229 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2230 EXPECT_EQ(1U, GetAndResetSentEventCount());
2231 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2232
2233 MoveTouchPoint(0, 0, 10);
2234 followup_scroll.type = WebInputEvent::GestureScrollUpdate;
2235 SetFollowupEvent(followup_scroll);
2236 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2237 EXPECT_FALSE(HasPendingAsyncTouchMove());
2238 EXPECT_EQ(1U, GetAndResetSentEventCount());
2239 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2240
2241 // Dispatch the touch move event when sufficient time has passed.
2242 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1);
2243 MoveTouchPoint(0, 0, 40);
2244 EXPECT_FALSE(HasPendingAsyncTouchMove());
2245 EXPECT_FALSE(sent_event().cancelable);
2246 // When we dispatch an async touchmove, we do not put it back to the queue
2247 // any more and we will ack to client right away.
2248 EXPECT_EQ(0U, queued_event_count());
2249 EXPECT_EQ(1U, GetAndResetSentEventCount());
2250 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2251 EXPECT_EQ(1U, uncancelable_touch_moves_pending_ack_count());
2252
2253 // We receive an ack back from render but the time interval is not expired,
2254 // so we do not dispatch the touch move event.
2255 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2256 EXPECT_EQ(0U, uncancelable_touch_moves_pending_ack_count());
2257 MoveTouchPoint(0, 0, 50);
2258 EXPECT_TRUE(HasPendingAsyncTouchMove());
2259 EXPECT_EQ(0U, queued_event_count());
2260 EXPECT_EQ(0U, GetAndResetSentEventCount());
2261 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2262
2263 // Dispatch the touch move when sufficient time has passed. Becasue the event
2264 // is consumed by client already, we would not increase the count and ack to
2265 // client again.
2266 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1);
2267 SetSyncAckResult(INPUT_EVENT_ACK_STATE_CONSUMED);
2268 MoveTouchPoint(0, 0, 50);
2269 EXPECT_FALSE(HasPendingAsyncTouchMove());
2270 EXPECT_EQ(WebInputEvent::TouchMove, sent_event().type);
2271 EXPECT_FALSE(sent_event().cancelable);
2272 EXPECT_EQ(0U, queued_event_count());
2273 EXPECT_EQ(1U, GetAndResetSentEventCount());
2274 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2275 EXPECT_EQ(0U, uncancelable_touch_moves_pending_ack_count());
1972 } 2276 }
1973 2277
1974 TEST_F(TouchEventQueueTest, TouchAbsorptionWithConsumedFirstMove) { 2278 TEST_F(TouchEventQueueTest, TouchAbsorptionWithConsumedFirstMove) {
1975 // Queue a TouchStart. 2279 // Queue a TouchStart.
1976 PressTouchPoint(0, 1); 2280 PressTouchPoint(0, 1);
1977 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 2281 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1978 EXPECT_EQ(0U, queued_event_count()); 2282 EXPECT_EQ(0U, queued_event_count());
1979 EXPECT_EQ(1U, GetAndResetAckedEventCount()); 2283 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1980 2284
1981 MoveTouchPoint(0, 20, 5); 2285 MoveTouchPoint(0, 20, 5);
(...skipping 16 matching lines...) Expand all
1998 SetFollowupEvent(followup_scroll); 2302 SetFollowupEvent(followup_scroll);
1999 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 2303 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2000 SendGestureEventAck(WebInputEvent::GestureScrollUpdate, 2304 SendGestureEventAck(WebInputEvent::GestureScrollUpdate,
2001 INPUT_EVENT_ACK_STATE_CONSUMED); 2305 INPUT_EVENT_ACK_STATE_CONSUMED);
2002 EXPECT_EQ(0U, queued_event_count()); 2306 EXPECT_EQ(0U, queued_event_count());
2003 EXPECT_TRUE(sent_event().cancelable); 2307 EXPECT_TRUE(sent_event().cancelable);
2004 EXPECT_EQ(1U, GetAndResetSentEventCount()); 2308 EXPECT_EQ(1U, GetAndResetSentEventCount());
2005 2309
2006 // Touch move event is throttled. 2310 // Touch move event is throttled.
2007 MoveTouchPoint(0, 60, 5); 2311 MoveTouchPoint(0, 60, 5);
2008 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2009 EXPECT_EQ(0U, queued_event_count()); 2312 EXPECT_EQ(0U, queued_event_count());
2010 EXPECT_EQ(0U, GetAndResetSentEventCount()); 2313 EXPECT_EQ(0U, GetAndResetSentEventCount());
2011 } 2314 }
2012 2315
2013 TEST_F(TouchEventQueueTest, TouchStartCancelableDuringScroll) { 2316 TEST_F(TouchEventQueueTest, TouchStartCancelableDuringScroll) {
2014 // Queue a touchstart and touchmove that go unconsumed, transitioning to an 2317 // Queue a touchstart and touchmove that go unconsumed, transitioning to an
2015 // active scroll sequence. 2318 // active scroll sequence.
2016 PressTouchPoint(0, 1); 2319 PressTouchPoint(0, 1);
2017 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 2320 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2321 EXPECT_TRUE(sent_event().cancelable);
2018 ASSERT_EQ(1U, GetAndResetSentEventCount()); 2322 ASSERT_EQ(1U, GetAndResetSentEventCount());
2019 EXPECT_TRUE(sent_event().cancelable);
2020 2323
2021 MoveTouchPoint(0, 20, 5); 2324 MoveTouchPoint(0, 20, 5);
2022 EXPECT_TRUE(sent_event().cancelable); 2325 EXPECT_TRUE(sent_event().cancelable);
2023 SendGestureEvent(blink::WebInputEvent::GestureScrollBegin); 2326 SendGestureEvent(blink::WebInputEvent::GestureScrollBegin);
2024 SendGestureEvent(blink::WebInputEvent::GestureScrollUpdate); 2327 SendGestureEvent(blink::WebInputEvent::GestureScrollUpdate);
2025 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 2328 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2329 EXPECT_TRUE(sent_event().cancelable);
2026 ASSERT_EQ(1U, GetAndResetSentEventCount()); 2330 ASSERT_EQ(1U, GetAndResetSentEventCount());
2027 EXPECT_TRUE(sent_event().cancelable);
2028 2331
2029 // Even though scrolling has begun, touchstart events should be cancelable, 2332 // Even though scrolling has begun, touchstart events should be cancelable,
2030 // allowing, for example, customized pinch processing. 2333 // allowing, for example, customized pinch processing.
2031 PressTouchPoint(10, 11); 2334 PressTouchPoint(10, 11);
2032 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); 2335 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2336 EXPECT_TRUE(sent_event().cancelable);
2033 ASSERT_EQ(1U, GetAndResetSentEventCount()); 2337 ASSERT_EQ(1U, GetAndResetSentEventCount());
2034 EXPECT_TRUE(sent_event().cancelable);
2035 2338
2036 // As the touch start was consumed, touchmoves should no longer be throttled. 2339 // As the touch start was consumed, touchmoves should no longer be throttled.
2037 MoveTouchPoint(1, 11, 11); 2340 MoveTouchPoint(1, 11, 11);
2038 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); 2341 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2342 EXPECT_TRUE(sent_event().cancelable);
2039 ASSERT_EQ(1U, GetAndResetSentEventCount()); 2343 ASSERT_EQ(1U, GetAndResetSentEventCount());
2040 EXPECT_TRUE(sent_event().cancelable);
2041 2344
2042 // With throttling disabled, touchend and touchmove events should also be 2345 // With throttling disabled, touchend and touchmove events should also be
2043 // cancelable. 2346 // cancelable.
2044 MoveTouchPoint(1, 12, 12); 2347 MoveTouchPoint(1, 12, 12);
2045 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); 2348 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2349 EXPECT_TRUE(sent_event().cancelable);
2046 ASSERT_EQ(1U, GetAndResetSentEventCount()); 2350 ASSERT_EQ(1U, GetAndResetSentEventCount());
2047 EXPECT_TRUE(sent_event().cancelable);
2048 ReleaseTouchPoint(1); 2351 ReleaseTouchPoint(1);
2049 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); 2352 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2353 EXPECT_TRUE(sent_event().cancelable);
2050 ASSERT_EQ(1U, GetAndResetSentEventCount()); 2354 ASSERT_EQ(1U, GetAndResetSentEventCount());
2051 EXPECT_TRUE(sent_event().cancelable);
2052 2355
2053 // If subsequent touchmoves aren't consumed, the generated scroll events 2356 // If subsequent touchmoves aren't consumed, the generated scroll events
2054 // will restore async touch dispatch. 2357 // will restore async touch dispatch.
2055 MoveTouchPoint(0, 25, 5); 2358 MoveTouchPoint(0, 25, 5);
2056 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 2359 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2057 SendGestureEvent(blink::WebInputEvent::GestureScrollUpdate); 2360 SendGestureEvent(blink::WebInputEvent::GestureScrollUpdate);
2361 EXPECT_TRUE(sent_event().cancelable);
2058 ASSERT_EQ(1U, GetAndResetSentEventCount()); 2362 ASSERT_EQ(1U, GetAndResetSentEventCount());
2059 EXPECT_TRUE(sent_event().cancelable);
2060 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1); 2363 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1);
2061 MoveTouchPoint(0, 30, 5); 2364 MoveTouchPoint(0, 30, 5);
2365 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2366 EXPECT_FALSE(sent_event().cancelable);
2062 ASSERT_EQ(1U, GetAndResetSentEventCount()); 2367 ASSERT_EQ(1U, GetAndResetSentEventCount());
2063 SendTouchEventAck(INPUT_EVENT_ACK_STATE_IGNORED);
2064 EXPECT_FALSE(sent_event().cancelable);
2065 2368
2066 // The touchend will be uncancelable during an active scroll sequence. 2369 // The touchend will be uncancelable during an active scroll sequence.
2067 ReleaseTouchPoint(0); 2370 ReleaseTouchPoint(0);
2371 EXPECT_FALSE(sent_event().cancelable);
2068 ASSERT_EQ(1U, GetAndResetSentEventCount()); 2372 ASSERT_EQ(1U, GetAndResetSentEventCount());
2069 EXPECT_FALSE(sent_event().cancelable);
2070 } 2373 }
2071 2374
2072 TEST_F(TouchEventQueueTest, UnseenTouchPointerIdsNotForwarded) { 2375 TEST_F(TouchEventQueueTest, UnseenTouchPointerIdsNotForwarded) {
2073 SyntheticWebTouchEvent event; 2376 SyntheticWebTouchEvent event;
2074 event.PressPoint(0, 0); 2377 event.PressPoint(0, 0);
2075 SendTouchEvent(event); 2378 SendTouchEvent(event);
2076 EXPECT_EQ(1U, GetAndResetSentEventCount()); 2379 EXPECT_EQ(1U, GetAndResetSentEventCount());
2077 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); 2380 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2078 EXPECT_EQ(1U, GetAndResetAckedEventCount()); 2381 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2079 2382
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
2211 PressTouchPoint(2, 2); 2514 PressTouchPoint(2, 2);
2212 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); 2515 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2213 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); 2516 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2214 EXPECT_EQ(0U, queued_event_count()); 2517 EXPECT_EQ(0U, queued_event_count());
2215 EXPECT_EQ(2U, GetAndResetSentEventCount()); 2518 EXPECT_EQ(2U, GetAndResetSentEventCount());
2216 EXPECT_EQ(2U, GetAndResetAckedEventCount()); 2519 EXPECT_EQ(2U, GetAndResetAckedEventCount());
2217 2520
2218 // Move 1st touch point. 2521 // Move 1st touch point.
2219 MoveTouchPoint(0, 10, 10); 2522 MoveTouchPoint(0, 10, 10);
2220 EXPECT_EQ(1U, queued_event_count()); 2523 EXPECT_EQ(1U, queued_event_count());
2221 EXPECT_EQ(1U, GetAndResetSentEventCount());
2222 EXPECT_EQ(0U, GetAndResetAckedEventCount());
2223 2524
2224 // TouchMove should be allowed and test for touches state. 2525 // TouchMove should be allowed and test for touches state.
2225 const WebTouchEvent& event1 = sent_event(); 2526 const WebTouchEvent& event1 = sent_event();
2226 EXPECT_EQ(WebInputEvent::TouchMove, event1.type); 2527 EXPECT_EQ(WebInputEvent::TouchMove, event1.type);
2227 EXPECT_EQ(WebTouchPoint::StateMoved, event1.touches[0].state); 2528 EXPECT_EQ(WebTouchPoint::StateMoved, event1.touches[0].state);
2228 EXPECT_EQ(WebTouchPoint::StateStationary, event1.touches[1].state); 2529 EXPECT_EQ(WebTouchPoint::StateStationary, event1.touches[1].state);
2530 EXPECT_EQ(1U, GetAndResetSentEventCount());
2531 EXPECT_EQ(0U, GetAndResetAckedEventCount());
2229 2532
2230 // Do not really move any touch points, but use previous values. 2533 // Do not really move any touch points, but use previous values.
2231 MoveTouchPoint(0, 10, 10); 2534 MoveTouchPoint(0, 10, 10);
2232 ChangeTouchPointRadius(1, 1, 1); 2535 ChangeTouchPointRadius(1, 1, 1);
2233 MoveTouchPoint(1, 2, 2); 2536 MoveTouchPoint(1, 2, 2);
2234 EXPECT_EQ(2U, queued_event_count()); 2537 EXPECT_EQ(2U, queued_event_count());
2235 EXPECT_EQ(0U, GetAndResetSentEventCount()); 2538 EXPECT_EQ(0U, GetAndResetSentEventCount());
2236 2539
2237 // Receive an ACK for 1st TouchMove. 2540 // Receive an ACK for 1st TouchMove.
2238 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); 2541 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2239 2542
2240 // Tries to forward TouchMove but should be filtered 2543 // Tries to forward TouchMove but should be filtered
2241 // when none of the touch points have changed. 2544 // when none of the touch points have changed.
2242 EXPECT_EQ(0U, queued_event_count()); 2545 EXPECT_EQ(0U, queued_event_count());
2243 EXPECT_EQ(0U, GetAndResetSentEventCount()); 2546 EXPECT_EQ(0U, GetAndResetSentEventCount());
2244 EXPECT_EQ(4U, GetAndResetAckedEventCount()); 2547 EXPECT_EQ(4U, GetAndResetAckedEventCount());
2245 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, acked_event_state()); 2548 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, acked_event_state());
2246 2549
2247 // Move 2nd touch point. 2550 // Move 2nd touch point.
2248 MoveTouchPoint(1, 3, 3); 2551 MoveTouchPoint(1, 3, 3);
2249 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); 2552 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2250 EXPECT_EQ(0U, queued_event_count()); 2553 EXPECT_EQ(0U, queued_event_count());
2251 EXPECT_EQ(1U, GetAndResetSentEventCount());
2252 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2253 2554
2254 // TouchMove should be allowed and test for touches state. 2555 // TouchMove should be allowed and test for touches state.
2255 const WebTouchEvent& event2 = sent_event(); 2556 const WebTouchEvent& event2 = sent_event();
2256 EXPECT_EQ(WebInputEvent::TouchMove, event2.type); 2557 EXPECT_EQ(WebInputEvent::TouchMove, event2.type);
2257 EXPECT_EQ(WebTouchPoint::StateStationary, event2.touches[0].state); 2558 EXPECT_EQ(WebTouchPoint::StateStationary, event2.touches[0].state);
2258 EXPECT_EQ(WebTouchPoint::StateMoved, event2.touches[1].state); 2559 EXPECT_EQ(WebTouchPoint::StateMoved, event2.touches[1].state);
2560 EXPECT_EQ(1U, GetAndResetSentEventCount());
2561 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2259 } 2562 }
2260 2563
2261 } // namespace content 2564 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698