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

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

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

Powered by Google App Engine
This is Rietveld 408576698