[chromium] Add test for ScrollingCoordinatorChromium
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 21 Sep 2012 14:11:27 +0000 (14:11 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 21 Sep 2012 14:11:27 +0000 (14:11 +0000)
https://bugs.webkit.org/show_bug.cgi?id=96657

Patch by Sami Kyostila <skyostil@chromium.org> on 2012-09-21
Reviewed by James Robinson.

Add tests for ScrollingCoordinatorChromium. These tests mainly verify that
fast (non-main thread) scrolling is enabled when necessary and that a proper
compositing layer structure is created for fixed position and accelerated
scrolling layers.

Tests: ScrollingCoordinatorChromiumTest.fastScrollingByDefault
       ScrollingCoordinatorChromiumTest.fastScrollingForFixedPosition
       ScrollingCoordinatorChromiumTest.nonFastScrollableRegion
       ScrollingCoordinatorChromiumTest.wheelEventHandler
       ScrollingCoordinatorChromiumTest.touchOverflowScrolling

* WebKit.gypi:
* tests/ScrollingCoordinatorChromiumTest.cpp: Added.
(WebKit):
(MockWebViewClient):
(ScrollingCoordinatorChromiumTest):
(WebKit::ScrollingCoordinatorChromiumTest::ScrollingCoordinatorChromiumTest):
(WebKit::ScrollingCoordinatorChromiumTest::createCompositedWebViewImpl):
(WebKit::ScrollingCoordinatorChromiumTest::registerMockedHttpURLLoad):
(WebKit::ScrollingCoordinatorChromiumTest::getRootScrollLayer):
(WebKit::TEST_F):
* tests/data/fixed_position.html: Added.
* tests/data/non_fast_scrollable.html: Added.
* tests/data/touch_overflow_scrolling.html: Added.
* tests/data/wheel_event_handler.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@129225 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/Platform/chromium/public/WebLayer.h
Source/WebKit/chromium/ChangeLog
Source/WebKit/chromium/WebKit.gyp
Source/WebKit/chromium/WebKit.gypi
Source/WebKit/chromium/tests/ScrollingCoordinatorChromiumTest.cpp [new file with mode: 0644]
Source/WebKit/chromium/tests/data/fixed-position.html [new file with mode: 0644]
Source/WebKit/chromium/tests/data/non-fast-scrollable.html [new file with mode: 0644]
Source/WebKit/chromium/tests/data/touch-overflow-scrolling.html [new file with mode: 0644]
Source/WebKit/chromium/tests/data/wheel-event-handler.html [new file with mode: 0644]

index 1bff7ef..3c9b997 100644 (file)
@@ -169,12 +169,25 @@ public:
     virtual WebPoint scrollPosition() const = 0;
 
     virtual void setMaxScrollPosition(WebSize) = 0;
+    virtual WebSize maxScrollPosition() const = 0;
+
     virtual void setScrollable(bool) = 0;
+    virtual bool scrollable() const = 0;
+
     virtual void setHaveWheelEventHandlers(bool) = 0;
+    virtual bool haveWheelEventHandlers() const = 0;
+
     virtual void setShouldScrollOnMainThread(bool) = 0;
+    virtual bool shouldScrollOnMainThread() const = 0;
+
     virtual void setNonFastScrollableRegion(const WebVector<WebRect>&) = 0;
+    virtual WebVector<WebRect> nonFastScrollableRegion() const = 0;
+
     virtual void setIsContainerForFixedPositionLayers(bool) = 0;
+    virtual bool isContainerForFixedPositionLayers() const = 0;
+
     virtual void setFixedToContainerLayer(bool) = 0;
+    virtual bool fixedToContainerLayer() const = 0;
 
     // The scroll client is notified when the scroll position of the WebLayer
     // changes. Only a single scroll client can be set for a WebLayer at a time.
index 6c7c38f..51d4893 100644 (file)
@@ -1,3 +1,36 @@
+2012-09-21  Sami Kyostila  <skyostil@chromium.org>
+
+        [chromium] Add test for ScrollingCoordinatorChromium
+        https://bugs.webkit.org/show_bug.cgi?id=96657
+
+        Reviewed by James Robinson.
+
+        Add tests for ScrollingCoordinatorChromium. These tests mainly verify that
+        fast (non-main thread) scrolling is enabled when necessary and that a proper
+        compositing layer structure is created for fixed position and accelerated
+        scrolling layers.
+
+        Tests: ScrollingCoordinatorChromiumTest.fastScrollingByDefault
+               ScrollingCoordinatorChromiumTest.fastScrollingForFixedPosition
+               ScrollingCoordinatorChromiumTest.nonFastScrollableRegion
+               ScrollingCoordinatorChromiumTest.wheelEventHandler
+               ScrollingCoordinatorChromiumTest.touchOverflowScrolling
+
+        * WebKit.gypi:
+        * tests/ScrollingCoordinatorChromiumTest.cpp: Added.
+        (WebKit):
+        (MockWebViewClient):
+        (ScrollingCoordinatorChromiumTest):
+        (WebKit::ScrollingCoordinatorChromiumTest::ScrollingCoordinatorChromiumTest):
+        (WebKit::ScrollingCoordinatorChromiumTest::createCompositedWebViewImpl):
+        (WebKit::ScrollingCoordinatorChromiumTest::registerMockedHttpURLLoad):
+        (WebKit::ScrollingCoordinatorChromiumTest::getRootScrollLayer):
+        (WebKit::TEST_F):
+        * tests/data/fixed_position.html: Added.
+        * tests/data/non_fast_scrollable.html: Added.
+        * tests/data/touch_overflow_scrolling.html: Added.
+        * tests/data/wheel_event_handler.html: Added.
+
 2012-09-20  Peter Beverloo  <peter@chromium.org>
 
         Leverage Chromium's code to set up FIFOs for Chromium Android layout tests
index 1f87ee5..709f0d9 100644 (file)
                                 'tests/PopupMenuTest.cpp',
                                 'tests/RenderTableCellTest.cpp',
                                 'tests/RenderTableRowTest.cpp',
+                                'tests/ScrollingCoordinatorChromiumTest.cpp',
                                 'tests/URLTestHelpers.cpp',
                                 'tests/WebFrameTest.cpp',
                                 'tests/WebImageTest.cpp',
index 140539f..f428cb1 100644 (file)
@@ -97,6 +97,7 @@
             'tests/RegionTest.cpp',
             'tests/RenderTableCellTest.cpp',
             'tests/RenderTableRowTest.cpp',
+            'tests/ScrollingCoordinatorChromiumTest.cpp',
             'tests/TilingDataTest.cpp',
             'tests/TreeTestHelpers.cpp',
             'tests/TreeTestHelpers.h',
diff --git a/Source/WebKit/chromium/tests/ScrollingCoordinatorChromiumTest.cpp b/Source/WebKit/chromium/tests/ScrollingCoordinatorChromiumTest.cpp
new file mode 100644 (file)
index 0000000..b4fa4a1
--- /dev/null
@@ -0,0 +1,217 @@
+/*
+ * Copyright (C) 2012 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#include "ScrollingCoordinator.h"
+
+#include "CompositorFakeWebGraphicsContext3D.h"
+#include "FakeWebCompositorOutputSurface.h"
+#include "FrameTestHelpers.h"
+#include "RenderLayerCompositor.h"
+#include "RenderView.h"
+#include "URLTestHelpers.h"
+#include "WebCompositorInitializer.h"
+#include "WebFrameClient.h"
+#include "WebFrameImpl.h"
+#include "WebSettings.h"
+#include "WebViewClient.h"
+#include "WebViewImpl.h"
+#include <gtest/gtest.h>
+#include <public/WebCompositorSupport.h>
+#include <public/WebLayer.h>
+#include <webkit/support/webkit_support.h>
+
+#if ENABLE(ACCELERATED_OVERFLOW_SCROLLING)
+#include "GraphicsLayerChromium.h"
+#endif
+
+using namespace WebCore;
+using namespace WebKit;
+
+namespace {
+
+class MockWebViewClient : public WebViewClient {
+public:
+    virtual WebCompositorOutputSurface* createOutputSurface() OVERRIDE
+    {
+        return FakeWebCompositorOutputSurface::create(CompositorFakeWebGraphicsContext3D::create(WebGraphicsContext3D::Attributes())).leakPtr();
+    }
+};
+
+class MockWebFrameClient : public WebFrameClient {
+};
+
+class ScrollingCoordinatorChromiumTest : public testing::Test {
+public:
+    ScrollingCoordinatorChromiumTest()
+        : m_baseURL("http://www.test.com/")
+        , m_webCompositorInitializer(0)
+    {
+        // We cannot reuse FrameTestHelpers::createWebViewAndLoad here because the compositing
+        // settings need to be set before the page is loaded.
+        m_webViewImpl = static_cast<WebViewImpl*>(WebView::create(&m_mockWebViewClient));
+        m_webViewImpl->settings()->setJavaScriptEnabled(true);
+        m_webViewImpl->settings()->setForceCompositingMode(true);
+        m_webViewImpl->settings()->setAcceleratedCompositingEnabled(true);
+        m_webViewImpl->settings()->setAcceleratedCompositingForFixedPositionEnabled(true);
+        m_webViewImpl->settings()->setFixedPositionCreatesStackingContext(true);
+        m_webViewImpl->initializeMainFrame(&m_mockWebFrameClient);
+        m_webViewImpl->resize(IntSize(320, 240));
+    }
+
+    virtual ~ScrollingCoordinatorChromiumTest()
+    {
+        webkit_support::UnregisterAllMockedURLs();
+        m_webViewImpl->close();
+    }
+
+    void navigateTo(const std::string& url)
+    {
+        FrameTestHelpers::loadFrame(m_webViewImpl->mainFrame(), url);
+        webkit_support::ServeAsynchronousMockedRequests();
+    }
+
+    void registerMockedHttpURLLoad(const std::string& fileName)
+    {
+        URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8(fileName.c_str()));
+    }
+
+    WebLayer* getRootScrollLayer()
+    {
+        RenderLayerCompositor* compositor = m_webViewImpl->mainFrameImpl()->frame()->contentRenderer()->compositor();
+        ASSERT(compositor);
+        ASSERT(compositor->scrollLayer());
+
+        WebLayer* webScrollLayer = static_cast<WebLayer*>(compositor->scrollLayer()->platformLayer());
+        return webScrollLayer;
+    }
+
+protected:
+    std::string m_baseURL;
+    MockWebFrameClient m_mockWebFrameClient;
+    MockWebViewClient m_mockWebViewClient;
+    WebKitTests::WebCompositorInitializer m_webCompositorInitializer;
+    WebViewImpl* m_webViewImpl;
+};
+
+TEST_F(ScrollingCoordinatorChromiumTest, fastScrollingByDefault)
+{
+    navigateTo("about:blank");
+
+    // Make sure the scrolling coordinator is active.
+    FrameView* frameView = m_webViewImpl->mainFrameImpl()->frameView();
+    Page* page = m_webViewImpl->mainFrameImpl()->frame()->page();
+    ASSERT_TRUE(page->scrollingCoordinator());
+    ASSERT_TRUE(page->scrollingCoordinator()->coordinatesScrollingForFrameView(frameView));
+
+    // Fast scrolling should be enabled by default.
+    WebLayer* rootScrollLayer = getRootScrollLayer();
+    ASSERT_TRUE(rootScrollLayer->scrollable());
+    ASSERT_FALSE(rootScrollLayer->shouldScrollOnMainThread());
+    ASSERT_FALSE(rootScrollLayer->haveWheelEventHandlers());
+}
+
+TEST_F(ScrollingCoordinatorChromiumTest, fastScrollingForFixedPosition)
+{
+    registerMockedHttpURLLoad("fixed-position.html");
+    navigateTo(m_baseURL + "fixed-position.html");
+
+    Page* page = m_webViewImpl->mainFrameImpl()->frame()->page();
+    ASSERT_TRUE(page->scrollingCoordinator()->supportsFixedPositionLayers());
+
+    // Fixed position should not fall back to main thread scrolling.
+    WebLayer* rootScrollLayer = getRootScrollLayer();
+    ASSERT_FALSE(rootScrollLayer->shouldScrollOnMainThread());
+
+    // Verify the properties of the fixed position element starting from the RenderObject all the
+    // way to the WebLayer.
+    Element* fixedElement = m_webViewImpl->mainFrameImpl()->frame()->document()->getElementById("fixed");
+    ASSERT(fixedElement);
+
+    RenderObject* renderer = fixedElement->renderer();
+    ASSERT_TRUE(renderer->isBoxModelObject());
+    ASSERT_TRUE(renderer->hasLayer());
+
+    RenderLayer* layer = toRenderBoxModelObject(renderer)->layer();
+    ASSERT_TRUE(layer->isComposited());
+
+    RenderLayerBacking* layerBacking = layer->backing();
+    WebLayer* webLayer = static_cast<WebLayer*>(layerBacking->graphicsLayer()->platformLayer());
+    ASSERT_TRUE(webLayer->fixedToContainerLayer());
+}
+
+TEST_F(ScrollingCoordinatorChromiumTest, nonFastScrollableRegion)
+{
+    registerMockedHttpURLLoad("non-fast-scrollable.html");
+    navigateTo(m_baseURL + "non-fast-scrollable.html");
+
+    WebLayer* rootScrollLayer = getRootScrollLayer();
+    WebVector<WebRect> nonFastScrollableRegion = rootScrollLayer->nonFastScrollableRegion();
+
+    ASSERT_EQ(1u, nonFastScrollableRegion.size());
+    ASSERT_EQ(WebRect(8, 8, 10, 10), nonFastScrollableRegion[0]);
+}
+
+TEST_F(ScrollingCoordinatorChromiumTest, wheelEventHandler)
+{
+    registerMockedHttpURLLoad("wheel-event-handler.html");
+    navigateTo(m_baseURL + "wheel-event-handler.html");
+
+    WebLayer* rootScrollLayer = getRootScrollLayer();
+    ASSERT_TRUE(rootScrollLayer->haveWheelEventHandlers());
+}
+
+#if ENABLE(ACCELERATED_OVERFLOW_SCROLLING)
+TEST_F(ScrollingCoordinatorChromiumTest, touchOverflowScrolling)
+{
+    registerMockedHttpURLLoad("touch-overflow-scrolling.html");
+    navigateTo(m_baseURL + "touch-overflow-scrolling.html");
+
+    // Verify the properties of the accelerated scrolling element starting from the RenderObject
+    // all the way to the WebLayer.
+    Element* scrollableElement = m_webViewImpl->mainFrameImpl()->frame()->document()->getElementById("scrollable");
+    ASSERT(scrollableElement);
+
+    RenderObject* renderer = scrollableElement->renderer();
+    ASSERT_TRUE(renderer->isBoxModelObject());
+    ASSERT_TRUE(renderer->hasLayer());
+
+    RenderLayer* layer = toRenderBoxModelObject(renderer)->layer();
+    ASSERT_TRUE(layer->usesCompositedScrolling());
+    ASSERT_TRUE(layer->isComposited());
+
+    RenderLayerBacking* layerBacking = layer->backing();
+    ASSERT_TRUE(layerBacking->hasScrollingLayer());
+    ASSERT(layerBacking->scrollingContentsLayer());
+
+    GraphicsLayerChromium* graphicsLayerChromium = static_cast<GraphicsLayerChromium*>(layerBacking->scrollingContentsLayer());
+    ASSERT_EQ(layer, graphicsLayerChromium->scrollableArea());
+
+    WebLayer* webScrollLayer = static_cast<WebLayer*>(layerBacking->scrollingContentsLayer()->platformLayer());
+    ASSERT_TRUE(webScrollLayer->scrollable());
+}
+#endif // ENABLE(ACCELERATED_OVERFLOW_SCROLLING)
+
+} // namespace
diff --git a/Source/WebKit/chromium/tests/data/fixed-position.html b/Source/WebKit/chromium/tests/data/fixed-position.html
new file mode 100644 (file)
index 0000000..bcb44e3
--- /dev/null
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<html>
+<head>
+  <style type="text/css">
+    #fixed {
+      position: fixed;
+    }
+  </style>
+</head>
+
+<body>
+  <div id="fixed">
+    Fixed positioned.
+  </div>
+</body>
+</html>
diff --git a/Source/WebKit/chromium/tests/data/non-fast-scrollable.html b/Source/WebKit/chromium/tests/data/non-fast-scrollable.html
new file mode 100644 (file)
index 0000000..b633d25
--- /dev/null
@@ -0,0 +1,18 @@
+<!DOCTYPE html>
+<html>
+<head>
+  <style type="text/css">
+    .scrollable {
+      width: 10px;
+      height: 10px;
+      overflow: scroll;
+    }
+  </style>
+</head>
+
+<body>
+  <div class="scrollable">
+    Scrolling content.
+  </div>
+</body>
+</html>
diff --git a/Source/WebKit/chromium/tests/data/touch-overflow-scrolling.html b/Source/WebKit/chromium/tests/data/touch-overflow-scrolling.html
new file mode 100644 (file)
index 0000000..25972aa
--- /dev/null
@@ -0,0 +1,23 @@
+<!DOCTYPE html>
+<html>
+<head>
+  <style type="text/css">
+    #scrollable {
+      width: 10px;
+      height: 10px;
+      overflow: scroll;
+      -webkit-overflow-scrolling: touch;
+    }
+    .content {
+      width: 100px;
+      height: 1000px;
+    }
+  </style>
+</head>
+
+<body>
+  <div id="scrollable">
+    <div class="content"></div>
+  </div>
+</body>
+</html>
diff --git a/Source/WebKit/chromium/tests/data/wheel-event-handler.html b/Source/WebKit/chromium/tests/data/wheel-event-handler.html
new file mode 100644 (file)
index 0000000..7e450a4
--- /dev/null
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<html>
+<head>
+  <script type="text/javascript">
+      window.addEventListener('mousewheel', function(event) {
+      });
+  </script>
+</head>
+
+</html>