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

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

Issue 2445093002: cc/blimp: Add synchronization for scroll/scale state. (Closed)
Patch Set: move application of deltas to push time. 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
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 :
20 public testing::Test,
21 public cc::RemoteCompositorBridgeClient,
22 public cc::RemoteProtoChannel {
23 public:
24 BlimpRemoteCompositorBridgeTest() = default;
25 ~BlimpRemoteCompositorBridgeTest() override = default;
26
27 void SetUp() override {
28 remote_compositor_bridge_ =
29 base::MakeUnique<BlimpRemoteCompositorBridge>(
30 this, base::ThreadTaskRunnerHandle::Get());
31 DCHECK(proto_receiver_);
32
33 remote_compositor_bridge_->BindToClient(this);
34 remote_compositor_bridge_->scheduler_for_testing()
35 ->set_frame_delay_for_testing(base::TimeDelta::FromSeconds(0));
36 }
37 void TearDown() override {
38 remote_compositor_bridge_ = nullptr;
39 DCHECK(!proto_receiver_);
40 }
41
42 // RemoteProtoChannel implementation.
43 void SetProtoReceiver(ProtoReceiver* receiver) override {
44 DCHECK(!proto_receiver_ || !receiver);
45 proto_receiver_ = receiver;
46 }
47 void SendCompositorProto(const cc::proto::CompositorMessage& proto) override {
48 if (proto.has_layer_tree_host())
49 num_of_frames_sent_++;
50 if (proto.has_client_state_update_ack())
51 num_of_client_state_acks_sent_++;
52 }
53
54 // cc::RemoteCompositorBridgeClient implementation.
55 void BeginMainFrame() override {
56 if (send_frame_) {
57 std::unique_ptr<cc::CompositorProtoState> proto_state =
58 base::MakeUnique<cc::CompositorProtoState>();
59 proto_state->compositor_message =
60 base::MakeUnique<cc::proto::CompositorMessage>();
61 proto_state->compositor_message->mutable_layer_tree_host()
62 ->mutable_layer_tree()->set_page_scale_factor(1.f);
63
64 send_frame_ = false;
65 remote_compositor_bridge_->ProcessCompositorStateUpdate(
66 std::move(proto_state));
67 }
68 }
69 void ApplyStateUpdateFromClient(
70 const cc::proto::ClientStateUpdate& client_state_update) override {
71 num_of_client_updates_++;
72 }
73
74 int num_of_frames_sent() const { return num_of_frames_sent_; }
75 int num_of_client_state_acks_sent() const {
76 return num_of_client_state_acks_sent_; }
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 cc::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

Powered by Google App Engine
This is Rietveld 408576698