chromium/content/browser/renderer_host/input/input_router_impl_unittest.cc

// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/input/input_router_impl.h"

#include <math.h>
#include <stddef.h>
#include <stdint.h>

#include <memory>
#include <tuple>
#include <vector>

#include "base/command_line.h"
#include "base/location.h"
#include "base/memory/raw_ptr.h"
#include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/task_environment.h"
#include "build/build_config.h"
#include "cc/input/touch_action.h"
#include "components/input/gesture_event_queue.h"
#include "components/input/switches.h"
#include "content/browser/renderer_host/input/mock_input_disposition_handler.h"
#include "content/browser/renderer_host/input/mock_input_router_client.h"
#include "content/browser/renderer_host/input/mock_render_widget_host_view_for_stylus_writing.h"
#include "content/browser/renderer_host/mock_render_widget_host.h"
#include "content/browser/scheduler/browser_ui_thread_scheduler.h"
#include "content/browser/site_instance_group.h"
#include "content/common/content_constants_internal.h"
#include "content/public/test/browser_task_environment.h"
#include "content/public/test/mock_render_process_host.h"
#include "content/public/test/test_browser_context.h"
#include "content/test/mock_render_widget_host_delegate.h"
#include "content/test/mock_widget_input_handler.h"
#include "content/test/test_render_view_host.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/input/synthetic_web_input_event_builders.h"
#include "third_party/blink/public/mojom/input/touch_event.mojom.h"
#include "ui/events/base_event_utils.h"
#include "ui/events/blink/blink_features.h"
#include "ui/events/blink/web_input_event_traits.h"
#include "ui/events/keycodes/keyboard_codes.h"

#if defined(USE_AURA)
#include "content/common/input/events_helper.h"
#include "ui/events/event.h"
#endif

SyntheticWebGestureEventBuilder;
SyntheticWebMouseEventBuilder;
SyntheticWebMouseWheelEventBuilder;
SyntheticWebTouchEvent;
WebGestureDevice;
WebGestureEvent;
WebInputEvent;
WebKeyboardEvent;
WebMouseEvent;
WebMouseWheelEvent;
WebTouchEvent;
WebTouchPoint;
DidOverscrollParams;
WebInputEventTraits;

