chromium/third_party/blink/renderer/core/layout/scrollbars_test.cc

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

#include "base/test/scoped_feature_list.h"
#include "build/build_config.h"
#include "cc/base/features.h"
#include "cc/paint/record_paint_canvas.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/common/input/web_coalesced_input_event.h"
#include "third_party/blink/public/common/input/web_pointer_properties.h"
#include "third_party/blink/public/platform/scheduler/test/renderer_scheduler_test_support.h"
#include "third_party/blink/public/platform/web_theme_engine.h"
#include "third_party/blink/public/web/web_script_source.h"
#include "third_party/blink/renderer/core/frame/frame_test_helpers.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_local_frame_impl.h"
#include "third_party/blink/renderer/core/html/html_iframe_element.h"
#include "third_party/blink/renderer/core/input/event_handler.h"
#include "third_party/blink/renderer/core/inspector/dev_tools_emulator.h"
#include "third_party/blink/renderer/core/layout/custom_scrollbar.h"
#include "third_party/blink/renderer/core/layout/layout_custom_scrollbar_part.h"
#include "third_party/blink/renderer/core/layout/layout_view.h"
#include "third_party/blink/renderer/core/page/page.h"
#include "third_party/blink/renderer/core/paint/paint_layer.h"
#include "third_party/blink/renderer/core/paint/paint_layer_scrollable_area.h"
#include "third_party/blink/renderer/core/scroll/scroll_types.h"
#include "third_party/blink/renderer/core/scroll/scrollbar_theme_overlay_mock.h"
#include "third_party/blink/renderer/core/testing/color_scheme_helper.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/testing/paint_test_configurations.h"
#include "third_party/blink/renderer/platform/testing/task_environment.h"
#include "third_party/blink/renderer/platform/testing/testing_platform_support.h"
#include "third_party/blink/renderer/platform/testing/unit_test_helpers.h"
#include "third_party/blink/renderer/platform/testing/url_test_helpers.h"
#include "third_party/blink/renderer/platform/theme/web_theme_engine_helper.h"
#include "ui/base/cursor/cursor.h"
#include "ui/base/cursor/mojom/cursor_type.mojom-blink.h"

