Chromium Code Reviews| Index: third_party/WebKit/Source/platform/graphics/CompositorMutableStateTest.cpp |
| diff --git a/third_party/WebKit/Source/platform/graphics/CompositorMutableStateTest.cpp b/third_party/WebKit/Source/platform/graphics/CompositorMutableStateTest.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..0ad48ae39f128bf09332e4399b1d40da0fd70f1f |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/platform/graphics/CompositorMutableStateTest.cpp |
| @@ -0,0 +1,156 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "platform/graphics/CompositorMutableState.h" |
| + |
| +#include "base/message_loop/message_loop.h" |
| +#include "cc/test/fake_impl_task_runner_provider.h" |
| +#include "cc/test/fake_layer_tree_host_impl.h" |
| +#include "cc/test/fake_output_surface.h" |
| +#include "cc/test/test_shared_bitmap_manager.h" |
| +#include "cc/test/test_task_graph_runner.h" |
| +#include "cc/trees/layer_tree_host_impl.h" |
| +#include "cc/trees/layer_tree_impl.h" |
| +#include "platform/graphics/CompositorMutableProperties.h" |
| +#include "platform/graphics/CompositorMutableStateProvider.h" |
| +#include "platform/graphics/CompositorMutation.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| +#include "wtf/OwnPtr.h" |
| + |
| +namespace blink { |
| + |
| +using cc::FakeImplTaskRunnerProvider; |
| +using cc::FakeLayerTreeHostImpl; |
| +using cc::FakeOutputSurface; |
| +using cc::LayerImpl; |
| +using cc::LayerTreeSettings; |
| +using cc::OutputSurface; |
| +using cc::TestTaskGraphRunner; |
| +using cc::TestSharedBitmapManager; |
| + |
| +class CompositorMutableStateTest : public testing::Test { |
| +public: |
| + CompositorMutableStateTest() |
| + : m_outputSurface(FakeOutputSurface::Create3d()) |
| + { |
| + LayerTreeSettings settings; |
| + settings.layer_transforms_should_scale_layer_contents = true; |
| + settings.verify_property_trees = true; |
| + m_hostImpl.reset(new FakeLayerTreeHostImpl(settings, &m_taskRunnerProvider, &m_sharedBitmapManager, &m_taskGraphRunner)); |
| + m_hostImpl->SetVisible(true); |
| + EXPECT_TRUE(m_hostImpl->InitializeRenderer(m_outputSurface.get())); |
| + } |
| + |
| + void SetLayerPropertiesForTesting(LayerImpl* layer) |
| + { |
| + layer->SetTransform(gfx::Transform()); |
| + layer->SetTransformOrigin(gfx::Point3F()); |
| + layer->SetPosition(gfx::PointF()); |
| + layer->SetBounds(gfx::Size(100, 100)); |
| + layer->SetShouldFlattenTransform(true); |
| + layer->Set3dSortingContextId(0); |
| + layer->SetForceRenderSurface(true); |
| + layer->SetDrawsContent(true); |
| + } |
| + |
| + FakeLayerTreeHostImpl& hostImpl() { return *m_hostImpl; } |
| + |
| + LayerImpl* rootLayer() { return m_hostImpl->active_tree()->root_layer(); } |
| + |
| +private: |
| + base::MessageLoop m_messageLoop; |
|
jbroman
2016/01/18 19:07:22
At least a comment explaining why this message loo
Ian Vollick
2016/01/18 21:25:04
Done.
|
| + TestSharedBitmapManager m_sharedBitmapManager; |
| + TestTaskGraphRunner m_taskGraphRunner; |
| + FakeImplTaskRunnerProvider m_taskRunnerProvider; |
| + scoped_ptr<OutputSurface> m_outputSurface; |
| + scoped_ptr<FakeLayerTreeHostImpl> m_hostImpl; |
| +}; |
| + |
| +TEST_F(CompositorMutableStateTest, NoMutableState) |
| +{ |
| + // In this test, there are no layers with either an element id or mutable |
| + // properties. We should not be able to get any mutable state. |
| + scoped_ptr<LayerImpl> root = LayerImpl::Create(hostImpl().active_tree(), 42); |
| + SetLayerPropertiesForTesting(root.get()); |
| + |
| + hostImpl().SetViewportSize(root->bounds()); |
| + hostImpl().active_tree()->SetRootLayer(std::move(root)); |
| + hostImpl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); |
| + |
| + CompositorMutations mutations; |
| + CompositorMutableStateProvider provider(hostImpl().active_tree(), &mutations); |
| + OwnPtr<CompositorMutableState> state(provider.getMutableStateFor(42)); |
| + EXPECT_FALSE(state); |
| +} |
| + |
| +TEST_F(CompositorMutableStateTest, MutableStateNoMutableProperties) |
| +{ |
| + // In this test, there is a layer with an element id, but no mutable |
| + // properties. This should behave just as if we'd had no element id. |
| + scoped_ptr<LayerImpl> root = LayerImpl::Create(hostImpl().active_tree(), 42); |
| + SetLayerPropertiesForTesting(root.get()); |
| + root->SetElementId(42); |
| + |
| + hostImpl().SetViewportSize(root->bounds()); |
| + hostImpl().active_tree()->SetRootLayer(std::move(root)); |
| + hostImpl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); |
| + |
| + CompositorMutations mutations; |
| + CompositorMutableStateProvider provider(hostImpl().active_tree(), &mutations); |
| + OwnPtr<CompositorMutableState> state(provider.getMutableStateFor(42)); |
| + EXPECT_FALSE(state); |
| +} |
| + |
| +TEST_F(CompositorMutableStateTest, MutableStateMutableProperties) |
| +{ |
| + // In this test, there is a layer with an element id and mutable properties. |
| + // In this case, we should get a valid mutable state for this element id that |
| + // has a real effect on the corresponding layer. |
| + scoped_ptr<LayerImpl> root = LayerImpl::Create(hostImpl().active_tree(), 42); |
| + SetLayerPropertiesForTesting(root.get()); |
| + root->SetElementId(42); |
| + root->SetMutableProperties(CompositorMutablePropertyOpacity | CompositorMutablePropertyTransform | CompositorMutablePropertyScrollLeft | CompositorMutablePropertyScrollTop); |
| + |
| + hostImpl().SetViewportSize(root->bounds()); |
| + hostImpl().active_tree()->SetRootLayer(std::move(root)); |
| + hostImpl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); |
| + |
| + CompositorMutations mutations; |
| + CompositorMutableStateProvider provider(hostImpl().active_tree(), &mutations); |
| + |
| + OwnPtr<CompositorMutableState> state(provider.getMutableStateFor(42)); |
| + EXPECT_TRUE(state.get()); |
| + |
| + EXPECT_EQ(1.0, rootLayer()->opacity()); |
| + EXPECT_EQ(gfx::Transform().ToString(), rootLayer()->transform().ToString()); |
| + EXPECT_EQ(0.0, rootLayer()->CurrentScrollOffset().x()); |
| + EXPECT_EQ(0.0, rootLayer()->CurrentScrollOffset().y()); |
| + |
| + gfx::Transform zero(0, 0, 0, 0, 0, 0); |
| + state->setOpacity(0.5); |
| + state->setTransform(zero.matrix()); |
| + state->setScrollLeft(1.0); |
| + state->setScrollTop(1.0); |
| + |
| + EXPECT_EQ(0.5, rootLayer()->opacity()); |
| + EXPECT_EQ(zero.ToString(), rootLayer()->transform().ToString()); |
| + EXPECT_EQ(1.0, rootLayer()->CurrentScrollOffset().x()); |
| + EXPECT_EQ(1.0, rootLayer()->CurrentScrollOffset().y()); |
| + |
| + // The corresponding mutation should reflect the changed values. |
| + EXPECT_EQ(1ul, mutations.map.size()); |
| + |
| + const CompositorMutation& mutation = mutations.map[42]; |
| + EXPECT_TRUE(mutation.isOpacityMutated()); |
| + EXPECT_TRUE(mutation.isTransformMutated()); |
| + EXPECT_TRUE(mutation.isScrollLeftMutated()); |
| + EXPECT_TRUE(mutation.isScrollTopMutated()); |
| + |
| + EXPECT_EQ(0.5, mutation.opacity()); |
| + EXPECT_EQ(zero.ToString(), gfx::Transform(mutation.transform()).ToString()); |
| + EXPECT_EQ(1.0, mutation.scrollLeft()); |
| + EXPECT_EQ(1.0, mutation.scrollTop()); |
| +} |
| + |
| +} // namespace blink |