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
3 // found in the LICENSE file.
7 #include "base/basictypes.h"
8 #include "base/command_line.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/strings/utf_string_conversions.h"
11 #include "content/browser/renderer_host/input/gesture_event_queue.h"
12 #include "content/browser/renderer_host/input/input_router_client.h"
13 #include "content/browser/renderer_host/input/input_router_impl.h"
14 #include "content/browser/renderer_host/input/mock_input_ack_handler.h"
15 #include "content/browser/renderer_host/input/mock_input_router_client.h"
16 #include "content/common/content_constants_internal.h"
17 #include "content/common/edit_command.h"
18 #include "content/common/input/synthetic_web_input_event_builders.h"
19 #include "content/common/input/touch_action.h"
20 #include "content/common/input/web_input_event_traits.h"
21 #include "content/common/input_messages.h"
22 #include "content/common/view_messages.h"
23 #include "content/public/common/content_switches.h"
24 #include "content/public/test/mock_render_process_host.h"
25 #include "content/public/test/test_browser_context.h"
26 #include "testing/gtest/include/gtest/gtest.h"
27 #include "ui/events/keycodes/keyboard_codes.h"
30 #include "content/browser/renderer_host/ui_events_helper.h"
31 #include "ui/events/event.h"
34 using base::TimeDelta
;
35 using blink::WebGestureEvent
;
36 using blink::WebKeyboardEvent
;
37 using blink::WebInputEvent
;
38 using blink::WebMouseEvent
;
39 using blink::WebMouseWheelEvent
;
40 using blink::WebTouchEvent
;
41 using blink::WebTouchPoint
;
47 const WebInputEvent
* GetInputEventFromMessage(const IPC::Message
& message
) {
48 PickleIterator
iter(message
);
51 if (!message
.ReadData(&iter
, &data
, &data_length
))
53 return reinterpret_cast<const WebInputEvent
*>(data
);
56 WebInputEvent
& GetEventWithType(WebInputEvent::Type type
) {
57 WebInputEvent
* event
= NULL
;
58 if (WebInputEvent::isMouseEventType(type
)) {
59 static WebMouseEvent mouse
;
61 } else if (WebInputEvent::isTouchEventType(type
)) {
62 static WebTouchEvent touch
;
64 } else if (WebInputEvent::isKeyboardEventType(type
)) {
65 static WebKeyboardEvent key
;
67 } else if (WebInputEvent::isGestureEventType(type
)) {
68 static WebGestureEvent gesture
;
70 } else if (type
== WebInputEvent::MouseWheel
) {
71 static WebMouseWheelEvent wheel
;
79 bool GetIsShortcutFromHandleInputEventMessage(const IPC::Message
* msg
) {
80 InputMsg_HandleInputEvent::Schema::Param param
;
81 InputMsg_HandleInputEvent::Read(msg
, ¶m
);
85 template<typename MSG_T
, typename ARG_T1
>
86 void ExpectIPCMessageWithArg1(const IPC::Message
* msg
, const ARG_T1
& arg1
) {
87 ASSERT_EQ(MSG_T::ID
, msg
->type());
88 typename
MSG_T::Schema::Param param
;
89 ASSERT_TRUE(MSG_T::Read(msg
, ¶m
));
90 EXPECT_EQ(arg1
, param
.a
);
93 template<typename MSG_T
, typename ARG_T1
, typename ARG_T2
>
94 void ExpectIPCMessageWithArg2(const IPC::Message
* msg
,
97 ASSERT_EQ(MSG_T::ID
, msg
->type());
98 typename
MSG_T::Schema::Param param
;
99 ASSERT_TRUE(MSG_T::Read(msg
, ¶m
));
100 EXPECT_EQ(arg1
, param
.a
);
101 EXPECT_EQ(arg2
, param
.b
);
104 #if defined(USE_AURA)
105 bool TouchEventsAreEquivalent(const ui::TouchEvent
& first
,
106 const ui::TouchEvent
& second
) {
107 if (first
.type() != second
.type())
109 if (first
.location() != second
.location())
111 if (first
.touch_id() != second
.touch_id())
113 if (second
.time_stamp().InSeconds() != first
.time_stamp().InSeconds())
118 bool EventListIsSubset(const ScopedVector
<ui::TouchEvent
>& subset
,
119 const ScopedVector
<ui::TouchEvent
>& set
) {
120 if (subset
.size() > set
.size())
122 for (size_t i
= 0; i
< subset
.size(); ++i
) {
123 const ui::TouchEvent
* first
= subset
[i
];
124 const ui::TouchEvent
* second
= set
[i
];
125 bool equivalent
= TouchEventsAreEquivalent(*first
, *second
);
132 #endif // defined(USE_AURA)
134 // Expected function used for converting pinch scales to deltaY values.
135 float PinchScaleToWheelDelta(float scale
) {
136 return 100.0 * log(scale
);
141 class InputRouterImplTest
: public testing::Test
{
143 InputRouterImplTest() {}
144 virtual ~InputRouterImplTest() {}
148 virtual void SetUp() OVERRIDE
{
149 browser_context_
.reset(new TestBrowserContext());
150 process_
.reset(new MockRenderProcessHost(browser_context_
.get()));
151 client_
.reset(new MockInputRouterClient());
152 ack_handler_
.reset(new MockInputAckHandler());
153 CommandLine
* command_line
= CommandLine::ForCurrentProcess();
154 command_line
->AppendSwitch(switches::kValidateInputEventStream
);
155 input_router_
.reset(new InputRouterImpl(process_
.get(),
160 client_
->set_input_router(input_router());
161 ack_handler_
->set_input_router(input_router());
164 virtual void TearDown() OVERRIDE
{
165 // Process all pending tasks to avoid leaks.
166 base::MessageLoop::current()->RunUntilIdle();
168 input_router_
.reset();
171 browser_context_
.reset();
174 void SetUpForTouchAckTimeoutTest(int timeout_ms
) {
175 config_
.touch_config
.touch_ack_timeout_delay
=
176 base::TimeDelta::FromMilliseconds(timeout_ms
);
177 config_
.touch_config
.touch_ack_timeout_supported
= true;
182 void SimulateKeyboardEvent(WebInputEvent::Type type
, bool is_shortcut
) {
183 WebKeyboardEvent event
= SyntheticWebKeyboardEventBuilder::Build(type
);
184 NativeWebKeyboardEvent native_event
;
185 memcpy(&native_event
, &event
, sizeof(event
));
186 input_router_
->SendKeyboardEvent(
192 void SimulateWheelEvent(float dX
, float dY
, int modifiers
, bool precise
) {
193 input_router_
->SendWheelEvent(MouseWheelEventWithLatencyInfo(
194 SyntheticWebMouseWheelEventBuilder::Build(dX
, dY
, modifiers
, precise
),
198 void SimulateMouseEvent(WebInputEvent::Type type
, int x
, int y
) {
199 input_router_
->SendMouseEvent(MouseEventWithLatencyInfo(
200 SyntheticWebMouseEventBuilder::Build(type
, x
, y
, 0),
204 void SimulateWheelEventWithPhase(WebMouseWheelEvent::Phase phase
) {
205 input_router_
->SendWheelEvent(MouseWheelEventWithLatencyInfo(
206 SyntheticWebMouseWheelEventBuilder::Build(phase
), ui::LatencyInfo()));
209 void SimulateGestureEvent(const WebGestureEvent
& gesture
) {
210 input_router_
->SendGestureEvent(
211 GestureEventWithLatencyInfo(gesture
, ui::LatencyInfo()));
214 void SimulateGestureEvent(WebInputEvent::Type type
,
215 WebGestureEvent::SourceDevice sourceDevice
) {
216 SimulateGestureEvent(
217 SyntheticWebGestureEventBuilder::Build(type
, sourceDevice
));
220 void SimulateGestureScrollUpdateEvent(float dX
, float dY
, int modifiers
) {
221 SimulateGestureEvent(
222 SyntheticWebGestureEventBuilder::BuildScrollUpdate(dX
, dY
, modifiers
));
225 void SimulateGesturePinchUpdateEvent(
230 WebGestureEvent::SourceDevice sourceDevice
) {
231 SimulateGestureEvent(SyntheticWebGestureEventBuilder::BuildPinchUpdate(
232 scale
, anchorX
, anchorY
, modifiers
, sourceDevice
));
235 void SimulateGestureFlingStartEvent(
238 WebGestureEvent::SourceDevice sourceDevice
) {
239 SimulateGestureEvent(
240 SyntheticWebGestureEventBuilder::BuildFling(velocityX
,
245 void SimulateTouchEvent(WebInputEvent::Type type
) {
246 touch_event_
.ResetPoints();
247 int index
= PressTouchPoint(0, 0);
249 case WebInputEvent::TouchStart
:
250 // Already handled by |PressTouchPoint()|.
252 case WebInputEvent::TouchMove
:
253 MoveTouchPoint(index
, 5, 5);
255 case WebInputEvent::TouchEnd
:
256 ReleaseTouchPoint(index
);
258 case WebInputEvent::TouchCancel
:
259 CancelTouchPoint(index
);
262 FAIL() << "Invalid touch event type.";
268 void SetTouchTimestamp(base::TimeDelta timestamp
) {
269 touch_event_
.SetTimestamp(timestamp
);
272 void SendTouchEvent() {
273 input_router_
->SendTouchEvent(
274 TouchEventWithLatencyInfo(touch_event_
, ui::LatencyInfo()));
275 touch_event_
.ResetPoints();
278 int PressTouchPoint(int x
, int y
) {
279 return touch_event_
.PressPoint(x
, y
);
282 void MoveTouchPoint(int index
, int x
, int y
) {
283 touch_event_
.MovePoint(index
, x
, y
);
286 void ReleaseTouchPoint(int index
) {
287 touch_event_
.ReleasePoint(index
);
290 void CancelTouchPoint(int index
) {
291 touch_event_
.CancelPoint(index
);
294 void SendInputEventACK(blink::WebInputEvent::Type type
,
295 InputEventAckState ack_result
) {
296 scoped_ptr
<IPC::Message
> response(
297 new InputHostMsg_HandleInputEvent_ACK(0, type
, ack_result
,
299 input_router_
->OnMessageReceived(*response
);
302 InputRouterImpl
* input_router() const {
303 return input_router_
.get();
306 bool TouchEventQueueEmpty() const {
307 return input_router()->touch_event_queue_
.empty();
310 bool TouchEventTimeoutEnabled() const {
311 return input_router()->touch_event_queue_
.ack_timeout_enabled();
315 return input_router_
->Flush();
318 size_t GetAndResetDidFlushCount() {
319 return client_
->GetAndResetDidFlushCount();
322 bool HasPendingEvents() const {
323 return input_router_
->HasPendingEvents();
326 void OnHasTouchEventHandlers(bool has_handlers
) {
327 input_router_
->OnMessageReceived(
328 ViewHostMsg_HasTouchEventHandlers(0, has_handlers
));
331 void OnSetTouchAction(content::TouchAction touch_action
) {
332 input_router_
->OnMessageReceived(
333 InputHostMsg_SetTouchAction(0, touch_action
));
336 size_t GetSentMessageCountAndResetSink() {
337 size_t count
= process_
->sink().message_count();
338 process_
->sink().ClearMessages();
342 static void RunTasksAndWait(base::TimeDelta delay
) {
343 base::MessageLoop::current()->PostDelayedTask(
344 FROM_HERE
, base::MessageLoop::QuitClosure(), delay
);
345 base::MessageLoop::current()->Run();
348 InputRouterImpl::Config config_
;
349 scoped_ptr
<MockRenderProcessHost
> process_
;
350 scoped_ptr
<MockInputRouterClient
> client_
;
351 scoped_ptr
<MockInputAckHandler
> ack_handler_
;
352 scoped_ptr
<InputRouterImpl
> input_router_
;
355 base::MessageLoopForUI message_loop_
;
356 SyntheticWebTouchEvent touch_event_
;
358 scoped_ptr
<TestBrowserContext
> browser_context_
;
361 TEST_F(InputRouterImplTest
, CoalescesRangeSelection
) {
362 input_router_
->SendInput(scoped_ptr
<IPC::Message
>(
363 new InputMsg_SelectRange(0, gfx::Point(1, 2), gfx::Point(3, 4))));
364 ExpectIPCMessageWithArg2
<InputMsg_SelectRange
>(
365 process_
->sink().GetMessageAt(0),
368 EXPECT_EQ(1u, GetSentMessageCountAndResetSink());
370 // Send two more messages without acking.
371 input_router_
->SendInput(scoped_ptr
<IPC::Message
>(
372 new InputMsg_SelectRange(0, gfx::Point(5, 6), gfx::Point(7, 8))));
373 EXPECT_EQ(0u, GetSentMessageCountAndResetSink());
375 input_router_
->SendInput(scoped_ptr
<IPC::Message
>(
376 new InputMsg_SelectRange(0, gfx::Point(9, 10), gfx::Point(11, 12))));
377 EXPECT_EQ(0u, GetSentMessageCountAndResetSink());
379 // Now ack the first message.
381 scoped_ptr
<IPC::Message
> response(new ViewHostMsg_SelectRange_ACK(0));
382 input_router_
->OnMessageReceived(*response
);
385 // Verify that the two messages are coalesced into one message.
386 ExpectIPCMessageWithArg2
<InputMsg_SelectRange
>(
387 process_
->sink().GetMessageAt(0),
390 EXPECT_EQ(1u, GetSentMessageCountAndResetSink());
392 // Acking the coalesced msg should not send any more msg.
394 scoped_ptr
<IPC::Message
> response(new ViewHostMsg_SelectRange_ACK(0));
395 input_router_
->OnMessageReceived(*response
);
397 EXPECT_EQ(0u, GetSentMessageCountAndResetSink());
400 TEST_F(InputRouterImplTest
, CoalescesCaretMove
) {
401 input_router_
->SendInput(
402 scoped_ptr
<IPC::Message
>(new InputMsg_MoveCaret(0, gfx::Point(1, 2))));
403 ExpectIPCMessageWithArg1
<InputMsg_MoveCaret
>(
404 process_
->sink().GetMessageAt(0), gfx::Point(1, 2));
405 EXPECT_EQ(1u, GetSentMessageCountAndResetSink());
407 // Send two more messages without acking.
408 input_router_
->SendInput(
409 scoped_ptr
<IPC::Message
>(new InputMsg_MoveCaret(0, gfx::Point(5, 6))));
410 EXPECT_EQ(0u, GetSentMessageCountAndResetSink());
412 input_router_
->SendInput(
413 scoped_ptr
<IPC::Message
>(new InputMsg_MoveCaret(0, gfx::Point(9, 10))));
414 EXPECT_EQ(0u, GetSentMessageCountAndResetSink());
416 // Now ack the first message.
418 scoped_ptr
<IPC::Message
> response(new ViewHostMsg_MoveCaret_ACK(0));
419 input_router_
->OnMessageReceived(*response
);
422 // Verify that the two messages are coalesced into one message.
423 ExpectIPCMessageWithArg1
<InputMsg_MoveCaret
>(
424 process_
->sink().GetMessageAt(0), gfx::Point(9, 10));
425 EXPECT_EQ(1u, GetSentMessageCountAndResetSink());
427 // Acking the coalesced msg should not send any more msg.
429 scoped_ptr
<IPC::Message
> response(new ViewHostMsg_MoveCaret_ACK(0));
430 input_router_
->OnMessageReceived(*response
);
432 EXPECT_EQ(0u, GetSentMessageCountAndResetSink());
435 TEST_F(InputRouterImplTest
, HandledInputEvent
) {
436 client_
->set_filter_state(INPUT_EVENT_ACK_STATE_CONSUMED
);
438 // Simulate a keyboard event.
439 SimulateKeyboardEvent(WebInputEvent::RawKeyDown
, false);
441 // Make sure no input event is sent to the renderer.
442 EXPECT_EQ(0u, GetSentMessageCountAndResetSink());
444 // OnKeyboardEventAck should be triggered without actual ack.
445 EXPECT_EQ(1U, ack_handler_
->GetAndResetAckCount());
447 // As the event was acked already, keyboard event queue should be
449 ASSERT_EQ(NULL
, input_router_
->GetLastKeyboardEvent());
452 TEST_F(InputRouterImplTest
, ClientCanceledKeyboardEvent
) {
453 client_
->set_filter_state(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS
);
455 // Simulate a keyboard event that has no consumer.
456 SimulateKeyboardEvent(WebInputEvent::RawKeyDown
, false);
458 // Make sure no input event is sent to the renderer.
459 EXPECT_EQ(0u, GetSentMessageCountAndResetSink());
460 EXPECT_EQ(1U, ack_handler_
->GetAndResetAckCount());
463 // Simulate a keyboard event that should be dropped.
464 client_
->set_filter_state(INPUT_EVENT_ACK_STATE_UNKNOWN
);
465 SimulateKeyboardEvent(WebInputEvent::RawKeyDown
, false);
467 // Make sure no input event is sent to the renderer, and no ack is sent.
468 EXPECT_EQ(0u, GetSentMessageCountAndResetSink());
469 EXPECT_EQ(0U, ack_handler_
->GetAndResetAckCount());
472 TEST_F(InputRouterImplTest
, ShortcutKeyboardEvent
) {
473 SimulateKeyboardEvent(WebInputEvent::RawKeyDown
, true);
474 EXPECT_TRUE(GetIsShortcutFromHandleInputEventMessage(
475 process_
->sink().GetMessageAt(0)));
477 process_
->sink().ClearMessages();
479 SimulateKeyboardEvent(WebInputEvent::RawKeyDown
, false);
480 EXPECT_FALSE(GetIsShortcutFromHandleInputEventMessage(
481 process_
->sink().GetMessageAt(0)));
484 TEST_F(InputRouterImplTest
, NoncorrespondingKeyEvents
) {
485 SimulateKeyboardEvent(WebInputEvent::RawKeyDown
, false);
487 SendInputEventACK(WebInputEvent::KeyUp
,
488 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
489 EXPECT_TRUE(ack_handler_
->unexpected_event_ack_called());
492 // Tests ported from RenderWidgetHostTest --------------------------------------
494 TEST_F(InputRouterImplTest
, HandleKeyEventsWeSent
) {
495 // Simulate a keyboard event.
496 SimulateKeyboardEvent(WebInputEvent::RawKeyDown
, false);
497 ASSERT_TRUE(input_router_
->GetLastKeyboardEvent());
498 EXPECT_EQ(WebInputEvent::RawKeyDown
,
499 input_router_
->GetLastKeyboardEvent()->type
);
501 // Make sure we sent the input event to the renderer.
502 EXPECT_TRUE(process_
->sink().GetUniqueMessageMatching(
503 InputMsg_HandleInputEvent::ID
));
504 process_
->sink().ClearMessages();
506 // Send the simulated response from the renderer back.
507 SendInputEventACK(WebInputEvent::RawKeyDown
,
508 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
509 EXPECT_EQ(1U, ack_handler_
->GetAndResetAckCount());
510 EXPECT_EQ(WebInputEvent::RawKeyDown
,
511 ack_handler_
->acked_keyboard_event().type
);
514 TEST_F(InputRouterImplTest
, IgnoreKeyEventsWeDidntSend
) {
515 // Send a simulated, unrequested key response. We should ignore this.
516 SendInputEventACK(WebInputEvent::RawKeyDown
,
517 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
519 EXPECT_EQ(0U, ack_handler_
->GetAndResetAckCount());
522 TEST_F(InputRouterImplTest
, CoalescesWheelEvents
) {
523 // Simulate wheel events.
524 SimulateWheelEvent(0, -5, 0, false); // sent directly
525 SimulateWheelEvent(0, -10, 0, false); // enqueued
526 SimulateWheelEvent(8, -6, 0, false); // coalesced into previous event
527 SimulateWheelEvent(9, -7, 1, false); // enqueued, different modifiers
528 SimulateWheelEvent(0, -10, 0, false); // enqueued, different modifiers
529 // Explicitly verify that PhaseEnd isn't coalesced to avoid bugs like
530 // https://crbug.com/154740.
531 SimulateWheelEventWithPhase(WebMouseWheelEvent::PhaseEnded
); // enqueued
533 // Check that only the first event was sent.
534 EXPECT_TRUE(process_
->sink().GetUniqueMessageMatching(
535 InputMsg_HandleInputEvent::ID
));
536 const WebInputEvent
* input_event
=
537 GetInputEventFromMessage(*process_
->sink().GetMessageAt(0));
538 ASSERT_EQ(WebInputEvent::MouseWheel
, input_event
->type
);
539 const WebMouseWheelEvent
* wheel_event
=
540 static_cast<const WebMouseWheelEvent
*>(input_event
);
541 EXPECT_EQ(0, wheel_event
->deltaX
);
542 EXPECT_EQ(-5, wheel_event
->deltaY
);
543 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
545 // Check that the ACK sends the second message immediately.
546 SendInputEventACK(WebInputEvent::MouseWheel
,
547 INPUT_EVENT_ACK_STATE_CONSUMED
);
548 // The coalesced events can queue up a delayed ack
549 // so that additional input events can be processed before
550 // we turn off coalescing.
551 base::MessageLoop::current()->RunUntilIdle();
552 EXPECT_EQ(1U, ack_handler_
->GetAndResetAckCount());
553 EXPECT_TRUE(process_
->sink().GetUniqueMessageMatching(
554 InputMsg_HandleInputEvent::ID
));
555 input_event
= GetInputEventFromMessage(*process_
->sink().GetMessageAt(0));
556 ASSERT_EQ(WebInputEvent::MouseWheel
, input_event
->type
);
557 wheel_event
= static_cast<const WebMouseWheelEvent
*>(input_event
);
558 EXPECT_EQ(8, wheel_event
->deltaX
);
559 EXPECT_EQ(-10 + -6, wheel_event
->deltaY
); // coalesced
560 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
562 // Ack the second event (which had the third coalesced into it).
563 SendInputEventACK(WebInputEvent::MouseWheel
,
564 INPUT_EVENT_ACK_STATE_CONSUMED
);
565 base::MessageLoop::current()->RunUntilIdle();
566 EXPECT_EQ(1U, ack_handler_
->GetAndResetAckCount());
567 EXPECT_TRUE(process_
->sink().GetUniqueMessageMatching(
568 InputMsg_HandleInputEvent::ID
));
569 input_event
= GetInputEventFromMessage(*process_
->sink().GetMessageAt(0));
570 ASSERT_EQ(WebInputEvent::MouseWheel
, input_event
->type
);
571 wheel_event
= static_cast<const WebMouseWheelEvent
*>(input_event
);
572 EXPECT_EQ(9, wheel_event
->deltaX
);
573 EXPECT_EQ(-7, wheel_event
->deltaY
);
574 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
576 // Ack the fourth event.
577 SendInputEventACK(WebInputEvent::MouseWheel
,
578 INPUT_EVENT_ACK_STATE_CONSUMED
);
579 base::MessageLoop::current()->RunUntilIdle();
580 EXPECT_EQ(1U, ack_handler_
->GetAndResetAckCount());
582 process_
->sink().GetUniqueMessageMatching(InputMsg_HandleInputEvent::ID
));
583 input_event
= GetInputEventFromMessage(*process_
->sink().GetMessageAt(0));
584 ASSERT_EQ(WebInputEvent::MouseWheel
, input_event
->type
);
585 wheel_event
= static_cast<const WebMouseWheelEvent
*>(input_event
);
586 EXPECT_EQ(0, wheel_event
->deltaX
);
587 EXPECT_EQ(-10, wheel_event
->deltaY
);
588 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
590 // Ack the fifth event.
591 SendInputEventACK(WebInputEvent::MouseWheel
, INPUT_EVENT_ACK_STATE_CONSUMED
);
592 base::MessageLoop::current()->RunUntilIdle();
593 EXPECT_EQ(1U, ack_handler_
->GetAndResetAckCount());
595 process_
->sink().GetUniqueMessageMatching(InputMsg_HandleInputEvent::ID
));
596 input_event
= GetInputEventFromMessage(*process_
->sink().GetMessageAt(0));
597 ASSERT_EQ(WebInputEvent::MouseWheel
, input_event
->type
);
598 wheel_event
= static_cast<const WebMouseWheelEvent
*>(input_event
);
599 EXPECT_EQ(0, wheel_event
->deltaX
);
600 EXPECT_EQ(0, wheel_event
->deltaY
);
601 EXPECT_EQ(WebMouseWheelEvent::PhaseEnded
, wheel_event
->phase
);
602 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
604 // After the final ack, the queue should be empty.
605 SendInputEventACK(WebInputEvent::MouseWheel
, INPUT_EVENT_ACK_STATE_CONSUMED
);
606 base::MessageLoop::current()->RunUntilIdle();
607 EXPECT_EQ(1U, ack_handler_
->GetAndResetAckCount());
608 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
611 // Tests that touch-events are queued properly.
612 TEST_F(InputRouterImplTest
, TouchEventQueue
) {
613 OnHasTouchEventHandlers(true);
615 PressTouchPoint(1, 1);
617 EXPECT_TRUE(client_
->GetAndResetFilterEventCalled());
618 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
619 EXPECT_FALSE(TouchEventQueueEmpty());
621 // The second touch should not be sent since one is already in queue.
622 MoveTouchPoint(0, 5, 5);
624 EXPECT_FALSE(client_
->GetAndResetFilterEventCalled());
625 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
626 EXPECT_FALSE(TouchEventQueueEmpty());
628 // Receive an ACK for the first touch-event.
629 SendInputEventACK(WebInputEvent::TouchStart
,
630 INPUT_EVENT_ACK_STATE_CONSUMED
);
631 EXPECT_FALSE(TouchEventQueueEmpty());
632 EXPECT_EQ(1U, ack_handler_
->GetAndResetAckCount());
633 EXPECT_EQ(WebInputEvent::TouchStart
,
634 ack_handler_
->acked_touch_event().event
.type
);
635 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
637 SendInputEventACK(WebInputEvent::TouchMove
,
638 INPUT_EVENT_ACK_STATE_CONSUMED
);
639 EXPECT_TRUE(TouchEventQueueEmpty());
640 EXPECT_EQ(1U, ack_handler_
->GetAndResetAckCount());
641 EXPECT_EQ(WebInputEvent::TouchMove
,
642 ack_handler_
->acked_touch_event().event
.type
);
643 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
646 // Tests that the touch-queue is emptied if a page stops listening for touch
648 TEST_F(InputRouterImplTest
, TouchEventQueueFlush
) {
649 OnHasTouchEventHandlers(true);
650 EXPECT_TRUE(client_
->has_touch_handler());
651 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
652 EXPECT_TRUE(TouchEventQueueEmpty());
654 EXPECT_TRUE(input_router_
->ShouldForwardTouchEvent());
656 // Send a touch-press event.
657 PressTouchPoint(1, 1);
659 EXPECT_FALSE(TouchEventQueueEmpty());
660 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
662 // The page stops listening for touch-events. The touch-event queue should now
663 // be emptied, but none of the queued touch-events should be sent to the
665 OnHasTouchEventHandlers(false);
666 EXPECT_FALSE(client_
->has_touch_handler());
667 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
668 EXPECT_TRUE(TouchEventQueueEmpty());
669 EXPECT_FALSE(input_router_
->ShouldForwardTouchEvent());
672 #if defined(USE_AURA)
673 // Tests that the acked events have correct state. (ui::Events are used only on
675 TEST_F(InputRouterImplTest
, AckedTouchEventState
) {
676 input_router_
->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true));
677 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
678 EXPECT_TRUE(TouchEventQueueEmpty());
679 EXPECT_TRUE(input_router_
->ShouldForwardTouchEvent());
681 // Send a bunch of events, and make sure the ACKed events are correct.
682 ScopedVector
<ui::TouchEvent
> expected_events
;
684 // Use a custom timestamp for all the events to test that the acked events
685 // have the same timestamp;
686 base::TimeDelta timestamp
= base::Time::NowFromSystemTime() - base::Time();
687 timestamp
-= base::TimeDelta::FromSeconds(600);
689 // Press the first finger.
690 PressTouchPoint(1, 1);
691 SetTouchTimestamp(timestamp
);
693 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
694 expected_events
.push_back(new ui::TouchEvent(ui::ET_TOUCH_PRESSED
,
695 gfx::Point(1, 1), 0, timestamp
));
698 timestamp
+= base::TimeDelta::FromSeconds(10);
699 MoveTouchPoint(0, 500, 500);
700 SetTouchTimestamp(timestamp
);
702 EXPECT_FALSE(TouchEventQueueEmpty());
703 expected_events
.push_back(new ui::TouchEvent(ui::ET_TOUCH_MOVED
,
704 gfx::Point(500, 500), 0, timestamp
));
706 // Now press a second finger.
707 timestamp
+= base::TimeDelta::FromSeconds(10);
708 PressTouchPoint(2, 2);
709 SetTouchTimestamp(timestamp
);
711 EXPECT_FALSE(TouchEventQueueEmpty());
712 expected_events
.push_back(new ui::TouchEvent(ui::ET_TOUCH_PRESSED
,
713 gfx::Point(2, 2), 1, timestamp
));
715 // Move both fingers.
716 timestamp
+= base::TimeDelta::FromSeconds(10);
717 MoveTouchPoint(0, 10, 10);
718 MoveTouchPoint(1, 20, 20);
719 SetTouchTimestamp(timestamp
);
721 EXPECT_FALSE(TouchEventQueueEmpty());
722 expected_events
.push_back(new ui::TouchEvent(ui::ET_TOUCH_MOVED
,
723 gfx::Point(10, 10), 0, timestamp
));
724 expected_events
.push_back(new ui::TouchEvent(ui::ET_TOUCH_MOVED
,
725 gfx::Point(20, 20), 1, timestamp
));
727 // Receive the ACKs and make sure the generated events from the acked events
729 WebInputEvent::Type acks
[] = { WebInputEvent::TouchStart
,
730 WebInputEvent::TouchMove
,
731 WebInputEvent::TouchStart
,
732 WebInputEvent::TouchMove
};
734 TouchEventCoordinateSystem coordinate_system
= LOCAL_COORDINATES
;
736 coordinate_system
= SCREEN_COORDINATES
;
738 for (size_t i
= 0; i
< arraysize(acks
); ++i
) {
739 SendInputEventACK(acks
[i
],
740 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
741 EXPECT_EQ(acks
[i
], ack_handler_
->acked_touch_event().event
.type
);
742 ScopedVector
<ui::TouchEvent
> acked
;
744 MakeUITouchEventsFromWebTouchEvents(
745 ack_handler_
->acked_touch_event(), &acked
, coordinate_system
);
746 bool success
= EventListIsSubset(acked
, expected_events
);
747 EXPECT_TRUE(success
) << "Failed on step: " << i
;
750 expected_events
.erase(expected_events
.begin(),
751 expected_events
.begin() + acked
.size());
754 EXPECT_TRUE(TouchEventQueueEmpty());
755 EXPECT_EQ(0U, expected_events
.size());
757 #endif // defined(USE_AURA)
759 TEST_F(InputRouterImplTest
, UnhandledWheelEvent
) {
760 // Simulate wheel events.
761 SimulateWheelEvent(0, -5, 0, false); // sent directly
762 SimulateWheelEvent(0, -10, 0, false); // enqueued
764 // Check that only the first event was sent.
765 EXPECT_TRUE(process_
->sink().GetUniqueMessageMatching(
766 InputMsg_HandleInputEvent::ID
));
767 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
769 // Indicate that the wheel event was unhandled.
770 SendInputEventACK(WebInputEvent::MouseWheel
,
771 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
773 // Check that the correct unhandled wheel event was received.
774 EXPECT_EQ(1U, ack_handler_
->GetAndResetAckCount());
775 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
, ack_handler_
->ack_state());
776 EXPECT_EQ(ack_handler_
->acked_wheel_event().deltaY
, -5);
778 // Check that the second event was sent.
779 EXPECT_TRUE(process_
->sink().GetUniqueMessageMatching(
780 InputMsg_HandleInputEvent::ID
));
781 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
783 // Check that the correct unhandled wheel event was received.
784 EXPECT_EQ(ack_handler_
->acked_wheel_event().deltaY
, -5);
787 TEST_F(InputRouterImplTest
, TouchTypesIgnoringAck
) {
788 OnHasTouchEventHandlers(true);
790 int start_type
= static_cast<int>(WebInputEvent::TouchStart
);
791 int end_type
= static_cast<int>(WebInputEvent::TouchCancel
);
792 ASSERT_LT(start_type
, end_type
);
793 for (int i
= start_type
; i
<= end_type
; ++i
) {
794 WebInputEvent::Type type
= static_cast<WebInputEvent::Type
>(i
);
795 if (!WebInputEventTraits::IgnoresAckDisposition(GetEventWithType(type
)))
798 // The TouchEventQueue requires an initial TouchStart for it to begin
799 // forwarding other touch event types.
800 if (type
!= WebInputEvent::TouchStart
) {
801 SimulateTouchEvent(WebInputEvent::TouchStart
);
802 SendInputEventACK(WebInputEvent::TouchStart
,
803 INPUT_EVENT_ACK_STATE_CONSUMED
);
804 ASSERT_EQ(1U, GetSentMessageCountAndResetSink());
805 ASSERT_EQ(1U, ack_handler_
->GetAndResetAckCount());
806 ASSERT_EQ(0, client_
->in_flight_event_count());
809 SimulateTouchEvent(type
);
810 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
811 EXPECT_EQ(1U, ack_handler_
->GetAndResetAckCount());
812 EXPECT_EQ(0, client_
->in_flight_event_count());
813 EXPECT_FALSE(HasPendingEvents());
814 SendInputEventACK(type
, INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
815 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
816 EXPECT_EQ(0U, ack_handler_
->GetAndResetAckCount());
817 EXPECT_FALSE(HasPendingEvents());
821 TEST_F(InputRouterImplTest
, GestureTypesIgnoringAck
) {
822 // We test every gesture type, ensuring that the stream of gestures is valid.
823 const int kEventTypesLength
= 29;
824 WebInputEvent::Type eventTypes
[kEventTypesLength
] = {
825 WebInputEvent::GestureTapDown
,
826 WebInputEvent::GestureShowPress
,
827 WebInputEvent::GestureTapCancel
,
828 WebInputEvent::GestureScrollBegin
,
829 WebInputEvent::GestureFlingStart
,
830 WebInputEvent::GestureFlingCancel
,
831 WebInputEvent::GestureTapDown
,
832 WebInputEvent::GestureTap
,
833 WebInputEvent::GestureTapDown
,
834 WebInputEvent::GestureLongPress
,
835 WebInputEvent::GestureTapCancel
,
836 WebInputEvent::GestureLongTap
,
837 WebInputEvent::GestureTapDown
,
838 WebInputEvent::GestureTapUnconfirmed
,
839 WebInputEvent::GestureTapCancel
,
840 WebInputEvent::GestureTapDown
,
841 WebInputEvent::GestureDoubleTap
,
842 WebInputEvent::GestureTapDown
,
843 WebInputEvent::GestureTapCancel
,
844 WebInputEvent::GestureTwoFingerTap
,
845 WebInputEvent::GestureTapDown
,
846 WebInputEvent::GestureTapCancel
,
847 WebInputEvent::GestureScrollBegin
,
848 WebInputEvent::GestureScrollUpdate
,
849 WebInputEvent::GestureScrollUpdateWithoutPropagation
,
850 WebInputEvent::GesturePinchBegin
,
851 WebInputEvent::GesturePinchUpdate
,
852 WebInputEvent::GesturePinchEnd
,
853 WebInputEvent::GestureScrollEnd
};
854 for (int i
= 0; i
< kEventTypesLength
; ++i
) {
855 WebInputEvent::Type type
= eventTypes
[i
];
856 if (!WebInputEventTraits::IgnoresAckDisposition(GetEventWithType(type
))) {
857 SimulateGestureEvent(type
, WebGestureEvent::Touchscreen
);
858 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
859 EXPECT_EQ(0U, ack_handler_
->GetAndResetAckCount());
860 EXPECT_EQ(1, client_
->in_flight_event_count());
861 EXPECT_TRUE(HasPendingEvents());
863 SendInputEventACK(type
, INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
864 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
865 EXPECT_EQ(1U, ack_handler_
->GetAndResetAckCount());
866 EXPECT_EQ(0, client_
->in_flight_event_count());
867 EXPECT_FALSE(HasPendingEvents());
871 SimulateGestureEvent(type
, WebGestureEvent::Touchscreen
);
872 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
873 EXPECT_EQ(1U, ack_handler_
->GetAndResetAckCount());
874 EXPECT_EQ(0, client_
->in_flight_event_count());
875 EXPECT_FALSE(HasPendingEvents());
879 TEST_F(InputRouterImplTest
, MouseTypesIgnoringAck
) {
880 int start_type
= static_cast<int>(WebInputEvent::MouseDown
);
881 int end_type
= static_cast<int>(WebInputEvent::ContextMenu
);
882 ASSERT_LT(start_type
, end_type
);
883 for (int i
= start_type
; i
<= end_type
; ++i
) {
884 WebInputEvent::Type type
= static_cast<WebInputEvent::Type
>(i
);
885 int expected_in_flight_event_count
=
886 WebInputEventTraits::IgnoresAckDisposition(GetEventWithType(type
)) ? 0
889 // Note: Mouse event acks are never forwarded to the ack handler, so the key
890 // result here is that ignored ack types don't affect the in-flight count.
891 SimulateMouseEvent(type
, 0, 0);
892 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
893 EXPECT_EQ(0U, ack_handler_
->GetAndResetAckCount());
894 EXPECT_EQ(expected_in_flight_event_count
, client_
->in_flight_event_count());
895 if (expected_in_flight_event_count
) {
896 SendInputEventACK(type
, INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
897 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
898 EXPECT_EQ(0U, ack_handler_
->GetAndResetAckCount());
899 EXPECT_EQ(0, client_
->in_flight_event_count());
904 // Guard against breaking changes to the list of ignored event ack types in
905 // |WebInputEventTraits::IgnoresAckDisposition|.
906 TEST_F(InputRouterImplTest
, RequiredEventAckTypes
) {
907 const WebInputEvent::Type kRequiredEventAckTypes
[] = {
908 WebInputEvent::MouseMove
,
909 WebInputEvent::MouseWheel
,
910 WebInputEvent::RawKeyDown
,
911 WebInputEvent::KeyDown
,
912 WebInputEvent::KeyUp
,
914 WebInputEvent::GestureScrollUpdate
,
915 WebInputEvent::GestureFlingStart
,
916 WebInputEvent::GestureFlingCancel
,
917 WebInputEvent::GesturePinchUpdate
,
918 WebInputEvent::TouchStart
,
919 WebInputEvent::TouchMove
921 for (size_t i
= 0; i
< arraysize(kRequiredEventAckTypes
); ++i
) {
922 const WebInputEvent::Type required_ack_type
= kRequiredEventAckTypes
[i
];
923 EXPECT_FALSE(WebInputEventTraits::IgnoresAckDisposition(
924 GetEventWithType(required_ack_type
)));
928 // Test that GestureShowPress, GestureTapDown and GestureTapCancel events don't
930 TEST_F(InputRouterImplTest
, GestureTypesIgnoringAckInterleaved
) {
931 // Interleave a few events that do and do not ignore acks, ensuring that
932 // ack-ignoring events aren't dispatched until all prior events which observe
933 // their ack disposition have been dispatched.
935 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
936 WebGestureEvent::Touchscreen
);
937 ASSERT_EQ(1U, GetSentMessageCountAndResetSink());
938 EXPECT_EQ(1U, ack_handler_
->GetAndResetAckCount());
939 EXPECT_EQ(0, client_
->in_flight_event_count());
941 SimulateGestureEvent(WebInputEvent::GestureScrollUpdate
,
942 WebGestureEvent::Touchscreen
);
943 ASSERT_EQ(1U, GetSentMessageCountAndResetSink());
944 EXPECT_EQ(0U, ack_handler_
->GetAndResetAckCount());
945 EXPECT_EQ(1, client_
->in_flight_event_count());
947 SimulateGestureEvent(WebInputEvent::GestureTapDown
,
948 WebGestureEvent::Touchscreen
);
949 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
950 EXPECT_EQ(0U, ack_handler_
->GetAndResetAckCount());
951 EXPECT_EQ(1, client_
->in_flight_event_count());
953 SimulateGestureEvent(WebInputEvent::GestureScrollUpdate
,
954 WebGestureEvent::Touchscreen
);
955 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
956 EXPECT_EQ(0U, ack_handler_
->GetAndResetAckCount());
958 SimulateGestureEvent(WebInputEvent::GestureShowPress
,
959 WebGestureEvent::Touchscreen
);
960 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
961 EXPECT_EQ(0U, ack_handler_
->GetAndResetAckCount());
963 SimulateGestureEvent(WebInputEvent::GestureScrollUpdate
,
964 WebGestureEvent::Touchscreen
);
965 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
966 EXPECT_EQ(0U, ack_handler_
->GetAndResetAckCount());
968 SimulateGestureEvent(WebInputEvent::GestureTapCancel
,
969 WebGestureEvent::Touchscreen
);
970 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
971 EXPECT_EQ(0U, ack_handler_
->GetAndResetAckCount());
973 // Now ack each ack-respecting event. Ack-ignoring events should not be
974 // dispatched until all prior events which observe ack disposition have been
975 // fired, at which point they should be sent immediately. They should also
976 // have no effect on the in-flight event count.
977 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
978 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
979 EXPECT_EQ(2U, GetSentMessageCountAndResetSink());
980 EXPECT_EQ(2U, ack_handler_
->GetAndResetAckCount());
981 EXPECT_EQ(1, client_
->in_flight_event_count());
983 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
984 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
985 EXPECT_EQ(2U, GetSentMessageCountAndResetSink());
986 EXPECT_EQ(2U, ack_handler_
->GetAndResetAckCount());
987 EXPECT_EQ(1, client_
->in_flight_event_count());
989 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
990 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
991 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
992 EXPECT_EQ(2U, ack_handler_
->GetAndResetAckCount());
993 EXPECT_EQ(0, client_
->in_flight_event_count());
996 // Test that GestureShowPress events don't get out of order due to
997 // ignoring their acks.
998 TEST_F(InputRouterImplTest
, GestureShowPressIsInOrder
) {
999 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
1000 WebGestureEvent::Touchscreen
);
1001 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1002 EXPECT_EQ(1U, ack_handler_
->GetAndResetAckCount());
1005 // GesturePinchBegin ignores its ack.
1006 SimulateGestureEvent(WebInputEvent::GesturePinchBegin
,
1007 WebGestureEvent::Touchscreen
);
1008 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1009 EXPECT_EQ(1U, ack_handler_
->GetAndResetAckCount());
1011 // GesturePinchUpdate waits for an ack.
1012 // This also verifies that GesturePinchUpdates for touchscreen are sent
1013 // to the renderer (in contrast to the TrackpadPinchUpdate test).
1014 SimulateGestureEvent(WebInputEvent::GesturePinchUpdate
,
1015 WebGestureEvent::Touchscreen
);
1016 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1017 EXPECT_EQ(0U, ack_handler_
->GetAndResetAckCount());
1019 SimulateGestureEvent(WebInputEvent::GestureShowPress
,
1020 WebGestureEvent::Touchscreen
);
1021 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1022 // The ShowPress, though it ignores ack, is still stuck in the queue
1023 // behind the PinchUpdate which requires an ack.
1024 EXPECT_EQ(0U, ack_handler_
->GetAndResetAckCount());
1026 SimulateGestureEvent(WebInputEvent::GestureShowPress
,
1027 WebGestureEvent::Touchscreen
);
1028 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1029 // ShowPress has entered the queue.
1030 EXPECT_EQ(0U, ack_handler_
->GetAndResetAckCount());
1032 SendInputEventACK(WebInputEvent::GesturePinchUpdate
,
1033 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1034 // Now that the Tap has been ACKed, the ShowPress events should receive
1035 // synthetic acks, and fire immediately.
1036 EXPECT_EQ(2U, GetSentMessageCountAndResetSink());
1037 EXPECT_EQ(3U, ack_handler_
->GetAndResetAckCount());
1040 // Test that touch ack timeout behavior is properly toggled by view update flags
1041 // and allowed touch actions.
1042 TEST_F(InputRouterImplTest
, TouchAckTimeoutConfigured
) {
1043 const int timeout_ms
= 1;
1044 SetUpForTouchAckTimeoutTest(timeout_ms
);
1045 ASSERT_TRUE(TouchEventTimeoutEnabled());
1047 // Verify that the touch ack timeout fires upon the delayed ack.
1048 PressTouchPoint(1, 1);
1050 EXPECT_EQ(0U, ack_handler_
->GetAndResetAckCount());
1051 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1052 RunTasksAndWait(base::TimeDelta::FromMilliseconds(timeout_ms
+ 1));
1054 // The timed-out event should have been ack'ed.
1055 EXPECT_EQ(1U, ack_handler_
->GetAndResetAckCount());
1056 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1058 // Ack'ing the timed-out event should fire a TouchCancel.
1059 SendInputEventACK(WebInputEvent::TouchStart
, INPUT_EVENT_ACK_STATE_CONSUMED
);
1060 EXPECT_EQ(0U, ack_handler_
->GetAndResetAckCount());
1061 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1063 // The remainder of the touch sequence should be dropped.
1064 ReleaseTouchPoint(0);
1066 EXPECT_EQ(1U, ack_handler_
->GetAndResetAckCount());
1067 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1068 ASSERT_TRUE(TouchEventTimeoutEnabled());
1070 // A fixed page scale or mobile viewport should disable the touch timeout.
1071 input_router()->OnViewUpdated(InputRouter::FIXED_PAGE_SCALE
);
1072 EXPECT_FALSE(TouchEventTimeoutEnabled());
1074 input_router()->OnViewUpdated(InputRouter::VIEW_FLAGS_NONE
);
1075 EXPECT_TRUE(TouchEventTimeoutEnabled());
1077 input_router()->OnViewUpdated(InputRouter::MOBILE_VIEWPORT
);
1078 EXPECT_FALSE(TouchEventTimeoutEnabled());
1080 input_router()->OnViewUpdated(InputRouter::MOBILE_VIEWPORT
|
1081 InputRouter::FIXED_PAGE_SCALE
);
1082 EXPECT_FALSE(TouchEventTimeoutEnabled());
1084 input_router()->OnViewUpdated(InputRouter::VIEW_FLAGS_NONE
);
1085 EXPECT_TRUE(TouchEventTimeoutEnabled());
1087 // TOUCH_ACTION_NONE (and no other touch-action) should disable the timeout.
1088 OnHasTouchEventHandlers(true);
1089 PressTouchPoint(1, 1);
1091 OnSetTouchAction(TOUCH_ACTION_PAN_Y
);
1092 EXPECT_TRUE(TouchEventTimeoutEnabled());
1093 ReleaseTouchPoint(0);
1095 SendInputEventACK(WebInputEvent::TouchStart
, INPUT_EVENT_ACK_STATE_CONSUMED
);
1096 SendInputEventACK(WebInputEvent::TouchEnd
, INPUT_EVENT_ACK_STATE_CONSUMED
);
1098 PressTouchPoint(1, 1);
1100 OnSetTouchAction(TOUCH_ACTION_NONE
);
1101 EXPECT_FALSE(TouchEventTimeoutEnabled());
1102 ReleaseTouchPoint(0);
1104 SendInputEventACK(WebInputEvent::TouchStart
, INPUT_EVENT_ACK_STATE_CONSUMED
);
1105 SendInputEventACK(WebInputEvent::TouchEnd
, INPUT_EVENT_ACK_STATE_CONSUMED
);
1107 // As the touch-action is reset by a new touch sequence, the timeout behavior
1108 // should be restored.
1109 PressTouchPoint(1, 1);
1111 EXPECT_TRUE(TouchEventTimeoutEnabled());
1114 // Test that a touch sequenced preceded by TOUCH_ACTION_NONE is not affected by
1115 // the touch timeout.
1116 TEST_F(InputRouterImplTest
,
1117 TouchAckTimeoutDisabledForTouchSequenceAfterTouchActionNone
) {
1118 const int timeout_ms
= 1;
1119 SetUpForTouchAckTimeoutTest(timeout_ms
);
1120 ASSERT_TRUE(TouchEventTimeoutEnabled());
1121 OnHasTouchEventHandlers(true);
1123 // Start a touch sequence.
1124 PressTouchPoint(1, 1);
1127 // TOUCH_ACTION_NONE should disable the timeout.
1128 OnSetTouchAction(TOUCH_ACTION_NONE
);
1129 SendInputEventACK(WebInputEvent::TouchStart
, INPUT_EVENT_ACK_STATE_CONSUMED
);
1130 EXPECT_FALSE(TouchEventTimeoutEnabled());
1132 // End the touch sequence.
1133 ReleaseTouchPoint(0);
1135 SendInputEventACK(WebInputEvent::TouchEnd
, INPUT_EVENT_ACK_STATE_CONSUMED
);
1136 EXPECT_FALSE(TouchEventTimeoutEnabled());
1137 ack_handler_
->GetAndResetAckCount();
1138 GetSentMessageCountAndResetSink();
1140 // Start another touch sequence. While this does restore the touch timeout
1141 // the timeout will not apply until the *next* touch sequence. This affords a
1142 // touch-action response from the renderer without racing against the timeout.
1143 PressTouchPoint(1, 1);
1145 EXPECT_TRUE(TouchEventTimeoutEnabled());
1146 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1148 // Delay the ack. The timeout should *not* fire.
1149 RunTasksAndWait(base::TimeDelta::FromMilliseconds(timeout_ms
+ 1));
1150 EXPECT_EQ(0U, ack_handler_
->GetAndResetAckCount());
1151 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1153 // Finally send the ack. The touch sequence should not have been cancelled.
1154 SendInputEventACK(WebInputEvent::TouchStart
,
1155 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1156 EXPECT_TRUE(TouchEventTimeoutEnabled());
1157 EXPECT_EQ(1U, ack_handler_
->GetAndResetAckCount());
1158 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1160 // End the sequence.
1161 ReleaseTouchPoint(0);
1163 SendInputEventACK(WebInputEvent::TouchEnd
, INPUT_EVENT_ACK_STATE_CONSUMED
);
1164 EXPECT_EQ(1U, ack_handler_
->GetAndResetAckCount());
1165 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1167 // A new touch sequence should (finally) be subject to the timeout.
1168 PressTouchPoint(1, 1);
1170 EXPECT_TRUE(TouchEventTimeoutEnabled());
1171 EXPECT_EQ(0U, ack_handler_
->GetAndResetAckCount());
1172 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1174 // Wait for the touch ack timeout to fire.
1175 RunTasksAndWait(base::TimeDelta::FromMilliseconds(timeout_ms
+ 1));
1176 EXPECT_EQ(1U, ack_handler_
->GetAndResetAckCount());
1179 // Test that TouchActionFilter::ResetTouchAction is called before the
1180 // first touch event for a touch sequence reaches the renderer.
1181 TEST_F(InputRouterImplTest
, ResetTouchActionBeforeEventReachesRenderer
) {
1182 OnHasTouchEventHandlers(true);
1185 PressTouchPoint(1, 1);
1187 OnSetTouchAction(TOUCH_ACTION_NONE
);
1188 MoveTouchPoint(0, 5, 5);
1190 ReleaseTouchPoint(0);
1194 PressTouchPoint(1, 1);
1196 MoveTouchPoint(0, 5, 5);
1198 ReleaseTouchPoint(0);
1201 SendInputEventACK(WebInputEvent::TouchStart
, INPUT_EVENT_ACK_STATE_CONSUMED
);
1202 SendInputEventACK(WebInputEvent::TouchMove
, INPUT_EVENT_ACK_STATE_CONSUMED
);
1204 // Ensure touch action is still none, as the next touch start hasn't been
1205 // acked yet. ScrollBegin and ScrollEnd don't require acks.
1206 EXPECT_EQ(3U, GetSentMessageCountAndResetSink());
1207 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
1208 WebGestureEvent::Touchpad
);
1209 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1210 SimulateGestureEvent(WebInputEvent::GestureScrollEnd
,
1211 WebGestureEvent::Touchpad
);
1212 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1214 // This allows the next touch sequence to start.
1215 SendInputEventACK(WebInputEvent::TouchEnd
, INPUT_EVENT_ACK_STATE_CONSUMED
);
1217 // Ensure touch action has been set to auto, as a new touch sequence has
1219 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1220 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
1221 WebGestureEvent::Touchpad
);
1222 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1223 SimulateGestureEvent(WebInputEvent::GestureScrollEnd
,
1224 WebGestureEvent::Touchpad
);
1225 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1227 SendInputEventACK(WebInputEvent::TouchStart
, INPUT_EVENT_ACK_STATE_CONSUMED
);
1228 SendInputEventACK(WebInputEvent::TouchMove
, INPUT_EVENT_ACK_STATE_CONSUMED
);
1229 SendInputEventACK(WebInputEvent::TouchEnd
, INPUT_EVENT_ACK_STATE_CONSUMED
);
1232 // Test that TouchActionFilter::OnStartNewTouchSequence is called when a touch
1233 // handler is removed.
1234 TEST_F(InputRouterImplTest
, OnStartNewTouchSequenceWhenTouchHandlerRemoved
) {
1235 OnHasTouchEventHandlers(true);
1238 PressTouchPoint(1, 1);
1240 OnSetTouchAction(TOUCH_ACTION_NONE
);
1241 SendInputEventACK(WebInputEvent::TouchStart
, INPUT_EVENT_ACK_STATE_CONSUMED
);
1243 ReleaseTouchPoint(0);
1247 PressTouchPoint(1, 1);
1250 // Ensure we have touch-action:none. ScrollBegin and ScrollEnd don't require
1252 EXPECT_EQ(2U, GetSentMessageCountAndResetSink());
1253 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
1254 WebGestureEvent::Touchpad
);
1255 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1256 SimulateGestureEvent(WebInputEvent::GestureScrollEnd
,
1257 WebGestureEvent::Touchpad
);
1258 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1260 SendInputEventACK(WebInputEvent::TouchEnd
, INPUT_EVENT_ACK_STATE_CONSUMED
);
1261 SendInputEventACK(WebInputEvent::TouchStart
,
1262 INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS
);
1264 // Ensure touch action has been set to auto, the touch handler has been
1266 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1267 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
1268 WebGestureEvent::Touchpad
);
1269 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1270 SimulateGestureEvent(WebInputEvent::GestureScrollEnd
,
1271 WebGestureEvent::Touchpad
);
1272 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1275 // Test that the double tap gesture depends on the touch action of the first
1277 TEST_F(InputRouterImplTest
, DoubleTapGestureDependsOnFirstTap
) {
1278 OnHasTouchEventHandlers(true);
1281 PressTouchPoint(1, 1);
1283 OnSetTouchAction(TOUCH_ACTION_NONE
);
1284 SendInputEventACK(WebInputEvent::TouchStart
, INPUT_EVENT_ACK_STATE_CONSUMED
);
1286 ReleaseTouchPoint(0);
1290 PressTouchPoint(1, 1);
1294 EXPECT_EQ(2U, GetSentMessageCountAndResetSink());
1295 SimulateGestureEvent(WebInputEvent::GestureTapDown
,
1296 WebGestureEvent::Touchscreen
);
1297 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1299 // The GestureTapUnconfirmed is converted into a tap, as the touch action is
1301 SimulateGestureEvent(WebInputEvent::GestureTapUnconfirmed
,
1302 WebGestureEvent::Touchscreen
);
1303 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1304 // This test will become invalid if GestureTap stops requiring an ack.
1305 ASSERT_FALSE(WebInputEventTraits::IgnoresAckDisposition(
1306 GetEventWithType(WebInputEvent::GestureTap
)));
1307 EXPECT_EQ(2, client_
->in_flight_event_count());
1308 SendInputEventACK(WebInputEvent::GestureTap
,
1309 INPUT_EVENT_ACK_STATE_CONSUMED
);
1310 EXPECT_EQ(1, client_
->in_flight_event_count());
1312 // This tap gesture is dropped, since the GestureTapUnconfirmed was turned
1314 SimulateGestureEvent(WebInputEvent::GestureTap
, WebGestureEvent::Touchscreen
);
1315 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1317 SendInputEventACK(WebInputEvent::TouchEnd
, INPUT_EVENT_ACK_STATE_CONSUMED
);
1318 SendInputEventACK(WebInputEvent::TouchStart
,
1319 INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS
);
1322 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1323 SimulateGestureEvent(WebInputEvent::GestureTapDown
,
1324 WebGestureEvent::Touchscreen
);
1325 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1327 // Although the touch-action is now auto, the double tap still won't be
1328 // dispatched, because the first tap occured when the touch-action was none.
1329 SimulateGestureEvent(WebInputEvent::GestureDoubleTap
,
1330 WebGestureEvent::Touchscreen
);
1331 // This test will become invalid if GestureDoubleTap stops requiring an ack.
1332 ASSERT_FALSE(WebInputEventTraits::IgnoresAckDisposition(
1333 GetEventWithType(WebInputEvent::GestureDoubleTap
)));
1334 EXPECT_EQ(1, client_
->in_flight_event_count());
1335 SendInputEventACK(WebInputEvent::GestureTap
, INPUT_EVENT_ACK_STATE_CONSUMED
);
1336 EXPECT_EQ(0, client_
->in_flight_event_count());
1339 // Test that the router will call the client's |DidFlush| after all events have
1340 // been dispatched following a call to |Flush|.
1341 TEST_F(InputRouterImplTest
, InputFlush
) {
1342 EXPECT_FALSE(HasPendingEvents());
1344 // Flushing an empty router should immediately trigger DidFlush.
1346 EXPECT_EQ(1U, GetAndResetDidFlushCount());
1347 EXPECT_FALSE(HasPendingEvents());
1349 // Queue a TouchStart.
1350 OnHasTouchEventHandlers(true);
1351 PressTouchPoint(1, 1);
1353 EXPECT_TRUE(HasPendingEvents());
1355 // DidFlush should be called only after the event is ack'ed.
1357 EXPECT_EQ(0U, GetAndResetDidFlushCount());
1358 SendInputEventACK(WebInputEvent::TouchStart
,
1359 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1360 EXPECT_EQ(1U, GetAndResetDidFlushCount());
1362 // Ensure different types of enqueued events will prevent the DidFlush call
1363 // until all such events have been fully dispatched.
1364 MoveTouchPoint(0, 50, 50);
1366 ASSERT_TRUE(HasPendingEvents());
1367 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
1368 WebGestureEvent::Touchscreen
);
1369 SimulateGestureEvent(WebInputEvent::GestureScrollUpdate
,
1370 WebGestureEvent::Touchscreen
);
1371 SimulateGestureEvent(WebInputEvent::GesturePinchBegin
,
1372 WebGestureEvent::Touchscreen
);
1373 SimulateGestureEvent(WebInputEvent::GesturePinchUpdate
,
1374 WebGestureEvent::Touchscreen
);
1376 EXPECT_EQ(0U, GetAndResetDidFlushCount());
1378 // Repeated flush calls should have no effect.
1380 EXPECT_EQ(0U, GetAndResetDidFlushCount());
1382 // There are still pending gestures.
1383 SendInputEventACK(WebInputEvent::TouchMove
,
1384 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1385 EXPECT_EQ(0U, GetAndResetDidFlushCount());
1386 EXPECT_TRUE(HasPendingEvents());
1388 // One more gesture to go.
1389 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
1390 INPUT_EVENT_ACK_STATE_CONSUMED
);
1391 EXPECT_EQ(0U, GetAndResetDidFlushCount());
1392 EXPECT_TRUE(HasPendingEvents());
1394 // The final ack'ed gesture should trigger the DidFlush.
1395 SendInputEventACK(WebInputEvent::GesturePinchUpdate
,
1396 INPUT_EVENT_ACK_STATE_CONSUMED
);
1397 EXPECT_EQ(1U, GetAndResetDidFlushCount());
1398 EXPECT_FALSE(HasPendingEvents());
1401 // Test that GesturePinchUpdate is handled specially for trackpad
1402 TEST_F(InputRouterImplTest
, TouchpadPinchUpdate
) {
1403 // GesturePinchUpdate for trackpad sends synthetic wheel events.
1404 // Note that the Touchscreen case is verified as NOT doing this as
1405 // part of the ShowPressIsInOrder test.
1407 SimulateGesturePinchUpdateEvent(1.5f
, 20, 25, 0, WebGestureEvent::Touchpad
);
1409 // Verify we actually sent a special wheel event to the renderer.
1410 const WebInputEvent
* input_event
=
1411 GetInputEventFromMessage(*process_
->sink().GetMessageAt(0));
1412 ASSERT_EQ(WebInputEvent::MouseWheel
, input_event
->type
);
1413 const WebMouseWheelEvent
* wheel_event
=
1414 static_cast<const WebMouseWheelEvent
*>(input_event
);
1415 EXPECT_EQ(20, wheel_event
->x
);
1416 EXPECT_EQ(25, wheel_event
->y
);
1417 EXPECT_EQ(20, wheel_event
->globalX
);
1418 EXPECT_EQ(25, wheel_event
->globalY
);
1419 EXPECT_EQ(20, wheel_event
->windowX
);
1420 EXPECT_EQ(25, wheel_event
->windowY
);
1421 EXPECT_EQ(PinchScaleToWheelDelta(1.5), wheel_event
->deltaY
);
1422 EXPECT_EQ(0, wheel_event
->deltaX
);
1423 EXPECT_EQ(1, wheel_event
->hasPreciseScrollingDeltas
);
1424 EXPECT_EQ(1, wheel_event
->wheelTicksY
);
1425 EXPECT_EQ(0, wheel_event
->wheelTicksX
);
1426 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1428 // Indicate that the wheel event was unhandled.
1429 SendInputEventACK(WebInputEvent::MouseWheel
,
1430 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1432 // Check that the correct unhandled pinch event was received.
1433 EXPECT_EQ(1U, ack_handler_
->GetAndResetAckCount());
1434 ASSERT_EQ(WebInputEvent::GesturePinchUpdate
, ack_handler_
->ack_event_type());
1435 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
, ack_handler_
->ack_state());
1436 EXPECT_EQ(1.5f
, ack_handler_
->acked_gesture_event().data
.pinchUpdate
.scale
);
1437 EXPECT_EQ(0, client_
->in_flight_event_count());
1439 // Second a second pinch event.
1440 SimulateGesturePinchUpdateEvent(0.3f
, 20, 25, 0, WebGestureEvent::Touchpad
);
1441 input_event
= GetInputEventFromMessage(*process_
->sink().GetMessageAt(0));
1442 ASSERT_EQ(WebInputEvent::MouseWheel
, input_event
->type
);
1443 wheel_event
= static_cast<const WebMouseWheelEvent
*>(input_event
);
1444 EXPECT_FLOAT_EQ(PinchScaleToWheelDelta(0.3f
), wheel_event
->deltaY
);
1445 EXPECT_EQ(1, wheel_event
->hasPreciseScrollingDeltas
);
1446 EXPECT_EQ(-1, wheel_event
->wheelTicksY
);
1447 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1449 // Indicate that the wheel event was handled this time.
1450 SendInputEventACK(WebInputEvent::MouseWheel
, INPUT_EVENT_ACK_STATE_CONSUMED
);
1452 // Check that the correct HANDLED pinch event was received.
1453 EXPECT_EQ(1U, ack_handler_
->GetAndResetAckCount());
1454 EXPECT_EQ(WebInputEvent::GesturePinchUpdate
, ack_handler_
->ack_event_type());
1455 EXPECT_EQ(INPUT_EVENT_ACK_STATE_CONSUMED
, ack_handler_
->ack_state());
1456 EXPECT_FLOAT_EQ(0.3f
,
1457 ack_handler_
->acked_gesture_event().data
.pinchUpdate
.scale
);
1460 // Test that touchpad pinch events are coalesced property, with their synthetic
1461 // wheel events getting the right ACKs.
1462 TEST_F(InputRouterImplTest
, TouchpadPinchCoalescing
) {
1463 // Send the first pinch.
1464 SimulateGesturePinchUpdateEvent(1.5f
, 20, 25, 0, WebGestureEvent::Touchpad
);
1466 // Verify we sent the wheel event to the renderer.
1467 const WebInputEvent
* input_event
=
1468 GetInputEventFromMessage(*process_
->sink().GetMessageAt(0));
1469 ASSERT_EQ(WebInputEvent::MouseWheel
, input_event
->type
);
1470 const WebMouseWheelEvent
* wheel_event
=
1471 static_cast<const WebMouseWheelEvent
*>(input_event
);
1472 EXPECT_EQ(PinchScaleToWheelDelta(1.5f
), wheel_event
->deltaY
);
1473 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1474 EXPECT_EQ(0U, ack_handler_
->GetAndResetAckCount());
1475 EXPECT_EQ(1, client_
->in_flight_event_count());
1477 // Send a second pinch, this should be queued in the GestureEventQueue.
1478 SimulateGesturePinchUpdateEvent(1.6f
, 20, 25, 0, WebGestureEvent::Touchpad
);
1479 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1480 EXPECT_EQ(0U, ack_handler_
->GetAndResetAckCount());
1482 // Send a third pinch, this should be coalesced into the second in the
1483 // GestureEventQueue.
1484 SimulateGesturePinchUpdateEvent(1.7f
, 20, 25, 0, WebGestureEvent::Touchpad
);
1485 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1486 EXPECT_EQ(0U, ack_handler_
->GetAndResetAckCount());
1488 // Indicate that the first wheel event was unhandled and verify the ACK.
1489 SendInputEventACK(WebInputEvent::MouseWheel
,
1490 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1491 EXPECT_EQ(1U, ack_handler_
->GetAndResetAckCount());
1492 EXPECT_EQ(WebInputEvent::GesturePinchUpdate
, ack_handler_
->ack_event_type());
1493 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
, ack_handler_
->ack_state());
1494 EXPECT_EQ(1.5f
, ack_handler_
->acked_gesture_event().data
.pinchUpdate
.scale
);
1496 // Verify a second wheel event was sent representing the 2nd and 3rd pinch
1498 EXPECT_EQ(1, client_
->in_flight_event_count());
1499 input_event
= GetInputEventFromMessage(*process_
->sink().GetMessageAt(0));
1500 ASSERT_EQ(WebInputEvent::MouseWheel
, input_event
->type
);
1501 wheel_event
= static_cast<const WebMouseWheelEvent
*>(input_event
);
1502 EXPECT_FLOAT_EQ(PinchScaleToWheelDelta(1.6f
* 1.7f
),
1503 PinchScaleToWheelDelta(1.6f
) + PinchScaleToWheelDelta(1.7f
));
1504 EXPECT_FLOAT_EQ(PinchScaleToWheelDelta(1.6f
* 1.7f
), wheel_event
->deltaY
);
1505 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1506 EXPECT_EQ(0U, ack_handler_
->GetAndResetAckCount());
1508 // Indicate that the second wheel event was handled and verify the ACK.
1509 SendInputEventACK(WebInputEvent::MouseWheel
, INPUT_EVENT_ACK_STATE_CONSUMED
);
1510 EXPECT_EQ(1U, ack_handler_
->GetAndResetAckCount());
1511 EXPECT_EQ(WebInputEvent::GesturePinchUpdate
, ack_handler_
->ack_event_type());
1512 EXPECT_EQ(INPUT_EVENT_ACK_STATE_CONSUMED
, ack_handler_
->ack_state());
1513 EXPECT_FLOAT_EQ(1.6f
* 1.7f
,
1514 ack_handler_
->acked_gesture_event().data
.pinchUpdate
.scale
);
1517 // Test interleaving pinch and wheel events.
1518 TEST_F(InputRouterImplTest
, TouchpadPinchAndWheel
) {
1519 // Simulate queued wheel and pinch events events.
1520 // Note that in practice interleaving pinch and wheel events should be rare
1521 // (eg. requires the use of a mouse and trackpad at the same time).
1523 // Use the control modifier to match the synthetic wheel events so that
1524 // they're elligble for coalescing.
1525 int mod
= WebInputEvent::ControlKey
;
1527 // Event 1: sent directly.
1528 SimulateWheelEvent(0, -5, mod
, true);
1529 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1531 // Event 2: enqueued in InputRouter.
1532 SimulateWheelEvent(0, -10, mod
, true);
1533 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1535 // Event 3: enqueued in InputRouter, not coalesced into #2.
1536 SimulateGesturePinchUpdateEvent(1.5f
, 20, 25, 0, WebGestureEvent::Touchpad
);
1537 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1539 // Event 4: enqueued in GestureEventQueue.
1540 SimulateGesturePinchUpdateEvent(1.2f
, 20, 25, 0, WebGestureEvent::Touchpad
);
1541 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1543 // Event 5: coalesced into wheel event for #3.
1544 SimulateWheelEvent(2, 0, mod
, true);
1545 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1548 SendInputEventACK(WebInputEvent::MouseWheel
,
1549 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1550 EXPECT_EQ(1U, ack_handler_
->GetAndResetAckCount());
1551 EXPECT_EQ(WebInputEvent::MouseWheel
, ack_handler_
->ack_event_type());
1553 // Verify we sent #2.
1554 ASSERT_EQ(1U, process_
->sink().message_count());
1555 const WebInputEvent
* input_event
=
1556 GetInputEventFromMessage(*process_
->sink().GetMessageAt(0));
1557 ASSERT_EQ(WebInputEvent::MouseWheel
, input_event
->type
);
1558 const WebMouseWheelEvent
* wheel_event
=
1559 static_cast<const WebMouseWheelEvent
*>(input_event
);
1560 EXPECT_EQ(0, wheel_event
->deltaX
);
1561 EXPECT_EQ(-10, wheel_event
->deltaY
);
1562 EXPECT_EQ(mod
, wheel_event
->modifiers
);
1563 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1566 SendInputEventACK(WebInputEvent::MouseWheel
,
1567 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1568 EXPECT_EQ(1U, ack_handler_
->GetAndResetAckCount());
1569 EXPECT_EQ(WebInputEvent::MouseWheel
, ack_handler_
->ack_event_type());
1571 // Verify we sent #3 (with #5 coalesced in).
1572 ASSERT_EQ(1U, process_
->sink().message_count());
1573 input_event
= GetInputEventFromMessage(*process_
->sink().GetMessageAt(0));
1574 ASSERT_EQ(WebInputEvent::MouseWheel
, input_event
->type
);
1575 wheel_event
= static_cast<const WebMouseWheelEvent
*>(input_event
);
1576 EXPECT_EQ(2, wheel_event
->deltaX
);
1577 EXPECT_EQ(PinchScaleToWheelDelta(1.5f
), wheel_event
->deltaY
);
1578 EXPECT_EQ(mod
, wheel_event
->modifiers
);
1579 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1582 SendInputEventACK(WebInputEvent::MouseWheel
,
1583 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1584 EXPECT_EQ(1U, ack_handler_
->GetAndResetAckCount());
1585 EXPECT_EQ(WebInputEvent::GesturePinchUpdate
, ack_handler_
->ack_event_type());
1587 // Verify we sent #4.
1588 ASSERT_EQ(1U, process_
->sink().message_count());
1589 input_event
= GetInputEventFromMessage(*process_
->sink().GetMessageAt(0));
1590 ASSERT_EQ(WebInputEvent::MouseWheel
, input_event
->type
);
1591 wheel_event
= static_cast<const WebMouseWheelEvent
*>(input_event
);
1592 EXPECT_EQ(0, wheel_event
->deltaX
);
1593 EXPECT_FLOAT_EQ(PinchScaleToWheelDelta(1.2f
), wheel_event
->deltaY
);
1594 EXPECT_EQ(mod
, wheel_event
->modifiers
);
1595 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1598 SendInputEventACK(WebInputEvent::MouseWheel
,
1599 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1600 EXPECT_EQ(1U, ack_handler_
->GetAndResetAckCount());
1601 EXPECT_EQ(WebInputEvent::GesturePinchUpdate
, ack_handler_
->ack_event_type());
1604 // Test proper handling of touchpad Gesture{Pinch,Scroll}Update sequences.
1605 TEST_F(InputRouterImplTest
, TouchpadPinchAndScrollUpdate
) {
1606 // The first scroll should be sent immediately.
1607 SimulateGestureEvent(WebInputEvent::GestureScrollUpdate
,
1608 WebGestureEvent::Touchpad
);
1609 ASSERT_EQ(1U, GetSentMessageCountAndResetSink());
1610 EXPECT_EQ(1, client_
->in_flight_event_count());
1612 // Subsequent scroll and pinch events should remain queued, coalescing as
1613 // more trackpad events arrive.
1614 SimulateGestureEvent(WebInputEvent::GesturePinchUpdate
,
1615 WebGestureEvent::Touchpad
);
1616 ASSERT_EQ(0U, GetSentMessageCountAndResetSink());
1617 EXPECT_EQ(1, client_
->in_flight_event_count());
1619 SimulateGestureEvent(WebInputEvent::GestureScrollUpdate
,
1620 WebGestureEvent::Touchpad
);
1621 ASSERT_EQ(0U, GetSentMessageCountAndResetSink());
1622 EXPECT_EQ(1, client_
->in_flight_event_count());
1624 SimulateGestureEvent(WebInputEvent::GesturePinchUpdate
,
1625 WebGestureEvent::Touchpad
);
1626 ASSERT_EQ(0U, GetSentMessageCountAndResetSink());
1627 EXPECT_EQ(1, client_
->in_flight_event_count());
1629 SimulateGestureEvent(WebInputEvent::GestureScrollUpdate
,
1630 WebGestureEvent::Touchpad
);
1631 ASSERT_EQ(0U, GetSentMessageCountAndResetSink());
1632 EXPECT_EQ(1, client_
->in_flight_event_count());
1634 // Ack'ing the first scroll should trigger both the coalesced scroll and the
1635 // coalesced pinch events (which is sent to the renderer as a wheel event).
1636 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
1637 INPUT_EVENT_ACK_STATE_CONSUMED
);
1638 EXPECT_EQ(1U, ack_handler_
->GetAndResetAckCount());
1639 EXPECT_EQ(2U, GetSentMessageCountAndResetSink());
1640 EXPECT_EQ(2, client_
->in_flight_event_count());
1642 // Ack the second scroll.
1643 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
1644 INPUT_EVENT_ACK_STATE_CONSUMED
);
1645 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1646 EXPECT_EQ(1U, ack_handler_
->GetAndResetAckCount());
1647 EXPECT_EQ(1, client_
->in_flight_event_count());
1649 // Ack the wheel event.
1650 SendInputEventACK(WebInputEvent::MouseWheel
, INPUT_EVENT_ACK_STATE_CONSUMED
);
1651 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1652 EXPECT_EQ(1U, ack_handler_
->GetAndResetAckCount());
1653 EXPECT_EQ(0, client_
->in_flight_event_count());
1656 } // namespace content