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

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

#include <memory>
#include <tuple>

#include "base/functional/bind.h"
#include "base/run_loop.h"
#include "base/test/scoped_feature_list.h"
#include "build/build_config.h"
#include "cc/base/switches.h"
#include "cc/input/scroll_utils.h"
#include "content/browser/renderer_host/render_widget_host_impl.h"
#include "content/browser/web_contents/web_contents_impl.h"
#include "content/common/input/synthetic_gesture.h"
#include "content/common/input/synthetic_gesture_controller.h"
#include "content/common/input/synthetic_gesture_params.h"
#include "content/common/input/synthetic_gesture_target.h"
#include "content/common/input/synthetic_smooth_scroll_gesture.h"
#include "content/common/input/synthetic_smooth_scroll_gesture_params.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/common/content_switches.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/content_browser_test.h"
#include "content/public/test/content_browser_test_utils.h"
#include "content/public/test/hit_test_region_observer.h"
#include "content/shell/browser/shell.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/common/switches.h"
#include "ui/base/ui_base_features.h"
#include "ui/native_theme/native_theme_features.h"

namespace {

constexpr int kIntermediateScrollOffset =;

const std::string kOverflowScrollDataURL =;

const std::string kMainFrameScrollDataURL =;

const std::string kSubframeScrollDataURL =;

const std::string kMirroredScrollersDataURL =;

}  // namespace

namespace content {

// This test is to verify that in-progress smooth scrolls stops when
// interrupted by an instant scroll, another smooth scroll, a touch scroll, or
// a mouse wheel scroll on an overflow:scroll element, main frame and subframe.
class ScrollBehaviorBrowserTest : public ContentBrowserTest {};

class ScrollBehaviorBrowserTestWithPercentBasedScrolling
    : public ScrollBehaviorBrowserTest {};

// This tests that a in-progress smooth scroll on an overflow:scroll element
// stops when interrupted by an instant scroll.
//
// TODO(crbug.com/40722572): the last animation is committed after we set the
// scrollTop even when we cancel the animation, so the final scrollTop value
// is not 0, we need to fix it.
IN_PROC_BROWSER_TEST_F(ScrollBehaviorBrowserTest,
                       DISABLED_InstantScriptScrollAbortsSmoothScriptScroll) {}

// Disabled for flakiness on Mac (crbug.com/1462985).
#if BUILDFLAG(IS_MAC)
#define MAYBE_InstantScriptScrollAdjustsSmoothWheelScroll
#else
#define MAYBE_InstantScriptScrollAdjustsSmoothWheelScroll
#endif
IN_PROC_BROWSER_TEST_F(ScrollBehaviorBrowserTestWithPercentBasedScrolling,
                       MAYBE_InstantScriptScrollAdjustsSmoothWheelScroll) {}

IN_PROC_BROWSER_TEST_F(ScrollBehaviorBrowserTest,
                       InstantScriptScrollAdjustsSmoothWheelScroll) {}

// This tests that a in-progress smooth wheel scroll on a scrollable element is
// adjusted (without cancellation) when interrupted by an instant script scroll.
void ScrollBehaviorBrowserTest::
    RunTestInstantScriptScrollAdjustsSmoothWheelScroll() {}

#if BUILDFLAG(IS_MAC)
#define MAYBE_SmoothWheelScrollCompletesWithScriptedMirror
#else
#define MAYBE_SmoothWheelScrollCompletesWithScriptedMirror
#endif
IN_PROC_BROWSER_TEST_F(ScrollBehaviorBrowserTestWithPercentBasedScrolling,
                       MAYBE_SmoothWheelScrollCompletesWithScriptedMirror) {}

IN_PROC_BROWSER_TEST_F(ScrollBehaviorBrowserTest,
                       SmoothWheelScrollCompletesWithScriptedMirror) {}

// This tests that a smooth wheel scroll is not interrupted when script syncs
// a separate scroller in the onscroll handler. (This was the root cause of
// crbug.com/1248388 affecting CodeMirror as described in crbug.com/1264266.)
void ScrollBehaviorBrowserTest::
    RunTestSmoothWheelScrollCompletesWithScriptedMirror() {}

// This tests that a in-progress smooth scroll on an overflow:scroll element
// stops when interrupted by another smooth scroll.
IN_PROC_BROWSER_TEST_F(ScrollBehaviorBrowserTest,
                       OneSmoothScriptScrollAbortsAnother_Element) {}

// This tests that a in-progress smooth scroll on an overflow:scroll element
// stops when interrupted by a touch scroll.
//
// TODO(crbug.com/40712058): compositing scroll should be able to cancel a
// running programmatic scroll.
IN_PROC_BROWSER_TEST_F(ScrollBehaviorBrowserTest,
                       DISABLED_TouchScrollAbortsSmoothScriptScroll) {}

// This tests that a in-progress smooth scroll on an overflow:scroll element
// stops when interrupted by a mouse wheel scroll.
//
// TODO(crbug.com/40712058): compositing scroll should be able to cancel a
// running programmatic scroll.
IN_PROC_BROWSER_TEST_F(ScrollBehaviorBrowserTest,
                       DISABLED_WheelScrollAbortsSmoothScriptScroll) {}

// This tests that a in-progress smooth scroll on the main frame stops when
// interrupted by another smooth scroll.
// Flaky on multiple platforms: crbug.com/1306980
IN_PROC_BROWSER_TEST_F(ScrollBehaviorBrowserTest,
                       DISABLED_OneSmoothScriptScrollAbortsAnother_Document) {}

// This tests that a in-progress smooth scroll on a subframe stops when
// interrupted by another smooth scroll.
// Flaky on multiple platforms: crbug.com/1306980
IN_PROC_BROWSER_TEST_F(ScrollBehaviorBrowserTest,
                       DISABLED_OneSmoothScriptScrollAbortsAnother_Subframe) {}

}  // namespace content