Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(253)

Unified Diff: third_party/WebKit/Source/web/tests/TopControlsTest.cpp

Issue 1844013002: Fix main thread top controls scrolling to mirror CC. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@propertyTreesBoundsDelta
Patch Set: Fixed anchoring to check width too Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/web/tests/TopControlsTest.cpp
diff --git a/third_party/WebKit/Source/web/tests/TopControlsTest.cpp b/third_party/WebKit/Source/web/tests/TopControlsTest.cpp
index a4de2cf1ea885c44b2450367c29c733619cdfba1..8f4f317360ab144a0566b3fc42a0df82d4ab49cf 100644
--- a/third_party/WebKit/Source/web/tests/TopControlsTest.cpp
+++ b/third_party/WebKit/Source/web/tests/TopControlsTest.cpp
@@ -156,7 +156,7 @@ TEST_F(TopControlsTest, MAYBE(HideOnScrollDown))
{
WebViewImpl* webView = initialize();
// initialize top controls to be shown.
- webView->setTopControlsHeight(50.f, true);
+ webView->resize(webView->size(), 50.f, true);
webView->topControls().setShownRatio(1);
webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollBegin));
@@ -183,7 +183,7 @@ TEST_F(TopControlsTest, MAYBE(ShowOnScrollUp))
{
WebViewImpl* webView = initialize();
// initialize top controls to be hidden.
- webView->setTopControlsHeight(50.f, false);
+ webView->resize(webView->size(), 50.f, false);
webView->topControls().setShownRatio(0);
webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollBegin));
@@ -204,7 +204,7 @@ TEST_F(TopControlsTest, MAYBE(ScrollDownThenUp))
{
WebViewImpl* webView = initialize();
// initialize top controls to be shown and position page at 100px.
- webView->setTopControlsHeight(50.f, true);
+ webView->resize(webView->size(), 50.f, true);
webView->topControls().setShownRatio(1);
frame()->view()->getScrollableArea()->setScrollPosition(IntPoint(0, 100), ProgrammaticScroll);
@@ -242,7 +242,7 @@ TEST_F(TopControlsTest, MAYBE(ScrollUpThenDown))
{
WebViewImpl* webView = initialize();
// initialize top controls to be hidden and position page at 100px.
- webView->setTopControlsHeight(50.f, false);
+ webView->resize(webView->size(), 50.f, false);
webView->topControls().setShownRatio(0);
frame()->view()->getScrollableArea()->setScrollPosition(IntPoint(0, 100), ProgrammaticScroll);
@@ -269,7 +269,7 @@ TEST_F(TopControlsTest, MAYBE(HorizontalScroll))
{
WebViewImpl* webView = initialize();
// initialize top controls to be shown.
- webView->setTopControlsHeight(50.f, true);
+ webView->resize(webView->size(), 50.f, true);
webView->topControls().setShownRatio(1);
webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollBegin));
@@ -293,7 +293,7 @@ TEST_F(TopControlsTest, MAYBE(PageScaleHasNoImpact))
webView->setPageScaleFactor(2.0);
// Initialize top controls to be shown.
- webView->setTopControlsHeight(50.f, true);
+ webView->resize(webView->size(), 50.f, true);
webView->topControls().setShownRatio(1);
webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollBegin));
@@ -339,7 +339,7 @@ TEST_F(TopControlsTest, MAYBE(FloatingPointSlippage))
webView->setPageScaleFactor(2.0);
// Initialize top controls to be shown.
- webView->setTopControlsHeight(50.f, true);
+ webView->resize(webView->size(), 50.f, true);
webView->topControls().setShownRatio(1);
webView->topControls().scrollBegin();
@@ -356,7 +356,7 @@ TEST_F(TopControlsTest, MAYBE(FloatingPointSlippage))
TEST_F(TopControlsTest, MAYBE(ScrollableSubregionScrollFirst))
{
WebViewImpl* webView = initialize("overflow-scrolling.html");
- webView->setTopControlsHeight(50.f, true);
+ webView->resize(webView->size(), 50.f, true);
webView->topControls().setShownRatio(1);
frame()->view()->getScrollableArea()->setScrollPosition(IntPoint(0, 50), ProgrammaticScroll);
@@ -398,7 +398,7 @@ TEST_F(TopControlsTest, MAYBE(ScrollableSubregionScrollFirst))
TEST_F(TopControlsTest, MAYBE(ScrollableIframeScrollFirst))
{
WebViewImpl* webView = initialize("iframe-scrolling.html");
- webView->setTopControlsHeight(50.f, true);
+ webView->resize(webView->size(), 50.f, true);
webView->topControls().setShownRatio(1);
frame()->view()->getScrollableArea()->setScrollPosition(IntPoint(0, 50), ProgrammaticScroll);
@@ -439,13 +439,13 @@ TEST_F(TopControlsTest, MAYBE(ScrollableIframeScrollFirst))
TEST_F(TopControlsTest, MAYBE(HeightChangeMaintainsVisibility))
{
WebViewImpl* webView = initialize();
- webView->setTopControlsHeight(20.f, false);
+ webView->resize(webView->size(), 20.f, false);
webView->topControls().setShownRatio(0);
- webView->setTopControlsHeight(20.f, false);
+ webView->resize(webView->size(), 20.f, false);
EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset());
- webView->setTopControlsHeight(40.f, false);
+ webView->resize(webView->size(), 40.f, false);
EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset());
// Scroll up to show top controls.
@@ -453,7 +453,7 @@ TEST_F(TopControlsTest, MAYBE(HeightChangeMaintainsVisibility))
EXPECT_FLOAT_EQ(40.f, webView->topControls().contentOffset());
// Changing height of a fully shown top controls should correctly adjust content offset
- webView->setTopControlsHeight(30.f, false);
+ webView->resize(webView->size(), 30.f, false);
EXPECT_FLOAT_EQ(30.f, webView->topControls().contentOffset());
}
@@ -461,7 +461,7 @@ TEST_F(TopControlsTest, MAYBE(HeightChangeMaintainsVisibility))
TEST_F(TopControlsTest, MAYBE(ZeroHeightMeansNoEffect))
{
WebViewImpl* webView = initialize();
- webView->setTopControlsHeight(0, false);
+ webView->resize(webView->size(), 0, false);
webView->topControls().setShownRatio(0);
frame()->view()->getScrollableArea()->setScrollPosition(IntPoint(0, 100), ProgrammaticScroll);
@@ -484,7 +484,7 @@ TEST_F(TopControlsTest, MAYBE(ScrollUpPastLimitDoesNotHide))
{
WebViewImpl* webView = initialize();
// Initialize top controls to be shown
- webView->setTopControlsHeight(50.f, true);
+ webView->resize(webView->size(), 50.f, true);
webView->topControls().setShownRatio(1);
// Use 2x scale so that both visual viewport and frameview are scrollable
webView->setPageScaleFactor(2.0);
@@ -516,7 +516,7 @@ TEST_F(TopControlsTest, MAYBE(ScrollUpPastLimitDoesNotHide))
TEST_F(TopControlsTest, MAYBE(StateConstraints))
{
WebViewImpl* webView = initialize();
- webView->setTopControlsHeight(50.f, false);
+ webView->resize(webView->size(), 50.f, false);
frame()->view()->getScrollableArea()->setScrollPosition(IntPoint(0, 100), ProgrammaticScroll);
// Setting permitted state should not change content offset
@@ -565,7 +565,7 @@ TEST_F(TopControlsTest, MAYBE(DontAffectLayoutHeight))
{
// Initialize with the top controls showing.
WebViewImpl* webView = initialize("percent-height.html");
- webView->setTopControlsHeight(100.f, true);
+ webView->resize(webView->size(), 100.f, true);
webView->updateTopControlsState(
WebTopControlsBoth, WebTopControlsShown, false);
webView->topControls().setShownRatio(1);
@@ -589,8 +589,7 @@ TEST_F(TopControlsTest, MAYBE(DontAffectLayoutHeight))
// Hide the top controls.
verticalScroll(-100.f);
- webView->setTopControlsHeight(100.f, false);
- webView->resize(WebSize(400, 400));
+ webView->resize(WebSize(400, 400), 100.f, false);
webView->updateAllLifecyclePhases();
ASSERT_EQ(0.f, webView->topControls().contentOffset());
@@ -610,11 +609,10 @@ TEST_F(TopControlsTest, MAYBE(DontAffectVHUnits))
{
// Initialize with the top controls showing.
WebViewImpl* webView = initialize("vh-height.html");
- webView->setTopControlsHeight(100.f, true);
+ webView->resize(WebSize(400, 300), 100.f, true);
webView->updateTopControlsState(
WebTopControlsBoth, WebTopControlsShown, false);
webView->topControls().setShownRatio(1);
- webView->resize(WebSize(400, 300));
webView->updateAllLifecyclePhases();
ASSERT_EQ(100.f, webView->topControls().contentOffset());
@@ -634,8 +632,7 @@ TEST_F(TopControlsTest, MAYBE(DontAffectVHUnits))
// Hide the top controls.
verticalScroll(-100.f);
- webView->setTopControlsHeight(100.f, false);
- webView->resize(WebSize(400, 400));
+ webView->resize(WebSize(400, 400), 100.f, false);
webView->updateAllLifecyclePhases();
ASSERT_EQ(0.f, webView->topControls().contentOffset());
@@ -657,11 +654,10 @@ TEST_F(TopControlsTest, MAYBE(DontAffectVHUnitsWithScale))
{
// Initialize with the top controls showing.
WebViewImpl* webView = initialize("vh-height-width-800.html");
- webView->setTopControlsHeight(100.f, true);
+ webView->resize(WebSize(400, 300), 100.f, true);
webView->updateTopControlsState(
WebTopControlsBoth, WebTopControlsShown, false);
webView->topControls().setShownRatio(1);
- webView->resize(WebSize(400, 300));
webView->updateAllLifecyclePhases();
ASSERT_EQ(100.f, webView->topControls().contentOffset());
@@ -688,8 +684,7 @@ TEST_F(TopControlsTest, MAYBE(DontAffectVHUnitsWithScale))
// Hide the top controls.
verticalScroll(-100.f);
- webView->setTopControlsHeight(100.f, false);
- webView->resize(WebSize(400, 400));
+ webView->resize(WebSize(400, 400), 100.f, false);
webView->updateAllLifecyclePhases();
ASSERT_EQ(0.f, webView->topControls().contentOffset());
@@ -712,11 +707,10 @@ TEST_F(TopControlsTest, MAYBE(DontAffectVHUnitsUseLayoutSize))
{
// Initialize with the top controls showing.
WebViewImpl* webView = initialize("vh-height-width-800-extra-wide.html");
- webView->setTopControlsHeight(100.f, true);
+ webView->resize(WebSize(400, 300), 100.f, true);
webView->updateTopControlsState(
WebTopControlsBoth, WebTopControlsShown, false);
webView->topControls().setShownRatio(1);
- webView->resize(WebSize(400, 300));
webView->updateAllLifecyclePhases();
ASSERT_EQ(100.f, webView->topControls().contentOffset());
@@ -731,4 +725,94 @@ TEST_F(TopControlsTest, MAYBE(DontAffectVHUnitsUseLayoutSize))
EXPECT_EQ(800, frame()->view()->viewportSizeForViewportUnits().height());
}
+// This tests that the viewport remains anchored when top controls are brought
+// in while the document is fully scrolled. This normally causes clamping of the
+// visual viewport to keep it bounded by the layout viewport so we're testing
+// that the viewport anchoring logic is working to keep the view unchanged.
+TEST_F(TopControlsTest, MAYBE(AnchorViewportDuringIncreasingAdjustment))
+{
+ int contentHeight = 1016;
+ int layoutViewportHeight = 500;
+ int visualViewportHeight = 500;
+ int topControlsHeight = 100;
+ int pageScale = 2;
+ int minScale = 1;
+
+ // Initialize with the top controls showing.
+ WebViewImpl* webView = initialize("large-div.html");
+ webViewImpl()->setDefaultPageScaleLimits(minScale, 5);
+ webView->updateTopControlsState(
+ WebTopControlsBoth, WebTopControlsShown, false);
+ webView->topControls().setShownRatio(1);
+ webView->resize(
+ WebSize(800, layoutViewportHeight),
+ topControlsHeight,
+ true);
+ webView->updateAllLifecyclePhases();
+
+ FrameView* view = frame()->view();
+ ScrollableArea* rootViewport = frame()->view()->getScrollableArea();
+
+ int expectedVisualOffset =
+ ((layoutViewportHeight + topControlsHeight / minScale) * pageScale
+ - (visualViewportHeight + topControlsHeight))
+ / pageScale;
+ int expectedLayoutOffset =
+ contentHeight - (layoutViewportHeight + topControlsHeight / minScale);
+ int expectedRootOffset = expectedVisualOffset + expectedLayoutOffset;
+
+ // Zoom in to 2X and fully scroll both viewports.
+ webView->setPageScaleFactor(pageScale);
+ {
+ webView->handleInputEvent(
+ generateEvent(WebInputEvent::GestureScrollBegin));
+ webView->handleInputEvent(
+ generateEvent(WebInputEvent::GestureScrollUpdate, 0, -10000));
+
+ ASSERT_EQ(0.f, webView->topControls().contentOffset());
+
+ EXPECT_EQ(expectedVisualOffset, visualViewport().location().y());
+ EXPECT_EQ(expectedLayoutOffset,
+ view->layoutViewportScrollableArea()->scrollPosition().y());
+ EXPECT_EQ(expectedRootOffset, rootViewport->scrollPosition().y());
+
+ webView->handleInputEvent(
+ generateEvent(WebInputEvent::GestureScrollEnd));
+ }
+
+ // Commit the top controls resize so that the top controls do not shrink the
+ // layout size. This should not have moved any of the viewports.
+ webView->resize(
+ WebSize(800, layoutViewportHeight + topControlsHeight),
+ topControlsHeight,
+ false);
+ webView->updateAllLifecyclePhases();
+ ASSERT_EQ(expectedVisualOffset, visualViewport().location().y());
+ ASSERT_EQ(expectedLayoutOffset,
+ view->layoutViewportScrollableArea()->scrollPosition().y());
+ ASSERT_EQ(expectedRootOffset, rootViewport->scrollPosition().y());
+
+ // Now scroll back up just enough to show the top controls. The top controls
+ // should shrink both viewports but the layout viewport by a greater amount.
+ // This means the visual viewport's offset must be clamped to keep it within
+ // the layout viewport. Make sure we adjust the scroll position to account
+ // for this and keep the visual viewport at the same location relative to
+ // the document (i.e. the user shouldn't see a movement).
+ {
+ webView->handleInputEvent(
+ generateEvent(WebInputEvent::GestureScrollBegin));
+ webView->handleInputEvent(
+ generateEvent(WebInputEvent::GestureScrollUpdate, 0, 80));
+
+ visualViewport().clampToBoundaries();
+ view->setScrollPosition(view->scrollPosition(), ProgrammaticScroll);
+
+ ASSERT_EQ(80.f, webView->topControls().contentOffset());
+ EXPECT_EQ(expectedRootOffset, rootViewport->scrollPosition().y());
+
+ webView->handleInputEvent(
+ generateEvent(WebInputEvent::GestureScrollEnd));
+ }
+}
+
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698