Commit ec5accba authored by David Bokan's avatar David Bokan Committed by Commit Bot

[FractionalScroll] Make Blink unittests pass

This CL fixes Blink unit tests when the FractionalScrollOffsets flag is
turned on. This flag enables storing floating point scroll offsets
inside Blink's ScrollableArea objects. This means that fractional
offsets are now visible to JS and test code; some tests need to be
adjusted to the new expectations.

The typical test here performed something like a ScrollIntoView which
should land on a fractional offset when trying to center an element.
Prior to FractionalScrollOffsets, this would be floored. I've adjusted
these tests to either change the page slightly so that we naturally land
on an integral offset or provided a new expectation behind the runtime
enabled feature. This is ok since these tests are just checking that an
element is scrolled into view, we don't care about exact pixel offsets.

For the smooth scrolling tests, I allowed a 1px difference in the
expectation since these are checking a scroll offset mid-animation.

After this CL, all Blink unit tests pass with FractionalScrollOffsets
enabled.

Bug: 414283
Change-Id: Ief639a780d0780ab74ca11718c05921ed8a4670d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1690221
Commit-Queue: David Bokan <bokan@chromium.org>
Reviewed-by: default avatarStefan Zager <szager@chromium.org>
Cr-Commit-Position: refs/heads/master@{#676135}
parent d2167d6a
...@@ -291,7 +291,7 @@ PhysicalRect RootFrameViewport::ScrollIntoView( ...@@ -291,7 +291,7 @@ PhysicalRect RootFrameViewport::ScrollIntoView(
PhysicalRect rect_in_document = rect_in_absolute; PhysicalRect rect_in_document = rect_in_absolute;
rect_in_document.Move( rect_in_document.Move(
PhysicalOffset::FromFloatSizeRound(LayoutViewport().GetScrollOffset())); PhysicalOffset::FromFloatSizeFloor(LayoutViewport().GetScrollOffset()));
ScrollOffset new_scroll_offset = ScrollOffset new_scroll_offset =
ClampScrollOffset(ScrollAlignment::GetScrollOffsetToExpose( ClampScrollOffset(ScrollAlignment::GetScrollOffsetToExpose(
......
...@@ -1264,8 +1264,13 @@ TEST_P(VisualViewportTest, ScrollIntoViewFractionalOffset) { ...@@ -1264,8 +1264,13 @@ TEST_P(VisualViewportTest, ScrollIntoViewFractionalOffset) {
kProgrammaticScroll); kProgrammaticScroll);
inputBox->scrollIntoViewIfNeeded(false); inputBox->scrollIntoViewIfNeeded(false);
EXPECT_EQ(ScrollOffset(0, 900), if (RuntimeEnabledFeatures::FractionalScrollOffsetsEnabled()) {
layout_viewport_scrollable_area->GetScrollOffset()); EXPECT_EQ(ScrollOffset(0, 900.75),
layout_viewport_scrollable_area->GetScrollOffset());
} else {
EXPECT_EQ(ScrollOffset(0, 900),
layout_viewport_scrollable_area->GetScrollOffset());
}
EXPECT_EQ(FloatSize(250.25f, 100.25f), visual_viewport.GetScrollOffset()); EXPECT_EQ(FloatSize(250.25f, 100.25f), visual_viewport.GetScrollOffset());
// Change the fractional part of the frameview to one that would round down. // Change the fractional part of the frameview to one that would round down.
...@@ -1273,8 +1278,13 @@ TEST_P(VisualViewportTest, ScrollIntoViewFractionalOffset) { ...@@ -1273,8 +1278,13 @@ TEST_P(VisualViewportTest, ScrollIntoViewFractionalOffset) {
kProgrammaticScroll); kProgrammaticScroll);
inputBox->scrollIntoViewIfNeeded(false); inputBox->scrollIntoViewIfNeeded(false);
EXPECT_EQ(ScrollOffset(0, 900), if (RuntimeEnabledFeatures::FractionalScrollOffsetsEnabled()) {
layout_viewport_scrollable_area->GetScrollOffset()); EXPECT_EQ(ScrollOffset(0, 900.125),
layout_viewport_scrollable_area->GetScrollOffset());
} else {
EXPECT_EQ(ScrollOffset(0, 900),
layout_viewport_scrollable_area->GetScrollOffset());
}
EXPECT_EQ(FloatSize(250.25f, 100.25f), visual_viewport.GetScrollOffset()); EXPECT_EQ(FloatSize(250.25f, 100.25f), visual_viewport.GetScrollOffset());
// Repeat both tests above with the visual viewport at a high fractional. // Repeat both tests above with the visual viewport at a high fractional.
...@@ -1283,8 +1293,13 @@ TEST_P(VisualViewportTest, ScrollIntoViewFractionalOffset) { ...@@ -1283,8 +1293,13 @@ TEST_P(VisualViewportTest, ScrollIntoViewFractionalOffset) {
kProgrammaticScroll); kProgrammaticScroll);
inputBox->scrollIntoViewIfNeeded(false); inputBox->scrollIntoViewIfNeeded(false);
EXPECT_EQ(ScrollOffset(0, 900), if (RuntimeEnabledFeatures::FractionalScrollOffsetsEnabled()) {
layout_viewport_scrollable_area->GetScrollOffset()); EXPECT_EQ(ScrollOffset(0, 900.75),
layout_viewport_scrollable_area->GetScrollOffset());
} else {
EXPECT_EQ(ScrollOffset(0, 900),
layout_viewport_scrollable_area->GetScrollOffset());
}
EXPECT_EQ(FloatSize(250.875f, 100.875f), visual_viewport.GetScrollOffset()); EXPECT_EQ(FloatSize(250.875f, 100.875f), visual_viewport.GetScrollOffset());
// Change the fractional part of the frameview to one that would round down. // Change the fractional part of the frameview to one that would round down.
...@@ -1292,8 +1307,13 @@ TEST_P(VisualViewportTest, ScrollIntoViewFractionalOffset) { ...@@ -1292,8 +1307,13 @@ TEST_P(VisualViewportTest, ScrollIntoViewFractionalOffset) {
kProgrammaticScroll); kProgrammaticScroll);
inputBox->scrollIntoViewIfNeeded(false); inputBox->scrollIntoViewIfNeeded(false);
EXPECT_EQ(ScrollOffset(0, 900), if (RuntimeEnabledFeatures::FractionalScrollOffsetsEnabled()) {
layout_viewport_scrollable_area->GetScrollOffset()); EXPECT_EQ(ScrollOffset(0, 900.125),
layout_viewport_scrollable_area->GetScrollOffset());
} else {
EXPECT_EQ(ScrollOffset(0, 900),
layout_viewport_scrollable_area->GetScrollOffset());
}
EXPECT_EQ(FloatSize(250.875f, 100.875f), visual_viewport.GetScrollOffset()); EXPECT_EQ(FloatSize(250.875f, 100.875f), visual_viewport.GetScrollOffset());
// Both viewports with a 0.5 fraction. // Both viewports with a 0.5 fraction.
...@@ -1302,8 +1322,13 @@ TEST_P(VisualViewportTest, ScrollIntoViewFractionalOffset) { ...@@ -1302,8 +1322,13 @@ TEST_P(VisualViewportTest, ScrollIntoViewFractionalOffset) {
kProgrammaticScroll); kProgrammaticScroll);
inputBox->scrollIntoViewIfNeeded(false); inputBox->scrollIntoViewIfNeeded(false);
EXPECT_EQ(ScrollOffset(0, 900), if (RuntimeEnabledFeatures::FractionalScrollOffsetsEnabled()) {
layout_viewport_scrollable_area->GetScrollOffset()); EXPECT_EQ(ScrollOffset(0, 900.5),
layout_viewport_scrollable_area->GetScrollOffset());
} else {
EXPECT_EQ(ScrollOffset(0, 900),
layout_viewport_scrollable_area->GetScrollOffset());
}
EXPECT_EQ(FloatSize(250.5f, 100.5f), visual_viewport.GetScrollOffset()); EXPECT_EQ(FloatSize(250.5f, 100.5f), visual_viewport.GetScrollOffset());
} }
......
...@@ -236,16 +236,26 @@ TEST_F(ImageDocumentTest, MAYBE(ImageCenteredAtDeviceScaleFactor)) { ...@@ -236,16 +236,26 @@ TEST_F(ImageDocumentTest, MAYBE(ImageCenteredAtDeviceScaleFactor)) {
GetDocument().ImageClicked(15, 27); GetDocument().ImageClicked(15, 27);
ScrollOffset offset = ScrollOffset offset =
GetDocument().GetFrame()->View()->LayoutViewport()->GetScrollOffset(); GetDocument().GetFrame()->View()->LayoutViewport()->GetScrollOffset();
EXPECT_EQ(22, offset.Width()); if (RuntimeEnabledFeatures::FractionalScrollOffsetsEnabled()) {
EXPECT_EQ(42, offset.Height()); EXPECT_EQ(22.5f, offset.Width());
EXPECT_EQ(42, offset.Height());
} else {
EXPECT_EQ(22, offset.Width());
EXPECT_EQ(42, offset.Height());
}
GetDocument().ImageClicked(20, 20); GetDocument().ImageClicked(20, 20);
GetDocument().ImageClicked(12, 15); GetDocument().ImageClicked(12, 15);
offset = offset =
GetDocument().GetFrame()->View()->LayoutViewport()->GetScrollOffset(); GetDocument().GetFrame()->View()->LayoutViewport()->GetScrollOffset();
EXPECT_EQ(11, offset.Width()); if (RuntimeEnabledFeatures::FractionalScrollOffsetsEnabled()) {
EXPECT_EQ(22, offset.Height()); EXPECT_EQ(11.25f, offset.Width());
EXPECT_EQ(22.5f, offset.Height());
} else {
EXPECT_EQ(11, offset.Width());
EXPECT_EQ(22, offset.Height());
}
} }
class ImageDocumentViewportTest : public SimTest { class ImageDocumentViewportTest : public SimTest {
......
...@@ -105,6 +105,10 @@ struct CORE_EXPORT PhysicalOffset { ...@@ -105,6 +105,10 @@ struct CORE_EXPORT PhysicalOffset {
return {LayoutUnit::FromFloatRound(point.X()), return {LayoutUnit::FromFloatRound(point.X()),
LayoutUnit::FromFloatRound(point.Y())}; LayoutUnit::FromFloatRound(point.Y())};
} }
static PhysicalOffset FromFloatSizeFloor(const FloatSize& size) {
return {LayoutUnit::FromFloatFloor(size.Width()),
LayoutUnit::FromFloatFloor(size.Height())};
}
static PhysicalOffset FromFloatSizeRound(const FloatSize& size) { static PhysicalOffset FromFloatSizeRound(const FloatSize& size) {
return {LayoutUnit::FromFloatRound(size.Width()), return {LayoutUnit::FromFloatRound(size.Width()),
LayoutUnit::FromFloatRound(size.Height())}; LayoutUnit::FromFloatRound(size.Height())};
......
...@@ -158,12 +158,12 @@ TEST_F(ProgrammaticScrollSimTest, NavigateToHash) { ...@@ -158,12 +158,12 @@ TEST_F(ProgrammaticScrollSimTest, NavigateToHash) {
body { body {
height: 4000px; height: 4000px;
} }
h2 { div {
position: absolute; position: absolute;
top: 3000px; top: 3000px;
} }
</style> </style>
<h2 id="target">Target</h2> <div id="target">Target</h2>
)HTML"); )HTML");
main_resource.Finish(); main_resource.Finish();
css_resource.Complete(); css_resource.Complete();
...@@ -174,7 +174,7 @@ TEST_F(ProgrammaticScrollSimTest, NavigateToHash) { ...@@ -174,7 +174,7 @@ TEST_F(ProgrammaticScrollSimTest, NavigateToHash) {
test::RunPendingTasks(); test::RunPendingTasks();
ScrollableArea* layout_viewport = GetDocument().View()->LayoutViewport(); ScrollableArea* layout_viewport = GetDocument().View()->LayoutViewport();
EXPECT_EQ(3001, layout_viewport->GetScrollOffset().Height()); EXPECT_EQ(3000, layout_viewport->GetScrollOffset().Height());
} }
} // namespace blink } // namespace blink
...@@ -171,7 +171,7 @@ TEST_F(ScrollIntoViewTest, SmoothScroll) { ...@@ -171,7 +171,7 @@ TEST_F(ScrollIntoViewTest, SmoothScroll) {
Compositor().BeginFrame(); // update run_state_. Compositor().BeginFrame(); // update run_state_.
Compositor().BeginFrame(); // Set start_time = now. Compositor().BeginFrame(); // Set start_time = now.
Compositor().BeginFrame(0.2); Compositor().BeginFrame(0.2);
ASSERT_EQ(Window().scrollY(), 299); ASSERT_NEAR(Window().scrollY(), 299, 1);
// Finish scrolling the container // Finish scrolling the container
Compositor().BeginFrame(1); Compositor().BeginFrame(1);
...@@ -207,7 +207,7 @@ TEST_F(ScrollIntoViewTest, NestedContainer) { ...@@ -207,7 +207,7 @@ TEST_F(ScrollIntoViewTest, NestedContainer) {
Compositor().BeginFrame(); // update run_state_. Compositor().BeginFrame(); // update run_state_.
Compositor().BeginFrame(); // Set start_time = now. Compositor().BeginFrame(); // Set start_time = now.
Compositor().BeginFrame(0.2); Compositor().BeginFrame(0.2);
ASSERT_EQ(Window().scrollY(), 299); ASSERT_NEAR(Window().scrollY(), 299, 1);
ASSERT_EQ(container->scrollTop(), 0); ASSERT_EQ(container->scrollTop(), 0);
// Finish scrolling the outer container // Finish scrolling the outer container
...@@ -218,7 +218,7 @@ TEST_F(ScrollIntoViewTest, NestedContainer) { ...@@ -218,7 +218,7 @@ TEST_F(ScrollIntoViewTest, NestedContainer) {
// Scrolling the inner container // Scrolling the inner container
Compositor().BeginFrame(); // Set start_time = now. Compositor().BeginFrame(); // Set start_time = now.
Compositor().BeginFrame(0.2); Compositor().BeginFrame(0.2);
ASSERT_EQ(container->scrollTop(), 299); ASSERT_NEAR(container->scrollTop(), 299, 1);
// Finish scrolling the inner container // Finish scrolling the inner container
Compositor().BeginFrame(1); Compositor().BeginFrame(1);
...@@ -261,14 +261,14 @@ TEST_F(ScrollIntoViewTest, NewScrollIntoViewAbortsCurrentAnimation) { ...@@ -261,14 +261,14 @@ TEST_F(ScrollIntoViewTest, NewScrollIntoViewAbortsCurrentAnimation) {
Compositor().BeginFrame(); // update run_state_. Compositor().BeginFrame(); // update run_state_.
Compositor().BeginFrame(); // Set start_time = now. Compositor().BeginFrame(); // Set start_time = now.
Compositor().BeginFrame(0.2); Compositor().BeginFrame(0.2);
ASSERT_EQ(Window().scrollY(), 299); ASSERT_NEAR(Window().scrollY(), 299, 1);
ASSERT_EQ(container1->scrollTop(), 0); ASSERT_EQ(container1->scrollTop(), 0);
content2->scrollIntoView(arg); content2->scrollIntoView(arg);
Compositor().BeginFrame(); // update run_state_. Compositor().BeginFrame(); // update run_state_.
Compositor().BeginFrame(); // Set start_time = now. Compositor().BeginFrame(); // Set start_time = now.
Compositor().BeginFrame(0.2); Compositor().BeginFrame(0.2);
ASSERT_EQ(Window().scrollY(), 61); ASSERT_NEAR(Window().scrollY(), 61, 1);
ASSERT_EQ(container1->scrollTop(), 0); // container1 should not scroll. ASSERT_EQ(container1->scrollTop(), 0); // container1 should not scroll.
Compositor().BeginFrame(1); Compositor().BeginFrame(1);
...@@ -278,7 +278,7 @@ TEST_F(ScrollIntoViewTest, NewScrollIntoViewAbortsCurrentAnimation) { ...@@ -278,7 +278,7 @@ TEST_F(ScrollIntoViewTest, NewScrollIntoViewAbortsCurrentAnimation) {
// Scrolling content2 in container2 // Scrolling content2 in container2
Compositor().BeginFrame(); // Set start_time = now. Compositor().BeginFrame(); // Set start_time = now.
Compositor().BeginFrame(0.2); Compositor().BeginFrame(0.2);
ASSERT_EQ(container2->scrollTop(), 300); ASSERT_NEAR(container2->scrollTop(), 300, 1);
// Finish all the animation to make sure there is no another animation queued // Finish all the animation to make sure there is no another animation queued
// on container1. // on container1.
...@@ -320,7 +320,7 @@ TEST_F(ScrollIntoViewTest, ScrollWindowAbortsCurrentAnimation) { ...@@ -320,7 +320,7 @@ TEST_F(ScrollIntoViewTest, ScrollWindowAbortsCurrentAnimation) {
Compositor().BeginFrame(); // update run_state_. Compositor().BeginFrame(); // update run_state_.
Compositor().BeginFrame(); // Set start_time = now. Compositor().BeginFrame(); // Set start_time = now.
Compositor().BeginFrame(0.2); Compositor().BeginFrame(0.2);
ASSERT_EQ(Window().scrollY(), 299); ASSERT_NEAR(Window().scrollY(), 299, 1);
ASSERT_EQ(container->scrollTop(), 0); ASSERT_EQ(container->scrollTop(), 0);
ScrollToOptions* window_option = ScrollToOptions::Create(); ScrollToOptions* window_option = ScrollToOptions::Create();
...@@ -331,7 +331,7 @@ TEST_F(ScrollIntoViewTest, ScrollWindowAbortsCurrentAnimation) { ...@@ -331,7 +331,7 @@ TEST_F(ScrollIntoViewTest, ScrollWindowAbortsCurrentAnimation) {
Compositor().BeginFrame(); // update run_state_. Compositor().BeginFrame(); // update run_state_.
Compositor().BeginFrame(); // Set start_time = now. Compositor().BeginFrame(); // Set start_time = now.
Compositor().BeginFrame(0.2); Compositor().BeginFrame(0.2);
ASSERT_EQ(Window().scrollY(), 58); ASSERT_NEAR(Window().scrollY(), 58, 1);
Compositor().BeginFrame(1); Compositor().BeginFrame(1);
ASSERT_EQ(Window().scrollY(), 0); ASSERT_EQ(Window().scrollY(), 0);
...@@ -435,7 +435,7 @@ TEST_F(ScrollIntoViewTest, SmoothAndInstantInChain) { ...@@ -435,7 +435,7 @@ TEST_F(ScrollIntoViewTest, SmoothAndInstantInChain) {
Compositor().BeginFrame(); // update run_state_. Compositor().BeginFrame(); // update run_state_.
Compositor().BeginFrame(); // Set start_time = now. Compositor().BeginFrame(); // Set start_time = now.
Compositor().BeginFrame(0.2); Compositor().BeginFrame(0.2);
ASSERT_EQ(container->scrollTop(), 299); ASSERT_NEAR(container->scrollTop(), 299, 1);
// Finish scrolling the container // Finish scrolling the container
Compositor().BeginFrame(1); Compositor().BeginFrame(1);
...@@ -468,7 +468,7 @@ TEST_F(ScrollIntoViewTest, SmoothScrollAnchor) { ...@@ -468,7 +468,7 @@ TEST_F(ScrollIntoViewTest, SmoothScrollAnchor) {
Compositor().BeginFrame(); // update run_state_. Compositor().BeginFrame(); // update run_state_.
Compositor().BeginFrame(); // Set start_time = now. Compositor().BeginFrame(); // Set start_time = now.
Compositor().BeginFrame(0.2); Compositor().BeginFrame(0.2);
ASSERT_EQ(container->scrollTop(), 299); ASSERT_NEAR(container->scrollTop(), 299, 1);
// Finish scrolling the container // Finish scrolling the container
Compositor().BeginFrame(1); Compositor().BeginFrame(1);
...@@ -521,7 +521,7 @@ TEST_F(ScrollIntoViewTest, ApplyRootElementScrollBehaviorToViewport) { ...@@ -521,7 +521,7 @@ TEST_F(ScrollIntoViewTest, ApplyRootElementScrollBehaviorToViewport) {
Compositor().BeginFrame(); // update run_state_. Compositor().BeginFrame(); // update run_state_.
Compositor().BeginFrame(); // Set start_time = now. Compositor().BeginFrame(); // Set start_time = now.
Compositor().BeginFrame(0.2); Compositor().BeginFrame(0.2);
ASSERT_EQ(Window().scrollY(), 299); ASSERT_NEAR(Window().scrollY(), 299, 1);
// Finish scrolling the container // Finish scrolling the container
Compositor().BeginFrame(1); Compositor().BeginFrame(1);
...@@ -687,7 +687,7 @@ TEST_F(ScrollIntoViewTest, SmoothUserScrollNotAbortedByProgrammaticScrolls) { ...@@ -687,7 +687,7 @@ TEST_F(ScrollIntoViewTest, SmoothUserScrollNotAbortedByProgrammaticScrolls) {
Compositor().BeginFrame(); // update run_state_. Compositor().BeginFrame(); // update run_state_.
Compositor().BeginFrame(); // Set start_time = now. Compositor().BeginFrame(); // Set start_time = now.
Compositor().BeginFrame(0.2); Compositor().BeginFrame(0.2);
ASSERT_EQ(Window().scrollY(), 299); ASSERT_NEAR(Window().scrollY(), 299, 1);
// ProgrammaticScroll that could interrupt the current smooth scroll. // ProgrammaticScroll that could interrupt the current smooth scroll.
Window().scrollTo(0, 0); Window().scrollTo(0, 0);
...@@ -722,7 +722,7 @@ TEST_F(ScrollIntoViewTest, LongDistanceSmoothScrollFinishedInThreeSeconds) { ...@@ -722,7 +722,7 @@ TEST_F(ScrollIntoViewTest, LongDistanceSmoothScrollFinishedInThreeSeconds) {
Compositor().BeginFrame(); // update run_state_. Compositor().BeginFrame(); // update run_state_.
Compositor().BeginFrame(); // Set start_time = now. Compositor().BeginFrame(); // Set start_time = now.
Compositor().BeginFrame(0.2); Compositor().BeginFrame(0.2);
ASSERT_EQ(Window().scrollY(), 864); ASSERT_NEAR(Window().scrollY(), 864, 1);
// Finish scrolling the container // Finish scrolling the container
Compositor().BeginFrame(2.8); Compositor().BeginFrame(2.8);
......
...@@ -2036,7 +2036,7 @@ PhysicalRect PaintLayerScrollableArea::ScrollIntoView( ...@@ -2036,7 +2036,7 @@ PhysicalRect PaintLayerScrollableArea::ScrollIntoView(
PhysicalOffset border_origin_to_scroll_origin(-GetLayoutBox()->BorderLeft(), PhysicalOffset border_origin_to_scroll_origin(-GetLayoutBox()->BorderLeft(),
-GetLayoutBox()->BorderTop()); -GetLayoutBox()->BorderTop());
border_origin_to_scroll_origin += border_origin_to_scroll_origin +=
PhysicalOffset::FromFloatSizeRound(GetScrollOffset()); PhysicalOffset::FromFloatSizeFloor(GetScrollOffset());
// Represent the rect in the container's scroll-origin coordinate. // Represent the rect in the container's scroll-origin coordinate.
local_expose_rect.Move(border_origin_to_scroll_origin); local_expose_rect.Move(border_origin_to_scroll_origin);
PhysicalRect scroll_snapport_rect = VisibleScrollSnapportRect(); PhysicalRect scroll_snapport_rect = VisibleScrollSnapportRect();
......
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