Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / web / tests / ScrollingCoordinatorChromiumTest.cpp
index de671f4..cdf1a04 100644 (file)
 
 #include "core/page/scrolling/ScrollingCoordinator.h"
 
-#include <gtest/gtest.h>
-#include "FrameTestHelpers.h"
-#include "URLTestHelpers.h"
-#include "WebFrameImpl.h"
-#include "WebSettings.h"
-#include "WebViewClient.h"
-#include "WebViewImpl.h"
-#include "core/rendering/CompositedLayerMapping.h"
-#include "core/rendering/RenderLayerCompositor.h"
+#include "core/page/Page.h"
+#include "core/rendering/RenderPart.h"
 #include "core/rendering/RenderView.h"
+#include "core/rendering/compositing/CompositedLayerMapping.h"
+#include "core/rendering/compositing/RenderLayerCompositor.h"
+#include "core/testing/URLTestHelpers.h"
 #include "platform/graphics/GraphicsLayer.h"
 #include "public/platform/Platform.h"
 #include "public/platform/WebLayer.h"
 #include "public/platform/WebLayerPositionConstraint.h"
 #include "public/platform/WebLayerTreeView.h"
 #include "public/platform/WebUnitTestSupport.h"
+#include "public/web/WebSettings.h"
+#include "public/web/WebViewClient.h"
+#include "web/WebLocalFrameImpl.h"
+#include "web/WebViewImpl.h"
+#include "web/tests/FrameTestHelpers.h"
+#include <gtest/gtest.h>
 
-using namespace WebCore;
 using namespace blink;
 
 namespace {
 
-class FakeWebViewClient : public WebViewClient {
-public:
-    virtual void initializeLayerTreeView()
-    {
-        m_layerTreeView = adoptPtr(Platform::current()->unitTestSupport()->createLayerTreeViewForTesting(WebUnitTestSupport::TestViewTypeUnitTest));
-        ASSERT(m_layerTreeView);
-    }
-
-    virtual WebLayerTreeView* layerTreeView()
-    {
-        return m_layerTreeView.get();
-    }
-
-private:
-    OwnPtr<WebLayerTreeView> m_layerTreeView;
-};
-
 class ScrollingCoordinatorChromiumTest : public testing::Test {
 public:
     ScrollingCoordinatorChromiumTest()
@@ -82,13 +66,11 @@ public:
     void navigateTo(const std::string& url)
     {
         FrameTestHelpers::loadFrame(webViewImpl()->mainFrame(), url);
-        Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests();
     }
 
     void forceFullCompositingUpdate()
     {
-        RenderLayerCompositor* compositor = frame()->contentRenderer()->compositor();
-        compositor->updateCompositingLayers();
+        webViewImpl()->layout();
     }
 
     void registerMockedHttpURLLoad(const std::string& fileName)
@@ -107,28 +89,28 @@ public:
     }
 
     WebViewImpl* webViewImpl() const { return m_helper.webViewImpl(); }
-    Frame* frame() const { return m_helper.webViewImpl()->mainFrameImpl()->frame(); }
+    LocalFrame* frame() const { return m_helper.webViewImpl()->mainFrameImpl()->frame(); }
 
 protected:
     std::string m_baseURL;
-    FakeWebViewClient m_mockWebViewClient;
+    FrameTestHelpers::TestWebViewClient m_mockWebViewClient;
 
 private:
     static void configureSettings(WebSettings* settings)
     {
         settings->setJavaScriptEnabled(true);
-        settings->setForceCompositingMode(true);
         settings->setAcceleratedCompositingEnabled(true);
-        settings->setAcceleratedCompositingForFixedPositionEnabled(true);
-        settings->setAcceleratedCompositingForOverflowScrollEnabled(true);
-        settings->setAcceleratedCompositingForScrollableFramesEnabled(true);
-        settings->setCompositedScrollingForFramesEnabled(true);
-        settings->setFixedPositionCreatesStackingContext(true);
+        settings->setPreferCompositingToLCDTextEnabled(true);
     }
 
     FrameTestHelpers::WebViewHelper m_helper;
 };
 
+class GraphicsLayerForScrollTesting : public GraphicsLayer {
+public:
+    virtual WebLayer* contentsLayer() const { return GraphicsLayer::contentsLayer(); }
+};
+
 TEST_F(ScrollingCoordinatorChromiumTest, fastScrollingByDefault)
 {
     navigateTo("about:blank");
@@ -147,6 +129,24 @@ TEST_F(ScrollingCoordinatorChromiumTest, fastScrollingByDefault)
     ASSERT_FALSE(rootScrollLayer->haveWheelEventHandlers());
 }
 
