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

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 // VideoStub interface.
Wez 2015/02/21 03:12:02 No need to duplicate the class declaration comment
Sergey Ulanov 2015/02/23 17:35:38 Done.
85 void ClientVideoDispatcherTest::ProcessVideoPacket(
86 scoped_ptr<VideoPacket> video_packet,
87 const base::Closure& done) {
88 video_packets_.push_back(video_packet.release());
89 packet_done_callbacks_.push_back(done);
90 }
91
92 // ChannelDispatcherBase::EventHandler interface.
93 void ClientVideoDispatcherTest::OnChannelInitialized(
94 ChannelDispatcherBase* channel_dispatcher) {
95 initialized_ = true;
96 }
97
98 void ClientVideoDispatcherTest::OnChannelError(
99 ChannelDispatcherBase* channel_dispatcher,
100 ErrorCode error) {
101 // Don't expect channel creation to fail.
102 FAIL();
103 }
104
105 void ClientVideoDispatcherTest::OnVideoAck(scoped_ptr<VideoAck> ack,
106 const base::Closure& done) {
107 ack_messages_.push_back(ack.release());
108 done.Run();
109 }
110
111 // Verify that the client can receive video packets and acks are not sent for
112 // VideoPackets that don't have frame_id field set.
113 TEST_F(ClientVideoDispatcherTest, WithoutAcks) {
114 Initialize();
115
116 VideoPacket packet;
117 packet.set_data(std::string());
118
119 // Send a VideoPacket and verify that the client receives it.
120 writer_.Write(SerializeAndFrameMessage(packet), base::Closure());
121 base::RunLoop().RunUntilIdle();
122 EXPECT_EQ(1U, video_packets_.size());
123
124 packet_done_callbacks_.front().Run();
125 base::RunLoop().RunUntilIdle();
126
127 // Ack should never be sent for the packet without frame_id.
128 EXPECT_TRUE(ack_messages_.empty());
129 }
130
131 // Verifies that the dispatcher sends Ack message with correct rendering delay.
132 TEST_F(ClientVideoDispatcherTest, WithAcks) {
133 int kTestFrameId = 3;
134
135 Initialize();
136
137 VideoPacket packet;
138 packet.set_data(std::string());
139 packet.set_frame_id(kTestFrameId);
140
141 // Send a VideoPacket and verify that the client receives it.
142 writer_.Write(SerializeAndFrameMessage(packet), base::Closure());
143 base::RunLoop().RunUntilIdle();
144 EXPECT_EQ(1U, video_packets_.size());
145
146 // Ack should only be sent after the packet is processed.
147 EXPECT_TRUE(ack_messages_.empty());
148 base::RunLoop().RunUntilIdle();
149
150 // Fake completion of video packet decoding, to trigger the Ack.
151 packet_done_callbacks_.front().Run();
152 base::RunLoop().RunUntilIdle();
153
154 // Verify that the Ack message has been received.
155 ASSERT_EQ(1U, ack_messages_.size());
156 EXPECT_EQ(kTestFrameId, ack_messages_[0]->frame_id());
157 }
158
159 // Verify that Ack messages are sent in correct order.
160 TEST_F(ClientVideoDispatcherTest, AcksOrder) {
161 int kTestFrameId = 3;
162
163 Initialize();
164
165 VideoPacket packet;
166 packet.set_data(std::string());
167 packet.set_frame_id(kTestFrameId);
168
169 // Send two VideoPackets.
170 writer_.Write(SerializeAndFrameMessage(packet), base::Closure());
171 base::RunLoop().RunUntilIdle();
172
173 packet.set_frame_id(kTestFrameId + 1);
174 writer_.Write(SerializeAndFrameMessage(packet), base::Closure());
175 base::RunLoop().RunUntilIdle();
176
177 EXPECT_EQ(2U, video_packets_.size());
178 EXPECT_TRUE(ack_messages_.empty());
179
180 // Call completion callbacks in revers order.
181 packet_done_callbacks_[1].Run();
182 packet_done_callbacks_[0].Run();
183
184 base::RunLoop().RunUntilIdle();
185
186 // Verify order of Ack messages.
187 ASSERT_EQ(2U, ack_messages_.size());
188 EXPECT_EQ(kTestFrameId, ack_messages_[0]->frame_id());
189 EXPECT_EQ(kTestFrameId + 1, ack_messages_[1]->frame_id());
190 }
191
192 } // namespace protocol
193 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698