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

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

Issue 1573283002: Don't change layout size due to top control show/hide (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 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 c81cd278c74753bc76b7cdc33eafa6cd23ffdcee..26e5274aeb764d6a484c24986a6e304f7fac61e1 100644
--- a/third_party/WebKit/Source/web/tests/TopControlsTest.cpp
+++ b/third_party/WebKit/Source/web/tests/TopControlsTest.cpp
@@ -29,6 +29,7 @@
*/
#include "core/frame/TopControls.h"
+#include "core/dom/ClientRect.h"
#include "core/frame/FrameHost.h"
#include "core/frame/FrameView.h"
#include "core/frame/LocalFrame.h"
@@ -37,6 +38,7 @@
#include "platform/testing/URLTestHelpers.h"
#include "public/platform/Platform.h"
#include "public/platform/WebUnitTestSupport.h"
+#include "public/web/WebElement.h"
#include "public/web/WebSettings.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -57,6 +59,8 @@ public:
registerMockedHttpURLLoad("overflow-scrolling.html");
registerMockedHttpURLLoad("iframe-scrolling.html");
registerMockedHttpURLLoad("iframe-scrolling-inner.html");
+ registerMockedHttpURLLoad("percent-height.html");
+ registerMockedHttpURLLoad("vh-height.html");
}
~TopControlsTest() override
@@ -112,6 +116,13 @@ public:
webViewImpl()->handleInputEvent(generateEvent(WebInputEvent::GestureScrollEnd));
}
+ PassRefPtrWillBeRawPtr<Element> getElementById(const WebString& id)
+ {
+ return static_cast<PassRefPtrWillBeRawPtr<Element>>(
+ webViewImpl()->mainFrame()->document().getElementById(id));
+ }
+
+
WebViewImpl* webViewImpl() const { return m_helper.webViewImpl(); }
LocalFrame* frame() const { return m_helper.webViewImpl()->mainFrameImpl()->frame(); }
VisualViewport& visualViewport() const { return m_helper.webViewImpl()->page()->frameHost().visualViewport(); }
@@ -544,4 +555,85 @@ TEST_F(TopControlsTest, MAYBE(StateConstraints))
EXPECT_POINT_EQ(IntPoint(0, 90), frame()->view()->scrollPosition());
}
+// Ensure that top controls do not affect the layout by showing and hiding
+// except for position: fixed elements.
+TEST_F(TopControlsTest, MAYBE(DontAffectLayoutHeight))
+{
+ // Initialize with the top controls showing.
+ WebViewImpl* webView = initialize("percent-height.html");
+ webView->setTopControlsHeight(100.f, true);
+ webView->updateTopControlsState(WebTopControlsBoth, WebTopControlsShown, false);
+ webView->topControls().setShownRatio(1);
+ webView->resize(WebSize(400, 300));
+ webView->updateAllLifecyclePhases();
+ EXPECT_FLOAT_EQ(100.f, webView->topControls().contentOffset());
+
+ // When the top controls are showing, there's 300px for the layout height so 50%
+ // should result in both the position:fixed and position: absolute divs having
+ // 150px of height.
+ RefPtrWillBeRawPtr<Element> absPos = getElementById(WebString::fromUTF8("abs"));
+ RefPtrWillBeRawPtr<Element> fixedPos = getElementById(WebString::fromUTF8("fixed"));
+ EXPECT_FLOAT_EQ(150.f, absPos->getBoundingClientRect()->height());
+ EXPECT_FLOAT_EQ(150.f, fixedPos->getBoundingClientRect()->height());
+
+ // The layout size on the FrameView should not include the top controls.
+ EXPECT_EQ(300, frame()->view()->layoutSize(IncludeScrollbars).height());
+
+ // Hide the top controls.
+ verticalScroll(-100.f);
+ EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset());
+ EXPECT_POINT_EQ(IntPoint(0, 0), frame()->view()->scrollPosition());
+ webView->setTopControlsHeight(100.f, false);
+ webView->resize(WebSize(400, 400));
+ webView->updateAllLifecyclePhases();
+
+ // Hiding the top controls shouldn't change the height of the initial
+ // containing block for non-position: fixed. Position: fixed however should
+ // use the entire height of the viewport however.
+ EXPECT_FLOAT_EQ(150.f, absPos->getBoundingClientRect()->height());
+ EXPECT_FLOAT_EQ(200.f, fixedPos->getBoundingClientRect()->height());
+
+ // The layout size should not change as a result of top controls hiding.
+ EXPECT_EQ(300, frame()->view()->layoutSize(IncludeScrollbars).height());
+}
+
+// Ensure that top controls do not affect vh units.
+TEST_F(TopControlsTest, MAYBE(DontAffectVHUnits))
+{
+ // Initialize with the top controls showing.
+ WebViewImpl* webView = initialize("vh-height.html");
+ webView->setTopControlsHeight(100.f, true);
+ webView->updateTopControlsState(WebTopControlsBoth, WebTopControlsShown, false);
+ webView->topControls().setShownRatio(1);
+ webView->resize(WebSize(400, 300));
+ webView->updateAllLifecyclePhases();
+ EXPECT_FLOAT_EQ(100.f, webView->topControls().contentOffset());
+
+ // 'vh' units should be based on the viewport when the top controls are
+ // hidden.
+ RefPtrWillBeRawPtr<Element> absPos = getElementById(WebString::fromUTF8("abs"));
+ RefPtrWillBeRawPtr<Element> fixedPos = getElementById(WebString::fromUTF8("fixed"));
+ EXPECT_FLOAT_EQ(200.f, absPos->getBoundingClientRect()->height());
+ EXPECT_FLOAT_EQ(200.f, fixedPos->getBoundingClientRect()->height());
+
+ // The size used for viewport units should not be reduced by the top controls.
+ EXPECT_EQ(400, frame()->view()->viewportSizeForViewportUnits().height());
+
+ // Hide the top controls.
+ verticalScroll(-100.f);
+ EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset());
+ EXPECT_POINT_EQ(IntPoint(0, 0), frame()->view()->scrollPosition());
+ webView->setTopControlsHeight(100.f, false);
+ webView->resize(WebSize(400, 400));
+ webView->updateAllLifecyclePhases();
+
+ // vh units should be static with respect to the top controls so neighter
+ // <div> should change size are a result of the top controls hiding.
+ EXPECT_FLOAT_EQ(200.f, absPos->getBoundingClientRect()->height());
+ EXPECT_FLOAT_EQ(200.f, fixedPos->getBoundingClientRect()->height());
+
+ // The viewport size used for vh units should not change as a result of top controls hiding.
+ EXPECT_EQ(400, frame()->view()->viewportSizeForViewportUnits().height());
+}
+
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698