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

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

Issue 259763010: Forward secondary touch points even if the first had no consumer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Clarify comment Created 6 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
« no previous file with comments | « content/browser/renderer_host/input/touch_event_queue.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 558 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 EXPECT_EQ(4U, GetAndResetAckedEventCount()); 569 EXPECT_EQ(4U, GetAndResetAckedEventCount());
570 EXPECT_EQ(1U, queued_event_count()); 570 EXPECT_EQ(1U, queued_event_count());
571 571
572 // ACK the second press event as NO_CONSUMER too. 572 // ACK the second press event as NO_CONSUMER too.
573 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); 573 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
574 EXPECT_EQ(0U, GetAndResetSentEventCount()); 574 EXPECT_EQ(0U, GetAndResetSentEventCount());
575 EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type); 575 EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type);
576 EXPECT_EQ(1U, GetAndResetAckedEventCount()); 576 EXPECT_EQ(1U, GetAndResetAckedEventCount());
577 EXPECT_EQ(0U, queued_event_count()); 577 EXPECT_EQ(0U, queued_event_count());
578 578
579 // Send a second press event. As the first touch press had NO_CONSUMER, this 579 // Send a second press event. Even though the first touch press had
580 // press event should not reach the renderer. 580 // NO_CONSUMER, this press event should reach the renderer.
581 PressTouchPoint(1, 1); 581 PressTouchPoint(1, 1);
582 EXPECT_EQ(0U, GetAndResetSentEventCount()); 582 EXPECT_EQ(1U, GetAndResetSentEventCount());
583 EXPECT_EQ(1U, queued_event_count());
584 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
583 EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type); 585 EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type);
584 EXPECT_EQ(1U, GetAndResetAckedEventCount()); 586 EXPECT_EQ(1U, GetAndResetAckedEventCount());
585 EXPECT_EQ(0U, queued_event_count());
586 } 587 }
587 588
588 TEST_F(TouchEventQueueTest, ConsumerIgnoreMultiFinger) { 589 TEST_F(TouchEventQueueTest, ConsumerIgnoreMultiFinger) {
589 // Press two touch points and move them around a bit. The renderer consumes 590 // Press two touch points and move them around a bit. The renderer consumes
590 // the events for the first touch point, but returns NO_CONSUMER_EXISTS for 591 // the events for the first touch point, but returns NO_CONSUMER_EXISTS for
591 // the second touch point. 592 // the second touch point.
592 593
593 PressTouchPoint(1, 1); 594 PressTouchPoint(1, 1);
594 EXPECT_EQ(1U, GetAndResetSentEventCount()); 595 EXPECT_EQ(1U, GetAndResetSentEventCount());
595 596
(...skipping 919 matching lines...) Expand 10 before | Expand all | Expand 10 after
1515 EXPECT_EQ(1U, GetAndResetAckedEventCount()); 1516 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1516 1517
1517 // TouchMove's should not should be suppressed, even with the original 1518 // TouchMove's should not should be suppressed, even with the original
1518 // unmoved pointer. 1519 // unmoved pointer.
1519 MoveTouchPoint(0, 0, 0); 1520 MoveTouchPoint(0, 0, 0);
1520 EXPECT_EQ(1U, queued_event_count()); 1521 EXPECT_EQ(1U, queued_event_count());
1521 EXPECT_EQ(1U, GetAndResetSentEventCount()); 1522 EXPECT_EQ(1U, GetAndResetSentEventCount());
1522 EXPECT_EQ(0U, GetAndResetAckedEventCount()); 1523 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1523 } 1524 }
1524 1525
1526 // Tests that secondary touch points can be forwarded even if the primary touch
1527 // point had no consumer.
1528 TEST_F(TouchEventQueueTest, SecondaryTouchForwardedAfterPrimaryHadNoConsumer) {
1529 // Queue a TouchStart.
1530 PressTouchPoint(0, 0);
1531 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
1532 ASSERT_EQ(1U, GetAndResetSentEventCount());
1533 ASSERT_EQ(1U, GetAndResetAckedEventCount());
1534
1535 // Events should not be forwarded, as the point had no consumer.
1536 MoveTouchPoint(0, 0, 15);
1537 EXPECT_EQ(0U, queued_event_count());
1538 EXPECT_EQ(0U, GetAndResetSentEventCount());
1539 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1540
1541 // Simulate a secondary pointer press.
1542 PressTouchPoint(20, 0);
1543 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1544 EXPECT_EQ(1U, GetAndResetSentEventCount());
1545 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1546
1547 // TouchMove with a secondary pointer should not be suppressed.
1548 MoveTouchPoint(1, 25, 0);
1549 EXPECT_EQ(1U, queued_event_count());
1550 EXPECT_EQ(1U, GetAndResetSentEventCount());
1551 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1552 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1553 }
1554
1555 // Tests that no touch points will be forwarded after scrolling begins while no
1556 // touch points have a consumer.
1557 TEST_F(TouchEventQueueTest, NoForwardingAfterScrollWithNoTouchConsumers) {
1558 // Queue a TouchStart.
1559 PressTouchPoint(0, 0);
1560 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
1561 ASSERT_EQ(1U, GetAndResetSentEventCount());
1562 ASSERT_EQ(1U, GetAndResetAckedEventCount());
1563
1564 WebGestureEvent followup_scroll;
1565 followup_scroll.type = WebInputEvent::GestureScrollBegin;
1566 SetFollowupEvent(followup_scroll);
1567 MoveTouchPoint(0, 20, 5);
1568 EXPECT_EQ(0U, GetAndResetSentEventCount());
1569 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1570 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, acked_event_state());
1571
1572 // The secondary pointer press should not be forwarded.
1573 PressTouchPoint(20, 0);
1574 EXPECT_EQ(0U, GetAndResetSentEventCount());
1575 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1576 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, acked_event_state());
1577
1578 // Neither should any further touchmoves be forwarded.
1579 MoveTouchPoint(1, 25, 0);
1580 EXPECT_EQ(0U, GetAndResetSentEventCount());
1581 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1582 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, acked_event_state());
1583 }
1584
1525 TEST_F(TouchEventQueueTest, SyncTouchMoveDoesntCancelTouchOnScroll) { 1585 TEST_F(TouchEventQueueTest, SyncTouchMoveDoesntCancelTouchOnScroll) {
1526 SetTouchScrollingMode(TouchEventQueue::TOUCH_SCROLLING_MODE_SYNC_TOUCHMOVE); 1586 SetTouchScrollingMode(TouchEventQueue::TOUCH_SCROLLING_MODE_SYNC_TOUCHMOVE);
1527 // Queue a TouchStart. 1587 // Queue a TouchStart.
1528 PressTouchPoint(0, 1); 1588 PressTouchPoint(0, 1);
1529 EXPECT_EQ(1U, GetAndResetSentEventCount()); 1589 EXPECT_EQ(1U, GetAndResetSentEventCount());
1530 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 1590 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1531 EXPECT_EQ(1U, GetAndResetAckedEventCount()); 1591 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1532 1592
1533 MoveTouchPoint(0, 20, 5); 1593 MoveTouchPoint(0, 20, 5);
1534 EXPECT_EQ(1U, queued_event_count()); 1594 EXPECT_EQ(1U, queued_event_count());
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
1763 // appropriately. 1823 // appropriately.
1764 TEST_F(TouchEventQueueTest, AsyncTouchWithAckTimeout) { 1824 TEST_F(TouchEventQueueTest, AsyncTouchWithAckTimeout) {
1765 SetTouchScrollingMode(TouchEventQueue::TOUCH_SCROLLING_MODE_ASYNC_TOUCHMOVE); 1825 SetTouchScrollingMode(TouchEventQueue::TOUCH_SCROLLING_MODE_ASYNC_TOUCHMOVE);
1766 SetUpForTimeoutTesting(DefaultTouchTimeoutDelay()); 1826 SetUpForTimeoutTesting(DefaultTouchTimeoutDelay());
1767 1827
1768 // The touchstart should start the timeout. 1828 // The touchstart should start the timeout.
1769 PressTouchPoint(0, 0); 1829 PressTouchPoint(0, 0);
1770 EXPECT_EQ(1U, GetAndResetSentEventCount()); 1830 EXPECT_EQ(1U, GetAndResetSentEventCount());
1771 EXPECT_TRUE(IsTimeoutRunning()); 1831 EXPECT_TRUE(IsTimeoutRunning());
1772 1832
1773 // The start of a scroll gesture should triger async touch event dispatch. 1833 // The start of a scroll gesture should trigger async touch event dispatch.
1774 WebGestureEvent followup_scroll; 1834 WebGestureEvent followup_scroll;
1775 followup_scroll.type = WebInputEvent::GestureScrollBegin; 1835 followup_scroll.type = WebInputEvent::GestureScrollBegin;
1776 SetFollowupEvent(followup_scroll); 1836 SetFollowupEvent(followup_scroll);
1777 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 1837 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1778 EXPECT_FALSE(IsTimeoutRunning()); 1838 EXPECT_FALSE(IsTimeoutRunning());
1779 EXPECT_EQ(1U, GetAndResetAckedEventCount()); 1839 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1780 1840
1781 SendGestureEventAck(WebInputEvent::GestureScrollUpdate, 1841 SendGestureEventAck(WebInputEvent::GestureScrollUpdate,
1782 INPUT_EVENT_ACK_STATE_CONSUMED); 1842 INPUT_EVENT_ACK_STATE_CONSUMED);
1783 1843
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1829 EXPECT_EQ(0U, GetAndResetSentEventCount()); 1889 EXPECT_EQ(0U, GetAndResetSentEventCount());
1830 1890
1831 SendGestureEventAck(WebInputEvent::GestureScrollUpdate, 1891 SendGestureEventAck(WebInputEvent::GestureScrollUpdate,
1832 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 1892 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1833 MoveTouchPoint(0, 25, 5); 1893 MoveTouchPoint(0, 25, 5);
1834 EXPECT_FALSE(HasPendingAsyncTouchMove()); 1894 EXPECT_FALSE(HasPendingAsyncTouchMove());
1835 EXPECT_EQ(1U, GetAndResetAckedEventCount()); 1895 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1836 EXPECT_EQ(0U, GetAndResetSentEventCount()); 1896 EXPECT_EQ(0U, GetAndResetSentEventCount());
1837 } 1897 }
1838 1898
1899 // Ensure that if the touch ack for an async touchmove triggers a follow-up
1900 // touch event, that follow-up touch will be forwarded appropriately.
1901 TEST_F(TouchEventQueueTest, AsyncTouchWithTouchCancelAfterAck) {
1902 SetTouchScrollingMode(TouchEventQueue::TOUCH_SCROLLING_MODE_ASYNC_TOUCHMOVE);
1903
1904 PressTouchPoint(0, 0);
1905 EXPECT_EQ(1U, GetAndResetSentEventCount());
1906
1907 // The start of a scroll gesture should trigger async touch event dispatch.
1908 WebGestureEvent followup_scroll;
1909 followup_scroll.type = WebInputEvent::GestureScrollBegin;
1910 SetFollowupEvent(followup_scroll);
1911 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1912 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1913 EXPECT_EQ(0U, queued_event_count());
1914
1915 // The async touchmove should be ack'ed immediately, but not forwarded.
1916 // However, because the ack triggers a touchcancel, both the pending touch and
1917 // the queued touchcancel should be flushed.
1918 WebTouchEvent followup_cancel;
1919 followup_cancel.type = WebInputEvent::TouchCancel;
1920 followup_cancel.touchesLength = 1;
1921 followup_cancel.touches[0].state = WebTouchPoint::StateCancelled;
1922 SetFollowupEvent(followup_cancel);
1923 MoveTouchPoint(0, 5, 5);
1924 EXPECT_EQ(2U, queued_event_count());
1925 EXPECT_FALSE(sent_event().cancelable);
1926 EXPECT_FALSE(HasPendingAsyncTouchMove());
1927 EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type);
1928 EXPECT_EQ(WebInputEvent::TouchMove, sent_event().type);
1929 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1930 EXPECT_EQ(1U, GetAndResetSentEventCount());
1931
1932 // The ack for the asnc touchmove should not reach the client, as it has
1933 // already been ack'ed.
1934 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1935 EXPECT_FALSE(sent_event().cancelable);
1936 EXPECT_EQ(1U, queued_event_count());
1937 EXPECT_EQ(WebInputEvent::TouchCancel, sent_event().type);
1938 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1939 EXPECT_EQ(1U, GetAndResetSentEventCount());
1940
1941 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1942 EXPECT_EQ(0U, queued_event_count());
1943 EXPECT_EQ(WebInputEvent::TouchCancel, acked_event().type);
1944 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1945 EXPECT_EQ(0U, GetAndResetSentEventCount());
1946 }
1947
1839 } // namespace content 1948 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/input/touch_event_queue.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698