// Copyright 2017 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 "testing/gtest/include/gtest/gtest.h" #include "third_party/blink/renderer/core/dom/element.h" #include "third_party/blink/renderer/core/input/event_handler.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/testing/sim/sim_request.h" #include "third_party/blink/renderer/core/testing/sim/sim_test.h" namespace blink { class AutoscrollControllerTest : public SimTest { public: AutoscrollController& GetAutoscrollController() { return WebView().GetPage()->GetAutoscrollController(); } }; // Ensure Autoscroll not crash by layout called in UpdateSelectionForMouseDrag. TEST_F(AutoscrollControllerTest, CrashWhenLayoutStopAnimationBeforeScheduleAnimation) { WebView().MainFrameWidget()->Resize(WebSize(800, 600)); WebView().SetBaseBackgroundColorOverride(SK_ColorTRANSPARENT); SimRequest request("https://example.com/test.html", "text/html"); LoadURL("https://example.com/test.html"); request.Complete(R"HTML(

Some text here for selection autoscroll.

Some text here for selection autoscroll.

Some text here for selection autoscroll.

Some text here for selection autoscroll.

Some text here for selection autoscroll.

Some text here for selection autoscroll.

Some text here for selection autoscroll.

Some text here for selection autoscroll.

)HTML"); Compositor().BeginFrame(); AutoscrollController& controller = GetAutoscrollController(); Document& document = GetDocument(); Element* scrollable = document.getElementById("scrollable"); DCHECK(scrollable); DCHECK(scrollable->GetLayoutObject()); WebMouseEvent event(WebInputEvent::kMouseDown, WebFloatPoint(5, 5), WebFloatPoint(5, 5), WebPointerProperties::Button::kLeft, 0, WebInputEvent::Modifiers::kLeftButtonDown, CurrentTimeTicks()); event.SetFrameScale(1); GetDocument().GetFrame()->GetEventHandler().HandleMousePressEvent(event); controller.StartAutoscrollForSelection(scrollable->GetLayoutObject()); DCHECK(controller.IsAutoscrolling()); // Hide scrollable here will cause UpdateSelectionForMouseDrag stop animation. scrollable->SetInlineStyleProperty(CSSPropertyDisplay, CSSValueNone); // BeginFrame will call AutoscrollController::Animate. Compositor().BeginFrame(); EXPECT_FALSE(controller.IsAutoscrolling()); } } // namespace blink