chromium/third_party/blink/renderer/core/input/event_handler_test.cc

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

#include "third_party/blink/renderer/core/input/event_handler.h"

#include <memory>

#include "base/test/scoped_feature_list.h"
#include "build/build_config.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/input/web_gesture_event.h"
#include "third_party/blink/public/common/input/web_keyboard_event.h"
#include "third_party/blink/public/common/input/web_mouse_wheel_event.h"
#include "third_party/blink/public/common/input/web_pointer_event.h"
#include "third_party/blink/public/mojom/input/focus_type.mojom-blink.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/dom/focus_params.h"
#include "third_party/blink/renderer/core/dom/range.h"
#include "third_party/blink/renderer/core/editing/dom_selection.h"
#include "third_party/blink/renderer/core/editing/editing_behavior.h"
#include "third_party/blink/renderer/core/editing/editor.h"
#include "third_party/blink/renderer/core/editing/ephemeral_range.h"
#include "third_party/blink/renderer/core/editing/frame_selection.h"
#include "third_party/blink/renderer/core/editing/selection_controller.h"
#include "third_party/blink/renderer/core/editing/selection_template.h"
#include "third_party/blink/renderer/core/editing/testing/editing_test_base.h"
#include "third_party/blink/renderer/core/editing/testing/selection_sample.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/frame/local_frame_view.h"
#include "third_party/blink/renderer/core/frame/visual_viewport.h"
#include "third_party/blink/renderer/core/frame/web_frame_widget_impl.h"
#include "third_party/blink/renderer/core/frame/web_local_frame_impl.h"
#include "third_party/blink/renderer/core/html/canvas/html_canvas_element.h"
#include "third_party/blink/renderer/core/html/forms/html_input_element.h"
#include "third_party/blink/renderer/core/html/html_iframe_element.h"
#include "third_party/blink/renderer/core/layout/layout_box.h"
#include "third_party/blink/renderer/core/layout/layout_embedded_content.h"
#include "third_party/blink/renderer/core/layout/layout_object.h"
#include "third_party/blink/renderer/core/layout/layout_view.h"
#include "third_party/blink/renderer/core/loader/empty_clients.h"
#include "third_party/blink/renderer/core/page/autoscroll_controller.h"
#include "third_party/blink/renderer/core/page/page.h"
#include "third_party/blink/renderer/core/page/page_animator.h"
#include "third_party/blink/renderer/core/paint/paint_layer_scrollable_area.h"
#include "third_party/blink/renderer/core/scroll/scroll_animator_base.h"
#include "third_party/blink/renderer/core/testing/core_unit_test_helper.h"
#include "third_party/blink/renderer/core/testing/page_test_base.h"
#include "third_party/blink/renderer/core/testing/sim/sim_request.h"
#include "third_party/blink/renderer/core/testing/sim/sim_test.h"
#include "third_party/blink/renderer/platform/keyboard_codes.h"
#include "third_party/blink/renderer/platform/testing/runtime_enabled_features_test_helpers.h"
#include "third_party/blink/renderer/platform/testing/unit_test_helpers.h"
#include "ui/base/cursor/cursor.h"
#include "ui/base/cursor/mojom/cursor_type.mojom-blink.h"
#include "ui/base/dragdrop/mojom/drag_drop_types.mojom-blink.h"
#include "ui/events/keycodes/dom/dom_code.h"
#include "ui/events/keycodes/dom/dom_key.h"

