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

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

#include <tuple>

#include "base/functional/bind.h"
#include "base/memory/raw_ptr.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/scoped_feature_list.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "components/input/render_widget_host_input_event_router.h"
#include "content/browser/web_contents/web_contents_impl.h"
#include "content/common/input/synthetic_smooth_scroll_gesture.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 "content/test/content_browser_test_utils_internal.h"
#include "net/dns/mock_host_resolver.h"
#include "third_party/blink/public/common/input/synthetic_web_input_event_builders.h"
#include "third_party/blink/public/common/input/web_input_event.h"
#include "ui/base/ui_base_features.h"
#include "ui/events/base_event_utils.h"

namespace {

const std::string kBrowserFlingDataURL =;

const std::string kTouchActionFilterDataURL =;
}  // namespace

namespace content {

class BrowserSideFlingBrowserTest : public ContentBrowserTest {};

// On Mac we don't have any touchscreen/touchpad fling events (GFS/GFC).
// Instead, the OS keeps sending wheel events when the user lifts their fingers
// from touchpad.
#if !BUILDFLAG(IS_MAC)
IN_PROC_BROWSER_TEST_F(BrowserSideFlingBrowserTest, TouchscreenFling) {}
IN_PROC_BROWSER_TEST_F(BrowserSideFlingBrowserTest, TouchpadFling) {}
IN_PROC_BROWSER_TEST_F(
    BrowserSideFlingBrowserTest,
    EarlyTouchscreenFlingCancelationOnInertialGSUAckNotConsumed) {}
IN_PROC_BROWSER_TEST_F(
    BrowserSideFlingBrowserTest,
    EarlyTouchpadFlingCancelationOnInertialGSUAckNotConsumed) {}

// TODO(crbug.com/1347271,crbug.com/269960): TODO: Re-enable this test.

// Tests that flinging does not continue after navigating to a page that uses
// the same renderer.
IN_PROC_BROWSER_TEST_F(BrowserSideFlingBrowserTest,
                       DISABLED_FlingingStopsAfterNavigation) {}

// TODO(crbug.com/40857753): Re-enable on Linux MSAN once not flaky.
#if BUILDFLAG(IS_LINUX) && defined(MEMORY_SANITIZER)
#define MAYBE_TouchscreenFlingInOOPIF
#else
#define MAYBE_TouchscreenFlingInOOPIF
#endif
IN_PROC_BROWSER_TEST_F(BrowserSideFlingBrowserTest,
                       MAYBE_TouchscreenFlingInOOPIF) {}
// TODO(crbug.com/40230295): flaky.
IN_PROC_BROWSER_TEST_F(BrowserSideFlingBrowserTest,
                       DISABLED_TouchpadFlingInOOPIF) {}
// TODO(crbug.com/40230295): flaky.
IN_PROC_BROWSER_TEST_F(BrowserSideFlingBrowserTest,
                       DISABLED_TouchscreenInertialGSUsBubbleFromOOPIF) {}

// Touchpad fling only happens on ChromeOS.
#if BUILDFLAG(IS_CHROMEOS_ASH)
IN_PROC_BROWSER_TEST_F(BrowserSideFlingBrowserTest,
                       TouchpadInertialGSUsBubbleFromOOPIF) {
  LoadPageWithOOPIF();
  // Scroll the parent down so that it is scrollable upward.
  EXPECT_TRUE(
      ExecJs(GetRootNode()->current_frame_host(), "window.scrollTo(0, 20)"));
  // We expect to have window.scrollY == 20 after scrolling but with zoom for
  // dsf enabled on android we get window.scrollY == 19 (see
  // https://crbug.com/891860).
  WaitForFrameScroll(GetRootNode(), 19);
  SynchronizeThreads();

  // Fling and wait for the parent to scroll upward.
  gfx::Vector2d fling_velocity(0, 2000);
  SimulateTouchpadFling(child_view_->host(), GetWidgetHost(), fling_velocity);
  WaitForFrameScroll(GetRootNode(), 15, true /* upward */);
}
#endif  // BUILDFLAG(IS_CHROMEOS_ASH)

// TODO(crbug.com/40230295): flaky.
IN_PROC_BROWSER_TEST_F(BrowserSideFlingBrowserTest,
                       DISABLED_InertialGSEGetsBubbledFromOOPIF) {}

// Checks that the fling controller of the oopif stops the fling when the
// bubbled inertial GSUs are not consumed by the parent's renderer.
// Flaky test https://crbug.com/1344075
IN_PROC_BROWSER_TEST_F(
    BrowserSideFlingBrowserTest,
    DISABLED_InertialGSUBubblingStopsWhenParentCannotScroll) {}

// Check that fling controller does not generate fling curve when view is
// destroyed.
IN_PROC_BROWSER_TEST_F(BrowserSideFlingBrowserTest,
                       NoFlingWhenViewIsDestroyed) {}
#endif  // !BUILDFLAG(IS_MAC)

class PhysicsBasedFlingCurveBrowserTest : public BrowserSideFlingBrowserTest {};

IN_PROC_BROWSER_TEST_F(PhysicsBasedFlingCurveBrowserTest,
                       TargetScrollOffsetForFlingAnimation) {}

}  // namespace content