|
Line 0
a/Source/WebKit/chromium/tests/ScrollingCoordinatorChromiumTest.cpp_sec1
|
|
|
1 |
/* |
| 2 |
* Copyright (C) 2012 Google Inc. All rights reserved. |
| 3 |
* |
| 4 |
* Redistribution and use in source and binary forms, with or without |
| 5 |
* modification, are permitted provided that the following conditions |
| 6 |
* are met: |
| 7 |
* 1. Redistributions of source code must retain the above copyright |
| 8 |
* notice, this list of conditions and the following disclaimer. |
| 9 |
* 2. Redistributions in binary form must reproduce the above copyright |
| 10 |
* notice, this list of conditions and the following disclaimer in the |
| 11 |
* documentation and/or other materials provided with the distribution. |
| 12 |
* |
| 13 |
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY |
| 14 |
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 15 |
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 16 |
* DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY |
| 17 |
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 18 |
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 19 |
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
| 20 |
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 21 |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 22 |
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 23 |
*/ |
| 24 |
|
| 25 |
#include "config.h" |
| 26 |
|
| 27 |
#include "ScrollingCoordinator.h" |
| 28 |
|
| 29 |
#include "CompositorFakeWebGraphicsContext3D.h" |
| 30 |
#include "FakeWebCompositorOutputSurface.h" |
| 31 |
#include "FrameTestHelpers.h" |
| 32 |
#include "RenderLayerCompositor.h" |
| 33 |
#include "RenderView.h" |
| 34 |
#include "URLTestHelpers.h" |
| 35 |
#include "WebFrameClient.h" |
| 36 |
#include "WebFrameImpl.h" |
| 37 |
#include "WebSettings.h" |
| 38 |
#include "WebViewClient.h" |
| 39 |
#include "WebViewImpl.h" |
| 40 |
#include <gtest/gtest.h> |
| 41 |
#include <public/WebCompositorSupport.h> |
| 42 |
#include <public/WebLayer.h> |
| 43 |
#include <webkit/support/webkit_support.h> |
| 44 |
|
| 45 |
#if ENABLE(ACCELERATED_OVERFLOW_SCROLLING) |
| 46 |
#include "GraphicsLayerChromium.h" |
| 47 |
#endif |
| 48 |
|
| 49 |
using namespace WebCore; |
| 50 |
using namespace WebKit; |
| 51 |
|
| 52 |
namespace { |
| 53 |
|
| 54 |
class MockWebViewClient : public WebViewClient { |
| 55 |
public: |
| 56 |
virtual WebCompositorOutputSurface* createOutputSurface() OVERRIDE |
| 57 |
{ |
| 58 |
return FakeWebCompositorOutputSurface::create(CompositorFakeWebGraphicsContext3D::create(WebGraphicsContext3D::Attributes())).leakPtr(); |
| 59 |
} |
| 60 |
}; |
| 61 |
|
| 62 |
class MockWebFrameClient : public WebFrameClient { |
| 63 |
}; |
| 64 |
|
| 65 |
class ScrollingCoordinatorChromiumTest : public testing::Test { |
| 66 |
public: |
| 67 |
ScrollingCoordinatorChromiumTest() |
| 68 |
: m_baseURL("http://www.test.com/") |
| 69 |
, m_webViewImpl(0) { } |
| 70 |
|
| 71 |
WebViewImpl* createCompositedWebViewImpl(const std::string& url) |
| 72 |
{ |
| 73 |
ASSERT(!m_webViewImpl); |
| 74 |
WebKit::Platform::current()->compositorSupport()->initialize(0); |
| 75 |
|
| 76 |
// We cannot reuse FrameTestHelpers::createWebViewAndLoad here because the compositing |
| 77 |
// settings need to be set before the page is loaded. |
| 78 |
m_webViewImpl = static_cast<WebViewImpl*>(WebView::create(&m_mockWebViewClient)); |
| 79 |
m_webViewImpl->settings()->setJavaScriptEnabled(true); |
| 80 |
m_webViewImpl->settings()->setForceCompositingMode(true); |
| 81 |
m_webViewImpl->settings()->setAcceleratedCompositingEnabled(true); |
| 82 |
m_webViewImpl->settings()->setAcceleratedCompositingForFixedPositionEnabled(true); |
| 83 |
m_webViewImpl->initializeMainFrame(&m_mockWebFrameClient); |
| 84 |
m_webViewImpl->resize(IntSize(320, 240)); |
| 85 |
|
| 86 |
FrameTestHelpers::loadFrame(m_webViewImpl->mainFrame(), url); |
| 87 |
webkit_support::ServeAsynchronousMockedRequests(); |
| 88 |
|
| 89 |
return m_webViewImpl; |
| 90 |
} |
| 91 |
|
| 92 |
virtual void TearDown() OVERRIDE |
| 93 |
{ |
| 94 |
webkit_support::UnregisterAllMockedURLs(); |
| 95 |
if (m_webViewImpl) { |
| 96 |
m_webViewImpl->close(); |
| 97 |
m_webViewImpl = 0; |
| 98 |
WebKit::Platform::current()->compositorSupport()->shutdown(); |
| 99 |
} |
| 100 |
} |
| 101 |
|
| 102 |
void registerMockedHttpURLLoad(const std::string& fileName) |
| 103 |
{ |
| 104 |
URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8(fileName.c_str())); |
| 105 |
} |
| 106 |
|
| 107 |
WebLayer* getRootScrollLayer(WebViewImpl* webViewImpl) |
| 108 |
{ |
| 109 |
RenderLayerCompositor* compositor = webViewImpl->mainFrameImpl()->frame()->contentRenderer()->compositor(); |
| 110 |
ASSERT(compositor); |
| 111 |
ASSERT(compositor->scrollLayer()); |
| 112 |
|
| 113 |
WebLayer* webScrollLayer = static_cast<WebLayer*>(compositor->scrollLayer()->platformLayer()); |
| 114 |
return webScrollLayer; |
| 115 |
} |
| 116 |
|
| 117 |
protected: |
| 118 |
std::string m_baseURL; |
| 119 |
MockWebFrameClient m_mockWebFrameClient; |
| 120 |
MockWebViewClient m_mockWebViewClient; |
| 121 |
WebViewImpl* m_webViewImpl; |
| 122 |
}; |
| 123 |
|
| 124 |
TEST_F(ScrollingCoordinatorChromiumTest, fastScrollingByDefault) |
| 125 |
{ |
| 126 |
WebViewImpl* webViewImpl = createCompositedWebViewImpl("about:blank"); |
| 127 |
|
| 128 |
// Make sure the scrolling coordinator is active. |
| 129 |
FrameView* frameView = webViewImpl->mainFrameImpl()->frameView(); |
| 130 |
Page* page = webViewImpl->mainFrameImpl()->frame()->page(); |
| 131 |
ASSERT_TRUE(page->scrollingCoordinator()); |
| 132 |
ASSERT_TRUE(page->scrollingCoordinator()->coordinatesScrollingForFrameView(frameView)); |
| 133 |
|
| 134 |
// Fast scrolling should be enabled by default. |
| 135 |
WebLayer* rootScrollLayer = getRootScrollLayer(webViewImpl); |
| 136 |
ASSERT_TRUE(rootScrollLayer->scrollable()); |
| 137 |
ASSERT_FALSE(rootScrollLayer->shouldScrollOnMainThread()); |
| 138 |
ASSERT_FALSE(rootScrollLayer->haveWheelEventHandlers()); |
| 139 |
} |
| 140 |
|
| 141 |
TEST_F(ScrollingCoordinatorChromiumTest, fastScrollingForFixedPosition) |
| 142 |
{ |
| 143 |
registerMockedHttpURLLoad("fixed_position.html"); |
| 144 |
WebViewImpl* webViewImpl = createCompositedWebViewImpl(m_baseURL + "fixed_position.html"); |
| 145 |
|
| 146 |
Page* page = webViewImpl->mainFrameImpl()->frame()->page(); |
| 147 |
ASSERT_TRUE(page->scrollingCoordinator()->supportsFixedPositionLayers()); |
| 148 |
|
| 149 |
// Fixed position should not fall back to main thread scrolling. |
| 150 |
WebLayer* rootScrollLayer = getRootScrollLayer(webViewImpl); |
| 151 |
ASSERT_FALSE(rootScrollLayer->shouldScrollOnMainThread()); |
| 152 |
|
| 153 |
// Verify the properties of the fixed position element starting from the RenderObject all the |
| 154 |
// way to the LayerChromium. |
| 155 |
Element* fixedElement = webViewImpl->mainFrameImpl()->frame()->document()->getElementById("fixed"); |
| 156 |
ASSERT(fixedElement); |
| 157 |
|
| 158 |
RenderObject* renderer = fixedElement->renderer(); |
| 159 |
ASSERT_TRUE(renderer->isBoxModelObject()); |
| 160 |
ASSERT_TRUE(renderer->hasLayer()); |
| 161 |
|
| 162 |
RenderLayer* layer = toRenderBoxModelObject(renderer)->layer(); |
| 163 |
ASSERT_TRUE(layer->isComposited()); |
| 164 |
|
| 165 |
RenderLayerBacking* layerBacking = layer->backing(); |
| 166 |
WebLayer* webLayer = static_cast<WebLayer*>(layerBacking->graphicsLayer()->platformLayer()); |
| 167 |
ASSERT_TRUE(webLayer->fixedToContainerLayer()); |
| 168 |
} |
| 169 |
|
| 170 |
TEST_F(ScrollingCoordinatorChromiumTest, slowScrollingForNonCompositedFixedPosition) |
| 171 |
{ |
| 172 |
registerMockedHttpURLLoad("fixed_position_non_composited.html"); |
| 173 |
WebViewImpl* webViewImpl = createCompositedWebViewImpl(m_baseURL + "fixed_position_non_composited.html"); |
| 174 |
|
| 175 |
Page* page = webViewImpl->mainFrameImpl()->frame()->page(); |
| 176 |
ASSERT_TRUE(page->scrollingCoordinator()->supportsFixedPositionLayers()); |
| 177 |
|
| 178 |
// Non-composited fixed position should fall back to main thread scrolling. |
| 179 |
WebLayer* rootScrollLayer = getRootScrollLayer(webViewImpl); |
| 180 |
ASSERT_TRUE(rootScrollLayer->shouldScrollOnMainThread()); |
| 181 |
} |
| 182 |
|
| 183 |
TEST_F(ScrollingCoordinatorChromiumTest, nonFastScrollableRegion) |
| 184 |
{ |
| 185 |
registerMockedHttpURLLoad("non_fast_scrollable.html"); |
| 186 |
WebViewImpl* webViewImpl = createCompositedWebViewImpl(m_baseURL + "non_fast_scrollable.html"); |
| 187 |
|
| 188 |
WebLayer* rootScrollLayer = getRootScrollLayer(webViewImpl); |
| 189 |
WebVector<WebRect> nonFastScrollableRegion = rootScrollLayer->nonFastScrollableRegion(); |
| 190 |
|
| 191 |
ASSERT_EQ(1u, nonFastScrollableRegion.size()); |
| 192 |
ASSERT_EQ(WebRect(8, 8, 10, 10), nonFastScrollableRegion[0]); |
| 193 |
} |
| 194 |
|
| 195 |
TEST_F(ScrollingCoordinatorChromiumTest, wheelEventHandler) |
| 196 |
{ |
| 197 |
registerMockedHttpURLLoad("wheel_event_handler.html"); |
| 198 |
WebViewImpl* webViewImpl = createCompositedWebViewImpl(m_baseURL + "wheel_event_handler.html"); |
| 199 |
|
| 200 |
WebLayer* rootScrollLayer = getRootScrollLayer(webViewImpl); |
| 201 |
ASSERT_TRUE(rootScrollLayer->haveWheelEventHandlers()); |
| 202 |
} |
| 203 |
|
| 204 |
#if ENABLE(ACCELERATED_OVERFLOW_SCROLLING) |
| 205 |
TEST_F(ScrollingCoordinatorChromiumTest, touchOverflowScrolling) |
| 206 |
{ |
| 207 |
registerMockedHttpURLLoad("touch_overflow_scrolling.html"); |
| 208 |
WebViewImpl* webViewImpl = createCompositedWebViewImpl(m_baseURL + "touch_overflow_scrolling.html"); |
| 209 |
|
| 210 |
// Verify the properties of the accelerated scrolling element starting from the RenderObject |
| 211 |
// all the way to the LayerChromium. |
| 212 |
Element* scrollableElement = webViewImpl->mainFrameImpl()->frame()->document()->getElementById("scrollable"); |
| 213 |
ASSERT(scrollableElement); |
| 214 |
|
| 215 |
RenderObject* renderer = scrollableElement->renderer(); |
| 216 |
ASSERT_TRUE(renderer->isBoxModelObject()); |
| 217 |
ASSERT_TRUE(renderer->hasLayer()); |
| 218 |
|
| 219 |
RenderLayer* layer = toRenderBoxModelObject(renderer)->layer(); |
| 220 |
ASSERT_TRUE(layer->usesCompositedScrolling()); |
| 221 |
ASSERT_TRUE(layer->isComposited()); |
| 222 |
|
| 223 |
RenderLayerBacking* layerBacking = layer->backing(); |
| 224 |
ASSERT_TRUE(layerBacking->hasScrollingLayer()); |
| 225 |
ASSERT(layerBacking->scrollingContentsLayer()); |
| 226 |
|
| 227 |
GraphicsLayerChromium* layerChromium = static_cast<GraphicsLayerChromium*>(layerBacking->scrollingContentsLayer()); |
| 228 |
ASSERT_EQ(layer, layerChromium->scrollableArea()); |
| 229 |
|
| 230 |
WebLayer* webScrollLayer = static_cast<WebLayer*>(layerBacking->scrollingContentsLayer()->platformLayer()); |
| 231 |
ASSERT_TRUE(webScrollLayer->scrollable()); |
| 232 |
} |
| 233 |
#endif // ENABLE(ACCELERATED_OVERFLOW_SCROLLING) |
| 234 |
|
| 235 |
} // namespace |