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

Side by Side Diff: content/browser/renderer_host/input/input_router_impl_unittest.cc

Issue 250923004: Synthesize ctrl-wheel events on touchpad pinch (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix windows build and tweaks Created 6 years, 7 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 | Annotate | Revision Log
OLDNEW
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 "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/command_line.h" 6 #include "base/command_line.h"
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "content/browser/renderer_host/input/gesture_event_queue.h" 9 #include "content/browser/renderer_host/input/gesture_event_queue.h"
10 #include "content/browser/renderer_host/input/input_router_client.h" 10 #include "content/browser/renderer_host/input/input_router_client.h"
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 WebGestureEvent::SourceDevice sourceDevice) { 199 WebGestureEvent::SourceDevice sourceDevice) {
200 SimulateGestureEvent( 200 SimulateGestureEvent(
201 SyntheticWebGestureEventBuilder::Build(type, sourceDevice)); 201 SyntheticWebGestureEventBuilder::Build(type, sourceDevice));
202 } 202 }
203 203
204 void SimulateGestureScrollUpdateEvent(float dX, float dY, int modifiers) { 204 void SimulateGestureScrollUpdateEvent(float dX, float dY, int modifiers) {
205 SimulateGestureEvent( 205 SimulateGestureEvent(
206 SyntheticWebGestureEventBuilder::BuildScrollUpdate(dX, dY, modifiers)); 206 SyntheticWebGestureEventBuilder::BuildScrollUpdate(dX, dY, modifiers));
207 } 207 }
208 208
209 void SimulateGesturePinchUpdateEvent(float scale, 209 void SimulateGesturePinchUpdateEvent(
210 float anchorX, 210 float scale,
211 float anchorY, 211 float anchorX,
212 int modifiers) { 212 float anchorY,
213 SimulateGestureEvent( 213 int modifiers,
214 SyntheticWebGestureEventBuilder::BuildPinchUpdate(scale, 214 WebGestureEvent::SourceDevice sourceDevice) {
215 anchorX, 215 SimulateGestureEvent(SyntheticWebGestureEventBuilder::BuildPinchUpdate(
216 anchorY, 216 scale, anchorX, anchorY, modifiers, sourceDevice));
217 modifiers));
218 } 217 }
219 218
220 void SimulateGestureFlingStartEvent( 219 void SimulateGestureFlingStartEvent(
221 float velocityX, 220 float velocityX,
222 float velocityY, 221 float velocityY,
223 WebGestureEvent::SourceDevice sourceDevice) { 222 WebGestureEvent::SourceDevice sourceDevice) {
224 SimulateGestureEvent( 223 SimulateGestureEvent(
225 SyntheticWebGestureEventBuilder::BuildFling(velocityX, 224 SyntheticWebGestureEventBuilder::BuildFling(velocityX,
226 velocityY, 225 velocityY,
227 sourceDevice)); 226 sourceDevice));
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 501
503 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount()); 502 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount());
504 } 503 }
505 504
506 TEST_F(InputRouterImplTest, CoalescesWheelEvents) { 505 TEST_F(InputRouterImplTest, CoalescesWheelEvents) {
507 // Simulate wheel events. 506 // Simulate wheel events.
508 SimulateWheelEvent(0, -5, 0, false); // sent directly 507 SimulateWheelEvent(0, -5, 0, false); // sent directly
509 SimulateWheelEvent(0, -10, 0, false); // enqueued 508 SimulateWheelEvent(0, -10, 0, false); // enqueued
510 SimulateWheelEvent(8, -6, 0, false); // coalesced into previous event 509 SimulateWheelEvent(8, -6, 0, false); // coalesced into previous event
511 SimulateWheelEvent(9, -7, 1, false); // enqueued, different modifiers 510 SimulateWheelEvent(9, -7, 1, false); // enqueued, different modifiers
511 SimulateWheelEvent(0, -10, 0, false); // enqueued, different modifiers
512 SimulateWheelEventWithPhase(WebMouseWheelEvent::PhaseEnded); // enqueued
512 513
513 // Check that only the first event was sent. 514 // Check that only the first event was sent.
514 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching( 515 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(
515 InputMsg_HandleInputEvent::ID)); 516 InputMsg_HandleInputEvent::ID));
517 const WebInputEvent* input_event =
518 GetInputEventFromMessage(*process_->sink().GetMessageAt(0));
519 ASSERT_EQ(WebInputEvent::MouseWheel, input_event->type);
520 const WebMouseWheelEvent* wheel_event =
521 static_cast<const WebMouseWheelEvent*>(input_event);
522 EXPECT_EQ(0, wheel_event->deltaX);
523 EXPECT_EQ(-5, wheel_event->deltaY);
516 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); 524 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
517 525
518 // Check that the ACK sends the second message immediately. 526 // Check that the ACK sends the second message immediately.
519 SendInputEventACK(WebInputEvent::MouseWheel, 527 SendInputEventACK(WebInputEvent::MouseWheel,
520 INPUT_EVENT_ACK_STATE_CONSUMED); 528 INPUT_EVENT_ACK_STATE_CONSUMED);
521 // The coalesced events can queue up a delayed ack 529 // The coalesced events can queue up a delayed ack
522 // so that additional input events can be processed before 530 // so that additional input events can be processed before
523 // we turn off coalescing. 531 // we turn off coalescing.
524 base::MessageLoop::current()->RunUntilIdle(); 532 base::MessageLoop::current()->RunUntilIdle();
525 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); 533 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
526 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching( 534 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(
527 InputMsg_HandleInputEvent::ID)); 535 InputMsg_HandleInputEvent::ID));
536 input_event = GetInputEventFromMessage(*process_->sink().GetMessageAt(0));
537 ASSERT_EQ(WebInputEvent::MouseWheel, input_event->type);
538 wheel_event = static_cast<const WebMouseWheelEvent*>(input_event);
539 EXPECT_EQ(8, wheel_event->deltaX);
540 EXPECT_EQ(-16, wheel_event->deltaY); // coalesced
jdduke (slow) 2014/05/01 15:44:47 Maybe write this as |-10 + -6| for clarity?
Rick Byers 2014/05/01 17:34:57 Done.
528 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); 541 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
529 542
530 // One more time. 543 // Ack the second event (which had the third coalesced into it).
531 SendInputEventACK(WebInputEvent::MouseWheel, 544 SendInputEventACK(WebInputEvent::MouseWheel,
532 INPUT_EVENT_ACK_STATE_CONSUMED); 545 INPUT_EVENT_ACK_STATE_CONSUMED);
533 base::MessageLoop::current()->RunUntilIdle(); 546 base::MessageLoop::current()->RunUntilIdle();
534 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); 547 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
535 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching( 548 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(
536 InputMsg_HandleInputEvent::ID)); 549 InputMsg_HandleInputEvent::ID));
550 input_event = GetInputEventFromMessage(*process_->sink().GetMessageAt(0));
551 ASSERT_EQ(WebInputEvent::MouseWheel, input_event->type);
552 wheel_event = static_cast<const WebMouseWheelEvent*>(input_event);
553 EXPECT_EQ(9, wheel_event->deltaX);
554 EXPECT_EQ(-7, wheel_event->deltaY);
555 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
556
557 // Ack the fourth event.
558 SendInputEventACK(WebInputEvent::MouseWheel,
559 INPUT_EVENT_ACK_STATE_CONSUMED);
560 base::MessageLoop::current()->RunUntilIdle();
561 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
562 EXPECT_TRUE(
563 process_->sink().GetUniqueMessageMatching(InputMsg_HandleInputEvent::ID));
564 input_event = GetInputEventFromMessage(*process_->sink().GetMessageAt(0));
565 ASSERT_EQ(WebInputEvent::MouseWheel, input_event->type);
566 wheel_event = static_cast<const WebMouseWheelEvent*>(input_event);
567 EXPECT_EQ(0, wheel_event->deltaX);
568 EXPECT_EQ(-10, wheel_event->deltaY);
569 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
570
571 // Ack the fifth event.
572 SendInputEventACK(WebInputEvent::MouseWheel, INPUT_EVENT_ACK_STATE_CONSUMED);
573 base::MessageLoop::current()->RunUntilIdle();
574 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
575 EXPECT_TRUE(
576 process_->sink().GetUniqueMessageMatching(InputMsg_HandleInputEvent::ID));
577 input_event = GetInputEventFromMessage(*process_->sink().GetMessageAt(0));
578 ASSERT_EQ(WebInputEvent::MouseWheel, input_event->type);
579 wheel_event = static_cast<const WebMouseWheelEvent*>(input_event);
580 EXPECT_EQ(0, wheel_event->deltaX);
581 EXPECT_EQ(0, wheel_event->deltaY);
582 EXPECT_EQ(WebMouseWheelEvent::PhaseEnded, wheel_event->phase);
537 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); 583 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
538 584
539 // After the final ack, the queue should be empty. 585 // After the final ack, the queue should be empty.
540 SendInputEventACK(WebInputEvent::MouseWheel, 586 SendInputEventACK(WebInputEvent::MouseWheel, INPUT_EVENT_ACK_STATE_CONSUMED);
541 INPUT_EVENT_ACK_STATE_CONSUMED);
542 base::MessageLoop::current()->RunUntilIdle(); 587 base::MessageLoop::current()->RunUntilIdle();
543 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); 588 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
544 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); 589 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
545 } 590 }
546 591
547 TEST_F(InputRouterImplTest,
548 CoalescesWheelEventsQueuedPhaseEndIsNotDropped) {
549 // Send an initial gesture begin and ACK it.
550 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
551 WebGestureEvent::Touchpad);
552 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
553 SendInputEventACK(WebInputEvent::GestureScrollBegin,
554 INPUT_EVENT_ACK_STATE_CONSUMED);
555 base::MessageLoop::current()->RunUntilIdle();
556
557 // Send a wheel event, should get sent directly.
558 SimulateWheelEvent(0, -5, 0, false);
559 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
560
561 // Send a wheel phase end event before an ACK is received for the previous
562 // wheel event, which should get queued.
563 SimulateWheelEventWithPhase(WebMouseWheelEvent::PhaseEnded);
564 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
565
566 // A gesture event should now result in the queued phase ended event being
567 // transmitted before it.
568 SimulateGestureEvent(WebInputEvent::GestureScrollEnd,
569 WebGestureEvent::Touchpad);
570
571 // Verify the events that were sent.
572 const WebInputEvent* input_event =
573 GetInputEventFromMessage(*process_->sink().GetMessageAt(0));
574 ASSERT_EQ(WebInputEvent::MouseWheel, input_event->type);
575 const WebMouseWheelEvent* wheel_event =
576 static_cast<const WebMouseWheelEvent*>(input_event);
577 ASSERT_EQ(WebMouseWheelEvent::PhaseEnded, wheel_event->phase);
578
579 input_event = GetInputEventFromMessage(*process_->sink().GetMessageAt(1));
580 EXPECT_EQ(WebInputEvent::GestureScrollEnd, input_event->type);
581
582 ASSERT_EQ(2U, GetSentMessageCountAndResetSink());
583 }
584
585 // Tests that touch-events are queued properly. 592 // Tests that touch-events are queued properly.
586 TEST_F(InputRouterImplTest, TouchEventQueue) { 593 TEST_F(InputRouterImplTest, TouchEventQueue) {
587 OnHasTouchEventHandlers(true); 594 OnHasTouchEventHandlers(true);
588 595
589 PressTouchPoint(1, 1); 596 PressTouchPoint(1, 1);
590 SendTouchEvent(); 597 SendTouchEvent();
591 EXPECT_TRUE(client_->GetAndResetFilterEventCalled()); 598 EXPECT_TRUE(client_->GetAndResetFilterEventCalled());
592 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); 599 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
593 EXPECT_FALSE(TouchEventQueueEmpty()); 600 EXPECT_FALSE(TouchEventQueueEmpty());
594 601
(...skipping 779 matching lines...) Expand 10 before | Expand all | Expand 10 after
1374 EXPECT_TRUE(HasPendingEvents()); 1381 EXPECT_TRUE(HasPendingEvents());
1375 1382
1376 // The final ack'ed gesture should trigger the DidFlush. 1383 // The final ack'ed gesture should trigger the DidFlush.
1377 SendInputEventACK(WebInputEvent::GesturePinchUpdate, 1384 SendInputEventACK(WebInputEvent::GesturePinchUpdate,
1378 INPUT_EVENT_ACK_STATE_CONSUMED); 1385 INPUT_EVENT_ACK_STATE_CONSUMED);
1379 EXPECT_EQ(1U, GetAndResetDidFlushCount()); 1386 EXPECT_EQ(1U, GetAndResetDidFlushCount());
1380 EXPECT_FALSE(HasPendingEvents()); 1387 EXPECT_FALSE(HasPendingEvents());
1381 } 1388 }
1382 1389
1383 // Test that GesturePinchUpdate is handled specially for trackpad 1390 // Test that GesturePinchUpdate is handled specially for trackpad
1384 TEST_F(InputRouterImplTest, TrackpadPinchUpdate) { 1391 TEST_F(InputRouterImplTest, TouchpadPinchUpdate) {
1385 // For now Trackpad PinchUpdate events are just immediately ACKed 1392 // GesturePinchUpdate for trackpad sends synthetic wheel events.
1386 // as unconsumed without going to the renderer.
1387 // TODO(rbyers): Update for wheel event behavior - crbug.com/289887.
1388 // Note that the Touchscreen case is verified as NOT doing this as 1393 // Note that the Touchscreen case is verified as NOT doing this as
1389 // part of the ShowPressIsInOrder test. 1394 // part of the ShowPressIsInOrder test.
1390 SimulateGestureEvent(WebInputEvent::GesturePinchUpdate, 1395
1391 WebGestureEvent::Touchpad); 1396 SimulateGesturePinchUpdateEvent(1.5, 20, 25, 0, WebGestureEvent::Touchpad);
1392 ASSERT_EQ(0U, GetSentMessageCountAndResetSink()); 1397
1393 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); 1398 // Verify we actually sent a special wheel event to the renderer.
1399 const WebInputEvent* input_event =
1400 GetInputEventFromMessage(*process_->sink().GetMessageAt(0));
1401 ASSERT_EQ(WebInputEvent::MouseWheel, input_event->type);
1402 const WebMouseWheelEvent* wheel_event =
1403 static_cast<const WebMouseWheelEvent*>(input_event);
1404 EXPECT_EQ(20, wheel_event->x);
1405 EXPECT_EQ(25, wheel_event->y);
1406 EXPECT_EQ(20, wheel_event->globalX);
1407 EXPECT_EQ(25, wheel_event->globalY);
1408 EXPECT_EQ(20, wheel_event->windowX);
1409 EXPECT_EQ(25, wheel_event->windowY);
1410 EXPECT_EQ(100.0 * (1.0 - 1.5), wheel_event->deltaY);
1411 EXPECT_EQ(0, wheel_event->deltaX);
1412 EXPECT_EQ(1, wheel_event->hasPreciseScrollingDeltas);
1413 EXPECT_EQ(1, wheel_event->wheelTicksY);
1414 EXPECT_EQ(0, wheel_event->wheelTicksX);
1415 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1416
1417 // Indicate that the wheel event was unhandled.
1418 SendInputEventACK(WebInputEvent::MouseWheel,
1419 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1420
1421 // Check that the correct unhandled pinch event was received.
1422 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
1423 ASSERT_EQ(WebInputEvent::GesturePinchUpdate, ack_handler_->ack_event_type());
1394 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NOT_CONSUMED, ack_handler_->ack_state()); 1424 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NOT_CONSUMED, ack_handler_->ack_state());
1425 EXPECT_EQ(1.5, ack_handler_->acked_gesture_event().data.pinchUpdate.scale);
1395 EXPECT_EQ(0, client_->in_flight_event_count()); 1426 EXPECT_EQ(0, client_->in_flight_event_count());
1396 } 1427
1397 1428 // Second a second pinch event.
1398 // Test proper handling of trackpad Gesture{Pinch,Scroll}Update sequences. 1429 SimulateGesturePinchUpdateEvent(0.3, 20, 25, 0, WebGestureEvent::Touchpad);
1399 TEST_F(InputRouterImplTest, TrackpadPinchAndScrollUpdate) { 1430 input_event = GetInputEventFromMessage(*process_->sink().GetMessageAt(0));
1431 ASSERT_EQ(WebInputEvent::MouseWheel, input_event->type);
1432 wheel_event = static_cast<const WebMouseWheelEvent*>(input_event);
1433 EXPECT_FLOAT_EQ(100.0 * (1.0 - 0.3), wheel_event->deltaY);
1434 EXPECT_EQ(1, wheel_event->hasPreciseScrollingDeltas);
1435 EXPECT_EQ(-1, wheel_event->wheelTicksY);
1436 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1437
1438 // Indicate that the wheel event was handled this time.
1439 SendInputEventACK(WebInputEvent::MouseWheel, INPUT_EVENT_ACK_STATE_CONSUMED);
1440
1441 // Check that the correct HANDLED pinch event was received.
1442 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
1443 EXPECT_EQ(WebInputEvent::GesturePinchUpdate, ack_handler_->ack_event_type());
1444 EXPECT_EQ(INPUT_EVENT_ACK_STATE_CONSUMED, ack_handler_->ack_state());
1445 EXPECT_FLOAT_EQ(0.3,
1446 ack_handler_->acked_gesture_event().data.pinchUpdate.scale);
1447 }
1448
1449 // Test that touchpad pinch events are coalesced property, with their synthetic
1450 // wheel events getting the right ACKs.
1451 TEST_F(InputRouterImplTest, TouchpadPinchCoalescing) {
1452 // Send the first pinch.
1453 SimulateGesturePinchUpdateEvent(1.5, 20, 25, 0, WebGestureEvent::Touchpad);
1454
1455 // Verify we sent the wheel event to the renderer.
1456 const WebInputEvent* input_event =
1457 GetInputEventFromMessage(*process_->sink().GetMessageAt(0));
1458 ASSERT_EQ(WebInputEvent::MouseWheel, input_event->type);
1459 const WebMouseWheelEvent* wheel_event =
1460 static_cast<const WebMouseWheelEvent*>(input_event);
1461 EXPECT_EQ(100.0 * (1.0 - 1.5), wheel_event->deltaY);
1462 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1463 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount());
1464 EXPECT_EQ(1, client_->in_flight_event_count());
1465
1466 // Send a second pinch, this should be queued in the GestureEventQueue.
1467 SimulateGesturePinchUpdateEvent(1.6, 20, 25, 0, WebGestureEvent::Touchpad);
1468 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1469 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount());
1470
1471 // Send a third pinch, this should be coalesced into the second in the
1472 // GestureEventQueue.
1473 SimulateGesturePinchUpdateEvent(1.7, 20, 25, 0, WebGestureEvent::Touchpad);
1474 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1475 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount());
1476
1477 // Indicate that the first wheel event was unhandled and verify the ACK.
1478 SendInputEventACK(WebInputEvent::MouseWheel,
1479 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1480 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
1481 EXPECT_EQ(WebInputEvent::GesturePinchUpdate, ack_handler_->ack_event_type());
1482 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NOT_CONSUMED, ack_handler_->ack_state());
1483 EXPECT_EQ(1.5, ack_handler_->acked_gesture_event().data.pinchUpdate.scale);
1484
1485 // Verify a second wheel event was sent represending the 2nd and 3rd pinch
jdduke (slow) 2014/05/01 15:44:47 representing
Rick Byers 2014/05/01 17:34:57 Done.
1486 // events.
1487 EXPECT_EQ(1, client_->in_flight_event_count());
1488 input_event = GetInputEventFromMessage(*process_->sink().GetMessageAt(0));
1489 ASSERT_EQ(WebInputEvent::MouseWheel, input_event->type);
1490 wheel_event = static_cast<const WebMouseWheelEvent*>(input_event);
1491 EXPECT_FLOAT_EQ(100.0 * (1.0 - 1.6 * 1.7), wheel_event->deltaY);
1492 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1493 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount());
1494
1495 // Indicate that the second wheel event was handled and verify the ACK.
1496 SendInputEventACK(WebInputEvent::MouseWheel, INPUT_EVENT_ACK_STATE_CONSUMED);
1497 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
1498 EXPECT_EQ(WebInputEvent::GesturePinchUpdate, ack_handler_->ack_event_type());
1499 EXPECT_EQ(INPUT_EVENT_ACK_STATE_CONSUMED, ack_handler_->ack_state());
1500 EXPECT_FLOAT_EQ(1.6 * 1.7,
1501 ack_handler_->acked_gesture_event().data.pinchUpdate.scale);
1502 }
1503
1504 // Test interleaving pinch and wheel events.
1505 TEST_F(InputRouterImplTest, TouchpadPinchAndWheel) {
1506 // Simulate queued wheel and pinch events events.
1507 // Note that in practice interleaving pinch and wheel events should be rare
1508 // (eg. requires the use of a mouse and trackpad at the same time).
1509
1510 // Use the control modifier to match the synthetic wheel events so that
1511 // they're elligble for coalescing.
1512 int mod = WebInputEvent::ControlKey;
1513
1514 // Event 1: sent directly.
1515 SimulateWheelEvent(0, -5, mod, true);
1516 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1517
1518 // Event 2: enqueued in InputRouter
jdduke (slow) 2014/05/01 15:44:47 Might as well slap periods on the end of each comm
Rick Byers 2014/05/01 17:34:57 Done. I think our style guide even requires (or a
1519 SimulateWheelEvent(0, -10, mod, true);
1520 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1521
1522 // Event 3: enqueued in InputRouter, not coalesced into #2.
1523 SimulateGesturePinchUpdateEvent(1.5, 20, 25, 0, WebGestureEvent::Touchpad);
1524 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1525
1526 // Event 4: enqueued in GestureEventQueue
1527 SimulateGesturePinchUpdateEvent(1.2, 20, 25, 0, WebGestureEvent::Touchpad);
1528 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1529
1530 // Event 5: coalesced into wheel event for #3
1531 SimulateWheelEvent(2, 0, mod, true);
1532 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1533
1534 // Send ack for #1.
1535 SendInputEventACK(WebInputEvent::MouseWheel,
1536 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1537 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
1538 EXPECT_EQ(WebInputEvent::MouseWheel, ack_handler_->ack_event_type());
1539
1540 // Verify we sent #2.
1541 ASSERT_EQ(1U, process_->sink().message_count());
1542 const WebInputEvent* input_event =
1543 GetInputEventFromMessage(*process_->sink().GetMessageAt(0));
1544 ASSERT_EQ(WebInputEvent::MouseWheel, input_event->type);
1545 const WebMouseWheelEvent* wheel_event =
1546 static_cast<const WebMouseWheelEvent*>(input_event);
1547 EXPECT_EQ(0, wheel_event->deltaX);
1548 EXPECT_EQ(-10, wheel_event->deltaY);
1549 EXPECT_EQ(mod, wheel_event->modifiers);
1550 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1551
1552 // Send ack for #2.
1553 SendInputEventACK(WebInputEvent::MouseWheel,
1554 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1555 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
1556 EXPECT_EQ(WebInputEvent::MouseWheel, ack_handler_->ack_event_type());
1557
1558 // Verify we sent #3 (with #5 coalesced in).
1559 ASSERT_EQ(1U, process_->sink().message_count());
1560 input_event = GetInputEventFromMessage(*process_->sink().GetMessageAt(0));
1561 ASSERT_EQ(WebInputEvent::MouseWheel, input_event->type);
1562 wheel_event = static_cast<const WebMouseWheelEvent*>(input_event);
1563 EXPECT_EQ(2, wheel_event->deltaX);
1564 EXPECT_EQ(100.0 * (1.0 - 1.5), wheel_event->deltaY);
1565 EXPECT_EQ(mod, wheel_event->modifiers);
1566 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1567
1568 // Send ack for #3.
1569 SendInputEventACK(WebInputEvent::MouseWheel,
1570 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1571 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
1572 EXPECT_EQ(WebInputEvent::GesturePinchUpdate, ack_handler_->ack_event_type());
1573
1574 // Verify we sent #4
jdduke (slow) 2014/05/01 15:44:47 #4.
Rick Byers 2014/05/01 17:34:57 Done.
1575 ASSERT_EQ(1U, process_->sink().message_count());
1576 input_event = GetInputEventFromMessage(*process_->sink().GetMessageAt(0));
1577 ASSERT_EQ(WebInputEvent::MouseWheel, input_event->type);
1578 wheel_event = static_cast<const WebMouseWheelEvent*>(input_event);
1579 EXPECT_EQ(0, wheel_event->deltaX);
1580 EXPECT_FLOAT_EQ(100.0 * (1.0 - 1.2), wheel_event->deltaY);
1581 EXPECT_EQ(mod, wheel_event->modifiers);
1582 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1583
1584 // Send ack for #4.
1585 SendInputEventACK(WebInputEvent::MouseWheel,
1586 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1587 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
1588 EXPECT_EQ(WebInputEvent::GesturePinchUpdate, ack_handler_->ack_event_type());
1589 }
1590
1591 // Test proper handling of touchpad Gesture{Pinch,Scroll}Update sequences.
1592 TEST_F(InputRouterImplTest, TouchpadPinchAndScrollUpdate) {
1400 // The first scroll should be sent immediately. 1593 // The first scroll should be sent immediately.
1401 SimulateGestureEvent(WebInputEvent::GestureScrollUpdate, 1594 SimulateGestureEvent(WebInputEvent::GestureScrollUpdate,
1402 WebGestureEvent::Touchpad); 1595 WebGestureEvent::Touchpad);
1403 ASSERT_EQ(1U, GetSentMessageCountAndResetSink()); 1596 ASSERT_EQ(1U, GetSentMessageCountAndResetSink());
1404 EXPECT_EQ(1, client_->in_flight_event_count()); 1597 EXPECT_EQ(1, client_->in_flight_event_count());
1405 1598
1406 // Subsequent scroll and pinch events should remain queued, coalescing as 1599 // Subsequent scroll and pinch events should remain queued, coalescing as
1407 // more trackpad events arrive. 1600 // more trackpad events arrive.
1408 SimulateGestureEvent(WebInputEvent::GesturePinchUpdate, 1601 SimulateGestureEvent(WebInputEvent::GesturePinchUpdate,
1409 WebGestureEvent::Touchpad); 1602 WebGestureEvent::Touchpad);
1410 ASSERT_EQ(0U, GetSentMessageCountAndResetSink()); 1603 ASSERT_EQ(0U, GetSentMessageCountAndResetSink());
1411 EXPECT_EQ(1, client_->in_flight_event_count()); 1604 EXPECT_EQ(1, client_->in_flight_event_count());
1412 1605
1413 SimulateGestureEvent(WebInputEvent::GestureScrollUpdate, 1606 SimulateGestureEvent(WebInputEvent::GestureScrollUpdate,
1414 WebGestureEvent::Touchpad); 1607 WebGestureEvent::Touchpad);
1415 ASSERT_EQ(0U, GetSentMessageCountAndResetSink()); 1608 ASSERT_EQ(0U, GetSentMessageCountAndResetSink());
1416 EXPECT_EQ(1, client_->in_flight_event_count()); 1609 EXPECT_EQ(1, client_->in_flight_event_count());
1417 1610
1418 SimulateGestureEvent(WebInputEvent::GesturePinchUpdate, 1611 SimulateGestureEvent(WebInputEvent::GesturePinchUpdate,
1419 WebGestureEvent::Touchpad); 1612 WebGestureEvent::Touchpad);
1420 ASSERT_EQ(0U, GetSentMessageCountAndResetSink()); 1613 ASSERT_EQ(0U, GetSentMessageCountAndResetSink());
1421 EXPECT_EQ(1, client_->in_flight_event_count()); 1614 EXPECT_EQ(1, client_->in_flight_event_count());
1422 1615
1423 SimulateGestureEvent(WebInputEvent::GestureScrollUpdate, 1616 SimulateGestureEvent(WebInputEvent::GestureScrollUpdate,
1424 WebGestureEvent::Touchpad); 1617 WebGestureEvent::Touchpad);
1425 ASSERT_EQ(0U, GetSentMessageCountAndResetSink()); 1618 ASSERT_EQ(0U, GetSentMessageCountAndResetSink());
1426 EXPECT_EQ(1, client_->in_flight_event_count()); 1619 EXPECT_EQ(1, client_->in_flight_event_count());
1427 1620
1428 // Ack'ing the first scroll should trigger both the coalesced scroll and the 1621 // Ack'ing the first scroll should trigger both the coalesced scroll and the
1429 // coalesced pinch events. However, the GesturePinchUpdate should be ack'ed 1622 // coalesced pinch events (which is sent to the renderer as a wheel event).
1430 // immediately without going to the renderer.
1431 // TODO(rbyers): Update for wheel event behavior - crbug.com/289887.
1432 SendInputEventACK(WebInputEvent::GestureScrollUpdate, 1623 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
1433 INPUT_EVENT_ACK_STATE_CONSUMED); 1624 INPUT_EVENT_ACK_STATE_CONSUMED);
1434 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); 1625 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
1435 EXPECT_EQ(2U, ack_handler_->GetAndResetAckCount()); 1626 EXPECT_EQ(2U, GetSentMessageCountAndResetSink());
1436 EXPECT_EQ(1, client_->in_flight_event_count()); 1627 EXPECT_EQ(2, client_->in_flight_event_count());
1437 1628
1438 // Ack the second scroll. 1629 // Ack the second scroll.
1439 SendInputEventACK(WebInputEvent::GestureScrollUpdate, 1630 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
1440 INPUT_EVENT_ACK_STATE_CONSUMED); 1631 INPUT_EVENT_ACK_STATE_CONSUMED);
1441 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); 1632 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1442 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); 1633 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
1634 EXPECT_EQ(1, client_->in_flight_event_count());
1635
1636 // Ack the wheel event.
1637 SendInputEventACK(WebInputEvent::MouseWheel, INPUT_EVENT_ACK_STATE_CONSUMED);
1638 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1639 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
1443 EXPECT_EQ(0, client_->in_flight_event_count()); 1640 EXPECT_EQ(0, client_->in_flight_event_count());
1444 } 1641 }
1445 1642
1446 } // namespace content 1643 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698