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

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

Issue 569653002: Add input coordinate information to InputLatency (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use uint32 instead of size_t to unbreak IPC. Created 6 years, 2 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 "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/bind.h" 6 #include "base/bind.h"
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/memory/shared_memory.h" 9 #include "base/memory/shared_memory.h"
10 #include "base/timer/timer.h" 10 #include "base/timer/timer.h"
(...skipping 1316 matching lines...) Expand 10 before | Expand all | Expand 10 after
1327 } 1327 }
1328 1328
1329 TEST_F(RenderWidgetHostTest, InputRouterReceivesHasTouchEventHandlers) { 1329 TEST_F(RenderWidgetHostTest, InputRouterReceivesHasTouchEventHandlers) {
1330 host_->SetupForInputRouterTest(); 1330 host_->SetupForInputRouterTest();
1331 1331
1332 host_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true)); 1332 host_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true));
1333 1333
1334 EXPECT_TRUE(host_->mock_input_router()->message_received_); 1334 EXPECT_TRUE(host_->mock_input_router()->message_received_);
1335 } 1335 }
1336 1336
1337 ui::LatencyInfo GetLatencyInfoFromInputEvent(RenderWidgetHostProcess* process) {
1338 const IPC::Message* message = process->sink().GetUniqueMessageMatching(
1339 InputMsg_HandleInputEvent::ID);
1340 EXPECT_TRUE(message);
1341 InputMsg_HandleInputEvent::Param params;
1342 EXPECT_TRUE(InputMsg_HandleInputEvent::Read(message, &params));
1343 process->sink().ClearMessages();
1344 return params.b;
1345 }
1337 1346
1338 void CheckLatencyInfoComponentInMessage(RenderWidgetHostProcess* process, 1347 void CheckLatencyInfoComponentInMessage(RenderWidgetHostProcess* process,
1339 int64 component_id, 1348 int64 component_id,
1340 WebInputEvent::Type input_type) { 1349 WebInputEvent::Type input_type) {
1341 const IPC::Message* message = process->sink().GetUniqueMessageMatching( 1350 ui::LatencyInfo latency_info = GetLatencyInfoFromInputEvent(process);
1342 InputMsg_HandleInputEvent::ID);
1343 ASSERT_TRUE(message);
1344 InputMsg_HandleInputEvent::Param params;
1345 EXPECT_TRUE(InputMsg_HandleInputEvent::Read(message, &params));
1346 ui::LatencyInfo latency_info = params.b;
1347 EXPECT_TRUE(latency_info.FindLatency( 1351 EXPECT_TRUE(latency_info.FindLatency(
1348 ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, 1352 ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT,
1349 component_id, 1353 component_id,
1350 NULL)); 1354 NULL));
1351 process->sink().ClearMessages();
1352 } 1355 }
1353 1356
1354 // Tests that after input event passes through RWHI through ForwardXXXEvent() 1357 // Tests that after input event passes through RWHI through ForwardXXXEvent()
1355 // or ForwardXXXEventWithLatencyInfo(), LatencyInfo component 1358 // or ForwardXXXEventWithLatencyInfo(), LatencyInfo component
1356 // ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT will always present in the 1359 // ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT will always present in the
1357 // event's LatencyInfo. 1360 // event's LatencyInfo.
1358 TEST_F(RenderWidgetHostTest, InputEventRWHLatencyComponent) { 1361 TEST_F(RenderWidgetHostTest, InputEventRWHLatencyComponent) {
1359 host_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true)); 1362 host_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true));
1360 process_->sink().ClearMessages(); 1363 process_->sink().ClearMessages();
1361 1364
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1400 INPUT_EVENT_ACK_STATE_CONSUMED); 1403 INPUT_EVENT_ACK_STATE_CONSUMED);
1401 1404
1402 // Tests RWHI::ForwardTouchEventWithLatencyInfo(). 1405 // Tests RWHI::ForwardTouchEventWithLatencyInfo().
1403 PressTouchPoint(0, 1); 1406 PressTouchPoint(0, 1);
1404 SendTouchEvent(); 1407 SendTouchEvent();
1405 CheckLatencyInfoComponentInMessage( 1408 CheckLatencyInfoComponentInMessage(
1406 process_, GetLatencyComponentId(), WebInputEvent::TouchStart); 1409 process_, GetLatencyComponentId(), WebInputEvent::TouchStart);
1407 SendInputEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED); 1410 SendInputEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED);
1408 } 1411 }
1409 1412
1413 // Tests that after input event passes through RWHI through
1414 // ForwardXXXEventWithLatencyInfo(), input event coordinates will be present in
1415 // the latency info.
1416 TEST_F(RenderWidgetHostTest, InputEventRWHLatencyInfoCoordinates) {
1417 host_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true));
1418 process_->sink().ClearMessages();
1419
1420 {
1421 WebMouseWheelEvent event =
1422 SyntheticWebMouseWheelEventBuilder::Build(-5, 0, 0, true);
1423 event.x = 100;
1424 event.y = 200;
1425 host_->ForwardWheelEvent(event);
1426 ui::LatencyInfo latency_info = GetLatencyInfoFromInputEvent(process_);
1427 EXPECT_EQ(1u, latency_info.input_coordinates_size);
1428 EXPECT_EQ(100, latency_info.input_coordinates[0].x);
1429 EXPECT_EQ(200, latency_info.input_coordinates[0].y);
1430 SendInputEventACK(WebInputEvent::MouseWheel,
1431 INPUT_EVENT_ACK_STATE_CONSUMED);
1432 }
1433
1434 {
1435 WebMouseEvent event =
1436 SyntheticWebMouseEventBuilder::Build(WebInputEvent::MouseMove);
1437 event.x = 300;
1438 event.y = 400;
1439 host_->ForwardMouseEvent(event);
1440 ui::LatencyInfo latency_info = GetLatencyInfoFromInputEvent(process_);
1441 EXPECT_EQ(1u, latency_info.input_coordinates_size);
1442 EXPECT_EQ(300, latency_info.input_coordinates[0].x);
1443 EXPECT_EQ(400, latency_info.input_coordinates[0].y);
1444 SendInputEventACK(WebInputEvent::MouseMove, INPUT_EVENT_ACK_STATE_CONSUMED);
1445 }
1446
1447 {
1448 WebGestureEvent event = SyntheticWebGestureEventBuilder::Build(
1449 WebInputEvent::GestureScrollBegin, blink::WebGestureDeviceTouchscreen);
1450 event.x = 500;
1451 event.y = 600;
1452 host_->ForwardGestureEvent(event);
1453 ui::LatencyInfo latency_info = GetLatencyInfoFromInputEvent(process_);
1454 EXPECT_EQ(1u, latency_info.input_coordinates_size);
1455 EXPECT_EQ(500, latency_info.input_coordinates[0].x);
1456 EXPECT_EQ(600, latency_info.input_coordinates[0].y);
1457 SendInputEventACK(WebInputEvent::GestureScrollBegin,
1458 INPUT_EVENT_ACK_STATE_CONSUMED);
1459 }
1460
1461 {
1462 PressTouchPoint(700, 800);
1463 PressTouchPoint(900, 1000);
1464 PressTouchPoint(1100, 1200); // LatencyInfo only holds two coordinates.
1465 SendTouchEvent();
1466 ui::LatencyInfo latency_info = GetLatencyInfoFromInputEvent(process_);
1467 EXPECT_EQ(2u, latency_info.input_coordinates_size);
1468 EXPECT_EQ(700, latency_info.input_coordinates[0].x);
1469 EXPECT_EQ(800, latency_info.input_coordinates[0].y);
1470 EXPECT_EQ(900, latency_info.input_coordinates[1].x);
1471 EXPECT_EQ(1000, latency_info.input_coordinates[1].y);
1472 SendInputEventACK(WebInputEvent::TouchStart,
1473 INPUT_EVENT_ACK_STATE_CONSUMED);
1474 }
1475
1476 {
1477 NativeWebKeyboardEvent event;
1478 event.type = WebKeyboardEvent::KeyDown;
1479 host_->ForwardKeyboardEvent(event);
1480 ui::LatencyInfo latency_info = GetLatencyInfoFromInputEvent(process_);
1481 EXPECT_EQ(0u, latency_info.input_coordinates_size);
1482 SendInputEventACK(WebInputEvent::KeyDown, INPUT_EVENT_ACK_STATE_CONSUMED);
1483 }
1484 }
1485
1410 TEST_F(RenderWidgetHostTest, RendererExitedResetsInputRouter) { 1486 TEST_F(RenderWidgetHostTest, RendererExitedResetsInputRouter) {
1411 // RendererExited will delete the view. 1487 // RendererExited will delete the view.
1412 host_->SetView(new TestView(host_.get())); 1488 host_->SetView(new TestView(host_.get()));
1413 host_->RendererExited(base::TERMINATION_STATUS_PROCESS_CRASHED, -1); 1489 host_->RendererExited(base::TERMINATION_STATUS_PROCESS_CRASHED, -1);
1414 1490
1415 // Make sure the input router is in a fresh state. 1491 // Make sure the input router is in a fresh state.
1416 ASSERT_FALSE(host_->input_router()->HasPendingEvents()); 1492 ASSERT_FALSE(host_->input_router()->HasPendingEvents());
1417 } 1493 }
1418 1494
1419 // Regression test for http://crbug.com/401859. 1495 // Regression test for http://crbug.com/401859.
1420 TEST_F(RenderWidgetHostTest, RendererExitedResetsIsHidden) { 1496 TEST_F(RenderWidgetHostTest, RendererExitedResetsIsHidden) {
1421 // RendererExited will delete the view. 1497 // RendererExited will delete the view.
1422 host_->SetView(new TestView(host_.get())); 1498 host_->SetView(new TestView(host_.get()));
1423 host_->WasHidden(); 1499 host_->WasHidden();
1424 1500
1425 ASSERT_TRUE(host_->is_hidden()); 1501 ASSERT_TRUE(host_->is_hidden());
1426 host_->RendererExited(base::TERMINATION_STATUS_PROCESS_CRASHED, -1); 1502 host_->RendererExited(base::TERMINATION_STATUS_PROCESS_CRASHED, -1);
1427 ASSERT_FALSE(host_->is_hidden()); 1503 ASSERT_FALSE(host_->is_hidden());
1428 1504
1429 // Make sure the input router is in a fresh state. 1505 // Make sure the input router is in a fresh state.
1430 ASSERT_FALSE(host_->input_router()->HasPendingEvents()); 1506 ASSERT_FALSE(host_->input_router()->HasPendingEvents());
1431 } 1507 }
1432 1508
1433 } // namespace content 1509 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_widget_host_impl.cc ('k') | ui/events/ipc/latency_info_param_traits.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698