OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 "remoting/protocol/client_video_dispatcher.h" | 5 #include "remoting/protocol/client_video_dispatcher.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/memory/scoped_vector.h" | 8 #include "base/memory/scoped_vector.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
11 #include "remoting/base/buffered_socket_writer.h" | 11 #include "remoting/base/buffered_socket_writer.h" |
12 #include "remoting/base/constants.h" | 12 #include "remoting/base/constants.h" |
13 #include "remoting/proto/video.pb.h" | 13 #include "remoting/proto/video.pb.h" |
14 #include "remoting/protocol/fake_stream_socket.h" | 14 #include "remoting/protocol/fake_stream_socket.h" |
15 #include "remoting/protocol/message_reader.h" | 15 #include "remoting/protocol/message_reader.h" |
16 #include "remoting/protocol/message_serialization.h" | 16 #include "remoting/protocol/message_serialization.h" |
| 17 #include "remoting/protocol/protocol_mock_objects.h" |
17 #include "remoting/protocol/stream_message_pipe_adapter.h" | 18 #include "remoting/protocol/stream_message_pipe_adapter.h" |
18 #include "remoting/protocol/video_stub.h" | 19 #include "remoting/protocol/video_stub.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
20 | 21 |
21 namespace remoting { | 22 namespace remoting { |
22 namespace protocol { | 23 namespace protocol { |
23 | 24 |
24 class ClientVideoDispatcherTest : public testing::Test, | 25 class ClientVideoDispatcherTest : public testing::Test, |
25 public VideoStub, | 26 public VideoStub, |
26 public ChannelDispatcherBase::EventHandler { | 27 public ChannelDispatcherBase::EventHandler { |
(...skipping 14 matching lines...) Expand all Loading... |
41 void OnReadError(int error); | 42 void OnReadError(int error); |
42 | 43 |
43 base::MessageLoop message_loop_; | 44 base::MessageLoop message_loop_; |
44 | 45 |
45 // Set to true in OnChannelInitialized(). | 46 // Set to true in OnChannelInitialized(). |
46 bool initialized_ = false; | 47 bool initialized_ = false; |
47 | 48 |
48 // Client side. | 49 // Client side. |
49 FakeStreamChannelFactory client_channel_factory_; | 50 FakeStreamChannelFactory client_channel_factory_; |
50 StreamMessageChannelFactoryAdapter channel_factory_adapter_; | 51 StreamMessageChannelFactoryAdapter channel_factory_adapter_; |
| 52 MockClientStub client_stub_; |
51 ClientVideoDispatcher dispatcher_; | 53 ClientVideoDispatcher dispatcher_; |
52 | 54 |
53 // Host side. | 55 // Host side. |
54 FakeStreamSocket host_socket_; | 56 FakeStreamSocket host_socket_; |
55 MessageReader reader_; | 57 MessageReader reader_; |
56 BufferedSocketWriter writer_; | 58 BufferedSocketWriter writer_; |
57 | 59 |
58 ScopedVector<VideoPacket> video_packets_; | 60 ScopedVector<VideoPacket> video_packets_; |
59 std::vector<base::Closure> packet_done_callbacks_; | 61 std::vector<base::Closure> packet_done_callbacks_; |
60 | 62 |
61 ScopedVector<VideoAck> ack_messages_; | 63 ScopedVector<VideoAck> ack_messages_; |
62 }; | 64 }; |
63 | 65 |
64 ClientVideoDispatcherTest::ClientVideoDispatcherTest() | 66 ClientVideoDispatcherTest::ClientVideoDispatcherTest() |
65 : channel_factory_adapter_( | 67 : channel_factory_adapter_( |
66 &client_channel_factory_, | 68 &client_channel_factory_, |
67 base::Bind(&ClientVideoDispatcherTest::OnChannelError, | 69 base::Bind(&ClientVideoDispatcherTest::OnChannelError, |
68 base::Unretained(this))), | 70 base::Unretained(this))), |
69 dispatcher_(this) { | 71 dispatcher_(this, &client_stub_) { |
70 dispatcher_.Init(&channel_factory_adapter_, this); | 72 dispatcher_.Init(&channel_factory_adapter_, this); |
71 base::RunLoop().RunUntilIdle(); | 73 base::RunLoop().RunUntilIdle(); |
72 DCHECK(initialized_); | 74 DCHECK(initialized_); |
73 host_socket_.PairWith( | 75 host_socket_.PairWith( |
74 client_channel_factory_.GetFakeChannel(kVideoChannelName)); | 76 client_channel_factory_.GetFakeChannel(kVideoChannelName)); |
75 reader_.StartReading(&host_socket_, | 77 reader_.StartReading(&host_socket_, |
76 base::Bind(&ClientVideoDispatcherTest::OnMessageReceived, | 78 base::Bind(&ClientVideoDispatcherTest::OnMessageReceived, |
77 base::Unretained(this)), | 79 base::Unretained(this)), |
78 base::Bind(&ClientVideoDispatcherTest::OnReadError, | 80 base::Bind(&ClientVideoDispatcherTest::OnReadError, |
79 base::Unretained(this))); | 81 base::Unretained(this))); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 | 149 |
148 // Fake completion of video packet decoding, to trigger the Ack. | 150 // Fake completion of video packet decoding, to trigger the Ack. |
149 packet_done_callbacks_.front().Run(); | 151 packet_done_callbacks_.front().Run(); |
150 base::RunLoop().RunUntilIdle(); | 152 base::RunLoop().RunUntilIdle(); |
151 | 153 |
152 // Verify that the Ack message has been received. | 154 // Verify that the Ack message has been received. |
153 ASSERT_EQ(1U, ack_messages_.size()); | 155 ASSERT_EQ(1U, ack_messages_.size()); |
154 EXPECT_EQ(kTestFrameId, ack_messages_[0]->frame_id()); | 156 EXPECT_EQ(kTestFrameId, ack_messages_[0]->frame_id()); |
155 } | 157 } |
156 | 158 |
| 159 // Verifies that the dispatcher properly synthesizes VideoLayout message when |
| 160 // screen size changes. |
| 161 TEST_F(ClientVideoDispatcherTest, VideoLayout) { |
| 162 const int kScreenSize = 100; |
| 163 const float kScaleFactor = 2.0; |
| 164 |
| 165 VideoPacket packet; |
| 166 packet.set_data(std::string()); |
| 167 packet.set_frame_id(42); |
| 168 packet.mutable_format()->set_screen_width(kScreenSize); |
| 169 packet.mutable_format()->set_screen_height(kScreenSize); |
| 170 packet.mutable_format()->set_x_dpi(kDefaultDpi * kScaleFactor); |
| 171 packet.mutable_format()->set_y_dpi(kDefaultDpi * kScaleFactor); |
| 172 |
| 173 VideoLayout layout; |
| 174 EXPECT_CALL(client_stub_, SetVideoLayout(testing::_)) |
| 175 .WillOnce(testing::SaveArg<0>(&layout)); |
| 176 |
| 177 // Send a VideoPacket and verify that the client receives it. |
| 178 writer_.Write(SerializeAndFrameMessage(packet), base::Closure()); |
| 179 base::RunLoop().RunUntilIdle(); |
| 180 |
| 181 ASSERT_EQ(1, layout.video_track_size()); |
| 182 EXPECT_EQ(0, layout.video_track(0).position_x()); |
| 183 EXPECT_EQ(0, layout.video_track(0).position_y()); |
| 184 EXPECT_EQ(kScreenSize / kScaleFactor, layout.video_track(0).width()); |
| 185 EXPECT_EQ(kScreenSize / kScaleFactor, layout.video_track(0).height()); |
| 186 EXPECT_EQ(kDefaultDpi * kScaleFactor, layout.video_track(0).x_dpi()); |
| 187 EXPECT_EQ(kDefaultDpi * kScaleFactor, layout.video_track(0).y_dpi()); |
| 188 } |
| 189 |
157 // Verify that Ack messages are sent in correct order. | 190 // Verify that Ack messages are sent in correct order. |
158 TEST_F(ClientVideoDispatcherTest, AcksOrder) { | 191 TEST_F(ClientVideoDispatcherTest, AcksOrder) { |
159 int kTestFrameId = 3; | 192 int kTestFrameId = 3; |
160 | 193 |
161 VideoPacket packet; | 194 VideoPacket packet; |
162 packet.set_data(std::string()); | 195 packet.set_data(std::string()); |
163 packet.set_frame_id(kTestFrameId); | 196 packet.set_frame_id(kTestFrameId); |
164 | 197 |
165 // Send two VideoPackets. | 198 // Send two VideoPackets. |
166 writer_.Write(SerializeAndFrameMessage(packet), base::Closure()); | 199 writer_.Write(SerializeAndFrameMessage(packet), base::Closure()); |
(...skipping 13 matching lines...) Expand all Loading... |
180 base::RunLoop().RunUntilIdle(); | 213 base::RunLoop().RunUntilIdle(); |
181 | 214 |
182 // Verify order of Ack messages. | 215 // Verify order of Ack messages. |
183 ASSERT_EQ(2U, ack_messages_.size()); | 216 ASSERT_EQ(2U, ack_messages_.size()); |
184 EXPECT_EQ(kTestFrameId, ack_messages_[0]->frame_id()); | 217 EXPECT_EQ(kTestFrameId, ack_messages_[0]->frame_id()); |
185 EXPECT_EQ(kTestFrameId + 1, ack_messages_[1]->frame_id()); | 218 EXPECT_EQ(kTestFrameId + 1, ack_messages_[1]->frame_id()); |
186 } | 219 } |
187 | 220 |
188 } // namespace protocol | 221 } // namespace protocol |
189 } // namespace remoting | 222 } // namespace remoting |
OLD | NEW |