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::WebGestureDevice
;
36 using blink::WebGestureEvent
;
37 using blink::WebKeyboardEvent
;
38 using blink::WebInputEvent
;
39 using blink::WebMouseEvent
;
40 using blink::WebMouseWheelEvent
;
41 using blink::WebTouchEvent
;
42 using blink::WebTouchPoint
;
48 const WebInputEvent
* GetInputEventFromMessage(const IPC::Message
& message
) {
49 PickleIterator
iter(message
);
52 if (!iter
.ReadData(&data
, &data_length
))
54 return reinterpret_cast<const WebInputEvent
*>(data
);
57 WebInputEvent
& GetEventWithType(WebInputEvent::Type type
) {
58 WebInputEvent
* event
= NULL
;
59 if (WebInputEvent::isMouseEventType(type
)) {
60 static WebMouseEvent mouse
;
62 } else if (WebInputEvent::isTouchEventType(type
)) {
63 static WebTouchEvent touch
;
65 } else if (WebInputEvent::isKeyboardEventType(type
)) {
66 static WebKeyboardEvent key
;
68 } else if (WebInputEvent::isGestureEventType(type
)) {
69 static WebGestureEvent gesture
;
71 } else if (type
== WebInputEvent::MouseWheel
) {
72 static WebMouseWheelEvent wheel
;
80 bool GetIsShortcutFromHandleInputEventMessage(const IPC::Message
* msg
) {
81 InputMsg_HandleInputEvent::Schema::Param param
;
82 InputMsg_HandleInputEvent::Read(msg
, ¶m
);
86 template<typename MSG_T
, typename ARG_T1
>
87 void ExpectIPCMessageWithArg1(const IPC::Message
* msg
, const ARG_T1
& arg1
) {
88 ASSERT_EQ(MSG_T::ID
, msg
->type());
89 typename
MSG_T::Schema::Param param
;
90 ASSERT_TRUE(MSG_T::Read(msg
, ¶m
));
91 EXPECT_EQ(arg1
, get
<0>(param
));
94 template<typename MSG_T
, typename ARG_T1
, typename ARG_T2
>
95 void ExpectIPCMessageWithArg2(const IPC::Message
* msg
,
98 ASSERT_EQ(MSG_T::ID
, msg
->type());
99 typename
MSG_T::Schema::Param param
;
100 ASSERT_TRUE(MSG_T::Read(msg
, ¶m
));
101 EXPECT_EQ(arg1
, get
<0>(param
));
102 EXPECT_EQ(arg2
, get
<1>(param
));
105 #if defined(USE_AURA)
106 bool TouchEventsAreEquivalent(const ui::TouchEvent
& first
,
107 const ui::TouchEvent
& second
) {
108 if (first
.type() != second
.type())
110 if (first
.location() != second
.location())
112 if (first
.touch_id() != second
.touch_id())
114 if (second
.time_stamp().InSeconds() != first
.time_stamp().InSeconds())
119 bool EventListIsSubset(const ScopedVector
<ui::TouchEvent
>& subset
,
120 const ScopedVector
<ui::TouchEvent
>& set
) {
121 if (subset
.size() > set
.size())
123 for (size_t i
= 0; i
< subset
.size(); ++i
) {
124 const ui::TouchEvent
* first
= subset
[i
];
125 const ui::TouchEvent
* second
= set
[i
];
126 bool equivalent
= TouchEventsAreEquivalent(*first
, *second
);
133 #endif // defined(USE_AURA)
137 class InputRouterImplTest
: public testing::Test
{
139 InputRouterImplTest() {}
140 ~InputRouterImplTest() override
{}
144 void SetUp() override
{
145 browser_context_
.reset(new TestBrowserContext());
146 process_
.reset(new MockRenderProcessHost(browser_context_
.get()));
147 client_
.reset(new MockInputRouterClient());
148 ack_handler_
.reset(new MockInputAckHandler());
149 base::CommandLine
* command_line
= base::CommandLine::ForCurrentProcess();
150 command_line
->AppendSwitch(switches::kValidateInputEventStream
);
151 input_router_
.reset(new InputRouterImpl(process_
.get(),
156 client_
->set_input_router(input_router());
157 ack_handler_
->set_input_router(input_router());
160 void TearDown() override
{
161 // Process all pending tasks to avoid leaks.
162 base::MessageLoop::current()->RunUntilIdle();
164 input_router_
.reset();
167 browser_context_
.reset();
170 void SetUpForTouchAckTimeoutTest(int timeout_ms
) {
171 config_
.touch_config
.touch_ack_timeout_delay
=
172 base::TimeDelta::FromMilliseconds(timeout_ms
);
173 config_
.touch_config
.touch_ack_timeout_supported
= true;
178 void SimulateKeyboardEvent(WebInputEvent::Type type
, bool is_shortcut
) {
179 WebKeyboardEvent event
= SyntheticWebKeyboardEventBuilder::Build(type
);
180 NativeWebKeyboardEvent native_event
;
181 memcpy(&native_event
, &event
, sizeof(event
));
182 input_router_
->SendKeyboardEvent(
188 void SimulateWheelEvent(float dX
, float dY
, int modifiers
, bool precise
) {
189 input_router_
->SendWheelEvent(MouseWheelEventWithLatencyInfo(
190 SyntheticWebMouseWheelEventBuilder::Build(dX
, dY
, modifiers
, precise
)));
193 void SimulateMouseEvent(WebInputEvent::Type type
, int x
, int y
) {
194 input_router_
->SendMouseEvent(MouseEventWithLatencyInfo(
195 SyntheticWebMouseEventBuilder::Build(type
, x
, y
, 0)));
198 void SimulateWheelEventWithPhase(WebMouseWheelEvent::Phase phase
) {
199 input_router_
->SendWheelEvent(MouseWheelEventWithLatencyInfo(
200 SyntheticWebMouseWheelEventBuilder::Build(phase
)));
203 void SimulateGestureEvent(WebGestureEvent gesture
) {
204 // Ensure non-zero touchscreen fling velocities, as the router will
205 // validate aganst such.
206 if (gesture
.type
== WebInputEvent::GestureFlingStart
&&
207 gesture
.sourceDevice
== blink::WebGestureDeviceTouchscreen
&&
208 !gesture
.data
.flingStart
.velocityX
&&
209 !gesture
.data
.flingStart
.velocityY
) {
210 gesture
.data
.flingStart
.velocityX
= 5.f
;
213 input_router_
->SendGestureEvent(GestureEventWithLatencyInfo(gesture
));
216 void SimulateGestureEvent(WebInputEvent::Type type
,
217 WebGestureDevice source_device
) {
218 SimulateGestureEvent(
219 SyntheticWebGestureEventBuilder::Build(type
, source_device
));
222 void SimulateGestureScrollUpdateEvent(float dX
,
225 WebGestureDevice source_device
) {
226 SimulateGestureEvent(SyntheticWebGestureEventBuilder::BuildScrollUpdate(
227 dX
, dY
, modifiers
, source_device
));
230 void SimulateGesturePinchUpdateEvent(float scale
,
234 WebGestureDevice source_device
) {
235 SimulateGestureEvent(SyntheticWebGestureEventBuilder::BuildPinchUpdate(
236 scale
, anchor_x
, anchor_y
, modifiers
, source_device
));
239 void SimulateGestureFlingStartEvent(float velocity_x
,
241 WebGestureDevice source_device
) {
242 SimulateGestureEvent(SyntheticWebGestureEventBuilder::BuildFling(
243 velocity_x
, velocity_y
, source_device
));
246 void SetTouchTimestamp(base::TimeDelta timestamp
) {
247 touch_event_
.SetTimestamp(timestamp
);
250 void SendTouchEvent() {
251 input_router_
->SendTouchEvent(TouchEventWithLatencyInfo(touch_event_
));
252 touch_event_
.ResetPoints();
255 int PressTouchPoint(int x
, int y
) {
256 return touch_event_
.PressPoint(x
, y
);
259 void MoveTouchPoint(int index
, int x
, int y
) {
260 touch_event_
.MovePoint(index
, x
, y
);
263 void ReleaseTouchPoint(int index
) {
264 touch_event_
.ReleasePoint(index
);
267 void CancelTouchPoint(int index
) {
268 touch_event_
.CancelPoint(index
);
271 void SendInputEventACK(blink::WebInputEvent::Type type
,
272 InputEventAckState ack_result
) {
273 InputHostMsg_HandleInputEvent_ACK_Params ack
;
275 ack
.state
= ack_result
;
276 input_router_
->OnMessageReceived(InputHostMsg_HandleInputEvent_ACK(0, ack
));
279 void NotifyDidStopFlinging() {
280 input_router_
->OnMessageReceived(InputHostMsg_DidStopFlinging(0));
283 InputRouterImpl
* input_router() const {
284 return input_router_
.get();
287 bool TouchEventQueueEmpty() const {
288 return input_router()->touch_event_queue_
.empty();
291 bool TouchEventTimeoutEnabled() const {
292 return input_router()->touch_event_queue_
.IsAckTimeoutEnabled();
295 void RequestNotificationWhenFlushed() const {
296 return input_router_
->RequestNotificationWhenFlushed();
299 size_t GetAndResetDidFlushCount() {
300 return client_
->GetAndResetDidFlushCount();
303 bool HasPendingEvents() const {
304 return input_router_
->HasPendingEvents();
307 void OnHasTouchEventHandlers(bool has_handlers
) {
308 input_router_
->OnMessageReceived(
309 ViewHostMsg_HasTouchEventHandlers(0, has_handlers
));
312 void OnSetTouchAction(content::TouchAction touch_action
) {
313 input_router_
->OnMessageReceived(
314 InputHostMsg_SetTouchAction(0, touch_action
));
317 size_t GetSentMessageCountAndResetSink() {
318 size_t count
= process_
->sink().message_count();
319 process_
->sink().ClearMessages();
323 static void RunTasksAndWait(base::TimeDelta delay
) {
324 base::MessageLoop::current()->PostDelayedTask(
325 FROM_HERE
, base::MessageLoop::QuitClosure(), delay
);
326 base::MessageLoop::current()->Run();
329 InputRouterImpl::Config config_
;
330 scoped_ptr
<MockRenderProcessHost
> process_
;
331 scoped_ptr
<MockInputRouterClient
> client_
;
332 scoped_ptr
<MockInputAckHandler
> ack_handler_
;
333 scoped_ptr
<InputRouterImpl
> input_router_
;
336 base::MessageLoopForUI message_loop_
;
337 SyntheticWebTouchEvent touch_event_
;
339 scoped_ptr
<TestBrowserContext
> browser_context_
;
342 TEST_F(InputRouterImplTest
, CoalescesRangeSelection
) {
343 input_router_
->SendInput(scoped_ptr
<IPC::Message
>(
344 new InputMsg_SelectRange(0, gfx::Point(1, 2), gfx::Point(3, 4))));
345 ExpectIPCMessageWithArg2
<InputMsg_SelectRange
>(
346 process_
->sink().GetMessageAt(0),
349 EXPECT_EQ(1u, GetSentMessageCountAndResetSink());
351 // Send two more messages without acking.
352 input_router_
->SendInput(scoped_ptr
<IPC::Message
>(
353 new InputMsg_SelectRange(0, gfx::Point(5, 6), gfx::Point(7, 8))));
354 EXPECT_EQ(0u, GetSentMessageCountAndResetSink());
356 input_router_
->SendInput(scoped_ptr
<IPC::Message
>(
357 new InputMsg_SelectRange(0, gfx::Point(9, 10), gfx::Point(11, 12))));
358 EXPECT_EQ(0u, GetSentMessageCountAndResetSink());
360 // Now ack the first message.
362 scoped_ptr
<IPC::Message
> response(new InputHostMsg_SelectRange_ACK(0));
363 input_router_
->OnMessageReceived(*response
);
366 // Verify that the two messages are coalesced into one message.
367 ExpectIPCMessageWithArg2
<InputMsg_SelectRange
>(
368 process_
->sink().GetMessageAt(0),
371 EXPECT_EQ(1u, GetSentMessageCountAndResetSink());
373 // Acking the coalesced msg should not send any more msg.
375 scoped_ptr
<IPC::Message
> response(new InputHostMsg_SelectRange_ACK(0));
376 input_router_
->OnMessageReceived(*response
);
378 EXPECT_EQ(0u, GetSentMessageCountAndResetSink());
381 TEST_F(InputRouterImplTest
, CoalescesMoveRangeSelectionExtent
) {
382 input_router_
->SendInput(scoped_ptr
<IPC::Message
>(
383 new InputMsg_MoveRangeSelectionExtent(0, gfx::Point(1, 2))));
384 ExpectIPCMessageWithArg1
<InputMsg_MoveRangeSelectionExtent
>(
385 process_
->sink().GetMessageAt(0),
387 EXPECT_EQ(1u, GetSentMessageCountAndResetSink());
389 // Send two more messages without acking.
390 input_router_
->SendInput(scoped_ptr
<IPC::Message
>(
391 new InputMsg_MoveRangeSelectionExtent(0, gfx::Point(3, 4))));
392 EXPECT_EQ(0u, GetSentMessageCountAndResetSink());
394 input_router_
->SendInput(scoped_ptr
<IPC::Message
>(
395 new InputMsg_MoveRangeSelectionExtent(0, gfx::Point(5, 6))));
396 EXPECT_EQ(0u, GetSentMessageCountAndResetSink());
398 // Now ack the first message.
400 scoped_ptr
<IPC::Message
> response(
401 new InputHostMsg_MoveRangeSelectionExtent_ACK(0));
402 input_router_
->OnMessageReceived(*response
);
405 // Verify that the two messages are coalesced into one message.
406 ExpectIPCMessageWithArg1
<InputMsg_MoveRangeSelectionExtent
>(
407 process_
->sink().GetMessageAt(0),
409 EXPECT_EQ(1u, GetSentMessageCountAndResetSink());
411 // Acking the coalesced msg should not send any more msg.
413 scoped_ptr
<IPC::Message
> response(
414 new InputHostMsg_MoveRangeSelectionExtent_ACK(0));
415 input_router_
->OnMessageReceived(*response
);
417 EXPECT_EQ(0u, GetSentMessageCountAndResetSink());
420 TEST_F(InputRouterImplTest
, InterleaveSelectRangeAndMoveRangeSelectionExtent
) {
421 // Send first message: SelectRange.
422 input_router_
->SendInput(scoped_ptr
<IPC::Message
>(
423 new InputMsg_SelectRange(0, gfx::Point(1, 2), gfx::Point(3, 4))));
424 ExpectIPCMessageWithArg2
<InputMsg_SelectRange
>(
425 process_
->sink().GetMessageAt(0),
428 EXPECT_EQ(1u, GetSentMessageCountAndResetSink());
430 // Send second message: MoveRangeSelectionExtent.
431 input_router_
->SendInput(scoped_ptr
<IPC::Message
>(
432 new InputMsg_MoveRangeSelectionExtent(0, gfx::Point(5, 6))));
433 EXPECT_EQ(0u, GetSentMessageCountAndResetSink());
435 // Send third message: SelectRange.
436 input_router_
->SendInput(scoped_ptr
<IPC::Message
>(
437 new InputMsg_SelectRange(0, gfx::Point(7, 8), gfx::Point(9, 10))));
438 EXPECT_EQ(0u, GetSentMessageCountAndResetSink());
440 // Ack the messages and verify that they're not coalesced and that they're in
443 // Ack the first message.
445 scoped_ptr
<IPC::Message
> response(
446 new InputHostMsg_SelectRange_ACK(0));
447 input_router_
->OnMessageReceived(*response
);
450 ExpectIPCMessageWithArg1
<InputMsg_MoveRangeSelectionExtent
>(
451 process_
->sink().GetMessageAt(0),
453 EXPECT_EQ(1u, GetSentMessageCountAndResetSink());
455 // Ack the second message.
457 scoped_ptr
<IPC::Message
> response(
458 new InputHostMsg_MoveRangeSelectionExtent_ACK(0));
459 input_router_
->OnMessageReceived(*response
);
462 ExpectIPCMessageWithArg2
<InputMsg_SelectRange
>(
463 process_
->sink().GetMessageAt(0),
466 EXPECT_EQ(1u, GetSentMessageCountAndResetSink());
468 // Ack the third message.
470 scoped_ptr
<IPC::Message
> response(
471 new InputHostMsg_SelectRange_ACK(0));
472 input_router_
->OnMessageReceived(*response
);
474 EXPECT_EQ(0u, GetSentMessageCountAndResetSink());
477 TEST_F(InputRouterImplTest
,
478 CoalescesInterleavedSelectRangeAndMoveRangeSelectionExtent
) {
479 // Send interleaved SelectRange and MoveRangeSelectionExtent messages. They
480 // should be coalesced as shown by the arrows.
482 // MoveRangeSelectionExtent
483 // MoveRangeSelectionExtent
484 // > MoveRangeSelectionExtent
487 // > MoveRangeSelectionExtent
489 input_router_
->SendInput(scoped_ptr
<IPC::Message
>(
490 new InputMsg_SelectRange(0, gfx::Point(1, 2), gfx::Point(3, 4))));
491 ExpectIPCMessageWithArg2
<InputMsg_SelectRange
>(
492 process_
->sink().GetMessageAt(0),
495 EXPECT_EQ(1u, GetSentMessageCountAndResetSink());
497 input_router_
->SendInput(scoped_ptr
<IPC::Message
>(
498 new InputMsg_MoveRangeSelectionExtent(0, gfx::Point(5, 6))));
499 EXPECT_EQ(0u, GetSentMessageCountAndResetSink());
501 input_router_
->SendInput(scoped_ptr
<IPC::Message
>(
502 new InputMsg_MoveRangeSelectionExtent(0, gfx::Point(7, 8))));
503 EXPECT_EQ(0u, GetSentMessageCountAndResetSink());
505 input_router_
->SendInput(scoped_ptr
<IPC::Message
>(
506 new InputMsg_MoveRangeSelectionExtent(0, gfx::Point(9, 10))));
507 EXPECT_EQ(0u, GetSentMessageCountAndResetSink());
509 input_router_
->SendInput(scoped_ptr
<IPC::Message
>(
510 new InputMsg_SelectRange(0, gfx::Point(11, 12), gfx::Point(13, 14))));
511 EXPECT_EQ(0u, GetSentMessageCountAndResetSink());
513 input_router_
->SendInput(scoped_ptr
<IPC::Message
>(
514 new InputMsg_SelectRange(0, gfx::Point(15, 16), gfx::Point(17, 18))));
515 EXPECT_EQ(0u, GetSentMessageCountAndResetSink());
517 input_router_
->SendInput(scoped_ptr
<IPC::Message
>(
518 new InputMsg_MoveRangeSelectionExtent(0, gfx::Point(19, 20))));
519 EXPECT_EQ(0u, GetSentMessageCountAndResetSink());
521 // Ack the first message.
523 scoped_ptr
<IPC::Message
> response(
524 new InputHostMsg_SelectRange_ACK(0));
525 input_router_
->OnMessageReceived(*response
);
528 // Verify that the three MoveRangeSelectionExtent messages are coalesced into
530 ExpectIPCMessageWithArg1
<InputMsg_MoveRangeSelectionExtent
>(
531 process_
->sink().GetMessageAt(0),
533 EXPECT_EQ(1u, GetSentMessageCountAndResetSink());
535 // Ack the second message.
537 scoped_ptr
<IPC::Message
> response(
538 new InputHostMsg_MoveRangeSelectionExtent_ACK(0));
539 input_router_
->OnMessageReceived(*response
);
542 // Verify that the two SelectRange messages are coalesced into one message.
543 ExpectIPCMessageWithArg2
<InputMsg_SelectRange
>(
544 process_
->sink().GetMessageAt(0),
547 EXPECT_EQ(1u, GetSentMessageCountAndResetSink());
549 // Ack the third message.
551 scoped_ptr
<IPC::Message
> response(
552 new InputHostMsg_SelectRange_ACK(0));
553 input_router_
->OnMessageReceived(*response
);
556 // Verify the fourth message.
557 ExpectIPCMessageWithArg1
<InputMsg_MoveRangeSelectionExtent
>(
558 process_
->sink().GetMessageAt(0),
560 EXPECT_EQ(1u, GetSentMessageCountAndResetSink());
562 // Ack the fourth message.
564 scoped_ptr
<IPC::Message
> response(
565 new InputHostMsg_MoveRangeSelectionExtent_ACK(0));
566 input_router_
->OnMessageReceived(*response
);
568 EXPECT_EQ(0u, GetSentMessageCountAndResetSink());
571 TEST_F(InputRouterImplTest
, CoalescesCaretMove
) {
572 input_router_
->SendInput(
573 scoped_ptr
<IPC::Message
>(new InputMsg_MoveCaret(0, gfx::Point(1, 2))));
574 ExpectIPCMessageWithArg1
<InputMsg_MoveCaret
>(
575 process_
->sink().GetMessageAt(0), gfx::Point(1, 2));
576 EXPECT_EQ(1u, GetSentMessageCountAndResetSink());
578 // Send two more messages without acking.
579 input_router_
->SendInput(
580 scoped_ptr
<IPC::Message
>(new InputMsg_MoveCaret(0, gfx::Point(5, 6))));
581 EXPECT_EQ(0u, GetSentMessageCountAndResetSink());
583 input_router_
->SendInput(
584 scoped_ptr
<IPC::Message
>(new InputMsg_MoveCaret(0, gfx::Point(9, 10))));
585 EXPECT_EQ(0u, GetSentMessageCountAndResetSink());
587 // Now ack the first message.
589 scoped_ptr
<IPC::Message
> response(new InputHostMsg_MoveCaret_ACK(0));
590 input_router_
->OnMessageReceived(*response
);
593 // Verify that the two messages are coalesced into one message.
594 ExpectIPCMessageWithArg1
<InputMsg_MoveCaret
>(
595 process_
->sink().GetMessageAt(0), gfx::Point(9, 10));
596 EXPECT_EQ(1u, GetSentMessageCountAndResetSink());
598 // Acking the coalesced msg should not send any more msg.
600 scoped_ptr
<IPC::Message
> response(new InputHostMsg_MoveCaret_ACK(0));
601 input_router_
->OnMessageReceived(*response
);
603 EXPECT_EQ(0u, GetSentMessageCountAndResetSink());
606 TEST_F(InputRouterImplTest
, HandledInputEvent
) {
607 client_
->set_filter_state(INPUT_EVENT_ACK_STATE_CONSUMED
);
609 // Simulate a keyboard event.
610 SimulateKeyboardEvent(WebInputEvent::RawKeyDown
, false);
612 // Make sure no input event is sent to the renderer.
613 EXPECT_EQ(0u, GetSentMessageCountAndResetSink());
615 // OnKeyboardEventAck should be triggered without actual ack.
616 EXPECT_EQ(1U, ack_handler_
->GetAndResetAckCount());
618 // As the event was acked already, keyboard event queue should be
620 ASSERT_EQ(NULL
, input_router_
->GetLastKeyboardEvent());
623 TEST_F(InputRouterImplTest
, ClientCanceledKeyboardEvent
) {
624 client_
->set_filter_state(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS
);
626 // Simulate a keyboard event that has no consumer.
627 SimulateKeyboardEvent(WebInputEvent::RawKeyDown
, false);
629 // Make sure no input event is sent to the renderer.
630 EXPECT_EQ(0u, GetSentMessageCountAndResetSink());
631 EXPECT_EQ(1U, ack_handler_
->GetAndResetAckCount());
634 // Simulate a keyboard event that should be dropped.
635 client_
->set_filter_state(INPUT_EVENT_ACK_STATE_UNKNOWN
);
636 SimulateKeyboardEvent(WebInputEvent::RawKeyDown
, false);
638 // Make sure no input event is sent to the renderer, and no ack is sent.
639 EXPECT_EQ(0u, GetSentMessageCountAndResetSink());
640 EXPECT_EQ(0U, ack_handler_
->GetAndResetAckCount());
643 TEST_F(InputRouterImplTest
, ShortcutKeyboardEvent
) {
644 SimulateKeyboardEvent(WebInputEvent::RawKeyDown
, true);
645 EXPECT_TRUE(GetIsShortcutFromHandleInputEventMessage(
646 process_
->sink().GetMessageAt(0)));
648 process_
->sink().ClearMessages();
650 SimulateKeyboardEvent(WebInputEvent::RawKeyDown
, false);
651 EXPECT_FALSE(GetIsShortcutFromHandleInputEventMessage(
652 process_
->sink().GetMessageAt(0)));
655 TEST_F(InputRouterImplTest
, NoncorrespondingKeyEvents
) {
656 SimulateKeyboardEvent(WebInputEvent::RawKeyDown
, false);
658 SendInputEventACK(WebInputEvent::KeyUp
,
659 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
660 EXPECT_TRUE(ack_handler_
->unexpected_event_ack_called());
663 // Tests ported from RenderWidgetHostTest --------------------------------------
665 TEST_F(InputRouterImplTest
, HandleKeyEventsWeSent
) {
666 // Simulate a keyboard event.
667 SimulateKeyboardEvent(WebInputEvent::RawKeyDown
, false);
668 ASSERT_TRUE(input_router_
->GetLastKeyboardEvent());
669 EXPECT_EQ(WebInputEvent::RawKeyDown
,
670 input_router_
->GetLastKeyboardEvent()->type
);
672 // Make sure we sent the input event to the renderer.
673 EXPECT_TRUE(process_
->sink().GetUniqueMessageMatching(
674 InputMsg_HandleInputEvent::ID
));
675 process_
->sink().ClearMessages();
677 // Send the simulated response from the renderer back.
678 SendInputEventACK(WebInputEvent::RawKeyDown
,
679 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
680 EXPECT_EQ(1U, ack_handler_
->GetAndResetAckCount());
681 EXPECT_EQ(WebInputEvent::RawKeyDown
,
682 ack_handler_
->acked_keyboard_event().type
);
685 TEST_F(InputRouterImplTest
, IgnoreKeyEventsWeDidntSend
) {
686 // Send a simulated, unrequested key response. We should ignore this.
687 SendInputEventACK(WebInputEvent::RawKeyDown
,
688 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
690 EXPECT_EQ(0U, ack_handler_
->GetAndResetAckCount());
693 TEST_F(InputRouterImplTest
, CoalescesWheelEvents
) {
694 // Simulate wheel events.
695 SimulateWheelEvent(0, -5, 0, false); // sent directly
696 SimulateWheelEvent(0, -10, 0, false); // enqueued
697 SimulateWheelEvent(8, -6, 0, false); // coalesced into previous event
698 SimulateWheelEvent(9, -7, 1, false); // enqueued, different modifiers
699 SimulateWheelEvent(0, -10, 0, false); // enqueued, different modifiers
700 // Explicitly verify that PhaseEnd isn't coalesced to avoid bugs like
701 // https://crbug.com/154740.
702 SimulateWheelEventWithPhase(WebMouseWheelEvent::PhaseEnded
); // enqueued
704 // Check that only the first event was sent.
705 EXPECT_TRUE(process_
->sink().GetUniqueMessageMatching(
706 InputMsg_HandleInputEvent::ID
));
707 const WebInputEvent
* input_event
=
708 GetInputEventFromMessage(*process_
->sink().GetMessageAt(0));
709 ASSERT_EQ(WebInputEvent::MouseWheel
, input_event
->type
);
710 const WebMouseWheelEvent
* wheel_event
=
711 static_cast<const WebMouseWheelEvent
*>(input_event
);
712 EXPECT_EQ(0, wheel_event
->deltaX
);
713 EXPECT_EQ(-5, wheel_event
->deltaY
);
714 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
716 // Check that the ACK sends the second message immediately.
717 SendInputEventACK(WebInputEvent::MouseWheel
,
718 INPUT_EVENT_ACK_STATE_CONSUMED
);
719 // The coalesced events can queue up a delayed ack
720 // so that additional input events can be processed before
721 // we turn off coalescing.
722 base::MessageLoop::current()->RunUntilIdle();
723 EXPECT_EQ(1U, ack_handler_
->GetAndResetAckCount());
724 EXPECT_TRUE(process_
->sink().GetUniqueMessageMatching(
725 InputMsg_HandleInputEvent::ID
));
726 input_event
= GetInputEventFromMessage(*process_
->sink().GetMessageAt(0));
727 ASSERT_EQ(WebInputEvent::MouseWheel
, input_event
->type
);
728 wheel_event
= static_cast<const WebMouseWheelEvent
*>(input_event
);
729 EXPECT_EQ(8, wheel_event
->deltaX
);
730 EXPECT_EQ(-10 + -6, wheel_event
->deltaY
); // coalesced
731 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
733 // Ack the second event (which had the third coalesced into it).
734 SendInputEventACK(WebInputEvent::MouseWheel
,
735 INPUT_EVENT_ACK_STATE_CONSUMED
);
736 base::MessageLoop::current()->RunUntilIdle();
737 EXPECT_EQ(1U, ack_handler_
->GetAndResetAckCount());
738 EXPECT_TRUE(process_
->sink().GetUniqueMessageMatching(
739 InputMsg_HandleInputEvent::ID
));
740 input_event
= GetInputEventFromMessage(*process_
->sink().GetMessageAt(0));
741 ASSERT_EQ(WebInputEvent::MouseWheel
, input_event
->type
);
742 wheel_event
= static_cast<const WebMouseWheelEvent
*>(input_event
);
743 EXPECT_EQ(9, wheel_event
->deltaX
);
744 EXPECT_EQ(-7, wheel_event
->deltaY
);
745 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
747 // Ack the fourth event.
748 SendInputEventACK(WebInputEvent::MouseWheel
,
749 INPUT_EVENT_ACK_STATE_CONSUMED
);
750 base::MessageLoop::current()->RunUntilIdle();
751 EXPECT_EQ(1U, ack_handler_
->GetAndResetAckCount());
753 process_
->sink().GetUniqueMessageMatching(InputMsg_HandleInputEvent::ID
));
754 input_event
= GetInputEventFromMessage(*process_
->sink().GetMessageAt(0));
755 ASSERT_EQ(WebInputEvent::MouseWheel
, input_event
->type
);
756 wheel_event
= static_cast<const WebMouseWheelEvent
*>(input_event
);
757 EXPECT_EQ(0, wheel_event
->deltaX
);
758 EXPECT_EQ(-10, wheel_event
->deltaY
);
759 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
761 // Ack the fifth event.
762 SendInputEventACK(WebInputEvent::MouseWheel
, INPUT_EVENT_ACK_STATE_CONSUMED
);
763 base::MessageLoop::current()->RunUntilIdle();
764 EXPECT_EQ(1U, ack_handler_
->GetAndResetAckCount());
766 process_
->sink().GetUniqueMessageMatching(InputMsg_HandleInputEvent::ID
));
767 input_event
= GetInputEventFromMessage(*process_
->sink().GetMessageAt(0));
768 ASSERT_EQ(WebInputEvent::MouseWheel
, input_event
->type
);
769 wheel_event
= static_cast<const WebMouseWheelEvent
*>(input_event
);
770 EXPECT_EQ(0, wheel_event
->deltaX
);
771 EXPECT_EQ(0, wheel_event
->deltaY
);
772 EXPECT_EQ(WebMouseWheelEvent::PhaseEnded
, wheel_event
->phase
);
773 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
775 // After the final ack, the queue should be empty.
776 SendInputEventACK(WebInputEvent::MouseWheel
, INPUT_EVENT_ACK_STATE_CONSUMED
);
777 base::MessageLoop::current()->RunUntilIdle();
778 EXPECT_EQ(1U, ack_handler_
->GetAndResetAckCount());
779 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
782 // Tests that touch-events are queued properly.
783 TEST_F(InputRouterImplTest
, TouchEventQueue
) {
784 OnHasTouchEventHandlers(true);
786 PressTouchPoint(1, 1);
788 EXPECT_TRUE(client_
->GetAndResetFilterEventCalled());
789 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
790 EXPECT_FALSE(TouchEventQueueEmpty());
792 // The second touch should not be sent since one is already in queue.
793 MoveTouchPoint(0, 5, 5);
795 EXPECT_FALSE(client_
->GetAndResetFilterEventCalled());
796 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
797 EXPECT_FALSE(TouchEventQueueEmpty());
799 // Receive an ACK for the first touch-event.
800 SendInputEventACK(WebInputEvent::TouchStart
,
801 INPUT_EVENT_ACK_STATE_CONSUMED
);
802 EXPECT_FALSE(TouchEventQueueEmpty());
803 EXPECT_EQ(1U, ack_handler_
->GetAndResetAckCount());
804 EXPECT_EQ(WebInputEvent::TouchStart
,
805 ack_handler_
->acked_touch_event().event
.type
);
806 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
808 SendInputEventACK(WebInputEvent::TouchMove
,
809 INPUT_EVENT_ACK_STATE_CONSUMED
);
810 EXPECT_TRUE(TouchEventQueueEmpty());
811 EXPECT_EQ(1U, ack_handler_
->GetAndResetAckCount());
812 EXPECT_EQ(WebInputEvent::TouchMove
,
813 ack_handler_
->acked_touch_event().event
.type
);
814 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
817 // Tests that the touch-queue is emptied after a page stops listening for touch
818 // events and the outstanding ack is received.
819 TEST_F(InputRouterImplTest
, TouchEventQueueFlush
) {
820 OnHasTouchEventHandlers(true);
821 EXPECT_TRUE(client_
->has_touch_handler());
822 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
823 EXPECT_TRUE(TouchEventQueueEmpty());
825 // Send a touch-press event.
826 PressTouchPoint(1, 1);
828 MoveTouchPoint(0, 2, 2);
829 MoveTouchPoint(0, 3, 3);
830 EXPECT_FALSE(TouchEventQueueEmpty());
831 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
833 // The page stops listening for touch-events. Note that flushing is deferred
834 // until the outstanding ack is received.
835 OnHasTouchEventHandlers(false);
836 EXPECT_FALSE(client_
->has_touch_handler());
837 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
838 EXPECT_FALSE(TouchEventQueueEmpty());
840 // After the ack, the touch-event queue should be empty, and none of the
841 // flushed touch-events should have been sent to the renderer.
842 SendInputEventACK(WebInputEvent::TouchStart
, INPUT_EVENT_ACK_STATE_CONSUMED
);
843 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
844 EXPECT_TRUE(TouchEventQueueEmpty());
847 #if defined(USE_AURA)
848 // Tests that the acked events have correct state. (ui::Events are used only on
850 TEST_F(InputRouterImplTest
, AckedTouchEventState
) {
851 input_router_
->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true));
852 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
853 EXPECT_TRUE(TouchEventQueueEmpty());
855 // Send a bunch of events, and make sure the ACKed events are correct.
856 ScopedVector
<ui::TouchEvent
> expected_events
;
858 // Use a custom timestamp for all the events to test that the acked events
859 // have the same timestamp;
860 base::TimeDelta timestamp
= base::Time::NowFromSystemTime() - base::Time();
861 timestamp
-= base::TimeDelta::FromSeconds(600);
863 // Press the first finger.
864 PressTouchPoint(1, 1);
865 SetTouchTimestamp(timestamp
);
867 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
868 expected_events
.push_back(new ui::TouchEvent(ui::ET_TOUCH_PRESSED
,
869 gfx::Point(1, 1), 0, timestamp
));
872 timestamp
+= base::TimeDelta::FromSeconds(10);
873 MoveTouchPoint(0, 500, 500);
874 SetTouchTimestamp(timestamp
);
876 EXPECT_FALSE(TouchEventQueueEmpty());
877 expected_events
.push_back(new ui::TouchEvent(ui::ET_TOUCH_MOVED
,
878 gfx::Point(500, 500), 0, timestamp
));
880 // Now press a second finger.
881 timestamp
+= base::TimeDelta::FromSeconds(10);
882 PressTouchPoint(2, 2);
883 SetTouchTimestamp(timestamp
);
885 EXPECT_FALSE(TouchEventQueueEmpty());
886 expected_events
.push_back(new ui::TouchEvent(ui::ET_TOUCH_PRESSED
,
887 gfx::Point(2, 2), 1, timestamp
));
889 // Move both fingers.
890 timestamp
+= base::TimeDelta::FromSeconds(10);
891 MoveTouchPoint(0, 10, 10);
892 MoveTouchPoint(1, 20, 20);
893 SetTouchTimestamp(timestamp
);
895 EXPECT_FALSE(TouchEventQueueEmpty());
896 expected_events
.push_back(new ui::TouchEvent(ui::ET_TOUCH_MOVED
,
897 gfx::Point(10, 10), 0, timestamp
));
898 expected_events
.push_back(new ui::TouchEvent(ui::ET_TOUCH_MOVED
,
899 gfx::Point(20, 20), 1, timestamp
));
901 // Receive the ACKs and make sure the generated events from the acked events
903 WebInputEvent::Type acks
[] = { WebInputEvent::TouchStart
,
904 WebInputEvent::TouchMove
,
905 WebInputEvent::TouchStart
,
906 WebInputEvent::TouchMove
};
908 TouchEventCoordinateSystem coordinate_system
= LOCAL_COORDINATES
;
910 coordinate_system
= SCREEN_COORDINATES
;
912 for (size_t i
= 0; i
< arraysize(acks
); ++i
) {
913 SendInputEventACK(acks
[i
],
914 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
915 EXPECT_EQ(acks
[i
], ack_handler_
->acked_touch_event().event
.type
);
916 ScopedVector
<ui::TouchEvent
> acked
;
918 MakeUITouchEventsFromWebTouchEvents(
919 ack_handler_
->acked_touch_event(), &acked
, coordinate_system
);
920 bool success
= EventListIsSubset(acked
, expected_events
);
921 EXPECT_TRUE(success
) << "Failed on step: " << i
;
924 expected_events
.erase(expected_events
.begin(),
925 expected_events
.begin() + acked
.size());
928 EXPECT_TRUE(TouchEventQueueEmpty());
929 EXPECT_EQ(0U, expected_events
.size());
931 #endif // defined(USE_AURA)
933 TEST_F(InputRouterImplTest
, UnhandledWheelEvent
) {
934 // Simulate wheel events.
935 SimulateWheelEvent(0, -5, 0, false); // sent directly
936 SimulateWheelEvent(0, -10, 0, false); // enqueued
938 // Check that only the first event was sent.
939 EXPECT_TRUE(process_
->sink().GetUniqueMessageMatching(
940 InputMsg_HandleInputEvent::ID
));
941 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
943 // Indicate that the wheel event was unhandled.
944 SendInputEventACK(WebInputEvent::MouseWheel
,
945 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
947 // Check that the correct unhandled wheel event was received.
948 EXPECT_EQ(1U, ack_handler_
->GetAndResetAckCount());
949 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
, ack_handler_
->ack_state());
950 EXPECT_EQ(ack_handler_
->acked_wheel_event().deltaY
, -5);
952 // Check that the second event was sent.
953 EXPECT_TRUE(process_
->sink().GetUniqueMessageMatching(
954 InputMsg_HandleInputEvent::ID
));
955 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
957 // Check that the correct unhandled wheel event was received.
958 EXPECT_EQ(ack_handler_
->acked_wheel_event().deltaY
, -5);
961 TEST_F(InputRouterImplTest
, TouchTypesIgnoringAck
) {
962 OnHasTouchEventHandlers(true);
963 // Only acks for TouchCancel should always be ignored.
964 ASSERT_FALSE(WebInputEventTraits::IgnoresAckDisposition(
965 GetEventWithType(WebInputEvent::TouchStart
)));
966 ASSERT_FALSE(WebInputEventTraits::IgnoresAckDisposition(
967 GetEventWithType(WebInputEvent::TouchMove
)));
968 ASSERT_FALSE(WebInputEventTraits::IgnoresAckDisposition(
969 GetEventWithType(WebInputEvent::TouchEnd
)));
971 // Precede the TouchCancel with an appropriate TouchStart;
972 PressTouchPoint(1, 1);
974 SendInputEventACK(WebInputEvent::TouchStart
, INPUT_EVENT_ACK_STATE_CONSUMED
);
975 ASSERT_EQ(1U, GetSentMessageCountAndResetSink());
976 ASSERT_EQ(1U, ack_handler_
->GetAndResetAckCount());
977 ASSERT_EQ(0, client_
->in_flight_event_count());
979 // The TouchCancel ack is always ignored.
982 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
983 EXPECT_EQ(1U, ack_handler_
->GetAndResetAckCount());
984 EXPECT_EQ(0, client_
->in_flight_event_count());
985 EXPECT_FALSE(HasPendingEvents());
986 SendInputEventACK(WebInputEvent::TouchCancel
,
987 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
988 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
989 EXPECT_EQ(0U, ack_handler_
->GetAndResetAckCount());
990 EXPECT_FALSE(HasPendingEvents());
993 TEST_F(InputRouterImplTest
, GestureTypesIgnoringAck
) {
994 // We test every gesture type, ensuring that the stream of gestures is valid.
995 const WebInputEvent::Type eventTypes
[] = {
996 WebInputEvent::GestureTapDown
,
997 WebInputEvent::GestureShowPress
,
998 WebInputEvent::GestureTapCancel
,
999 WebInputEvent::GestureScrollBegin
,
1000 WebInputEvent::GestureFlingStart
,
1001 WebInputEvent::GestureFlingCancel
,
1002 WebInputEvent::GestureTapDown
,
1003 WebInputEvent::GestureTap
,
1004 WebInputEvent::GestureTapDown
,
1005 WebInputEvent::GestureLongPress
,
1006 WebInputEvent::GestureTapCancel
,
1007 WebInputEvent::GestureLongTap
,
1008 WebInputEvent::GestureTapDown
,
1009 WebInputEvent::GestureTapUnconfirmed
,
1010 WebInputEvent::GestureTapCancel
,
1011 WebInputEvent::GestureTapDown
,
1012 WebInputEvent::GestureDoubleTap
,
1013 WebInputEvent::GestureTapDown
,
1014 WebInputEvent::GestureTapCancel
,
1015 WebInputEvent::GestureTwoFingerTap
,
1016 WebInputEvent::GestureTapDown
,
1017 WebInputEvent::GestureTapCancel
,
1018 WebInputEvent::GestureScrollBegin
,
1019 WebInputEvent::GestureScrollUpdate
,
1020 WebInputEvent::GesturePinchBegin
,
1021 WebInputEvent::GesturePinchUpdate
,
1022 WebInputEvent::GesturePinchEnd
,
1023 WebInputEvent::GestureScrollEnd
};
1024 for (size_t i
= 0; i
< arraysize(eventTypes
); ++i
) {
1025 WebInputEvent::Type type
= eventTypes
[i
];
1026 SCOPED_TRACE(WebInputEventTraits::GetName(type
));
1027 if (!WebInputEventTraits::IgnoresAckDisposition(GetEventWithType(type
))) {
1028 SimulateGestureEvent(type
, blink::WebGestureDeviceTouchscreen
);
1029 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1030 EXPECT_EQ(0U, ack_handler_
->GetAndResetAckCount());
1031 EXPECT_EQ(1, client_
->in_flight_event_count());
1032 EXPECT_TRUE(HasPendingEvents());
1034 SendInputEventACK(type
, INPUT_EVENT_ACK_STATE_CONSUMED
);
1035 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1036 EXPECT_EQ(1U, ack_handler_
->GetAndResetAckCount());
1037 EXPECT_EQ(0, client_
->in_flight_event_count());
1039 // A GestureFlingCancel will be dropped unless there's an active
1040 // fling, and an active fling is considered a "pending" event. This rather
1041 // nasty bookkeeping is necessary to ensure the fling cancel gets properly
1042 // dispatched and the pending event expectations are valid.
1043 if (type
== blink::WebInputEvent::GestureFlingCancel
)
1044 NotifyDidStopFlinging();
1045 if (type
!= blink::WebInputEvent::GestureFlingStart
)
1046 EXPECT_FALSE(HasPendingEvents());
1051 SimulateGestureEvent(type
, blink::WebGestureDeviceTouchscreen
);
1052 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1053 EXPECT_EQ(1U, ack_handler_
->GetAndResetAckCount());
1054 EXPECT_EQ(0, client_
->in_flight_event_count());
1055 EXPECT_FALSE(HasPendingEvents());
1059 TEST_F(InputRouterImplTest
, MouseTypesIgnoringAck
) {
1060 int start_type
= static_cast<int>(WebInputEvent::MouseDown
);
1061 int end_type
= static_cast<int>(WebInputEvent::ContextMenu
);
1062 ASSERT_LT(start_type
, end_type
);
1063 for (int i
= start_type
; i
<= end_type
; ++i
) {
1064 WebInputEvent::Type type
= static_cast<WebInputEvent::Type
>(i
);
1065 int expected_in_flight_event_count
=
1066 WebInputEventTraits::IgnoresAckDisposition(GetEventWithType(type
)) ? 0
1069 // Note: Mouse event acks are never forwarded to the ack handler, so the key
1070 // result here is that ignored ack types don't affect the in-flight count.
1071 SimulateMouseEvent(type
, 0, 0);
1072 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1073 EXPECT_EQ(0U, ack_handler_
->GetAndResetAckCount());
1074 EXPECT_EQ(expected_in_flight_event_count
, client_
->in_flight_event_count());
1075 if (expected_in_flight_event_count
) {
1076 SendInputEventACK(type
, INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1077 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1078 EXPECT_EQ(0U, ack_handler_
->GetAndResetAckCount());
1079 EXPECT_EQ(0, client_
->in_flight_event_count());
1084 // Guard against breaking changes to the list of ignored event ack types in
1085 // |WebInputEventTraits::IgnoresAckDisposition|.
1086 TEST_F(InputRouterImplTest
, RequiredEventAckTypes
) {
1087 const WebInputEvent::Type kRequiredEventAckTypes
[] = {
1088 WebInputEvent::MouseMove
,
1089 WebInputEvent::MouseWheel
,
1090 WebInputEvent::RawKeyDown
,
1091 WebInputEvent::KeyDown
,
1092 WebInputEvent::KeyUp
,
1093 WebInputEvent::Char
,
1094 WebInputEvent::GestureScrollUpdate
,
1095 WebInputEvent::GestureFlingStart
,
1096 WebInputEvent::GestureFlingCancel
,
1097 WebInputEvent::GesturePinchUpdate
,
1098 WebInputEvent::TouchStart
,
1099 WebInputEvent::TouchMove
1101 for (size_t i
= 0; i
< arraysize(kRequiredEventAckTypes
); ++i
) {
1102 const WebInputEvent::Type required_ack_type
= kRequiredEventAckTypes
[i
];
1103 EXPECT_FALSE(WebInputEventTraits::IgnoresAckDisposition(
1104 GetEventWithType(required_ack_type
)));
1108 // Test that GestureShowPress, GestureTapDown and GestureTapCancel events don't
1110 TEST_F(InputRouterImplTest
, GestureTypesIgnoringAckInterleaved
) {
1111 // Interleave a few events that do and do not ignore acks, ensuring that
1112 // ack-ignoring events aren't dispatched until all prior events which observe
1113 // their ack disposition have been dispatched.
1115 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
1116 blink::WebGestureDeviceTouchscreen
);
1117 ASSERT_EQ(1U, GetSentMessageCountAndResetSink());
1118 EXPECT_EQ(1U, ack_handler_
->GetAndResetAckCount());
1119 EXPECT_EQ(0, client_
->in_flight_event_count());
1121 SimulateGestureEvent(WebInputEvent::GestureScrollUpdate
,
1122 blink::WebGestureDeviceTouchscreen
);
1123 ASSERT_EQ(1U, GetSentMessageCountAndResetSink());
1124 EXPECT_EQ(0U, ack_handler_
->GetAndResetAckCount());
1125 EXPECT_EQ(1, client_
->in_flight_event_count());
1127 SimulateGestureEvent(WebInputEvent::GestureTapDown
,
1128 blink::WebGestureDeviceTouchscreen
);
1129 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1130 EXPECT_EQ(0U, ack_handler_
->GetAndResetAckCount());
1131 EXPECT_EQ(1, client_
->in_flight_event_count());
1133 SimulateGestureEvent(WebInputEvent::GestureScrollUpdate
,
1134 blink::WebGestureDeviceTouchscreen
);
1135 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1136 EXPECT_EQ(0U, ack_handler_
->GetAndResetAckCount());
1138 SimulateGestureEvent(WebInputEvent::GestureShowPress
,
1139 blink::WebGestureDeviceTouchscreen
);
1140 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1141 EXPECT_EQ(0U, ack_handler_
->GetAndResetAckCount());
1143 SimulateGestureEvent(WebInputEvent::GestureScrollUpdate
,
1144 blink::WebGestureDeviceTouchscreen
);
1145 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1146 EXPECT_EQ(0U, ack_handler_
->GetAndResetAckCount());
1148 SimulateGestureEvent(WebInputEvent::GestureTapCancel
,
1149 blink::WebGestureDeviceTouchscreen
);
1150 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1151 EXPECT_EQ(0U, ack_handler_
->GetAndResetAckCount());
1153 // Now ack each ack-respecting event. Ack-ignoring events should not be
1154 // dispatched until all prior events which observe ack disposition have been
1155 // fired, at which point they should be sent immediately. They should also
1156 // have no effect on the in-flight event count.
1157 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
1158 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1159 EXPECT_EQ(2U, GetSentMessageCountAndResetSink());
1160 EXPECT_EQ(2U, ack_handler_
->GetAndResetAckCount());
1161 EXPECT_EQ(1, client_
->in_flight_event_count());
1163 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
1164 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1165 EXPECT_EQ(2U, GetSentMessageCountAndResetSink());
1166 EXPECT_EQ(2U, ack_handler_
->GetAndResetAckCount());
1167 EXPECT_EQ(1, client_
->in_flight_event_count());
1169 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
1170 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1171 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1172 EXPECT_EQ(2U, ack_handler_
->GetAndResetAckCount());
1173 EXPECT_EQ(0, client_
->in_flight_event_count());
1176 // Test that GestureShowPress events don't get out of order due to
1177 // ignoring their acks.
1178 TEST_F(InputRouterImplTest
, GestureShowPressIsInOrder
) {
1179 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
1180 blink::WebGestureDeviceTouchscreen
);
1181 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1182 EXPECT_EQ(1U, ack_handler_
->GetAndResetAckCount());
1185 // GesturePinchBegin ignores its ack.
1186 SimulateGestureEvent(WebInputEvent::GesturePinchBegin
,
1187 blink::WebGestureDeviceTouchscreen
);
1188 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1189 EXPECT_EQ(1U, ack_handler_
->GetAndResetAckCount());
1191 // GesturePinchUpdate waits for an ack.
1192 // This also verifies that GesturePinchUpdates for touchscreen are sent
1193 // to the renderer (in contrast to the TrackpadPinchUpdate test).
1194 SimulateGestureEvent(WebInputEvent::GesturePinchUpdate
,
1195 blink::WebGestureDeviceTouchscreen
);
1196 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1197 EXPECT_EQ(0U, ack_handler_
->GetAndResetAckCount());
1199 SimulateGestureEvent(WebInputEvent::GestureShowPress
,
1200 blink::WebGestureDeviceTouchscreen
);
1201 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1202 // The ShowPress, though it ignores ack, is still stuck in the queue
1203 // behind the PinchUpdate which requires an ack.
1204 EXPECT_EQ(0U, ack_handler_
->GetAndResetAckCount());
1206 SimulateGestureEvent(WebInputEvent::GestureShowPress
,
1207 blink::WebGestureDeviceTouchscreen
);
1208 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1209 // ShowPress has entered the queue.
1210 EXPECT_EQ(0U, ack_handler_
->GetAndResetAckCount());
1212 SendInputEventACK(WebInputEvent::GesturePinchUpdate
,
1213 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1214 // Now that the Tap has been ACKed, the ShowPress events should receive
1215 // synthetic acks, and fire immediately.
1216 EXPECT_EQ(2U, GetSentMessageCountAndResetSink());
1217 EXPECT_EQ(3U, ack_handler_
->GetAndResetAckCount());
1220 // Test that touch ack timeout behavior is properly toggled by view update flags
1221 // and allowed touch actions.
1222 TEST_F(InputRouterImplTest
, TouchAckTimeoutConfigured
) {
1223 const int timeout_ms
= 1;
1224 SetUpForTouchAckTimeoutTest(timeout_ms
);
1225 ASSERT_TRUE(TouchEventTimeoutEnabled());
1227 // Verify that the touch ack timeout fires upon the delayed ack.
1228 PressTouchPoint(1, 1);
1230 EXPECT_EQ(0U, ack_handler_
->GetAndResetAckCount());
1231 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1232 RunTasksAndWait(base::TimeDelta::FromMilliseconds(timeout_ms
+ 1));
1234 // The timed-out event should have been ack'ed.
1235 EXPECT_EQ(1U, ack_handler_
->GetAndResetAckCount());
1236 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1238 // Ack'ing the timed-out event should fire a TouchCancel.
1239 SendInputEventACK(WebInputEvent::TouchStart
, INPUT_EVENT_ACK_STATE_CONSUMED
);
1240 EXPECT_EQ(0U, ack_handler_
->GetAndResetAckCount());
1241 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1243 // The remainder of the touch sequence should be dropped.
1244 ReleaseTouchPoint(0);
1246 EXPECT_EQ(1U, ack_handler_
->GetAndResetAckCount());
1247 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1248 ASSERT_TRUE(TouchEventTimeoutEnabled());
1250 // A fixed page scale or mobile viewport should disable the touch timeout.
1251 input_router()->OnViewUpdated(InputRouter::FIXED_PAGE_SCALE
);
1252 EXPECT_FALSE(TouchEventTimeoutEnabled());
1254 input_router()->OnViewUpdated(InputRouter::VIEW_FLAGS_NONE
);
1255 EXPECT_TRUE(TouchEventTimeoutEnabled());
1257 input_router()->OnViewUpdated(InputRouter::MOBILE_VIEWPORT
);
1258 EXPECT_FALSE(TouchEventTimeoutEnabled());
1260 input_router()->OnViewUpdated(InputRouter::MOBILE_VIEWPORT
|
1261 InputRouter::FIXED_PAGE_SCALE
);
1262 EXPECT_FALSE(TouchEventTimeoutEnabled());
1264 input_router()->OnViewUpdated(InputRouter::VIEW_FLAGS_NONE
);
1265 EXPECT_TRUE(TouchEventTimeoutEnabled());
1267 // TOUCH_ACTION_NONE (and no other touch-action) should disable the timeout.
1268 OnHasTouchEventHandlers(true);
1269 PressTouchPoint(1, 1);
1271 OnSetTouchAction(TOUCH_ACTION_PAN_Y
);
1272 EXPECT_TRUE(TouchEventTimeoutEnabled());
1273 ReleaseTouchPoint(0);
1275 SendInputEventACK(WebInputEvent::TouchStart
, INPUT_EVENT_ACK_STATE_CONSUMED
);
1276 SendInputEventACK(WebInputEvent::TouchEnd
, INPUT_EVENT_ACK_STATE_CONSUMED
);
1278 PressTouchPoint(1, 1);
1280 OnSetTouchAction(TOUCH_ACTION_NONE
);
1281 EXPECT_FALSE(TouchEventTimeoutEnabled());
1282 ReleaseTouchPoint(0);
1284 SendInputEventACK(WebInputEvent::TouchStart
, INPUT_EVENT_ACK_STATE_CONSUMED
);
1285 SendInputEventACK(WebInputEvent::TouchEnd
, INPUT_EVENT_ACK_STATE_CONSUMED
);
1287 // As the touch-action is reset by a new touch sequence, the timeout behavior
1288 // should be restored.
1289 PressTouchPoint(1, 1);
1291 EXPECT_TRUE(TouchEventTimeoutEnabled());
1294 // Test that a touch sequenced preceded by TOUCH_ACTION_NONE is not affected by
1295 // the touch timeout.
1296 TEST_F(InputRouterImplTest
,
1297 TouchAckTimeoutDisabledForTouchSequenceAfterTouchActionNone
) {
1298 const int timeout_ms
= 1;
1299 SetUpForTouchAckTimeoutTest(timeout_ms
);
1300 ASSERT_TRUE(TouchEventTimeoutEnabled());
1301 OnHasTouchEventHandlers(true);
1303 // Start a touch sequence.
1304 PressTouchPoint(1, 1);
1306 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1308 // TOUCH_ACTION_NONE should disable the timeout.
1309 OnSetTouchAction(TOUCH_ACTION_NONE
);
1310 SendInputEventACK(WebInputEvent::TouchStart
, INPUT_EVENT_ACK_STATE_CONSUMED
);
1311 EXPECT_EQ(1U, ack_handler_
->GetAndResetAckCount());
1312 EXPECT_FALSE(TouchEventTimeoutEnabled());
1314 MoveTouchPoint(0, 1, 2);
1316 EXPECT_FALSE(TouchEventTimeoutEnabled());
1317 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1319 // Delay the move ack. The timeout should not fire.
1320 RunTasksAndWait(base::TimeDelta::FromMilliseconds(timeout_ms
+ 1));
1321 EXPECT_EQ(0U, ack_handler_
->GetAndResetAckCount());
1322 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1323 SendInputEventACK(WebInputEvent::TouchEnd
, INPUT_EVENT_ACK_STATE_CONSUMED
);
1324 EXPECT_EQ(1U, ack_handler_
->GetAndResetAckCount());
1326 // End the touch sequence.
1327 ReleaseTouchPoint(0);
1329 SendInputEventACK(WebInputEvent::TouchEnd
, INPUT_EVENT_ACK_STATE_CONSUMED
);
1330 EXPECT_FALSE(TouchEventTimeoutEnabled());
1331 ack_handler_
->GetAndResetAckCount();
1332 GetSentMessageCountAndResetSink();
1334 // Start another touch sequence. This should restore the touch timeout.
1335 PressTouchPoint(1, 1);
1337 EXPECT_TRUE(TouchEventTimeoutEnabled());
1338 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1339 EXPECT_EQ(0U, ack_handler_
->GetAndResetAckCount());
1341 // Wait for the touch ack timeout to fire.
1342 RunTasksAndWait(base::TimeDelta::FromMilliseconds(timeout_ms
+ 1));
1343 EXPECT_EQ(1U, ack_handler_
->GetAndResetAckCount());
1346 // Test that TouchActionFilter::ResetTouchAction is called before the
1347 // first touch event for a touch sequence reaches the renderer.
1348 TEST_F(InputRouterImplTest
, TouchActionResetBeforeEventReachesRenderer
) {
1349 OnHasTouchEventHandlers(true);
1352 PressTouchPoint(1, 1);
1354 OnSetTouchAction(TOUCH_ACTION_NONE
);
1355 MoveTouchPoint(0, 50, 50);
1357 ReleaseTouchPoint(0);
1361 PressTouchPoint(1, 1);
1363 MoveTouchPoint(0, 50, 50);
1365 ReleaseTouchPoint(0);
1368 SendInputEventACK(WebInputEvent::TouchStart
, INPUT_EVENT_ACK_STATE_CONSUMED
);
1369 SendInputEventACK(WebInputEvent::TouchMove
, INPUT_EVENT_ACK_STATE_CONSUMED
);
1371 // Ensure touch action is still none, as the next touch start hasn't been
1372 // acked yet. ScrollBegin and ScrollEnd don't require acks.
1373 EXPECT_EQ(3U, GetSentMessageCountAndResetSink());
1374 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
1375 blink::WebGestureDeviceTouchscreen
);
1376 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1377 SimulateGestureEvent(WebInputEvent::GestureScrollEnd
,
1378 blink::WebGestureDeviceTouchscreen
);
1379 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1381 // This allows the next touch sequence to start.
1382 SendInputEventACK(WebInputEvent::TouchEnd
, INPUT_EVENT_ACK_STATE_CONSUMED
);
1384 // Ensure touch action has been set to auto, as a new touch sequence has
1386 SendInputEventACK(WebInputEvent::TouchStart
, INPUT_EVENT_ACK_STATE_CONSUMED
);
1387 SendInputEventACK(WebInputEvent::TouchMove
, INPUT_EVENT_ACK_STATE_CONSUMED
);
1388 EXPECT_EQ(3U, GetSentMessageCountAndResetSink());
1389 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
1390 blink::WebGestureDeviceTouchscreen
);
1391 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1392 SimulateGestureEvent(WebInputEvent::GestureScrollEnd
,
1393 blink::WebGestureDeviceTouchscreen
);
1394 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1395 SendInputEventACK(WebInputEvent::TouchEnd
, INPUT_EVENT_ACK_STATE_CONSUMED
);
1398 // Test that TouchActionFilter::ResetTouchAction is called when a new touch
1399 // sequence has no consumer.
1400 TEST_F(InputRouterImplTest
, TouchActionResetWhenTouchHasNoConsumer
) {
1401 OnHasTouchEventHandlers(true);
1404 PressTouchPoint(1, 1);
1406 MoveTouchPoint(0, 50, 50);
1408 OnSetTouchAction(TOUCH_ACTION_NONE
);
1409 SendInputEventACK(WebInputEvent::TouchStart
, INPUT_EVENT_ACK_STATE_CONSUMED
);
1410 SendInputEventACK(WebInputEvent::TouchMove
, INPUT_EVENT_ACK_STATE_CONSUMED
);
1412 ReleaseTouchPoint(0);
1416 PressTouchPoint(1, 1);
1418 MoveTouchPoint(0, 50, 50);
1420 ReleaseTouchPoint(0);
1423 // Ensure we have touch-action:none. ScrollBegin and ScrollEnd don't require
1425 EXPECT_EQ(3U, GetSentMessageCountAndResetSink());
1426 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
1427 blink::WebGestureDeviceTouchscreen
);
1428 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1429 SimulateGestureEvent(WebInputEvent::GestureScrollEnd
,
1430 blink::WebGestureDeviceTouchscreen
);
1431 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1433 SendInputEventACK(WebInputEvent::TouchEnd
, INPUT_EVENT_ACK_STATE_CONSUMED
);
1434 SendInputEventACK(WebInputEvent::TouchStart
,
1435 INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS
);
1437 // Ensure touch action has been set to auto, as the touch had no consumer.
1438 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1439 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
1440 blink::WebGestureDeviceTouchscreen
);
1441 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1442 SimulateGestureEvent(WebInputEvent::GestureScrollEnd
,
1443 blink::WebGestureDeviceTouchscreen
);
1444 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1447 // Test that TouchActionFilter::ResetTouchAction is called when the touch
1448 // handler is removed.
1449 TEST_F(InputRouterImplTest
, TouchActionResetWhenTouchHandlerRemoved
) {
1450 // Touch sequence with touch handler.
1451 OnHasTouchEventHandlers(true);
1452 PressTouchPoint(1, 1);
1454 MoveTouchPoint(0, 50, 50);
1456 OnSetTouchAction(TOUCH_ACTION_NONE
);
1457 ReleaseTouchPoint(0);
1459 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1461 // Ensure we have touch-action:none, suppressing scroll events.
1462 SendInputEventACK(WebInputEvent::TouchStart
, INPUT_EVENT_ACK_STATE_CONSUMED
);
1463 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1464 SendInputEventACK(WebInputEvent::TouchMove
,
1465 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1466 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1467 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
1468 blink::WebGestureDeviceTouchscreen
);
1469 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1471 SendInputEventACK(WebInputEvent::TouchEnd
,
1472 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1473 SimulateGestureEvent(WebInputEvent::GestureScrollEnd
,
1474 blink::WebGestureDeviceTouchscreen
);
1475 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1477 // Sequence without a touch handler. Note that in this case, the view may not
1478 // necessarily forward touches to the router (as no touch handler exists).
1479 OnHasTouchEventHandlers(false);
1481 // Ensure touch action has been set to auto, as the touch handler has been
1483 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
1484 blink::WebGestureDeviceTouchscreen
);
1485 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1486 SimulateGestureEvent(WebInputEvent::GestureScrollEnd
,
1487 blink::WebGestureDeviceTouchscreen
);
1488 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1491 // Test that the double tap gesture depends on the touch action of the first
1493 TEST_F(InputRouterImplTest
, DoubleTapGestureDependsOnFirstTap
) {
1494 OnHasTouchEventHandlers(true);
1497 PressTouchPoint(1, 1);
1499 OnSetTouchAction(TOUCH_ACTION_NONE
);
1500 SendInputEventACK(WebInputEvent::TouchStart
, INPUT_EVENT_ACK_STATE_CONSUMED
);
1502 ReleaseTouchPoint(0);
1506 PressTouchPoint(1, 1);
1510 EXPECT_EQ(2U, GetSentMessageCountAndResetSink());
1511 SimulateGestureEvent(WebInputEvent::GestureTapDown
,
1512 blink::WebGestureDeviceTouchscreen
);
1513 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1515 // The GestureTapUnconfirmed is converted into a tap, as the touch action is
1517 SimulateGestureEvent(WebInputEvent::GestureTapUnconfirmed
,
1518 blink::WebGestureDeviceTouchscreen
);
1519 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1520 // This test will become invalid if GestureTap stops requiring an ack.
1521 ASSERT_FALSE(WebInputEventTraits::IgnoresAckDisposition(
1522 GetEventWithType(WebInputEvent::GestureTap
)));
1523 EXPECT_EQ(2, client_
->in_flight_event_count());
1524 SendInputEventACK(WebInputEvent::GestureTap
,
1525 INPUT_EVENT_ACK_STATE_CONSUMED
);
1526 EXPECT_EQ(1, client_
->in_flight_event_count());
1528 // This tap gesture is dropped, since the GestureTapUnconfirmed was turned
1530 SimulateGestureEvent(WebInputEvent::GestureTap
,
1531 blink::WebGestureDeviceTouchscreen
);
1532 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1534 SendInputEventACK(WebInputEvent::TouchEnd
, INPUT_EVENT_ACK_STATE_CONSUMED
);
1535 SendInputEventACK(WebInputEvent::TouchStart
,
1536 INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS
);
1539 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1540 SimulateGestureEvent(WebInputEvent::GestureTapDown
,
1541 blink::WebGestureDeviceTouchscreen
);
1542 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1544 // Although the touch-action is now auto, the double tap still won't be
1545 // dispatched, because the first tap occured when the touch-action was none.
1546 SimulateGestureEvent(WebInputEvent::GestureDoubleTap
,
1547 blink::WebGestureDeviceTouchscreen
);
1548 // This test will become invalid if GestureDoubleTap stops requiring an ack.
1549 ASSERT_FALSE(WebInputEventTraits::IgnoresAckDisposition(
1550 GetEventWithType(WebInputEvent::GestureDoubleTap
)));
1551 EXPECT_EQ(1, client_
->in_flight_event_count());
1552 SendInputEventACK(WebInputEvent::GestureTap
, INPUT_EVENT_ACK_STATE_CONSUMED
);
1553 EXPECT_EQ(0, client_
->in_flight_event_count());
1556 // Test that the router will call the client's |DidFlush| after all events have
1557 // been dispatched following a call to |Flush|.
1558 TEST_F(InputRouterImplTest
, InputFlush
) {
1559 EXPECT_FALSE(HasPendingEvents());
1561 // Flushing an empty router should immediately trigger DidFlush.
1562 RequestNotificationWhenFlushed();
1563 EXPECT_EQ(1U, GetAndResetDidFlushCount());
1564 EXPECT_FALSE(HasPendingEvents());
1566 // Queue a TouchStart.
1567 OnHasTouchEventHandlers(true);
1568 PressTouchPoint(1, 1);
1570 EXPECT_TRUE(HasPendingEvents());
1572 // DidFlush should be called only after the event is ack'ed.
1573 RequestNotificationWhenFlushed();
1574 EXPECT_EQ(0U, GetAndResetDidFlushCount());
1575 SendInputEventACK(WebInputEvent::TouchStart
,
1576 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1577 EXPECT_EQ(1U, GetAndResetDidFlushCount());
1579 // Ensure different types of enqueued events will prevent the DidFlush call
1580 // until all such events have been fully dispatched.
1581 MoveTouchPoint(0, 50, 50);
1583 ASSERT_TRUE(HasPendingEvents());
1584 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
1585 blink::WebGestureDeviceTouchscreen
);
1586 SimulateGestureEvent(WebInputEvent::GestureScrollUpdate
,
1587 blink::WebGestureDeviceTouchscreen
);
1588 SimulateGestureEvent(WebInputEvent::GesturePinchBegin
,
1589 blink::WebGestureDeviceTouchscreen
);
1590 SimulateGestureEvent(WebInputEvent::GesturePinchUpdate
,
1591 blink::WebGestureDeviceTouchscreen
);
1592 RequestNotificationWhenFlushed();
1593 EXPECT_EQ(0U, GetAndResetDidFlushCount());
1595 // Repeated flush calls should have no effect.
1596 RequestNotificationWhenFlushed();
1597 EXPECT_EQ(0U, GetAndResetDidFlushCount());
1599 // There are still pending gestures.
1600 SendInputEventACK(WebInputEvent::TouchMove
,
1601 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1602 EXPECT_EQ(0U, GetAndResetDidFlushCount());
1603 EXPECT_TRUE(HasPendingEvents());
1605 // One more gesture to go.
1606 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
1607 INPUT_EVENT_ACK_STATE_CONSUMED
);
1608 EXPECT_EQ(0U, GetAndResetDidFlushCount());
1609 EXPECT_TRUE(HasPendingEvents());
1611 // The final ack'ed gesture should trigger the DidFlush.
1612 SendInputEventACK(WebInputEvent::GesturePinchUpdate
,
1613 INPUT_EVENT_ACK_STATE_CONSUMED
);
1614 EXPECT_EQ(1U, GetAndResetDidFlushCount());
1615 EXPECT_FALSE(HasPendingEvents());
1618 // Test that the router will call the client's |DidFlush| after all fling
1619 // animations have completed.
1620 TEST_F(InputRouterImplTest
, InputFlushAfterFling
) {
1621 EXPECT_FALSE(HasPendingEvents());
1623 // Simulate a fling.
1624 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
1625 blink::WebGestureDeviceTouchscreen
);
1626 SimulateGestureEvent(WebInputEvent::GestureFlingStart
,
1627 blink::WebGestureDeviceTouchscreen
);
1628 EXPECT_TRUE(HasPendingEvents());
1630 // If the fling is unconsumed, the flush is complete.
1631 RequestNotificationWhenFlushed();
1632 EXPECT_EQ(0U, GetAndResetDidFlushCount());
1633 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
1634 blink::WebGestureDeviceTouchscreen
);
1635 SendInputEventACK(WebInputEvent::GestureFlingStart
,
1636 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1637 EXPECT_FALSE(HasPendingEvents());
1638 EXPECT_EQ(1U, GetAndResetDidFlushCount());
1640 // Simulate a second fling.
1641 SimulateGestureEvent(WebInputEvent::GestureFlingStart
,
1642 blink::WebGestureDeviceTouchscreen
);
1643 EXPECT_TRUE(HasPendingEvents());
1645 // If the fling is consumed, the flush is complete only when the renderer
1646 // reports that is has ended.
1647 RequestNotificationWhenFlushed();
1648 EXPECT_EQ(0U, GetAndResetDidFlushCount());
1649 SendInputEventACK(WebInputEvent::GestureFlingStart
,
1650 INPUT_EVENT_ACK_STATE_CONSUMED
);
1651 EXPECT_TRUE(HasPendingEvents());
1652 EXPECT_EQ(0U, GetAndResetDidFlushCount());
1654 // The fling end notification should signal that the router is flushed.
1655 NotifyDidStopFlinging();
1656 EXPECT_EQ(1U, GetAndResetDidFlushCount());
1659 // Test that GesturePinchUpdate is handled specially for trackpad
1660 TEST_F(InputRouterImplTest
, TouchpadPinchUpdate
) {
1661 // GesturePinchUpdate for trackpad sends synthetic wheel events.
1662 // Note that the Touchscreen case is verified as NOT doing this as
1663 // part of the ShowPressIsInOrder test.
1665 SimulateGesturePinchUpdateEvent(
1666 1.5f
, 20, 25, 0, blink::WebGestureDeviceTouchpad
);
1668 // Verify we actually sent a special wheel event to the renderer.
1669 const WebInputEvent
* input_event
=
1670 GetInputEventFromMessage(*process_
->sink().GetMessageAt(0));
1671 ASSERT_EQ(WebInputEvent::GesturePinchUpdate
, input_event
->type
);
1672 const WebGestureEvent
* gesture_event
=
1673 static_cast<const WebGestureEvent
*>(input_event
);
1674 EXPECT_EQ(20, gesture_event
->x
);
1675 EXPECT_EQ(25, gesture_event
->y
);
1676 EXPECT_EQ(20, gesture_event
->globalX
);
1677 EXPECT_EQ(25, gesture_event
->globalY
);
1678 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1680 // Indicate that the wheel event was unhandled.
1681 SendInputEventACK(WebInputEvent::GesturePinchUpdate
,
1682 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1684 // Check that the correct unhandled pinch event was received.
1685 EXPECT_EQ(1U, ack_handler_
->GetAndResetAckCount());
1686 ASSERT_EQ(WebInputEvent::GesturePinchUpdate
, ack_handler_
->ack_event_type());
1687 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
, ack_handler_
->ack_state());
1688 EXPECT_EQ(1.5f
, ack_handler_
->acked_gesture_event().data
.pinchUpdate
.scale
);
1689 EXPECT_EQ(0, client_
->in_flight_event_count());
1691 // Second a second pinch event.
1692 SimulateGesturePinchUpdateEvent(
1693 0.3f
, 20, 25, 0, blink::WebGestureDeviceTouchpad
);
1694 input_event
= GetInputEventFromMessage(*process_
->sink().GetMessageAt(0));
1695 ASSERT_EQ(WebInputEvent::GesturePinchUpdate
, input_event
->type
);
1696 gesture_event
= static_cast<const WebGestureEvent
*>(input_event
);
1697 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1699 // Indicate that the wheel event was handled this time.
1700 SendInputEventACK(WebInputEvent::GesturePinchUpdate
,
1701 INPUT_EVENT_ACK_STATE_CONSUMED
);
1703 // Check that the correct HANDLED pinch event was received.
1704 EXPECT_EQ(1U, ack_handler_
->GetAndResetAckCount());
1705 EXPECT_EQ(WebInputEvent::GesturePinchUpdate
, ack_handler_
->ack_event_type());
1706 EXPECT_EQ(INPUT_EVENT_ACK_STATE_CONSUMED
, ack_handler_
->ack_state());
1707 EXPECT_FLOAT_EQ(0.3f
,
1708 ack_handler_
->acked_gesture_event().data
.pinchUpdate
.scale
);
1711 // Test proper handling of touchpad Gesture{Pinch,Scroll}Update sequences.
1712 TEST_F(InputRouterImplTest
, TouchpadPinchAndScrollUpdate
) {
1713 // The first scroll should be sent immediately.
1714 SimulateGestureScrollUpdateEvent(1.5f
, 0.f
, 0,
1715 blink::WebGestureDeviceTouchpad
);
1716 SimulateGestureEvent(WebInputEvent::GestureScrollUpdate
,
1717 blink::WebGestureDeviceTouchpad
);
1718 ASSERT_EQ(1U, GetSentMessageCountAndResetSink());
1719 EXPECT_EQ(1, client_
->in_flight_event_count());
1721 // Subsequent scroll and pinch events should remain queued, coalescing as
1722 // more trackpad events arrive.
1723 SimulateGesturePinchUpdateEvent(1.5f
, 20, 25, 0,
1724 blink::WebGestureDeviceTouchpad
);
1725 ASSERT_EQ(0U, GetSentMessageCountAndResetSink());
1726 EXPECT_EQ(1, client_
->in_flight_event_count());
1728 SimulateGestureScrollUpdateEvent(1.5f
, 1.5f
, 0,
1729 blink::WebGestureDeviceTouchpad
);
1730 ASSERT_EQ(0U, GetSentMessageCountAndResetSink());
1731 EXPECT_EQ(1, client_
->in_flight_event_count());
1733 SimulateGesturePinchUpdateEvent(1.5f
, 20, 25, 0,
1734 blink::WebGestureDeviceTouchpad
);
1735 ASSERT_EQ(0U, GetSentMessageCountAndResetSink());
1736 EXPECT_EQ(1, client_
->in_flight_event_count());
1738 SimulateGestureScrollUpdateEvent(0.f
, 1.5f
, 0,
1739 blink::WebGestureDeviceTouchpad
);
1740 ASSERT_EQ(0U, GetSentMessageCountAndResetSink());
1741 EXPECT_EQ(1, client_
->in_flight_event_count());
1743 // Ack'ing the first scroll should trigger both the coalesced scroll and the
1744 // coalesced pinch events (which is sent to the renderer as a wheel event).
1745 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
1746 INPUT_EVENT_ACK_STATE_CONSUMED
);
1747 EXPECT_EQ(1U, ack_handler_
->GetAndResetAckCount());
1748 EXPECT_EQ(2U, GetSentMessageCountAndResetSink());
1749 EXPECT_EQ(2, client_
->in_flight_event_count());
1751 // Ack the second scroll.
1752 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
1753 INPUT_EVENT_ACK_STATE_CONSUMED
);
1754 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1755 EXPECT_EQ(1U, ack_handler_
->GetAndResetAckCount());
1756 EXPECT_EQ(1, client_
->in_flight_event_count());
1758 // Ack the wheel event.
1759 SendInputEventACK(WebInputEvent::MouseWheel
, INPUT_EVENT_ACK_STATE_CONSUMED
);
1760 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1761 EXPECT_EQ(1U, ack_handler_
->GetAndResetAckCount());
1762 EXPECT_EQ(0, client_
->in_flight_event_count());
1765 // Test proper routing of overscroll notifications received either from
1766 // event acks or from |DidOverscroll| IPC messages.
1767 TEST_F(InputRouterImplTest
, OverscrollDispatch
) {
1768 DidOverscrollParams overscroll
;
1769 overscroll
.accumulated_overscroll
= gfx::Vector2dF(-14, 14);
1770 overscroll
.latest_overscroll_delta
= gfx::Vector2dF(-7, 0);
1771 overscroll
.current_fling_velocity
= gfx::Vector2dF(-1, 0);
1773 input_router_
->OnMessageReceived(InputHostMsg_DidOverscroll(0, overscroll
));
1774 DidOverscrollParams client_overscroll
= client_
->GetAndResetOverscroll();
1775 EXPECT_EQ(overscroll
.accumulated_overscroll
,
1776 client_overscroll
.accumulated_overscroll
);
1777 EXPECT_EQ(overscroll
.latest_overscroll_delta
,
1778 client_overscroll
.latest_overscroll_delta
);
1779 EXPECT_EQ(overscroll
.current_fling_velocity
,
1780 client_overscroll
.current_fling_velocity
);
1782 DidOverscrollParams wheel_overscroll
;
1783 wheel_overscroll
.accumulated_overscroll
= gfx::Vector2dF(7, -7);
1784 wheel_overscroll
.latest_overscroll_delta
= gfx::Vector2dF(3, 0);
1785 wheel_overscroll
.current_fling_velocity
= gfx::Vector2dF(1, 0);
1787 SimulateWheelEvent(3, 0, 0, false);
1788 InputHostMsg_HandleInputEvent_ACK_Params ack
;
1789 ack
.type
= WebInputEvent::MouseWheel
;
1790 ack
.state
= INPUT_EVENT_ACK_STATE_NOT_CONSUMED
;
1791 ack
.overscroll
.reset(new DidOverscrollParams(wheel_overscroll
));
1792 input_router_
->OnMessageReceived(InputHostMsg_HandleInputEvent_ACK(0, ack
));
1794 client_overscroll
= client_
->GetAndResetOverscroll();
1795 EXPECT_EQ(wheel_overscroll
.accumulated_overscroll
,
1796 client_overscroll
.accumulated_overscroll
);
1797 EXPECT_EQ(wheel_overscroll
.latest_overscroll_delta
,
1798 client_overscroll
.latest_overscroll_delta
);
1799 EXPECT_EQ(wheel_overscroll
.current_fling_velocity
,
1800 client_overscroll
.current_fling_velocity
);
1803 } // namespace content