Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 scaleToDelta(float scale) { | |
|
jdduke (slow)
2014/05/01 17:53:27
PinchScaleToWheelDelta
Rick Byers
2014/05/01 18:11:44
Done.
| |
| 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 Loading... | |
| 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 Loading... | |
| 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 SimulateWheelEventWithPhase(WebMouseWheelEvent::PhaseEnded); // enqueued | |
| 512 | 520 |
| 513 // Check that only the first event was sent. | 521 // Check that only the first event was sent. |
| 514 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching( | 522 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching( |
| 515 InputMsg_HandleInputEvent::ID)); | 523 InputMsg_HandleInputEvent::ID)); |
| 524 const WebInputEvent* input_event = | |
| 525 GetInputEventFromMessage(*process_->sink().GetMessageAt(0)); | |
| 526 ASSERT_EQ(WebInputEvent::MouseWheel, input_event->type); | |
| 527 const WebMouseWheelEvent* wheel_event = | |
| 528 static_cast<const WebMouseWheelEvent*>(input_event); | |
| 529 EXPECT_EQ(0, wheel_event->deltaX); | |
| 530 EXPECT_EQ(-5, wheel_event->deltaY); | |
| 516 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | 531 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 517 | 532 |
| 518 // Check that the ACK sends the second message immediately. | 533 // Check that the ACK sends the second message immediately. |
| 519 SendInputEventACK(WebInputEvent::MouseWheel, | 534 SendInputEventACK(WebInputEvent::MouseWheel, |
| 520 INPUT_EVENT_ACK_STATE_CONSUMED); | 535 INPUT_EVENT_ACK_STATE_CONSUMED); |
| 521 // The coalesced events can queue up a delayed ack | 536 // The coalesced events can queue up a delayed ack |
| 522 // so that additional input events can be processed before | 537 // so that additional input events can be processed before |
| 523 // we turn off coalescing. | 538 // we turn off coalescing. |
| 524 base::MessageLoop::current()->RunUntilIdle(); | 539 base::MessageLoop::current()->RunUntilIdle(); |
| 525 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); | 540 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); |
| 526 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching( | 541 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching( |
| 527 InputMsg_HandleInputEvent::ID)); | 542 InputMsg_HandleInputEvent::ID)); |
| 543 input_event = GetInputEventFromMessage(*process_->sink().GetMessageAt(0)); | |
| 544 ASSERT_EQ(WebInputEvent::MouseWheel, input_event->type); | |
| 545 wheel_event = static_cast<const WebMouseWheelEvent*>(input_event); | |
| 546 EXPECT_EQ(8, wheel_event->deltaX); | |
| 547 EXPECT_EQ(-16, wheel_event->deltaY); // coalesced | |
| 528 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | 548 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 529 | 549 |
| 530 // One more time. | 550 // Ack the second event (which had the third coalesced into it). |
| 531 SendInputEventACK(WebInputEvent::MouseWheel, | 551 SendInputEventACK(WebInputEvent::MouseWheel, |
| 532 INPUT_EVENT_ACK_STATE_CONSUMED); | 552 INPUT_EVENT_ACK_STATE_CONSUMED); |
| 533 base::MessageLoop::current()->RunUntilIdle(); | 553 base::MessageLoop::current()->RunUntilIdle(); |
| 534 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); | 554 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); |
| 535 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching( | 555 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching( |
| 536 InputMsg_HandleInputEvent::ID)); | 556 InputMsg_HandleInputEvent::ID)); |
| 557 input_event = GetInputEventFromMessage(*process_->sink().GetMessageAt(0)); | |
| 558 ASSERT_EQ(WebInputEvent::MouseWheel, input_event->type); | |
| 559 wheel_event = static_cast<const WebMouseWheelEvent*>(input_event); | |
| 560 EXPECT_EQ(9, wheel_event->deltaX); | |
| 561 EXPECT_EQ(-7, wheel_event->deltaY); | |
| 562 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | |
| 563 | |
| 564 // Ack the fourth event. | |
| 565 SendInputEventACK(WebInputEvent::MouseWheel, | |
| 566 INPUT_EVENT_ACK_STATE_CONSUMED); | |
| 567 base::MessageLoop::current()->RunUntilIdle(); | |
| 568 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); | |
| 569 EXPECT_TRUE( | |
| 570 process_->sink().GetUniqueMessageMatching(InputMsg_HandleInputEvent::ID)); | |
| 571 input_event = GetInputEventFromMessage(*process_->sink().GetMessageAt(0)); | |
| 572 ASSERT_EQ(WebInputEvent::MouseWheel, input_event->type); | |
| 573 wheel_event = static_cast<const WebMouseWheelEvent*>(input_event); | |
| 574 EXPECT_EQ(0, wheel_event->deltaX); | |
| 575 EXPECT_EQ(-10, wheel_event->deltaY); | |
| 576 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | |
| 577 | |
| 578 // Ack the fifth event. | |
| 579 SendInputEventACK(WebInputEvent::MouseWheel, INPUT_EVENT_ACK_STATE_CONSUMED); | |
| 580 base::MessageLoop::current()->RunUntilIdle(); | |
| 581 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); | |
| 582 EXPECT_TRUE( | |
| 583 process_->sink().GetUniqueMessageMatching(InputMsg_HandleInputEvent::ID)); | |
| 584 input_event = GetInputEventFromMessage(*process_->sink().GetMessageAt(0)); | |
| 585 ASSERT_EQ(WebInputEvent::MouseWheel, input_event->type); | |
| 586 wheel_event = static_cast<const WebMouseWheelEvent*>(input_event); | |
| 587 EXPECT_EQ(0, wheel_event->deltaX); | |
| 588 EXPECT_EQ(0, wheel_event->deltaY); | |
| 589 EXPECT_EQ(WebMouseWheelEvent::PhaseEnded, wheel_event->phase); | |
| 537 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | 590 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 538 | 591 |
| 539 // After the final ack, the queue should be empty. | 592 // After the final ack, the queue should be empty. |
| 540 SendInputEventACK(WebInputEvent::MouseWheel, | 593 SendInputEventACK(WebInputEvent::MouseWheel, INPUT_EVENT_ACK_STATE_CONSUMED); |
| 541 INPUT_EVENT_ACK_STATE_CONSUMED); | |
| 542 base::MessageLoop::current()->RunUntilIdle(); | 594 base::MessageLoop::current()->RunUntilIdle(); |
| 543 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); | 595 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); |
| 544 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); | 596 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); |
| 545 } | 597 } |
| 546 | 598 |
| 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. | 599 // Tests that touch-events are queued properly. |
| 586 TEST_F(InputRouterImplTest, TouchEventQueue) { | 600 TEST_F(InputRouterImplTest, TouchEventQueue) { |
| 587 OnHasTouchEventHandlers(true); | 601 OnHasTouchEventHandlers(true); |
| 588 | 602 |
| 589 PressTouchPoint(1, 1); | 603 PressTouchPoint(1, 1); |
| 590 SendTouchEvent(); | 604 SendTouchEvent(); |
| 591 EXPECT_TRUE(client_->GetAndResetFilterEventCalled()); | 605 EXPECT_TRUE(client_->GetAndResetFilterEventCalled()); |
| 592 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | 606 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 593 EXPECT_FALSE(TouchEventQueueEmpty()); | 607 EXPECT_FALSE(TouchEventQueueEmpty()); |
| 594 | 608 |
| (...skipping 779 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1374 EXPECT_TRUE(HasPendingEvents()); | 1388 EXPECT_TRUE(HasPendingEvents()); |
| 1375 | 1389 |
| 1376 // The final ack'ed gesture should trigger the DidFlush. | 1390 // The final ack'ed gesture should trigger the DidFlush. |
| 1377 SendInputEventACK(WebInputEvent::GesturePinchUpdate, | 1391 SendInputEventACK(WebInputEvent::GesturePinchUpdate, |
| 1378 INPUT_EVENT_ACK_STATE_CONSUMED); | 1392 INPUT_EVENT_ACK_STATE_CONSUMED); |
| 1379 EXPECT_EQ(1U, GetAndResetDidFlushCount()); | 1393 EXPECT_EQ(1U, GetAndResetDidFlushCount()); |
| 1380 EXPECT_FALSE(HasPendingEvents()); | 1394 EXPECT_FALSE(HasPendingEvents()); |
| 1381 } | 1395 } |
| 1382 | 1396 |
| 1383 // Test that GesturePinchUpdate is handled specially for trackpad | 1397 // Test that GesturePinchUpdate is handled specially for trackpad |
| 1384 TEST_F(InputRouterImplTest, TrackpadPinchUpdate) { | 1398 TEST_F(InputRouterImplTest, TouchpadPinchUpdate) { |
| 1385 // For now Trackpad PinchUpdate events are just immediately ACKed | 1399 // 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 | 1400 // Note that the Touchscreen case is verified as NOT doing this as |
| 1389 // part of the ShowPressIsInOrder test. | 1401 // part of the ShowPressIsInOrder test. |
| 1390 SimulateGestureEvent(WebInputEvent::GesturePinchUpdate, | 1402 |
| 1391 WebGestureEvent::Touchpad); | 1403 SimulateGesturePinchUpdateEvent(1.5, 20, 25, 0, WebGestureEvent::Touchpad); |
| 1392 ASSERT_EQ(0U, GetSentMessageCountAndResetSink()); | 1404 |
| 1393 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); | 1405 // Verify we actually sent a special wheel event to the renderer. |
| 1406 const WebInputEvent* input_event = | |
| 1407 GetInputEventFromMessage(*process_->sink().GetMessageAt(0)); | |
| 1408 ASSERT_EQ(WebInputEvent::MouseWheel, input_event->type); | |
| 1409 const WebMouseWheelEvent* wheel_event = | |
| 1410 static_cast<const WebMouseWheelEvent*>(input_event); | |
| 1411 EXPECT_EQ(20, wheel_event->x); | |
| 1412 EXPECT_EQ(25, wheel_event->y); | |
| 1413 EXPECT_EQ(20, wheel_event->globalX); | |
| 1414 EXPECT_EQ(25, wheel_event->globalY); | |
| 1415 EXPECT_EQ(20, wheel_event->windowX); | |
| 1416 EXPECT_EQ(25, wheel_event->windowY); | |
| 1417 EXPECT_EQ(scaleToDelta(1.5), wheel_event->deltaY); | |
| 1418 EXPECT_EQ(0, wheel_event->deltaX); | |
| 1419 EXPECT_EQ(1, wheel_event->hasPreciseScrollingDeltas); | |
| 1420 EXPECT_EQ(1, wheel_event->wheelTicksY); | |
| 1421 EXPECT_EQ(0, wheel_event->wheelTicksX); | |
| 1422 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | |
| 1423 | |
| 1424 // Indicate that the wheel event was unhandled. | |
| 1425 SendInputEventACK(WebInputEvent::MouseWheel, | |
| 1426 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 1427 | |
| 1428 // Check that the correct unhandled pinch event was received. | |
| 1429 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); | |
| 1430 ASSERT_EQ(WebInputEvent::GesturePinchUpdate, ack_handler_->ack_event_type()); | |
| 1394 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NOT_CONSUMED, ack_handler_->ack_state()); | 1431 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NOT_CONSUMED, ack_handler_->ack_state()); |
| 1432 EXPECT_EQ(1.5, ack_handler_->acked_gesture_event().data.pinchUpdate.scale); | |
| 1395 EXPECT_EQ(0, client_->in_flight_event_count()); | 1433 EXPECT_EQ(0, client_->in_flight_event_count()); |
| 1396 } | 1434 |
| 1397 | 1435 // Second a second pinch event. |
| 1398 // Test proper handling of trackpad Gesture{Pinch,Scroll}Update sequences. | 1436 SimulateGesturePinchUpdateEvent(0.3, 20, 25, 0, WebGestureEvent::Touchpad); |
| 1399 TEST_F(InputRouterImplTest, TrackpadPinchAndScrollUpdate) { | 1437 input_event = GetInputEventFromMessage(*process_->sink().GetMessageAt(0)); |
| 1438 ASSERT_EQ(WebInputEvent::MouseWheel, input_event->type); | |
| 1439 wheel_event = static_cast<const WebMouseWheelEvent*>(input_event); | |
| 1440 EXPECT_FLOAT_EQ(scaleToDelta(0.3), wheel_event->deltaY); | |
| 1441 EXPECT_EQ(1, wheel_event->hasPreciseScrollingDeltas); | |
| 1442 EXPECT_EQ(-1, wheel_event->wheelTicksY); | |
| 1443 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | |
| 1444 | |
| 1445 // Indicate that the wheel event was handled this time. | |
| 1446 SendInputEventACK(WebInputEvent::MouseWheel, INPUT_EVENT_ACK_STATE_CONSUMED); | |
| 1447 | |
| 1448 // Check that the correct HANDLED pinch event was received. | |
| 1449 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); | |
| 1450 EXPECT_EQ(WebInputEvent::GesturePinchUpdate, ack_handler_->ack_event_type()); | |
| 1451 EXPECT_EQ(INPUT_EVENT_ACK_STATE_CONSUMED, ack_handler_->ack_state()); | |
| 1452 EXPECT_FLOAT_EQ(0.3, | |
| 1453 ack_handler_->acked_gesture_event().data.pinchUpdate.scale); | |
| 1454 } | |
| 1455 | |
| 1456 // Test that touchpad pinch events are coalesced property, with their synthetic | |
| 1457 // wheel events getting the right ACKs. | |
| 1458 TEST_F(InputRouterImplTest, TouchpadPinchCoalescing) { | |
| 1459 // Send the first pinch. | |
| 1460 SimulateGesturePinchUpdateEvent(1.5, 20, 25, 0, WebGestureEvent::Touchpad); | |
| 1461 | |
| 1462 // Verify we sent the wheel event to the renderer. | |
| 1463 const WebInputEvent* input_event = | |
| 1464 GetInputEventFromMessage(*process_->sink().GetMessageAt(0)); | |
| 1465 ASSERT_EQ(WebInputEvent::MouseWheel, input_event->type); | |
| 1466 const WebMouseWheelEvent* wheel_event = | |
| 1467 static_cast<const WebMouseWheelEvent*>(input_event); | |
| 1468 EXPECT_EQ(scaleToDelta(1.5), wheel_event->deltaY); | |
| 1469 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | |
| 1470 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount()); | |
| 1471 EXPECT_EQ(1, client_->in_flight_event_count()); | |
| 1472 | |
| 1473 // Send a second pinch, this should be queued in the GestureEventQueue. | |
| 1474 SimulateGesturePinchUpdateEvent(1.6, 20, 25, 0, WebGestureEvent::Touchpad); | |
| 1475 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); | |
| 1476 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount()); | |
| 1477 | |
| 1478 // Send a third pinch, this should be coalesced into the second in the | |
| 1479 // GestureEventQueue. | |
| 1480 SimulateGesturePinchUpdateEvent(1.7, 20, 25, 0, WebGestureEvent::Touchpad); | |
| 1481 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); | |
| 1482 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount()); | |
| 1483 | |
| 1484 // Indicate that the first wheel event was unhandled and verify the ACK. | |
| 1485 SendInputEventACK(WebInputEvent::MouseWheel, | |
| 1486 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 1487 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); | |
| 1488 EXPECT_EQ(WebInputEvent::GesturePinchUpdate, ack_handler_->ack_event_type()); | |
| 1489 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NOT_CONSUMED, ack_handler_->ack_state()); | |
| 1490 EXPECT_EQ(1.5, ack_handler_->acked_gesture_event().data.pinchUpdate.scale); | |
| 1491 | |
| 1492 // Verify a second wheel event was sent represending the 2nd and 3rd pinch | |
| 1493 // events. | |
| 1494 EXPECT_EQ(1, client_->in_flight_event_count()); | |
| 1495 input_event = GetInputEventFromMessage(*process_->sink().GetMessageAt(0)); | |
| 1496 ASSERT_EQ(WebInputEvent::MouseWheel, input_event->type); | |
| 1497 wheel_event = static_cast<const WebMouseWheelEvent*>(input_event); | |
| 1498 EXPECT_FLOAT_EQ(scaleToDelta(1.6 * 1.7), | |
| 1499 scaleToDelta(1.6) + scaleToDelta(1.7)); | |
| 1500 EXPECT_FLOAT_EQ(scaleToDelta(1.6 * 1.7), wheel_event->deltaY); | |
| 1501 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | |
| 1502 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount()); | |
| 1503 | |
| 1504 // Indicate that the second wheel event was handled and verify the ACK. | |
| 1505 SendInputEventACK(WebInputEvent::MouseWheel, INPUT_EVENT_ACK_STATE_CONSUMED); | |
| 1506 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); | |
| 1507 EXPECT_EQ(WebInputEvent::GesturePinchUpdate, ack_handler_->ack_event_type()); | |
| 1508 EXPECT_EQ(INPUT_EVENT_ACK_STATE_CONSUMED, ack_handler_->ack_state()); | |
| 1509 EXPECT_FLOAT_EQ(1.6 * 1.7, | |
| 1510 ack_handler_->acked_gesture_event().data.pinchUpdate.scale); | |
| 1511 } | |
| 1512 | |
| 1513 // Test interleaving pinch and wheel events. | |
| 1514 TEST_F(InputRouterImplTest, TouchpadPinchAndWheel) { | |
| 1515 // Simulate queued wheel and pinch events events. | |
| 1516 // Note that in practice interleaving pinch and wheel events should be rare | |
| 1517 // (eg. requires the use of a mouse and trackpad at the same time). | |
| 1518 | |
| 1519 // Use the control modifier to match the synthetic wheel events so that | |
| 1520 // they're elligble for coalescing. | |
| 1521 int mod = WebInputEvent::ControlKey; | |
| 1522 | |
| 1523 // Event 1: sent directly. | |
| 1524 SimulateWheelEvent(0, -5, mod, true); | |
| 1525 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | |
| 1526 | |
| 1527 // Event 2: enqueued in InputRouter | |
| 1528 SimulateWheelEvent(0, -10, mod, true); | |
| 1529 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); | |
| 1530 | |
| 1531 // Event 3: enqueued in InputRouter, not coalesced into #2. | |
| 1532 SimulateGesturePinchUpdateEvent(1.5, 20, 25, 0, WebGestureEvent::Touchpad); | |
| 1533 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); | |
| 1534 | |
| 1535 // Event 4: enqueued in GestureEventQueue | |
| 1536 SimulateGesturePinchUpdateEvent(1.2, 20, 25, 0, WebGestureEvent::Touchpad); | |
| 1537 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); | |
| 1538 | |
| 1539 // Event 5: coalesced into wheel event for #3 | |
| 1540 SimulateWheelEvent(2, 0, mod, true); | |
| 1541 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); | |
| 1542 | |
| 1543 // Send ack for #1. | |
| 1544 SendInputEventACK(WebInputEvent::MouseWheel, | |
| 1545 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 1546 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); | |
| 1547 EXPECT_EQ(WebInputEvent::MouseWheel, ack_handler_->ack_event_type()); | |
| 1548 | |
| 1549 // Verify we sent #2. | |
| 1550 ASSERT_EQ(1U, process_->sink().message_count()); | |
| 1551 const WebInputEvent* input_event = | |
| 1552 GetInputEventFromMessage(*process_->sink().GetMessageAt(0)); | |
| 1553 ASSERT_EQ(WebInputEvent::MouseWheel, input_event->type); | |
| 1554 const WebMouseWheelEvent* wheel_event = | |
| 1555 static_cast<const WebMouseWheelEvent*>(input_event); | |
| 1556 EXPECT_EQ(0, wheel_event->deltaX); | |
| 1557 EXPECT_EQ(-10, wheel_event->deltaY); | |
| 1558 EXPECT_EQ(mod, wheel_event->modifiers); | |
| 1559 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | |
| 1560 | |
| 1561 // Send ack for #2. | |
| 1562 SendInputEventACK(WebInputEvent::MouseWheel, | |
| 1563 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 1564 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); | |
| 1565 EXPECT_EQ(WebInputEvent::MouseWheel, ack_handler_->ack_event_type()); | |
| 1566 | |
| 1567 // Verify we sent #3 (with #5 coalesced in). | |
| 1568 ASSERT_EQ(1U, process_->sink().message_count()); | |
| 1569 input_event = GetInputEventFromMessage(*process_->sink().GetMessageAt(0)); | |
| 1570 ASSERT_EQ(WebInputEvent::MouseWheel, input_event->type); | |
| 1571 wheel_event = static_cast<const WebMouseWheelEvent*>(input_event); | |
| 1572 EXPECT_EQ(2, wheel_event->deltaX); | |
| 1573 EXPECT_EQ(scaleToDelta(1.5), wheel_event->deltaY); | |
| 1574 EXPECT_EQ(mod, wheel_event->modifiers); | |
| 1575 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | |
| 1576 | |
| 1577 // Send ack for #3. | |
| 1578 SendInputEventACK(WebInputEvent::MouseWheel, | |
| 1579 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 1580 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); | |
| 1581 EXPECT_EQ(WebInputEvent::GesturePinchUpdate, ack_handler_->ack_event_type()); | |
| 1582 | |
| 1583 // Verify we sent #4 | |
| 1584 ASSERT_EQ(1U, process_->sink().message_count()); | |
| 1585 input_event = GetInputEventFromMessage(*process_->sink().GetMessageAt(0)); | |
| 1586 ASSERT_EQ(WebInputEvent::MouseWheel, input_event->type); | |
| 1587 wheel_event = static_cast<const WebMouseWheelEvent*>(input_event); | |
| 1588 EXPECT_EQ(0, wheel_event->deltaX); | |
| 1589 EXPECT_FLOAT_EQ(scaleToDelta(1.2), wheel_event->deltaY); | |
| 1590 EXPECT_EQ(mod, wheel_event->modifiers); | |
| 1591 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | |
| 1592 | |
| 1593 // Send ack for #4. | |
| 1594 SendInputEventACK(WebInputEvent::MouseWheel, | |
| 1595 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 1596 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); | |
| 1597 EXPECT_EQ(WebInputEvent::GesturePinchUpdate, ack_handler_->ack_event_type()); | |
| 1598 } | |
| 1599 | |
| 1600 // Test proper handling of touchpad Gesture{Pinch,Scroll}Update sequences. | |
| 1601 TEST_F(InputRouterImplTest, TouchpadPinchAndScrollUpdate) { | |
| 1400 // The first scroll should be sent immediately. | 1602 // The first scroll should be sent immediately. |
| 1401 SimulateGestureEvent(WebInputEvent::GestureScrollUpdate, | 1603 SimulateGestureEvent(WebInputEvent::GestureScrollUpdate, |
| 1402 WebGestureEvent::Touchpad); | 1604 WebGestureEvent::Touchpad); |
| 1403 ASSERT_EQ(1U, GetSentMessageCountAndResetSink()); | 1605 ASSERT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 1404 EXPECT_EQ(1, client_->in_flight_event_count()); | 1606 EXPECT_EQ(1, client_->in_flight_event_count()); |
| 1405 | 1607 |
| 1406 // Subsequent scroll and pinch events should remain queued, coalescing as | 1608 // Subsequent scroll and pinch events should remain queued, coalescing as |
| 1407 // more trackpad events arrive. | 1609 // more trackpad events arrive. |
| 1408 SimulateGestureEvent(WebInputEvent::GesturePinchUpdate, | 1610 SimulateGestureEvent(WebInputEvent::GesturePinchUpdate, |
| 1409 WebGestureEvent::Touchpad); | 1611 WebGestureEvent::Touchpad); |
| 1410 ASSERT_EQ(0U, GetSentMessageCountAndResetSink()); | 1612 ASSERT_EQ(0U, GetSentMessageCountAndResetSink()); |
| 1411 EXPECT_EQ(1, client_->in_flight_event_count()); | 1613 EXPECT_EQ(1, client_->in_flight_event_count()); |
| 1412 | 1614 |
| 1413 SimulateGestureEvent(WebInputEvent::GestureScrollUpdate, | 1615 SimulateGestureEvent(WebInputEvent::GestureScrollUpdate, |
| 1414 WebGestureEvent::Touchpad); | 1616 WebGestureEvent::Touchpad); |
| 1415 ASSERT_EQ(0U, GetSentMessageCountAndResetSink()); | 1617 ASSERT_EQ(0U, GetSentMessageCountAndResetSink()); |
| 1416 EXPECT_EQ(1, client_->in_flight_event_count()); | 1618 EXPECT_EQ(1, client_->in_flight_event_count()); |
| 1417 | 1619 |
| 1418 SimulateGestureEvent(WebInputEvent::GesturePinchUpdate, | 1620 SimulateGestureEvent(WebInputEvent::GesturePinchUpdate, |
| 1419 WebGestureEvent::Touchpad); | 1621 WebGestureEvent::Touchpad); |
| 1420 ASSERT_EQ(0U, GetSentMessageCountAndResetSink()); | 1622 ASSERT_EQ(0U, GetSentMessageCountAndResetSink()); |
| 1421 EXPECT_EQ(1, client_->in_flight_event_count()); | 1623 EXPECT_EQ(1, client_->in_flight_event_count()); |
| 1422 | 1624 |
| 1423 SimulateGestureEvent(WebInputEvent::GestureScrollUpdate, | 1625 SimulateGestureEvent(WebInputEvent::GestureScrollUpdate, |
| 1424 WebGestureEvent::Touchpad); | 1626 WebGestureEvent::Touchpad); |
| 1425 ASSERT_EQ(0U, GetSentMessageCountAndResetSink()); | 1627 ASSERT_EQ(0U, GetSentMessageCountAndResetSink()); |
| 1426 EXPECT_EQ(1, client_->in_flight_event_count()); | 1628 EXPECT_EQ(1, client_->in_flight_event_count()); |
| 1427 | 1629 |
| 1428 // Ack'ing the first scroll should trigger both the coalesced scroll and the | 1630 // Ack'ing the first scroll should trigger both the coalesced scroll and the |
| 1429 // coalesced pinch events. However, the GesturePinchUpdate should be ack'ed | 1631 // 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, | 1632 SendInputEventACK(WebInputEvent::GestureScrollUpdate, |
| 1433 INPUT_EVENT_ACK_STATE_CONSUMED); | 1633 INPUT_EVENT_ACK_STATE_CONSUMED); |
| 1434 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | 1634 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); |
| 1435 EXPECT_EQ(2U, ack_handler_->GetAndResetAckCount()); | 1635 EXPECT_EQ(2U, GetSentMessageCountAndResetSink()); |
| 1436 EXPECT_EQ(1, client_->in_flight_event_count()); | 1636 EXPECT_EQ(2, client_->in_flight_event_count()); |
| 1437 | 1637 |
| 1438 // Ack the second scroll. | 1638 // Ack the second scroll. |
| 1439 SendInputEventACK(WebInputEvent::GestureScrollUpdate, | 1639 SendInputEventACK(WebInputEvent::GestureScrollUpdate, |
| 1440 INPUT_EVENT_ACK_STATE_CONSUMED); | 1640 INPUT_EVENT_ACK_STATE_CONSUMED); |
| 1441 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); | 1641 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); |
| 1442 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); | 1642 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); |
| 1643 EXPECT_EQ(1, client_->in_flight_event_count()); | |
| 1644 | |
| 1645 // Ack the wheel event. | |
| 1646 SendInputEventACK(WebInputEvent::MouseWheel, INPUT_EVENT_ACK_STATE_CONSUMED); | |
| 1647 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); | |
| 1648 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); | |
| 1443 EXPECT_EQ(0, client_->in_flight_event_count()); | 1649 EXPECT_EQ(0, client_->in_flight_event_count()); |
| 1444 } | 1650 } |
| 1445 | 1651 |
| 1446 } // namespace content | 1652 } // namespace content |
| OLD | NEW |