Chromium Code Reviews| 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 e6a39ff13f3bdd3036ffe121ec0e665ca9cd9138..f7a60d44636b717dc5e575e333a1f7d606f27c71 100644 |
| --- a/third_party/WebKit/Source/web/tests/TopControlsTest.cpp |
| +++ b/third_party/WebKit/Source/web/tests/TopControlsTest.cpp |
| @@ -731,4 +731,84 @@ 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->setTopControlsHeight(topControlsHeight, true); |
| + webView->updateTopControlsState( |
| + WebTopControlsBoth, WebTopControlsShown, false); |
| + webView->topControls().setShownRatio(1); |
| + webView->resize(WebSize(800, layoutViewportHeight)); |
| + 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); |
| + |
| + // 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(expectedVisualOffset + expectedLayoutOffset, rootViewport->scrollPosition().y()); |
|
majidvp
2016/04/01 17:09:36
s/expectedVisualOffset + expectedLayoutOffset/expe
bokan
2016/04/05 17:11:40
Done.
|
| + |
| + webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollEnd)); |
| + } |
| + |
| + webView->setTopControlsHeight(topControlsHeight, false); |
| + webView->resize(WebSize(800, 600)); |
|
majidvp
2016/04/01 17:09:36
600? did you mean layoutViewportHeight + topContro
bokan
2016/04/05 17:11:40
Done.
|
| + webView->updateAllLifecyclePhases(); |
| + |
| + // 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. |
| + int previousRootOffset = expectedVisualOffset + expectedLayoutOffset; |
|
majidvp
2016/04/01 17:09:36
You can use expectedRootOffset which should be def
bokan
2016/04/05 17:11:40
Done.
|
| + ASSERT_EQ(expectedVisualOffset, visualViewport().location().y()); |
| + ASSERT_EQ(expectedLayoutOffset, |
| + view->layoutViewportScrollableArea()->scrollPosition().y()); |
| + ASSERT_EQ(previousRootOffset, 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, 100)); |
|
majidvp
2016/04/01 17:09:36
100 is the same as topControlsHeight which may be
bokan
2016/04/05 17:11:40
Changed to 80.
|
| + |
| + visualViewport().clampToBoundaries(); |
| + view->setScrollPosition(view->scrollPosition(), ProgrammaticScroll); |
|
majidvp
2016/04/01 17:09:36
Why are these clamps required?
bokan
2016/04/05 17:11:40
If we don't run the anchoring logic, the viewport
|
| + |
| + ASSERT_EQ(100.f, webView->topControls().contentOffset()); |
| + EXPECT_EQ(previousRootOffset, rootViewport->scrollPosition().y()); |
| + |
| + webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollEnd)); |
| + } |
| +} |
| + |
| } // namespace blink |