| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/renderer_host/input/touch_event_queue.h" | 5 #include "content/browser/renderer_host/input/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> |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 void ReleaseTouchPoint(int index) { | 229 void ReleaseTouchPoint(int index) { |
| 230 touch_event_.ReleasePoint(index); | 230 touch_event_.ReleasePoint(index); |
| 231 SendTouchEvent(); | 231 SendTouchEvent(); |
| 232 } | 232 } |
| 233 | 233 |
| 234 void CancelTouchPoint(int index) { | 234 void CancelTouchPoint(int index) { |
| 235 touch_event_.CancelPoint(index); | 235 touch_event_.CancelPoint(index); |
| 236 SendTouchEvent(); | 236 SendTouchEvent(); |
| 237 } | 237 } |
| 238 | 238 |
| 239 void PrependTouchScrollNotification() { |
| 240 queue_->PrependTouchScrollNotification(); |
| 241 } |
| 242 |
| 239 void AdvanceTouchTime(double seconds) { | 243 void AdvanceTouchTime(double seconds) { |
| 240 touch_event_.timeStampSeconds += seconds; | 244 touch_event_.timeStampSeconds += seconds; |
| 241 } | 245 } |
| 242 | 246 |
| 243 void ResetTouchEvent() { | 247 void ResetTouchEvent() { |
| 244 touch_event_ = SyntheticWebTouchEvent(); | 248 touch_event_ = SyntheticWebTouchEvent(); |
| 245 } | 249 } |
| 246 | 250 |
| 247 size_t GetAndResetAckedEventCount() { | 251 size_t GetAndResetAckedEventCount() { |
| 248 size_t count = acked_event_count_; | 252 size_t count = acked_event_count_; |
| (...skipping 2362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2611 | 2615 |
| 2612 // TouchMove should be allowed and test for touches state. | 2616 // TouchMove should be allowed and test for touches state. |
| 2613 const WebTouchEvent& event2 = sent_event(); | 2617 const WebTouchEvent& event2 = sent_event(); |
| 2614 EXPECT_EQ(WebInputEvent::TouchMove, event2.type); | 2618 EXPECT_EQ(WebInputEvent::TouchMove, event2.type); |
| 2615 EXPECT_EQ(WebTouchPoint::StateStationary, event2.touches[0].state); | 2619 EXPECT_EQ(WebTouchPoint::StateStationary, event2.touches[0].state); |
| 2616 EXPECT_EQ(WebTouchPoint::StateMoved, event2.touches[1].state); | 2620 EXPECT_EQ(WebTouchPoint::StateMoved, event2.touches[1].state); |
| 2617 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 2621 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 2618 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 2622 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 2619 } | 2623 } |
| 2620 | 2624 |
| 2625 // Tests that touch-scroll-notification is not pushed into an empty queue. |
| 2626 TEST_F(TouchEventQueueTest, TouchScrollNotificationOrder_EmptyQueue) { |
| 2627 PrependTouchScrollNotification(); |
| 2628 |
| 2629 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| 2630 EXPECT_EQ(0U, queued_event_count()); |
| 2631 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 2632 } |
| 2633 |
| 2634 // Tests touch-scroll-notification firing order when the event is placed at the |
| 2635 // end of touch queue because of a pending ack for the head of the queue. |
| 2636 TEST_F(TouchEventQueueTest, TouchScrollNotificationOrder_EndOfQueue) { |
| 2637 PressTouchPoint(1, 1); |
| 2638 |
| 2639 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| 2640 EXPECT_EQ(1U, queued_event_count()); |
| 2641 |
| 2642 // Send the touch-scroll-notification when 3 events are in the queue. |
| 2643 PrependTouchScrollNotification(); |
| 2644 |
| 2645 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| 2646 EXPECT_EQ(2U, queued_event_count()); |
| 2647 |
| 2648 // Receive an ACK for the touchstart. |
| 2649 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 2650 |
| 2651 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 2652 EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type); |
| 2653 EXPECT_EQ(1U, queued_event_count()); |
| 2654 |
| 2655 // Receive an ACK for the touch-scroll-notification. |
| 2656 SendTouchEventAck(INPUT_EVENT_ACK_STATE_IGNORED); |
| 2657 |
| 2658 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| 2659 EXPECT_EQ(0U, queued_event_count()); |
| 2660 |
| 2661 EXPECT_EQ(WebInputEvent::TouchStart, all_sent_events()[0].type); |
| 2662 EXPECT_EQ(WebInputEvent::TouchScrollStarted, all_sent_events()[1].type); |
| 2663 EXPECT_EQ(2U, GetAndResetSentEventCount()); |
| 2664 } |
| 2665 |
| 2666 // Tests touch-scroll-notification firing order when the event is placed in the |
| 2667 // 2nd position in the touch queue between two events. |
| 2668 TEST_F(TouchEventQueueTest, TouchScrollNotificationOrder_SecondPosition) { |
| 2669 PressTouchPoint(1, 1); |
| 2670 MoveTouchPoint(0, 5, 5); |
| 2671 ReleaseTouchPoint(0); |
| 2672 |
| 2673 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| 2674 EXPECT_EQ(3U, queued_event_count()); |
| 2675 |
| 2676 // Send the touch-scroll-notification when 3 events are in the queue. |
| 2677 PrependTouchScrollNotification(); |
| 2678 |
| 2679 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| 2680 EXPECT_EQ(4U, queued_event_count()); |
| 2681 |
| 2682 // Receive an ACK for the touchstart. |
| 2683 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 2684 |
| 2685 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 2686 EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type); |
| 2687 EXPECT_EQ(3U, queued_event_count()); |
| 2688 |
| 2689 // Receive an ACK for the touch-scroll-notification. |
| 2690 SendTouchEventAck(INPUT_EVENT_ACK_STATE_IGNORED); |
| 2691 |
| 2692 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| 2693 EXPECT_EQ(2U, queued_event_count()); |
| 2694 |
| 2695 // Receive an ACK for the touchmove. |
| 2696 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 2697 |
| 2698 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 2699 EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type); |
| 2700 EXPECT_EQ(1U, queued_event_count()); |
| 2701 |
| 2702 // Receive an ACK for the touchend. |
| 2703 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 2704 |
| 2705 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 2706 EXPECT_EQ(WebInputEvent::TouchEnd, acked_event().type); |
| 2707 EXPECT_EQ(0U, queued_event_count()); |
| 2708 |
| 2709 EXPECT_EQ(WebInputEvent::TouchStart, all_sent_events()[0].type); |
| 2710 EXPECT_EQ(WebInputEvent::TouchScrollStarted, all_sent_events()[1].type); |
| 2711 EXPECT_EQ(WebInputEvent::TouchMove, all_sent_events()[2].type); |
| 2712 EXPECT_EQ(WebInputEvent::TouchEnd, all_sent_events()[3].type); |
| 2713 EXPECT_EQ(4U, GetAndResetSentEventCount()); |
| 2714 } |
| 2715 |
| 2621 } // namespace content | 2716 } // namespace content |
| OLD | NEW |