Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(34)

Unified Diff: third_party/WebKit/Source/platform/graphics/CompositorMutatorClientTest.cpp

Issue 2765053002: Avoid exposing cc::Layer tree to CompositorProxy (Closed)
Patch Set: Minor changes Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/platform/graphics/CompositorMutatorClientTest.cpp
diff --git a/third_party/WebKit/Source/platform/graphics/CompositorMutatorClientTest.cpp b/third_party/WebKit/Source/platform/graphics/CompositorMutatorClientTest.cpp
index 2e51228aff69a0a4b13682ea945ae5ebb2d244fb..a1192d0f3377f16dc10ddd98258d88f76633f9ed 100644
--- a/third_party/WebKit/Source/platform/graphics/CompositorMutatorClientTest.cpp
+++ b/third_party/WebKit/Source/platform/graphics/CompositorMutatorClientTest.cpp
@@ -4,14 +4,26 @@
#include "platform/graphics/CompositorMutatorClient.h"
+#include <memory>
#include "base/callback.h"
+#include "base/message_loop/message_loop.h"
+#include "base/time/time.h"
+#include "cc/test/fake_compositor_frame_sink.h"
+#include "cc/test/fake_impl_task_runner_provider.h"
+#include "cc/test/fake_layer_tree_host_impl.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/CompositorElementId.h"
+#include "platform/graphics/CompositorMutableState.h"
+#include "platform/graphics/CompositorMutableStateProvider.h"
#include "platform/graphics/CompositorMutation.h"
#include "platform/graphics/CompositorMutationsTarget.h"
#include "platform/graphics/CompositorMutator.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "wtf/PtrUtil.h"
-#include <memory>
using ::testing::_;
@@ -28,13 +40,43 @@ class StubCompositorMutator : public CompositorMutator {
}
};
-class MockCompositoMutationsTarget : public CompositorMutationsTarget {
+class MockCompositorMutator : public CompositorMutator {
+ public:
+ MOCK_METHOD2(mutate, bool(double, CompositorMutableStateProvider*));
+};
+
+class MockCompositorMutationsTarget : public CompositorMutationsTarget {
public:
MOCK_METHOD1(applyMutations, void(CompositorMutations*));
};
-TEST(CompositorMutatorClient, CallbackForNonNullMutationsShouldApply) {
- MockCompositoMutationsTarget target;
+class CompositorMutatorClientTest : public testing::Test {
+ public:
+ CompositorMutatorClientTest()
+ : m_compositorFrameSink(cc::FakeCompositorFrameSink::Create3d()) {
+ cc::LayerTreeSettings settings;
+ settings.layer_transforms_should_scale_layer_contents = true;
+ m_hostImpl.reset(new cc::FakeLayerTreeHostImpl(
+ settings, &m_taskRunnerProvider, &m_taskGraphRunner));
+ m_hostImpl->SetVisible(true);
+ EXPECT_TRUE(m_hostImpl->InitializeRenderer(m_compositorFrameSink.get()));
+ }
+
+ cc::FakeLayerTreeHostImpl& hostImpl() { return *m_hostImpl; }
+
+ private:
+ // The cc testing machinery has fairly deep dependency on having a main
+ // message loop (one example is the task runner provider). We construct one
+ // here so that it's installed in TLA and can be found by other cc classes.
+ base::MessageLoop m_messageLoop;
+ cc::TestTaskGraphRunner m_taskGraphRunner;
+ cc::FakeImplTaskRunnerProvider m_taskRunnerProvider;
+ std::unique_ptr<cc::FakeCompositorFrameSink> m_compositorFrameSink;
+ std::unique_ptr<cc::FakeLayerTreeHostImpl> m_hostImpl;
+};
+
+TEST_F(CompositorMutatorClientTest, CallbackForNonNullMutationsShouldApply) {
+ MockCompositorMutationsTarget target;
CompositorMutatorClient client(new StubCompositorMutator, &target);
std::unique_ptr<CompositorMutations> mutations =
@@ -45,13 +87,99 @@ TEST(CompositorMutatorClient, CallbackForNonNullMutationsShouldApply) {
client.TakeMutations().Run();
}
-TEST(CompositorMutatorClient, CallbackForNullMutationsShouldBeNoop) {
- MockCompositoMutationsTarget target;
+TEST_F(CompositorMutatorClientTest, CallbackForNullMutationsShouldBeNoop) {
+ MockCompositorMutationsTarget target;
CompositorMutatorClient client(new StubCompositorMutator, &target);
EXPECT_CALL(target, applyMutations(_)).Times(0);
EXPECT_TRUE(client.TakeMutations().is_null());
}
+TEST_F(CompositorMutatorClientTest, MutateOneProxy) {
+ MockCompositorMutationsTarget target;
+ MockCompositorMutator mutator;
+ CompositorMutatorClient client(&mutator, &target);
+
+ uint64_t proxyId = 12;
+ uint64_t elementId = 15;
+ uint32_t mutableProperties = CompositorMutableProperty::kOpacity |
+ CompositorMutableProperty::kTransform |
+ CompositorMutableProperty::kScrollLeft |
+ CompositorMutableProperty::kScrollTop;
+ client.registerCompositorProxy(proxyId, elementId, mutableProperties);
+
+ std::unique_ptr<cc::LayerImpl> root =
+ cc::LayerImpl::Create(hostImpl().active_tree(), 42);
+ std::unique_ptr<cc::LayerImpl> scroll =
+ cc::LayerImpl::Create(hostImpl().active_tree(), 11);
+ cc::LayerImpl* scrollLayer = scroll.get();
+ cc::LayerImpl* rootLayer = root.get();
+
+ root->test_properties()->AddChild(std::move(scroll));
+ root->SetElementId(
+ createCompositorElementId(elementId, CompositorSubElementId::Primary));
+ root->SetMutableProperties(CompositorMutableProperty::kOpacity |
+ CompositorMutableProperty::kTransform);
+
+ scrollLayer->SetScrollClipLayer(root->id());
+ scrollLayer->test_properties()->transform = gfx::Transform();
+ scrollLayer->SetPosition(gfx::PointF());
+ scrollLayer->SetBounds(gfx::Size(100, 100));
+ scrollLayer->SetDrawsContent(true);
+ scrollLayer->SetElementId(
+ createCompositorElementId(elementId, CompositorSubElementId::Scroll));
+ scrollLayer->SetMutableProperties(CompositorMutableProperty::kScrollLeft |
+ CompositorMutableProperty::kScrollTop);
+
+ hostImpl().SetViewportSize(scrollLayer->bounds());
+ hostImpl().active_tree()->SetRootLayerForTesting(std::move(root));
+ hostImpl().UpdateNumChildrenAndDrawPropertiesForActiveTree();
+
+ gfx::Transform zero(0, 0, 0, 0, 0, 0);
+ EXPECT_CALL(mutator, mutate(_, _))
+ .WillOnce(testing::Invoke(
+ [zero, proxyId](double now,
+ CompositorMutableStateProvider* stateProvider) {
+ std::unique_ptr<CompositorMutableState> mutableState =
+ stateProvider->getMutableStateFor(proxyId);
+ EXPECT_TRUE(mutableState);
+ EXPECT_EQ(gfx::Transform().ToString(),
+ gfx::Transform(mutableState->transform()).ToString());
+ EXPECT_EQ(0, mutableState->scrollLeft());
+ EXPECT_EQ(0, mutableState->scrollTop());
+
+ mutableState->setOpacity(0.5);
+ mutableState->setTransform(zero.matrix());
+ mutableState->setScrollLeft(10);
+ mutableState->setScrollTop(20);
+ return false;
+ }));
+ client.Mutate(base::TimeTicks(), hostImpl().active_tree());
+
+ EXPECT_EQ(0.5, rootLayer->Opacity());
+ EXPECT_EQ(zero.ToString(), rootLayer->Transform().ToString());
+ EXPECT_EQ(10, scrollLayer->CurrentScrollOffset().x());
+ EXPECT_EQ(20, scrollLayer->CurrentScrollOffset().y());
+
+ EXPECT_CALL(target, applyMutations(_))
+ .WillOnce(
+ testing::Invoke([elementId, zero](CompositorMutations* mutations) {
+ EXPECT_EQ(1ul, mutations->map.size());
+ const CompositorMutation& mutation =
+ *mutations->map.find(elementId)->value;
+ 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(10, mutation.scrollLeft());
+ EXPECT_EQ(20, mutation.scrollTop());
+ }));
+ client.TakeMutations().Run();
+}
+
} // namespace
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698