namespace blink {

namespace {

class StubWebThemeEngine : public WebThemeEngine {};

constexpr int StubWebThemeEngine::kMinimumHorizontalLength;
constexpr int StubWebThemeEngine::kMinimumVerticalLength;

class ScopedStubThemeEngine {};

}  // namespace

class ScrollbarsTest : public PaintTestConfigurations, public SimTest {};

INSTANTIATE_PAINT_TEST_SUITE_P();

class ScrollbarsTestWithVirtualTimer : public ScrollbarsTest {};

INSTANTIATE_PAINT_TEST_SUITE_P();

// Try to force enable/disable overlay. Skip the test if the desired setting
// is not supported by the platform.
#define ENABLE_OVERLAY_SCROLLBARS(b)

TEST_P(ScrollbarsTest, DocumentStyleRecalcPreservesScrollbars) {}

TEST_P(ScrollbarsTest, ScrollbarsUpdatedOnOverlaySettingsChange) {}

TEST(ScrollbarsTestWithOwnWebViewHelper, ScrollbarSizeF) {}

// Ensure that causing a change in scrollbar existence causes a nested layout
// to recalculate the existence of the opposite scrollbar. The bug here was
// caused by trying to avoid the layout when overlays are enabled but not
// checking whether the scrollbars should be custom - which do take up layout
// space. https://crbug.com/668387.
TEST_P(ScrollbarsTest, CustomScrollbarsCauseLayoutOnExistenceChange) {}

TEST_P(ScrollbarsTest, TransparentBackgroundUsesLightOverlayColorScheme) {}

TEST_P(ScrollbarsTest, BodyBackgroundChangesOverlayColorTheme) {}

// Ensure overlay scrollbar change to display:none correctly.
TEST_P(ScrollbarsTest, OverlayScrollbarChangeToDisplayNoneDynamically) {}

// Ensure that overlay scrollbars are not created, even in overflow:scroll,
// situations when there's no overflow. Specifically, after style-only changes.
TEST_P(ScrollbarsTest, OverlayScrolblarNotCreatedInUnscrollableAxis) {}

TEST_P(ScrollbarsTest, HidingScrollbarsOnScrollableAreaDisablesScrollbars) {}

// Ensure mouse cursor should be pointer when hovering over the scrollbar.
TEST_P(ScrollbarsTest, MouseOverScrollbarInCustomCursorElement) {}

// Ensure mouse cursor should be override when hovering over the custom
// scrollbar.
TEST_P(ScrollbarsTest, MouseOverCustomScrollbarInCustomCursorElement) {}

// Ensure mouse cursor should be custom style when hovering over the custom
// scrollbar with custom cursor style.
TEST_P(ScrollbarsTest, MouseOverCustomScrollbarWithCustomCursor) {}

// Ensure mouse cursor should be custom style when hovering over the custom
// scrollbar-thumb with custom cursor style.
TEST_P(ScrollbarsTest, MouseOverCustomScrollbarThumbWithCustomCursor) {}

// Ensure mouse cursor should be custom style when hovering over the custom
// scrollbar-track-piece with custom cursor style.
TEST_P(ScrollbarsTest, MouseOverCustomScrollbarTrackPieceWithCustomCursor) {}

// Ensure mouse cursor should inherit the style set by the custom
// scrollbar-track when hovering over the custom scrollbar-track-piece
// that has no style set.
TEST_P(ScrollbarsTest, MouseOverCustomScrollbarTrackPieceWithoutStyle) {}

// Ensure mouse cursor should inherit the style set by the custom scrollbar
// when hovering over the custom scrollbar-track-piece that both
// scrollbar-track and scrollbar-track-piece has no style set.
TEST_P(ScrollbarsTest,
       MouseOverCustomScrollbarTrackPieceBothTrackAndTrackPieceWithoutStyle) {}

// Ensure mouse cursor should be custom style when hovering over the custom
// scrollbar-button with custom cursor style;
TEST_P(ScrollbarsTest, MouseOverCustomScrollbarButtonTrackWithCustomCursor) {}

// Ensure mouse cursor should be custom style when hovering over the custom
// scrollbar-corner with custom cursor style;
TEST_P(ScrollbarsTest, MouseOverCustomScrollbarCornerTrackWithCustomCursor) {}

TEST_P(ScrollbarsTest, MouseOverCustomScrollbarCornerFrame) {}

// Makes sure that mouse hover over an overlay scrollbar doesn't activate
// elements below (except the Element that owns the scrollbar) unless the
// scrollbar is faded out.
TEST_P(ScrollbarsTest, MouseOverLinkAndOverlayScrollbar) {}

// Makes sure that mouse hover over an custom scrollbar doesn't change the
// activate elements.
TEST_P(ScrollbarsTest, MouseOverCustomScrollbar) {}

// Makes sure that mouse hover over an overlay scrollbar doesn't hover iframe
// below.
TEST_P(ScrollbarsTest, MouseOverScrollbarAndIFrame) {}

// Makes sure that mouse hover over a scrollbar also hover the element owns the
// scrollbar.
TEST_P(ScrollbarsTest, MouseOverScrollbarAndParentElement) {}

// Makes sure that mouse over a root scrollbar also hover the html element.
TEST_P(ScrollbarsTest, MouseOverRootScrollbar) {}

TEST_P(ScrollbarsTest, MouseReleaseUpdatesScrollbarHoveredPart) {}

TEST_P(ScrollbarsTest, ContextMenuUpdatesScrollbarPressedPart) {}

TEST_P(ScrollbarsTest,
       CustomScrollbarInOverlayScrollbarThemeWillNotCauseDCHECKFails) {}

// Make sure root custom scrollbar can change by Emulator but div custom
// scrollbar not.
TEST_P(ScrollbarsTest, CustomScrollbarChangeToMobileByEmulator) {}

// Ensure custom scrollbar recreate when style owner change,
TEST_P(ScrollbarsTest, CustomScrollbarWhenStyleOwnerChange) {}

// Make sure overlay scrollbars on non-composited scrollers fade out and set
// the hidden bit as needed.
// To avoid TSAN/ASAN race issue, this test use Virtual Time and give scrollbar
// a huge fadeout delay.
// Disable on Android since VirtualTime not work for Android.
// http://crbug.com/633321
#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_IOS)
TEST_P(ScrollbarsTestWithVirtualTimer,
       DISABLED_TestNonCompositedOverlayScrollbarsFade) {
#else
TEST_P(ScrollbarsTestWithVirtualTimer, TestNonCompositedOverlayScrollbarsFade) {}

enum {};

class ScrollbarAppearanceTest : public ScrollbarsTest {};

// Test both overlay and non-overlay scrollbars.
INSTANTIATE_TEST_SUITE_P();

// Make sure native scrollbar can change by Emulator.
// Disable on Android since Android always enable OverlayScrollbar.
#if BUILDFLAG(IS_ANDROID)
TEST_P(ScrollbarAppearanceTest,
       DISABLED_NativeScrollbarChangeToMobileByEmulator) {
#else
TEST_P(ScrollbarAppearanceTest, NativeScrollbarChangeToMobileByEmulator) {}

#if !BUILDFLAG(IS_MAC)
// Ensure that the minimum length for a scrollbar thumb comes from the
// WebThemeEngine. Note, Mac scrollbars differ from all other platforms so this
// test doesn't apply there. https://crbug.com/682209.
TEST_P(ScrollbarAppearanceTest, ThemeEngineDefinesMinimumThumbLength) {}

// Ensure thumb position is correctly calculated even at ridiculously large
// scales.
TEST_P(ScrollbarAppearanceTest, HugeScrollingThumbPosition) {}
#endif

// A body with width just under the window width should not have scrollbars.
TEST_P(ScrollbarsTest, WideBodyShouldNotHaveScrollbars) {}

// A body with height just under the window height should not have scrollbars.
TEST_P(ScrollbarsTest, TallBodyShouldNotHaveScrollbars) {}

// A body with dimensions just barely inside the window dimensions should not
// have scrollbars.
TEST_P(ScrollbarsTest, TallAndWideBodyShouldNotHaveScrollbars) {}

// A body with dimensions equal to the window dimensions should not have
// scrollbars.
TEST_P(ScrollbarsTest, BodySizeEqualWindowSizeShouldNotHaveScrollbars) {}

// A body with percentage width extending beyond the window width should cause a
// horizontal scrollbar.
TEST_P(ScrollbarsTest, WidePercentageBodyShouldHaveScrollbar) {}

// Similar to |WidePercentageBodyShouldHaveScrollbar| but with a body height
// equal to the window height.
TEST_P(ScrollbarsTest, WidePercentageAndTallBodyShouldHaveScrollbar) {}

// A body with percentage height extending beyond the window height should cause
// a vertical scrollbar.
TEST_P(ScrollbarsTest, TallPercentageBodyShouldHaveScrollbar) {}

// Similar to |TallPercentageBodyShouldHaveScrollbar| but with a body width
// equal to the window width.
TEST_P(ScrollbarsTest, TallPercentageAndWideBodyShouldHaveScrollbar) {}

// A body with percentage dimensions extending beyond the window dimensions
// should cause scrollbars.
TEST_P(ScrollbarsTest, TallAndWidePercentageBodyShouldHaveScrollbars) {}

TEST_P(ScrollbarsTest, MouseOverIFrameScrollbar) {}

TEST_P(ScrollbarsTest, AutosizeTest) {}

TEST_P(ScrollbarsTest, AutosizeAlmostRemovableScrollbar) {}

TEST_P(ScrollbarsTest, AutosizeExpandingContentScrollable) {}

TEST_P(ScrollbarsTest,
       HideTheOverlayScrollbarNotCrashAfterPLSADisposedPaintLayer) {}

TEST_P(ScrollbarsTest, PLSADisposeShouldClearPointerInLayers) {}

TEST_P(ScrollbarsTest, OverlayScrollbarHitTest) {}

TEST_P(ScrollbarsTest, RecorderedOverlayScrollbarHitTest) {}

TEST_P(ScrollbarsTest,
       AllowMiddleButtonPressOnScrollbarWhenDisableMiddleClickAutoScroll) {}

TEST_P(ScrollbarsTest,
       NotAllowMiddleButtonPressOnScrollbarWhenEnableMiddleClickAutoScroll) {}

TEST_P(ScrollbarsTest, NotAllowNonLeftButtonPressOnScrollbar) {}

// Ensure Scrollbar not release press by middle button down.
TEST_P(ScrollbarsTest, MiddleDownShouldNotAffectScrollbarPress) {}

TEST_P(ScrollbarsTest, UseCounterNegativeWhenThumbIsNotScrolledWithMouse) {}

TEST_P(ScrollbarsTest, UseCounterPositiveWhenThumbIsScrolledWithMouse) {}

TEST_P(ScrollbarsTest, UseCounterNegativeWhenThumbIsNotScrolledWithTouch) {}

TEST_P(ScrollbarsTest, UseCounterPositiveWhenThumbIsScrolledWithTouch) {}

TEST_P(ScrollbarsTest, UseCounterCustomScrollbarPercentSize) {}

TEST_P(ScrollbarsTest, CheckScrollCornerIfThereIsNoScrollbar) {}

TEST_P(ScrollbarsTest, NoNeedsBeginFrameForCustomScrollbarAfterBeginFrame) {}

TEST_P(ScrollbarsTest, CustomScrollbarHypotheticalThickness) {}

// For infinite scrolling page (load more content when scroll to bottom), user
// press on scrollbar button should keep scrolling after content loaded.
// Disable on Android since VirtualTime not work for Android.
// http://crbug.com/633321
#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_IOS)
TEST_P(ScrollbarsTestWithVirtualTimer,
       DISABLED_PressScrollbarButtonOnInfiniteScrolling) {
#else
TEST_P(ScrollbarsTestWithVirtualTimer,
       PressScrollbarButtonOnInfiniteScrolling) {}

class ScrollbarTrackMarginsTest : public ScrollbarsTest {};

INSTANTIATE_PAINT_TEST_SUITE_P();

TEST_P(ScrollbarTrackMarginsTest,
       CustomScrollbarFractionalMarginsWillNotCauseDCHECKFailure) {}

TEST_P(ScrollbarTrackMarginsTest,
       CustomScrollbarScaledMarginsWillNotCauseDCHECKFailure) {}

class ScrollbarColorSchemeTest : public ScrollbarAppearanceTest {};

INSTANTIATE_TEST_SUITE_P();

TEST_P(ScrollbarColorSchemeTest, ThemeEnginePaint) {}

// Test scrollbar-gutter values with classic scrollbars and horizontal-tb text.
TEST_P(ScrollbarsTest, ScrollbarGutterWithHorizontalTextAndClassicScrollbars) {}

// Test scrollbar-gutter values with classic scrollbars and vertical-rl text.
TEST_P(ScrollbarsTest, ScrollbarGutterWithVerticalTextAndClassicScrollbars) {}

// Test scrollbar-gutter values with overlay scrollbars and horizontal-tb text.
TEST_P(ScrollbarsTest, ScrollbarGutterWithHorizontalTextAndOverlayScrollbars) {}

// Test scrollbar-gutter values with overlay scrollbars and vertical-rl text.
TEST_P(ScrollbarsTest, ScrollbarGutterWithVerticalTextAndOverlayScrollbars) {}

// Test events on the additional gutter created by the "both-edges" keyword of
// scrollbar-gutter.
TEST_P(ScrollbarsTest, ScrollbarGutterBothEdgesKeywordWithClassicScrollbars) {}

TEST_P(ScrollbarsTest, ScrollbarsRestoredAfterCapturePaintPreview) {}

// Tests that when overlay scrollbars are on, Scrollbar::UsedColorScheme follows
// the overlay theme, and when overlay scrollbars are disabled, the function
// returns the scrollable area's color scheme.
TEST_P(ScrollbarsTest, ScrollbarsUsedColorSchemeFollowsOverlayTheme) {}

}  // namespace blink