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

Side by Side Diff: ui/events/gesture_detection/gesture_provider_unittest.cc

Issue 349463002: [Android] Map raw touch coordinates to global gesture locations (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 6 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "base/time/time.h" 9 #include "base/time/time.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 718 matching lines...) Expand 10 before | Expand all | Expand 10 after
729 EXPECT_EQ(ET_GESTURE_SCROLL_END, GetMostRecentGestureEventType()); 729 EXPECT_EQ(ET_GESTURE_SCROLL_END, GetMostRecentGestureEventType());
730 EXPECT_EQ(BoundsForSingleMockTouchAtLocation(kFakeCoordX, kFakeCoordY - 200), 730 EXPECT_EQ(BoundsForSingleMockTouchAtLocation(kFakeCoordX, kFakeCoordY - 200),
731 GetMostRecentGestureEvent().details.bounding_box()); 731 GetMostRecentGestureEvent().details.bounding_box());
732 } 732 }
733 733
734 // Generate a scroll gesture and verify that the resulting scroll motion event 734 // Generate a scroll gesture and verify that the resulting scroll motion event
735 // has both absolute and relative position information. 735 // has both absolute and relative position information.
736 TEST_F(GestureProviderTest, ScrollUpdateValues) { 736 TEST_F(GestureProviderTest, ScrollUpdateValues) {
737 const float delta_x = 16; 737 const float delta_x = 16;
738 const float delta_y = 84; 738 const float delta_y = 84;
739 const float raw_offset_x = 17.3;
740 const float raw_offset_y = 13.7;
739 741
740 const base::TimeTicks event_time = TimeTicks::Now(); 742 const base::TimeTicks event_time = TimeTicks::Now();
741 743
742 MockMotionEvent event = 744 MockMotionEvent event =
743 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); 745 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
744 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 746 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
745 747
746 // Move twice so that we get two ET_GESTURE_SCROLL_UPDATE events and can 748 // Move twice so that we get two ET_GESTURE_SCROLL_UPDATE events and can
747 // compare the relative and absolute coordinates. 749 // compare the relative and absolute coordinates.
748 event = ObtainMotionEvent(event_time + kOneMicrosecond, 750 event = ObtainMotionEvent(event_time + kOneMicrosecond,
749 MotionEvent::ACTION_MOVE, 751 MotionEvent::ACTION_MOVE,
750 kFakeCoordX - delta_x / 2, 752 kFakeCoordX - delta_x / 2,
751 kFakeCoordY - delta_y / 2); 753 kFakeCoordY - delta_y / 2);
752 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 754 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
753 755
754 event = ObtainMotionEvent(event_time + kOneMicrosecond * 2, 756 event = ObtainMotionEvent(event_time + kOneMicrosecond * 2,
755 MotionEvent::ACTION_MOVE, 757 MotionEvent::ACTION_MOVE,
756 kFakeCoordX - delta_x, 758 kFakeCoordX - delta_x,
757 kFakeCoordY - delta_y); 759 kFakeCoordY - delta_y);
760 event.SetRawOffset(raw_offset_x, raw_offset_y);
758 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 761 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
759 762
760 // Make sure the reported gesture event has all the expected details. 763 // Make sure the reported gesture event has all the expected details.
761 ASSERT_LT(0U, GetReceivedGestureCount()); 764 ASSERT_LT(0U, GetReceivedGestureCount());
762 GestureEventData gesture = GetMostRecentGestureEvent(); 765 GestureEventData gesture = GetMostRecentGestureEvent();
763 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, gesture.type()); 766 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, gesture.type());
764 EXPECT_EQ(event_time + kOneMicrosecond * 2, gesture.time); 767 EXPECT_EQ(event_time + kOneMicrosecond * 2, gesture.time);
765 EXPECT_EQ(kFakeCoordX - delta_x, gesture.x); 768 EXPECT_EQ(kFakeCoordX - delta_x, gesture.x);
766 EXPECT_EQ(kFakeCoordY - delta_y, gesture.y); 769 EXPECT_EQ(kFakeCoordY - delta_y, gesture.y);
770 EXPECT_EQ(kFakeCoordX - delta_x + raw_offset_x, gesture.raw_x);
771 EXPECT_EQ(kFakeCoordY - delta_y + raw_offset_y, gesture.raw_y);
767 EXPECT_EQ(1, gesture.details.touch_points()); 772 EXPECT_EQ(1, gesture.details.touch_points());
768 773
769 // No horizontal delta because of snapping. 774 // No horizontal delta because of snapping.
770 EXPECT_EQ(0, gesture.details.scroll_x()); 775 EXPECT_EQ(0, gesture.details.scroll_x());
771 EXPECT_EQ(-delta_y / 2, gesture.details.scroll_y()); 776 EXPECT_EQ(-delta_y / 2, gesture.details.scroll_y());
772 } 777 }
773 778
774 // Verify that fractional scroll deltas are rounded as expected and that 779 // Verify that fractional scroll deltas are rounded as expected and that
775 // fractional scrolling doesn't break scroll snapping. 780 // fractional scrolling doesn't break scroll snapping.
776 TEST_F(GestureProviderTest, FractionalScroll) { 781 TEST_F(GestureProviderTest, FractionalScroll) {
(...skipping 632 matching lines...) Expand 10 before | Expand all | Expand 10 after
1409 kFakeCoordX, 1414 kFakeCoordX,
1410 kFakeCoordY + 200); 1415 kFakeCoordY + 200);
1411 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1416 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1412 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_END)); 1417 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_END));
1413 } 1418 }
1414 1419
1415 // Verify that pinch zoom sends the proper event sequence. 1420 // Verify that pinch zoom sends the proper event sequence.
1416 TEST_F(GestureProviderTest, PinchZoom) { 1421 TEST_F(GestureProviderTest, PinchZoom) {
1417 base::TimeTicks event_time = base::TimeTicks::Now(); 1422 base::TimeTicks event_time = base::TimeTicks::Now();
1418 const float touch_slop = GetTouchSlop(); 1423 const float touch_slop = GetTouchSlop();
1424 const float raw_offset_x = 3.2;
1425 const float raw_offset_y = 4.3;
1419 int motion_event_id = 0; 1426 int motion_event_id = 0;
1420 1427
1421 gesture_provider_->SetDoubleTapSupportForPageEnabled(false); 1428 gesture_provider_->SetDoubleTapSupportForPageEnabled(false);
1422 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(true); 1429 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(true);
1423 gesture_provider_->SetMultiTouchZoomSupportEnabled(true); 1430 gesture_provider_->SetMultiTouchZoomSupportEnabled(true);
1424 1431
1425 int secondary_coord_x = kFakeCoordX + 20 * touch_slop; 1432 int secondary_coord_x = kFakeCoordX + 20 * touch_slop;
1426 int secondary_coord_y = kFakeCoordY + 20 * touch_slop; 1433 int secondary_coord_y = kFakeCoordY + 20 * touch_slop;
1427 1434
1428 MockMotionEvent event = 1435 MockMotionEvent event =
1429 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); 1436 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
1430 event.SetId(++motion_event_id); 1437 event.SetId(++motion_event_id);
1438 event.SetRawOffset(raw_offset_x, raw_offset_y);
1431 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1439 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1432 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); 1440 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
1441 EXPECT_EQ(kFakeCoordX, GetMostRecentGestureEvent().x);
1442 EXPECT_EQ(kFakeCoordY, GetMostRecentGestureEvent().y);
1443 EXPECT_EQ(kFakeCoordX + raw_offset_x, GetMostRecentGestureEvent().raw_x);
1444 EXPECT_EQ(kFakeCoordY + raw_offset_y, GetMostRecentGestureEvent().raw_y);
1433 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); 1445 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1434 EXPECT_EQ(BoundsForSingleMockTouchAtLocation(kFakeCoordX, kFakeCoordY), 1446 EXPECT_EQ(BoundsForSingleMockTouchAtLocation(kFakeCoordX, kFakeCoordY),
1435 GetMostRecentGestureEvent().details.bounding_box()); 1447 GetMostRecentGestureEvent().details.bounding_box());
1436 1448
1437 // Toggling double-tap support should not take effect until the next sequence. 1449 // Toggling double-tap support should not take effect until the next sequence.
1438 gesture_provider_->SetDoubleTapSupportForPageEnabled(true); 1450 gesture_provider_->SetDoubleTapSupportForPageEnabled(true);
1439 1451
1440 event = ObtainMotionEvent(event_time, 1452 event = ObtainMotionEvent(event_time,
1441 MotionEvent::ACTION_POINTER_DOWN, 1453 MotionEvent::ACTION_POINTER_DOWN,
1442 kFakeCoordX, 1454 kFakeCoordX,
1443 kFakeCoordY, 1455 kFakeCoordY,
1444 secondary_coord_x, 1456 secondary_coord_x,
1445 secondary_coord_y); 1457 secondary_coord_y);
1446 event.SetId(++motion_event_id); 1458 event.SetId(++motion_event_id);
1459 event.SetRawOffset(raw_offset_x, raw_offset_y);
1447 1460
1448 gesture_provider_->OnTouchEvent(event); 1461 gesture_provider_->OnTouchEvent(event);
1449 EXPECT_EQ(1U, GetReceivedGestureCount()); 1462 EXPECT_EQ(1U, GetReceivedGestureCount());
1450 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); 1463 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1451 EXPECT_EQ(BoundsForSingleMockTouchAtLocation(kFakeCoordX, kFakeCoordY), 1464 EXPECT_EQ(BoundsForSingleMockTouchAtLocation(kFakeCoordX, kFakeCoordY),
1452 GetMostRecentGestureEvent().details.bounding_box()); 1465 GetMostRecentGestureEvent().details.bounding_box());
1453 1466
1454 secondary_coord_x += 5 * touch_slop; 1467 secondary_coord_x += 5 * touch_slop;
1455 secondary_coord_y += 5 * touch_slop; 1468 secondary_coord_y += 5 * touch_slop;
1456 event = ObtainMotionEvent(event_time, 1469 event = ObtainMotionEvent(event_time,
1457 MotionEvent::ACTION_MOVE, 1470 MotionEvent::ACTION_MOVE,
1458 kFakeCoordX, 1471 kFakeCoordX,
1459 kFakeCoordY, 1472 kFakeCoordY,
1460 secondary_coord_x, 1473 secondary_coord_x,
1461 secondary_coord_y); 1474 secondary_coord_y);
1462 event.SetId(++motion_event_id); 1475 event.SetId(++motion_event_id);
1476 event.SetRawOffset(raw_offset_x, raw_offset_y);
1463 1477
1464 // Toggling double-tap support should not take effect until the next sequence. 1478 // Toggling double-tap support should not take effect until the next sequence.
1465 gesture_provider_->SetDoubleTapSupportForPageEnabled(false); 1479 gesture_provider_->SetDoubleTapSupportForPageEnabled(false);
1466 1480
1467 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1481 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1468 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id); 1482 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
1469 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points()); 1483 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
1470 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_PINCH_BEGIN)); 1484 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_PINCH_BEGIN));
1471 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN)); 1485 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
1472 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_UPDATE)); 1486 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_UPDATE));
1473 1487
1474 EXPECT_EQ((kFakeCoordX + secondary_coord_x) / 2, GetReceivedGesture(3).x); 1488 EXPECT_EQ((kFakeCoordX + secondary_coord_x) / 2, GetReceivedGesture(3).x);
1475 EXPECT_EQ((kFakeCoordY + secondary_coord_y) / 2, GetReceivedGesture(3).y); 1489 EXPECT_EQ((kFakeCoordY + secondary_coord_y) / 2, GetReceivedGesture(3).y);
1490 EXPECT_EQ((kFakeCoordX + secondary_coord_x) / 2 + raw_offset_x,
1491 GetReceivedGesture(3).raw_x);
1492 EXPECT_EQ((kFakeCoordY + secondary_coord_y) / 2 + raw_offset_y,
1493 GetReceivedGesture(3).raw_y);
1476 1494
1477 EXPECT_EQ( 1495 EXPECT_EQ(
1478 gfx::RectF(kFakeCoordX - kMockTouchRadius, 1496 gfx::RectF(kFakeCoordX - kMockTouchRadius,
1479 kFakeCoordY - kMockTouchRadius, 1497 kFakeCoordY - kMockTouchRadius,
1480 secondary_coord_x - kFakeCoordX + kMockTouchRadius * 2, 1498 secondary_coord_x - kFakeCoordX + kMockTouchRadius * 2,
1481 secondary_coord_y - kFakeCoordY + kMockTouchRadius * 2), 1499 secondary_coord_y - kFakeCoordY + kMockTouchRadius * 2),
1482 GetMostRecentGestureEvent().details.bounding_box()); 1500 GetMostRecentGestureEvent().details.bounding_box());
1483 1501
1484 secondary_coord_x += 2 * touch_slop; 1502 secondary_coord_x += 2 * touch_slop;
1485 secondary_coord_y += 2 * touch_slop; 1503 secondary_coord_y += 2 * touch_slop;
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
1825 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1843 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1826 EXPECT_EQ(gesture_count + 1, GetReceivedGestureCount()); 1844 EXPECT_EQ(gesture_count + 1, GetReceivedGestureCount());
1827 EXPECT_EQ(ET_GESTURE_SCROLL_END, GetMostRecentGestureEventType()); 1845 EXPECT_EQ(ET_GESTURE_SCROLL_END, GetMostRecentGestureEventType());
1828 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); 1846 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1829 } 1847 }
1830 1848
1831 // Verify that gesture begin and gesture end events are dispatched correctly. 1849 // Verify that gesture begin and gesture end events are dispatched correctly.
1832 TEST_F(GestureProviderTest, GestureBeginAndEnd) { 1850 TEST_F(GestureProviderTest, GestureBeginAndEnd) {
1833 EnableBeginEndTypes(); 1851 EnableBeginEndTypes();
1834 base::TimeTicks event_time = base::TimeTicks::Now(); 1852 base::TimeTicks event_time = base::TimeTicks::Now();
1853 const float raw_offset_x = 7.5;
1854 const float raw_offset_y = 5.7;
1835 1855
1836 EXPECT_EQ(0U, GetReceivedGestureCount()); 1856 EXPECT_EQ(0U, GetReceivedGestureCount());
1837 MockMotionEvent event = 1857 MockMotionEvent event =
1838 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN, 1, 1); 1858 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN, 1, 1);
1839 event.pointer_count = 1; 1859 event.pointer_count = 1;
1860 event.SetRawOffset(raw_offset_x, raw_offset_y);
1840 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1861 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1841 EXPECT_EQ(ET_GESTURE_BEGIN, GetReceivedGesture(0).type()); 1862 EXPECT_EQ(ET_GESTURE_BEGIN, GetReceivedGesture(0).type());
1842 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); 1863 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
1843 EXPECT_EQ(2U, GetReceivedGestureCount()); 1864 EXPECT_EQ(2U, GetReceivedGestureCount());
1844 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); 1865 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1845 EXPECT_EQ(1, GetMostRecentGestureEvent().x); 1866 EXPECT_EQ(1, GetMostRecentGestureEvent().x);
1846 EXPECT_EQ(1, GetMostRecentGestureEvent().y); 1867 EXPECT_EQ(1, GetMostRecentGestureEvent().y);
1868 EXPECT_EQ(1 + raw_offset_x, GetMostRecentGestureEvent().raw_x);
1869 EXPECT_EQ(1 + raw_offset_y, GetMostRecentGestureEvent().raw_y);
1847 EXPECT_EQ(gfx::RectF(1 - kMockTouchRadius, 1870 EXPECT_EQ(gfx::RectF(1 - kMockTouchRadius,
1848 1 - kMockTouchRadius, 1871 1 - kMockTouchRadius,
1849 kMockTouchRadius * 2, 1872 kMockTouchRadius * 2,
1850 kMockTouchRadius * 2), 1873 kMockTouchRadius * 2),
1851 GetMostRecentGestureEvent().details.bounding_box()); 1874 GetMostRecentGestureEvent().details.bounding_box());
1852 1875
1853 event = ObtainMotionEvent( 1876 event = ObtainMotionEvent(
1854 event_time, MotionEvent::ACTION_POINTER_DOWN, 1, 1, 2, 2); 1877 event_time, MotionEvent::ACTION_POINTER_DOWN, 1, 1, 2, 2);
1855 event.pointer_count = 2; 1878 event.pointer_count = 2;
1879 event.SetRawOffset(raw_offset_x, raw_offset_y);
1856 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1880 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1857 EXPECT_EQ(ET_GESTURE_BEGIN, GetMostRecentGestureEventType()); 1881 EXPECT_EQ(ET_GESTURE_BEGIN, GetMostRecentGestureEventType());
1858 EXPECT_EQ(3U, GetReceivedGestureCount()); 1882 EXPECT_EQ(3U, GetReceivedGestureCount());
1859 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points()); 1883 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
1860 EXPECT_EQ(2, GetMostRecentGestureEvent().x); 1884 EXPECT_EQ(2, GetMostRecentGestureEvent().x);
1861 EXPECT_EQ(2, GetMostRecentGestureEvent().y); 1885 EXPECT_EQ(2, GetMostRecentGestureEvent().y);
1886 EXPECT_EQ(2 + raw_offset_x, GetMostRecentGestureEvent().raw_x);
1887 EXPECT_EQ(2 + raw_offset_y, GetMostRecentGestureEvent().raw_y);
1862 1888
1863 event = ObtainMotionEvent( 1889 event = ObtainMotionEvent(
1864 event_time, MotionEvent::ACTION_POINTER_DOWN, 1, 1, 2, 2, 3, 3); 1890 event_time, MotionEvent::ACTION_POINTER_DOWN, 1, 1, 2, 2, 3, 3);
1865 event.pointer_count = 3; 1891 event.pointer_count = 3;
1892 event.SetRawOffset(raw_offset_x, raw_offset_y);
1866 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1893 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1867 EXPECT_EQ(ET_GESTURE_BEGIN, GetMostRecentGestureEventType()); 1894 EXPECT_EQ(ET_GESTURE_BEGIN, GetMostRecentGestureEventType());
1868 EXPECT_EQ(4U, GetReceivedGestureCount()); 1895 EXPECT_EQ(4U, GetReceivedGestureCount());
1869 EXPECT_EQ(3, GetMostRecentGestureEvent().details.touch_points()); 1896 EXPECT_EQ(3, GetMostRecentGestureEvent().details.touch_points());
1870 EXPECT_EQ(3, GetMostRecentGestureEvent().x); 1897 EXPECT_EQ(3, GetMostRecentGestureEvent().x);
1871 EXPECT_EQ(3, GetMostRecentGestureEvent().y); 1898 EXPECT_EQ(3, GetMostRecentGestureEvent().y);
1899 EXPECT_EQ(3 + raw_offset_x, GetMostRecentGestureEvent().raw_x);
1900 EXPECT_EQ(3 + raw_offset_y, GetMostRecentGestureEvent().raw_y);
1872 1901
1873 event = ObtainMotionEvent( 1902 event = ObtainMotionEvent(
1874 event_time, MotionEvent::ACTION_POINTER_UP, 1, 1, 2, 2, 3, 3); 1903 event_time, MotionEvent::ACTION_POINTER_UP, 1, 1, 2, 2, 3, 3);
1875 event.pointer_count = 2; 1904 event.pointer_count = 2;
1905 event.SetRawOffset(raw_offset_x, raw_offset_y);
1876 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1906 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1877 EXPECT_EQ(ET_GESTURE_END, GetMostRecentGestureEventType()); 1907 EXPECT_EQ(ET_GESTURE_END, GetMostRecentGestureEventType());
1878 EXPECT_EQ(5U, GetReceivedGestureCount()); 1908 EXPECT_EQ(5U, GetReceivedGestureCount());
1879 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points()); 1909 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
1880 EXPECT_EQ(1, GetMostRecentGestureEvent().x); 1910 EXPECT_EQ(1, GetMostRecentGestureEvent().x);
1881 EXPECT_EQ(1, GetMostRecentGestureEvent().y); 1911 EXPECT_EQ(1, GetMostRecentGestureEvent().y);
1912 EXPECT_EQ(1 + raw_offset_x, GetMostRecentGestureEvent().raw_x);
1913 EXPECT_EQ(1 + raw_offset_y, GetMostRecentGestureEvent().raw_y);
1882 1914
1883 event = ObtainMotionEvent( 1915 event = ObtainMotionEvent(
1884 event_time, MotionEvent::ACTION_POINTER_DOWN, 2, 2, 3, 3, 4, 4); 1916 event_time, MotionEvent::ACTION_POINTER_DOWN, 2, 2, 3, 3, 4, 4);
1917 event.SetRawOffset(raw_offset_x, raw_offset_y);
1885 event.pointer_count = 3; 1918 event.pointer_count = 3;
1886 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1919 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1887 EXPECT_EQ(ET_GESTURE_BEGIN, GetMostRecentGestureEventType()); 1920 EXPECT_EQ(ET_GESTURE_BEGIN, GetMostRecentGestureEventType());
1888 EXPECT_EQ(6U, GetReceivedGestureCount()); 1921 EXPECT_EQ(6U, GetReceivedGestureCount());
1889 EXPECT_EQ(3, GetMostRecentGestureEvent().details.touch_points()); 1922 EXPECT_EQ(3, GetMostRecentGestureEvent().details.touch_points());
1890 EXPECT_EQ(4, GetMostRecentGestureEvent().x); 1923 EXPECT_EQ(4, GetMostRecentGestureEvent().x);
1891 EXPECT_EQ(4, GetMostRecentGestureEvent().y); 1924 EXPECT_EQ(4, GetMostRecentGestureEvent().y);
1925 EXPECT_EQ(4 + raw_offset_x, GetMostRecentGestureEvent().raw_x);
1926 EXPECT_EQ(4 + raw_offset_y, GetMostRecentGestureEvent().raw_y);
1892 1927
1893 event = ObtainMotionEvent( 1928 event = ObtainMotionEvent(
1894 event_time, MotionEvent::ACTION_POINTER_UP, 2, 2, 3, 3, 4, 4); 1929 event_time, MotionEvent::ACTION_POINTER_UP, 2, 2, 3, 3, 4, 4);
1895 event.pointer_count = 2; 1930 event.pointer_count = 2;
1931 event.SetRawOffset(raw_offset_x, raw_offset_y);
1896 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1932 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1897 EXPECT_EQ(ET_GESTURE_END, GetMostRecentGestureEventType()); 1933 EXPECT_EQ(ET_GESTURE_END, GetMostRecentGestureEventType());
1898 EXPECT_EQ(7U, GetReceivedGestureCount()); 1934 EXPECT_EQ(7U, GetReceivedGestureCount());
1899 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points()); 1935 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
1900 EXPECT_EQ(2, GetMostRecentGestureEvent().x); 1936 EXPECT_EQ(2, GetMostRecentGestureEvent().x);
1901 EXPECT_EQ(2, GetMostRecentGestureEvent().y); 1937 EXPECT_EQ(2, GetMostRecentGestureEvent().y);
1938 EXPECT_EQ(2 + raw_offset_x, GetMostRecentGestureEvent().raw_x);
1939 EXPECT_EQ(2 + raw_offset_y, GetMostRecentGestureEvent().raw_y);
1902 1940
1903 event = 1941 event =
1904 ObtainMotionEvent(event_time, MotionEvent::ACTION_POINTER_UP, 3, 3, 4, 4); 1942 ObtainMotionEvent(event_time, MotionEvent::ACTION_POINTER_UP, 3, 3, 4, 4);
1905 event.pointer_count = 1; 1943 event.pointer_count = 1;
1944 event.SetRawOffset(raw_offset_x, raw_offset_y);
1906 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1945 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1907 EXPECT_EQ(ET_GESTURE_END, GetMostRecentGestureEventType()); 1946 EXPECT_EQ(ET_GESTURE_END, GetMostRecentGestureEventType());
1908 EXPECT_EQ(8U, GetReceivedGestureCount()); 1947 EXPECT_EQ(8U, GetReceivedGestureCount());
1909 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); 1948 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1910 EXPECT_EQ(3, GetMostRecentGestureEvent().x); 1949 EXPECT_EQ(3, GetMostRecentGestureEvent().x);
1911 EXPECT_EQ(3, GetMostRecentGestureEvent().y); 1950 EXPECT_EQ(3, GetMostRecentGestureEvent().y);
1951 EXPECT_EQ(3 + raw_offset_x, GetMostRecentGestureEvent().raw_x);
1952 EXPECT_EQ(3 + raw_offset_y, GetMostRecentGestureEvent().raw_y);
1912 1953
1913 1954
1914 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_UP, 4, 4); 1955 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_UP, 4, 4);
1915 event.pointer_count = 1; 1956 event.pointer_count = 1;
1957 event.SetRawOffset(raw_offset_x, raw_offset_y);
1916 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1958 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1917 EXPECT_EQ(ET_GESTURE_END, GetMostRecentGestureEventType()); 1959 EXPECT_EQ(ET_GESTURE_END, GetMostRecentGestureEventType());
1918 EXPECT_EQ(9U, GetReceivedGestureCount()); 1960 EXPECT_EQ(9U, GetReceivedGestureCount());
1919 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); 1961 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1920 EXPECT_EQ(4, GetMostRecentGestureEvent().x); 1962 EXPECT_EQ(4, GetMostRecentGestureEvent().x);
1921 EXPECT_EQ(4, GetMostRecentGestureEvent().y); 1963 EXPECT_EQ(4, GetMostRecentGestureEvent().y);
1964 EXPECT_EQ(4 + raw_offset_x, GetMostRecentGestureEvent().raw_x);
1965 EXPECT_EQ(4 + raw_offset_y, GetMostRecentGestureEvent().raw_y);
1922 } 1966 }
1923 1967
1924 // Verify that gesture begin and gesture end events are dispatched correctly 1968 // Verify that gesture begin and gesture end events are dispatched correctly
1925 // when an ACTION_CANCEL is received. 1969 // when an ACTION_CANCEL is received.
1926 TEST_F(GestureProviderTest, GestureBeginAndEndOnCancel) { 1970 TEST_F(GestureProviderTest, GestureBeginAndEndOnCancel) {
1927 EnableBeginEndTypes(); 1971 EnableBeginEndTypes();
1928 base::TimeTicks event_time = base::TimeTicks::Now(); 1972 base::TimeTicks event_time = base::TimeTicks::Now();
1929 1973
1930 EXPECT_EQ(0U, GetReceivedGestureCount()); 1974 EXPECT_EQ(0U, GetReceivedGestureCount());
1931 MockMotionEvent event = 1975 MockMotionEvent event =
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
2245 ObtainMotionEvent(event_time + kOneMicrosecond, MotionEvent::ACTION_UP); 2289 ObtainMotionEvent(event_time + kOneMicrosecond, MotionEvent::ACTION_UP);
2246 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 2290 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2247 EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType()); 2291 EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
2248 EXPECT_EQ(kMinGestureBoundsLength, 2292 EXPECT_EQ(kMinGestureBoundsLength,
2249 GetMostRecentGestureEvent().details.bounding_box_f().width()); 2293 GetMostRecentGestureEvent().details.bounding_box_f().width());
2250 EXPECT_EQ(kMinGestureBoundsLength, 2294 EXPECT_EQ(kMinGestureBoundsLength,
2251 GetMostRecentGestureEvent().details.bounding_box_f().height()); 2295 GetMostRecentGestureEvent().details.bounding_box_f().height());
2252 } 2296 }
2253 2297
2254 } // namespace ui 2298 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698