153e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)/*
253e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) * Copyright (C) 2013 Google Inc. All rights reserved.
353e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) *
453e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) * Redistribution and use in source and binary forms, with or without
553e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) * modification, are permitted provided that the following conditions
653e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) * are met:
753e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) *
853e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) * 1.  Redistributions of source code must retain the above copyright
953e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) *     notice, this list of conditions and the following disclaimer.
1053e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) * 2.  Redistributions in binary form must reproduce the above copyright
1153e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) *     notice, this list of conditions and the following disclaimer in the
1253e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) *     documentation and/or other materials provided with the distribution.
1353e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) *
1453e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
1553e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
1653e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
1753e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
1853e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
1953e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
2053e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
2153e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2253e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2353e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2453e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) */
2553e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
2653e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "config.h"
2753e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
2853e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/rendering/RenderLayerBacking.h"
2953e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
3053e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include <gtest/gtest.h>
3153e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "FrameTestHelpers.h"
3253e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "URLTestHelpers.h"
3353e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "WebDocument.h"
3453e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "WebElement.h"
3553e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "WebFrameClient.h"
3653e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "WebFrameImpl.h"
3753e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "WebSettings.h"
3853e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "WebViewClient.h"
3953e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "WebViewImpl.h"
4053e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/dom/Document.h"
4153e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/page/FrameView.h"
425267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)#include "public/platform/Platform.h"
435267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)#include "public/platform/WebUnitTestSupport.h"
4453e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
4553e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)using namespace WebKit;
4653e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
4753e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)namespace WebCore {
4853e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
4953e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)namespace {
5053e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
5153e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)class MockWebViewClient : public WebViewClient {
5253e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)public:
5353e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    virtual void initializeLayerTreeView()
5453e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    {
5553e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)        m_layerTreeView = adoptPtr(Platform::current()->unitTestSupport()->createLayerTreeViewForTesting(WebUnitTestSupport::TestViewTypeUnitTest));
5653e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)        ASSERT(m_layerTreeView);
5753e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    }
5853e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
5953e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    virtual WebLayerTreeView* layerTreeView()
6053e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    {
6153e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)        return m_layerTreeView.get();
6253e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    }
6353e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
6453e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)private:
6553e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    OwnPtr<WebLayerTreeView> m_layerTreeView;
6653e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)};
6753e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
6853e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)class MockWebFrameClient : public WebFrameClient {
6953e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)};
7053e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
7153e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)class RenderLayerBackingTest : public testing::Test {
7253e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)public:
7353e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    RenderLayerBackingTest()
7453e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)        : m_baseURL("http://www.test.com/")
7553e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    {
7653e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)        // We cannot reuse FrameTestHelpers::createWebViewAndLoad here because the compositing
7753e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)        // settings need to be set before the page is loaded.
7853e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)        m_webViewImpl = static_cast<WebViewImpl*>(WebView::create(&m_mockWebViewClient));
7953e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)        m_webViewImpl->settings()->setForceCompositingMode(true);
8053e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)        m_webViewImpl->settings()->setAcceleratedCompositingEnabled(true);
8153e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)        m_webViewImpl->settings()->setAcceleratedCompositingForFixedPositionEnabled(true);
8253e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)        m_webViewImpl->settings()->setAcceleratedCompositingForOverflowScrollEnabled(true);
8353e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)        m_webViewImpl->settings()->setAcceleratedCompositingForScrollableFramesEnabled(true);
8453e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)        m_webViewImpl->settings()->setCompositedScrollingForFramesEnabled(true);
8553e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)        m_webViewImpl->settings()->setFixedPositionCreatesStackingContext(true);
8653e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)        m_webViewImpl->initializeMainFrame(&m_mockWebFrameClient);
8753e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)        m_webViewImpl->resize(IntSize(320, 240));
8853e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    }
8953e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
9053e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    virtual void TearDown()
9153e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    {
9253e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)        Platform::current()->unitTestSupport()->unregisterAllMockedURLs();
9353e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)        m_webViewImpl->close();
9453e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    }
9553e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
9653e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    void navigateTo(const std::string& url)
9753e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    {
9853e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)        FrameTestHelpers::loadFrame(m_webViewImpl->mainFrame(), url);
9953e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)        Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests();
10053e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    }
10153e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
10253e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    void registerMockedHttpURLLoad(const std::string& fileName)
10353e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    {
10453e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)        URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8(fileName.c_str()));
10553e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    }
10653e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
10753e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)protected:
10853e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    std::string m_baseURL;
10953e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    MockWebFrameClient m_mockWebFrameClient;
11053e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    MockWebViewClient m_mockWebViewClient;
11153e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    WebViewImpl* m_webViewImpl;
11253e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)};
11353e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
11453e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)TEST_F(RenderLayerBackingTest, DISABLED_GraphicsLayerBackgroundColor)
11553e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles){
11653e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    registerMockedHttpURLLoad("layer_background_color.html");
11753e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    navigateTo(m_baseURL + "layer_background_color.html");
11853e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    m_webViewImpl->layout();
11953e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
12053e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    Document* document = m_webViewImpl->mainFrameImpl()->frame()->document();
12153e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    Element* layerElement = document->getElementById("layer");
12253e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    RenderLayerModelObject* renderer = toRenderLayerModelObject(layerElement->renderer());
12353e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    EXPECT_EQ(renderer->style()->visitedDependentColor(CSSPropertyBackgroundColor),
12453e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)              renderer->layer()->backing()->graphicsLayer()->backgroundColor());
12553e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
12653e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    layerElement = document->getElementById("layer-solid-color");
12753e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    renderer = toRenderLayerModelObject(layerElement->renderer());
12853e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    // RenderLayerBacking::graphicsLayer's background color is unset if SolidColorLayer is created.
12953e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    EXPECT_EQ(Color(), renderer->layer()->backing()->graphicsLayer()->backgroundColor());
13053e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)}
13153e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
13253e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)}
13353e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
13453e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)} // namespace WebCore
135