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

Side by Side Diff: third_party/WebKit/Source/web/tests/RootScrollerTest.cpp

Issue 2499853002: Fixed clip resize for document.rootScroller with inertTopControls (Closed)
Patch Set: Fixed typo Created 4 years 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/dom/ClientRect.h" 5 #include "core/dom/ClientRect.h"
6 #include "core/frame/BrowserControls.h" 6 #include "core/frame/BrowserControls.h"
7 #include "core/frame/FrameHost.h" 7 #include "core/frame/FrameHost.h"
8 #include "core/frame/FrameView.h" 8 #include "core/frame/FrameView.h"
9 #include "core/frame/RootFrameViewport.h" 9 #include "core/frame/RootFrameViewport.h"
10 #include "core/frame/VisualViewport.h" 10 #include "core/frame/VisualViewport.h"
11 #include "core/html/HTMLFrameOwnerElement.h" 11 #include "core/html/HTMLFrameOwnerElement.h"
12 #include "core/layout/LayoutBox.h" 12 #include "core/layout/LayoutBox.h"
13 #include "core/layout/api/LayoutViewItem.h" 13 #include "core/layout/api/LayoutViewItem.h"
14 #include "core/layout/compositing/CompositedLayerMapping.h"
14 #include "core/layout/compositing/PaintLayerCompositor.h" 15 #include "core/layout/compositing/PaintLayerCompositor.h"
15 #include "core/page/Page.h" 16 #include "core/page/Page.h"
16 #include "core/page/scrolling/RootScrollerController.h" 17 #include "core/page/scrolling/RootScrollerController.h"
17 #include "core/page/scrolling/TopDocumentRootScrollerController.h" 18 #include "core/page/scrolling/TopDocumentRootScrollerController.h"
19 #include "core/paint/PaintLayer.h"
18 #include "core/paint/PaintLayerScrollableArea.h" 20 #include "core/paint/PaintLayerScrollableArea.h"
19 #include "platform/testing/URLTestHelpers.h" 21 #include "platform/testing/URLTestHelpers.h"
20 #include "platform/testing/UnitTestHelpers.h" 22 #include "platform/testing/UnitTestHelpers.h"
21 #include "public/platform/Platform.h" 23 #include "public/platform/Platform.h"
22 #include "public/platform/WebURLLoaderMockFactory.h" 24 #include "public/platform/WebURLLoaderMockFactory.h"
23 #include "public/web/WebCache.h" 25 #include "public/web/WebCache.h"
24 #include "public/web/WebConsoleMessage.h" 26 #include "public/web/WebConsoleMessage.h"
25 #include "public/web/WebRemoteFrame.h" 27 #include "public/web/WebRemoteFrame.h"
26 #include "public/web/WebScriptSource.h" 28 #include "public/web/WebScriptSource.h"
27 #include "public/web/WebSettings.h" 29 #include "public/web/WebSettings.h"
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 } 88 }
87 89
88 void registerMockedHttpURLLoad(const std::string& fileName) { 90 void registerMockedHttpURLLoad(const std::string& fileName) {
89 URLTestHelpers::registerMockedURLFromBaseURL( 91 URLTestHelpers::registerMockedURLFromBaseURL(
90 WebString::fromUTF8(m_baseURL.c_str()), 92 WebString::fromUTF8(m_baseURL.c_str()),
91 WebString::fromUTF8(fileName.c_str())); 93 WebString::fromUTF8(fileName.c_str()));
92 } 94 }
93 95
94 void executeScript(const WebString& code) { 96 void executeScript(const WebString& code) {
95 executeScript(code, *mainWebFrame()); 97 executeScript(code, *mainWebFrame());
96 mainWebFrame()->view()->updateAllLifecyclePhases();
97 } 98 }
98 99
99 void executeScript(const WebString& code, WebLocalFrame& frame) { 100 void executeScript(const WebString& code, WebLocalFrame& frame) {
100 frame.executeScript(WebScriptSource(code)); 101 frame.executeScript(WebScriptSource(code));
101 frame.view()->updateAllLifecyclePhases(); 102 frame.view()->updateAllLifecyclePhases();
102 runPendingTasks(); 103 runPendingTasks();
103 } 104 }
104 105
105 WebViewImpl* webViewImpl() const { return m_helper.webView(); } 106 WebViewImpl* webViewImpl() const { return m_helper.webView(); }
106 107
(...skipping 773 matching lines...) Expand 10 before | Expand all | Expand 10 after
880 881
881 EXPECT_FALSE( 882 EXPECT_FALSE(
882 childCompositor->rootContentLayer()->platformLayer()->masksToBounds()); 883 childCompositor->rootContentLayer()->platformLayer()->masksToBounds());
883 EXPECT_FALSE( 884 EXPECT_FALSE(
884 childCompositor->rootGraphicsLayer()->platformLayer()->masksToBounds()); 885 childCompositor->rootGraphicsLayer()->platformLayer()->masksToBounds());
885 EXPECT_FALSE( 886 EXPECT_FALSE(
886 childCompositor->containerLayer()->platformLayer()->masksToBounds()); 887 childCompositor->containerLayer()->platformLayer()->masksToBounds());
887 } 888 }
888 } 889 }
889 890
891 // Tests that the clipping layer is resized on the root scroller element even
892 // if the layout height doesn't change.
893 TEST_F(RootScrollerTest, BrowserControlsResizeClippingLayer) {
894 bool oldInertTopControls = RuntimeEnabledFeatures::inertTopControlsEnabled();
895 RuntimeEnabledFeatures::setInertTopControlsEnabled(true);
896
897 initialize("root-scroller.html");
898 Element* container = mainFrame()->document()->getElementById("container");
899
900 {
901 NonThrowableExceptionState exceptionState;
902 mainFrame()->document()->setRootScroller(container, exceptionState);
903
904 mainFrameView()->updateAllLifecyclePhases();
905 ASSERT_EQ(toLayoutBox(container->layoutObject())->clientHeight(), 400);
906
907 GraphicsLayer* clipLayer = toLayoutBox(container->layoutObject())
908 ->layer()
909 ->compositedLayerMapping()
910 ->scrollingLayer();
911 ASSERT_EQ(clipLayer->size().height(), 400);
912 }
913
914 {
915 webViewImpl()->handleInputEvent(
916 generateTouchGestureEvent(WebInputEvent::GestureScrollBegin));
917
918 // Scrolling over the #container DIV should cause the browser controls to
919 // hide.
920 EXPECT_FLOAT_EQ(1, browserControls().shownRatio());
921 webViewImpl()->handleInputEvent(generateTouchGestureEvent(
922 WebInputEvent::GestureScrollUpdate, 0, -browserControls().height()));
923 EXPECT_FLOAT_EQ(0, browserControls().shownRatio());
924
925 webViewImpl()->handleInputEvent(
926 generateTouchGestureEvent(WebInputEvent::GestureScrollEnd));
927
928 webViewImpl()->resizeWithBrowserControls(IntSize(400, 450), 50, false);
929
930 EXPECT_FALSE(container->layoutObject()->needsLayout());
931
932 mainFrameView()->updateAllLifecyclePhases();
933
934 // Since inert top controls are enabled, the container should not have
935 // resized, however, the clip layer should.
936 EXPECT_EQ(toLayoutBox(container->layoutObject())->clientHeight(), 400);
937 GraphicsLayer* clipLayer = toLayoutBox(container->layoutObject())
938 ->layer()
939 ->compositedLayerMapping()
940 ->scrollingLayer();
941 EXPECT_EQ(clipLayer->size().height(), 450);
942 }
943
944 RuntimeEnabledFeatures::setInertTopControlsEnabled(oldInertTopControls);
945 }
946
947 // Tests that the clipping layer is resized on the root scroller element when
948 // it's an iframe and even if the layout height doesn't change.
949 TEST_F(RootScrollerTest, BrowserControlsResizeClippingLayerIFrame) {
950 bool oldInertTopControls = RuntimeEnabledFeatures::inertTopControlsEnabled();
951 RuntimeEnabledFeatures::setInertTopControlsEnabled(true);
952
953 initialize("root-scroller-iframe.html");
954
955 Element* iframe = mainFrame()->document()->getElementById("iframe");
956 LocalFrame* childFrame =
957 toLocalFrame(toHTMLFrameOwnerElement(iframe)->contentFrame());
958
959 PaintLayerCompositor* childPLC =
960 childFrame->view()->layoutViewItem().compositor();
961
962 // Give the iframe itself scrollable content and make it the root scroller.
963 {
964 NonThrowableExceptionState nonThrow;
965 mainFrame()->document()->setRootScroller(iframe, nonThrow);
966
967 WebLocalFrame* childWebFrame =
968 mainWebFrame()->firstChild()->toWebLocalFrame();
969 executeScript(
970 "document.getElementById('container').style.width = '300%';"
971 "document.getElementById('container').style.height = '300%';",
972 *childWebFrame);
973
974 mainFrameView()->updateAllLifecyclePhases();
975
976 // Some sanity checks to make sure the test is setup correctly.
977 ASSERT_EQ(childFrame->view()->visibleContentSize().height(), 400);
978 ASSERT_EQ(childPLC->containerLayer()->size().height(), 400);
979 ASSERT_EQ(childPLC->rootGraphicsLayer()->size().height(), 400);
980 }
981
982 {
983 webViewImpl()->handleInputEvent(
984 generateTouchGestureEvent(WebInputEvent::GestureScrollBegin));
985
986 // Scrolling over the #container DIV should cause the browser controls to
987 // hide.
988 EXPECT_FLOAT_EQ(1, browserControls().shownRatio());
989 webViewImpl()->handleInputEvent(generateTouchGestureEvent(
990 WebInputEvent::GestureScrollUpdate, 0, -browserControls().height()));
991 EXPECT_FLOAT_EQ(0, browserControls().shownRatio());
992
993 webViewImpl()->handleInputEvent(
994 generateTouchGestureEvent(WebInputEvent::GestureScrollEnd));
995
996 webViewImpl()->resizeWithBrowserControls(IntSize(400, 450), 50, false);
997
998 EXPECT_FALSE(childFrame->view()->needsLayout());
999
1000 mainFrameView()->updateAllLifecyclePhases();
1001
1002 // Since inert top controls are enabled, the iframe element should not have
1003 // resized, however, its clip layer should resize to reveal content as the
1004 // browser controls hide.
1005 EXPECT_EQ(childFrame->view()->visibleContentSize().height(), 400);
1006 EXPECT_EQ(childPLC->containerLayer()->size().height(), 450);
1007 EXPECT_EQ(childPLC->rootGraphicsLayer()->size().height(), 450);
1008 }
1009
1010 RuntimeEnabledFeatures::setInertTopControlsEnabled(oldInertTopControls);
1011 }
1012
890 // Tests that removing the root scroller element from the DOM resets the 1013 // Tests that removing the root scroller element from the DOM resets the
891 // effective root scroller without waiting for any lifecycle events. 1014 // effective root scroller without waiting for any lifecycle events.
892 TEST_F(RootScrollerTest, RemoveRootScrollerFromDom) { 1015 TEST_F(RootScrollerTest, RemoveRootScrollerFromDom) {
893 initialize("root-scroller-iframe.html"); 1016 initialize("root-scroller-iframe.html");
894 1017
895 { 1018 {
896 HTMLFrameOwnerElement* iframe = toHTMLFrameOwnerElement( 1019 HTMLFrameOwnerElement* iframe = toHTMLFrameOwnerElement(
897 mainFrame()->document()->getElementById("iframe")); 1020 mainFrame()->document()->getElementById("iframe"));
898 Element* innerContainer = 1021 Element* innerContainer =
899 iframe->contentDocument()->getElementById("container"); 1022 iframe->contentDocument()->getElementById("container");
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
1041 1164
1042 // The visual viewport should remain fully filled by the target. 1165 // The visual viewport should remain fully filled by the target.
1043 ClientRect* rect = target->getBoundingClientRect(); 1166 ClientRect* rect = target->getBoundingClientRect();
1044 EXPECT_EQ(rect->left(), visualViewport().scrollOffset().width()); 1167 EXPECT_EQ(rect->left(), visualViewport().scrollOffset().width());
1045 EXPECT_EQ(rect->top(), visualViewport().scrollOffset().height()); 1168 EXPECT_EQ(rect->top(), visualViewport().scrollOffset().height());
1046 } 1169 }
1047 1170
1048 } // namespace 1171 } // namespace
1049 1172
1050 } // namespace blink 1173 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/scroll/ScrollableArea.h ('k') | third_party/WebKit/Source/web/tests/VisualViewportTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698