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

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

Issue 2499853002: Fixed clip resize for document.rootScroller with inertTopControls (Closed)
Patch Set: Fixed issues + Rebase Created 4 years, 1 month 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/RootScrollerTest.cpp
diff --git a/third_party/WebKit/Source/web/tests/RootScrollerTest.cpp b/third_party/WebKit/Source/web/tests/RootScrollerTest.cpp
index f510c5002ab999a9107adc0477379b293c0adc38..35daa9441fdd51ff6ec77887e8df6d8aeb8d8711 100644
--- a/third_party/WebKit/Source/web/tests/RootScrollerTest.cpp
+++ b/third_party/WebKit/Source/web/tests/RootScrollerTest.cpp
@@ -9,10 +9,12 @@
#include "core/html/HTMLFrameOwnerElement.h"
#include "core/layout/LayoutBox.h"
#include "core/layout/api/LayoutViewItem.h"
+#include "core/layout/compositing/CompositedLayerMapping.h"
#include "core/layout/compositing/PaintLayerCompositor.h"
#include "core/page/Page.h"
#include "core/page/scrolling/RootScrollerController.h"
#include "core/page/scrolling/TopDocumentRootScrollerController.h"
+#include "core/paint/PaintLayer.h"
#include "core/paint/PaintLayerScrollableArea.h"
#include "platform/testing/URLTestHelpers.h"
#include "platform/testing/UnitTestHelpers.h"
@@ -89,8 +91,12 @@ class RootScrollerTest : public ::testing::Test {
}
void executeScript(const WebString& code) {
- mainWebFrame()->executeScript(WebScriptSource(code));
- mainWebFrame()->view()->updateAllLifecyclePhases();
+ executeScript(code, *mainWebFrame());
+ }
+
+ void executeScript(const WebString& code, WebLocalFrame& frame) {
+ frame.executeScript(WebScriptSource(code));
+ frame.view()->updateAllLifecyclePhases();
runPendingTasks();
}
@@ -879,6 +885,126 @@ TEST_F(RootScrollerTest, RemoveClippingOnCompositorLayers) {
}
}
+// Tests that the clipping layer is resized on the root scroller element even
+// if the layout height doesn't change.
+TEST_F(RootScrollerTest, BrowserControlsResizeClippingLayer) {
+ bool oldInertTopControls = RuntimeEnabledFeatures::inertTopControlsEnabled();
+ RuntimeEnabledFeatures::setInertTopControlsEnabled(true);
+
+ initialize("root-scroller.html");
+ Element* container = mainFrame()->document()->getElementById("container");
+
+ {
+ NonThrowableExceptionState exceptionState;
+ mainFrame()->document()->setRootScroller(container, exceptionState);
+
+ mainFrameView()->updateAllLifecyclePhases();
+ ASSERT_EQ(toLayoutBox(container->layoutObject())->clientHeight(), 400);
+
+ GraphicsLayer* clipLayer = toLayoutBox(container->layoutObject())
+ ->layer()
+ ->compositedLayerMapping()
+ ->scrollingLayer();
+ ASSERT_EQ(clipLayer->size().height(), 400);
+ EXPECT_TRUE(toLayoutBox(container->layoutObject())
+ ->layer()
+ ->isGlobalRootScroller());
+ }
+
+ {
+ webViewImpl()->handleInputEvent(
+ generateTouchGestureEvent(WebInputEvent::GestureScrollBegin));
+
+ // Scrolling over the #container DIV should cause the browser controls to
+ // hide.
+ EXPECT_FLOAT_EQ(1, browserControls().shownRatio());
+ webViewImpl()->handleInputEvent(generateTouchGestureEvent(
+ WebInputEvent::GestureScrollUpdate, 0, -browserControls().height()));
+ EXPECT_FLOAT_EQ(0, browserControls().shownRatio());
+
+ webViewImpl()->handleInputEvent(
+ generateTouchGestureEvent(WebInputEvent::GestureScrollEnd));
+
+ webViewImpl()->resizeWithBrowserControls(IntSize(400, 450), 50, false);
+ mainFrameView()->updateAllLifecyclePhases();
chrishtr 2016/11/18 00:37:09 Add a check before this line that the root scrolle
bokan 2016/11/18 22:30:35 Done.
+
+ // Since inert top controls are enabled, the container should not have
+ // resized, however, the clip layer should.
+ EXPECT_EQ(toLayoutBox(container->layoutObject())->clientHeight(), 400);
+ GraphicsLayer* clipLayer = toLayoutBox(container->layoutObject())
+ ->layer()
+ ->compositedLayerMapping()
+ ->scrollingLayer();
+ EXPECT_EQ(clipLayer->size().height(), 450);
+ }
+
+ RuntimeEnabledFeatures::setInertTopControlsEnabled(oldInertTopControls);
+}
+
+// Tests that the clipping layer is resized on the root scroller element when
+// it's an iframe and even if the layout height doesn't change.
+TEST_F(RootScrollerTest, BrowserControlsResizeClippingLayerIFrame) {
+ bool oldInertTopControls = RuntimeEnabledFeatures::inertTopControlsEnabled();
+ RuntimeEnabledFeatures::setInertTopControlsEnabled(true);
+
+ initialize("root-scroller-iframe.html");
+
+ Element* iframe = mainFrame()->document()->getElementById("iframe");
+ LocalFrame* childFrame =
+ toLocalFrame(toHTMLFrameOwnerElement(iframe)->contentFrame());
+
+ PaintLayerCompositor* childPLC =
+ childFrame->view()->layoutViewItem().compositor();
+
+ // Give the iframe itself scrollable content and make it the root scroller.
+ {
+ NonThrowableExceptionState nonThrow;
+ mainFrame()->document()->setRootScroller(iframe, nonThrow);
+
+ WebLocalFrame* childWebFrame =
+ mainWebFrame()->firstChild()->toWebLocalFrame();
+ executeScript(
+ "document.getElementById('container').style.width = '300%';"
+ "document.getElementById('container').style.height = '300%';",
+ *childWebFrame);
+
+ mainFrameView()->updateAllLifecyclePhases();
+
+ // Some sanity checks to make sure the test is setup correctly.
+ ASSERT_EQ(childFrame->view()->visibleContentSize().height(), 400);
+ ASSERT_EQ(childPLC->containerLayer()->size().height(), 400);
+ ASSERT_EQ(childPLC->rootGraphicsLayer()->size().height(), 400);
+ ASSERT_TRUE(childFrame->view()->layer()->isGlobalRootScroller());
+ }
+
+ {
+ webViewImpl()->handleInputEvent(
+ generateTouchGestureEvent(WebInputEvent::GestureScrollBegin));
+
+ // Scrolling over the #container DIV should cause the browser controls to
+ // hide.
+ EXPECT_FLOAT_EQ(1, browserControls().shownRatio());
+ webViewImpl()->handleInputEvent(generateTouchGestureEvent(
+ WebInputEvent::GestureScrollUpdate, 0, -browserControls().height()));
+ EXPECT_FLOAT_EQ(0, browserControls().shownRatio());
+
+ webViewImpl()->handleInputEvent(
+ generateTouchGestureEvent(WebInputEvent::GestureScrollEnd));
+
+ webViewImpl()->resizeWithBrowserControls(IntSize(400, 450), 50, false);
+ mainFrameView()->updateAllLifecyclePhases();
+
+ // Since inert top controls are enabled, the iframe element should not have
+ // resized, however, its clip layer should resize to reveal content as the
+ // browser controls hide.
+ EXPECT_EQ(childFrame->view()->visibleContentSize().height(), 400);
+ EXPECT_EQ(childPLC->containerLayer()->size().height(), 450);
+ EXPECT_EQ(childPLC->rootGraphicsLayer()->size().height(), 450);
+ }
+
+ RuntimeEnabledFeatures::setInertTopControlsEnabled(oldInertTopControls);
+}
+
// Tests that removing the root scroller element from the DOM resets the
// effective root scroller without waiting for any lifecycle events.
TEST_F(RootScrollerTest, RemoveRootScrollerFromDom) {

Powered by Google App Engine
This is Rietveld 408576698