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

Side by Side Diff: remoting/protocol/client_video_dispatcher_unittest.cc

Issue 850983002: Implement video frame acknowledgements in the chromoting protocol. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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 2015 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 "remoting/protocol/client_video_dispatcher.h"
6
7 #include "base/bind.h"
8 #include "base/memory/scoped_vector.h"
9 #include "base/message_loop/message_loop.h"
10 #include "base/run_loop.h"
11 #include "remoting/base/constants.h"
12 #include "remoting/proto/video.pb.h"
13 #include "remoting/protocol/fake_session.h"
14 #include "remoting/protocol/fake_stream_socket.h"
15 #include "remoting/protocol/message_serialization.h"
16 #include "remoting/protocol/video_stub.h"
17 #include "testing/gtest/include/gtest/gtest.h"
18
19 namespace remoting {
20 namespace protocol {
21
22 class ClientVideoDispatcherTest : public testing::Test,
23 public VideoStub,
24 public ChannelDispatcherBase::EventHandler {
25 public:
26 ClientVideoDispatcherTest()
27 : initialized_(false),
28 dispatcher_(this),
29 parser_(base::Bind(&ClientVideoDispatcherTest::OnVideoAck,
30 base::Unretained(this)),
31 &reader_);
32
33 // VideoStub interface.
34 void ProcessVideoPacket(scoped_ptr<VideoPacket> video_packet,
35 const base::Closure& done);
36
37 // ChannelDispatcherBase::EventHandler interface.
38 void OnChannelInitialized(ChannelDispatcherBase* channel_dispatcher);
39 void OnChannelError(ChannelDispatcherBase* channel_dispatcher,
40 ErrorCode error);
41
42 protected:
43 void OnVideoAck(scoped_ptr<VideoAck> ack, const base::Closure& done);
44
45 base::MessageLoop message_loop_;
46
47 // Set to true in OnChannelInitialized().
48 bool initialized_;
49
50 // Client side.
51 ClientVideoDispatcher dispatcher_;
52 FakeSession session_;
53
54 // Host side.
55 FakeStreamSocket host_socket_;
56 MessageReader reader_;
57 ProtobufMessageParser<VideoAck> parser_;
58 BufferedSocketWriter writer_;
59
60 ScopedVector<VideoPacket> video_packets_;
61 std::vector<base::Closure> packet_done_callbacks_;
62
63 ScopedVector<VideoAck> ack_messages_;
64 };
65
66 ClientVideoDispatcherTest::ClientVideoDispatcherTest()
67 : initialized_(false),
68 dispatcher_(this),
69 parser_(base::Bind(&ClientVideoDispatcherTest::OnVideoAck,
70 base::Unretained(this)),
71 &reader_) {
72 dispatcher_.Init(&session_, ChannelConfig(ChannelConfig::TRANSPORT_MUX_STREAM,
73 kDefaultStreamVersion,
74 ChannelConfig::CODEC_UNDEFINED),
75 this);
76 base::RunLoop().RunUntilIdle();
77 DCHECK(initialized_);
78 host_socket_.PairWith(
79 session_.fake_channel_factory().GetFakeChannel(kVideoChannelName));
80 reader_.StartReading(&host_socket_);
81 writer_.Init(&host_socket_, BufferedSocketWriter::WriteFailedCallback());
82 }
83
84 void ClientVideoDispatcherTest::ProcessVideoPacket(
85 scoped_ptr<VideoPacket> video_packet,
86 const base::Closure& done) {
87 video_packets_.push_back(video_packet.release());
88 packet_done_callbacks_.push_back(done);
89 }
90
91 void ClientVideoDispatcherTest::OnChannelInitialized(
92 ChannelDispatcherBase* channel_dispatcher) {
93 initialized_ = true;
94 }
95
96 void ClientVideoDispatcherTest::OnChannelError(
97 ChannelDispatcherBase* channel_dispatcher,
98 ErrorCode error) {
99 // Don't expect channel creation to fail.
100 FAIL();
101 }
102
103 void ClientVideoDispatcherTest::OnVideoAck(scoped_ptr<VideoAck> ack,
104 const base::Closure& done) {
105 ack_messages_.push_back(ack.release());
106 done.Run();
107 }
108
109 // Verify that the client can receive video packets and acks are not sent for
110 // VideoPackets that don't have frame_id field set.
111 TEST_F(ClientVideoDispatcherTest, WithoutAcks) {
112 Initialize();
113
114 VideoPacket packet;
115 packet.set_data(std::string());
116
117 // Send a VideoPacket and verify that the client receives it.
118 writer_.Write(SerializeAndFrameMessage(packet), base::Closure());
119 base::RunLoop().RunUntilIdle();
120 EXPECT_EQ(1U, video_packets_.size());
121
122 packet_done_callbacks_.front().Run();
123 base::RunLoop().RunUntilIdle();
124
125 // Ack should never be sent for the packet without frame_id.
126 EXPECT_TRUE(ack_messages_.empty());
127 }
128
129 // Verifies that the dispatcher sends Ack message with correct rendering delay.
130 TEST_F(ClientVideoDispatcherTest, WithAcks) {
131 int kTestFrameId = 3;
132
133 Initialize();
134
135 VideoPacket packet;
136 packet.set_data(std::string());
137 packet.set_frame_id(kTestFrameId);
138
139 // Send a VideoPacket and verify that the client receives it.
140 writer_.Write(SerializeAndFrameMessage(packet), base::Closure());
141 base::RunLoop().RunUntilIdle();
142 EXPECT_EQ(1U, video_packets_.size());
143
144 // Ack should only be sent after the packet is processed.
145 EXPECT_TRUE(ack_messages_.empty());
146 base::RunLoop().RunUntilIdle();
147
148 // Fake completion of video packet decoding, to trigger the Ack.
149 packet_done_callbacks_.front().Run();
150 base::RunLoop().RunUntilIdle();
151
152 // Verify that the Ack message has been received.
153 ASSERT_EQ(1U, ack_messages_.size());
154 EXPECT_EQ(kTestFrameId, ack_messages_[0]->frame_id());
155 }
156
157 // Verify that Ack messages are sent in correct order.
158 TEST_F(ClientVideoDispatcherTest, AcksOrder) {
159 int kTestFrameId = 3;
160
161 Initialize();
162
163 VideoPacket packet;
164 packet.set_data(std::string());
165 packet.set_frame_id(kTestFrameId);
166
167 // Send two VideoPackets.
168 writer_.Write(SerializeAndFrameMessage(packet), base::Closure());
169 base::RunLoop().RunUntilIdle();
170
171 packet.set_frame_id(kTestFrameId + 1);
172 writer_.Write(SerializeAndFrameMessage(packet), base::Closure());
173 base::RunLoop().RunUntilIdle();
174
175 EXPECT_EQ(2U, video_packets_.size());
176 EXPECT_TRUE(ack_messages_.empty());
177
178 // Call completion callbacks in revers order.
179 packet_done_callbacks_[1].Run();
180 packet_done_callbacks_[0].Run();
181
182 base::RunLoop().RunUntilIdle();
183
184 // Verify order of Ack messages.
185 ASSERT_EQ(2U, ack_messages_.size());
186 EXPECT_EQ(kTestFrameId, ack_messages_[0]->frame_id());
187 EXPECT_EQ(kTestFrameId + 1, ack_messages_[1]->frame_id());
188 }
189
190 } // namespace protocol
191 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698