Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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(toLayoutBox(container->layoutObject()) | |
| 910 ->layer() | |
| 911 ->isGlobalRootScroller()); | |
| 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 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.
| |
| 930 | |
| 931 // Since inert top controls are enabled, the container should not have | |
| 932 // resized, however, the clip layer should. | |
| 933 EXPECT_EQ(toLayoutBox(container->layoutObject())->clientHeight(), 400); | |
| 934 GraphicsLayer* clipLayer = toLayoutBox(container->layoutObject()) | |
| 935 ->layer() | |
| 936 ->compositedLayerMapping() | |
| 937 ->scrollingLayer(); | |
| 938 EXPECT_EQ(clipLayer->size().height(), 450); | |
| 939 } | |
| 940 | |
| 941 RuntimeEnabledFeatures::setInertTopControlsEnabled(oldInertTopControls); | |
| 942 } | |
| 943 | |
| 944 // Tests that the clipping layer is resized on the root scroller element when | |
| 945 // it's an iframe and even if the layout height doesn't change. | |
| 946 TEST_F(RootScrollerTest, BrowserControlsResizeClippingLayerIFrame) { | |
| 947 bool oldInertTopControls = RuntimeEnabledFeatures::inertTopControlsEnabled(); | |
| 948 RuntimeEnabledFeatures::setInertTopControlsEnabled(true); | |
| 949 | |
| 950 initialize("root-scroller-iframe.html"); | |
| 951 | |
| 952 Element* iframe = mainFrame()->document()->getElementById("iframe"); | |
| 953 LocalFrame* childFrame = | |
| 954 toLocalFrame(toHTMLFrameOwnerElement(iframe)->contentFrame()); | |
| 955 | |
| 956 PaintLayerCompositor* childPLC = | |
| 957 childFrame->view()->layoutViewItem().compositor(); | |
| 958 | |
| 959 // Give the iframe itself scrollable content and make it the root scroller. | |
| 960 { | |
| 961 NonThrowableExceptionState nonThrow; | |
| 962 mainFrame()->document()->setRootScroller(iframe, nonThrow); | |
| 963 | |
| 964 WebLocalFrame* childWebFrame = | |
| 965 mainWebFrame()->firstChild()->toWebLocalFrame(); | |
| 966 executeScript( | |
| 967 "document.getElementById('container').style.width = '300%';" | |
| 968 "document.getElementById('container').style.height = '300%';", | |
| 969 *childWebFrame); | |
| 970 | |
| 971 mainFrameView()->updateAllLifecyclePhases(); | |
| 972 | |
| 973 // Some sanity checks to make sure the test is setup correctly. | |
| 974 ASSERT_EQ(childFrame->view()->visibleContentSize().height(), 400); | |
| 975 ASSERT_EQ(childPLC->containerLayer()->size().height(), 400); | |
| 976 ASSERT_EQ(childPLC->rootGraphicsLayer()->size().height(), 400); | |
| 977 ASSERT_TRUE(childFrame->view()->layer()->isGlobalRootScroller()); | |
| 978 } | |
| 979 | |
| 980 { | |
| 981 webViewImpl()->handleInputEvent( | |
| 982 generateTouchGestureEvent(WebInputEvent::GestureScrollBegin)); | |
| 983 | |
| 984 // Scrolling over the #container DIV should cause the browser controls to | |
| 985 // hide. | |
| 986 EXPECT_FLOAT_EQ(1, browserControls().shownRatio()); | |
| 987 webViewImpl()->handleInputEvent(generateTouchGestureEvent( | |
| 988 WebInputEvent::GestureScrollUpdate, 0, -browserControls().height())); | |
| 989 EXPECT_FLOAT_EQ(0, browserControls().shownRatio()); | |
| 990 | |
| 991 webViewImpl()->handleInputEvent( | |
| 992 generateTouchGestureEvent(WebInputEvent::GestureScrollEnd)); | |
| 993 | |
| 994 webViewImpl()->resizeWithBrowserControls(IntSize(400, 450), 50, false); | |
| 995 mainFrameView()->updateAllLifecyclePhases(); | |
| 996 | |
| 997 // Since inert top controls are enabled, the iframe element should not have | |
| 998 // resized, however, its clip layer should resize to reveal content as the | |
| 999 // browser controls hide. | |
| 1000 EXPECT_EQ(childFrame->view()->visibleContentSize().height(), 400); | |
| 1001 EXPECT_EQ(childPLC->containerLayer()->size().height(), 450); | |
| 1002 EXPECT_EQ(childPLC->rootGraphicsLayer()->size().height(), 450); | |
| 1003 } | |
| 1004 | |
| 1005 RuntimeEnabledFeatures::setInertTopControlsEnabled(oldInertTopControls); | |
| 1006 } | |
| 1007 | |
| 882 // Tests that removing the root scroller element from the DOM resets the | 1008 // Tests that removing the root scroller element from the DOM resets the |
| 883 // effective root scroller without waiting for any lifecycle events. | 1009 // effective root scroller without waiting for any lifecycle events. |
| 884 TEST_F(RootScrollerTest, RemoveRootScrollerFromDom) { | 1010 TEST_F(RootScrollerTest, RemoveRootScrollerFromDom) { |
| 885 initialize("root-scroller-iframe.html"); | 1011 initialize("root-scroller-iframe.html"); |
| 886 | 1012 |
| 887 { | 1013 { |
| 888 HTMLFrameOwnerElement* iframe = toHTMLFrameOwnerElement( | 1014 HTMLFrameOwnerElement* iframe = toHTMLFrameOwnerElement( |
| 889 mainFrame()->document()->getElementById("iframe")); | 1015 mainFrame()->document()->getElementById("iframe")); |
| 890 Element* innerContainer = | 1016 Element* innerContainer = |
| 891 iframe->contentDocument()->getElementById("container"); | 1017 iframe->contentDocument()->getElementById("container"); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 927 EXPECT_EQ(mainFrame()->document()->documentElement(), | 1053 EXPECT_EQ(mainFrame()->document()->documentElement(), |
| 928 globalController.globalRootScroller()); | 1054 globalController.globalRootScroller()); |
| 929 EXPECT_EQ( | 1055 EXPECT_EQ( |
| 930 mainFrameView()->layoutViewportScrollableArea()->layerForScrolling(), | 1056 mainFrameView()->layoutViewportScrollableArea()->layerForScrolling(), |
| 931 globalController.rootScrollerLayer()); | 1057 globalController.rootScrollerLayer()); |
| 932 } | 1058 } |
| 933 | 1059 |
| 934 } // namespace | 1060 } // namespace |
| 935 | 1061 |
| 936 } // namespace blink | 1062 } // namespace blink |
| OLD | NEW |