1 /* 2 * Copyright (C) 2013 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 * 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. 13 * 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. 24 */ 25 26 #include "config.h" 27 28 #include "core/rendering/CompositedLayerMapping.h" 29 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" 43 44 #include <gtest/gtest.h> 45 46 using namespace blink; 47 48 namespace WebCore { 49 50 namespace { 51 52 class MockWebViewClient : public WebViewClient { 53 public: 54 virtual void initializeLayerTreeView() 55 { 56 m_layerTreeView = adoptPtr(Platform::current()->unitTestSupport()->createLayerTreeViewForTesting(WebUnitTestSupport::TestViewTypeUnitTest)); 57 ASSERT(m_layerTreeView); 58 } 59 60 virtual WebLayerTreeView* layerTreeView() 61 { 62 return m_layerTreeView.get(); 63 } 64 65 private: 66 OwnPtr<WebLayerTreeView> m_layerTreeView; 67 }; 68 69 class MockWebFrameClient : public WebFrameClient { 70 }; 71 72 class CompositedLayerMappingTest : public testing::Test { 73 public: 74 CompositedLayerMappingTest() 75 : m_baseURL("http://www.test.com/") 76 { 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)); 90 } 91 92 virtual void TearDown() 93 { 94 Platform::current()->unitTestSupport()->unregisterAllMockedURLs(); 95 m_webViewImpl->close(); 96 m_mainFrame->close(); 97 } 98 99 void navigateTo(const std::string& url) 100 { 101 FrameTestHelpers::loadFrame(m_webViewImpl->mainFrame(), url); 102 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); 103 } 104 105 void registerMockedHttpURLLoad(const std::string& fileName) 106 { 107 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8(fileName.c_str())); 108 } 109 110 protected: 111 std::string m_baseURL; 112 MockWebFrameClient m_mockWebFrameClient; 113 MockWebViewClient m_mockWebViewClient; 114 WebViewImpl* m_webViewImpl; 115 WebFrame* m_mainFrame; 116 }; 117 118 TEST_F(CompositedLayerMappingTest, DISABLED_GraphicsLayerBackgroundColor) 119 { 120 registerMockedHttpURLLoad("layer_background_color.html"); 121 navigateTo(m_baseURL + "layer_background_color.html"); 122 m_webViewImpl->layout(); 123 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()); 129 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()); 134 } 135 136 } 137 138 } // namespace WebCore 139