Chromium Code Reviews| Index: third_party/WebKit/Source/web/tests/VisualViewportTest.cpp |
| diff --git a/third_party/WebKit/Source/web/tests/VisualViewportTest.cpp b/third_party/WebKit/Source/web/tests/VisualViewportTest.cpp |
| index b400edc6827a10b9c60692b6e61f5a51fa869246..0819a7969cba60da05271480cb2d021699d99d93 100644 |
| --- a/third_party/WebKit/Source/web/tests/VisualViewportTest.cpp |
| +++ b/third_party/WebKit/Source/web/tests/VisualViewportTest.cpp |
| @@ -1174,16 +1174,15 @@ TEST_P(ParameterizedVisualViewportTest, ScrollIntoViewFractionalOffset) |
| // crbug.com/437620 |
| TEST_F(VisualViewportTest, TestResizeDoesntChangeScrollOffset) |
| { |
| + RuntimeEnabledFeatures::setInertTopControlsEnabled(false); |
| initializeWithAndroidSettings(); |
| - webViewImpl()->resize(IntSize(980, 650)); |
| + webViewImpl()->resize(IntSize(980, 650), 20, false); |
| navigateTo("about:blank"); |
| VisualViewport& visualViewport = frame()->page()->frameHost().visualViewport(); |
| FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); |
| - webViewImpl()->setTopControlsHeight(20, false); |
| - |
| // Outer viewport isn't scrollable |
| EXPECT_SIZE_EQ(IntSize(980, 650), frameView.visibleContentRect().size()); |
| @@ -1195,8 +1194,7 @@ TEST_F(VisualViewportTest, TestResizeDoesntChangeScrollOffset) |
| EXPECT_EQ(20, frameView.layoutViewportScrollableArea()->scrollPosition().y()); |
| - webViewImpl()->setTopControlsHeight(20, true); |
| - webViewImpl()->resize(WebSize(980, 630)); |
| + webViewImpl()->resize(WebSize(980, 630), 20, true); |
| EXPECT_EQ(0, frameView.layoutViewportScrollableArea()->scrollPosition().y()); |
| EXPECT_EQ(60, visualViewport.location().y()); |
| @@ -1222,7 +1220,7 @@ TEST_F(VisualViewportTest, TestTopControlsAdjustment) |
| VisualViewport& visualViewport = frame()->page()->frameHost().visualViewport(); |
| FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); |
| - webViewImpl()->setTopControlsHeight(20, false); |
| + webViewImpl()->resize(webViewImpl()->size(), 20, false); |
| visualViewport.setScale(1); |
| EXPECT_SIZE_EQ(IntSize(500, 450), visualViewport.visibleRect().size()); |
| @@ -1248,9 +1246,9 @@ TEST_F(VisualViewportTest, TestTopControlsAdjustment) |
| webViewImpl()->applyViewportDeltas(WebFloatSize(), WebFloatSize(), WebFloatSize(), 1, -10.5f / 20); |
| EXPECT_FLOAT_SIZE_EQ(FloatSize(500, 440.5f), visualViewport.visibleRect().size()); |
| - // maximumScrollPosition floors the final values. |
| + // maximumScrollPosition |ceil|s the top controls adjustment. |
| visualViewport.move(FloatPoint(10000, 10000)); |
| - EXPECT_FLOAT_POINT_EQ(FloatPoint(500, 881 - 440.5f), visualViewport.location()); |
| + EXPECT_FLOAT_POINT_EQ(FloatPoint(500, 881 - 441), visualViewport.location()); |
| // The outer viewport (FrameView) should be affected as well. |
| frameView.scrollBy(IntSize(10000, 10000), UserScroll); |
| @@ -1270,7 +1268,7 @@ TEST_F(VisualViewportTest, TestTopControlsAdjustmentWithScale) |
| VisualViewport& visualViewport = frame()->page()->frameHost().visualViewport(); |
| FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); |
| - webViewImpl()->setTopControlsHeight(20, false); |
| + webViewImpl()->resize(webViewImpl()->size(), 20, false); |
| visualViewport.setScale(2); |
| EXPECT_SIZE_EQ(IntSize(250, 225), visualViewport.visibleRect().size()); |
| @@ -1322,10 +1320,25 @@ TEST_F(VisualViewportTest, TestTopControlsAdjustmentWithScale) |
| } |
| +// Tests that a scroll all the way to the bottom of the page, while hiding the |
| +// top controls doesn't cause a clamp in the viewport scroll offset when the |
| +// top controls initiated resize occurs. |
| TEST_F(VisualViewportTest, TestTopControlsAdjustmentAndResize) |
|
bokan
2016/04/05 17:11:41
I think this test was accidentally testing somethi
|
| { |
| + int topControlsHeight = 20; |
| + int visualViewportHeight = 450; |
| + int layoutViewportHeight = 900; |
| + float pageScale = 2; |
| + float minPageScale = 0.5; |
| + |
| initializeWithAndroidSettings(); |
| - webViewImpl()->resize(IntSize(500, 450)); |
| + |
| + // Initialize with top controls showing and shrinking the Blink size. |
| + webViewImpl()->resize( |
| + IntSize(500, visualViewportHeight - topControlsHeight), |
| + 20, |
| + true); |
| + webViewImpl()->topControls().setShownRatio(1); |
| registerMockedHttpURLLoad("content-width-1000.html"); |
| navigateTo(m_baseURL + "content-width-1000.html"); |
| @@ -1333,35 +1346,137 @@ TEST_F(VisualViewportTest, TestTopControlsAdjustmentAndResize) |
| VisualViewport& visualViewport = frame()->page()->frameHost().visualViewport(); |
| FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); |
| - visualViewport.setScale(2); |
| - EXPECT_SIZE_EQ(IntSize(250, 225), visualViewport.visibleRect().size()); |
| - EXPECT_SIZE_EQ(IntSize(1000, 900), frameView.frameRect().size()); |
| + visualViewport.setScale(pageScale); |
| + EXPECT_SIZE_EQ( |
| + IntSize(250, (visualViewportHeight - topControlsHeight) / pageScale), |
| + visualViewport.visibleRect().size()); |
| + EXPECT_SIZE_EQ( |
| + IntSize(1000, layoutViewportHeight - topControlsHeight / minPageScale), |
| + frameView.frameRect().size()); |
| + EXPECT_SIZE_EQ( |
| + IntSize(500, visualViewportHeight - topControlsHeight), |
| + visualViewport.size()); |
| + |
| + // Scroll all the way to the bottom, hiding the top controls in the process. |
| + visualViewport.move(FloatPoint(10000, 10000)); |
| + frameView.scrollBy(IntSize(10000, 10000), UserScroll); |
| + webViewImpl()->topControls().setShownRatio(0); |
| - webViewImpl()->setTopControlsHeight(20, false); |
| + EXPECT_SIZE_EQ( |
| + IntSize(250, visualViewportHeight / pageScale), |
| + visualViewport.visibleRect().size()); |
| - webViewImpl()->applyViewportDeltas(WebFloatSize(), WebFloatSize(), WebFloatSize(), 1, 1); |
| - EXPECT_SIZE_EQ(IntSize(500, 450), visualViewport.size()); |
| - EXPECT_SIZE_EQ(IntSize(250, 215), visualViewport.visibleRect().size()); |
| + IntPoint frameViewExpected = |
| + expectedMaxFrameViewScrollOffset(visualViewport, frameView); |
| + FloatPoint visualViewportExpected = |
| + FloatPoint( |
| + 750, |
| + layoutViewportHeight - visualViewportHeight / pageScale); |
| - // Scroll all the way to the bottom. |
| - visualViewport.move(FloatPoint(10000, 10000)); |
| - frameView.scrollBy(IntSize(10000, 10000), UserScroll); |
| - IntPoint frameViewExpected = expectedMaxFrameViewScrollOffset(visualViewport, frameView); |
| - FloatPoint visualViewportExpected = FloatPoint(750, 860 - 215); |
| EXPECT_POINT_EQ(visualViewportExpected, visualViewport.location()); |
| EXPECT_POINT_EQ(frameViewExpected, frameView.scrollPosition()); |
| - // Resize the widget to match the top controls adjustment. Ensure that scroll |
| - // offsets don't get clamped in the the process. |
| - webViewImpl()->setTopControlsHeight(20, true); |
| - webViewImpl()->resize(WebSize(500, 430)); |
| + FloatPoint totalExpected = visualViewportExpected + frameViewExpected; |
| - EXPECT_SIZE_EQ(IntSize(500, 430), visualViewport.size()); |
| - EXPECT_SIZE_EQ(IntSize(250, 215), visualViewport.visibleRect().size()); |
| - EXPECT_SIZE_EQ(IntSize(1000, 860), frameView.frameRect().size()); |
| + // Resize the widget to match the top controls adjustment. Ensure that the |
| + // total offset (i.e. what the user sees) doesn't change because of clamping |
| + // the offsets to valid values. |
| + webViewImpl()->resize(WebSize(500, visualViewportHeight), 20, false); |
| + |
| + EXPECT_SIZE_EQ(IntSize(500, visualViewportHeight), visualViewport.size()); |
| + EXPECT_SIZE_EQ( |
| + IntSize(250, visualViewportHeight / pageScale), |
| + visualViewport.visibleRect().size()); |
| + EXPECT_SIZE_EQ( |
| + IntSize(1000, layoutViewportHeight), |
| + frameView.frameRect().size()); |
| + EXPECT_POINT_EQ( |
| + totalExpected, |
| + frameView.scrollPosition() + visualViewport.location()); |
| +} |
| + |
| +// Tests that a scroll all the way to the bottom while showing the top controls |
| +// doesn't cause a clamp to the viewport scroll offset when the top controls |
| +// initiated resize occurs. |
| +TEST_F(VisualViewportTest, TestTopControlsShrinkAdjustmentAndResize) |
| +{ |
| + int topControlsHeight = 20; |
| + int visualViewportHeight = 500; |
| + int layoutViewportHeight = 1000; |
| + int contentHeight = 2000; |
| + float pageScale = 2; |
| + float minPageScale = 0.5; |
| + |
| + initializeWithAndroidSettings(); |
| + |
| + // Initialize with top controls hidden and not shrinking the Blink size. |
| + webViewImpl()->resize( |
| + IntSize(500, visualViewportHeight), |
| + 20, |
| + false); |
| + webViewImpl()->topControls().setShownRatio(0); |
| + |
| + registerMockedHttpURLLoad("content-width-1000.html"); |
| + navigateTo(m_baseURL + "content-width-1000.html"); |
| + |
| + VisualViewport& visualViewport = frame()->page()->frameHost().visualViewport(); |
| + FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); |
| + |
| + visualViewport.setScale(pageScale); |
| + EXPECT_SIZE_EQ( |
| + IntSize(250, visualViewportHeight / pageScale), |
| + visualViewport.visibleRect().size()); |
| + EXPECT_SIZE_EQ( |
| + IntSize(1000, layoutViewportHeight), |
| + frameView.frameRect().size()); |
| + EXPECT_SIZE_EQ( |
| + IntSize(500, visualViewportHeight), |
| + visualViewport.size()); |
| + |
| + // Scroll all the way to the bottom, showing the the top controls in the |
| + // process. (This could happen via window.scrollTo during a scroll, for |
| + // example). |
| + webViewImpl()->topControls().setShownRatio(1); |
| + visualViewport.move(FloatPoint(10000, 10000)); |
| + frameView.scrollBy(IntSize(10000, 10000), UserScroll); |
| + |
| + EXPECT_SIZE_EQ( |
| + IntSize(250, (visualViewportHeight - topControlsHeight) / pageScale), |
| + visualViewport.visibleRect().size()); |
| + |
| + IntPoint frameViewExpected = IntPoint(0, |
| + contentHeight |
| + - (layoutViewportHeight - topControlsHeight / minPageScale)); |
| + FloatPoint visualViewportExpected = |
| + FloatPoint(750, |
| + (layoutViewportHeight - topControlsHeight / minPageScale |
| + - visualViewport.visibleRect().height())); |
| - EXPECT_POINT_EQ(frameViewExpected, frameView.scrollPosition()); |
| EXPECT_POINT_EQ(visualViewportExpected, visualViewport.location()); |
| + EXPECT_POINT_EQ(frameViewExpected, frameView.scrollPosition()); |
| + |
| + FloatPoint totalExpected = visualViewportExpected + frameViewExpected; |
| + |
| + // Resize the widget to match the top controls adjustment. Ensure that the |
| + // total offset (i.e. what the user sees) doesn't change because of clamping |
| + // the offsets to valid values. |
| + webViewImpl()->resize( |
| + WebSize(500, visualViewportHeight - topControlsHeight), |
| + 20, |
| + true); |
| + |
| + EXPECT_SIZE_EQ( |
| + IntSize(500, visualViewportHeight - topControlsHeight), |
| + visualViewport.size()); |
| + EXPECT_SIZE_EQ( |
| + IntSize(250, (visualViewportHeight - topControlsHeight) / pageScale), |
| + visualViewport.visibleRect().size()); |
| + EXPECT_SIZE_EQ( |
| + IntSize(1000, layoutViewportHeight - topControlsHeight / minPageScale), |
| + frameView.frameRect().size()); |
| + EXPECT_POINT_EQ( |
| + totalExpected, |
| + frameView.scrollPosition() + visualViewport.location()); |
| } |
| // Tests that a resize due to top controls hiding doesn't incorrectly clamp the |
| @@ -1369,10 +1484,9 @@ TEST_F(VisualViewportTest, TestTopControlsAdjustmentAndResize) |
| TEST_F(VisualViewportTest, TestTopControlHidingResizeDoesntClampMainFrame) |
| { |
| initializeWithAndroidSettings(); |
| - webViewImpl()->setTopControlsHeight(500, false); |
| + webViewImpl()->resize(webViewImpl()->size(), 500, false); |
| webViewImpl()->applyViewportDeltas(WebFloatSize(), WebFloatSize(), WebFloatSize(), 1, 1); |
| - webViewImpl()->setTopControlsHeight(500, true); |
| - webViewImpl()->resize(IntSize(1000, 1000)); |
| + webViewImpl()->resize(IntSize(1000, 1000), 500, true); |
| registerMockedHttpURLLoad("content-width-1000.html"); |
| navigateTo(m_baseURL + "content-width-1000.html"); |
| @@ -1386,8 +1500,7 @@ TEST_F(VisualViewportTest, TestTopControlHidingResizeDoesntClampMainFrame) |
| EXPECT_EQ(500, frameView.scrollPositionDouble().y()); |
| // Now send the resize, make sure the scroll offset doesn't change. |
| - webViewImpl()->setTopControlsHeight(500, false); |
| - webViewImpl()->resize(IntSize(1000, 1500)); |
| + webViewImpl()->resize(IntSize(1000, 1500), 500, false); |
| EXPECT_EQ(500, frameView.scrollPositionDouble().y()); |
| } |