| 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(bool raf_aligned_touch = false) { |
| 148 if (raf_aligned_touch) { |
| 149 feature_list_.InitFromCommandLine( |
| 150 features::kRafAlignedTouchInputEvents.name, ""); |
| 151 } else { |
| 152 feature_list_.InitFromCommandLine( |
| 153 "", features::kRafAlignedTouchInputEvents.name); |
| 154 } |
| 155 } |
| 156 |
| 146 ~InputRouterImplTest() override {} | 157 ~InputRouterImplTest() override {} |
| 147 | 158 |
| 148 protected: | 159 protected: |
| 149 // testing::Test | 160 // testing::Test |
| 150 void SetUp() override { | 161 void SetUp() override { |
| 151 browser_context_.reset(new TestBrowserContext()); | 162 browser_context_.reset(new TestBrowserContext()); |
| 152 process_.reset(new MockRenderProcessHost(browser_context_.get())); | 163 process_.reset(new MockRenderProcessHost(browser_context_.get())); |
| 153 client_.reset(new MockInputRouterClient()); | 164 client_.reset(new MockInputRouterClient()); |
| 154 ack_handler_.reset(new MockInputAckHandler()); | 165 ack_handler_.reset(new MockInputAckHandler()); |
| 155 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 166 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 InputRouterImpl::Config config_; | 359 InputRouterImpl::Config config_; |
| 349 std::unique_ptr<MockRenderProcessHost> process_; | 360 std::unique_ptr<MockRenderProcessHost> process_; |
| 350 std::unique_ptr<MockInputRouterClient> client_; | 361 std::unique_ptr<MockInputRouterClient> client_; |
| 351 std::unique_ptr<MockInputAckHandler> ack_handler_; | 362 std::unique_ptr<MockInputAckHandler> ack_handler_; |
| 352 std::unique_ptr<InputRouterImpl> input_router_; | 363 std::unique_ptr<InputRouterImpl> input_router_; |
| 353 | 364 |
| 354 private: | 365 private: |
| 355 base::MessageLoopForUI message_loop_; | 366 base::MessageLoopForUI message_loop_; |
| 356 SyntheticWebTouchEvent touch_event_; | 367 SyntheticWebTouchEvent touch_event_; |
| 357 | 368 |
| 369 base::test::ScopedFeatureList feature_list_; |
| 358 std::unique_ptr<TestBrowserContext> browser_context_; | 370 std::unique_ptr<TestBrowserContext> browser_context_; |
| 359 }; | 371 }; |
| 360 | 372 |
| 373 class InputRouterImplRafAlignedTouchEnabledTest : public InputRouterImplTest { |
| 374 public: |
| 375 InputRouterImplRafAlignedTouchEnabledTest() : InputRouterImplTest(true) {} |
| 376 }; |
| 377 |
| 361 TEST_F(InputRouterImplTest, CoalescesRangeSelection) { | 378 TEST_F(InputRouterImplTest, CoalescesRangeSelection) { |
| 362 input_router_->SendInput(std::unique_ptr<IPC::Message>( | 379 input_router_->SendInput(std::unique_ptr<IPC::Message>( |
| 363 new InputMsg_SelectRange(0, gfx::Point(1, 2), gfx::Point(3, 4)))); | 380 new InputMsg_SelectRange(0, gfx::Point(1, 2), gfx::Point(3, 4)))); |
| 364 ExpectIPCMessageWithArg2<InputMsg_SelectRange>( | 381 ExpectIPCMessageWithArg2<InputMsg_SelectRange>( |
| 365 process_->sink().GetMessageAt(0), | 382 process_->sink().GetMessageAt(0), |
| 366 gfx::Point(1, 2), | 383 gfx::Point(1, 2), |
| 367 gfx::Point(3, 4)); | 384 gfx::Point(3, 4)); |
| 368 EXPECT_EQ(1u, GetSentMessageCountAndResetSink()); | 385 EXPECT_EQ(1u, GetSentMessageCountAndResetSink()); |
| 369 | 386 |
| 370 // Send two more messages without acking. | 387 // Send two more messages without acking. |
| (...skipping 953 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1324 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); | 1341 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); |
| 1325 SendTouchEventACK(WebInputEvent::TouchMove, INPUT_EVENT_ACK_STATE_CONSUMED, | 1342 SendTouchEventACK(WebInputEvent::TouchMove, INPUT_EVENT_ACK_STATE_CONSUMED, |
| 1326 touch_move_event_id); | 1343 touch_move_event_id); |
| 1327 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); | 1344 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); |
| 1328 | 1345 |
| 1329 // End the touch sequence. | 1346 // End the touch sequence. |
| 1330 ReleaseTouchPoint(0); | 1347 ReleaseTouchPoint(0); |
| 1331 uint32_t touch_release_event_id = SendTouchEvent(); | 1348 uint32_t touch_release_event_id = SendTouchEvent(); |
| 1332 SendTouchEventACK(WebInputEvent::TouchEnd, INPUT_EVENT_ACK_STATE_CONSUMED, | 1349 SendTouchEventACK(WebInputEvent::TouchEnd, INPUT_EVENT_ACK_STATE_CONSUMED, |
| 1333 touch_release_event_id); | 1350 touch_release_event_id); |
| 1334 EXPECT_FALSE(TouchEventTimeoutEnabled()); | 1351 EXPECT_TRUE(TouchEventTimeoutEnabled()); |
| 1335 ack_handler_->GetAndResetAckCount(); | 1352 ack_handler_->GetAndResetAckCount(); |
| 1336 GetSentMessageCountAndResetSink(); | 1353 GetSentMessageCountAndResetSink(); |
| 1337 | 1354 |
| 1338 // Start another touch sequence. This should restore the touch timeout. | 1355 // Start another touch sequence. This should restore the touch timeout. |
| 1339 PressTouchPoint(1, 1); | 1356 PressTouchPoint(1, 1); |
| 1340 SendTouchEvent(); | 1357 SendTouchEvent(); |
| 1341 EXPECT_TRUE(TouchEventTimeoutEnabled()); | 1358 EXPECT_TRUE(TouchEventTimeoutEnabled()); |
| 1342 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | 1359 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 1343 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount()); | 1360 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount()); |
| 1344 | 1361 |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1498 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, | 1515 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, |
| 1499 blink::WebGestureDeviceTouchscreen); | 1516 blink::WebGestureDeviceTouchscreen); |
| 1500 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | 1517 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 1501 SimulateGestureEvent(WebInputEvent::GestureScrollEnd, | 1518 SimulateGestureEvent(WebInputEvent::GestureScrollEnd, |
| 1502 blink::WebGestureDeviceTouchscreen); | 1519 blink::WebGestureDeviceTouchscreen); |
| 1503 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | 1520 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 1504 } | 1521 } |
| 1505 | 1522 |
| 1506 // Test that the double tap gesture depends on the touch action of the first | 1523 // Test that the double tap gesture depends on the touch action of the first |
| 1507 // tap. | 1524 // tap. |
| 1525 TEST_F(InputRouterImplRafAlignedTouchEnabledTest, |
| 1526 DoubleTapGestureDependsOnFirstTap) { |
| 1527 OnHasTouchEventHandlers(true); |
| 1528 |
| 1529 // Sequence 1. |
| 1530 PressTouchPoint(1, 1); |
| 1531 uint32_t touch_press_event_id1 = SendTouchEvent(); |
| 1532 OnSetTouchAction(TOUCH_ACTION_NONE); |
| 1533 SendTouchEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED, |
| 1534 touch_press_event_id1); |
| 1535 |
| 1536 ReleaseTouchPoint(0); |
| 1537 uint32_t touch_release_event_id = SendTouchEvent(); |
| 1538 |
| 1539 // Sequence 2 |
| 1540 PressTouchPoint(1, 1); |
| 1541 uint32_t touch_press_event_id2 = SendTouchEvent(); |
| 1542 |
| 1543 // First tap. |
| 1544 EXPECT_EQ(3U, GetSentMessageCountAndResetSink()); |
| 1545 SimulateGestureEvent(WebInputEvent::GestureTapDown, |
| 1546 blink::WebGestureDeviceTouchscreen); |
| 1547 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 1548 |
| 1549 // The GestureTapUnconfirmed is converted into a tap, as the touch action is |
| 1550 // none. |
| 1551 SimulateGestureEvent(WebInputEvent::GestureTapUnconfirmed, |
| 1552 blink::WebGestureDeviceTouchscreen); |
| 1553 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 1554 // This test will become invalid if GestureTap stops requiring an ack. |
| 1555 ASSERT_TRUE(WebInputEventTraits::ShouldBlockEventStream( |
| 1556 GetEventWithType(WebInputEvent::GestureTap))); |
| 1557 EXPECT_EQ(3, client_->in_flight_event_count()); |
| 1558 SendInputEventACK(WebInputEvent::GestureTap, INPUT_EVENT_ACK_STATE_CONSUMED); |
| 1559 EXPECT_EQ(2, client_->in_flight_event_count()); |
| 1560 |
| 1561 // This tap gesture is dropped, since the GestureTapUnconfirmed was turned |
| 1562 // into a tap. |
| 1563 SimulateGestureEvent(WebInputEvent::GestureTap, |
| 1564 blink::WebGestureDeviceTouchscreen); |
| 1565 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); |
| 1566 |
| 1567 SendTouchEventACK(WebInputEvent::TouchEnd, INPUT_EVENT_ACK_STATE_CONSUMED, |
| 1568 touch_release_event_id); |
| 1569 SendTouchEventACK(WebInputEvent::TouchStart, |
| 1570 INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, |
| 1571 touch_press_event_id2); |
| 1572 |
| 1573 // Second Tap. |
| 1574 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); |
| 1575 SimulateGestureEvent(WebInputEvent::GestureTapDown, |
| 1576 blink::WebGestureDeviceTouchscreen); |
| 1577 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 1578 |
| 1579 // Although the touch-action is now auto, the double tap still won't be |
| 1580 // dispatched, because the first tap occured when the touch-action was none. |
| 1581 SimulateGestureEvent(WebInputEvent::GestureDoubleTap, |
| 1582 blink::WebGestureDeviceTouchscreen); |
| 1583 // This test will become invalid if GestureDoubleTap stops requiring an ack. |
| 1584 ASSERT_TRUE(WebInputEventTraits::ShouldBlockEventStream( |
| 1585 GetEventWithType(WebInputEvent::GestureDoubleTap))); |
| 1586 EXPECT_EQ(1, client_->in_flight_event_count()); |
| 1587 SendInputEventACK(WebInputEvent::GestureTap, INPUT_EVENT_ACK_STATE_CONSUMED); |
| 1588 EXPECT_EQ(0, client_->in_flight_event_count()); |
| 1589 } |
| 1590 |
| 1591 // Test that the double tap gesture depends on the touch action of the first |
| 1592 // tap. |
| 1508 TEST_F(InputRouterImplTest, DoubleTapGestureDependsOnFirstTap) { | 1593 TEST_F(InputRouterImplTest, DoubleTapGestureDependsOnFirstTap) { |
| 1509 OnHasTouchEventHandlers(true); | 1594 OnHasTouchEventHandlers(true); |
| 1510 | 1595 |
| 1511 // Sequence 1. | 1596 // Sequence 1. |
| 1512 PressTouchPoint(1, 1); | 1597 PressTouchPoint(1, 1); |
| 1513 uint32_t touch_press_event_id1 = SendTouchEvent(); | 1598 uint32_t touch_press_event_id1 = SendTouchEvent(); |
| 1514 OnSetTouchAction(TOUCH_ACTION_NONE); | 1599 OnSetTouchAction(TOUCH_ACTION_NONE); |
| 1515 SendTouchEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED, | 1600 SendTouchEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED, |
| 1516 touch_press_event_id1); | 1601 touch_press_event_id1); |
| 1517 | 1602 |
| (...skipping 763 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2281 EXPECT_EQ(80, sent_event->data.flingStart.velocityY); | 2366 EXPECT_EQ(80, sent_event->data.flingStart.velocityY); |
| 2282 | 2367 |
| 2283 const WebGestureEvent* filter_event = | 2368 const WebGestureEvent* filter_event = |
| 2284 GetFilterWebInputEvent<WebGestureEvent>(); | 2369 GetFilterWebInputEvent<WebGestureEvent>(); |
| 2285 TestLocationInFilterEvent(filter_event, orig); | 2370 TestLocationInFilterEvent(filter_event, orig); |
| 2286 EXPECT_EQ(30, filter_event->data.flingStart.velocityX); | 2371 EXPECT_EQ(30, filter_event->data.flingStart.velocityX); |
| 2287 EXPECT_EQ(40, filter_event->data.flingStart.velocityY); | 2372 EXPECT_EQ(40, filter_event->data.flingStart.velocityY); |
| 2288 } | 2373 } |
| 2289 | 2374 |
| 2290 } // namespace content | 2375 } // namespace content |
| OLD | NEW |