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

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

Issue 2727683002: Fix unit tests to enable them testing with the rAF aligned touch input. (Closed)
Patch Set: Rebase 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 420 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 } 461 }
460 bool MouseEventCallback(const blink::WebMouseEvent& /* event */) { 462 bool MouseEventCallback(const blink::WebMouseEvent& /* event */) {
461 return handle_mouse_event_; 463 return handle_mouse_event_;
462 } 464 }
463 465
464 protected: 466 protected:
465 // testing::Test 467 // testing::Test
466 void SetUp() override { 468 void SetUp() override {
467 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); 469 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
468 command_line->AppendSwitch(switches::kValidateInputEventStream); 470 command_line->AppendSwitch(switches::kValidateInputEventStream);
471 feature_list_.InitFromCommandLine(
472 features::kRafAlignedTouchInputEvents.name, "");
469 473
470 browser_context_.reset(new TestBrowserContext()); 474 browser_context_.reset(new TestBrowserContext());
471 delegate_.reset(new MockRenderWidgetHostDelegate()); 475 delegate_.reset(new MockRenderWidgetHostDelegate());
472 process_ = new RenderWidgetHostProcess(browser_context_.get()); 476 process_ = new RenderWidgetHostProcess(browser_context_.get());
473 #if defined(USE_AURA) || defined(OS_MACOSX) 477 #if defined(USE_AURA) || defined(OS_MACOSX)
474 ImageTransportFactory::InitializeForUnitTests( 478 ImageTransportFactory::InitializeForUnitTests(
475 std::unique_ptr<ImageTransportFactory>( 479 std::unique_ptr<ImageTransportFactory>(
476 new NoTransportImageTransportFactory)); 480 new NoTransportImageTransportFactory));
477 #endif 481 #endif
478 #if defined(OS_ANDROID) 482 #if defined(OS_ANDROID)
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
664 double simulated_event_time_delta_seconds_; 668 double simulated_event_time_delta_seconds_;
665 669
666 #if defined(OS_ANDROID) 670 #if defined(OS_ANDROID)
667 MockGpuChannelEstablishFactory gpu_channel_factory_; 671 MockGpuChannelEstablishFactory gpu_channel_factory_;
668 #endif 672 #endif
669 673
670 private: 674 private:
671 SyntheticWebTouchEvent touch_event_; 675 SyntheticWebTouchEvent touch_event_;
672 676
673 TestBrowserThreadBundle thread_bundle_; 677 TestBrowserThreadBundle thread_bundle_;
678 base::test::ScopedFeatureList feature_list_;
674 679
675 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostTest); 680 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostTest);
676 }; 681 };
677 682
678 #if GTEST_HAS_PARAM_TEST 683 #if GTEST_HAS_PARAM_TEST
679 // RenderWidgetHostWithSourceTest ---------------------------------------------- 684 // RenderWidgetHostWithSourceTest ----------------------------------------------
680 685
681 // This is for tests that are to be run for all source devices. 686 // This is for tests that are to be run for all source devices.
682 class RenderWidgetHostWithSourceTest 687 class RenderWidgetHostWithSourceTest
683 : public RenderWidgetHostTest, 688 : public RenderWidgetHostTest,
(...skipping 613 matching lines...) Expand 10 before | Expand all | Expand 10 after
1297 1302
1298 // Mouse press becomes touch start which in turn becomes tap. 1303 // Mouse press becomes touch start which in turn becomes tap.
1299 SimulateMouseEvent(WebInputEvent::MouseDown, 10, 10, 0, true); 1304 SimulateMouseEvent(WebInputEvent::MouseDown, 10, 10, 0, true);
1300 EXPECT_EQ(WebInputEvent::TouchStart, host_->acked_touch_event_type()); 1305 EXPECT_EQ(WebInputEvent::TouchStart, host_->acked_touch_event_type());
1301 EXPECT_EQ("GestureTapDown", GetInputMessageTypes(process_)); 1306 EXPECT_EQ("GestureTapDown", GetInputMessageTypes(process_));
1302 1307
1303 // Mouse drag generates touch move, cancels tap and starts scroll. 1308 // Mouse drag generates touch move, cancels tap and starts scroll.
1304 SimulateMouseEvent(WebInputEvent::MouseMove, 10, 30, 0, true); 1309 SimulateMouseEvent(WebInputEvent::MouseMove, 10, 30, 0, true);
1305 EXPECT_EQ(WebInputEvent::TouchMove, host_->acked_touch_event_type()); 1310 EXPECT_EQ(WebInputEvent::TouchMove, host_->acked_touch_event_type());
1306 EXPECT_EQ( 1311 EXPECT_EQ(
1307 "GestureTapCancel GestureScrollBegin GestureScrollUpdate", 1312 "GestureTapCancel GestureScrollBegin TouchScrollStarted "
1313 "GestureScrollUpdate",
1308 GetInputMessageTypes(process_)); 1314 GetInputMessageTypes(process_));
1309 SendInputEventACK(WebInputEvent::GestureScrollUpdate, 1315 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
1310 INPUT_EVENT_ACK_STATE_CONSUMED); 1316 INPUT_EVENT_ACK_STATE_CONSUMED);
1311 EXPECT_EQ(0U, process_->sink().message_count()); 1317 EXPECT_EQ(0U, process_->sink().message_count());
1312 1318
1313 // Mouse drag with shift becomes pinch. 1319 // Mouse drag with shift becomes pinch.
1314 SimulateMouseEvent( 1320 SimulateMouseEvent(
1315 WebInputEvent::MouseMove, 10, 40, WebInputEvent::ShiftKey, true); 1321 WebInputEvent::MouseMove, 10, 40, WebInputEvent::ShiftKey, true);
1316 EXPECT_EQ(WebInputEvent::TouchMove, host_->acked_touch_event_type()); 1322 EXPECT_EQ(WebInputEvent::TouchMove, host_->acked_touch_event_type());
1317 EXPECT_EQ("GesturePinchBegin", 1323 EXPECT_EQ("GesturePinchBegin",
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1355 1361
1356 // Another mouse down continues scroll. 1362 // Another mouse down continues scroll.
1357 SimulateMouseEvent(WebInputEvent::MouseDown, 10, 80, 0, true); 1363 SimulateMouseEvent(WebInputEvent::MouseDown, 10, 80, 0, true);
1358 EXPECT_EQ(WebInputEvent::TouchStart, host_->acked_touch_event_type()); 1364 EXPECT_EQ(WebInputEvent::TouchStart, host_->acked_touch_event_type());
1359 EXPECT_EQ("GestureTapDown", GetInputMessageTypes(process_)); 1365 EXPECT_EQ("GestureTapDown", GetInputMessageTypes(process_));
1360 EXPECT_EQ(0U, process_->sink().message_count()); 1366 EXPECT_EQ(0U, process_->sink().message_count());
1361 1367
1362 SimulateMouseEvent(WebInputEvent::MouseMove, 10, 100, 0, true); 1368 SimulateMouseEvent(WebInputEvent::MouseMove, 10, 100, 0, true);
1363 EXPECT_EQ(WebInputEvent::TouchMove, host_->acked_touch_event_type()); 1369 EXPECT_EQ(WebInputEvent::TouchMove, host_->acked_touch_event_type());
1364 EXPECT_EQ( 1370 EXPECT_EQ(
1365 "GestureTapCancel GestureScrollBegin GestureScrollUpdate", 1371 "GestureTapCancel GestureScrollBegin TouchScrollStarted "
1372 "GestureScrollUpdate",
1366 GetInputMessageTypes(process_)); 1373 GetInputMessageTypes(process_));
1367 SendInputEventACK(WebInputEvent::GestureScrollUpdate, 1374 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
1368 INPUT_EVENT_ACK_STATE_CONSUMED); 1375 INPUT_EVENT_ACK_STATE_CONSUMED);
1369 EXPECT_EQ(0U, process_->sink().message_count()); 1376 EXPECT_EQ(0U, process_->sink().message_count());
1370 1377
1371 // Another pinch. 1378 // Another pinch.
1372 SimulateMouseEvent( 1379 SimulateMouseEvent(
1373 WebInputEvent::MouseMove, 10, 110, WebInputEvent::ShiftKey, true); 1380 WebInputEvent::MouseMove, 10, 110, WebInputEvent::ShiftKey, true);
1374 EXPECT_EQ(WebInputEvent::TouchMove, host_->acked_touch_event_type()); 1381 EXPECT_EQ(WebInputEvent::TouchMove, host_->acked_touch_event_type());
1375 EXPECT_EQ("GesturePinchBegin", 1382 EXPECT_EQ("GesturePinchBegin",
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1409 // Another touch. 1416 // Another touch.
1410 SimulateMouseEvent(WebInputEvent::MouseDown, 10, 10, 0, true); 1417 SimulateMouseEvent(WebInputEvent::MouseDown, 10, 10, 0, true);
1411 EXPECT_EQ(WebInputEvent::TouchStart, host_->acked_touch_event_type()); 1418 EXPECT_EQ(WebInputEvent::TouchStart, host_->acked_touch_event_type());
1412 EXPECT_EQ("GestureTapDown", GetInputMessageTypes(process_)); 1419 EXPECT_EQ("GestureTapDown", GetInputMessageTypes(process_));
1413 EXPECT_EQ(0U, process_->sink().message_count()); 1420 EXPECT_EQ(0U, process_->sink().message_count());
1414 1421
1415 // Scroll. 1422 // Scroll.
1416 SimulateMouseEvent(WebInputEvent::MouseMove, 10, 30, 0, true); 1423 SimulateMouseEvent(WebInputEvent::MouseMove, 10, 30, 0, true);
1417 EXPECT_EQ(WebInputEvent::TouchMove, host_->acked_touch_event_type()); 1424 EXPECT_EQ(WebInputEvent::TouchMove, host_->acked_touch_event_type());
1418 EXPECT_EQ( 1425 EXPECT_EQ(
1419 "GestureTapCancel GestureScrollBegin GestureScrollUpdate", 1426 "GestureTapCancel GestureScrollBegin TouchScrollStarted "
1427 "GestureScrollUpdate",
1420 GetInputMessageTypes(process_)); 1428 GetInputMessageTypes(process_));
1421 SendInputEventACK(WebInputEvent::GestureScrollUpdate, 1429 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
1422 INPUT_EVENT_ACK_STATE_CONSUMED); 1430 INPUT_EVENT_ACK_STATE_CONSUMED);
1423 1431
1424 // Turn off emulation during a scroll. 1432 // Turn off emulation during a scroll.
1425 host_->SetTouchEventEmulationEnabled( 1433 host_->SetTouchEventEmulationEnabled(
1426 false, ui::GestureProviderConfigType::GENERIC_MOBILE); 1434 false, ui::GestureProviderConfigType::GENERIC_MOBILE);
1427 EXPECT_EQ(WebInputEvent::TouchCancel, host_->acked_touch_event_type()); 1435 EXPECT_EQ(WebInputEvent::TouchCancel, host_->acked_touch_event_type());
1428 1436
1429 EXPECT_EQ("GestureScrollEnd", GetInputMessageTypes(process_)); 1437 EXPECT_EQ("GestureScrollEnd", GetInputMessageTypes(process_));
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
1605 const WebInputEvent* event = std::get<0>(params); 1613 const WebInputEvent* event = std::get<0>(params);
1606 ui::LatencyInfo latency_info = std::get<2>(params); 1614 ui::LatencyInfo latency_info = std::get<2>(params);
1607 1615
1608 EXPECT_TRUE(event->type() == expected_type); 1616 EXPECT_TRUE(event->type() == expected_type);
1609 EXPECT_TRUE(latency_info.FindLatency( 1617 EXPECT_TRUE(latency_info.FindLatency(
1610 ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, component_id, NULL)); 1618 ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, component_id, NULL));
1611 1619
1612 process->sink().ClearMessages(); 1620 process->sink().ClearMessages();
1613 } 1621 }
1614 1622
1623 void CheckLatencyInfoComponentInGestureScrollUpdate(
1624 RenderWidgetHostProcess* process,
1625 int64_t component_id) {
1626 EXPECT_EQ(process->sink().message_count(), 2U);
1627 const IPC::Message* message = process->sink().GetMessageAt(0);
1628 EXPECT_EQ(InputMsg_HandleInputEvent::ID, message->type());
1629 InputMsg_HandleInputEvent::Param params;
1630 EXPECT_TRUE(InputMsg_HandleInputEvent::Read(message, &params));
1631
1632 const WebInputEvent* event = std::get<0>(params);
1633 ui::LatencyInfo latency_info = std::get<2>(params);
1634
1635 EXPECT_TRUE(event->type() == WebInputEvent::TouchScrollStarted);
1636
1637 message = process->sink().GetMessageAt(1);
1638 EXPECT_EQ(InputMsg_HandleInputEvent::ID, message->type());
1639 EXPECT_TRUE(InputMsg_HandleInputEvent::Read(message, &params));
1640
1641 event = std::get<0>(params);
1642 latency_info = std::get<2>(params);
1643
1644 EXPECT_TRUE(event->type() == WebInputEvent::GestureScrollUpdate);
1645 EXPECT_TRUE(latency_info.FindLatency(
1646 ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, component_id, NULL));
1647
1648 process->sink().ClearMessages();
1649 }
1650
1615 // Tests that after input event passes through RWHI through ForwardXXXEvent() 1651 // Tests that after input event passes through RWHI through ForwardXXXEvent()
1616 // or ForwardXXXEventWithLatencyInfo(), LatencyInfo component 1652 // or ForwardXXXEventWithLatencyInfo(), LatencyInfo component
1617 // ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT will always present in the 1653 // ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT will always present in the
1618 // event's LatencyInfo. 1654 // event's LatencyInfo.
1619 TEST_F(RenderWidgetHostTest, InputEventRWHLatencyComponent) { 1655 TEST_F(RenderWidgetHostTest, InputEventRWHLatencyComponent) {
1620 host_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true)); 1656 host_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true));
1621 process_->sink().ClearMessages(); 1657 process_->sink().ClearMessages();
1622 1658
1623 // Tests RWHI::ForwardWheelEvent(). 1659 // Tests RWHI::ForwardWheelEvent().
1624 SimulateWheelEvent(-5, 0, 0, true); 1660 SimulateWheelEvent(-5, 0, 0, true);
(...skipping 23 matching lines...) Expand all
1648 // Tests RWHI::ForwardGestureEvent(). 1684 // Tests RWHI::ForwardGestureEvent().
1649 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, 1685 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
1650 blink::WebGestureDeviceTouchscreen); 1686 blink::WebGestureDeviceTouchscreen);
1651 CheckLatencyInfoComponentInMessage( 1687 CheckLatencyInfoComponentInMessage(
1652 process_, GetLatencyComponentId(), WebInputEvent::GestureScrollBegin); 1688 process_, GetLatencyComponentId(), WebInputEvent::GestureScrollBegin);
1653 1689
1654 // Tests RWHI::ForwardGestureEventWithLatencyInfo(). 1690 // Tests RWHI::ForwardGestureEventWithLatencyInfo().
1655 SimulateGestureEventWithLatencyInfo(WebInputEvent::GestureScrollUpdate, 1691 SimulateGestureEventWithLatencyInfo(WebInputEvent::GestureScrollUpdate,
1656 blink::WebGestureDeviceTouchscreen, 1692 blink::WebGestureDeviceTouchscreen,
1657 ui::LatencyInfo()); 1693 ui::LatencyInfo());
1658 CheckLatencyInfoComponentInMessage( 1694 CheckLatencyInfoComponentInGestureScrollUpdate(process_,
1659 process_, GetLatencyComponentId(), WebInputEvent::GestureScrollUpdate); 1695 GetLatencyComponentId());
1660 SendInputEventACK(WebInputEvent::GestureScrollUpdate, 1696 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
1661 INPUT_EVENT_ACK_STATE_CONSUMED); 1697 INPUT_EVENT_ACK_STATE_CONSUMED);
1662 1698
1663 // Tests RWHI::ForwardTouchEventWithLatencyInfo(). 1699 // Tests RWHI::ForwardTouchEventWithLatencyInfo().
1664 PressTouchPoint(0, 1); 1700 PressTouchPoint(0, 1);
1665 uint32_t touch_event_id = SendTouchEvent(); 1701 uint32_t touch_event_id = SendTouchEvent();
1666 InputEventAck ack(InputEventAckSource::COMPOSITOR_THREAD, 1702 InputEventAck ack(InputEventAckSource::COMPOSITOR_THREAD,
1667 WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED, 1703 WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED,
1668 touch_event_id); 1704 touch_event_id);
1669 host_->OnMessageReceived(InputHostMsg_HandleInputEvent_ACK(0, ack)); 1705 host_->OnMessageReceived(InputHostMsg_HandleInputEvent_ACK(0, ack));
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
1743 ui::LatencyInfo()); 1779 ui::LatencyInfo());
1744 1780
1745 1781
1746 // Tests RWHI::ForwardWheelEventWithLatencyInfo(). 1782 // Tests RWHI::ForwardWheelEventWithLatencyInfo().
1747 SimulateWheelEventWithLatencyInfo(-5, 0, 0, true, ui::LatencyInfo()); 1783 SimulateWheelEventWithLatencyInfo(-5, 0, 0, true, ui::LatencyInfo());
1748 1784
1749 ASSERT_FALSE(host_->input_router()->HasPendingEvents()); 1785 ASSERT_FALSE(host_->input_router()->HasPendingEvents());
1750 } 1786 }
1751 1787
1752 } // namespace content 1788 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698