2 * Copyright (C) 2013 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #include "core/rendering/CompositedLayerMapping.h"
30 #include "FrameTestHelpers.h"
31 #include "URLTestHelpers.h"
32 #include "WebDocument.h"
33 #include "WebElement.h"
34 #include "WebFrameClient.h"
35 #include "WebFrameImpl.h"
36 #include "WebSettings.h"
37 #include "WebViewClient.h"
38 #include "WebViewImpl.h"
39 #include "core/dom/Document.h"
40 #include "core/frame/FrameView.h"
41 #include "public/platform/Platform.h"
42 #include "public/platform/WebUnitTestSupport.h"
44 #include <gtest/gtest.h>
46 using namespace blink;
52 class MockWebViewClient : public WebViewClient {
54 virtual void initializeLayerTreeView()
56 m_layerTreeView = adoptPtr(Platform::current()->unitTestSupport()->createLayerTreeViewForTesting(WebUnitTestSupport::TestViewTypeUnitTest));
57 ASSERT(m_layerTreeView);
60 virtual WebLayerTreeView* layerTreeView()
62 return m_layerTreeView.get();
66 OwnPtr<WebLayerTreeView> m_layerTreeView;
69 class MockWebFrameClient : public WebFrameClient {
72 class CompositedLayerMappingTest : public testing::Test {
74 CompositedLayerMappingTest()
75 : m_baseURL("http://www.test.com/")
77 // We cannot reuse FrameTestHelpers::createWebViewAndLoad here because the compositing
78 // settings need to be set before the page is loaded.
79 m_mainFrame = WebFrame::create(&m_mockWebFrameClient);
80 m_webViewImpl = toWebViewImpl(WebView::create(&m_mockWebViewClient));
81 m_webViewImpl->settings()->setForceCompositingMode(true);
82 m_webViewImpl->settings()->setAcceleratedCompositingEnabled(true);
83 m_webViewImpl->settings()->setAcceleratedCompositingForFixedPositionEnabled(true);
84 m_webViewImpl->settings()->setAcceleratedCompositingForOverflowScrollEnabled(true);
85 m_webViewImpl->settings()->setAcceleratedCompositingForScrollableFramesEnabled(true);
86 m_webViewImpl->settings()->setCompositedScrollingForFramesEnabled(true);
87 m_webViewImpl->settings()->setFixedPositionCreatesStackingContext(true);
88 m_webViewImpl->setMainFrame(m_mainFrame);
89 m_webViewImpl->resize(IntSize(320, 240));
92 virtual void TearDown()
94 Platform::current()->unitTestSupport()->unregisterAllMockedURLs();
95 m_webViewImpl->close();
99 void navigateTo(const std::string& url)
101 FrameTestHelpers::loadFrame(m_webViewImpl->mainFrame(), url);
102 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests();
105 void registerMockedHttpURLLoad(const std::string& fileName)
107 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8(fileName.c_str()));
111 std::string m_baseURL;
112 MockWebFrameClient m_mockWebFrameClient;
113 MockWebViewClient m_mockWebViewClient;
114 WebViewImpl* m_webViewImpl;
115 WebFrame* m_mainFrame;
118 TEST_F(CompositedLayerMappingTest, DISABLED_GraphicsLayerBackgroundColor)
120 registerMockedHttpURLLoad("layer_background_color.html");
121 navigateTo(m_baseURL + "layer_background_color.html");
122 m_webViewImpl->layout();
124 Document* document = m_webViewImpl->mainFrameImpl()->frame()->document();
125 Element* layerElement = document->getElementById("layer");
126 RenderLayerModelObject* renderer = toRenderLayerModelObject(layerElement->renderer());
127 EXPECT_EQ(renderer->style()->visitedDependentColor(CSSPropertyBackgroundColor),
128 renderer->layer()->compositedLayerMapping()->mainGraphicsLayer()->backgroundColor());
130 layerElement = document->getElementById("layer-solid-color");
131 renderer = toRenderLayerModelObject(layerElement->renderer());
132 // CompositedLayerMapping::graphicsLayer's background color is unset if SolidColorLayer is created.
133 EXPECT_EQ(Color(), renderer->layer()->compositedLayerMapping()->mainGraphicsLayer()->backgroundColor());
138 } // namespace WebCore