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

Side by Side Diff: blimp/engine/renderer/blimp_remote_compositor_bridge_unittest.cc

Issue 2629743003: Remove all blimp engine code (Closed)
Patch Set: Use consistent comment style in //chrome Created 3 years, 11 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 unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "blimp/engine/renderer/blimp_remote_compositor_bridge.h"
6
7 #include "base/memory/ptr_util.h"
8 #include "base/run_loop.h"
9 #include "base/threading/thread_task_runner_handle.h"
10 #include "cc/blimp/compositor_proto_state.h"
11 #include "cc/blimp/remote_compositor_bridge_client.h"
12 #include "cc/proto/compositor_message.pb.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14
15 namespace blimp {
16 namespace engine {
17 namespace {
18
19 class BlimpRemoteCompositorBridgeTest : public testing::Test,
20 public cc::RemoteCompositorBridgeClient,
21 public content::RemoteProtoChannel {
22 public:
23 BlimpRemoteCompositorBridgeTest() = default;
24 ~BlimpRemoteCompositorBridgeTest() override = default;
25
26 void SetUp() override {
27 remote_compositor_bridge_ = base::MakeUnique<BlimpRemoteCompositorBridge>(
28 this, base::ThreadTaskRunnerHandle::Get());
29 DCHECK(proto_receiver_);
30
31 remote_compositor_bridge_->BindToClient(this);
32 remote_compositor_bridge_->scheduler_for_testing()
33 ->set_frame_delay_for_testing(base::TimeDelta::FromSeconds(0));
34 }
35 void TearDown() override {
36 remote_compositor_bridge_ = nullptr;
37 DCHECK(!proto_receiver_);
38 }
39
40 // RemoteProtoChannel implementation.
41 void SetProtoReceiver(ProtoReceiver* receiver) override {
42 DCHECK(!proto_receiver_ || !receiver);
43 proto_receiver_ = receiver;
44 }
45 void SendCompositorProto(const cc::proto::CompositorMessage& proto) override {
46 if (proto.has_layer_tree_host())
47 num_of_frames_sent_++;
48 if (proto.has_client_state_update_ack())
49 num_of_client_state_acks_sent_++;
50 }
51
52 // cc::RemoteCompositorBridgeClient implementation.
53 void BeginMainFrame() override {
54 if (send_frame_) {
55 std::unique_ptr<cc::CompositorProtoState> proto_state =
56 base::MakeUnique<cc::CompositorProtoState>();
57 proto_state->compositor_message =
58 base::MakeUnique<cc::proto::CompositorMessage>();
59 proto_state->compositor_message->mutable_layer_tree_host()
60 ->mutable_layer_tree()
61 ->set_page_scale_factor(1.f);
62
63 send_frame_ = false;
64 remote_compositor_bridge_->ProcessCompositorStateUpdate(
65 std::move(proto_state));
66 }
67 }
68 void ApplyStateUpdateFromClient(
69 const cc::proto::ClientStateUpdate& client_state_update) override {
70 num_of_client_updates_++;
71 }
72
73 int num_of_frames_sent() const { return num_of_frames_sent_; }
74 int num_of_client_state_acks_sent() const {
75 return num_of_client_state_acks_sent_;
76 }
77 int num_of_client_updates() const { return num_of_client_updates_; }
78
79 void set_send_frame(bool send_frame) { send_frame_ = send_frame; }
80
81 void SendFrameAck() {
82 std::unique_ptr<cc::proto::CompositorMessage> message =
83 base::MakeUnique<cc::proto::CompositorMessage>();
84 message->set_frame_ack(true);
85 proto_receiver_->OnProtoReceived(std::move(message));
86 }
87
88 void SendClientStateUpdate() {
89 std::unique_ptr<cc::proto::CompositorMessage> message =
90 base::MakeUnique<cc::proto::CompositorMessage>();
91 message->mutable_client_state_update()->set_page_scale_delta(0.2f);
92 proto_receiver_->OnProtoReceived(std::move(message));
93 }
94
95 protected:
96 base::MessageLoop loop_;
97 std::unique_ptr<BlimpRemoteCompositorBridge> remote_compositor_bridge_;
98 content::RemoteProtoChannel::ProtoReceiver* proto_receiver_ = nullptr;
99
100 private:
101 int num_of_frames_sent_ = 0;
102 int num_of_client_state_acks_sent_ = 0;
103 int num_of_client_updates_ = 0;
104 bool send_frame_ = false;
105 };
106
107 TEST_F(BlimpRemoteCompositorBridgeTest, FrameAndFrameAck) {
108 // Request a frame with an update.
109 set_send_frame(true);
110 remote_compositor_bridge_->ScheduleMainFrame();
111 base::RunLoop().RunUntilIdle();
112 EXPECT_EQ(1, num_of_frames_sent());
113
114 // Request another frame while the previous one has not been acked.
115 set_send_frame(true);
116 remote_compositor_bridge_->ScheduleMainFrame();
117 base::RunLoop().RunUntilIdle();
118 EXPECT_EQ(1, num_of_frames_sent());
119
120 // Ack the previous frame and ensure that the next frame is run.
121 SendFrameAck();
122 base::RunLoop().RunUntilIdle();
123 EXPECT_EQ(2, num_of_frames_sent());
124 }
125
126 TEST_F(BlimpRemoteCompositorBridgeTest, ClientStateUpdateAck) {
127 // Send a client state update with no frame requests present. We should see
128 // an ack immediately
129 SendClientStateUpdate();
130 EXPECT_EQ(1, num_of_client_updates());
131 EXPECT_EQ(1, num_of_client_state_acks_sent());
132
133 // Request a frame with no update, the ack should come after the frame runs.
134 remote_compositor_bridge_->ScheduleMainFrame();
135 SendClientStateUpdate();
136 EXPECT_EQ(2, num_of_client_updates());
137 EXPECT_EQ(1, num_of_client_state_acks_sent());
138 base::RunLoop().RunUntilIdle();
139 EXPECT_EQ(2, num_of_client_state_acks_sent());
140
141 // Request a frame with an update, the ack should be bundled with the frame.
142 set_send_frame(true);
143 remote_compositor_bridge_->ScheduleMainFrame();
144 SendClientStateUpdate();
145 EXPECT_EQ(3, num_of_client_updates());
146 EXPECT_EQ(2, num_of_client_state_acks_sent());
147 EXPECT_EQ(0, num_of_frames_sent());
148 base::RunLoop().RunUntilIdle();
149 EXPECT_EQ(3, num_of_client_state_acks_sent());
150 EXPECT_EQ(1, num_of_frames_sent());
151 }
152
153 } // namespace
154 } // namespace engine
155 } // namespace blimp
OLDNEW
« no previous file with comments | « blimp/engine/renderer/blimp_remote_compositor_bridge.cc ('k') | blimp/engine/renderer/blob_channel_sender_proxy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698