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

Side by Side Diff: cc/blimp/layer_tree_host_remote_unittest.cc

Issue 2456093003: Enable more layer_tree_host_unittest for LayerTreeHostRemote. (Closed)
Patch Set: Added unit test case in LTH remote unittest. Created 4 years, 1 month 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 unified diff | Download patch
« no previous file with comments | « cc/blimp/layer_tree_host_remote.cc ('k') | cc/layers/layer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
7 #include "base/bind.h" 9 #include "base/bind.h"
8 #include "base/run_loop.h" 10 #include "base/run_loop.h"
9 #include "base/threading/thread_task_runner_handle.h" 11 #include "base/threading/thread_task_runner_handle.h"
10 #include "cc/animation/animation_host.h" 12 #include "cc/animation/animation_host.h"
11 #include "cc/layers/layer.h" 13 #include "cc/layers/layer.h"
12 #include "cc/output/begin_frame_args.h" 14 #include "cc/output/begin_frame_args.h"
15 #include "cc/proto/compositor_message.pb.h"
13 #include "cc/test/fake_image_serialization_processor.h" 16 #include "cc/test/fake_image_serialization_processor.h"
14 #include "cc/test/fake_remote_compositor_bridge.h" 17 #include "cc/test/fake_remote_compositor_bridge.h"
18 #include "cc/test/push_properties_counting_layer.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;
23 27
24 #define EXPECT_BEGIN_MAIN_FRAME(client, num) \ 28 #define EXPECT_BEGIN_MAIN_FRAME(client, num) \
(...skipping 16 matching lines...) Expand all
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.
57 compositor_proto_state_ = std::move(compositor_proto_state);
Khushal 2016/10/31 23:43:27 This looks perfect. Thanks! :)
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
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<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
433 PushPropertiesCountingLayer::Create();
434 scoped_refptr<PushPropertiesCountingLayer> grandchild_layer =
435 PushPropertiesCountingLayer::Create();
436 root_layer_->AddChild(child_layer);
437 child_layer->AddChild(grandchild_layer);
438 layer_tree_host_->SetNeedsCommit();
439
440 base::RunLoop().RunUntilIdle();
441
442 // Ensure all layers called ToLayerPropertiesProto during first commit.
443 size_t push_properties_expectation = 1;
444 EXPECT_EQ(push_properties_expectation, child_layer->push_properties_count());
445 EXPECT_EQ(push_properties_expectation,
446 grandchild_layer->push_properties_count());
447
448 // Ensure the first proto contains all layer updates.
449 EXPECT_EQ(1, remote_compositor_bridge_->num_updates_received());
450 CompositorProtoState* compositor_proto_state =
451 remote_compositor_bridge_->compositor_proto_state();
452 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.
453 const proto::LayerUpdate& layer_updates_first_commit =
454 compositor_proto_state->compositor_message->layer_tree_host()
455 .layer_updates();
456 EXPECT_EQ(3, layer_updates_first_commit.layers_size());
457
458 // Modify the |child_layer|, and run the second frame.
459 child_layer->SetNeedsPushProperties();
460 layer_tree_host_->SetNeedsCommit();
461 base::RunLoop().RunUntilIdle();
462
463 // Ensure ToLayerPropertiesProto is only called by |child_layer|.
464 EXPECT_EQ(push_properties_expectation + 1,
465 child_layer->push_properties_count());
466 EXPECT_EQ(push_properties_expectation,
467 grandchild_layer->push_properties_count());
468
469 // Ensure the second proto only contains |child_layer|.
470 EXPECT_EQ(2, remote_compositor_bridge_->num_updates_received());
471 compositor_proto_state = remote_compositor_bridge_->compositor_proto_state();
472 DCHECK(compositor_proto_state);
473 const proto::LayerUpdate& layer_updates_second_commit =
474 compositor_proto_state->compositor_message->layer_tree_host()
475 .layer_updates();
476 EXPECT_EQ(1, layer_updates_second_commit.layers_size());
477 EXPECT_EQ(child_layer->id(), layer_updates_second_commit.layers(0).id());
478 }
479
416 } // namespace 480 } // namespace
417 } // namespace cc 481 } // namespace cc
OLDNEW
« no previous file with comments | « cc/blimp/layer_tree_host_remote.cc ('k') | cc/layers/layer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698