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

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: Build fix after rebase 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 3785e9b0688e19accb10f0883ccada7669a3ea5a..faf99c2115e1bcbea0780ddba342896b0fe5ef4c 100644
--- a/third_party/WebKit/Source/web/tests/TopControlsTest.cpp
+++ b/third_party/WebKit/Source/web/tests/TopControlsTest.cpp
@@ -158,7 +158,7 @@ TEST_F(TopControlsTest, MAYBE(HideOnScrollDown))
{
WebViewImpl* webView = initialize();
// initialize top controls to be shown.
- webView->setTopControlsHeight(50.f, true);
+ webView->resizeWithTopControls(webView->size(), 50.f, true);
webView->topControls().setShownRatio(1);
webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollBegin));
@@ -185,7 +185,7 @@ TEST_F(TopControlsTest, MAYBE(ShowOnScrollUp))
{
WebViewImpl* webView = initialize();
// initialize top controls to be hidden.
- webView->setTopControlsHeight(50.f, false);
+ webView->resizeWithTopControls(webView->size(), 50.f, false);
webView->topControls().setShownRatio(0);
webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollBegin));
@@ -206,7 +206,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->resizeWithTopControls(webView->size(), 50.f, true);
webView->topControls().setShownRatio(1);
frame()->view()->getScrollableArea()->setScrollPosition(IntPoint(0, 100), ProgrammaticScroll);
@@ -244,7 +244,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->resizeWithTopControls(webView->size(), 50.f, false);
webView->topControls().setShownRatio(0);
frame()->view()->getScrollableArea()->setScrollPosition(IntPoint(0, 100), ProgrammaticScroll);
@@ -271,7 +271,7 @@ TEST_F(TopControlsTest, MAYBE(HorizontalScroll))
{
WebViewImpl* webView = initialize();
// initialize top controls to be shown.
- webView->setTopControlsHeight(50.f, true);
+ webView->resizeWithTopControls(webView->size(), 50.f, true);
webView->topControls().setShownRatio(1);
webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollBegin));
@@ -295,7 +295,7 @@ TEST_F(TopControlsTest, MAYBE(PageScaleHasNoImpact))
webView->setPageScaleFactor(2.0);
// Initialize top controls to be shown.
- webView->setTopControlsHeight(50.f, true);
+ webView->resizeWithTopControls(webView->size(), 50.f, true);
webView->topControls().setShownRatio(1);
webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollBegin));
@@ -341,7 +341,7 @@ TEST_F(TopControlsTest, MAYBE(FloatingPointSlippage))
webView->setPageScaleFactor(2.0);
// Initialize top controls to be shown.
- webView->setTopControlsHeight(50.f, true);
+ webView->resizeWithTopControls(webView->size(), 50.f, true);
webView->topControls().setShownRatio(1);
webView->topControls().scrollBegin();
@@ -358,7 +358,7 @@ TEST_F(TopControlsTest, MAYBE(FloatingPointSlippage))
TEST_F(TopControlsTest, MAYBE(ScrollableSubregionScrollFirst))
{
WebViewImpl* webView = initialize("overflow-scrolling.html");
- webView->setTopControlsHeight(50.f, true);
+ webView->resizeWithTopControls(webView->size(), 50.f, true);
webView->topControls().setShownRatio(1);
frame()->view()->getScrollableArea()->setScrollPosition(IntPoint(0, 50), ProgrammaticScroll);
@@ -400,7 +400,7 @@ TEST_F(TopControlsTest, MAYBE(ScrollableSubregionScrollFirst))
TEST_F(TopControlsTest, MAYBE(ScrollableIframeScrollFirst))
{
WebViewImpl* webView = initialize("iframe-scrolling.html");
- webView->setTopControlsHeight(50.f, true);
+ webView->resizeWithTopControls(webView->size(), 50.f, true);
webView->topControls().setShownRatio(1);
frame()->view()->getScrollableArea()->setScrollPosition(IntPoint(0, 50), ProgrammaticScroll);
@@ -441,13 +441,13 @@ TEST_F(TopControlsTest, MAYBE(ScrollableIframeScrollFirst))
TEST_F(TopControlsTest, MAYBE(HeightChangeMaintainsVisibility))
{
WebViewImpl* webView = initialize();
- webView->setTopControlsHeight(20.f, false);
+ webView->resizeWithTopControls(webView->size(), 20.f, false);
webView->topControls().setShownRatio(0);
- webView->setTopControlsHeight(20.f, false);
+ webView->resizeWithTopControls(webView->size(), 20.f, false);
EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset());
- webView->setTopControlsHeight(40.f, false);
+ webView->resizeWithTopControls(webView->size(), 40.f, false);
EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset());
// Scroll up to show top controls.
@@ -455,7 +455,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->resizeWithTopControls(webView->size(), 30.f, false);
EXPECT_FLOAT_EQ(30.f, webView->topControls().contentOffset());
}
@@ -463,7 +463,7 @@ TEST_F(TopControlsTest, MAYBE(HeightChangeMaintainsVisibility))
TEST_F(TopControlsTest, MAYBE(ZeroHeightMeansNoEffect))
{
WebViewImpl* webView = initialize();
- webView->setTopControlsHeight(0, false);
+ webView->resizeWithTopControls(webView->size(), 0, false);
webView->topControls().setShownRatio(0);
frame()->view()->getScrollableArea()->setScrollPosition(IntPoint(0, 100), ProgrammaticScroll);
@@ -486,7 +486,7 @@ TEST_F(TopControlsTest, MAYBE(ScrollUpPastLimitDoesNotHide))
{
WebViewImpl* webView = initialize();
// Initialize top controls to be shown
- webView->setTopControlsHeight(50.f, true);
+ webView->resizeWithTopControls(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);
@@ -518,7 +518,7 @@ TEST_F(TopControlsTest, MAYBE(ScrollUpPastLimitDoesNotHide))
TEST_F(TopControlsTest, MAYBE(StateConstraints))
{
WebViewImpl* webView = initialize();
- webView->setTopControlsHeight(50.f, false);
+ webView->resizeWithTopControls(webView->size(), 50.f, false);
frame()->view()->getScrollableArea()->setScrollPosition(IntPoint(0, 100), ProgrammaticScroll);
// Setting permitted state should not change content offset
@@ -567,11 +567,10 @@ TEST_F(TopControlsTest, MAYBE(DontAffectLayoutHeight))
{
// Initialize with the top controls showing.
WebViewImpl* webView = initialize("percent-height.html");
- webView->setTopControlsHeight(100.f, true);
+ webView->resizeWithTopControls(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());
@@ -591,8 +590,7 @@ TEST_F(TopControlsTest, MAYBE(DontAffectLayoutHeight))
// Hide the top controls.
verticalScroll(-100.f);
- webView->setTopControlsHeight(100.f, false);
- webView->resize(WebSize(400, 400));
+ webView->resizeWithTopControls(WebSize(400, 400), 100.f, false);
webView->updateAllLifecyclePhases();
ASSERT_EQ(0.f, webView->topControls().contentOffset());
@@ -612,11 +610,10 @@ TEST_F(TopControlsTest, MAYBE(DontAffectVHUnits))
{
// Initialize with the top controls showing.
WebViewImpl* webView = initialize("vh-height.html");
- webView->setTopControlsHeight(100.f, true);
+ webView->resizeWithTopControls(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());
@@ -636,8 +633,7 @@ TEST_F(TopControlsTest, MAYBE(DontAffectVHUnits))
// Hide the top controls.
verticalScroll(-100.f);
- webView->setTopControlsHeight(100.f, false);
- webView->resize(WebSize(400, 400));
+ webView->resizeWithTopControls(WebSize(400, 400), 100.f, false);
webView->updateAllLifecyclePhases();
ASSERT_EQ(0.f, webView->topControls().contentOffset());
@@ -659,11 +655,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->resizeWithTopControls(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());
@@ -690,8 +685,7 @@ TEST_F(TopControlsTest, MAYBE(DontAffectVHUnitsWithScale))
// Hide the top controls.
verticalScroll(-100.f);
- webView->setTopControlsHeight(100.f, false);
- webView->resize(WebSize(400, 400));
+ webView->resizeWithTopControls(WebSize(400, 400), 100.f, false);
webView->updateAllLifecyclePhases();
ASSERT_EQ(0.f, webView->topControls().contentOffset());
@@ -714,11 +708,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->resizeWithTopControls(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());
@@ -733,4 +726,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(AnchorViewportDuringTopControlsAdjustment))
+{
+ 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->resizeWithTopControls(
+ WebSize(800, layoutViewportHeight),
+ topControlsHeight,
+ true);
+ webView->updateTopControlsState(
+ WebTopControlsBoth, WebTopControlsShown, false);
+ webView->topControls().setShownRatio(1);
+ 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->resizeWithTopControls(
+ 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
« no previous file with comments | « third_party/WebKit/Source/web/WebViewImpl.cpp ('k') | third_party/WebKit/Source/web/tests/VisualViewportTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698