Chromium Code Reviews| Index: cc/blimp/layer_tree_host_remote_unittest.cc |
| diff --git a/cc/blimp/layer_tree_host_remote_unittest.cc b/cc/blimp/layer_tree_host_remote_unittest.cc |
| index 8cd6d6d439db2426ab6048250d5deecd98a415aa..6976bdd47f7d2d0a05e3634569bbe547f955728d 100644 |
| --- a/cc/blimp/layer_tree_host_remote_unittest.cc |
| +++ b/cc/blimp/layer_tree_host_remote_unittest.cc |
| @@ -4,14 +4,18 @@ |
| #include "cc/blimp/layer_tree_host_remote.h" |
| +#include <memory> |
| + |
| #include "base/bind.h" |
| #include "base/run_loop.h" |
| #include "base/threading/thread_task_runner_handle.h" |
| #include "cc/animation/animation_host.h" |
| #include "cc/layers/layer.h" |
| #include "cc/output/begin_frame_args.h" |
| +#include "cc/proto/compositor_message.pb.h" |
| #include "cc/test/fake_image_serialization_processor.h" |
| #include "cc/test/fake_remote_compositor_bridge.h" |
| +#include "cc/test/push_properties_counting_layer.h" |
| #include "cc/test/stub_layer_tree_host_client.h" |
| #include "cc/trees/layer_tree_settings.h" |
| #include "testing/gmock/include/gmock/gmock.h" |
| @@ -48,6 +52,9 @@ class UpdateTrackingRemoteCompositorBridge : public FakeRemoteCompositorBridge { |
| void ProcessCompositorStateUpdate( |
| std::unique_ptr<CompositorProtoState> compositor_proto_state) override { |
| num_updates_received_++; |
| + |
| + // Cache the proto here for verification. |
| + compositor_proto_state_ = std::move(compositor_proto_state); |
|
Khushal
2016/10/31 23:43:27
This looks perfect. Thanks! :)
|
| }; |
| bool SendUpdates(const std::unordered_map<int, gfx::ScrollOffset>& scroll_map, |
| @@ -57,8 +64,13 @@ class UpdateTrackingRemoteCompositorBridge : public FakeRemoteCompositorBridge { |
| int num_updates_received() const { return num_updates_received_; } |
| + CompositorProtoState* compositor_proto_state() { |
| + return compositor_proto_state_.get(); |
| + } |
| + |
| private: |
| int num_updates_received_ = 0; |
| + std::unique_ptr<CompositorProtoState> compositor_proto_state_; |
| }; |
| class MockLayerTreeHostClient : public StubLayerTreeHostClient { |
| @@ -413,5 +425,57 @@ TEST_F(LayerTreeHostRemoteTest, ScrollAndScaleSync) { |
| EXPECT_FALSE(updates_applied); |
| } |
| +TEST_F(LayerTreeHostRemoteTest, OnlyPushPropertiesOnChangingLayers) { |
| + EXPECT_BEGIN_MAIN_FRAME_AND_COMMIT(mock_layer_tree_host_client_, 2); |
| + |
| + // Setup a tree with 3 nodes. |
| + scoped_refptr<PushPropertiesCountingLayer> child_layer = |
|
Khushal
2016/10/31 23:43:27
To be honest, I'd say just use Layer for this test
xingliu
2016/11/01 01:31:13
Yeah, I think PushPropertiesCountingLayer looks re
|
| + PushPropertiesCountingLayer::Create(); |
| + scoped_refptr<PushPropertiesCountingLayer> grandchild_layer = |
| + PushPropertiesCountingLayer::Create(); |
| + root_layer_->AddChild(child_layer); |
| + child_layer->AddChild(grandchild_layer); |
| + layer_tree_host_->SetNeedsCommit(); |
| + |
| + base::RunLoop().RunUntilIdle(); |
| + |
| + // Ensure all layers called ToLayerPropertiesProto during first commit. |
| + size_t push_properties_expectation = 1; |
| + EXPECT_EQ(push_properties_expectation, child_layer->push_properties_count()); |
| + EXPECT_EQ(push_properties_expectation, |
| + grandchild_layer->push_properties_count()); |
| + |
| + // Ensure the first proto contains all layer updates. |
| + EXPECT_EQ(1, remote_compositor_bridge_->num_updates_received()); |
| + CompositorProtoState* compositor_proto_state = |
| + remote_compositor_bridge_->compositor_proto_state(); |
| + DCHECK(compositor_proto_state); |
|
Khushal
2016/10/31 23:43:27
nit: Can do without the DCHECK? We'll crash on the
xingliu
2016/11/01 01:31:13
Removed the DCHECK.
|
| + const proto::LayerUpdate& layer_updates_first_commit = |
| + compositor_proto_state->compositor_message->layer_tree_host() |
| + .layer_updates(); |
| + EXPECT_EQ(3, layer_updates_first_commit.layers_size()); |
| + |
| + // Modify the |child_layer|, and run the second frame. |
| + child_layer->SetNeedsPushProperties(); |
| + layer_tree_host_->SetNeedsCommit(); |
| + base::RunLoop().RunUntilIdle(); |
| + |
| + // Ensure ToLayerPropertiesProto is only called by |child_layer|. |
| + EXPECT_EQ(push_properties_expectation + 1, |
| + child_layer->push_properties_count()); |
| + EXPECT_EQ(push_properties_expectation, |
| + grandchild_layer->push_properties_count()); |
| + |
| + // Ensure the second proto only contains |child_layer|. |
| + EXPECT_EQ(2, remote_compositor_bridge_->num_updates_received()); |
| + compositor_proto_state = remote_compositor_bridge_->compositor_proto_state(); |
| + DCHECK(compositor_proto_state); |
| + const proto::LayerUpdate& layer_updates_second_commit = |
| + compositor_proto_state->compositor_message->layer_tree_host() |
| + .layer_updates(); |
| + EXPECT_EQ(1, layer_updates_second_commit.layers_size()); |
| + EXPECT_EQ(child_layer->id(), layer_updates_second_commit.layers(0).id()); |
| +} |
| + |
| } // namespace |
| } // namespace cc |