+TEST_F(ScrollingCoordinatorChromiumTest, fastScrollingCanBeDisabledWithSetting)
+{
+    navigateTo("about:blank");
+    webViewImpl()->settings()->setThreadedScrollingEnabled(false);
+    forceFullCompositingUpdate();
+
+    // Make sure the scrolling coordinator is active.
+    FrameView* frameView = frame()->view();
+    Page* page = frame()->page();
+    ASSERT_TRUE(page->scrollingCoordinator());
+    ASSERT_TRUE(page->scrollingCoordinator()->coordinatesScrollingForFrameView(frameView));
+
+    // Main scrolling should be enabled with the setting override.
+    WebLayer* rootScrollLayer = getRootScrollLayer();
+    ASSERT_TRUE(rootScrollLayer->scrollable());
+    ASSERT_TRUE(rootScrollLayer->shouldScrollOnMainThread());
+}
+
 static WebLayer* webLayerFromElement(Element* element)
 {
     if (!element)
@@ -159,7 +159,7 @@ static WebLayer* webLayerFromElement(Element* element)
         return 0;
     if (!layer->hasCompositedLayerMapping())
         return 0;
-    CompositedLayerMappingPtr compositedLayerMapping = layer->compositedLayerMapping();
+    CompositedLayerMapping* compositedLayerMapping = layer->compositedLayerMapping();
     GraphicsLayer* graphicsLayer = compositedLayerMapping->mainGraphicsLayer();
     if (!graphicsLayer)
         return 0;
@@ -251,27 +251,35 @@ TEST_F(ScrollingCoordinatorChromiumTest, fastScrollingForFixedPosition)
     }
 }
 
-TEST_F(ScrollingCoordinatorChromiumTest, nonFastScrollableRegion)
+TEST_F(ScrollingCoordinatorChromiumTest, wheelEventHandler)
 {
-    registerMockedHttpURLLoad("non-fast-scrollable.html");
-    navigateTo(m_baseURL + "non-fast-scrollable.html");
+    registerMockedHttpURLLoad("wheel-event-handler.html");
+    navigateTo(m_baseURL + "wheel-event-handler.html");
     forceFullCompositingUpdate();
 
     WebLayer* rootScrollLayer = getRootScrollLayer();
-    WebVector<WebRect> nonFastScrollableRegion = rootScrollLayer->nonFastScrollableRegion();
-
-    ASSERT_EQ(1u, nonFastScrollableRegion.size());
-    ASSERT_EQ(WebRect(8, 8, 10, 10), nonFastScrollableRegion[0]);
+    ASSERT_TRUE(rootScrollLayer->haveWheelEventHandlers());
 }
 
-TEST_F(ScrollingCoordinatorChromiumTest, wheelEventHandler)
+TEST_F(ScrollingCoordinatorChromiumTest, scrollEventHandler)
 {
-    registerMockedHttpURLLoad("wheel-event-handler.html");
-    navigateTo(m_baseURL + "wheel-event-handler.html");
+    registerMockedHttpURLLoad("scroll-event-handler.html");
+    navigateTo(m_baseURL + "scroll-event-handler.html");
     forceFullCompositingUpdate();
 
     WebLayer* rootScrollLayer = getRootScrollLayer();
-    ASSERT_TRUE(rootScrollLayer->haveWheelEventHandlers());
+    ASSERT_TRUE(rootScrollLayer->haveScrollEventHandlers());
+}
+
+TEST_F(ScrollingCoordinatorChromiumTest, updateEventHandlersDuringTeardown)
+{
+    registerMockedHttpURLLoad("scroll-event-handler-window.html");
+    navigateTo(m_baseURL + "scroll-event-handler-window.html");
+    forceFullCompositingUpdate();
+
+    // Simulate detaching the document from its DOM window. This should not
+    // cause a crash when the WebViewImpl is closed by the test runner.
+    frame()->document()->prepareForDestruction();
 }
 
 TEST_F(ScrollingCoordinatorChromiumTest, clippedBodyTest)
@@ -303,7 +311,7 @@ TEST_F(ScrollingCoordinatorChromiumTest, overflowScrolling)
     ASSERT_TRUE(box->usesCompositedScrolling());
     ASSERT_EQ(PaintsIntoOwnBacking, box->layer()->compositingState());
 
-    CompositedLayerMappingPtr compositedLayerMapping = box->layer()->compositedLayerMapping();
+    CompositedLayerMapping* compositedLayerMapping = box->layer()->compositedLayerMapping();
     ASSERT_TRUE(compositedLayerMapping->hasScrollingLayer());
     ASSERT(compositedLayerMapping->scrollingContentsLayer());
 
@@ -343,7 +351,7 @@ TEST_F(ScrollingCoordinatorChromiumTest, overflowHidden)
     ASSERT_TRUE(box->usesCompositedScrolling());
     ASSERT_EQ(PaintsIntoOwnBacking, box->layer()->compositingState());
 
