| 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 0c10d6476898f9653f5a072f21a8d7181705e8d8..c9285aaa81370a02c433dc2527fc8971888e0b73 100644
|
| --- a/third_party/WebKit/Source/platform/graphics/CompositorMutatorClientTest.cpp
|
| +++ b/third_party/WebKit/Source/platform/graphics/CompositorMutatorClientTest.cpp
|
| @@ -6,6 +6,18 @@
|
|
|
| #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"
|
| @@ -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()
|
| + : compositor_frame_sink_(cc::FakeCompositorFrameSink::Create3d()) {
|
| + cc::LayerTreeSettings settings;
|
| + settings.layer_transforms_should_scale_layer_contents = true;
|
| + host_impl_.reset(new cc::FakeLayerTreeHostImpl(
|
| + settings, &task_runner_provider_, &task_graph_runner_));
|
| + host_impl_->SetVisible(true);
|
| + EXPECT_TRUE(host_impl_->InitializeRenderer(compositor_frame_sink_.get()));
|
| + }
|
| +
|
| + cc::FakeLayerTreeHostImpl& hostImpl() { return *host_impl_; }
|
| +
|
| + 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 message_loop_;
|
| + cc::TestTaskGraphRunner task_graph_runner_;
|
| + cc::FakeImplTaskRunnerProvider task_runner_provider_;
|
| + std::unique_ptr<cc::FakeCompositorFrameSink> compositor_frame_sink_;
|
| + std::unique_ptr<cc::FakeLayerTreeHostImpl> host_impl_;
|
| +};
|
| +
|
| +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::kPrimary));
|
| + 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::kScroll));
|
| + 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
|
|
|