 Chromium Code Reviews
 Chromium Code Reviews Issue 2456093003:
  Enable more layer_tree_host_unittest for LayerTreeHostRemote.  (Closed)
    
  
    Issue 2456093003:
  Enable more layer_tree_host_unittest for LayerTreeHostRemote.  (Closed) 
  | OLD | NEW | 
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 #include "cc/blimp/layer_tree_host_remote.h" | 5 #include "cc/blimp/layer_tree_host_remote.h" | 
| 6 | 6 | 
| 7 #include <memory> | |
| 8 #include <unordered_set> | |
| 9 | |
| 7 #include "base/bind.h" | 10 #include "base/bind.h" | 
| 8 #include "base/run_loop.h" | 11 #include "base/run_loop.h" | 
| 9 #include "base/threading/thread_task_runner_handle.h" | 12 #include "base/threading/thread_task_runner_handle.h" | 
| 10 #include "cc/animation/animation_host.h" | 13 #include "cc/animation/animation_host.h" | 
| 11 #include "cc/layers/layer.h" | 14 #include "cc/layers/layer.h" | 
| 12 #include "cc/output/begin_frame_args.h" | 15 #include "cc/output/begin_frame_args.h" | 
| 16 #include "cc/proto/compositor_message.pb.h" | |
| 13 #include "cc/test/fake_image_serialization_processor.h" | 17 #include "cc/test/fake_image_serialization_processor.h" | 
| 14 #include "cc/test/fake_remote_compositor_bridge.h" | 18 #include "cc/test/fake_remote_compositor_bridge.h" | 
| 15 #include "cc/test/stub_layer_tree_host_client.h" | 19 #include "cc/test/stub_layer_tree_host_client.h" | 
| 16 #include "cc/trees/layer_tree_settings.h" | 20 #include "cc/trees/layer_tree_settings.h" | 
| 17 #include "testing/gmock/include/gmock/gmock.h" | 21 #include "testing/gmock/include/gmock/gmock.h" | 
| 18 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" | 
| 19 | 23 | 
| 20 using testing::InSequence; | 24 using testing::InSequence; | 
| 21 using testing::Mock; | 25 using testing::Mock; | 
| 22 using testing::StrictMock; | 26 using testing::StrictMock; | 
| (...skipping 18 matching lines...) Expand all Loading... | |
| 41 public: | 45 public: | 
| 42 UpdateTrackingRemoteCompositorBridge( | 46 UpdateTrackingRemoteCompositorBridge( | 
| 43 scoped_refptr<base::SingleThreadTaskRunner> compositor_main_task_runner) | 47 scoped_refptr<base::SingleThreadTaskRunner> compositor_main_task_runner) | 
| 44 : FakeRemoteCompositorBridge(std::move(compositor_main_task_runner)) {} | 48 : FakeRemoteCompositorBridge(std::move(compositor_main_task_runner)) {} | 
| 45 | 49 | 
| 46 ~UpdateTrackingRemoteCompositorBridge() override = default; | 50 ~UpdateTrackingRemoteCompositorBridge() override = default; | 
| 47 | 51 | 
| 48 void ProcessCompositorStateUpdate( | 52 void ProcessCompositorStateUpdate( | 
| 49 std::unique_ptr<CompositorProtoState> compositor_proto_state) override { | 53 std::unique_ptr<CompositorProtoState> compositor_proto_state) override { | 
| 50 num_updates_received_++; | 54 num_updates_received_++; | 
| 55 | |
| 56 // Cache the proto here for verification. | |
| 
Khushal
2016/11/01 03:26:50
nit: Its fine without the comment too. Pretty obvi
 
xingliu
2016/11/02 17:33:53
Done.
 | |
| 57 compositor_proto_state_ = std::move(compositor_proto_state); | |
| 51 }; | 58 }; | 
| 52 | 59 | 
| 53 bool SendUpdates(const std::unordered_map<int, gfx::ScrollOffset>& scroll_map, | 60 bool SendUpdates(const std::unordered_map<int, gfx::ScrollOffset>& scroll_map, | 
| 54 float page_scale) { | 61 float page_scale) { | 
| 55 return client_->ApplyScrollAndScaleUpdateFromClient(scroll_map, page_scale); | 62 return client_->ApplyScrollAndScaleUpdateFromClient(scroll_map, page_scale); | 
| 56 } | 63 } | 
| 57 | 64 | 
| 58 int num_updates_received() const { return num_updates_received_; } | 65 int num_updates_received() const { return num_updates_received_; } | 
| 59 | 66 | 
| 67 CompositorProtoState* compositor_proto_state() { | |
| 68 return compositor_proto_state_.get(); | |
| 69 } | |
| 70 | |
| 60 private: | 71 private: | 
| 61 int num_updates_received_ = 0; | 72 int num_updates_received_ = 0; | 
| 73 std::unique_ptr<CompositorProtoState> compositor_proto_state_; | |
| 62 }; | 74 }; | 
| 63 | 75 | 
| 64 class MockLayerTreeHostClient : public StubLayerTreeHostClient { | 76 class MockLayerTreeHostClient : public StubLayerTreeHostClient { | 
| 65 public: | 77 public: | 
| 66 MockLayerTreeHostClient() = default; | 78 MockLayerTreeHostClient() = default; | 
| 67 ~MockLayerTreeHostClient() override = default; | 79 ~MockLayerTreeHostClient() override = default; | 
| 68 | 80 | 
| 69 void set_update_host_callback(base::Closure callback) { | 81 void set_update_host_callback(base::Closure callback) { | 
| 70 update_host_callback_ = callback; | 82 update_host_callback_ = callback; | 
| 71 } | 83 } | 
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 406 // Destroy a layer and send a scroll update for it. We should be informed that | 418 // Destroy a layer and send a scroll update for it. We should be informed that | 
| 407 // the update could not be applied successfully. | 419 // the update could not be applied successfully. | 
| 408 child_layer1->RemoveAllChildren(); | 420 child_layer1->RemoveAllChildren(); | 
| 409 scroll_updates.clear(); | 421 scroll_updates.clear(); | 
| 410 scroll_updates[child_layer2->id()] = gfx::ScrollOffset(3, 2); | 422 scroll_updates[child_layer2->id()] = gfx::ScrollOffset(3, 2); | 
| 411 updates_applied = | 423 updates_applied = | 
| 412 remote_compositor_bridge_->SendUpdates(scroll_updates, new_scale_factor); | 424 remote_compositor_bridge_->SendUpdates(scroll_updates, new_scale_factor); | 
| 413 EXPECT_FALSE(updates_applied); | 425 EXPECT_FALSE(updates_applied); | 
| 414 } | 426 } | 
| 415 | 427 | 
| 428 TEST_F(LayerTreeHostRemoteTest, OnlyPushPropertiesOnChangingLayers) { | |
| 429 EXPECT_BEGIN_MAIN_FRAME_AND_COMMIT(mock_layer_tree_host_client_, 2); | |
| 430 | |
| 431 // Setup a tree with 3 nodes. | |
| 432 scoped_refptr<Layer> child_layer = Layer::Create(); | |
| 433 scoped_refptr<Layer> grandchild_layer = Layer::Create(); | |
| 434 root_layer_->AddChild(child_layer); | |
| 435 child_layer->AddChild(grandchild_layer); | |
| 436 layer_tree_host_->SetNeedsCommit(); | |
| 437 | |
| 438 base::RunLoop().RunUntilIdle(); | |
| 439 | |
| 440 // Ensure the first proto contains all layer updates. | |
| 441 EXPECT_EQ(1, remote_compositor_bridge_->num_updates_received()); | |
| 442 CompositorProtoState* compositor_proto_state = | |
| 443 remote_compositor_bridge_->compositor_proto_state(); | |
| 444 const proto::LayerUpdate& layer_updates_first_commit = | |
| 445 compositor_proto_state->compositor_message->layer_tree_host() | |
| 446 .layer_updates(); | |
| 447 | |
| 448 std::unordered_set<int> layer_updates_id_set; | |
| 449 for (int i = 0; i < layer_updates_first_commit.layers_size(); ++i) { | |
| 450 layer_updates_id_set.insert(layer_updates_first_commit.layers(i).id()); | |
| 451 } | |
| 452 | |
| 453 EXPECT_TRUE(layer_updates_id_set.find(root_layer_->id()) != | |
| 454 layer_updates_id_set.end()); | |
| 455 EXPECT_TRUE(layer_updates_id_set.find(child_layer->id()) != | |
| 456 layer_updates_id_set.end()); | |
| 457 EXPECT_TRUE(layer_updates_id_set.find(grandchild_layer->id()) != | |
| 458 layer_updates_id_set.end()); | |
| 459 EXPECT_EQ(3, layer_updates_first_commit.layers_size()); | |
| 460 | |
| 461 // Modify the |child_layer|, and run the second frame. | |
| 462 child_layer->SetNeedsPushProperties(); | |
| 463 layer_tree_host_->SetNeedsCommit(); | |
| 464 base::RunLoop().RunUntilIdle(); | |
| 465 | |
| 466 // Ensure the second proto only contains |child_layer|. | |
| 467 EXPECT_EQ(2, remote_compositor_bridge_->num_updates_received()); | |
| 468 compositor_proto_state = remote_compositor_bridge_->compositor_proto_state(); | |
| 469 DCHECK(compositor_proto_state); | |
| 470 const proto::LayerUpdate& layer_updates_second_commit = | |
| 471 compositor_proto_state->compositor_message->layer_tree_host() | |
| 472 .layer_updates(); | |
| 473 EXPECT_EQ(1, layer_updates_second_commit.layers_size()); | |
| 474 EXPECT_EQ(child_layer->id(), layer_updates_second_commit.layers(0).id()); | |
| 475 } | |
| 476 | |
| 416 } // namespace | 477 } // namespace | 
| 417 } // namespace cc | 478 } // namespace cc | 
| OLD | NEW |