Commit dd2d3eff authored by Sahel Sharify's avatar Sahel Sharify Committed by Commit Bot

Wheel scrolling works after autoscroll cancellation.

This cl sends a GFS with zero velocity in |OnAutoscrollStart| to make sure
that the GFC sent in |onAutoscrollEnd| doesn't get filtered. Processing the
GFC will generate a GSE with ends the current scroll sequence.

Bug: 829794
Test: WheelScrollingWorksAfterAutoscrollCancel
Change-Id: I929e473018f3de9ecf8fafb1f7b2e8e6a9adfd2f
Reviewed-on: https://chromium-review.googlesource.com/1026454
Commit-Queue: Sahel Sharifymoghaddam <sahel@chromium.org>
Reviewed-by: default avatarDavid Bokan <bokan@chromium.org>
Reviewed-by: default avatarDave Tapuska <dtapuska@chromium.org>
Reviewed-by: default avatarTimothy Dresser <tdresser@chromium.org>
Reviewed-by: default avatarSahel Sharifymoghaddam <sahel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#555217}
parent e131417d
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "build/build_config.h"
#include "content/browser/web_contents/web_contents_impl.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/shell/browser/shell.h"
#include "third_party/blink/public/platform/web_input_event.h"
#include "ui/events/base_event_utils.h"
using blink::WebInputEvent;
namespace {
const std::string kBrowserFlingDataURL = R"HTML(
<!DOCTYPE html>
<meta name='viewport' content='width=device-width'/>
<style>
html, body {
margin: 0;
}
.spacer { height: 10000px; }
</style>
<div class=spacer></div>
<script>
document.title='ready';
</script>)HTML";
} // namespace
namespace content {
class BrowserSideFlingBrowserTest : public ContentBrowserTest {
public:
BrowserSideFlingBrowserTest() {}
~BrowserSideFlingBrowserTest() override {}
void SetUpCommandLine(base::CommandLine* command_line) override {
command_line->AppendSwitchASCII("--enable-blink-features",
"MiddleClickAutoscroll");
}
protected:
RenderWidgetHostImpl* GetWidgetHost() {
return RenderWidgetHostImpl::From(
shell()->web_contents()->GetRenderViewHost()->GetWidget());
}
void LoadURL(const std::string& page_data) {
const GURL data_url("data:text/html," + page_data);
NavigateToURL(shell(), data_url);
RenderWidgetHostImpl* host = GetWidgetHost();
host->GetView()->SetSize(gfx::Size(400, 400));
base::string16 ready_title(base::ASCIIToUTF16("ready"));
TitleWatcher watcher(shell()->web_contents(), ready_title);
ignore_result(watcher.WaitAndGetTitle());
MainThreadFrameObserver main_thread_sync(host);
main_thread_sync.Wait();
}
void SimulateMiddleClick(int x, int y, int modifiers) {
// Simulate and send middle click mouse down.
blink::WebMouseEvent down_event = SyntheticWebMouseEventBuilder::Build(
blink::WebInputEvent::kMouseDown, x, y, modifiers);
down_event.button = blink::WebMouseEvent::Button::kMiddle;
down_event.SetTimeStamp(ui::EventTimeForNow());
down_event.SetPositionInScreen(x, y);
GetWidgetHost()->ForwardMouseEvent(down_event);
// Simulate and send middle click mouse up.
blink::WebMouseEvent up_event = SyntheticWebMouseEventBuilder::Build(
blink::WebInputEvent::kMouseUp, x, y, modifiers);
up_event.button = blink::WebMouseEvent::Button::kMiddle;
up_event.SetTimeStamp(ui::EventTimeForNow());
up_event.SetPositionInScreen(x, y);
GetWidgetHost()->ForwardMouseEvent(up_event);
}
private:
DISALLOW_COPY_AND_ASSIGN(BrowserSideFlingBrowserTest);
};
#if !defined(OS_ANDROID)
#define MAYBE_AutoscrollFling AutoscrollFling
#else
#define MAYBE_AutoscrollFling DISABLED_AutoscrollFling
#endif
IN_PROC_BROWSER_TEST_F(BrowserSideFlingBrowserTest, MAYBE_AutoscrollFling) {
LoadURL(kBrowserFlingDataURL);
// Start autoscroll with middle click.
auto input_msg_watcher = std::make_unique<InputMsgWatcher>(
GetWidgetHost(), blink::WebInputEvent::kGestureScrollBegin);
SimulateMiddleClick(10, 10, blink::WebInputEvent::kNoModifiers);
input_msg_watcher->WaitForAck();
// The page should start scrolling with mouse move.
RenderFrameSubmissionObserver observer(
GetWidgetHost()->render_frame_metadata_provider());
blink::WebMouseEvent move_event = SyntheticWebMouseEventBuilder::Build(
blink::WebInputEvent::kMouseMove, 30, 30,
blink::WebInputEvent::kNoModifiers);
move_event.SetTimeStamp(ui::EventTimeForNow());
move_event.SetPositionInScreen(30, 30);
GetWidgetHost()->ForwardMouseEvent(move_event);
gfx::Vector2dF default_scroll_offset;
while (observer.LastRenderFrameMetadata()
.root_scroll_offset.value_or(default_scroll_offset)
.y() <= 0) {
observer.WaitForMetadataChange();
}
}
#if !defined(OS_ANDROID)
#define MAYBE_WheelScrollingWorksAfterAutoscrollCancel \
WheelScrollingWorksAfterAutoscrollCancel
#else
#define MAYBE_WheelScrollingWorksAfterAutoscrollCancel \
DISABLED_WheelScrollingWorksAfterAutoscrollCancel
#endif
// Checks that wheel scrolling works after autoscroll cancelation.
IN_PROC_BROWSER_TEST_F(BrowserSideFlingBrowserTest,
MAYBE_WheelScrollingWorksAfterAutoscrollCancel) {
LoadURL(kBrowserFlingDataURL);
// Start autoscroll with middle click.
auto input_msg_watcher = std::make_unique<InputMsgWatcher>(
GetWidgetHost(), blink::WebInputEvent::kGestureScrollBegin);
SimulateMiddleClick(10, 10, blink::WebInputEvent::kNoModifiers);
input_msg_watcher->WaitForAck();
// Without moving the mouse cancel the autoscroll fling with another click.
input_msg_watcher = std::make_unique<InputMsgWatcher>(
GetWidgetHost(), blink::WebInputEvent::kGestureScrollEnd);
SimulateMiddleClick(10, 10, blink::WebInputEvent::kNoModifiers);
input_msg_watcher->WaitForAck();
// The mouse wheel scrolling must work after autoscroll cancellation.
RenderFrameSubmissionObserver observer(
GetWidgetHost()->render_frame_metadata_provider());
blink::WebMouseWheelEvent wheel_event =
SyntheticWebMouseWheelEventBuilder::Build(10, 10, 0, -53, 0, true);
wheel_event.phase = blink::WebMouseWheelEvent::kPhaseBegan;
GetWidgetHost()->ForwardWheelEvent(wheel_event);
gfx::Vector2dF default_scroll_offset;
while (observer.LastRenderFrameMetadata()
.root_scroll_offset.value_or(default_scroll_offset)
.y() <= 0) {
observer.WaitForMetadataChange();
}
}
} // namespace content
\ No newline at end of file
......@@ -2236,6 +2236,12 @@ void RenderWidgetHostImpl::OnAutoscrollStart(const gfx::PointF& position) {
ForwardGestureEventWithLatencyInfo(
scroll_begin, ui::LatencyInfo(ui::SourceEventType::OTHER));
// Send a GFS event with zero velocity to make sure that the scroll sequence
// will end with the GFC generated in |OnAutoscrollEnd()|; Otherwise if the
// user cancels the autoscroll without moving the mouse, the GFC will get
// filtered since no GFS is sent in the sequence. https://crbug.com/829794
OnAutoscrollFling(gfx::Vector2dF());
}
void RenderWidgetHostImpl::OnAutoscrollFling(const gfx::Vector2dF& velocity) {
......
......@@ -792,6 +792,7 @@ test("content_browsertests") {
"../browser/presentation/presentation_browsertest.cc",
"../browser/renderer_host/input/composited_scrolling_browsertest.cc",
"../browser/renderer_host/input/compositor_event_ack_browsertest.cc",
"../browser/renderer_host/input/fling_browsertest.cc",
"../browser/renderer_host/input/interaction_mq_dynamic_browsertest.cc",
"../browser/renderer_host/input/main_thread_event_queue_browsertest.cc",
"../browser/renderer_host/input/mouse_latency_browsertest.cc",
......
......@@ -90,6 +90,7 @@
# Browser side fling cannot use SetNeedsBeginFrame on viz https://crbug.com/823310
-CompositorEventAckBrowserTest.TouchStartDuringFling
-BrowserSideFlingBrowserTest.*
# Uses LatencyInfo for input info https://crbug.com/791557
-MouseLatencyBrowserTest.CoalescedMouseMovesCorrectlyTerminated
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment