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

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: Ensure scales never coalesce to 0 or Infinity 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 <math.h>
6
5 #include "base/basictypes.h" 7 #include "base/basictypes.h"
6 #include "base/command_line.h" 8 #include "base/command_line.h"
7 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
8 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
9 #include "content/browser/renderer_host/input/gesture_event_queue.h" 11 #include "content/browser/renderer_host/input/gesture_event_queue.h"
10 #include "content/browser/renderer_host/input/input_router_client.h" 12 #include "content/browser/renderer_host/input/input_router_client.h"
11 #include "content/browser/renderer_host/input/input_router_impl.h" 13 #include "content/browser/renderer_host/input/input_router_impl.h"
12 #include "content/browser/renderer_host/input/mock_input_ack_handler.h" 14 #include "content/browser/renderer_host/input/mock_input_ack_handler.h"
13 #include "content/browser/renderer_host/input/mock_input_router_client.h" 15 #include "content/browser/renderer_host/input/mock_input_router_client.h"
14 #include "content/common/content_constants_internal.h" 16 #include "content/common/content_constants_internal.h"
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 const ui::TouchEvent* second = set[i]; 124 const ui::TouchEvent* second = set[i];
123 bool equivalent = TouchEventsAreEquivalent(*first, *second); 125 bool equivalent = TouchEventsAreEquivalent(*first, *second);
124 if (!equivalent) 126 if (!equivalent)
125 return false; 127 return false;
126 } 128 }
127 129
128 return true; 130 return true;
129 } 131 }
130 #endif // defined(USE_AURA) 132 #endif // defined(USE_AURA)
131 133
134 // Expected function used for converting pinch scales to deltaY values.
135 float PinchScaleToWheelDelta(float scale) {
136 return 100.0 * log(scale);
137 }
138
132 } // namespace 139 } // namespace
133 140
134 class InputRouterImplTest : public testing::Test { 141 class InputRouterImplTest : public testing::Test {
135 public: 142 public:
136 InputRouterImplTest() {} 143 InputRouterImplTest() {}
137 virtual ~InputRouterImplTest() {} 144 virtual ~InputRouterImplTest() {}
138 145
139 protected: 146 protected:
140 // testing::Test 147 // testing::Test
141 virtual void SetUp() OVERRIDE { 148 virtual void SetUp() OVERRIDE {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 WebGestureEvent::SourceDevice sourceDevice) { 206 WebGestureEvent::SourceDevice sourceDevice) {
200 SimulateGestureEvent( 207 SimulateGestureEvent(
201 SyntheticWebGestureEventBuilder::Build(type, sourceDevice)); 208 SyntheticWebGestureEventBuilder::Build(type, sourceDevice));
202 } 209 }
203 210
204 void SimulateGestureScrollUpdateEvent(float dX, float dY, int modifiers) { 211 void SimulateGestureScrollUpdateEvent(float dX, float dY, int modifiers) {
205 SimulateGestureEvent( 212 SimulateGestureEvent(
206 SyntheticWebGestureEventBuilder::BuildScrollUpdate(dX, dY, modifiers)); 213 SyntheticWebGestureEventBuilder::BuildScrollUpdate(dX, dY, modifiers));
207 } 214 }
208 215
209 void SimulateGesturePinchUpdateEvent(float scale, 216 void SimulateGesturePinchUpdateEvent(
210 float anchorX, 217 float scale,
211 float anchorY, 218 float anchorX,
212 int modifiers) { 219 float anchorY,
213 SimulateGestureEvent( 220 int modifiers,
214 SyntheticWebGestureEventBuilder::BuildPinchUpdate(scale, 221 WebGestureEvent::SourceDevice sourceDevice) {
215 anchorX, 222 SimulateGestureEvent(SyntheticWebGestureEventBuilder::BuildPinchUpdate(
216 anchorY, 223 scale, anchorX, anchorY, modifiers, sourceDevice));
217 modifiers));
218 } 224 }
219 225
220 void SimulateGestureFlingStartEvent( 226 void SimulateGestureFlingStartEvent(
221 float velocityX, 227 float velocityX,
222 float velocityY, 228 float velocityY,
223 WebGestureEvent::SourceDevice sourceDevice) { 229 WebGestureEvent::SourceDevice sourceDevice) {
224 SimulateGestureEvent( 230 SimulateGestureEvent(
225 SyntheticWebGestureEventBuilder::BuildFling(velocityX, 231 SyntheticWebGestureEventBuilder::BuildFling(velocityX,
226 velocityY, 232 velocityY,
227 sourceDevice)); 233 sourceDevice));
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 508
503 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount()); 509 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount());
504 } 510 }
505 511
506 TEST_F(InputRouterImplTest, CoalescesWheelEvents) { 512 TEST_F(InputRouterImplTest, CoalescesWheelEvents) {
507 // Simulate wheel events. 513 // Simulate wheel events.
508 SimulateWheelEvent(0, -5, 0, false); // sent directly 514 SimulateWheelEvent(0, -5, 0, false); // sent directly
509 SimulateWheelEvent(0, -10, 0, false); // enqueued 515 SimulateWheelEvent(0, -10, 0, false); // enqueued
510 SimulateWheelEvent(8, -6, 0, false); // coalesced into previous event 516 SimulateWheelEvent(8, -6, 0, false); // coalesced into previous event
511 SimulateWheelEvent(9, -7, 1, false); // enqueued, different modifiers 517 SimulateWheelEvent(9, -7, 1, false); // enqueued, different modifiers
518 SimulateWheelEvent(0, -10, 0, false); // enqueued, different modifiers
519 // Explicitly verify that PhaseEnd isn't coalesced to avoid bugs like
520 // https://crbug.com/154740.
521 SimulateWheelEventWithPhase(WebMouseWheelEvent::PhaseEnded); // enqueued
512 522
513 // Check that only the first event was sent. 523 // Check that only the first event was sent.
514 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching( 524 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(
515 InputMsg_HandleInputEvent::ID)); 525 InputMsg_HandleInputEvent::ID));
526 const WebInputEvent* input_event =
527 GetInputEventFromMessage(*process_->sink().GetMessageAt(0));
528 ASSERT_EQ(WebInputEvent::MouseWheel, input_event->type);
529 const WebMouseWheelEvent* wheel_event =
530 static_cast<const WebMouseWheelEvent*>(input_event);
531 EXPECT_EQ(0, wheel_event->deltaX);
532 EXPECT_EQ(-5, wheel_event->deltaY);
516 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); 533 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
517 534
518 // Check that the ACK sends the second message immediately. 535 // Check that the ACK sends the second message immediately.
519 SendInputEventACK(WebInputEvent::MouseWheel, 536 SendInputEventACK(WebInputEvent::MouseWheel,
520 INPUT_EVENT_ACK_STATE_CONSUMED); 537 INPUT_EVENT_ACK_STATE_CONSUMED);
521 // The coalesced events can queue up a delayed ack 538 // The coalesced events can queue up a delayed ack
522 // so that additional input events can be processed before 539 // so that additional input events can be processed before
523 // we turn off coalescing. 540 // we turn off coalescing.
524 base::MessageLoop::current()->RunUntilIdle(); 541 base::MessageLoop::current()->RunUntilIdle();
525 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); 542 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
526 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching( 543 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(
527 InputMsg_HandleInputEvent::ID)); 544 InputMsg_HandleInputEvent::ID));
545 input_event = GetInputEventFromMessage(*process_->sink().GetMessageAt(0));
546 ASSERT_EQ(WebInputEvent::MouseWheel, input_event->type);
547 wheel_event = static_cast<const WebMouseWheelEvent*>(input_event);
548 EXPECT_EQ(8, wheel_event->deltaX);
549 EXPECT_EQ(-10 + -6, wheel_event->deltaY); // coalesced
528 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); 550 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
529 551
530 // One more time. 552 // Ack the second event (which had the third coalesced into it).
531 SendInputEventACK(WebInputEvent::MouseWheel, 553 SendInputEventACK(WebInputEvent::MouseWheel,
532 INPUT_EVENT_ACK_STATE_CONSUMED); 554 INPUT_EVENT_ACK_STATE_CONSUMED);
533 base::MessageLoop::current()->RunUntilIdle(); 555 base::MessageLoop::current()->RunUntilIdle();
534 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); 556 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
535 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching( 557 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(
536 InputMsg_HandleInputEvent::ID)); 558 InputMsg_HandleInputEvent::ID));
559 input_event = GetInputEventFromMessage(*process_->sink().GetMessageAt(0));
560 ASSERT_EQ(WebInputEvent::MouseWheel, input_event->type);
561 wheel_event = static_cast<const WebMouseWheelEvent*>(input_event);
562 EXPECT_EQ(9, wheel_event->deltaX);
563 EXPECT_EQ(-7, wheel_event->deltaY);
564 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
565
566 // Ack the fourth event.
567 SendInputEventACK(WebInputEvent::MouseWheel,
568 INPUT_EVENT_ACK_STATE_CONSUMED);
569 base::MessageLoop::current()->RunUntilIdle();
570 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
571 EXPECT_TRUE(
572 process_->sink().GetUniqueMessageMatching(InputMsg_HandleInputEvent::ID));
573 input_event = GetInputEventFromMessage(*process_->sink().GetMessageAt(0));
574 ASSERT_EQ(WebInputEvent::MouseWheel, input_event->type);
575 wheel_event = static_cast<const WebMouseWheelEvent*>(input_event);
576 EXPECT_EQ(0, wheel_event->deltaX);
577 EXPECT_EQ(-10, wheel_event->deltaY);
578 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
579
580 // Ack the fifth event.
581 SendInputEventACK(WebInputEvent::MouseWheel, INPUT_EVENT_ACK_STATE_CONSUMED);
582 base::MessageLoop::current()->RunUntilIdle();
583 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
584 EXPECT_TRUE(
585 process_->sink().GetUniqueMessageMatching(InputMsg_HandleInputEvent::ID));
586 input_event = GetInputEventFromMessage(*process_->sink().GetMessageAt(0));
587 ASSERT_EQ(WebInputEvent::MouseWheel, input_event->type);
588 wheel_event = static_cast<const WebMouseWheelEvent*>(input_event);
589 EXPECT_EQ(0, wheel_event->deltaX);
590 EXPECT_EQ(0, wheel_event->deltaY);
591 EXPECT_EQ(WebMouseWheelEvent::PhaseEnded, wheel_event->phase);
537 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); 592 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
538 593
539 // After the final ack, the queue should be empty. 594 // After the final ack, the queue should be empty.
540 SendInputEventACK(WebInputEvent::MouseWheel, 595 SendInputEventACK(WebInputEvent::MouseWheel, INPUT_EVENT_ACK_STATE_CONSUMED);
541 INPUT_EVENT_ACK_STATE_CONSUMED);
542 base::MessageLoop::current()->RunUntilIdle(); 596 base::MessageLoop::current()->RunUntilIdle();
543 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); 597 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
544 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); 598 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
545 } 599 }
546 600
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. 601 // Tests that touch-events are queued properly.
586 TEST_F(InputRouterImplTest, TouchEventQueue) { 602 TEST_F(InputRouterImplTest, TouchEventQueue) {
587 OnHasTouchEventHandlers(true); 603 OnHasTouchEventHandlers(true);
588 604
589 PressTouchPoint(1, 1); 605 PressTouchPoint(1, 1);
590 SendTouchEvent(); 606 SendTouchEvent();
591 EXPECT_TRUE(client_->GetAndResetFilterEventCalled()); 607 EXPECT_TRUE(client_->GetAndResetFilterEventCalled());
592 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); 608 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
593 EXPECT_FALSE(TouchEventQueueEmpty()); 609 EXPECT_FALSE(TouchEventQueueEmpty());
594 610
(...skipping 779 matching lines...) Expand 10 before | Expand all | Expand 10 after
1374 EXPECT_TRUE(HasPendingEvents()); 1390 EXPECT_TRUE(HasPendingEvents());
1375 1391
1376 // The final ack'ed gesture should trigger the DidFlush. 1392 // The final ack'ed gesture should trigger the DidFlush.
1377 SendInputEventACK(WebInputEvent::GesturePinchUpdate, 1393 SendInputEventACK(WebInputEvent::GesturePinchUpdate,
1378 INPUT_EVENT_ACK_STATE_CONSUMED); 1394 INPUT_EVENT_ACK_STATE_CONSUMED);
1379 EXPECT_EQ(1U, GetAndResetDidFlushCount()); 1395 EXPECT_EQ(1U, GetAndResetDidFlushCount());
1380 EXPECT_FALSE(HasPendingEvents()); 1396 EXPECT_FALSE(HasPendingEvents());
1381 } 1397 }
1382 1398
1383 // Test that GesturePinchUpdate is handled specially for trackpad 1399 // Test that GesturePinchUpdate is handled specially for trackpad
1384 TEST_F(InputRouterImplTest, TrackpadPinchUpdate) { 1400 TEST_F(InputRouterImplTest, TouchpadPinchUpdate) {
1385 // For now Trackpad PinchUpdate events are just immediately ACKed 1401 // 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 1402 // Note that the Touchscreen case is verified as NOT doing this as
1389 // part of the ShowPressIsInOrder test. 1403 // part of the ShowPressIsInOrder test.
1390 SimulateGestureEvent(WebInputEvent::GesturePinchUpdate, 1404
1391 WebGestureEvent::Touchpad); 1405 SimulateGesturePinchUpdateEvent(1.5f, 20, 25, 0, WebGestureEvent::Touchpad);
1392 ASSERT_EQ(0U, GetSentMessageCountAndResetSink()); 1406
1393 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); 1407 // Verify we actually sent a special wheel event to the renderer.
1408 const WebInputEvent* input_event =
1409 GetInputEventFromMessage(*process_->sink().GetMessageAt(0));
1410 ASSERT_EQ(WebInputEvent::MouseWheel, input_event->type);
1411 const WebMouseWheelEvent* wheel_event =
1412 static_cast<const WebMouseWheelEvent*>(input_event);
1413 EXPECT_EQ(20, wheel_event->x);
1414 EXPECT_EQ(25, wheel_event->y);
1415 EXPECT_EQ(20, wheel_event->globalX);
1416 EXPECT_EQ(25, wheel_event->globalY);
1417 EXPECT_EQ(20, wheel_event->windowX);
1418 EXPECT_EQ(25, wheel_event->windowY);
1419 EXPECT_EQ(PinchScaleToWheelDelta(1.5), wheel_event->deltaY);
1420 EXPECT_EQ(0, wheel_event->deltaX);
1421 EXPECT_EQ(1, wheel_event->hasPreciseScrollingDeltas);
1422 EXPECT_EQ(1, wheel_event->wheelTicksY);
1423 EXPECT_EQ(0, wheel_event->wheelTicksX);
1424 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1425
1426 // Indicate that the wheel event was unhandled.
1427 SendInputEventACK(WebInputEvent::MouseWheel,
1428 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1429
1430 // Check that the correct unhandled pinch event was received.
1431 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
1432 ASSERT_EQ(WebInputEvent::GesturePinchUpdate, ack_handler_->ack_event_type());
1394 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NOT_CONSUMED, ack_handler_->ack_state()); 1433 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NOT_CONSUMED, ack_handler_->ack_state());
1434 EXPECT_EQ(1.5f, ack_handler_->acked_gesture_event().data.pinchUpdate.scale);
1395 EXPECT_EQ(0, client_->in_flight_event_count()); 1435 EXPECT_EQ(0, client_->in_flight_event_count());
1396 } 1436
1397 1437 // Second a second pinch event.
1398 // Test proper handling of trackpad Gesture{Pinch,Scroll}Update sequences. 1438 SimulateGesturePinchUpdateEvent(0.3f, 20, 25, 0, WebGestureEvent::Touchpad);
1399 TEST_F(InputRouterImplTest, TrackpadPinchAndScrollUpdate) { 1439 input_event = GetInputEventFromMessage(*process_->sink().GetMessageAt(0));
1440 ASSERT_EQ(WebInputEvent::MouseWheel, input_event->type);
1441 wheel_event = static_cast<const WebMouseWheelEvent*>(input_event);
1442 EXPECT_FLOAT_EQ(PinchScaleToWheelDelta(0.3f), wheel_event->deltaY);
1443 EXPECT_EQ(1, wheel_event->hasPreciseScrollingDeltas);
1444 EXPECT_EQ(-1, wheel_event->wheelTicksY);
1445 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1446
1447 // Indicate that the wheel event was handled this time.
1448 SendInputEventACK(WebInputEvent::MouseWheel, INPUT_EVENT_ACK_STATE_CONSUMED);
1449
1450 // Check that the correct HANDLED pinch event was received.
1451 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
1452 EXPECT_EQ(WebInputEvent::GesturePinchUpdate, ack_handler_->ack_event_type());
1453 EXPECT_EQ(INPUT_EVENT_ACK_STATE_CONSUMED, ack_handler_->ack_state());
1454 EXPECT_FLOAT_EQ(0.3f,
1455 ack_handler_->acked_gesture_event().data.pinchUpdate.scale);
1456 }
1457
1458 // Test that touchpad pinch events are coalesced property, with their synthetic
1459 // wheel events getting the right ACKs.
1460 TEST_F(InputRouterImplTest, TouchpadPinchCoalescing) {
1461 // Send the first pinch.
1462 SimulateGesturePinchUpdateEvent(1.5f, 20, 25, 0, WebGestureEvent::Touchpad);
1463
1464 // Verify we sent the wheel event to the renderer.
1465 const WebInputEvent* input_event =
1466 GetInputEventFromMessage(*process_->sink().GetMessageAt(0));
1467 ASSERT_EQ(WebInputEvent::MouseWheel, input_event->type);
1468 const WebMouseWheelEvent* wheel_event =
1469 static_cast<const WebMouseWheelEvent*>(input_event);
1470 EXPECT_EQ(PinchScaleToWheelDelta(1.5f), wheel_event->deltaY);
1471 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1472 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount());
1473 EXPECT_EQ(1, client_->in_flight_event_count());
1474
1475 // Send a second pinch, this should be queued in the GestureEventQueue.
1476 SimulateGesturePinchUpdateEvent(1.6f, 20, 25, 0, WebGestureEvent::Touchpad);
1477 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1478 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount());
1479
1480 // Send a third pinch, this should be coalesced into the second in the
1481 // GestureEventQueue.
1482 SimulateGesturePinchUpdateEvent(1.7f, 20, 25, 0, WebGestureEvent::Touchpad);
1483 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1484 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount());
1485
1486 // Indicate that the first wheel event was unhandled and verify the ACK.
1487 SendInputEventACK(WebInputEvent::MouseWheel,
1488 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1489 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
1490 EXPECT_EQ(WebInputEvent::GesturePinchUpdate, ack_handler_->ack_event_type());
1491 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NOT_CONSUMED, ack_handler_->ack_state());
1492 EXPECT_EQ(1.5f, ack_handler_->acked_gesture_event().data.pinchUpdate.scale);
1493
1494 // Verify a second wheel event was sent representing the 2nd and 3rd pinch
1495 // events.
1496 EXPECT_EQ(1, client_->in_flight_event_count());
1497 input_event = GetInputEventFromMessage(*process_->sink().GetMessageAt(0));
1498 ASSERT_EQ(WebInputEvent::MouseWheel, input_event->type);
1499 wheel_event = static_cast<const WebMouseWheelEvent*>(input_event);
1500 EXPECT_FLOAT_EQ(PinchScaleToWheelDelta(1.6f * 1.7f),
1501 PinchScaleToWheelDelta(1.6f) + PinchScaleToWheelDelta(1.7f));
1502 EXPECT_FLOAT_EQ(PinchScaleToWheelDelta(1.6f * 1.7f), wheel_event->deltaY);
1503 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1504 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount());
1505
1506 // Indicate that the second wheel event was handled and verify the ACK.
1507 SendInputEventACK(WebInputEvent::MouseWheel, INPUT_EVENT_ACK_STATE_CONSUMED);
1508 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
1509 EXPECT_EQ(WebInputEvent::GesturePinchUpdate, ack_handler_->ack_event_type());
1510 EXPECT_EQ(INPUT_EVENT_ACK_STATE_CONSUMED, ack_handler_->ack_state());
1511 EXPECT_FLOAT_EQ(1.6f * 1.7f,
1512 ack_handler_->acked_gesture_event().data.pinchUpdate.scale);
1513 }
1514
1515 // Test interleaving pinch and wheel events.
1516 TEST_F(InputRouterImplTest, TouchpadPinchAndWheel) {
1517 // Simulate queued wheel and pinch events events.
1518 // Note that in practice interleaving pinch and wheel events should be rare
1519 // (eg. requires the use of a mouse and trackpad at the same time).
1520
1521 // Use the control modifier to match the synthetic wheel events so that
1522 // they're elligble for coalescing.
1523 int mod = WebInputEvent::ControlKey;
1524
1525 // Event 1: sent directly.
1526 SimulateWheelEvent(0, -5, mod, true);
1527 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1528
1529 // Event 2: enqueued in InputRouter.
1530 SimulateWheelEvent(0, -10, mod, true);
1531 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1532
1533 // Event 3: enqueued in InputRouter, not coalesced into #2.
1534 SimulateGesturePinchUpdateEvent(1.5f, 20, 25, 0, WebGestureEvent::Touchpad);
1535 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1536
1537 // Event 4: enqueued in GestureEventQueue.
1538 SimulateGesturePinchUpdateEvent(1.2f, 20, 25, 0, WebGestureEvent::Touchpad);
1539 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1540
1541 // Event 5: coalesced into wheel event for #3.
1542 SimulateWheelEvent(2, 0, mod, true);
1543 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1544
1545 // Send ack for #1.
1546 SendInputEventACK(WebInputEvent::MouseWheel,
1547 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1548 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
1549 EXPECT_EQ(WebInputEvent::MouseWheel, ack_handler_->ack_event_type());
1550
1551 // Verify we sent #2.
1552 ASSERT_EQ(1U, process_->sink().message_count());
1553 const WebInputEvent* input_event =
1554 GetInputEventFromMessage(*process_->sink().GetMessageAt(0));
1555 ASSERT_EQ(WebInputEvent::MouseWheel, input_event->type);
1556 const WebMouseWheelEvent* wheel_event =
1557 static_cast<const WebMouseWheelEvent*>(input_event);
1558 EXPECT_EQ(0, wheel_event->deltaX);
1559 EXPECT_EQ(-10, wheel_event->deltaY);
1560 EXPECT_EQ(mod, wheel_event->modifiers);
1561 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1562
1563 // Send ack for #2.
1564 SendInputEventACK(WebInputEvent::MouseWheel,
1565 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1566 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
1567 EXPECT_EQ(WebInputEvent::MouseWheel, ack_handler_->ack_event_type());
1568
1569 // Verify we sent #3 (with #5 coalesced in).
1570 ASSERT_EQ(1U, process_->sink().message_count());
1571 input_event = GetInputEventFromMessage(*process_->sink().GetMessageAt(0));
1572 ASSERT_EQ(WebInputEvent::MouseWheel, input_event->type);
1573 wheel_event = static_cast<const WebMouseWheelEvent*>(input_event);
1574 EXPECT_EQ(2, wheel_event->deltaX);
1575 EXPECT_EQ(PinchScaleToWheelDelta(1.5f), wheel_event->deltaY);
1576 EXPECT_EQ(mod, wheel_event->modifiers);
1577 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1578
1579 // Send ack for #3.
1580 SendInputEventACK(WebInputEvent::MouseWheel,
1581 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1582 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
1583 EXPECT_EQ(WebInputEvent::GesturePinchUpdate, ack_handler_->ack_event_type());
1584
1585 // Verify we sent #4.
1586 ASSERT_EQ(1U, process_->sink().message_count());
1587 input_event = GetInputEventFromMessage(*process_->sink().GetMessageAt(0));
1588 ASSERT_EQ(WebInputEvent::MouseWheel, input_event->type);
1589 wheel_event = static_cast<const WebMouseWheelEvent*>(input_event);
1590 EXPECT_EQ(0, wheel_event->deltaX);
1591 EXPECT_FLOAT_EQ(PinchScaleToWheelDelta(1.2f), wheel_event->deltaY);
1592 EXPECT_EQ(mod, wheel_event->modifiers);
1593 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1594
1595 // Send ack for #4.
1596 SendInputEventACK(WebInputEvent::MouseWheel,
1597 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1598 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
1599 EXPECT_EQ(WebInputEvent::GesturePinchUpdate, ack_handler_->ack_event_type());
1600 }
1601
1602 // Test proper handling of touchpad Gesture{Pinch,Scroll}Update sequences.
1603 TEST_F(InputRouterImplTest, TouchpadPinchAndScrollUpdate) {
1400 // The first scroll should be sent immediately. 1604 // The first scroll should be sent immediately.
1401 SimulateGestureEvent(WebInputEvent::GestureScrollUpdate, 1605 SimulateGestureEvent(WebInputEvent::GestureScrollUpdate,
1402 WebGestureEvent::Touchpad); 1606 WebGestureEvent::Touchpad);
1403 ASSERT_EQ(1U, GetSentMessageCountAndResetSink()); 1607 ASSERT_EQ(1U, GetSentMessageCountAndResetSink());
1404 EXPECT_EQ(1, client_->in_flight_event_count()); 1608 EXPECT_EQ(1, client_->in_flight_event_count());
1405 1609
1406 // Subsequent scroll and pinch events should remain queued, coalescing as 1610 // Subsequent scroll and pinch events should remain queued, coalescing as
1407 // more trackpad events arrive. 1611 // more trackpad events arrive.
1408 SimulateGestureEvent(WebInputEvent::GesturePinchUpdate, 1612 SimulateGestureEvent(WebInputEvent::GesturePinchUpdate,
1409 WebGestureEvent::Touchpad); 1613 WebGestureEvent::Touchpad);
1410 ASSERT_EQ(0U, GetSentMessageCountAndResetSink()); 1614 ASSERT_EQ(0U, GetSentMessageCountAndResetSink());
1411 EXPECT_EQ(1, client_->in_flight_event_count()); 1615 EXPECT_EQ(1, client_->in_flight_event_count());
1412 1616
1413 SimulateGestureEvent(WebInputEvent::GestureScrollUpdate, 1617 SimulateGestureEvent(WebInputEvent::GestureScrollUpdate,
1414 WebGestureEvent::Touchpad); 1618 WebGestureEvent::Touchpad);
1415 ASSERT_EQ(0U, GetSentMessageCountAndResetSink()); 1619 ASSERT_EQ(0U, GetSentMessageCountAndResetSink());
1416 EXPECT_EQ(1, client_->in_flight_event_count()); 1620 EXPECT_EQ(1, client_->in_flight_event_count());
1417 1621
1418 SimulateGestureEvent(WebInputEvent::GesturePinchUpdate, 1622 SimulateGestureEvent(WebInputEvent::GesturePinchUpdate,
1419 WebGestureEvent::Touchpad); 1623 WebGestureEvent::Touchpad);
1420 ASSERT_EQ(0U, GetSentMessageCountAndResetSink()); 1624 ASSERT_EQ(0U, GetSentMessageCountAndResetSink());
1421 EXPECT_EQ(1, client_->in_flight_event_count()); 1625 EXPECT_EQ(1, client_->in_flight_event_count());
1422 1626
1423 SimulateGestureEvent(WebInputEvent::GestureScrollUpdate, 1627 SimulateGestureEvent(WebInputEvent::GestureScrollUpdate,
1424 WebGestureEvent::Touchpad); 1628 WebGestureEvent::Touchpad);
1425 ASSERT_EQ(0U, GetSentMessageCountAndResetSink()); 1629 ASSERT_EQ(0U, GetSentMessageCountAndResetSink());
1426 EXPECT_EQ(1, client_->in_flight_event_count()); 1630 EXPECT_EQ(1, client_->in_flight_event_count());
1427 1631
1428 // Ack'ing the first scroll should trigger both the coalesced scroll and the 1632 // Ack'ing the first scroll should trigger both the coalesced scroll and the
1429 // coalesced pinch events. However, the GesturePinchUpdate should be ack'ed 1633 // 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, 1634 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
1433 INPUT_EVENT_ACK_STATE_CONSUMED); 1635 INPUT_EVENT_ACK_STATE_CONSUMED);
1434 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); 1636 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
1435 EXPECT_EQ(2U, ack_handler_->GetAndResetAckCount()); 1637 EXPECT_EQ(2U, GetSentMessageCountAndResetSink());
1436 EXPECT_EQ(1, client_->in_flight_event_count()); 1638 EXPECT_EQ(2, client_->in_flight_event_count());
1437 1639
1438 // Ack the second scroll. 1640 // Ack the second scroll.
1439 SendInputEventACK(WebInputEvent::GestureScrollUpdate, 1641 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
1440 INPUT_EVENT_ACK_STATE_CONSUMED); 1642 INPUT_EVENT_ACK_STATE_CONSUMED);
1441 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); 1643 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1442 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); 1644 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
1645 EXPECT_EQ(1, client_->in_flight_event_count());
1646
1647 // Ack the wheel event.
1648 SendInputEventACK(WebInputEvent::MouseWheel, INPUT_EVENT_ACK_STATE_CONSUMED);
1649 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1650 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
1443 EXPECT_EQ(0, client_->in_flight_event_count()); 1651 EXPECT_EQ(0, client_->in_flight_event_count());
1444 } 1652 }
1445 1653
1446 } // namespace content 1654 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/input/input_router_impl.cc ('k') | content/browser/renderer_host/input/mock_input_ack_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698