OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "config.h" |
| 6 |
| 7 #include "core/frame/FrameView.h" |
| 8 #include "core/layout/LayoutView.h" |
| 9 #include "core/layout/compositing/CompositedLayerMapping.h" |
| 10 #include "core/layout/compositing/PaintLayerCompositor.h" |
| 11 #include "core/page/Page.h" |
| 12 #include "platform/graphics/GraphicsLayer.h" |
| 13 #include "platform/testing/URLTestHelpers.h" |
| 14 #include "public/platform/Platform.h" |
| 15 #include "public/platform/WebCompositorMutableProperties.h" |
| 16 #include "public/platform/WebLayer.h" |
| 17 #include "public/platform/WebLayerTreeView.h" |
| 18 #include "public/platform/WebUnitTestSupport.h" |
| 19 #include "public/web/WebSettings.h" |
| 20 #include "public/web/WebViewClient.h" |
| 21 #include "web/WebLocalFrameImpl.h" |
| 22 #include "web/WebViewImpl.h" |
| 23 #include "web/tests/FrameTestHelpers.h" |
| 24 #include <gtest/gtest.h> |
| 25 |
| 26 namespace blink { |
| 27 |
| 28 class CompositorWorkerTest : public testing::Test { |
| 29 public: |
| 30 CompositorWorkerTest() |
| 31 : m_baseURL("http://www.test.com/") |
| 32 { |
| 33 RuntimeEnabledFeatures::setCompositorWorkerEnabled(true); |
| 34 m_helper.initialize(true, 0, &m_mockWebViewClient, &configureSettings); |
| 35 webViewImpl()->resize(IntSize(320, 240)); |
| 36 } |
| 37 |
| 38 ~CompositorWorkerTest() override |
| 39 { |
| 40 Platform::current()->unitTestSupport()->unregisterAllMockedURLs(); |
| 41 } |
| 42 |
| 43 void navigateTo(const String& url) |
| 44 { |
| 45 FrameTestHelpers::loadFrame(webViewImpl()->mainFrame(), url.utf8().data(
)); |
| 46 } |
| 47 |
| 48 void forceFullCompositingUpdate() |
| 49 { |
| 50 webViewImpl()->updateAllLifecyclePhases(); |
| 51 } |
| 52 |
| 53 void registerMockedHttpURLLoad(const std::string& fileName) |
| 54 { |
| 55 URLTestHelpers::registerMockedURLFromBaseURL(m_baseURL, WebString::fromU
TF8(fileName.c_str())); |
| 56 } |
| 57 |
| 58 WebLayer* getRootScrollLayer() |
| 59 { |
| 60 PaintLayerCompositor* compositor = frame()->contentLayoutObject()->compo
sitor(); |
| 61 ASSERT(compositor); |
| 62 ASSERT(compositor->scrollLayer()); |
| 63 |
| 64 WebLayer* webScrollLayer = compositor->scrollLayer()->platformLayer(); |
| 65 return webScrollLayer; |
| 66 } |
| 67 |
| 68 WebViewImpl* webViewImpl() const { return m_helper.webViewImpl(); } |
| 69 LocalFrame* frame() const { return m_helper.webViewImpl()->mainFrameImpl()->
frame(); } |
| 70 |
| 71 protected: |
| 72 String m_baseURL; |
| 73 FrameTestHelpers::TestWebViewClient m_mockWebViewClient; |
| 74 |
| 75 private: |
| 76 static void configureSettings(WebSettings* settings) |
| 77 { |
| 78 settings->setJavaScriptEnabled(true); |
| 79 settings->setAcceleratedCompositingEnabled(true); |
| 80 settings->setPreferCompositingToLCDTextEnabled(true); |
| 81 } |
| 82 |
| 83 FrameTestHelpers::WebViewHelper m_helper; |
| 84 FrameTestHelpers::UseMockScrollbarSettings m_mockScrollbarSettings; |
| 85 }; |
| 86 |
| 87 static CompositedLayerMapping* mappingFromElement(Element* element) |
| 88 { |
| 89 if (!element) |
| 90 return nullptr; |
| 91 LayoutObject* layoutObject = element->layoutObject(); |
| 92 if (!layoutObject || !layoutObject->isBoxModelObject()) |
| 93 return nullptr; |
| 94 PaintLayer* layer = toLayoutBoxModelObject(layoutObject)->layer(); |
| 95 if (!layer) |
| 96 return nullptr; |
| 97 if (!layer->hasCompositedLayerMapping()) |
| 98 return nullptr; |
| 99 return layer->compositedLayerMapping(); |
| 100 } |
| 101 |
| 102 static WebLayer* webLayerFromGraphicsLayer(GraphicsLayer* graphicsLayer) |
| 103 { |
| 104 if (!graphicsLayer) |
| 105 return nullptr; |
| 106 return graphicsLayer->platformLayer(); |
| 107 } |
| 108 |
| 109 static WebLayer* scrollingWebLayerFromElement(Element* element) |
| 110 { |
| 111 CompositedLayerMapping* compositedLayerMapping = mappingFromElement(element)
; |
| 112 if (!compositedLayerMapping) |
| 113 return nullptr; |
| 114 return webLayerFromGraphicsLayer(compositedLayerMapping->scrollingContentsLa
yer()); |
| 115 } |
| 116 |
| 117 static WebLayer* webLayerFromElement(Element* element) |
| 118 { |
| 119 CompositedLayerMapping* compositedLayerMapping = mappingFromElement(element)
; |
| 120 if (!compositedLayerMapping) |
| 121 return nullptr; |
| 122 return webLayerFromGraphicsLayer(compositedLayerMapping->mainGraphicsLayer()
); |
| 123 } |
| 124 |
| 125 TEST_F(CompositorWorkerTest, plumbingElementIdAndMutableProperties) |
| 126 { |
| 127 registerMockedHttpURLLoad("compositor-proxy-basic.html"); |
| 128 navigateTo(m_baseURL + "compositor-proxy-basic.html"); |
| 129 |
| 130 forceFullCompositingUpdate(); |
| 131 |
| 132 Document* document = frame()->document(); |
| 133 |
| 134 Element* tallElement = document->getElementById("tall"); |
| 135 WebLayer* tallLayer = webLayerFromElement(tallElement); |
| 136 EXPECT_TRUE(!tallLayer); |
| 137 |
| 138 Element* proxiedElement = document->getElementById("proxied"); |
| 139 WebLayer* proxiedLayer = webLayerFromElement(proxiedElement); |
| 140 EXPECT_TRUE(proxiedLayer->compositorMutableProperties() & WebCompositorMutab
lePropertyTransform); |
| 141 EXPECT_FALSE(proxiedLayer->compositorMutableProperties() & (WebCompositorMut
ablePropertyScrollLeft | WebCompositorMutablePropertyScrollTop | WebCompositorMu
tablePropertyOpacity)); |
| 142 EXPECT_NE(0UL, proxiedLayer->elementId()); |
| 143 |
| 144 Element* scrollElement = document->getElementById("proxied-scroller"); |
| 145 WebLayer* scrollLayer = scrollingWebLayerFromElement(scrollElement); |
| 146 EXPECT_TRUE(scrollLayer->compositorMutableProperties() & (WebCompositorMutab
lePropertyScrollLeft | WebCompositorMutablePropertyScrollTop)); |
| 147 EXPECT_FALSE(scrollLayer->compositorMutableProperties() & (WebCompositorMuta
blePropertyTransform | WebCompositorMutablePropertyOpacity)); |
| 148 EXPECT_NE(0UL, scrollLayer->elementId()); |
| 149 |
| 150 WebLayer* rootScrollLayer = getRootScrollLayer(); |
| 151 EXPECT_TRUE(rootScrollLayer->compositorMutableProperties() & (WebCompositorM
utablePropertyScrollLeft | WebCompositorMutablePropertyScrollTop)); |
| 152 EXPECT_FALSE(rootScrollLayer->compositorMutableProperties() & (WebCompositor
MutablePropertyTransform | WebCompositorMutablePropertyOpacity)); |
| 153 |
| 154 EXPECT_NE(0UL, rootScrollLayer->elementId()); |
| 155 } |
| 156 |
| 157 TEST_F(CompositorWorkerTest, noProxies) |
| 158 { |
| 159 // This case is identical to compositor-proxy-basic, but no proxies have |
| 160 // actually been created. |
| 161 registerMockedHttpURLLoad("compositor-proxy-plumbing-no-proxies.html"); |
| 162 navigateTo(m_baseURL + "compositor-proxy-plumbing-no-proxies.html"); |
| 163 |
| 164 forceFullCompositingUpdate(); |
| 165 |
| 166 Document* document = frame()->document(); |
| 167 |
| 168 Element* tallElement = document->getElementById("tall"); |
| 169 WebLayer* tallLayer = webLayerFromElement(tallElement); |
| 170 EXPECT_TRUE(!tallLayer); |
| 171 |
| 172 Element* proxiedElement = document->getElementById("proxied"); |
| 173 WebLayer* proxiedLayer = webLayerFromElement(proxiedElement); |
| 174 EXPECT_TRUE(!proxiedLayer); |
| 175 |
| 176 Element* scrollElement = document->getElementById("proxied-scroller"); |
| 177 WebLayer* scrollLayer = scrollingWebLayerFromElement(scrollElement); |
| 178 EXPECT_FALSE(!!scrollLayer->compositorMutableProperties()); |
| 179 EXPECT_EQ(0UL, scrollLayer->elementId()); |
| 180 |
| 181 WebLayer* rootScrollLayer = getRootScrollLayer(); |
| 182 EXPECT_FALSE(!!rootScrollLayer->compositorMutableProperties()); |
| 183 EXPECT_EQ(0UL, rootScrollLayer->elementId()); |
| 184 } |
| 185 |
| 186 TEST_F(CompositorWorkerTest, disconnectedProxies) |
| 187 { |
| 188 // This case is identical to compositor-proxy-basic, but the proxies are |
| 189 // disconnected (the result should be the same as compositor-proxy-plumbing-
no-proxies). |
| 190 registerMockedHttpURLLoad("compositor-proxy-basic-disconnected.html"); |
| 191 navigateTo(m_baseURL + "compositor-proxy-basic-disconnected.html"); |
| 192 |
| 193 forceFullCompositingUpdate(); |
| 194 |
| 195 Document* document = frame()->document(); |
| 196 |
| 197 Element* tallElement = document->getElementById("tall"); |
| 198 WebLayer* tallLayer = webLayerFromElement(tallElement); |
| 199 EXPECT_TRUE(!tallLayer); |
| 200 |
| 201 Element* proxiedElement = document->getElementById("proxied"); |
| 202 WebLayer* proxiedLayer = webLayerFromElement(proxiedElement); |
| 203 EXPECT_TRUE(!proxiedLayer); |
| 204 |
| 205 Element* scrollElement = document->getElementById("proxied-scroller"); |
| 206 WebLayer* scrollLayer = scrollingWebLayerFromElement(scrollElement); |
| 207 EXPECT_FALSE(!!scrollLayer->compositorMutableProperties()); |
| 208 EXPECT_EQ(0UL, scrollLayer->elementId()); |
| 209 |
| 210 WebLayer* rootScrollLayer = getRootScrollLayer(); |
| 211 EXPECT_FALSE(!!rootScrollLayer->compositorMutableProperties()); |
| 212 EXPECT_EQ(0UL, rootScrollLayer->elementId()); |
| 213 } |
| 214 |
| 215 } // namespace blink |
OLD | NEW |