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

Side by Side Diff: content/browser/renderer_host/render_widget_host_unittest.cc

Issue 2740613002: Reland fix unit tests to enable them testing with the rAF aligned touch input. (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include <memory> 8 #include <memory>
9 #include <tuple> 9 #include <tuple>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/location.h" 13 #include "base/location.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/run_loop.h" 15 #include "base/run_loop.h"
16 #include "base/single_thread_task_runner.h" 16 #include "base/single_thread_task_runner.h"
17 #include "base/test/scoped_feature_list.h"
17 #include "base/threading/thread_task_runner_handle.h" 18 #include "base/threading/thread_task_runner_handle.h"
18 #include "base/timer/timer.h" 19 #include "base/timer/timer.h"
19 #include "build/build_config.h" 20 #include "build/build_config.h"
20 #include "content/browser/gpu/compositor_util.h" 21 #include "content/browser/gpu/compositor_util.h"
21 #include "content/browser/renderer_host/input/input_router_impl.h" 22 #include "content/browser/renderer_host/input/input_router_impl.h"
22 #include "content/browser/renderer_host/render_widget_host_delegate.h" 23 #include "content/browser/renderer_host/render_widget_host_delegate.h"
23 #include "content/browser/renderer_host/render_widget_host_view_base.h" 24 #include "content/browser/renderer_host/render_widget_host_view_base.h"
24 #include "content/common/edit_command.h" 25 #include "content/common/edit_command.h"
25 #include "content/common/input/synthetic_web_input_event_builders.h" 26 #include "content/common/input/synthetic_web_input_event_builders.h"
26 #include "content/common/input_messages.h" 27 #include "content/common/input_messages.h"
27 #include "content/common/resize_params.h" 28 #include "content/common/resize_params.h"
28 #include "content/common/view_messages.h" 29 #include "content/common/view_messages.h"
30 #include "content/public/common/content_features.h"
29 #include "content/public/common/content_switches.h" 31 #include "content/public/common/content_switches.h"
30 #include "content/public/test/mock_render_process_host.h" 32 #include "content/public/test/mock_render_process_host.h"
31 #include "content/public/test/test_browser_context.h" 33 #include "content/public/test/test_browser_context.h"
32 #include "content/public/test/test_browser_thread_bundle.h" 34 #include "content/public/test/test_browser_thread_bundle.h"
33 #include "content/test/test_render_view_host.h" 35 #include "content/test/test_render_view_host.h"
34 #include "testing/gtest/include/gtest/gtest.h" 36 #include "testing/gtest/include/gtest/gtest.h"
35 #include "ui/display/screen.h" 37 #include "ui/display/screen.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"
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 } 459 }
458 bool MouseEventCallback(const blink::WebMouseEvent& /* event */) { 460 bool MouseEventCallback(const blink::WebMouseEvent& /* event */) {
459 return handle_mouse_event_; 461 return handle_mouse_event_;
460 } 462 }
461 463
462 protected: 464 protected:
463 // testing::Test 465 // testing::Test
464 void SetUp() override { 466 void SetUp() override {
465 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); 467 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
466 command_line->AppendSwitch(switches::kValidateInputEventStream); 468 command_line->AppendSwitch(switches::kValidateInputEventStream);
469 feature_list_.InitFromCommandLine(
470 features::kRafAlignedTouchInputEvents.name, "");
467 471
468 browser_context_.reset(new TestBrowserContext()); 472 browser_context_.reset(new TestBrowserContext());
469 delegate_.reset(new MockRenderWidgetHostDelegate()); 473 delegate_.reset(new MockRenderWidgetHostDelegate());
470 process_ = new RenderWidgetHostProcess(browser_context_.get()); 474 process_ = new RenderWidgetHostProcess(browser_context_.get());
471 #if defined(USE_AURA) || defined(OS_MACOSX) 475 #if defined(USE_AURA) || defined(OS_MACOSX)
472 ImageTransportFactory::InitializeForUnitTests( 476 ImageTransportFactory::InitializeForUnitTests(
473 std::unique_ptr<ImageTransportFactory>( 477 std::unique_ptr<ImageTransportFactory>(
474 new NoTransportImageTransportFactory)); 478 new NoTransportImageTransportFactory));
475 #endif 479 #endif
476 #if defined(OS_ANDROID) 480 #if defined(OS_ANDROID)
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
653 std::unique_ptr<display::Screen> screen_; 657 std::unique_ptr<display::Screen> screen_;
654 bool handle_key_press_event_; 658 bool handle_key_press_event_;
655 bool handle_mouse_event_; 659 bool handle_mouse_event_;
656 double last_simulated_event_time_seconds_; 660 double last_simulated_event_time_seconds_;
657 double simulated_event_time_delta_seconds_; 661 double simulated_event_time_delta_seconds_;
658 662
659 private: 663 private:
660 SyntheticWebTouchEvent touch_event_; 664 SyntheticWebTouchEvent touch_event_;
661 665
662 TestBrowserThreadBundle thread_bundle_; 666 TestBrowserThreadBundle thread_bundle_;
667 base::test::ScopedFeatureList feature_list_;
663 668
664 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostTest); 669 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostTest);
665 }; 670 };
666 671
667 #if GTEST_HAS_PARAM_TEST 672 #if GTEST_HAS_PARAM_TEST
668 // RenderWidgetHostWithSourceTest ---------------------------------------------- 673 // RenderWidgetHostWithSourceTest ----------------------------------------------
669 674
670 // This is for tests that are to be run for all source devices. 675 // This is for tests that are to be run for all source devices.
671 class RenderWidgetHostWithSourceTest 676 class RenderWidgetHostWithSourceTest
672 : public RenderWidgetHostTest, 677 : public RenderWidgetHostTest,
(...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after
1319 1324
1320 // Mouse press becomes touch start which in turn becomes tap. 1325 // Mouse press becomes touch start which in turn becomes tap.
1321 SimulateMouseEvent(WebInputEvent::MouseDown, 10, 10, 0, true); 1326 SimulateMouseEvent(WebInputEvent::MouseDown, 10, 10, 0, true);
1322 EXPECT_EQ(WebInputEvent::TouchStart, host_->acked_touch_event_type()); 1327 EXPECT_EQ(WebInputEvent::TouchStart, host_->acked_touch_event_type());
1323 EXPECT_EQ("GestureTapDown", GetInputMessageTypes(process_)); 1328 EXPECT_EQ("GestureTapDown", GetInputMessageTypes(process_));
1324 1329
1325 // Mouse drag generates touch move, cancels tap and starts scroll. 1330 // Mouse drag generates touch move, cancels tap and starts scroll.
1326 SimulateMouseEvent(WebInputEvent::MouseMove, 10, 30, 0, true); 1331 SimulateMouseEvent(WebInputEvent::MouseMove, 10, 30, 0, true);
1327 EXPECT_EQ(WebInputEvent::TouchMove, host_->acked_touch_event_type()); 1332 EXPECT_EQ(WebInputEvent::TouchMove, host_->acked_touch_event_type());
1328 EXPECT_EQ( 1333 EXPECT_EQ(
1329 "GestureTapCancel GestureScrollBegin GestureScrollUpdate", 1334 "GestureTapCancel GestureScrollBegin TouchScrollStarted "
1335 "GestureScrollUpdate",
1330 GetInputMessageTypes(process_)); 1336 GetInputMessageTypes(process_));
1331 SendInputEventACK(WebInputEvent::GestureScrollUpdate, 1337 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
1332 INPUT_EVENT_ACK_STATE_CONSUMED); 1338 INPUT_EVENT_ACK_STATE_CONSUMED);
1333 EXPECT_EQ(0U, process_->sink().message_count()); 1339 EXPECT_EQ(0U, process_->sink().message_count());
1334 1340
1335 // Mouse drag with shift becomes pinch. 1341 // Mouse drag with shift becomes pinch.
1336 SimulateMouseEvent( 1342 SimulateMouseEvent(
1337 WebInputEvent::MouseMove, 10, 40, WebInputEvent::ShiftKey, true); 1343 WebInputEvent::MouseMove, 10, 40, WebInputEvent::ShiftKey, true);
1338 EXPECT_EQ(WebInputEvent::TouchMove, host_->acked_touch_event_type()); 1344 EXPECT_EQ(WebInputEvent::TouchMove, host_->acked_touch_event_type());
1339 EXPECT_EQ("GesturePinchBegin", 1345 EXPECT_EQ("GesturePinchBegin",
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1377 1383
1378 // Another mouse down continues scroll. 1384 // Another mouse down continues scroll.
1379 SimulateMouseEvent(WebInputEvent::MouseDown, 10, 80, 0, true); 1385 SimulateMouseEvent(WebInputEvent::MouseDown, 10, 80, 0, true);
1380 EXPECT_EQ(WebInputEvent::TouchStart, host_->acked_touch_event_type()); 1386 EXPECT_EQ(WebInputEvent::TouchStart, host_->acked_touch_event_type());
1381 EXPECT_EQ("GestureTapDown", GetInputMessageTypes(process_)); 1387 EXPECT_EQ("GestureTapDown", GetInputMessageTypes(process_));
1382 EXPECT_EQ(0U, process_->sink().message_count()); 1388 EXPECT_EQ(0U, process_->sink().message_count());
1383 1389
1384 SimulateMouseEvent(WebInputEvent::MouseMove, 10, 100, 0, true); 1390 SimulateMouseEvent(WebInputEvent::MouseMove, 10, 100, 0, true);
1385 EXPECT_EQ(WebInputEvent::TouchMove, host_->acked_touch_event_type()); 1391 EXPECT_EQ(WebInputEvent::TouchMove, host_->acked_touch_event_type());
1386 EXPECT_EQ( 1392 EXPECT_EQ(
1387 "GestureTapCancel GestureScrollBegin GestureScrollUpdate", 1393 "GestureTapCancel GestureScrollBegin TouchScrollStarted "
1394 "GestureScrollUpdate",
1388 GetInputMessageTypes(process_)); 1395 GetInputMessageTypes(process_));
1389 SendInputEventACK(WebInputEvent::GestureScrollUpdate, 1396 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
1390 INPUT_EVENT_ACK_STATE_CONSUMED); 1397 INPUT_EVENT_ACK_STATE_CONSUMED);
1391 EXPECT_EQ(0U, process_->sink().message_count()); 1398 EXPECT_EQ(0U, process_->sink().message_count());
1392 1399
1393 // Another pinch. 1400 // Another pinch.
1394 SimulateMouseEvent( 1401 SimulateMouseEvent(
1395 WebInputEvent::MouseMove, 10, 110, WebInputEvent::ShiftKey, true); 1402 WebInputEvent::MouseMove, 10, 110, WebInputEvent::ShiftKey, true);
1396 EXPECT_EQ(WebInputEvent::TouchMove, host_->acked_touch_event_type()); 1403 EXPECT_EQ(WebInputEvent::TouchMove, host_->acked_touch_event_type());
1397 EXPECT_EQ("GesturePinchBegin", 1404 EXPECT_EQ("GesturePinchBegin",
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1431 // Another touch. 1438 // Another touch.
1432 SimulateMouseEvent(WebInputEvent::MouseDown, 10, 10, 0, true); 1439 SimulateMouseEvent(WebInputEvent::MouseDown, 10, 10, 0, true);
1433 EXPECT_EQ(WebInputEvent::TouchStart, host_->acked_touch_event_type()); 1440 EXPECT_EQ(WebInputEvent::TouchStart, host_->acked_touch_event_type());
1434 EXPECT_EQ("GestureTapDown", GetInputMessageTypes(process_)); 1441 EXPECT_EQ("GestureTapDown", GetInputMessageTypes(process_));
1435 EXPECT_EQ(0U, process_->sink().message_count()); 1442 EXPECT_EQ(0U, process_->sink().message_count());
1436 1443
1437 // Scroll. 1444 // Scroll.
1438 SimulateMouseEvent(WebInputEvent::MouseMove, 10, 30, 0, true); 1445 SimulateMouseEvent(WebInputEvent::MouseMove, 10, 30, 0, true);
1439 EXPECT_EQ(WebInputEvent::TouchMove, host_->acked_touch_event_type()); 1446 EXPECT_EQ(WebInputEvent::TouchMove, host_->acked_touch_event_type());
1440 EXPECT_EQ( 1447 EXPECT_EQ(
1441 "GestureTapCancel GestureScrollBegin GestureScrollUpdate", 1448 "GestureTapCancel GestureScrollBegin TouchScrollStarted "
1449 "GestureScrollUpdate",
1442 GetInputMessageTypes(process_)); 1450 GetInputMessageTypes(process_));
1443 SendInputEventACK(WebInputEvent::GestureScrollUpdate, 1451 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
1444 INPUT_EVENT_ACK_STATE_CONSUMED); 1452 INPUT_EVENT_ACK_STATE_CONSUMED);
1445 1453
1446 // Turn off emulation during a scroll. 1454 // Turn off emulation during a scroll.
1447 host_->SetTouchEventEmulationEnabled( 1455 host_->SetTouchEventEmulationEnabled(
1448 false, ui::GestureProviderConfigType::GENERIC_MOBILE); 1456 false, ui::GestureProviderConfigType::GENERIC_MOBILE);
1449 EXPECT_EQ(WebInputEvent::TouchCancel, host_->acked_touch_event_type()); 1457 EXPECT_EQ(WebInputEvent::TouchCancel, host_->acked_touch_event_type());
1450 1458
1451 EXPECT_EQ("GestureScrollEnd", GetInputMessageTypes(process_)); 1459 EXPECT_EQ("GestureScrollEnd", GetInputMessageTypes(process_));
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
1627 const WebInputEvent* event = std::get<0>(params); 1635 const WebInputEvent* event = std::get<0>(params);
1628 ui::LatencyInfo latency_info = std::get<2>(params); 1636 ui::LatencyInfo latency_info = std::get<2>(params);
1629 1637
1630 EXPECT_TRUE(event->type() == expected_type); 1638 EXPECT_TRUE(event->type() == expected_type);
1631 EXPECT_TRUE(latency_info.FindLatency( 1639 EXPECT_TRUE(latency_info.FindLatency(
1632 ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, component_id, NULL)); 1640 ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, component_id, NULL));
1633 1641
1634 process->sink().ClearMessages(); 1642 process->sink().ClearMessages();
1635 } 1643 }
1636 1644
1645 void CheckLatencyInfoComponentInGestureScrollUpdate(
1646 RenderWidgetHostProcess* process,
1647 int64_t component_id) {
1648 EXPECT_EQ(process->sink().message_count(), 2U);
1649 const IPC::Message* message = process->sink().GetMessageAt(0);
1650 EXPECT_EQ(InputMsg_HandleInputEvent::ID, message->type());
1651 InputMsg_HandleInputEvent::Param params;
1652 EXPECT_TRUE(InputMsg_HandleInputEvent::Read(message, &params));
1653
1654 const WebInputEvent* event = std::get<0>(params);
1655 ui::LatencyInfo latency_info = std::get<2>(params);
1656
1657 EXPECT_TRUE(event->type() == WebInputEvent::TouchScrollStarted);
1658
1659 message = process->sink().GetMessageAt(1);
1660 EXPECT_EQ(InputMsg_HandleInputEvent::ID, message->type());
1661 EXPECT_TRUE(InputMsg_HandleInputEvent::Read(message, &params));
1662
1663 event = std::get<0>(params);
1664 latency_info = std::get<2>(params);
1665
1666 EXPECT_TRUE(event->type() == WebInputEvent::GestureScrollUpdate);
1667 EXPECT_TRUE(latency_info.FindLatency(
1668 ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, component_id, NULL));
1669
1670 process->sink().ClearMessages();
1671 }
1672
1637 // Tests that after input event passes through RWHI through ForwardXXXEvent() 1673 // Tests that after input event passes through RWHI through ForwardXXXEvent()
1638 // or ForwardXXXEventWithLatencyInfo(), LatencyInfo component 1674 // or ForwardXXXEventWithLatencyInfo(), LatencyInfo component
1639 // ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT will always present in the 1675 // ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT will always present in the
1640 // event's LatencyInfo. 1676 // event's LatencyInfo.
1641 TEST_F(RenderWidgetHostTest, InputEventRWHLatencyComponent) { 1677 TEST_F(RenderWidgetHostTest, InputEventRWHLatencyComponent) {
1642 host_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true)); 1678 host_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true));
1643 process_->sink().ClearMessages(); 1679 process_->sink().ClearMessages();
1644 1680
1645 // Tests RWHI::ForwardWheelEvent(). 1681 // Tests RWHI::ForwardWheelEvent().
1646 SimulateWheelEvent(-5, 0, 0, true); 1682 SimulateWheelEvent(-5, 0, 0, true);
(...skipping 23 matching lines...) Expand all
1670 // Tests RWHI::ForwardGestureEvent(). 1706 // Tests RWHI::ForwardGestureEvent().
1671 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, 1707 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
1672 blink::WebGestureDeviceTouchscreen); 1708 blink::WebGestureDeviceTouchscreen);
1673 CheckLatencyInfoComponentInMessage( 1709 CheckLatencyInfoComponentInMessage(
1674 process_, GetLatencyComponentId(), WebInputEvent::GestureScrollBegin); 1710 process_, GetLatencyComponentId(), WebInputEvent::GestureScrollBegin);
1675 1711
1676 // Tests RWHI::ForwardGestureEventWithLatencyInfo(). 1712 // Tests RWHI::ForwardGestureEventWithLatencyInfo().
1677 SimulateGestureEventWithLatencyInfo(WebInputEvent::GestureScrollUpdate, 1713 SimulateGestureEventWithLatencyInfo(WebInputEvent::GestureScrollUpdate,
1678 blink::WebGestureDeviceTouchscreen, 1714 blink::WebGestureDeviceTouchscreen,
1679 ui::LatencyInfo()); 1715 ui::LatencyInfo());
1680 CheckLatencyInfoComponentInMessage( 1716 CheckLatencyInfoComponentInGestureScrollUpdate(process_,
1681 process_, GetLatencyComponentId(), WebInputEvent::GestureScrollUpdate); 1717 GetLatencyComponentId());
1682 SendInputEventACK(WebInputEvent::GestureScrollUpdate, 1718 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
1683 INPUT_EVENT_ACK_STATE_CONSUMED); 1719 INPUT_EVENT_ACK_STATE_CONSUMED);
1684 1720
1685 // Tests RWHI::ForwardTouchEventWithLatencyInfo(). 1721 // Tests RWHI::ForwardTouchEventWithLatencyInfo().
1686 PressTouchPoint(0, 1); 1722 PressTouchPoint(0, 1);
1687 uint32_t touch_event_id = SendTouchEvent(); 1723 uint32_t touch_event_id = SendTouchEvent();
1688 InputEventAck ack(InputEventAckSource::COMPOSITOR_THREAD, 1724 InputEventAck ack(InputEventAckSource::COMPOSITOR_THREAD,
1689 WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED, 1725 WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED,
1690 touch_event_id); 1726 touch_event_id);
1691 host_->OnMessageReceived(InputHostMsg_HandleInputEvent_ACK(0, ack)); 1727 host_->OnMessageReceived(InputHostMsg_HandleInputEvent_ACK(0, ack));
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
1765 ui::LatencyInfo()); 1801 ui::LatencyInfo());
1766 1802
1767 1803
1768 // Tests RWHI::ForwardWheelEventWithLatencyInfo(). 1804 // Tests RWHI::ForwardWheelEventWithLatencyInfo().
1769 SimulateWheelEventWithLatencyInfo(-5, 0, 0, true, ui::LatencyInfo()); 1805 SimulateWheelEventWithLatencyInfo(-5, 0, 0, true, ui::LatencyInfo());
1770 1806
1771 ASSERT_FALSE(host_->input_router()->HasPendingEvents()); 1807 ASSERT_FALSE(host_->input_router()->HasPendingEvents());
1772 } 1808 }
1773 1809
1774 } // namespace content 1810 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698