-    CompositedLayerMappingPtr compositedLayerMapping = box->layer()->compositedLayerMapping();
+    CompositedLayerMapping* compositedLayerMapping = box->layer()->compositedLayerMapping();
     ASSERT_TRUE(compositedLayerMapping->hasScrollingLayer());
     ASSERT(compositedLayerMapping->scrollingContentsLayer());
 
@@ -393,14 +401,14 @@ TEST_F(ScrollingCoordinatorChromiumTest, iframeScrolling)
 
     RenderObject* renderer = scrollableFrame->renderer();
     ASSERT_TRUE(renderer);
-    ASSERT_TRUE(renderer->isWidget());
+    ASSERT_TRUE(renderer->isRenderPart());
 
-    RenderWidget* renderWidget = toRenderWidget(renderer);
-    ASSERT_TRUE(renderWidget);
-    ASSERT_TRUE(renderWidget->widget());
-    ASSERT_TRUE(renderWidget->widget()->isFrameView());
+    RenderPart* renderPart = toRenderPart(renderer);
+    ASSERT_TRUE(renderPart);
+    ASSERT_TRUE(renderPart->widget());
+    ASSERT_TRUE(renderPart->widget()->isFrameView());
 
-    FrameView* innerFrameView = toFrameView(renderWidget->widget());
+    FrameView* innerFrameView = toFrameView(renderPart->widget());
     RenderView* innerRenderView = innerFrameView->renderView();
     ASSERT_TRUE(innerRenderView);
 
@@ -437,14 +445,14 @@ TEST_F(ScrollingCoordinatorChromiumTest, rtlIframe)
 
     RenderObject* renderer = scrollableFrame->renderer();
     ASSERT_TRUE(renderer);
-    ASSERT_TRUE(renderer->isWidget());
+    ASSERT_TRUE(renderer->isRenderPart());
 
-    RenderWidget* renderWidget = toRenderWidget(renderer);
-    ASSERT_TRUE(renderWidget);
-    ASSERT_TRUE(renderWidget->widget());
-    ASSERT_TRUE(renderWidget->widget()->isFrameView());
+    RenderPart* renderPart = toRenderPart(renderer);
+    ASSERT_TRUE(renderPart);
+    ASSERT_TRUE(renderPart->widget());
+    ASSERT_TRUE(renderPart->widget()->isFrameView());
 
-    FrameView* innerFrameView = toFrameView(renderWidget->widget());
+    FrameView* innerFrameView = toFrameView(renderPart->widget());
     RenderView* innerRenderView = innerFrameView->renderView();
     ASSERT_TRUE(innerRenderView);
 
@@ -459,8 +467,7 @@ TEST_F(ScrollingCoordinatorChromiumTest, rtlIframe)
     ASSERT_TRUE(webScrollLayer->scrollable());
 
     int expectedScrollPosition = 958 + (innerFrameView->verticalScrollbar()->isOverlayScrollbar() ? 0 : 15);
-    ASSERT_EQ(expectedScrollPosition, webScrollLayer->scrollPosition().x);
-    ASSERT_EQ(expectedScrollPosition, webScrollLayer->maxScrollPosition().width);
+    ASSERT_EQ(expectedScrollPosition, webScrollLayer->scrollPositionDouble().x);
 }
 
 TEST_F(ScrollingCoordinatorChromiumTest, setupScrollbarLayerShouldNotCrash)
@@ -472,4 +479,32 @@ TEST_F(ScrollingCoordinatorChromiumTest, setupScrollbarLayerShouldNotCrash)
     // an empty document by javascript.
 }
 
+#if OS(MACOSX)
+TEST_F(ScrollingCoordinatorChromiumTest, DISABLED_setupScrollbarLayerShouldSetScrollLayerOpaque)
+#else
+TEST_F(ScrollingCoordinatorChromiumTest, setupScrollbarLayerShouldSetScrollLayerOpaque)
+#endif
+{
+    registerMockedHttpURLLoad("wide_document.html");
+    navigateTo(m_baseURL + "wide_document.html");
+    forceFullCompositingUpdate();
+
+    FrameView* frameView = frame()->view();
+    ASSERT_TRUE(frameView);
+
+    GraphicsLayerForScrollTesting* scrollbarGraphicsLayer = static_cast<GraphicsLayerForScrollTesting*>(frameView->layerForHorizontalScrollbar());
+    ASSERT_TRUE(scrollbarGraphicsLayer);
+
+    WebLayer* platformLayer = scrollbarGraphicsLayer->platformLayer();
+    ASSERT_TRUE(platformLayer);
+
+    WebLayer* contentsLayer = scrollbarGraphicsLayer->contentsLayer();
+    ASSERT_TRUE(contentsLayer);
+
+    // After scrollableAreaScrollbarLayerDidChange,
+    // if the main frame's scrollbarLayer is opaque,
+    // contentsLayer should be opaque too.
+    ASSERT_EQ(platformLayer->opaque(), contentsLayer->opaque());
+}
+
 } // namespace