1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907
|
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <math.h>
#include "base/basictypes.h"
#include "base/command_line.h"
#include "base/memory/scoped_ptr.h"
#include "base/strings/utf_string_conversions.h"
#include "content/browser/renderer_host/input/gesture_event_queue.h"
#include "content/browser/renderer_host/input/input_router_client.h"
#include "content/browser/renderer_host/input/input_router_impl.h"
#include "content/browser/renderer_host/input/mock_input_ack_handler.h"
#include "content/browser/renderer_host/input/mock_input_router_client.h"
#include "content/common/content_constants_internal.h"
#include "content/common/edit_command.h"
#include "content/common/input/synthetic_web_input_event_builders.h"
#include "content/common/input/touch_action.h"
#include "content/common/input/web_input_event_traits.h"
#include "content/common/input_messages.h"
#include "content/common/view_messages.h"
#include "content/public/common/content_switches.h"
#include "content/public/test/mock_render_process_host.h"
#include "content/public/test/test_browser_context.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/events/keycodes/keyboard_codes.h"
#if defined(USE_AURA)
#include "content/browser/renderer_host/ui_events_helper.h"
#include "ui/events/event.h"
#endif
using base::TimeDelta;
using blink::WebGestureDevice;
using blink::WebGestureEvent;
using blink::WebKeyboardEvent;
using blink::WebInputEvent;
using blink::WebMouseEvent;
using blink::WebMouseWheelEvent;
using blink::WebTouchEvent;
using blink::WebTouchPoint;
namespace content {
namespace {
const WebInputEvent* GetInputEventFromMessage(const IPC::Message& message) {
PickleIterator iter(message);
const char* data;
int data_length;
if (!iter.ReadData(&data, &data_length))
return NULL;
return reinterpret_cast<const WebInputEvent*>(data);
}
WebInputEvent& GetEventWithType(WebInputEvent::Type type) {
WebInputEvent* event = NULL;
if (WebInputEvent::isMouseEventType(type)) {
static WebMouseEvent mouse;
event = &mouse;
} else if (WebInputEvent::isTouchEventType(type)) {
static WebTouchEvent touch;
event = &touch;
} else if (WebInputEvent::isKeyboardEventType(type)) {
static WebKeyboardEvent key;
event = &key;
} else if (WebInputEvent::isGestureEventType(type)) {
static WebGestureEvent gesture;
event = &gesture;
} else if (type == WebInputEvent::MouseWheel) {
static WebMouseWheelEvent wheel;
event = &wheel;
}
CHECK(event);
event->type = type;
return *event;
}
bool GetIsShortcutFromHandleInputEventMessage(const IPC::Message* msg) {
InputMsg_HandleInputEvent::Schema::Param param;
InputMsg_HandleInputEvent::Read(msg, ¶m);
return get<2>(param);
}
template<typename MSG_T, typename ARG_T1>
void ExpectIPCMessageWithArg1(const IPC::Message* msg, const ARG_T1& arg1) {
ASSERT_EQ(MSG_T::ID, msg->type());
typename MSG_T::Schema::Param param;
ASSERT_TRUE(MSG_T::Read(msg, ¶m));
EXPECT_EQ(arg1, get<0>(param));
}
template<typename MSG_T, typename ARG_T1, typename ARG_T2>
void ExpectIPCMessageWithArg2(const IPC::Message* msg,
const ARG_T1& arg1,
const ARG_T2& arg2) {
ASSERT_EQ(MSG_T::ID, msg->type());
typename MSG_T::Schema::Param param;
ASSERT_TRUE(MSG_T::Read(msg, ¶m));
EXPECT_EQ(arg1, get<0>(param));
EXPECT_EQ(arg2, get<1>(param));
}
#if defined(USE_AURA)
bool TouchEventsAreEquivalent(const ui::TouchEvent& first,
const ui::TouchEvent& second) {
if (first.type() != second.type())
return false;
if (first.location() != second.location())
return false;
if (first.touch_id() != second.touch_id())
return false;
if (second.time_stamp().InSeconds() != first.time_stamp().InSeconds())
return false;
return true;
}
bool EventListIsSubset(const ScopedVector<ui::TouchEvent>& subset,
const ScopedVector<ui::TouchEvent>& set) {
if (subset.size() > set.size())
return false;
for (size_t i = 0; i < subset.size(); ++i) {
const ui::TouchEvent* first = subset[i];
const ui::TouchEvent* second = set[i];
bool equivalent = TouchEventsAreEquivalent(*first, *second);
if (!equivalent)
return false;
}
return true;
}
#endif // defined(USE_AURA)
// Expected function used for converting pinch scales to deltaY values.
float PinchScaleToWheelDelta(float scale) {
return 100.0 * log(scale);
}
} // namespace
class InputRouterImplTest : public testing::Test {
public:
InputRouterImplTest() {}
~InputRouterImplTest() override {}
protected:
// testing::Test
void SetUp() override {
browser_context_.reset(new TestBrowserContext());
process_.reset(new MockRenderProcessHost(browser_context_.get()));
client_.reset(new MockInputRouterClient());
ack_handler_.reset(new MockInputAckHandler());
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
command_line->AppendSwitch(switches::kValidateInputEventStream);
input_router_.reset(new InputRouterImpl(process_.get(),
client_.get(),
ack_handler_.get(),
MSG_ROUTING_NONE,
config_));
client_->set_input_router(input_router());
ack_handler_->set_input_router(input_router());
}
void TearDown() override {
// Process all pending tasks to avoid leaks.
base::MessageLoop::current()->RunUntilIdle();
input_router_.reset();
client_.reset();
process_.reset();
browser_context_.reset();
}
void SetUpForTouchAckTimeoutTest(int timeout_ms) {
config_.touch_config.touch_ack_timeout_delay =
base::TimeDelta::FromMilliseconds(timeout_ms);
config_.touch_config.touch_ack_timeout_supported = true;
TearDown();
SetUp();
}
void SimulateKeyboardEvent(WebInputEvent::Type type, bool is_shortcut) {
WebKeyboardEvent event = SyntheticWebKeyboardEventBuilder::Build(type);
NativeWebKeyboardEvent native_event;
memcpy(&native_event, &event, sizeof(event));
input_router_->SendKeyboardEvent(
native_event,
ui::LatencyInfo(),
is_shortcut);
}
void SimulateWheelEvent(float dX, float dY, int modifiers, bool precise) {
input_router_->SendWheelEvent(MouseWheelEventWithLatencyInfo(
SyntheticWebMouseWheelEventBuilder::Build(dX, dY, modifiers, precise)));
}
void SimulateMouseEvent(WebInputEvent::Type type, int x, int y) {
input_router_->SendMouseEvent(MouseEventWithLatencyInfo(
SyntheticWebMouseEventBuilder::Build(type, x, y, 0)));
}
void SimulateWheelEventWithPhase(WebMouseWheelEvent::Phase phase) {
input_router_->SendWheelEvent(MouseWheelEventWithLatencyInfo(
SyntheticWebMouseWheelEventBuilder::Build(phase)));
}
void SimulateGestureEvent(const WebGestureEvent& gesture) {
input_router_->SendGestureEvent(GestureEventWithLatencyInfo(gesture));
}
void SimulateGestureEvent(WebInputEvent::Type type,
WebGestureDevice source_device) {
SimulateGestureEvent(
SyntheticWebGestureEventBuilder::Build(type, source_device));
}
void SimulateGestureScrollUpdateEvent(float dX,
float dY,
int modifiers,
WebGestureDevice source_device) {
SimulateGestureEvent(SyntheticWebGestureEventBuilder::BuildScrollUpdate(
dX, dY, modifiers, source_device));
}
void SimulateGesturePinchUpdateEvent(float scale,
float anchor_x,
float anchor_y,
int modifiers,
WebGestureDevice source_device) {
SimulateGestureEvent(SyntheticWebGestureEventBuilder::BuildPinchUpdate(
scale, anchor_x, anchor_y, modifiers, source_device));
}
void SimulateGestureFlingStartEvent(float velocity_x,
float velocity_y,
WebGestureDevice source_device) {
SimulateGestureEvent(SyntheticWebGestureEventBuilder::BuildFling(
velocity_x, velocity_y, source_device));
}
void SetTouchTimestamp(base::TimeDelta timestamp) {
touch_event_.SetTimestamp(timestamp);
}
void SendTouchEvent() {
input_router_->SendTouchEvent(TouchEventWithLatencyInfo(touch_event_));
touch_event_.ResetPoints();
}
int PressTouchPoint(int x, int y) {
return touch_event_.PressPoint(x, y);
}
void MoveTouchPoint(int index, int x, int y) {
touch_event_.MovePoint(index, x, y);
}
void ReleaseTouchPoint(int index) {
touch_event_.ReleasePoint(index);
}
void CancelTouchPoint(int index) {
touch_event_.CancelPoint(index);
}
void SendInputEventACK(blink::WebInputEvent::Type type,
InputEventAckState ack_result) {
InputHostMsg_HandleInputEvent_ACK_Params ack;
ack.type = type;
ack.state = ack_result;
input_router_->OnMessageReceived(InputHostMsg_HandleInputEvent_ACK(0, ack));
}
InputRouterImpl* input_router() const {
return input_router_.get();
}
bool TouchEventQueueEmpty() const {
return input_router()->touch_event_queue_.empty();
}
bool TouchEventTimeoutEnabled() const {
return input_router()->touch_event_queue_.IsAckTimeoutEnabled();
}
void Flush() const {
return input_router_->Flush();
}
size_t GetAndResetDidFlushCount() {
return client_->GetAndResetDidFlushCount();
}
bool HasPendingEvents() const {
return input_router_->HasPendingEvents();
}
void OnHasTouchEventHandlers(bool has_handlers) {
input_router_->OnMessageReceived(
ViewHostMsg_HasTouchEventHandlers(0, has_handlers));
}
void OnSetTouchAction(content::TouchAction touch_action) {
input_router_->OnMessageReceived(
InputHostMsg_SetTouchAction(0, touch_action));
}
size_t GetSentMessageCountAndResetSink() {
size_t count = process_->sink().message_count();
process_->sink().ClearMessages();
return count;
}
static void RunTasksAndWait(base::TimeDelta delay) {
base::MessageLoop::current()->PostDelayedTask(
FROM_HERE, base::MessageLoop::QuitClosure(), delay);
base::MessageLoop::current()->Run();
}
InputRouterImpl::Config config_;
scoped_ptr<MockRenderProcessHost> process_;
scoped_ptr<MockInputRouterClient> client_;
scoped_ptr<MockInputAckHandler> ack_handler_;
scoped_ptr<InputRouterImpl> input_router_;
private:
base::MessageLoopForUI message_loop_;
SyntheticWebTouchEvent touch_event_;
scoped_ptr<TestBrowserContext> browser_context_;
};
TEST_F(InputRouterImplTest, CoalescesRangeSelection) {
input_router_->SendInput(scoped_ptr<IPC::Message>(
new InputMsg_SelectRange(0, gfx::Point(1, 2), gfx::Point(3, 4))));
ExpectIPCMessageWithArg2<InputMsg_SelectRange>(
process_->sink().GetMessageAt(0),
gfx::Point(1, 2),
gfx::Point(3, 4));
EXPECT_EQ(1u, GetSentMessageCountAndResetSink());
// Send two more messages without acking.
input_router_->SendInput(scoped_ptr<IPC::Message>(
new InputMsg_SelectRange(0, gfx::Point(5, 6), gfx::Point(7, 8))));
EXPECT_EQ(0u, GetSentMessageCountAndResetSink());
input_router_->SendInput(scoped_ptr<IPC::Message>(
new InputMsg_SelectRange(0, gfx::Point(9, 10), gfx::Point(11, 12))));
EXPECT_EQ(0u, GetSentMessageCountAndResetSink());
// Now ack the first message.
{
scoped_ptr<IPC::Message> response(new InputHostMsg_SelectRange_ACK(0));
input_router_->OnMessageReceived(*response);
}
// Verify that the two messages are coalesced into one message.
ExpectIPCMessageWithArg2<InputMsg_SelectRange>(
process_->sink().GetMessageAt(0),
gfx::Point(9, 10),
gfx::Point(11, 12));
EXPECT_EQ(1u, GetSentMessageCountAndResetSink());
// Acking the coalesced msg should not send any more msg.
{
scoped_ptr<IPC::Message> response(new InputHostMsg_SelectRange_ACK(0));
input_router_->OnMessageReceived(*response);
}
EXPECT_EQ(0u, GetSentMessageCountAndResetSink());
}
TEST_F(InputRouterImplTest, CoalescesMoveRangeSelectionExtent) {
input_router_->SendInput(scoped_ptr<IPC::Message>(
new InputMsg_MoveRangeSelectionExtent(0, gfx::Point(1, 2))));
ExpectIPCMessageWithArg1<InputMsg_MoveRangeSelectionExtent>(
process_->sink().GetMessageAt(0),
gfx::Point(1, 2));
EXPECT_EQ(1u, GetSentMessageCountAndResetSink());
// Send two more messages without acking.
input_router_->SendInput(scoped_ptr<IPC::Message>(
new InputMsg_MoveRangeSelectionExtent(0, gfx::Point(3, 4))));
EXPECT_EQ(0u, GetSentMessageCountAndResetSink());
input_router_->SendInput(scoped_ptr<IPC::Message>(
new InputMsg_MoveRangeSelectionExtent(0, gfx::Point(5, 6))));
EXPECT_EQ(0u, GetSentMessageCountAndResetSink());
// Now ack the first message.
{
scoped_ptr<IPC::Message> response(
new InputHostMsg_MoveRangeSelectionExtent_ACK(0));
input_router_->OnMessageReceived(*response);
}
// Verify that the two messages are coalesced into one message.
ExpectIPCMessageWithArg1<InputMsg_MoveRangeSelectionExtent>(
process_->sink().GetMessageAt(0),
gfx::Point(5, 6));
EXPECT_EQ(1u, GetSentMessageCountAndResetSink());
// Acking the coalesced msg should not send any more msg.
{
scoped_ptr<IPC::Message> response(
new InputHostMsg_MoveRangeSelectionExtent_ACK(0));
input_router_->OnMessageReceived(*response);
}
EXPECT_EQ(0u, GetSentMessageCountAndResetSink());
}
TEST_F(InputRouterImplTest, InterleaveSelectRangeAndMoveRangeSelectionExtent) {
// Send first message: SelectRange.
input_router_->SendInput(scoped_ptr<IPC::Message>(
new InputMsg_SelectRange(0, gfx::Point(1, 2), gfx::Point(3, 4))));
ExpectIPCMessageWithArg2<InputMsg_SelectRange>(
process_->sink().GetMessageAt(0),
gfx::Point(1, 2),
gfx::Point(3, 4));
EXPECT_EQ(1u, GetSentMessageCountAndResetSink());
// Send second message: MoveRangeSelectionExtent.
input_router_->SendInput(scoped_ptr<IPC::Message>(
new InputMsg_MoveRangeSelectionExtent(0, gfx::Point(5, 6))));
EXPECT_EQ(0u, GetSentMessageCountAndResetSink());
// Send third message: SelectRange.
input_router_->SendInput(scoped_ptr<IPC::Message>(
new InputMsg_SelectRange(0, gfx::Point(7, 8), gfx::Point(9, 10))));
EXPECT_EQ(0u, GetSentMessageCountAndResetSink());
// Ack the messages and verify that they're not coalesced and that they're in
// correct order.
// Ack the first message.
{
scoped_ptr<IPC::Message> response(
new InputHostMsg_SelectRange_ACK(0));
input_router_->OnMessageReceived(*response);
}
ExpectIPCMessageWithArg1<InputMsg_MoveRangeSelectionExtent>(
process_->sink().GetMessageAt(0),
gfx::Point(5, 6));
EXPECT_EQ(1u, GetSentMessageCountAndResetSink());
// Ack the second message.
{
scoped_ptr<IPC::Message> response(
new InputHostMsg_MoveRangeSelectionExtent_ACK(0));
input_router_->OnMessageReceived(*response);
}
ExpectIPCMessageWithArg2<InputMsg_SelectRange>(
process_->sink().GetMessageAt(0),
gfx::Point(7, 8),
gfx::Point(9, 10));
EXPECT_EQ(1u, GetSentMessageCountAndResetSink());
// Ack the third message.
{
scoped_ptr<IPC::Message> response(
new InputHostMsg_SelectRange_ACK(0));
input_router_->OnMessageReceived(*response);
}
EXPECT_EQ(0u, GetSentMessageCountAndResetSink());
}
TEST_F(InputRouterImplTest,
CoalescesInterleavedSelectRangeAndMoveRangeSelectionExtent) {
// Send interleaved SelectRange and MoveRangeSelectionExtent messages. They
// should be coalesced as shown by the arrows.
// > SelectRange
// MoveRangeSelectionExtent
// MoveRangeSelectionExtent
// > MoveRangeSelectionExtent
// SelectRange
// > SelectRange
// > MoveRangeSelectionExtent
input_router_->SendInput(scoped_ptr<IPC::Message>(
new InputMsg_SelectRange(0, gfx::Point(1, 2), gfx::Point(3, 4))));
ExpectIPCMessageWithArg2<InputMsg_SelectRange>(
process_->sink().GetMessageAt(0),
gfx::Point(1, 2),
gfx::Point(3, 4));
EXPECT_EQ(1u, GetSentMessageCountAndResetSink());
input_router_->SendInput(scoped_ptr<IPC::Message>(
new InputMsg_MoveRangeSelectionExtent(0, gfx::Point(5, 6))));
EXPECT_EQ(0u, GetSentMessageCountAndResetSink());
input_router_->SendInput(scoped_ptr<IPC::Message>(
new InputMsg_MoveRangeSelectionExtent(0, gfx::Point(7, 8))));
EXPECT_EQ(0u, GetSentMessageCountAndResetSink());
input_router_->SendInput(scoped_ptr<IPC::Message>(
new InputMsg_MoveRangeSelectionExtent(0, gfx::Point(9, 10))));
EXPECT_EQ(0u, GetSentMessageCountAndResetSink());
input_router_->SendInput(scoped_ptr<IPC::Message>(
new InputMsg_SelectRange(0, gfx::Point(11, 12), gfx::Point(13, 14))));
EXPECT_EQ(0u, GetSentMessageCountAndResetSink());
input_router_->SendInput(scoped_ptr<IPC::Message>(
new InputMsg_SelectRange(0, gfx::Point(15, 16), gfx::Point(17, 18))));
EXPECT_EQ(0u, GetSentMessageCountAndResetSink());
input_router_->SendInput(scoped_ptr<IPC::Message>(
new InputMsg_MoveRangeSelectionExtent(0, gfx::Point(19, 20))));
EXPECT_EQ(0u, GetSentMessageCountAndResetSink());
// Ack the first message.
{
scoped_ptr<IPC::Message> response(
new InputHostMsg_SelectRange_ACK(0));
input_router_->OnMessageReceived(*response);
}
// Verify that the three MoveRangeSelectionExtent messages are coalesced into
// one message.
ExpectIPCMessageWithArg1<InputMsg_MoveRangeSelectionExtent>(
process_->sink().GetMessageAt(0),
gfx::Point(9, 10));
EXPECT_EQ(1u, GetSentMessageCountAndResetSink());
// Ack the second message.
{
scoped_ptr<IPC::Message> response(
new InputHostMsg_MoveRangeSelectionExtent_ACK(0));
input_router_->OnMessageReceived(*response);
}
// Verify that the two SelectRange messages are coalesced into one message.
ExpectIPCMessageWithArg2<InputMsg_SelectRange>(
process_->sink().GetMessageAt(0),
gfx::Point(15, 16),
gfx::Point(17, 18));
EXPECT_EQ(1u, GetSentMessageCountAndResetSink());
// Ack the third message.
{
scoped_ptr<IPC::Message> response(
new InputHostMsg_SelectRange_ACK(0));
input_router_->OnMessageReceived(*response);
}
// Verify the fourth message.
ExpectIPCMessageWithArg1<InputMsg_MoveRangeSelectionExtent>(
process_->sink().GetMessageAt(0),
gfx::Point(19, 20));
EXPECT_EQ(1u, GetSentMessageCountAndResetSink());
// Ack the fourth message.
{
scoped_ptr<IPC::Message> response(
new InputHostMsg_MoveRangeSelectionExtent_ACK(0));
input_router_->OnMessageReceived(*response);
}
EXPECT_EQ(0u, GetSentMessageCountAndResetSink());
}
TEST_F(InputRouterImplTest, CoalescesCaretMove) {
input_router_->SendInput(
scoped_ptr<IPC::Message>(new InputMsg_MoveCaret(0, gfx::Point(1, 2))));
ExpectIPCMessageWithArg1<InputMsg_MoveCaret>(
process_->sink().GetMessageAt(0), gfx::Point(1, 2));
EXPECT_EQ(1u, GetSentMessageCountAndResetSink());
// Send two more messages without acking.
input_router_->SendInput(
scoped_ptr<IPC::Message>(new InputMsg_MoveCaret(0, gfx::Point(5, 6))));
EXPECT_EQ(0u, GetSentMessageCountAndResetSink());
input_router_->SendInput(
scoped_ptr<IPC::Message>(new InputMsg_MoveCaret(0, gfx::Point(9, 10))));
EXPECT_EQ(0u, GetSentMessageCountAndResetSink());
// Now ack the first message.
{
scoped_ptr<IPC::Message> response(new InputHostMsg_MoveCaret_ACK(0));
input_router_->OnMessageReceived(*response);
}
// Verify that the two messages are coalesced into one message.
ExpectIPCMessageWithArg1<InputMsg_MoveCaret>(
process_->sink().GetMessageAt(0), gfx::Point(9, 10));
EXPECT_EQ(1u, GetSentMessageCountAndResetSink());
// Acking the coalesced msg should not send any more msg.
{
scoped_ptr<IPC::Message> response(new InputHostMsg_MoveCaret_ACK(0));
input_router_->OnMessageReceived(*response);
}
EXPECT_EQ(0u, GetSentMessageCountAndResetSink());
}
TEST_F(InputRouterImplTest, HandledInputEvent) {
client_->set_filter_state(INPUT_EVENT_ACK_STATE_CONSUMED);
// Simulate a keyboard event.
SimulateKeyboardEvent(WebInputEvent::RawKeyDown, false);
// Make sure no input event is sent to the renderer.
EXPECT_EQ(0u, GetSentMessageCountAndResetSink());
// OnKeyboardEventAck should be triggered without actual ack.
EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
// As the event was acked already, keyboard event queue should be
// empty.
ASSERT_EQ(NULL, input_router_->GetLastKeyboardEvent());
}
TEST_F(InputRouterImplTest, ClientCanceledKeyboardEvent) {
client_->set_filter_state(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
// Simulate a keyboard event that has no consumer.
SimulateKeyboardEvent(WebInputEvent::RawKeyDown, false);
// Make sure no input event is sent to the renderer.
EXPECT_EQ(0u, GetSentMessageCountAndResetSink());
EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
// Simulate a keyboard event that should be dropped.
client_->set_filter_state(INPUT_EVENT_ACK_STATE_UNKNOWN);
SimulateKeyboardEvent(WebInputEvent::RawKeyDown, false);
// Make sure no input event is sent to the renderer, and no ack is sent.
EXPECT_EQ(0u, GetSentMessageCountAndResetSink());
EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount());
}
TEST_F(InputRouterImplTest, ShortcutKeyboardEvent) {
SimulateKeyboardEvent(WebInputEvent::RawKeyDown, true);
EXPECT_TRUE(GetIsShortcutFromHandleInputEventMessage(
process_->sink().GetMessageAt(0)));
process_->sink().ClearMessages();
SimulateKeyboardEvent(WebInputEvent::RawKeyDown, false);
EXPECT_FALSE(GetIsShortcutFromHandleInputEventMessage(
process_->sink().GetMessageAt(0)));
}
TEST_F(InputRouterImplTest, NoncorrespondingKeyEvents) {
SimulateKeyboardEvent(WebInputEvent::RawKeyDown, false);
SendInputEventACK(WebInputEvent::KeyUp,
INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_TRUE(ack_handler_->unexpected_event_ack_called());
}
// Tests ported from RenderWidgetHostTest --------------------------------------
TEST_F(InputRouterImplTest, HandleKeyEventsWeSent) {
// Simulate a keyboard event.
SimulateKeyboardEvent(WebInputEvent::RawKeyDown, false);
ASSERT_TRUE(input_router_->GetLastKeyboardEvent());
EXPECT_EQ(WebInputEvent::RawKeyDown,
input_router_->GetLastKeyboardEvent()->type);
// Make sure we sent the input event to the renderer.
EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(
InputMsg_HandleInputEvent::ID));
process_->sink().ClearMessages();
// Send the simulated response from the renderer back.
SendInputEventACK(WebInputEvent::RawKeyDown,
INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
EXPECT_EQ(WebInputEvent::RawKeyDown,
ack_handler_->acked_keyboard_event().type);
}
TEST_F(InputRouterImplTest, IgnoreKeyEventsWeDidntSend) {
// Send a simulated, unrequested key response. We should ignore this.
SendInputEventACK(WebInputEvent::RawKeyDown,
INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount());
}
TEST_F(InputRouterImplTest, CoalescesWheelEvents) {
// Simulate wheel events.
SimulateWheelEvent(0, -5, 0, false); // sent directly
SimulateWheelEvent(0, -10, 0, false); // enqueued
SimulateWheelEvent(8, -6, 0, false); // coalesced into previous event
SimulateWheelEvent(9, -7, 1, false); // enqueued, different modifiers
SimulateWheelEvent(0, -10, 0, false); // enqueued, different modifiers
// Explicitly verify that PhaseEnd isn't coalesced to avoid bugs like
// https://crbug.com/154740.
SimulateWheelEventWithPhase(WebMouseWheelEvent::PhaseEnded); // enqueued
// Check that only the first event was sent.
EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(
InputMsg_HandleInputEvent::ID));
const WebInputEvent* input_event =
GetInputEventFromMessage(*process_->sink().GetMessageAt(0));
ASSERT_EQ(WebInputEvent::MouseWheel, input_event->type);
const WebMouseWheelEvent* wheel_event =
static_cast<const WebMouseWheelEvent*>(input_event);
EXPECT_EQ(0, wheel_event->deltaX);
EXPECT_EQ(-5, wheel_event->deltaY);
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
// Check that the ACK sends the second message immediately.
SendInputEventACK(WebInputEvent::MouseWheel,
INPUT_EVENT_ACK_STATE_CONSUMED);
// The coalesced events can queue up a delayed ack
// so that additional input events can be processed before
// we turn off coalescing.
base::MessageLoop::current()->RunUntilIdle();
EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(
InputMsg_HandleInputEvent::ID));
input_event = GetInputEventFromMessage(*process_->sink().GetMessageAt(0));
ASSERT_EQ(WebInputEvent::MouseWheel, input_event->type);
wheel_event = static_cast<const WebMouseWheelEvent*>(input_event);
EXPECT_EQ(8, wheel_event->deltaX);
EXPECT_EQ(-10 + -6, wheel_event->deltaY); // coalesced
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
// Ack the second event (which had the third coalesced into it).
SendInputEventACK(WebInputEvent::MouseWheel,
INPUT_EVENT_ACK_STATE_CONSUMED);
base::MessageLoop::current()->RunUntilIdle();
EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(
InputMsg_HandleInputEvent::ID));
input_event = GetInputEventFromMessage(*process_->sink().GetMessageAt(0));
ASSERT_EQ(WebInputEvent::MouseWheel, input_event->type);
wheel_event = static_cast<const WebMouseWheelEvent*>(input_event);
EXPECT_EQ(9, wheel_event->deltaX);
EXPECT_EQ(-7, wheel_event->deltaY);
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
// Ack the fourth event.
SendInputEventACK(WebInputEvent::MouseWheel,
INPUT_EVENT_ACK_STATE_CONSUMED);
base::MessageLoop::current()->RunUntilIdle();
EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
EXPECT_TRUE(
process_->sink().GetUniqueMessageMatching(InputMsg_HandleInputEvent::ID));
input_event = GetInputEventFromMessage(*process_->sink().GetMessageAt(0));
ASSERT_EQ(WebInputEvent::MouseWheel, input_event->type);
wheel_event = static_cast<const WebMouseWheelEvent*>(input_event);
EXPECT_EQ(0, wheel_event->deltaX);
EXPECT_EQ(-10, wheel_event->deltaY);
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
// Ack the fifth event.
SendInputEventACK(WebInputEvent::MouseWheel, INPUT_EVENT_ACK_STATE_CONSUMED);
base::MessageLoop::current()->RunUntilIdle();
EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
EXPECT_TRUE(
process_->sink().GetUniqueMessageMatching(InputMsg_HandleInputEvent::ID));
input_event = GetInputEventFromMessage(*process_->sink().GetMessageAt(0));
ASSERT_EQ(WebInputEvent::MouseWheel, input_event->type);
wheel_event = static_cast<const WebMouseWheelEvent*>(input_event);
EXPECT_EQ(0, wheel_event->deltaX);
EXPECT_EQ(0, wheel_event->deltaY);
EXPECT_EQ(WebMouseWheelEvent::PhaseEnded, wheel_event->phase);
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
// After the final ack, the queue should be empty.
SendInputEventACK(WebInputEvent::MouseWheel, INPUT_EVENT_ACK_STATE_CONSUMED);
base::MessageLoop::current()->RunUntilIdle();
EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
}
// Tests that touch-events are queued properly.
TEST_F(InputRouterImplTest, TouchEventQueue) {
OnHasTouchEventHandlers(true);
PressTouchPoint(1, 1);
SendTouchEvent();
EXPECT_TRUE(client_->GetAndResetFilterEventCalled());
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
EXPECT_FALSE(TouchEventQueueEmpty());
// The second touch should not be sent since one is already in queue.
MoveTouchPoint(0, 5, 5);
SendTouchEvent();
EXPECT_FALSE(client_->GetAndResetFilterEventCalled());
EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
EXPECT_FALSE(TouchEventQueueEmpty());
// Receive an ACK for the first touch-event.
SendInputEventACK(WebInputEvent::TouchStart,
INPUT_EVENT_ACK_STATE_CONSUMED);
EXPECT_FALSE(TouchEventQueueEmpty());
EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
EXPECT_EQ(WebInputEvent::TouchStart,
ack_handler_->acked_touch_event().event.type);
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
SendInputEventACK(WebInputEvent::TouchMove,
INPUT_EVENT_ACK_STATE_CONSUMED);
EXPECT_TRUE(TouchEventQueueEmpty());
EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
EXPECT_EQ(WebInputEvent::TouchMove,
ack_handler_->acked_touch_event().event.type);
EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
}
// Tests that the touch-queue is emptied after a page stops listening for touch
// events and the outstanding ack is received.
TEST_F(InputRouterImplTest, TouchEventQueueFlush) {
OnHasTouchEventHandlers(true);
EXPECT_TRUE(client_->has_touch_handler());
EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
EXPECT_TRUE(TouchEventQueueEmpty());
EXPECT_TRUE(input_router_->ShouldForwardTouchEvent());
// Send a touch-press event.
PressTouchPoint(1, 1);
SendTouchEvent();
MoveTouchPoint(0, 2, 2);
MoveTouchPoint(0, 3, 3);
EXPECT_FALSE(TouchEventQueueEmpty());
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
// The page stops listening for touch-events. Note that flushing is deferred
// until the outstanding ack is received.
OnHasTouchEventHandlers(false);
EXPECT_FALSE(client_->has_touch_handler());
EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
EXPECT_FALSE(TouchEventQueueEmpty());
EXPECT_TRUE(input_router_->ShouldForwardTouchEvent());
// After the ack, the touch-event queue should be empty, and none of the
// flushed touch-events should have been sent to the renderer.
SendInputEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED);
EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
EXPECT_TRUE(TouchEventQueueEmpty());
EXPECT_FALSE(input_router_->ShouldForwardTouchEvent());
}
#if defined(USE_AURA)
// Tests that the acked events have correct state. (ui::Events are used only on
// windows and aura)
TEST_F(InputRouterImplTest, AckedTouchEventState) {
input_router_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true));
EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
EXPECT_TRUE(TouchEventQueueEmpty());
EXPECT_TRUE(input_router_->ShouldForwardTouchEvent());
// Send a bunch of events, and make sure the ACKed events are correct.
ScopedVector<ui::TouchEvent> expected_events;
// Use a custom timestamp for all the events to test that the acked events
// have the same timestamp;
base::TimeDelta timestamp = base::Time::NowFromSystemTime() - base::Time();
timestamp -= base::TimeDelta::FromSeconds(600);
// Press the first finger.
PressTouchPoint(1, 1);
SetTouchTimestamp(timestamp);
SendTouchEvent();
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
expected_events.push_back(new ui::TouchEvent(ui::ET_TOUCH_PRESSED,
gfx::Point(1, 1), 0, timestamp));
// Move the finger.
timestamp += base::TimeDelta::FromSeconds(10);
MoveTouchPoint(0, 500, 500);
SetTouchTimestamp(timestamp);
SendTouchEvent();
EXPECT_FALSE(TouchEventQueueEmpty());
expected_events.push_back(new ui::TouchEvent(ui::ET_TOUCH_MOVED,
gfx::Point(500, 500), 0, timestamp));
// Now press a second finger.
timestamp += base::TimeDelta::FromSeconds(10);
PressTouchPoint(2, 2);
SetTouchTimestamp(timestamp);
SendTouchEvent();
EXPECT_FALSE(TouchEventQueueEmpty());
expected_events.push_back(new ui::TouchEvent(ui::ET_TOUCH_PRESSED,
gfx::Point(2, 2), 1, timestamp));
// Move both fingers.
timestamp += base::TimeDelta::FromSeconds(10);
MoveTouchPoint(0, 10, 10);
MoveTouchPoint(1, 20, 20);
SetTouchTimestamp(timestamp);
SendTouchEvent();
EXPECT_FALSE(TouchEventQueueEmpty());
expected_events.push_back(new ui::TouchEvent(ui::ET_TOUCH_MOVED,
gfx::Point(10, 10), 0, timestamp));
expected_events.push_back(new ui::TouchEvent(ui::ET_TOUCH_MOVED,
gfx::Point(20, 20), 1, timestamp));
// Receive the ACKs and make sure the generated events from the acked events
// are correct.
WebInputEvent::Type acks[] = { WebInputEvent::TouchStart,
WebInputEvent::TouchMove,
WebInputEvent::TouchStart,
WebInputEvent::TouchMove };
TouchEventCoordinateSystem coordinate_system = LOCAL_COORDINATES;
#if !defined(OS_WIN)
coordinate_system = SCREEN_COORDINATES;
#endif
for (size_t i = 0; i < arraysize(acks); ++i) {
SendInputEventACK(acks[i],
INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(acks[i], ack_handler_->acked_touch_event().event.type);
ScopedVector<ui::TouchEvent> acked;
MakeUITouchEventsFromWebTouchEvents(
ack_handler_->acked_touch_event(), &acked, coordinate_system);
bool success = EventListIsSubset(acked, expected_events);
EXPECT_TRUE(success) << "Failed on step: " << i;
if (!success)
break;
expected_events.erase(expected_events.begin(),
expected_events.begin() + acked.size());
}
EXPECT_TRUE(TouchEventQueueEmpty());
EXPECT_EQ(0U, expected_events.size());
}
#endif // defined(USE_AURA)
TEST_F(InputRouterImplTest, UnhandledWheelEvent) {
// Simulate wheel events.
SimulateWheelEvent(0, -5, 0, false); // sent directly
SimulateWheelEvent(0, -10, 0, false); // enqueued
// Check that only the first event was sent.
EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(
InputMsg_HandleInputEvent::ID));
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
// Indicate that the wheel event was unhandled.
SendInputEventACK(WebInputEvent::MouseWheel,
INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
// Check that the correct unhandled wheel event was received.
EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
EXPECT_EQ(INPUT_EVENT_ACK_STATE_NOT_CONSUMED, ack_handler_->ack_state());
EXPECT_EQ(ack_handler_->acked_wheel_event().deltaY, -5);
// Check that the second event was sent.
EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(
InputMsg_HandleInputEvent::ID));
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
// Check that the correct unhandled wheel event was received.
EXPECT_EQ(ack_handler_->acked_wheel_event().deltaY, -5);
}
TEST_F(InputRouterImplTest, TouchTypesIgnoringAck) {
OnHasTouchEventHandlers(true);
// Only acks for TouchCancel should always be ignored.
ASSERT_FALSE(WebInputEventTraits::IgnoresAckDisposition(
GetEventWithType(WebInputEvent::TouchStart)));
ASSERT_FALSE(WebInputEventTraits::IgnoresAckDisposition(
GetEventWithType(WebInputEvent::TouchMove)));
ASSERT_FALSE(WebInputEventTraits::IgnoresAckDisposition(
GetEventWithType(WebInputEvent::TouchEnd)));
// Precede the TouchCancel with an appropriate TouchStart;
PressTouchPoint(1, 1);
SendTouchEvent();
SendInputEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED);
ASSERT_EQ(1U, GetSentMessageCountAndResetSink());
ASSERT_EQ(1U, ack_handler_->GetAndResetAckCount());
ASSERT_EQ(0, client_->in_flight_event_count());
// The TouchCancel ack is always ignored.
CancelTouchPoint(0);
SendTouchEvent();
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
EXPECT_EQ(0, client_->in_flight_event_count());
EXPECT_FALSE(HasPendingEvents());
SendInputEventACK(WebInputEvent::TouchCancel,
INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount());
EXPECT_FALSE(HasPendingEvents());
}
TEST_F(InputRouterImplTest, GestureTypesIgnoringAck) {
// We test every gesture type, ensuring that the stream of gestures is valid.
const WebInputEvent::Type eventTypes[] = {
WebInputEvent::GestureTapDown,
WebInputEvent::GestureShowPress,
WebInputEvent::GestureTapCancel,
WebInputEvent::GestureScrollBegin,
WebInputEvent::GestureFlingStart,
WebInputEvent::GestureFlingCancel,
WebInputEvent::GestureTapDown,
WebInputEvent::GestureTap,
WebInputEvent::GestureTapDown,
WebInputEvent::GestureLongPress,
WebInputEvent::GestureTapCancel,
WebInputEvent::GestureLongTap,
WebInputEvent::GestureTapDown,
WebInputEvent::GestureTapUnconfirmed,
WebInputEvent::GestureTapCancel,
WebInputEvent::GestureTapDown,
WebInputEvent::GestureDoubleTap,
WebInputEvent::GestureTapDown,
WebInputEvent::GestureTapCancel,
WebInputEvent::GestureTwoFingerTap,
WebInputEvent::GestureTapDown,
WebInputEvent::GestureTapCancel,
WebInputEvent::GestureScrollBegin,
WebInputEvent::GestureScrollUpdate,
WebInputEvent::GesturePinchBegin,
WebInputEvent::GesturePinchUpdate,
WebInputEvent::GesturePinchEnd,
WebInputEvent::GestureScrollEnd};
for (size_t i = 0; i < arraysize(eventTypes); ++i) {
WebInputEvent::Type type = eventTypes[i];
if (!WebInputEventTraits::IgnoresAckDisposition(GetEventWithType(type))) {
SimulateGestureEvent(type, blink::WebGestureDeviceTouchscreen);
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount());
EXPECT_EQ(1, client_->in_flight_event_count());
EXPECT_TRUE(HasPendingEvents());
SendInputEventACK(type, INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
EXPECT_EQ(0, client_->in_flight_event_count());
EXPECT_FALSE(HasPendingEvents());
continue;
}
SimulateGestureEvent(type, blink::WebGestureDeviceTouchscreen);
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
EXPECT_EQ(0, client_->in_flight_event_count());
EXPECT_FALSE(HasPendingEvents());
}
}
TEST_F(InputRouterImplTest, MouseTypesIgnoringAck) {
int start_type = static_cast<int>(WebInputEvent::MouseDown);
int end_type = static_cast<int>(WebInputEvent::ContextMenu);
ASSERT_LT(start_type, end_type);
for (int i = start_type; i <= end_type; ++i) {
WebInputEvent::Type type = static_cast<WebInputEvent::Type>(i);
int expected_in_flight_event_count =
WebInputEventTraits::IgnoresAckDisposition(GetEventWithType(type)) ? 0
: 1;
// Note: Mouse event acks are never forwarded to the ack handler, so the key
// result here is that ignored ack types don't affect the in-flight count.
SimulateMouseEvent(type, 0, 0);
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount());
EXPECT_EQ(expected_in_flight_event_count, client_->in_flight_event_count());
if (expected_in_flight_event_count) {
SendInputEventACK(type, INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount());
EXPECT_EQ(0, client_->in_flight_event_count());
}
}
}
// Guard against breaking changes to the list of ignored event ack types in
// |WebInputEventTraits::IgnoresAckDisposition|.
TEST_F(InputRouterImplTest, RequiredEventAckTypes) {
const WebInputEvent::Type kRequiredEventAckTypes[] = {
WebInputEvent::MouseMove,
WebInputEvent::MouseWheel,
WebInputEvent::RawKeyDown,
WebInputEvent::KeyDown,
WebInputEvent::KeyUp,
WebInputEvent::Char,
WebInputEvent::GestureScrollUpdate,
WebInputEvent::GestureFlingStart,
WebInputEvent::GestureFlingCancel,
WebInputEvent::GesturePinchUpdate,
WebInputEvent::TouchStart,
WebInputEvent::TouchMove
};
for (size_t i = 0; i < arraysize(kRequiredEventAckTypes); ++i) {
const WebInputEvent::Type required_ack_type = kRequiredEventAckTypes[i];
EXPECT_FALSE(WebInputEventTraits::IgnoresAckDisposition(
GetEventWithType(required_ack_type)));
}
}
// Test that GestureShowPress, GestureTapDown and GestureTapCancel events don't
// wait for ACKs.
TEST_F(InputRouterImplTest, GestureTypesIgnoringAckInterleaved) {
// Interleave a few events that do and do not ignore acks, ensuring that
// ack-ignoring events aren't dispatched until all prior events which observe
// their ack disposition have been dispatched.
SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
blink::WebGestureDeviceTouchscreen);
ASSERT_EQ(1U, GetSentMessageCountAndResetSink());
EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
EXPECT_EQ(0, client_->in_flight_event_count());
SimulateGestureEvent(WebInputEvent::GestureScrollUpdate,
blink::WebGestureDeviceTouchscreen);
ASSERT_EQ(1U, GetSentMessageCountAndResetSink());
EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount());
EXPECT_EQ(1, client_->in_flight_event_count());
SimulateGestureEvent(WebInputEvent::GestureTapDown,
blink::WebGestureDeviceTouchscreen);
EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount());
EXPECT_EQ(1, client_->in_flight_event_count());
SimulateGestureEvent(WebInputEvent::GestureScrollUpdate,
blink::WebGestureDeviceTouchscreen);
EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount());
SimulateGestureEvent(WebInputEvent::GestureShowPress,
blink::WebGestureDeviceTouchscreen);
EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount());
SimulateGestureEvent(WebInputEvent::GestureScrollUpdate,
blink::WebGestureDeviceTouchscreen);
EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount());
SimulateGestureEvent(WebInputEvent::GestureTapCancel,
blink::WebGestureDeviceTouchscreen);
EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount());
// Now ack each ack-respecting event. Ack-ignoring events should not be
// dispatched until all prior events which observe ack disposition have been
// fired, at which point they should be sent immediately. They should also
// have no effect on the in-flight event count.
SendInputEventACK(WebInputEvent::GestureScrollUpdate,
INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(2U, GetSentMessageCountAndResetSink());
EXPECT_EQ(2U, ack_handler_->GetAndResetAckCount());
EXPECT_EQ(1, client_->in_flight_event_count());
SendInputEventACK(WebInputEvent::GestureScrollUpdate,
INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(2U, GetSentMessageCountAndResetSink());
EXPECT_EQ(2U, ack_handler_->GetAndResetAckCount());
EXPECT_EQ(1, client_->in_flight_event_count());
SendInputEventACK(WebInputEvent::GestureScrollUpdate,
INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
EXPECT_EQ(2U, ack_handler_->GetAndResetAckCount());
EXPECT_EQ(0, client_->in_flight_event_count());
}
// Test that GestureShowPress events don't get out of order due to
// ignoring their acks.
TEST_F(InputRouterImplTest, GestureShowPressIsInOrder) {
SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
blink::WebGestureDeviceTouchscreen);
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
// GesturePinchBegin ignores its ack.
SimulateGestureEvent(WebInputEvent::GesturePinchBegin,
blink::WebGestureDeviceTouchscreen);
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
// GesturePinchUpdate waits for an ack.
// This also verifies that GesturePinchUpdates for touchscreen are sent
// to the renderer (in contrast to the TrackpadPinchUpdate test).
SimulateGestureEvent(WebInputEvent::GesturePinchUpdate,
blink::WebGestureDeviceTouchscreen);
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount());
SimulateGestureEvent(WebInputEvent::GestureShowPress,
blink::WebGestureDeviceTouchscreen);
EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
// The ShowPress, though it ignores ack, is still stuck in the queue
// behind the PinchUpdate which requires an ack.
EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount());
SimulateGestureEvent(WebInputEvent::GestureShowPress,
blink::WebGestureDeviceTouchscreen);
EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
// ShowPress has entered the queue.
EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount());
SendInputEventACK(WebInputEvent::GesturePinchUpdate,
INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
// Now that the Tap has been ACKed, the ShowPress events should receive
// synthetic acks, and fire immediately.
EXPECT_EQ(2U, GetSentMessageCountAndResetSink());
EXPECT_EQ(3U, ack_handler_->GetAndResetAckCount());
}
// Test that touch ack timeout behavior is properly toggled by view update flags
// and allowed touch actions.
TEST_F(InputRouterImplTest, TouchAckTimeoutConfigured) {
const int timeout_ms = 1;
SetUpForTouchAckTimeoutTest(timeout_ms);
ASSERT_TRUE(TouchEventTimeoutEnabled());
// Verify that the touch ack timeout fires upon the delayed ack.
PressTouchPoint(1, 1);
SendTouchEvent();
EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount());
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
RunTasksAndWait(base::TimeDelta::FromMilliseconds(timeout_ms + 1));
// The timed-out event should have been ack'ed.
EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
// Ack'ing the timed-out event should fire a TouchCancel.
SendInputEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED);
EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount());
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
// The remainder of the touch sequence should be dropped.
ReleaseTouchPoint(0);
SendTouchEvent();
EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
ASSERT_TRUE(TouchEventTimeoutEnabled());
// A fixed page scale or mobile viewport should disable the touch timeout.
input_router()->OnViewUpdated(InputRouter::FIXED_PAGE_SCALE);
EXPECT_FALSE(TouchEventTimeoutEnabled());
input_router()->OnViewUpdated(InputRouter::VIEW_FLAGS_NONE);
EXPECT_TRUE(TouchEventTimeoutEnabled());
input_router()->OnViewUpdated(InputRouter::MOBILE_VIEWPORT);
EXPECT_FALSE(TouchEventTimeoutEnabled());
input_router()->OnViewUpdated(InputRouter::MOBILE_VIEWPORT |
InputRouter::FIXED_PAGE_SCALE);
EXPECT_FALSE(TouchEventTimeoutEnabled());
input_router()->OnViewUpdated(InputRouter::VIEW_FLAGS_NONE);
EXPECT_TRUE(TouchEventTimeoutEnabled());
// TOUCH_ACTION_NONE (and no other touch-action) should disable the timeout.
OnHasTouchEventHandlers(true);
PressTouchPoint(1, 1);
SendTouchEvent();
OnSetTouchAction(TOUCH_ACTION_PAN_Y);
EXPECT_TRUE(TouchEventTimeoutEnabled());
ReleaseTouchPoint(0);
SendTouchEvent();
SendInputEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED);
SendInputEventACK(WebInputEvent::TouchEnd, INPUT_EVENT_ACK_STATE_CONSUMED);
PressTouchPoint(1, 1);
SendTouchEvent();
OnSetTouchAction(TOUCH_ACTION_NONE);
EXPECT_FALSE(TouchEventTimeoutEnabled());
ReleaseTouchPoint(0);
SendTouchEvent();
SendInputEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED);
SendInputEventACK(WebInputEvent::TouchEnd, INPUT_EVENT_ACK_STATE_CONSUMED);
// As the touch-action is reset by a new touch sequence, the timeout behavior
// should be restored.
PressTouchPoint(1, 1);
SendTouchEvent();
EXPECT_TRUE(TouchEventTimeoutEnabled());
}
// Test that a touch sequenced preceded by TOUCH_ACTION_NONE is not affected by
// the touch timeout.
TEST_F(InputRouterImplTest,
TouchAckTimeoutDisabledForTouchSequenceAfterTouchActionNone) {
const int timeout_ms = 1;
SetUpForTouchAckTimeoutTest(timeout_ms);
ASSERT_TRUE(TouchEventTimeoutEnabled());
OnHasTouchEventHandlers(true);
// Start a touch sequence.
PressTouchPoint(1, 1);
SendTouchEvent();
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
// TOUCH_ACTION_NONE should disable the timeout.
OnSetTouchAction(TOUCH_ACTION_NONE);
SendInputEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED);
EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
EXPECT_FALSE(TouchEventTimeoutEnabled());
MoveTouchPoint(0, 1, 1);
SendTouchEvent();
EXPECT_FALSE(TouchEventTimeoutEnabled());
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
// Delay the move ack. The timeout should not fire.
RunTasksAndWait(base::TimeDelta::FromMilliseconds(timeout_ms + 1));
EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount());
EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
SendInputEventACK(WebInputEvent::TouchEnd, INPUT_EVENT_ACK_STATE_CONSUMED);
EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
// End the touch sequence.
ReleaseTouchPoint(0);
SendTouchEvent();
SendInputEventACK(WebInputEvent::TouchEnd, INPUT_EVENT_ACK_STATE_CONSUMED);
EXPECT_FALSE(TouchEventTimeoutEnabled());
ack_handler_->GetAndResetAckCount();
GetSentMessageCountAndResetSink();
// Start another touch sequence. This should restore the touch timeout.
PressTouchPoint(1, 1);
SendTouchEvent();
EXPECT_TRUE(TouchEventTimeoutEnabled());
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount());
// Wait for the touch ack timeout to fire.
RunTasksAndWait(base::TimeDelta::FromMilliseconds(timeout_ms + 1));
EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
}
// Test that TouchActionFilter::ResetTouchAction is called before the
// first touch event for a touch sequence reaches the renderer.
TEST_F(InputRouterImplTest, TouchActionResetBeforeEventReachesRenderer) {
OnHasTouchEventHandlers(true);
// Sequence 1.
PressTouchPoint(1, 1);
SendTouchEvent();
OnSetTouchAction(TOUCH_ACTION_NONE);
MoveTouchPoint(0, 50, 50);
SendTouchEvent();
ReleaseTouchPoint(0);
SendTouchEvent();
// Sequence 2.
PressTouchPoint(1, 1);
SendTouchEvent();
MoveTouchPoint(0, 50, 50);
SendTouchEvent();
ReleaseTouchPoint(0);
SendTouchEvent();
SendInputEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED);
SendInputEventACK(WebInputEvent::TouchMove, INPUT_EVENT_ACK_STATE_CONSUMED);
// Ensure touch action is still none, as the next touch start hasn't been
// acked yet. ScrollBegin and ScrollEnd don't require acks.
EXPECT_EQ(3U, GetSentMessageCountAndResetSink());
SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
blink::WebGestureDeviceTouchscreen);
EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
SimulateGestureEvent(WebInputEvent::GestureScrollEnd,
blink::WebGestureDeviceTouchscreen);
EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
// This allows the next touch sequence to start.
SendInputEventACK(WebInputEvent::TouchEnd, INPUT_EVENT_ACK_STATE_CONSUMED);
// Ensure touch action has been set to auto, as a new touch sequence has
// started.
SendInputEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED);
SendInputEventACK(WebInputEvent::TouchMove, INPUT_EVENT_ACK_STATE_CONSUMED);
EXPECT_EQ(3U, GetSentMessageCountAndResetSink());
SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
blink::WebGestureDeviceTouchscreen);
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
SimulateGestureEvent(WebInputEvent::GestureScrollEnd,
blink::WebGestureDeviceTouchscreen);
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
SendInputEventACK(WebInputEvent::TouchEnd, INPUT_EVENT_ACK_STATE_CONSUMED);
}
// Test that TouchActionFilter::ResetTouchAction is called when a new touch
// sequence has no consumer.
TEST_F(InputRouterImplTest, TouchActionResetWhenTouchHasNoConsumer) {
OnHasTouchEventHandlers(true);
// Sequence 1.
PressTouchPoint(1, 1);
SendTouchEvent();
MoveTouchPoint(0, 50, 50);
SendTouchEvent();
OnSetTouchAction(TOUCH_ACTION_NONE);
SendInputEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED);
SendInputEventACK(WebInputEvent::TouchMove, INPUT_EVENT_ACK_STATE_CONSUMED);
ReleaseTouchPoint(0);
SendTouchEvent();
// Sequence 2
PressTouchPoint(1, 1);
SendTouchEvent();
MoveTouchPoint(0, 50, 50);
SendTouchEvent();
ReleaseTouchPoint(0);
SendTouchEvent();
// Ensure we have touch-action:none. ScrollBegin and ScrollEnd don't require
// acks.
EXPECT_EQ(3U, GetSentMessageCountAndResetSink());
SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
blink::WebGestureDeviceTouchscreen);
EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
SimulateGestureEvent(WebInputEvent::GestureScrollEnd,
blink::WebGestureDeviceTouchscreen);
EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
SendInputEventACK(WebInputEvent::TouchEnd, INPUT_EVENT_ACK_STATE_CONSUMED);
SendInputEventACK(WebInputEvent::TouchStart,
INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
// Ensure touch action has been set to auto, as the touch had no consumer.
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
blink::WebGestureDeviceTouchscreen);
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
SimulateGestureEvent(WebInputEvent::GestureScrollEnd,
blink::WebGestureDeviceTouchscreen);
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
}
// Test that TouchActionFilter::ResetTouchAction is called when the touch
// handler is removed.
TEST_F(InputRouterImplTest, TouchActionResetWhenTouchHandlerRemoved) {
// Touch sequence with touch handler.
OnHasTouchEventHandlers(true);
PressTouchPoint(1, 1);
SendTouchEvent();
MoveTouchPoint(0, 50, 50);
SendTouchEvent();
OnSetTouchAction(TOUCH_ACTION_NONE);
ReleaseTouchPoint(0);
SendTouchEvent();
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
// Ensure we have touch-action:none, suppressing scroll events.
SendInputEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED);
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
SendInputEventACK(WebInputEvent::TouchMove,
INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
blink::WebGestureDeviceTouchscreen);
EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
SendInputEventACK(WebInputEvent::TouchEnd,
INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
SimulateGestureEvent(WebInputEvent::GestureScrollEnd,
blink::WebGestureDeviceTouchscreen);
EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
// Sequence without a touch handler. Note that in this case, the view may not
// necessarily forward touches to the router (as no touch handler exists).
OnHasTouchEventHandlers(false);
// Ensure touch action has been set to auto, as the touch handler has been
// removed.
SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
blink::WebGestureDeviceTouchscreen);
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
SimulateGestureEvent(WebInputEvent::GestureScrollEnd,
blink::WebGestureDeviceTouchscreen);
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
}
// Test that the double tap gesture depends on the touch action of the first
// tap.
TEST_F(InputRouterImplTest, DoubleTapGestureDependsOnFirstTap) {
OnHasTouchEventHandlers(true);
// Sequence 1.
PressTouchPoint(1, 1);
SendTouchEvent();
OnSetTouchAction(TOUCH_ACTION_NONE);
SendInputEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED);
ReleaseTouchPoint(0);
SendTouchEvent();
// Sequence 2
PressTouchPoint(1, 1);
SendTouchEvent();
// First tap.
EXPECT_EQ(2U, GetSentMessageCountAndResetSink());
SimulateGestureEvent(WebInputEvent::GestureTapDown,
blink::WebGestureDeviceTouchscreen);
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
// The GestureTapUnconfirmed is converted into a tap, as the touch action is
// none.
SimulateGestureEvent(WebInputEvent::GestureTapUnconfirmed,
blink::WebGestureDeviceTouchscreen);
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
// This test will become invalid if GestureTap stops requiring an ack.
ASSERT_FALSE(WebInputEventTraits::IgnoresAckDisposition(
GetEventWithType(WebInputEvent::GestureTap)));
EXPECT_EQ(2, client_->in_flight_event_count());
SendInputEventACK(WebInputEvent::GestureTap,
INPUT_EVENT_ACK_STATE_CONSUMED);
EXPECT_EQ(1, client_->in_flight_event_count());
// This tap gesture is dropped, since the GestureTapUnconfirmed was turned
// into a tap.
SimulateGestureEvent(WebInputEvent::GestureTap,
blink::WebGestureDeviceTouchscreen);
EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
SendInputEventACK(WebInputEvent::TouchEnd, INPUT_EVENT_ACK_STATE_CONSUMED);
SendInputEventACK(WebInputEvent::TouchStart,
INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
// Second Tap.
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
SimulateGestureEvent(WebInputEvent::GestureTapDown,
blink::WebGestureDeviceTouchscreen);
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
// Although the touch-action is now auto, the double tap still won't be
// dispatched, because the first tap occured when the touch-action was none.
SimulateGestureEvent(WebInputEvent::GestureDoubleTap,
blink::WebGestureDeviceTouchscreen);
// This test will become invalid if GestureDoubleTap stops requiring an ack.
ASSERT_FALSE(WebInputEventTraits::IgnoresAckDisposition(
GetEventWithType(WebInputEvent::GestureDoubleTap)));
EXPECT_EQ(1, client_->in_flight_event_count());
SendInputEventACK(WebInputEvent::GestureTap, INPUT_EVENT_ACK_STATE_CONSUMED);
EXPECT_EQ(0, client_->in_flight_event_count());
}
// Test that the router will call the client's |DidFlush| after all events have
// been dispatched following a call to |Flush|.
TEST_F(InputRouterImplTest, InputFlush) {
EXPECT_FALSE(HasPendingEvents());
// Flushing an empty router should immediately trigger DidFlush.
Flush();
EXPECT_EQ(1U, GetAndResetDidFlushCount());
EXPECT_FALSE(HasPendingEvents());
// Queue a TouchStart.
OnHasTouchEventHandlers(true);
PressTouchPoint(1, 1);
SendTouchEvent();
EXPECT_TRUE(HasPendingEvents());
// DidFlush should be called only after the event is ack'ed.
Flush();
EXPECT_EQ(0U, GetAndResetDidFlushCount());
SendInputEventACK(WebInputEvent::TouchStart,
INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(1U, GetAndResetDidFlushCount());
// Ensure different types of enqueued events will prevent the DidFlush call
// until all such events have been fully dispatched.
MoveTouchPoint(0, 50, 50);
SendTouchEvent();
ASSERT_TRUE(HasPendingEvents());
SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
blink::WebGestureDeviceTouchscreen);
SimulateGestureEvent(WebInputEvent::GestureScrollUpdate,
blink::WebGestureDeviceTouchscreen);
SimulateGestureEvent(WebInputEvent::GesturePinchBegin,
blink::WebGestureDeviceTouchscreen);
SimulateGestureEvent(WebInputEvent::GesturePinchUpdate,
blink::WebGestureDeviceTouchscreen);
Flush();
EXPECT_EQ(0U, GetAndResetDidFlushCount());
// Repeated flush calls should have no effect.
Flush();
EXPECT_EQ(0U, GetAndResetDidFlushCount());
// There are still pending gestures.
SendInputEventACK(WebInputEvent::TouchMove,
INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(0U, GetAndResetDidFlushCount());
EXPECT_TRUE(HasPendingEvents());
// One more gesture to go.
SendInputEventACK(WebInputEvent::GestureScrollUpdate,
INPUT_EVENT_ACK_STATE_CONSUMED);
EXPECT_EQ(0U, GetAndResetDidFlushCount());
EXPECT_TRUE(HasPendingEvents());
// The final ack'ed gesture should trigger the DidFlush.
SendInputEventACK(WebInputEvent::GesturePinchUpdate,
INPUT_EVENT_ACK_STATE_CONSUMED);
EXPECT_EQ(1U, GetAndResetDidFlushCount());
EXPECT_FALSE(HasPendingEvents());
}
// Test that GesturePinchUpdate is handled specially for trackpad
TEST_F(InputRouterImplTest, TouchpadPinchUpdate) {
// GesturePinchUpdate for trackpad sends synthetic wheel events.
// Note that the Touchscreen case is verified as NOT doing this as
// part of the ShowPressIsInOrder test.
SimulateGesturePinchUpdateEvent(
1.5f, 20, 25, 0, blink::WebGestureDeviceTouchpad);
// Verify we actually sent a special wheel event to the renderer.
const WebInputEvent* input_event =
GetInputEventFromMessage(*process_->sink().GetMessageAt(0));
ASSERT_EQ(WebInputEvent::MouseWheel, input_event->type);
const WebMouseWheelEvent* wheel_event =
static_cast<const WebMouseWheelEvent*>(input_event);
EXPECT_EQ(20, wheel_event->x);
EXPECT_EQ(25, wheel_event->y);
EXPECT_EQ(20, wheel_event->globalX);
EXPECT_EQ(25, wheel_event->globalY);
EXPECT_EQ(20, wheel_event->windowX);
EXPECT_EQ(25, wheel_event->windowY);
EXPECT_EQ(PinchScaleToWheelDelta(1.5), wheel_event->deltaY);
EXPECT_EQ(0, wheel_event->deltaX);
EXPECT_TRUE(wheel_event->hasPreciseScrollingDeltas);
EXPECT_EQ(1, wheel_event->wheelTicksY);
EXPECT_EQ(0, wheel_event->wheelTicksX);
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
// Indicate that the wheel event was unhandled.
SendInputEventACK(WebInputEvent::MouseWheel,
INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
// Check that the correct unhandled pinch event was received.
EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
ASSERT_EQ(WebInputEvent::GesturePinchUpdate, ack_handler_->ack_event_type());
EXPECT_EQ(INPUT_EVENT_ACK_STATE_NOT_CONSUMED, ack_handler_->ack_state());
EXPECT_EQ(1.5f, ack_handler_->acked_gesture_event().data.pinchUpdate.scale);
EXPECT_EQ(0, client_->in_flight_event_count());
// Second a second pinch event.
SimulateGesturePinchUpdateEvent(
0.3f, 20, 25, 0, blink::WebGestureDeviceTouchpad);
input_event = GetInputEventFromMessage(*process_->sink().GetMessageAt(0));
ASSERT_EQ(WebInputEvent::MouseWheel, input_event->type);
wheel_event = static_cast<const WebMouseWheelEvent*>(input_event);
EXPECT_FLOAT_EQ(PinchScaleToWheelDelta(0.3f), wheel_event->deltaY);
EXPECT_TRUE(wheel_event->hasPreciseScrollingDeltas);
EXPECT_EQ(-1, wheel_event->wheelTicksY);
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
// Indicate that the wheel event was handled this time.
SendInputEventACK(WebInputEvent::MouseWheel, INPUT_EVENT_ACK_STATE_CONSUMED);
// Check that the correct HANDLED pinch event was received.
EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
EXPECT_EQ(WebInputEvent::GesturePinchUpdate, ack_handler_->ack_event_type());
EXPECT_EQ(INPUT_EVENT_ACK_STATE_CONSUMED, ack_handler_->ack_state());
EXPECT_FLOAT_EQ(0.3f,
ack_handler_->acked_gesture_event().data.pinchUpdate.scale);
}
// Test that touchpad pinch events are coalesced property, with their synthetic
// wheel events getting the right ACKs.
TEST_F(InputRouterImplTest, TouchpadPinchCoalescing) {
// Send the first pinch.
SimulateGesturePinchUpdateEvent(
1.5f, 20, 25, 0, blink::WebGestureDeviceTouchpad);
// Verify we sent the wheel event to the renderer.
const WebInputEvent* input_event =
GetInputEventFromMessage(*process_->sink().GetMessageAt(0));
ASSERT_EQ(WebInputEvent::MouseWheel, input_event->type);
const WebMouseWheelEvent* wheel_event =
static_cast<const WebMouseWheelEvent*>(input_event);
EXPECT_EQ(PinchScaleToWheelDelta(1.5f), wheel_event->deltaY);
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount());
EXPECT_EQ(1, client_->in_flight_event_count());
// Send a second pinch, this should be queued in the GestureEventQueue.
SimulateGesturePinchUpdateEvent(
1.6f, 20, 25, 0, blink::WebGestureDeviceTouchpad);
EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount());
// Send a third pinch, this should be coalesced into the second in the
// GestureEventQueue.
SimulateGesturePinchUpdateEvent(
1.7f, 20, 25, 0, blink::WebGestureDeviceTouchpad);
EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount());
// Indicate that the first wheel event was unhandled and verify the ACK.
SendInputEventACK(WebInputEvent::MouseWheel,
INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
EXPECT_EQ(WebInputEvent::GesturePinchUpdate, ack_handler_->ack_event_type());
EXPECT_EQ(INPUT_EVENT_ACK_STATE_NOT_CONSUMED, ack_handler_->ack_state());
EXPECT_EQ(1.5f, ack_handler_->acked_gesture_event().data.pinchUpdate.scale);
// Verify a second wheel event was sent representing the 2nd and 3rd pinch
// events.
EXPECT_EQ(1, client_->in_flight_event_count());
input_event = GetInputEventFromMessage(*process_->sink().GetMessageAt(0));
ASSERT_EQ(WebInputEvent::MouseWheel, input_event->type);
wheel_event = static_cast<const WebMouseWheelEvent*>(input_event);
EXPECT_FLOAT_EQ(PinchScaleToWheelDelta(1.6f * 1.7f),
PinchScaleToWheelDelta(1.6f) + PinchScaleToWheelDelta(1.7f));
EXPECT_FLOAT_EQ(PinchScaleToWheelDelta(1.6f * 1.7f), wheel_event->deltaY);
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount());
// Indicate that the second wheel event was handled and verify the ACK.
SendInputEventACK(WebInputEvent::MouseWheel, INPUT_EVENT_ACK_STATE_CONSUMED);
EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
EXPECT_EQ(WebInputEvent::GesturePinchUpdate, ack_handler_->ack_event_type());
EXPECT_EQ(INPUT_EVENT_ACK_STATE_CONSUMED, ack_handler_->ack_state());
EXPECT_FLOAT_EQ(1.6f * 1.7f,
ack_handler_->acked_gesture_event().data.pinchUpdate.scale);
}
// Test interleaving pinch and wheel events.
TEST_F(InputRouterImplTest, TouchpadPinchAndWheel) {
// Simulate queued wheel and pinch events events.
// Note that in practice interleaving pinch and wheel events should be rare
// (eg. requires the use of a mouse and trackpad at the same time).
// Use the control modifier to match the synthetic wheel events so that
// they're elligble for coalescing.
int mod = WebInputEvent::ControlKey;
// Event 1: sent directly.
SimulateWheelEvent(0, -5, mod, true);
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
// Event 2: enqueued in InputRouter.
SimulateWheelEvent(0, -10, mod, true);
EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
// Event 3: enqueued in InputRouter, not coalesced into #2.
SimulateGesturePinchUpdateEvent(
1.5f, 20, 25, 0, blink::WebGestureDeviceTouchpad);
EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
// Event 4: enqueued in GestureEventQueue.
SimulateGesturePinchUpdateEvent(
1.2f, 20, 25, 0, blink::WebGestureDeviceTouchpad);
EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
// Event 5: coalesced into wheel event for #3.
SimulateWheelEvent(2, 0, mod, true);
EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
// Send ack for #1.
SendInputEventACK(WebInputEvent::MouseWheel,
INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
EXPECT_EQ(WebInputEvent::MouseWheel, ack_handler_->ack_event_type());
// Verify we sent #2.
ASSERT_EQ(1U, process_->sink().message_count());
const WebInputEvent* input_event =
GetInputEventFromMessage(*process_->sink().GetMessageAt(0));
ASSERT_EQ(WebInputEvent::MouseWheel, input_event->type);
const WebMouseWheelEvent* wheel_event =
static_cast<const WebMouseWheelEvent*>(input_event);
EXPECT_EQ(0, wheel_event->deltaX);
EXPECT_EQ(-10, wheel_event->deltaY);
EXPECT_EQ(mod, wheel_event->modifiers);
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
// Send ack for #2.
SendInputEventACK(WebInputEvent::MouseWheel,
INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
EXPECT_EQ(WebInputEvent::MouseWheel, ack_handler_->ack_event_type());
// Verify we sent #3 (with #5 coalesced in).
ASSERT_EQ(1U, process_->sink().message_count());
input_event = GetInputEventFromMessage(*process_->sink().GetMessageAt(0));
ASSERT_EQ(WebInputEvent::MouseWheel, input_event->type);
wheel_event = static_cast<const WebMouseWheelEvent*>(input_event);
EXPECT_EQ(2, wheel_event->deltaX);
EXPECT_EQ(PinchScaleToWheelDelta(1.5f), wheel_event->deltaY);
EXPECT_EQ(mod, wheel_event->modifiers);
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
// Send ack for #3.
SendInputEventACK(WebInputEvent::MouseWheel,
INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
EXPECT_EQ(WebInputEvent::GesturePinchUpdate, ack_handler_->ack_event_type());
// Verify we sent #4.
ASSERT_EQ(1U, process_->sink().message_count());
input_event = GetInputEventFromMessage(*process_->sink().GetMessageAt(0));
ASSERT_EQ(WebInputEvent::MouseWheel, input_event->type);
wheel_event = static_cast<const WebMouseWheelEvent*>(input_event);
EXPECT_EQ(0, wheel_event->deltaX);
EXPECT_FLOAT_EQ(PinchScaleToWheelDelta(1.2f), wheel_event->deltaY);
EXPECT_EQ(mod, wheel_event->modifiers);
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
// Send ack for #4.
SendInputEventACK(WebInputEvent::MouseWheel,
INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
EXPECT_EQ(WebInputEvent::GesturePinchUpdate, ack_handler_->ack_event_type());
}
// Test proper handling of touchpad Gesture{Pinch,Scroll}Update sequences.
TEST_F(InputRouterImplTest, TouchpadPinchAndScrollUpdate) {
// The first scroll should be sent immediately.
SimulateGestureScrollUpdateEvent(1.5f, 0.f, 0,
blink::WebGestureDeviceTouchpad);
SimulateGestureEvent(WebInputEvent::GestureScrollUpdate,
blink::WebGestureDeviceTouchpad);
ASSERT_EQ(1U, GetSentMessageCountAndResetSink());
EXPECT_EQ(1, client_->in_flight_event_count());
// Subsequent scroll and pinch events should remain queued, coalescing as
// more trackpad events arrive.
SimulateGesturePinchUpdateEvent(1.5f, 20, 25, 0,
blink::WebGestureDeviceTouchpad);
ASSERT_EQ(0U, GetSentMessageCountAndResetSink());
EXPECT_EQ(1, client_->in_flight_event_count());
SimulateGestureScrollUpdateEvent(1.5f, 1.5f, 0,
blink::WebGestureDeviceTouchpad);
ASSERT_EQ(0U, GetSentMessageCountAndResetSink());
EXPECT_EQ(1, client_->in_flight_event_count());
SimulateGesturePinchUpdateEvent(1.5f, 20, 25, 0,
blink::WebGestureDeviceTouchpad);
ASSERT_EQ(0U, GetSentMessageCountAndResetSink());
EXPECT_EQ(1, client_->in_flight_event_count());
SimulateGestureScrollUpdateEvent(0.f, 1.5f, 0,
blink::WebGestureDeviceTouchpad);
ASSERT_EQ(0U, GetSentMessageCountAndResetSink());
EXPECT_EQ(1, client_->in_flight_event_count());
// Ack'ing the first scroll should trigger both the coalesced scroll and the
// coalesced pinch events (which is sent to the renderer as a wheel event).
SendInputEventACK(WebInputEvent::GestureScrollUpdate,
INPUT_EVENT_ACK_STATE_CONSUMED);
EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
EXPECT_EQ(2U, GetSentMessageCountAndResetSink());
EXPECT_EQ(2, client_->in_flight_event_count());
// Ack the second scroll.
SendInputEventACK(WebInputEvent::GestureScrollUpdate,
INPUT_EVENT_ACK_STATE_CONSUMED);
EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
EXPECT_EQ(1, client_->in_flight_event_count());
// Ack the wheel event.
SendInputEventACK(WebInputEvent::MouseWheel, INPUT_EVENT_ACK_STATE_CONSUMED);
EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
EXPECT_EQ(0, client_->in_flight_event_count());
}
// Test proper routing of overscroll notifications received either from
// event acks or from |DidOverscroll| IPC messages.
TEST_F(InputRouterImplTest, OverscrollDispatch) {
DidOverscrollParams overscroll;
overscroll.accumulated_overscroll = gfx::Vector2dF(-14, 14);
overscroll.latest_overscroll_delta = gfx::Vector2dF(-7, 0);
overscroll.current_fling_velocity = gfx::Vector2dF(-1, 0);
input_router_->OnMessageReceived(InputHostMsg_DidOverscroll(0, overscroll));
DidOverscrollParams client_overscroll = client_->GetAndResetOverscroll();
EXPECT_EQ(overscroll.accumulated_overscroll,
client_overscroll.accumulated_overscroll);
EXPECT_EQ(overscroll.latest_overscroll_delta,
client_overscroll.latest_overscroll_delta);
EXPECT_EQ(overscroll.current_fling_velocity,
client_overscroll.current_fling_velocity);
DidOverscrollParams wheel_overscroll;
wheel_overscroll.accumulated_overscroll = gfx::Vector2dF(7, -7);
wheel_overscroll.latest_overscroll_delta = gfx::Vector2dF(3, 0);
wheel_overscroll.current_fling_velocity = gfx::Vector2dF(1, 0);
SimulateWheelEvent(3, 0, 0, false);
InputHostMsg_HandleInputEvent_ACK_Params ack;
ack.type = WebInputEvent::MouseWheel;
ack.state = INPUT_EVENT_ACK_STATE_NOT_CONSUMED;
ack.overscroll.reset(new DidOverscrollParams(wheel_overscroll));
input_router_->OnMessageReceived(InputHostMsg_HandleInputEvent_ACK(0, ack));
client_overscroll = client_->GetAndResetOverscroll();
EXPECT_EQ(wheel_overscroll.accumulated_overscroll,
client_overscroll.accumulated_overscroll);
EXPECT_EQ(wheel_overscroll.latest_overscroll_delta,
client_overscroll.latest_overscroll_delta);
EXPECT_EQ(wheel_overscroll.current_fling_velocity,
client_overscroll.current_fling_velocity);
}
} // namespace content
|