namespace content {

namespace {

bool ShouldBlockEventStream(const blink::WebInputEvent& event) {}

WebInputEvent& GetEventWithType(WebInputEvent::Type type) {}

}  // namespace


class InputRouterImplTestBase : public testing::Test {};

class InputRouterImplTest : public InputRouterImplTestBase {};

TEST_F(InputRouterImplTest, HandledInputEvent) {}

TEST_F(InputRouterImplTest, ClientCanceledKeyboardEvent) {}

// Tests ported from RenderWidgetHostTest --------------------------------------

TEST_F(InputRouterImplTest, HandleKeyEventsWeSent) {}

TEST_F(InputRouterImplTest, CoalescesWheelEvents) {}

// Test that the active touch sequence count increment when the touch start is
// not ACKed from the main thread.
TEST_F(InputRouterImplTest, ActiveTouchSequenceCountWithoutTouchAction) {}

TEST_F(InputRouterImplTest,
       ActiveTouchSequenceCountWithoutTouchActionNoConsumer) {}

// Test that the active touch sequence count increment when the touch start is
// ACKed from the main thread.
TEST_F(InputRouterImplTest, ActiveTouchSequenceCountWithTouchAction) {}

TEST_F(InputRouterImplTest, ActiveTouchSequenceCountWithTouchActionNoConsumer) {}

// Test that after touch action is set from the main thread, the touch action
// won't be overridden by the call to TouchEventHandled.
TEST_F(InputRouterImplTest, TouchActionSetFromMainNotOverridden) {}

TEST_F(InputRouterImplTest, TouchActionAutoWithAckStateConsumed) {}

TEST_F(InputRouterImplTest, TouchActionAutoWithAckStateNotConsumed) {}

TEST_F(InputRouterImplTest, TouchActionAutoWithAckStateConsumedShouldBubble) {}

TEST_F(InputRouterImplTest, TouchActionAutoWithAckStateNoConsumerExists) {}

TEST_F(InputRouterImplTest, TouchActionAutoWithAckStateIgnored) {}

TEST_F(InputRouterImplTest, TouchActionAutoWithAckStateNonBlocking) {}

TEST_F(InputRouterImplTest, TouchActionAutoWithAckStateNonBlockingDueToFling) {}

// Tests that touch-events are sent properly.
TEST_F(InputRouterImplTest, TouchEventQueue) {}

// Tests that the touch-queue is emptied after a page stops listening for touch
// events and the outstanding ack is received.
TEST_F(InputRouterImplTest, TouchEventQueueFlush) {}

TEST_F(InputRouterImplTest, UnhandledWheelEvent) {}

TEST_F(InputRouterImplTest, TouchTypesIgnoringAck) {}

// Flaky on Linux: https://crbug.com/1295039
// Flaky on at least Win7 and Win10 as well: https://crbug.com/1326564
TEST_F(InputRouterImplTest, DISABLED_GestureTypesIgnoringAck) {}

TEST_F(InputRouterImplTest, MouseTypesIgnoringAck) {}

// Guard against breaking changes to the list of ignored event ack types in
// |WebInputEventTraits::ShouldBlockEventStream|.
TEST_F(InputRouterImplTest, RequiredEventAckTypes) {}

TEST_F(InputRouterImplTest, GestureTypesIgnoringAckInterleaved) {}

// Test that GestureShowPress events don't get out of order due to
// ignoring their acks.
TEST_F(InputRouterImplTest, GestureShowPressIsInOrder) {}

// Test that touch ack timeout behavior is properly configured for
// mobile-optimized sites and allowed touch actions.
TEST_F(InputRouterImplTest, TouchAckTimeoutConfigured) {}

// Test that a touch sequenced preceded by TouchAction::kNone is not affected by
// the touch timeout.
TEST_F(InputRouterImplTest,
       TouchAckTimeoutDisabledForTouchSequenceAfterTouchActionNone) {}

// Test that TouchActionFilter::ResetTouchAction is called before the
// first touch event for a touch sequence reaches the renderer.
TEST_F(InputRouterImplTest, TouchActionResetBeforeEventReachesRenderer) {}

// Test that TouchActionFilter::ResetTouchAction is called when a new touch
// sequence has no consumer.
TEST_F(InputRouterImplTest, TouchActionResetWhenTouchHasNoConsumer) {}

// Test that TouchActionFilter::ResetTouchAction is called when the touch
// handler is removed.
TEST_F(InputRouterImplTest, TouchActionResetWhenTouchHandlerRemoved) {}

// Tests that async touch-moves are ack'd from the browser side.
TEST_F(InputRouterImplTest, AsyncTouchMoveAckedImmediately) {}

// Test that the double tap gesture depends on the touch action of the first
// tap.
TEST_F(InputRouterImplTest, DoubleTapGestureDependsOnFirstTap) {}

// Test that GesturePinchUpdate is handled specially for trackpad
TEST_F(InputRouterImplTest, TouchpadPinchUpdate) {}

// Test proper handling of touchpad Gesture{Pinch,Scroll}Update sequences.
TEST_F(InputRouterImplTest, TouchpadPinchAndScrollUpdate) {}

// Test proper routing of overscroll notifications received either from
// event acks or from |DidOverscroll| IPC messages.
TEST_F(InputRouterImplTest, OverscrollDispatch) {}

// Tests that touch event stream validation passes when events are filtered
// out. See https://crbug.com/581231 for details.
TEST_F(InputRouterImplTest, TouchValidationPassesWithFilteredInputEvents) {}

TEST_F(InputRouterImplTest, TouchActionInCallback) {}

// TODO(crbug.com/40623448): enable this when the bug is fixed.
TEST_F(InputRouterImplTest,
       DISABLED_TimeoutMonitorStopWithMainThreadTouchAction) {}

namespace {

class InputRouterImplStylusWritingTest : public InputRouterImplTest {};

}  // namespace

// Tests that hover action stylus writable is set when pan action is received.
TEST_F(InputRouterImplStylusWritingTest, SetHoverActionStylusWritableToView) {}

// Tests that stylus writing is not started when touch action is not writable.
TEST_F(InputRouterImplStylusWritingTest,
       StylusWritingNotStartedForNotWritableTouchAction) {}

// Tests that stylus writing is not started when touch action is writable, but
// request to start stylus writing returned false.
TEST_F(InputRouterImplStylusWritingTest,
       StylusWritingNotStartedForTouchActionWritable) {}

// Tests that stylus writing is not started when touch action is writable,
// request to start stylus writing returns true but pointer count is more
// than 1.
TEST_F(InputRouterImplStylusWritingTest, StylusWritingNotStartedForMultiTouch) {}

// Tests that stylus writing is started when touch action is writable, and
// request to start stylus writing returns true, and pointer count is 1.
TEST_F(InputRouterImplStylusWritingTest,
       StylusWritingStartedForTouchActionWritable) {}

// Tests that GestureScrollBegin is filtered even if compositor touch action
// allows scroll.
TEST_F(InputRouterImplStylusWritingTest,
       StylusWritingFiltersGSBEvenWhenCompositorTouchActionAllows) {}

namespace {

class InputRouterImplScaleEventTest : public InputRouterImplTestBase {};

class InputRouterImplScaleMouseEventTest
    : public InputRouterImplScaleEventTest {};

}  // namespace

TEST_F(InputRouterImplScaleMouseEventTest, ScaleMouseEventTest) {}

TEST_F(InputRouterImplScaleEventTest, ScaleMouseWheelEventTest) {}

namespace {

class InputRouterImplScaleTouchEventTest
    : public InputRouterImplScaleEventTest {};

}  // namespace

TEST_F(InputRouterImplScaleTouchEventTest, ScaleTouchEventTest) {}

namespace {

class InputRouterImplScaleGestureEventTest
    : public InputRouterImplScaleEventTest {};

}  // namespace

TEST_F(InputRouterImplScaleGestureEventTest, GestureScroll) {}

TEST_F(InputRouterImplScaleGestureEventTest, GesturePinch) {}

TEST_F(InputRouterImplScaleGestureEventTest, GestureTap) {}

TEST_F(InputRouterImplScaleGestureEventTest, GestureDoubleTap) {}

TEST_F(InputRouterImplScaleGestureEventTest, GestureLongPress) {}

TEST_F(InputRouterImplScaleGestureEventTest, GestureTwoFingerTap) {}

}  // namespace content