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

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: +Test 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 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/frame/BrowserControls.h" 5 #include "core/frame/BrowserControls.h"
6 #include "core/frame/FrameHost.h" 6 #include "core/frame/FrameHost.h"
7 #include "core/frame/FrameView.h" 7 #include "core/frame/FrameView.h"
8 #include "core/frame/RootFrameViewport.h" 8 #include "core/frame/RootFrameViewport.h"
9 #include "core/html/HTMLFrameOwnerElement.h" 9 #include "core/html/HTMLFrameOwnerElement.h"
10 #include "core/layout/LayoutBox.h" 10 #include "core/layout/LayoutBox.h"
11 #include "core/layout/api/LayoutViewItem.h" 11 #include "core/layout/api/LayoutViewItem.h"
12 #include "core/layout/compositing/CompositedLayerMapping.h"
12 #include "core/layout/compositing/PaintLayerCompositor.h" 13 #include "core/layout/compositing/PaintLayerCompositor.h"
13 #include "core/page/Page.h" 14 #include "core/page/Page.h"
14 #include "core/page/scrolling/RootScrollerController.h" 15 #include "core/page/scrolling/RootScrollerController.h"
15 #include "core/page/scrolling/TopDocumentRootScrollerController.h" 16 #include "core/page/scrolling/TopDocumentRootScrollerController.h"
17 #include "core/paint/PaintLayer.h"
16 #include "core/paint/PaintLayerScrollableArea.h" 18 #include "core/paint/PaintLayerScrollableArea.h"
17 #include "platform/testing/URLTestHelpers.h" 19 #include "platform/testing/URLTestHelpers.h"
18 #include "platform/testing/UnitTestHelpers.h" 20 #include "platform/testing/UnitTestHelpers.h"
19 #include "public/platform/Platform.h" 21 #include "public/platform/Platform.h"
20 #include "public/platform/WebURLLoaderMockFactory.h" 22 #include "public/platform/WebURLLoaderMockFactory.h"
21 #include "public/web/WebCache.h" 23 #include "public/web/WebCache.h"
22 #include "public/web/WebConsoleMessage.h" 24 #include "public/web/WebConsoleMessage.h"
23 #include "public/web/WebRemoteFrame.h" 25 #include "public/web/WebRemoteFrame.h"
24 #include "public/web/WebScriptSource.h" 26 #include "public/web/WebScriptSource.h"
25 #include "public/web/WebSettings.h" 27 #include "public/web/WebSettings.h"
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 settings->setMainFrameResizesAreOrientationChanges(true); 84 settings->setMainFrameResizesAreOrientationChanges(true);
83 } 85 }
84 86
85 void registerMockedHttpURLLoad(const std::string& fileName) { 87 void registerMockedHttpURLLoad(const std::string& fileName) {
86 URLTestHelpers::registerMockedURLFromBaseURL( 88 URLTestHelpers::registerMockedURLFromBaseURL(
87 WebString::fromUTF8(m_baseURL.c_str()), 89 WebString::fromUTF8(m_baseURL.c_str()),
88 WebString::fromUTF8(fileName.c_str())); 90 WebString::fromUTF8(fileName.c_str()));
89 } 91 }
90 92
91 void executeScript(const WebString& code) { 93 void executeScript(const WebString& code) {
92 mainWebFrame()->executeScript(WebScriptSource(code)); 94 executeScript(code, *mainWebFrame());
93 mainWebFrame()->view()->updateAllLifecyclePhases(); 95 }
96
97 void executeScript(const WebString& code, WebLocalFrame& frame) {
98 frame.executeScript(WebScriptSource(code));
99 frame.view()->updateAllLifecyclePhases();
94 runPendingTasks(); 100 runPendingTasks();
95 } 101 }
96 102
97 WebViewImpl* webViewImpl() const { return m_helper.webView(); } 103 WebViewImpl* webViewImpl() const { return m_helper.webView(); }
98 104
99 FrameHost& frameHost() const { 105 FrameHost& frameHost() const {
100 return m_helper.webView()->page()->frameHost(); 106 return m_helper.webView()->page()->frameHost();
101 } 107 }
102 108
103 LocalFrame* mainFrame() const { 109 LocalFrame* mainFrame() const {
(...skipping 768 matching lines...) Expand 10 before | Expand all | Expand 10 after
872 878
873 EXPECT_FALSE( 879 EXPECT_FALSE(
874 childCompositor->rootContentLayer()->platformLayer()->masksToBounds()); 880 childCompositor->rootContentLayer()->platformLayer()->masksToBounds());
875 EXPECT_FALSE( 881 EXPECT_FALSE(
876 childCompositor->rootGraphicsLayer()->platformLayer()->masksToBounds()); 882 childCompositor->rootGraphicsLayer()->platformLayer()->masksToBounds());
877 EXPECT_FALSE( 883 EXPECT_FALSE(
878 childCompositor->containerLayer()->platformLayer()->masksToBounds()); 884 childCompositor->containerLayer()->platformLayer()->masksToBounds());
879 } 885 }
880 } 886 }
881 887
888 // Tests that the clipping layer is resized on the root scroller element even
889 // if the layout height doesn't change.
890 TEST_F(RootScrollerTest, BrowserControlsResizeClippingLayer) {
891 bool oldInertTopControls = RuntimeEnabledFeatures::inertTopControlsEnabled();
892 RuntimeEnabledFeatures::setInertTopControlsEnabled(true);
893
894 initialize("root-scroller.html");
895 Element* container = mainFrame()->document()->getElementById("container");
896
897 {
898 NonThrowableExceptionState exceptionState;
899 mainFrame()->document()->setRootScroller(container, exceptionState);
900
901 mainFrameView()->updateAllLifecyclePhases();
902 ASSERT_EQ(toLayoutBox(container->layoutObject())->clientHeight(), 400);
903
904 GraphicsLayer* clipLayer = toLayoutBox(container->layoutObject())
905 ->layer()
906 ->compositedLayerMapping()
907 ->scrollingLayer();
908 ASSERT_EQ(clipLayer->size().height(), 400);
909 EXPECT_TRUE(
910 toLayoutBox(container->layoutObject())->layer()->isRootScroller());
911 }
912
913 {
914 webViewImpl()->handleInputEvent(
915 generateTouchGestureEvent(WebInputEvent::GestureScrollBegin));
916
917 // Scrolling over the #container DIV should cause the browser controls to
918 // hide.
919 EXPECT_FLOAT_EQ(1, browserControls().shownRatio());
920 webViewImpl()->handleInputEvent(generateTouchGestureEvent(
921 WebInputEvent::GestureScrollUpdate, 0, -browserControls().height()));
922 EXPECT_FLOAT_EQ(0, browserControls().shownRatio());
923
924 webViewImpl()->handleInputEvent(
925 generateTouchGestureEvent(WebInputEvent::GestureScrollEnd));
926
927 webViewImpl()->resizeWithBrowserControls(IntSize(400, 450), 50, false);
928 mainFrameView()->updateAllLifecyclePhases();
929
930 // Since inert top controls are enabled, the container should not have
931 // resized, however, the clip layer should.
932 EXPECT_EQ(toLayoutBox(container->layoutObject())->clientHeight(), 400);
933 GraphicsLayer* clipLayer = toLayoutBox(container->layoutObject())
934 ->layer()
935 ->compositedLayerMapping()
936 ->scrollingLayer();
937 EXPECT_EQ(clipLayer->size().height(), 450);
938 }
939
940 RuntimeEnabledFeatures::setInertTopControlsEnabled(oldInertTopControls);
941 }
942
943 // Tests that the clipping layer is resized on the root scroller element when
944 // it's an iframe and even if the layout height doesn't change.
945 TEST_F(RootScrollerTest, BrowserControlsResizeClippingLayerIFrame) {
946 bool oldInertTopControls = RuntimeEnabledFeatures::inertTopControlsEnabled();
947 RuntimeEnabledFeatures::setInertTopControlsEnabled(true);
948
949 initialize("root-scroller-iframe.html");
950
951 Element* iframe = mainFrame()->document()->getElementById("iframe");
952 LocalFrame* childFrame =
953 toLocalFrame(toHTMLFrameOwnerElement(iframe)->contentFrame());
954
955 PaintLayerCompositor* childPLC =
956 childFrame->view()->layoutViewItem().compositor();
957
958 // Give the iframe itself scrollable content and make it the root scroller.
959 {
960 NonThrowableExceptionState nonThrow;
961 mainFrame()->document()->setRootScroller(iframe, nonThrow);
962
963 WebLocalFrame* childWebFrame =
964 mainWebFrame()->firstChild()->toWebLocalFrame();
965 executeScript(
966 "document.getElementById('container').style.width = '300%';"
967 "document.getElementById('container').style.height = '300%';",
968 *childWebFrame);
969
970 mainFrameView()->updateAllLifecyclePhases();
971
972 // Some sanity checks to make sure the test is setup correctly.
973 ASSERT_EQ(childFrame->view()->visibleContentSize().height(), 400);
974 ASSERT_EQ(childPLC->containerLayer()->size().height(), 400);
975 ASSERT_EQ(childPLC->rootGraphicsLayer()->size().height(), 400);
976 ASSERT_TRUE(childFrame->view()->layer()->isRootScroller());
977 }
978
979 {
980 webViewImpl()->handleInputEvent(
981 generateTouchGestureEvent(WebInputEvent::GestureScrollBegin));
982
983 // Scrolling over the #container DIV should cause the browser controls to
984 // hide.
985 EXPECT_FLOAT_EQ(1, browserControls().shownRatio());
986 webViewImpl()->handleInputEvent(generateTouchGestureEvent(
987 WebInputEvent::GestureScrollUpdate, 0, -browserControls().height()));
988 EXPECT_FLOAT_EQ(0, browserControls().shownRatio());
989
990 webViewImpl()->handleInputEvent(
991 generateTouchGestureEvent(WebInputEvent::GestureScrollEnd));
992
993 webViewImpl()->resizeWithBrowserControls(IntSize(400, 450), 50, false);
994 mainFrameView()->updateAllLifecyclePhases();
995
996 // Since inert top controls are enabled, the iframe element should not have
997 // resized, however, its clip layer should resize to reveal content as the
998 // browser controls hide.
999 EXPECT_EQ(childFrame->view()->visibleContentSize().height(), 400);
1000 EXPECT_EQ(childPLC->containerLayer()->size().height(), 450);
1001 EXPECT_EQ(childPLC->rootGraphicsLayer()->size().height(), 450);
1002 }
1003
1004 RuntimeEnabledFeatures::setInertTopControlsEnabled(oldInertTopControls);
1005 }
1006
882 // Tests that removing the root scroller element from the DOM resets the 1007 // Tests that removing the root scroller element from the DOM resets the
883 // effective root scroller without waiting for any lifecycle events. 1008 // effective root scroller without waiting for any lifecycle events.
884 TEST_F(RootScrollerTest, RemoveRootScrollerFromDom) { 1009 TEST_F(RootScrollerTest, RemoveRootScrollerFromDom) {
885 initialize("root-scroller-iframe.html"); 1010 initialize("root-scroller-iframe.html");
886 1011
887 { 1012 {
888 HTMLFrameOwnerElement* iframe = toHTMLFrameOwnerElement( 1013 HTMLFrameOwnerElement* iframe = toHTMLFrameOwnerElement(
889 mainFrame()->document()->getElementById("iframe")); 1014 mainFrame()->document()->getElementById("iframe"));
890 Element* innerContainer = 1015 Element* innerContainer =
891 iframe->contentDocument()->getElementById("container"); 1016 iframe->contentDocument()->getElementById("container");
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
927 EXPECT_EQ(mainFrame()->document()->documentElement(), 1052 EXPECT_EQ(mainFrame()->document()->documentElement(),
928 globalController.globalRootScroller()); 1053 globalController.globalRootScroller());
929 EXPECT_EQ( 1054 EXPECT_EQ(
930 mainFrameView()->layoutViewportScrollableArea()->layerForScrolling(), 1055 mainFrameView()->layoutViewportScrollableArea()->layerForScrolling(),
931 globalController.rootScrollerLayer()); 1056 globalController.rootScrollerLayer());
932 } 1057 }
933 1058
934 } // namespace 1059 } // namespace
935 1060
936 } // namespace blink 1061 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698