| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/renderer_host/input/input_router_impl.h" | 5 #include "content/browser/renderer_host/input/input_router_impl.h" |
| 6 | 6 |
| 7 #include <math.h> | 7 #include <math.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| 11 #include <memory> | 11 #include <memory> |
| 12 #include <tuple> | 12 #include <tuple> |
| 13 | 13 |
| 14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 15 #include "base/location.h" | 15 #include "base/location.h" |
| 16 #include "base/macros.h" | 16 #include "base/macros.h" |
| 17 #include "base/run_loop.h" | 17 #include "base/run_loop.h" |
| 18 #include "base/single_thread_task_runner.h" | 18 #include "base/single_thread_task_runner.h" |
| 19 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
| 20 #include "base/test/scoped_feature_list.h" |
| 20 #include "base/threading/thread_task_runner_handle.h" | 21 #include "base/threading/thread_task_runner_handle.h" |
| 21 #include "build/build_config.h" | 22 #include "build/build_config.h" |
| 22 #include "content/browser/renderer_host/input/gesture_event_queue.h" | 23 #include "content/browser/renderer_host/input/gesture_event_queue.h" |
| 23 #include "content/browser/renderer_host/input/input_router_client.h" | 24 #include "content/browser/renderer_host/input/input_router_client.h" |
| 24 #include "content/browser/renderer_host/input/mock_input_ack_handler.h" | 25 #include "content/browser/renderer_host/input/mock_input_ack_handler.h" |
| 25 #include "content/browser/renderer_host/input/mock_input_router_client.h" | 26 #include "content/browser/renderer_host/input/mock_input_router_client.h" |
| 26 #include "content/common/content_constants_internal.h" | 27 #include "content/common/content_constants_internal.h" |
| 27 #include "content/common/edit_command.h" | 28 #include "content/common/edit_command.h" |
| 28 #include "content/common/input/synthetic_web_input_event_builders.h" | 29 #include "content/common/input/synthetic_web_input_event_builders.h" |
| 29 #include "content/common/input/touch_action.h" | 30 #include "content/common/input/touch_action.h" |
| 30 #include "content/common/input_messages.h" | 31 #include "content/common/input_messages.h" |
| 31 #include "content/common/view_messages.h" | 32 #include "content/common/view_messages.h" |
| 33 #include "content/public/common/content_features.h" |
| 32 #include "content/public/common/content_switches.h" | 34 #include "content/public/common/content_switches.h" |
| 33 #include "content/public/test/mock_render_process_host.h" | 35 #include "content/public/test/mock_render_process_host.h" |
| 34 #include "content/public/test/test_browser_context.h" | 36 #include "content/public/test/test_browser_context.h" |
| 35 #include "testing/gtest/include/gtest/gtest.h" | 37 #include "testing/gtest/include/gtest/gtest.h" |
| 36 #include "ui/events/base_event_utils.h" | 38 #include "ui/events/base_event_utils.h" |
| 37 #include "ui/events/blink/web_input_event_traits.h" | 39 #include "ui/events/blink/web_input_event_traits.h" |
| 38 #include "ui/events/keycodes/keyboard_codes.h" | 40 #include "ui/events/keycodes/keyboard_codes.h" |
| 39 | 41 |
| 40 #if defined(USE_AURA) | 42 #if defined(USE_AURA) |
| 41 #include "content/browser/renderer_host/ui_events_helper.h" | 43 #include "content/browser/renderer_host/ui_events_helper.h" |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 } | 137 } |
| 136 | 138 |
| 137 return true; | 139 return true; |
| 138 } | 140 } |
| 139 #endif // defined(USE_AURA) | 141 #endif // defined(USE_AURA) |
| 140 | 142 |
| 141 } // namespace | 143 } // namespace |
| 142 | 144 |
| 143 class InputRouterImplTest : public testing::Test { | 145 class InputRouterImplTest : public testing::Test { |
| 144 public: | 146 public: |
| 145 InputRouterImplTest() {} | 147 InputRouterImplTest() { EnableRafAlignedTouchInput(); } |
| 148 |
| 146 ~InputRouterImplTest() override {} | 149 ~InputRouterImplTest() override {} |
| 147 | 150 |
| 148 protected: | 151 protected: |
| 149 // testing::Test | 152 // testing::Test |
| 150 void SetUp() override { | 153 void SetUp() override { |
| 151 browser_context_.reset(new TestBrowserContext()); | 154 browser_context_.reset(new TestBrowserContext()); |
| 152 process_.reset(new MockRenderProcessHost(browser_context_.get())); | 155 process_.reset(new MockRenderProcessHost(browser_context_.get())); |
| 153 client_.reset(new MockInputRouterClient()); | 156 client_.reset(new MockInputRouterClient()); |
| 154 ack_handler_.reset(new MockInputAckHandler()); | 157 ack_handler_.reset(new MockInputAckHandler()); |
| 155 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 158 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 process_->sink().ClearMessages(); | 341 process_->sink().ClearMessages(); |
| 339 return count; | 342 return count; |
| 340 } | 343 } |
| 341 | 344 |
| 342 static void RunTasksAndWait(base::TimeDelta delay) { | 345 static void RunTasksAndWait(base::TimeDelta delay) { |
| 343 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 346 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 344 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), delay); | 347 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), delay); |
| 345 base::RunLoop().Run(); | 348 base::RunLoop().Run(); |
| 346 } | 349 } |
| 347 | 350 |
| 351 void EnableRafAlignedTouchInput() { |
| 352 feature_list_.InitFromCommandLine( |
| 353 features::kRafAlignedTouchInputEvents.name, ""); |
| 354 } |
| 355 |
| 356 void DisableRafAlignedTouchInput() { |
| 357 feature_list_.InitFromCommandLine( |
| 358 "", features::kRafAlignedTouchInputEvents.name); |
| 359 } |
| 360 |
| 348 InputRouterImpl::Config config_; | 361 InputRouterImpl::Config config_; |
| 349 std::unique_ptr<MockRenderProcessHost> process_; | 362 std::unique_ptr<MockRenderProcessHost> process_; |
| 350 std::unique_ptr<MockInputRouterClient> client_; | 363 std::unique_ptr<MockInputRouterClient> client_; |
| 351 std::unique_ptr<MockInputAckHandler> ack_handler_; | 364 std::unique_ptr<MockInputAckHandler> ack_handler_; |
| 352 std::unique_ptr<InputRouterImpl> input_router_; | 365 std::unique_ptr<InputRouterImpl> input_router_; |
| 353 | 366 |
| 354 private: | 367 private: |
| 355 base::MessageLoopForUI message_loop_; | 368 base::MessageLoopForUI message_loop_; |
| 356 SyntheticWebTouchEvent touch_event_; | 369 SyntheticWebTouchEvent touch_event_; |
| 357 | 370 |
| 371 base::test::ScopedFeatureList feature_list_; |
| 358 std::unique_ptr<TestBrowserContext> browser_context_; | 372 std::unique_ptr<TestBrowserContext> browser_context_; |
| 359 }; | 373 }; |
| 360 | 374 |
| 375 class InputRouterImplRafAlignedTouchDisabledTest : public InputRouterImplTest { |
| 376 public: |
| 377 void SetUp() override { |
| 378 DisableRafAlignedTouchInput(); |
| 379 InputRouterImplTest::SetUp(); |
| 380 } |
| 381 }; |
| 382 |
| 361 TEST_F(InputRouterImplTest, CoalescesRangeSelection) { | 383 TEST_F(InputRouterImplTest, CoalescesRangeSelection) { |
| 362 input_router_->SendInput(std::unique_ptr<IPC::Message>( | 384 input_router_->SendInput(std::unique_ptr<IPC::Message>( |
| 363 new InputMsg_SelectRange(0, gfx::Point(1, 2), gfx::Point(3, 4)))); | 385 new InputMsg_SelectRange(0, gfx::Point(1, 2), gfx::Point(3, 4)))); |
| 364 ExpectIPCMessageWithArg2<InputMsg_SelectRange>( | 386 ExpectIPCMessageWithArg2<InputMsg_SelectRange>( |
| 365 process_->sink().GetMessageAt(0), | 387 process_->sink().GetMessageAt(0), |
| 366 gfx::Point(1, 2), | 388 gfx::Point(1, 2), |
| 367 gfx::Point(3, 4)); | 389 gfx::Point(3, 4)); |
| 368 EXPECT_EQ(1u, GetSentMessageCountAndResetSink()); | 390 EXPECT_EQ(1u, GetSentMessageCountAndResetSink()); |
| 369 | 391 |
| 370 // Send two more messages without acking. | 392 // Send two more messages without acking. |
| (...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 776 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | 798 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 777 | 799 |
| 778 // After the final ack, the queue should be empty. | 800 // After the final ack, the queue should be empty. |
| 779 SendInputEventACK(WebInputEvent::MouseWheel, INPUT_EVENT_ACK_STATE_CONSUMED); | 801 SendInputEventACK(WebInputEvent::MouseWheel, INPUT_EVENT_ACK_STATE_CONSUMED); |
| 780 base::RunLoop().RunUntilIdle(); | 802 base::RunLoop().RunUntilIdle(); |
| 781 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); | 803 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); |
| 782 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); | 804 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); |
| 783 } | 805 } |
| 784 | 806 |
| 785 // Tests that touch-events are queued properly. | 807 // Tests that touch-events are queued properly. |
| 786 TEST_F(InputRouterImplTest, TouchEventQueue) { | 808 TEST_F(InputRouterImplRafAlignedTouchDisabledTest, TouchEventQueue) { |
| 787 OnHasTouchEventHandlers(true); | 809 OnHasTouchEventHandlers(true); |
| 788 | 810 |
| 789 PressTouchPoint(1, 1); | 811 PressTouchPoint(1, 1); |
| 790 uint32_t touch_press_event_id = SendTouchEvent(); | 812 uint32_t touch_press_event_id = SendTouchEvent(); |
| 791 EXPECT_TRUE(client_->GetAndResetFilterEventCalled()); | 813 EXPECT_TRUE(client_->GetAndResetFilterEventCalled()); |
| 792 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | 814 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 793 EXPECT_FALSE(TouchEventQueueEmpty()); | 815 EXPECT_FALSE(TouchEventQueueEmpty()); |
| 794 | 816 |
| 795 // The second touch should not be sent since one is already in queue. | 817 // The second touch should not be sent since one is already in queue. |
| 796 MoveTouchPoint(0, 5, 5); | 818 MoveTouchPoint(0, 5, 5); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 810 | 832 |
| 811 SendTouchEventACK(WebInputEvent::TouchMove, INPUT_EVENT_ACK_STATE_CONSUMED, | 833 SendTouchEventACK(WebInputEvent::TouchMove, INPUT_EVENT_ACK_STATE_CONSUMED, |
| 812 touch_move_event_id); | 834 touch_move_event_id); |
| 813 EXPECT_TRUE(TouchEventQueueEmpty()); | 835 EXPECT_TRUE(TouchEventQueueEmpty()); |
| 814 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); | 836 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); |
| 815 EXPECT_EQ(WebInputEvent::TouchMove, | 837 EXPECT_EQ(WebInputEvent::TouchMove, |
| 816 ack_handler_->acked_touch_event().event.type()); | 838 ack_handler_->acked_touch_event().event.type()); |
| 817 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); | 839 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); |
| 818 } | 840 } |
| 819 | 841 |
| 842 // Tests that touch-events are sent properly. |
| 843 TEST_F(InputRouterImplTest, TouchEventQueue) { |
| 844 OnHasTouchEventHandlers(true); |
| 845 |
| 846 PressTouchPoint(1, 1); |
| 847 uint32_t touch_press_event_id = SendTouchEvent(); |
| 848 EXPECT_TRUE(client_->GetAndResetFilterEventCalled()); |
| 849 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 850 EXPECT_FALSE(TouchEventQueueEmpty()); |
| 851 |
| 852 // The second touch should be sent right away. |
| 853 MoveTouchPoint(0, 5, 5); |
| 854 uint32_t touch_move_event_id = SendTouchEvent(); |
| 855 EXPECT_TRUE(client_->GetAndResetFilterEventCalled()); |
| 856 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 857 EXPECT_FALSE(TouchEventQueueEmpty()); |
| 858 |
| 859 // Receive an ACK for the first touch-event. |
| 860 SendTouchEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED, |
| 861 touch_press_event_id); |
| 862 EXPECT_FALSE(TouchEventQueueEmpty()); |
| 863 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); |
| 864 EXPECT_EQ(WebInputEvent::TouchStart, |
| 865 ack_handler_->acked_touch_event().event.type()); |
| 866 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); |
| 867 |
| 868 SendTouchEventACK(WebInputEvent::TouchMove, INPUT_EVENT_ACK_STATE_CONSUMED, |
| 869 touch_move_event_id); |
| 870 EXPECT_TRUE(TouchEventQueueEmpty()); |
| 871 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); |
| 872 EXPECT_EQ(WebInputEvent::TouchMove, |
| 873 ack_handler_->acked_touch_event().event.type()); |
| 874 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); |
| 875 } |
| 876 |
| 820 // Tests that the touch-queue is emptied after a page stops listening for touch | 877 // Tests that the touch-queue is emptied after a page stops listening for touch |
| 821 // events and the outstanding ack is received. | 878 // events and the outstanding ack is received. |
| 822 TEST_F(InputRouterImplTest, TouchEventQueueFlush) { | 879 TEST_F(InputRouterImplTest, TouchEventQueueFlush) { |
| 823 OnHasTouchEventHandlers(true); | 880 OnHasTouchEventHandlers(true); |
| 824 EXPECT_TRUE(client_->has_touch_handler()); | 881 EXPECT_TRUE(client_->has_touch_handler()); |
| 825 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); | 882 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); |
| 826 EXPECT_TRUE(TouchEventQueueEmpty()); | 883 EXPECT_TRUE(TouchEventQueueEmpty()); |
| 827 | 884 |
| 828 // Send a touch-press event. | 885 // Send a touch-press event. |
| 829 PressTouchPoint(1, 1); | 886 PressTouchPoint(1, 1); |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1031 WebInputEvent::GestureScrollBegin, | 1088 WebInputEvent::GestureScrollBegin, |
| 1032 WebInputEvent::GestureScrollUpdate, | 1089 WebInputEvent::GestureScrollUpdate, |
| 1033 WebInputEvent::GesturePinchBegin, | 1090 WebInputEvent::GesturePinchBegin, |
| 1034 WebInputEvent::GesturePinchUpdate, | 1091 WebInputEvent::GesturePinchUpdate, |
| 1035 WebInputEvent::GesturePinchEnd, | 1092 WebInputEvent::GesturePinchEnd, |
| 1036 WebInputEvent::GestureScrollEnd}; | 1093 WebInputEvent::GestureScrollEnd}; |
| 1037 for (size_t i = 0; i < arraysize(eventTypes); ++i) { | 1094 for (size_t i = 0; i < arraysize(eventTypes); ++i) { |
| 1038 WebInputEvent::Type type = eventTypes[i]; | 1095 WebInputEvent::Type type = eventTypes[i]; |
| 1039 if (WebInputEventTraits::ShouldBlockEventStream(GetEventWithType(type))) { | 1096 if (WebInputEventTraits::ShouldBlockEventStream(GetEventWithType(type))) { |
| 1040 SimulateGestureEvent(type, blink::WebGestureDeviceTouchscreen); | 1097 SimulateGestureEvent(type, blink::WebGestureDeviceTouchscreen); |
| 1041 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | 1098 if (type == WebInputEvent::GestureScrollUpdate) |
| 1099 EXPECT_EQ(2U, GetSentMessageCountAndResetSink()); |
| 1100 else |
| 1101 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 1042 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount()); | 1102 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount()); |
| 1043 EXPECT_EQ(1, client_->in_flight_event_count()); | 1103 EXPECT_EQ(1, client_->in_flight_event_count()); |
| 1044 EXPECT_TRUE(HasPendingEvents()); | 1104 EXPECT_TRUE(HasPendingEvents()); |
| 1045 | 1105 |
| 1046 SendInputEventACK(type, INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1106 SendInputEventACK(type, INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1047 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); | 1107 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); |
| 1048 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); | 1108 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); |
| 1049 EXPECT_EQ(0, client_->in_flight_event_count()); | 1109 EXPECT_EQ(0, client_->in_flight_event_count()); |
| 1050 EXPECT_FALSE(HasPendingEvents()); | 1110 EXPECT_FALSE(HasPendingEvents()); |
| 1051 continue; | 1111 continue; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1117 // their ack disposition have been dispatched. | 1177 // their ack disposition have been dispatched. |
| 1118 | 1178 |
| 1119 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, | 1179 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, |
| 1120 blink::WebGestureDeviceTouchscreen); | 1180 blink::WebGestureDeviceTouchscreen); |
| 1121 ASSERT_EQ(1U, GetSentMessageCountAndResetSink()); | 1181 ASSERT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 1122 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); | 1182 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); |
| 1123 EXPECT_EQ(0, client_->in_flight_event_count()); | 1183 EXPECT_EQ(0, client_->in_flight_event_count()); |
| 1124 | 1184 |
| 1125 SimulateGestureEvent(WebInputEvent::GestureScrollUpdate, | 1185 SimulateGestureEvent(WebInputEvent::GestureScrollUpdate, |
| 1126 blink::WebGestureDeviceTouchscreen); | 1186 blink::WebGestureDeviceTouchscreen); |
| 1127 ASSERT_EQ(1U, GetSentMessageCountAndResetSink()); | 1187 ASSERT_EQ(2U, GetSentMessageCountAndResetSink()); |
| 1128 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount()); | 1188 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount()); |
| 1129 EXPECT_EQ(1, client_->in_flight_event_count()); | 1189 EXPECT_EQ(1, client_->in_flight_event_count()); |
| 1130 | 1190 |
| 1131 SimulateGestureEvent(WebInputEvent::GestureTapDown, | 1191 SimulateGestureEvent(WebInputEvent::GestureTapDown, |
| 1132 blink::WebGestureDeviceTouchscreen); | 1192 blink::WebGestureDeviceTouchscreen); |
| 1133 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); | 1193 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); |
| 1134 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount()); | 1194 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount()); |
| 1135 EXPECT_EQ(1, client_->in_flight_event_count()); | 1195 EXPECT_EQ(1, client_->in_flight_event_count()); |
| 1136 | 1196 |
| 1137 SimulateGestureEvent(WebInputEvent::GestureScrollUpdate, | 1197 SimulateGestureEvent(WebInputEvent::GestureScrollUpdate, |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1369 ReleaseTouchPoint(0); | 1429 ReleaseTouchPoint(0); |
| 1370 uint32_t touch_release_event_id2 = SendTouchEvent(); | 1430 uint32_t touch_release_event_id2 = SendTouchEvent(); |
| 1371 | 1431 |
| 1372 SendTouchEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED, | 1432 SendTouchEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED, |
| 1373 touch_press_event_id1); | 1433 touch_press_event_id1); |
| 1374 SendTouchEventACK(WebInputEvent::TouchMove, INPUT_EVENT_ACK_STATE_CONSUMED, | 1434 SendTouchEventACK(WebInputEvent::TouchMove, INPUT_EVENT_ACK_STATE_CONSUMED, |
| 1375 touch_move_event_id1); | 1435 touch_move_event_id1); |
| 1376 | 1436 |
| 1377 // Ensure touch action is still none, as the next touch start hasn't been | 1437 // Ensure touch action is still none, as the next touch start hasn't been |
| 1378 // acked yet. ScrollBegin and ScrollEnd don't require acks. | 1438 // acked yet. ScrollBegin and ScrollEnd don't require acks. |
| 1379 EXPECT_EQ(3U, GetSentMessageCountAndResetSink()); | 1439 EXPECT_EQ(6U, GetSentMessageCountAndResetSink()); |
| 1380 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, | 1440 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, |
| 1381 blink::WebGestureDeviceTouchscreen); | 1441 blink::WebGestureDeviceTouchscreen); |
| 1382 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); | 1442 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); |
| 1383 SimulateGestureEvent(WebInputEvent::GestureScrollEnd, | 1443 SimulateGestureEvent(WebInputEvent::GestureScrollEnd, |
| 1384 blink::WebGestureDeviceTouchscreen); | 1444 blink::WebGestureDeviceTouchscreen); |
| 1385 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); | 1445 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); |
| 1386 | 1446 |
| 1387 // This allows the next touch sequence to start. | 1447 // This allows the next touch sequence to start. |
| 1388 SendTouchEventACK(WebInputEvent::TouchEnd, INPUT_EVENT_ACK_STATE_CONSUMED, | 1448 SendTouchEventACK(WebInputEvent::TouchEnd, INPUT_EVENT_ACK_STATE_CONSUMED, |
| 1389 touch_release_event_id1); | 1449 touch_release_event_id1); |
| 1390 | 1450 |
| 1391 // Ensure touch action has been set to auto, as a new touch sequence has | 1451 // Ensure touch action has been set to auto, as a new touch sequence has |
| 1392 // started. | 1452 // started. |
| 1393 SendTouchEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED, | 1453 SendTouchEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED, |
| 1394 touch_press_event_id2); | 1454 touch_press_event_id2); |
| 1395 SendTouchEventACK(WebInputEvent::TouchMove, INPUT_EVENT_ACK_STATE_CONSUMED, | 1455 SendTouchEventACK(WebInputEvent::TouchMove, INPUT_EVENT_ACK_STATE_CONSUMED, |
| 1396 touch_move_event_id2); | 1456 touch_move_event_id2); |
| 1397 EXPECT_EQ(3U, GetSentMessageCountAndResetSink()); | 1457 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); |
| 1398 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, | 1458 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, |
| 1399 blink::WebGestureDeviceTouchscreen); | 1459 blink::WebGestureDeviceTouchscreen); |
| 1400 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | 1460 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 1401 SimulateGestureEvent(WebInputEvent::GestureScrollEnd, | 1461 SimulateGestureEvent(WebInputEvent::GestureScrollEnd, |
| 1402 blink::WebGestureDeviceTouchscreen); | 1462 blink::WebGestureDeviceTouchscreen); |
| 1403 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | 1463 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 1404 SendTouchEventACK(WebInputEvent::TouchEnd, INPUT_EVENT_ACK_STATE_CONSUMED, | 1464 SendTouchEventACK(WebInputEvent::TouchEnd, INPUT_EVENT_ACK_STATE_CONSUMED, |
| 1405 touch_release_event_id2); | 1465 touch_release_event_id2); |
| 1406 } | 1466 } |
| 1407 | 1467 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1427 // Sequence 2 | 1487 // Sequence 2 |
| 1428 PressTouchPoint(1, 1); | 1488 PressTouchPoint(1, 1); |
| 1429 uint32_t touch_press_event_id2 = SendTouchEvent(); | 1489 uint32_t touch_press_event_id2 = SendTouchEvent(); |
| 1430 MoveTouchPoint(0, 50, 50); | 1490 MoveTouchPoint(0, 50, 50); |
| 1431 SendTouchEvent(); | 1491 SendTouchEvent(); |
| 1432 ReleaseTouchPoint(0); | 1492 ReleaseTouchPoint(0); |
| 1433 SendTouchEvent(); | 1493 SendTouchEvent(); |
| 1434 | 1494 |
| 1435 // Ensure we have touch-action:none. ScrollBegin and ScrollEnd don't require | 1495 // Ensure we have touch-action:none. ScrollBegin and ScrollEnd don't require |
| 1436 // acks. | 1496 // acks. |
| 1437 EXPECT_EQ(3U, GetSentMessageCountAndResetSink()); | 1497 EXPECT_EQ(6U, GetSentMessageCountAndResetSink()); |
| 1438 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, | 1498 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, |
| 1439 blink::WebGestureDeviceTouchscreen); | 1499 blink::WebGestureDeviceTouchscreen); |
| 1440 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); | 1500 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); |
| 1441 SimulateGestureEvent(WebInputEvent::GestureScrollEnd, | 1501 SimulateGestureEvent(WebInputEvent::GestureScrollEnd, |
| 1442 blink::WebGestureDeviceTouchscreen); | 1502 blink::WebGestureDeviceTouchscreen); |
| 1443 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); | 1503 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); |
| 1444 | 1504 |
| 1445 SendTouchEventACK(WebInputEvent::TouchEnd, INPUT_EVENT_ACK_STATE_CONSUMED, | 1505 SendTouchEventACK(WebInputEvent::TouchEnd, INPUT_EVENT_ACK_STATE_CONSUMED, |
| 1446 touch_release_event_id1); | 1506 touch_release_event_id1); |
| 1447 SendTouchEventACK(WebInputEvent::TouchStart, | 1507 SendTouchEventACK(WebInputEvent::TouchStart, |
| 1448 INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, | 1508 INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, |
| 1449 touch_press_event_id2); | 1509 touch_press_event_id2); |
| 1450 | 1510 |
| 1451 // Ensure touch action has been set to auto, as the touch had no consumer. | 1511 // Ensure touch action has been set to auto, as the touch had no consumer. |
| 1452 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | 1512 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); |
| 1453 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, | 1513 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, |
| 1454 blink::WebGestureDeviceTouchscreen); | 1514 blink::WebGestureDeviceTouchscreen); |
| 1455 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | 1515 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 1456 SimulateGestureEvent(WebInputEvent::GestureScrollEnd, | 1516 SimulateGestureEvent(WebInputEvent::GestureScrollEnd, |
| 1457 blink::WebGestureDeviceTouchscreen); | 1517 blink::WebGestureDeviceTouchscreen); |
| 1458 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | 1518 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 1459 } | 1519 } |
| 1460 | 1520 |
| 1461 // Test that TouchActionFilter::ResetTouchAction is called when the touch | 1521 // Test that TouchActionFilter::ResetTouchAction is called when the touch |
| 1462 // handler is removed. | 1522 // handler is removed. |
| 1463 TEST_F(InputRouterImplTest, TouchActionResetWhenTouchHandlerRemoved) { | 1523 TEST_F(InputRouterImplTest, TouchActionResetWhenTouchHandlerRemoved) { |
| 1464 // Touch sequence with touch handler. | 1524 // Touch sequence with touch handler. |
| 1465 OnHasTouchEventHandlers(true); | 1525 OnHasTouchEventHandlers(true); |
| 1466 PressTouchPoint(1, 1); | 1526 PressTouchPoint(1, 1); |
| 1467 uint32_t touch_press_event_id = SendTouchEvent(); | 1527 uint32_t touch_press_event_id = SendTouchEvent(); |
| 1468 MoveTouchPoint(0, 50, 50); | 1528 MoveTouchPoint(0, 50, 50); |
| 1469 uint32_t touch_move_event_id = SendTouchEvent(); | 1529 uint32_t touch_move_event_id = SendTouchEvent(); |
| 1470 OnSetTouchAction(TOUCH_ACTION_NONE); | 1530 OnSetTouchAction(TOUCH_ACTION_NONE); |
| 1471 ReleaseTouchPoint(0); | 1531 ReleaseTouchPoint(0); |
| 1472 uint32_t touch_release_event_id = SendTouchEvent(); | 1532 uint32_t touch_release_event_id = SendTouchEvent(); |
| 1473 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | 1533 EXPECT_EQ(3U, GetSentMessageCountAndResetSink()); |
| 1474 | 1534 |
| 1475 // Ensure we have touch-action:none, suppressing scroll events. | 1535 // Ensure we have touch-action:none, suppressing scroll events. |
| 1476 SendTouchEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED, | 1536 SendTouchEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED, |
| 1477 touch_press_event_id); | 1537 touch_press_event_id); |
| 1478 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | 1538 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); |
| 1479 SendTouchEventACK(WebInputEvent::TouchMove, | 1539 SendTouchEventACK(WebInputEvent::TouchMove, |
| 1480 INPUT_EVENT_ACK_STATE_NOT_CONSUMED, touch_move_event_id); | 1540 INPUT_EVENT_ACK_STATE_NOT_CONSUMED, touch_move_event_id); |
| 1481 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | 1541 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); |
| 1482 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, | 1542 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, |
| 1483 blink::WebGestureDeviceTouchscreen); | 1543 blink::WebGestureDeviceTouchscreen); |
| 1484 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); | 1544 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); |
| 1485 | 1545 |
| 1486 SendTouchEventACK(WebInputEvent::TouchEnd, INPUT_EVENT_ACK_STATE_NOT_CONSUMED, | 1546 SendTouchEventACK(WebInputEvent::TouchEnd, INPUT_EVENT_ACK_STATE_NOT_CONSUMED, |
| 1487 touch_release_event_id); | 1547 touch_release_event_id); |
| 1488 SimulateGestureEvent(WebInputEvent::GestureScrollEnd, | 1548 SimulateGestureEvent(WebInputEvent::GestureScrollEnd, |
| 1489 blink::WebGestureDeviceTouchscreen); | 1549 blink::WebGestureDeviceTouchscreen); |
| 1490 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); | 1550 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); |
| 1491 | 1551 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1516 touch_press_event_id1); | 1576 touch_press_event_id1); |
| 1517 | 1577 |
| 1518 ReleaseTouchPoint(0); | 1578 ReleaseTouchPoint(0); |
| 1519 uint32_t touch_release_event_id = SendTouchEvent(); | 1579 uint32_t touch_release_event_id = SendTouchEvent(); |
| 1520 | 1580 |
| 1521 // Sequence 2 | 1581 // Sequence 2 |
| 1522 PressTouchPoint(1, 1); | 1582 PressTouchPoint(1, 1); |
| 1523 uint32_t touch_press_event_id2 = SendTouchEvent(); | 1583 uint32_t touch_press_event_id2 = SendTouchEvent(); |
| 1524 | 1584 |
| 1525 // First tap. | 1585 // First tap. |
| 1526 EXPECT_EQ(2U, GetSentMessageCountAndResetSink()); | 1586 EXPECT_EQ(3U, GetSentMessageCountAndResetSink()); |
| 1527 SimulateGestureEvent(WebInputEvent::GestureTapDown, | 1587 SimulateGestureEvent(WebInputEvent::GestureTapDown, |
| 1528 blink::WebGestureDeviceTouchscreen); | 1588 blink::WebGestureDeviceTouchscreen); |
| 1529 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | 1589 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 1530 | 1590 |
| 1531 // The GestureTapUnconfirmed is converted into a tap, as the touch action is | 1591 // The GestureTapUnconfirmed is converted into a tap, as the touch action is |
| 1532 // none. | 1592 // none. |
| 1533 SimulateGestureEvent(WebInputEvent::GestureTapUnconfirmed, | 1593 SimulateGestureEvent(WebInputEvent::GestureTapUnconfirmed, |
| 1534 blink::WebGestureDeviceTouchscreen); | 1594 blink::WebGestureDeviceTouchscreen); |
| 1535 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | 1595 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 1536 // This test will become invalid if GestureTap stops requiring an ack. | 1596 // This test will become invalid if GestureTap stops requiring an ack. |
| 1537 ASSERT_TRUE(WebInputEventTraits::ShouldBlockEventStream( | 1597 ASSERT_TRUE(WebInputEventTraits::ShouldBlockEventStream( |
| 1538 GetEventWithType(WebInputEvent::GestureTap))); | 1598 GetEventWithType(WebInputEvent::GestureTap))); |
| 1539 EXPECT_EQ(2, client_->in_flight_event_count()); | 1599 EXPECT_EQ(3, client_->in_flight_event_count()); |
| 1540 SendInputEventACK(WebInputEvent::GestureTap, | 1600 SendInputEventACK(WebInputEvent::GestureTap, |
| 1541 INPUT_EVENT_ACK_STATE_CONSUMED); | 1601 INPUT_EVENT_ACK_STATE_CONSUMED); |
| 1542 EXPECT_EQ(1, client_->in_flight_event_count()); | 1602 EXPECT_EQ(2, client_->in_flight_event_count()); |
| 1543 | 1603 |
| 1544 // This tap gesture is dropped, since the GestureTapUnconfirmed was turned | 1604 // This tap gesture is dropped, since the GestureTapUnconfirmed was turned |
| 1545 // into a tap. | 1605 // into a tap. |
| 1546 SimulateGestureEvent(WebInputEvent::GestureTap, | 1606 SimulateGestureEvent(WebInputEvent::GestureTap, |
| 1547 blink::WebGestureDeviceTouchscreen); | 1607 blink::WebGestureDeviceTouchscreen); |
| 1548 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); | 1608 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); |
| 1549 | 1609 |
| 1550 SendTouchEventACK(WebInputEvent::TouchEnd, INPUT_EVENT_ACK_STATE_CONSUMED, | 1610 SendTouchEventACK(WebInputEvent::TouchEnd, INPUT_EVENT_ACK_STATE_CONSUMED, |
| 1551 touch_release_event_id); | 1611 touch_release_event_id); |
| 1552 SendTouchEventACK(WebInputEvent::TouchStart, | 1612 SendTouchEventACK(WebInputEvent::TouchStart, |
| 1553 INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, | 1613 INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, |
| 1554 touch_press_event_id2); | 1614 touch_press_event_id2); |
| 1555 | 1615 |
| 1556 // Second Tap. | 1616 // Second Tap. |
| 1557 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | 1617 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); |
| 1558 SimulateGestureEvent(WebInputEvent::GestureTapDown, | 1618 SimulateGestureEvent(WebInputEvent::GestureTapDown, |
| 1559 blink::WebGestureDeviceTouchscreen); | 1619 blink::WebGestureDeviceTouchscreen); |
| 1560 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | 1620 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 1561 | 1621 |
| 1562 // Although the touch-action is now auto, the double tap still won't be | 1622 // Although the touch-action is now auto, the double tap still won't be |
| 1563 // dispatched, because the first tap occured when the touch-action was none. | 1623 // dispatched, because the first tap occured when the touch-action was none. |
| 1564 SimulateGestureEvent(WebInputEvent::GestureDoubleTap, | 1624 SimulateGestureEvent(WebInputEvent::GestureDoubleTap, |
| 1565 blink::WebGestureDeviceTouchscreen); | 1625 blink::WebGestureDeviceTouchscreen); |
| 1566 // This test will become invalid if GestureDoubleTap stops requiring an ack. | 1626 // This test will become invalid if GestureDoubleTap stops requiring an ack. |
| 1567 ASSERT_TRUE(WebInputEventTraits::ShouldBlockEventStream( | 1627 ASSERT_TRUE(WebInputEventTraits::ShouldBlockEventStream( |
| (...skipping 713 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2281 EXPECT_EQ(80, sent_event->data.flingStart.velocityY); | 2341 EXPECT_EQ(80, sent_event->data.flingStart.velocityY); |
| 2282 | 2342 |
| 2283 const WebGestureEvent* filter_event = | 2343 const WebGestureEvent* filter_event = |
| 2284 GetFilterWebInputEvent<WebGestureEvent>(); | 2344 GetFilterWebInputEvent<WebGestureEvent>(); |
| 2285 TestLocationInFilterEvent(filter_event, orig); | 2345 TestLocationInFilterEvent(filter_event, orig); |
| 2286 EXPECT_EQ(30, filter_event->data.flingStart.velocityX); | 2346 EXPECT_EQ(30, filter_event->data.flingStart.velocityX); |
| 2287 EXPECT_EQ(40, filter_event->data.flingStart.velocityY); | 2347 EXPECT_EQ(40, filter_event->data.flingStart.velocityY); |
| 2288 } | 2348 } |
| 2289 | 2349 |
| 2290 } // namespace content | 2350 } // namespace content |
| OLD | NEW |