namespace blink {

class EventHandlerTest : public PageTestBase {};

class EventHandlerSimTest : public SimTest {};

WebPointerEvent CreateMinimalTouchPointerEvent(WebInputEvent::Type type,
                                               gfx::PointF position) {}

WebGestureEvent CreateMinimalGestureEvent(WebInputEvent::Type type,
                                          gfx::PointF position) {}

// TODO(mustaq): We no longer needs any of these Builder classes because the
// fields are publicly modifiable.

class TapEventBuilder : public WebGestureEvent {};

class TapDownEventBuilder : public WebGestureEvent {};

class ShowPressEventBuilder : public WebGestureEvent {};

class LongPressEventBuilder : public WebGestureEvent {};

class MousePressEventBuilder : public WebMouseEvent {};

void EventHandlerTest::SetUp() {}

void EventHandlerTest::SetHtmlInnerHTML(const char* html_content) {}

ShadowRoot* EventHandlerTest::SetShadowContent(const char* shadow_content,
                                               const char* host) {}

// Tests that WebFeature::kMouseDragOnCancelledMouseMove is use-counted after a
// cancelled "mousemove" iff "selectstart" was not cancelled.
TEST_F(EventHandlerTest, UseCountSelectionChangeOnCancelledMouseMove) {}

TEST_F(EventHandlerTest, UseCountDragDropOnCancelledMouseMove) {}

TEST_F(EventHandlerTest, dragSelectionAfterScroll) {}

TEST_F(EventHandlerTest, multiClickSelectionFromTap) {}

TEST_F(EventHandlerTest, multiClickSelectionFromTapDisabledIfNotEditable) {}

TEST_F(EventHandlerTest, draggedInlinePositionTest) {}

TEST_F(EventHandlerTest, draggedSVGImagePositionTest) {}

TEST_F(EventHandlerTest, HitOnNothingDoesNotShowIBeam) {}

TEST_F(EventHandlerTest, HitOnTextShowsIBeam) {}

TEST_F(EventHandlerTest, HitOnUserSelectNoneDoesNotShowIBeam) {}

TEST_F(EventHandlerTest, ShadowChildCanOverrideUserSelectNone) {}

TEST_F(EventHandlerTest, UserSelectAllCanOverrideUserSelectNone) {}

TEST_F(EventHandlerTest, UserSelectNoneCanOverrideUserSelectAll) {}

TEST_F(EventHandlerTest, UserSelectTextCanOverrideUserSelectNone) {}

TEST_F(EventHandlerTest, UserSelectNoneCanOverrideUserSelectText) {}

TEST_F(EventHandlerTest, ShadowChildCanOverrideUserSelectText) {}

TEST_F(EventHandlerTest, InputFieldsCanStartSelection) {}

TEST_F(EventHandlerTest, ReadOnlyInputDoesNotInheritUserSelect) {}

TEST_F(EventHandlerTest, ImagesCannotStartSelection) {}

TEST_F(EventHandlerTest, AnchorTextCannotStartSelection) {}

TEST_F(EventHandlerTest, EditableAnchorTextCanStartSelection) {}

TEST_F(EventHandlerTest, CursorForVerticalResizableTextArea) {}

TEST_F(EventHandlerTest, CursorForHorizontalResizableTextArea) {}

TEST_F(EventHandlerTest, CursorForResizableTextArea) {}

TEST_F(EventHandlerTest, CursorForRtlResizableTextArea) {}

TEST_F(EventHandlerTest, CursorForInlineVerticalWritingMode) {}

TEST_F(EventHandlerTest, CursorForBlockVerticalWritingMode) {}

TEST_F(EventHandlerTest, implicitSend) {}

// Regression test for http://crbug.com/641403 to verify we use up-to-date
// layout tree for dispatching "contextmenu" event.
TEST_F(EventHandlerTest, sendContextMenuEventWithHover) {}

TEST_F(EventHandlerTest, EmptyTextfieldInsertionOnTap) {}

TEST_F(EventHandlerTest, NonEmptyTextfieldInsertionOnTap) {}

TEST_F(EventHandlerTest, NewlineDivInsertionOnTap) {}

TEST_F(EventHandlerTest, EmptyTextfieldInsertionOnLongPress) {}

TEST_F(EventHandlerTest, NonEmptyTextfieldInsertionOnLongPress) {}

TEST_F(EventHandlerTest, SelectionOnDoublePress) {}

TEST_F(EventHandlerTest, SelectionOnDoublePressPreventDefaultMousePress) {}

TEST_F(EventHandlerTest, ClearHandleAfterTap) {}

TEST_F(EventHandlerTest, HandleNotShownOnMouseEvents) {}

// https://crbug.com/1410448
TEST_F(EventHandlerTest,
       TripleClickUserSelectNoneParagraphWithSelectableChildren) {}

TEST_F(EventHandlerTest, MisspellingContextMenuEvent) {}

// Tests that touch adjustment algorithm can handle editable elements without
// layout objects.
//
// TODO(mustaq): A fix for https://crbug.com/1230045 can make this test
// obsolete.
TEST_F(EventHandlerTest, TouchAdjustmentOnEditableDisplayContents) {}

// Tests that `EventHandler` can gracefully handle a multi-touch gesture event
// for which the first touch pointer event was NOT sent to Blink but a latter
// touch pointer event was sent. https://crbug.com/1409069
TEST_F(EventHandlerTest, GestureHandlingForHeldBackTouchPointer) {}

TEST_F(EventHandlerTest, dragEndInNewDrag) {}

// This test mouse move with modifier kRelativeMotionEvent
// should not start drag.
TEST_F(EventHandlerTest, FakeMouseMoveNotStartDrag) {}

class TooltipCapturingChromeClient : public EmptyChromeClient {};

class EventHandlerTooltipTest : public EventHandlerTest {};

TEST_F(EventHandlerTooltipTest, mouseLeaveClearsTooltip) {}

// macOS doesn't have keyboard-triggered tooltips.
#if BUILDFLAG(IS_MAC)
#define MAYBE_FocusSetFromTabUpdatesTooltip
#else
#define MAYBE_FocusSetFromTabUpdatesTooltip
#endif
// Moving the focus with the tab key should trigger a tooltip update.
TEST_F(EventHandlerTooltipTest, MAYBE_FocusSetFromTabUpdatesTooltip) {}

// macOS doesn't have keyboard-triggered tooltips.
#if BUILDFLAG(IS_MAC)
#define MAYBE_FocusSetFromAccessKeyUpdatesTooltip
#else
#define MAYBE_FocusSetFromAccessKeyUpdatesTooltip
#endif
// Moving the focus by pressing the access key on button should trigger a
// tooltip update.
TEST_F(EventHandlerTooltipTest, MAYBE_FocusSetFromAccessKeyUpdatesTooltip) {}

// macOS doesn't have keyboard-triggered tooltips.
#if BUILDFLAG(IS_MAC)
#define MAYBE_FocusSetFromMouseDoesntUpdateTooltip
#else
#define MAYBE_FocusSetFromMouseDoesntUpdateTooltip
#endif
// Moving the focus to an element with a mouse action shouldn't update the
// tooltip.
TEST_F(EventHandlerTooltipTest, MAYBE_FocusSetFromMouseDoesntUpdateTooltip) {}

// macOS doesn't have keyboard-triggered tooltips.
#if BUILDFLAG(IS_MAC)
#define MAYBE_FocusSetFromScriptDoesntUpdateTooltip
#else
#define MAYBE_FocusSetFromScriptDoesntUpdateTooltip
#endif
// Moving the focus to an element with a script action (FocusType::kNone means
// that the focus was set from a script) shouldn't update the tooltip.
TEST_F(EventHandlerTooltipTest, MAYBE_FocusSetFromScriptDoesntUpdateTooltip) {}

// macOS doesn't have keyboard-triggered tooltips.
#if BUILDFLAG(IS_MAC)
#define MAYBE_FocusSetScriptInitiatedFromKeypressUpdatesTooltip
#else
#define MAYBE_FocusSetScriptInitiatedFromKeypressUpdatesTooltip
#endif
// Moving the focus with a keypress that leads to a script being called
// should trigger a tooltip update.
TEST_F(EventHandlerTooltipTest,
       MAYBE_FocusSetScriptInitiatedFromKeypressUpdatesTooltip) {}

// macOS doesn't have keyboard-triggered tooltips.
#if BUILDFLAG(IS_MAC)
#define MAYBE_FocusSetFromScriptClearsKeyboardTriggeredTooltip
#else
#define MAYBE_FocusSetFromScriptClearsKeyboardTriggeredTooltip
#endif
// Moving the focus programmatically to an element that doesn't have a title
// attribute set while the user previously set the focus from keyboard on an
// element with a title text should hide the tooltip.
TEST_F(EventHandlerTooltipTest,
       MAYBE_FocusSetFromScriptClearsKeyboardTriggeredTooltip) {}

// Moving the focus programmatically while a cursor-triggered tooltip is visible
// shouldn't hide the visible tooltip.
TEST_F(EventHandlerTooltipTest,
       FocusSetFromScriptDoesntClearCursorTriggeredTooltip) {}

class UnbufferedInputEventsTrackingChromeClient : public EmptyChromeClient {};

class EventHandlerLatencyTest : public PageTestBase {};

TEST_F(EventHandlerLatencyTest, NeedsUnbufferedInput) {}

TEST_F(EventHandlerSimTest, MouseUpOffScrollbarGeneratesScrollEnd) {}

TEST_F(EventHandlerSimTest, MouseUpOnlyOnScrollbar) {}

TEST_F(EventHandlerSimTest, RightClickNoGestures) {}

// https://crbug.com/976557 tracks the fix for re-enabling this test on Mac.
#if BUILDFLAG(IS_MAC)
#define MAYBE_GestureTapWithScrollSnaps
#else
#define MAYBE_GestureTapWithScrollSnaps
#endif

TEST_F(EventHandlerSimTest, MAYBE_GestureTapWithScrollSnaps) {}

// Test that leaving a window leaves mouse position unknown.
TEST_F(EventHandlerTest, MouseLeaveResetsUnknownState) {}

// Test that leaving an iframe sets the mouse position to unknown on that
// iframe.
TEST_F(EventHandlerSimTest, MouseLeaveIFrameResets) {}

// Test that mouse down and move a small distance on a draggable element will
// not change cursor style.
TEST_F(EventHandlerSimTest, CursorStyleBeforeStartDragging) {}

// Ensure that tap on element in iframe should apply active state.
TEST_F(EventHandlerSimTest, TapActiveInFrame) {}

// Test that the hover is updated at the next begin frame after the compositor
// scroll ends.
TEST_F(EventHandlerSimTest, TestUpdateHoverAfterCompositorScrollAtBeginFrame) {}

// Test that the hover is updated at the next begin frame after the smooth JS
// scroll ends.
TEST_F(EventHandlerSimTest, TestUpdateHoverAfterJSScrollAtBeginFrame) {}

TEST_F(EventHandlerSimTest, LargeCustomCursorIntersectsViewport) {}

TEST_F(EventHandlerSimTest, SmallCustomCursorIntersectsViewport) {}

TEST_F(EventHandlerSimTest, NeverExposeKeyboardEvent) {}

TEST_F(EventHandlerSimTest, NotExposeKeyboardEvent) {}

TEST_F(EventHandlerSimTest, DoNotScrollWithTouchpadIfOverflowIsHidden) {}

TEST_F(EventHandlerSimTest, ElementTargetedGestureScroll) {}

TEST_F(EventHandlerSimTest, ElementTargetedGestureScrollIFrame) {}

TEST_F(EventHandlerSimTest, ElementTargetedGestureScrollViewport) {}

TEST_F(EventHandlerSimTest, SelecteTransformedTextWhenCapturing) {}

// Test that mouse right button down and move to an iframe will route the events
// to iframe correctly.
TEST_F(EventHandlerSimTest, MouseRightButtonDownMoveToIFrame) {}

// Tests that pen dragging on an element and moves will keep the element active.
TEST_F(EventHandlerSimTest, PenDraggingOnElementActive) {}

TEST_F(EventHandlerSimTest, TestNoCrashOnMouseWheelZeroDelta) {}

// The mouse wheel events which have the phases of "MayBegin" or "Cancel"
// should fire wheel events to the DOM.
TEST_F(EventHandlerSimTest, TestNoWheelEventWithPhaseMayBeginAndCancel) {}

// The mouse wheel events which have the phases of "End" should fire wheel
// events to the DOM, but for other phases like "Begin", "Change" and
// "Stationary", there should be wheels evnets fired to the DOM.
TEST_F(EventHandlerSimTest, TestWheelEventsWithDifferentPhases) {}

TEST_F(EventHandlerSimTest, TestScrollendFiresOnKeyUpAfterScroll) {}

TEST_F(EventHandlerSimTest, TestScrollendFiresAfterScrollWithEarlyKeyUp) {}

TEST_F(EventHandlerSimTest, TestScrollendFiresOnKeyUpAfterScrollInstant) {}

TEST_F(EventHandlerSimTest, DiscardEventsToRecentlyMovedIframe) {}

// Tests that click.pointerId is valid for a gesture tap for which no low-level
// pointer events (pointerdown, pointermove, pointerup etc) are sent from the
// browser to the renderer because of absence of relevant event listeners.
TEST_F(EventHandlerSimTest, ValidClickPointerIdForUnseenPointerEvent) {}

}  // namespace blink