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 <memory> |
| 8 #include <vector> |
| 9 |
7 #include "base/bind.h" | 10 #include "base/bind.h" |
8 #include "base/memory/scoped_vector.h" | |
9 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
10 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
11 #include "remoting/base/buffered_socket_writer.h" | 13 #include "remoting/base/buffered_socket_writer.h" |
12 #include "remoting/base/constants.h" | 14 #include "remoting/base/constants.h" |
13 #include "remoting/proto/video.pb.h" | 15 #include "remoting/proto/video.pb.h" |
14 #include "remoting/protocol/fake_stream_socket.h" | 16 #include "remoting/protocol/fake_stream_socket.h" |
15 #include "remoting/protocol/message_reader.h" | 17 #include "remoting/protocol/message_reader.h" |
16 #include "remoting/protocol/message_serialization.h" | 18 #include "remoting/protocol/message_serialization.h" |
17 #include "remoting/protocol/protocol_mock_objects.h" | 19 #include "remoting/protocol/protocol_mock_objects.h" |
18 #include "remoting/protocol/stream_message_pipe_adapter.h" | 20 #include "remoting/protocol/stream_message_pipe_adapter.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 FakeStreamChannelFactory client_channel_factory_; | 53 FakeStreamChannelFactory client_channel_factory_; |
52 StreamMessageChannelFactoryAdapter channel_factory_adapter_; | 54 StreamMessageChannelFactoryAdapter channel_factory_adapter_; |
53 MockClientStub client_stub_; | 55 MockClientStub client_stub_; |
54 ClientVideoDispatcher dispatcher_; | 56 ClientVideoDispatcher dispatcher_; |
55 | 57 |
56 // Host side. | 58 // Host side. |
57 FakeStreamSocket host_socket_; | 59 FakeStreamSocket host_socket_; |
58 MessageReader reader_; | 60 MessageReader reader_; |
59 BufferedSocketWriter writer_; | 61 BufferedSocketWriter writer_; |
60 | 62 |
61 ScopedVector<VideoPacket> video_packets_; | 63 std::vector<std::unique_ptr<VideoPacket>> video_packets_; |
62 std::vector<base::Closure> packet_done_callbacks_; | 64 std::vector<base::Closure> packet_done_callbacks_; |
63 | 65 |
64 ScopedVector<VideoAck> ack_messages_; | 66 std::vector<std::unique_ptr<VideoAck>> ack_messages_; |
65 }; | 67 }; |
66 | 68 |
67 ClientVideoDispatcherTest::ClientVideoDispatcherTest() | 69 ClientVideoDispatcherTest::ClientVideoDispatcherTest() |
68 : channel_factory_adapter_( | 70 : channel_factory_adapter_( |
69 &client_channel_factory_, | 71 &client_channel_factory_, |
70 base::Bind(&ClientVideoDispatcherTest::OnChannelError, | 72 base::Bind(&ClientVideoDispatcherTest::OnChannelError, |
71 base::Unretained(this))), | 73 base::Unretained(this))), |
72 dispatcher_(this, &client_stub_) { | 74 dispatcher_(this, &client_stub_) { |
73 dispatcher_.Init(&channel_factory_adapter_, this); | 75 dispatcher_.Init(&channel_factory_adapter_, this); |
74 base::RunLoop().RunUntilIdle(); | 76 base::RunLoop().RunUntilIdle(); |
75 DCHECK(initialized_); | 77 DCHECK(initialized_); |
76 host_socket_.PairWith( | 78 host_socket_.PairWith( |
77 client_channel_factory_.GetFakeChannel(kVideoChannelName)); | 79 client_channel_factory_.GetFakeChannel(kVideoChannelName)); |
78 reader_.StartReading(&host_socket_, | 80 reader_.StartReading(&host_socket_, |
79 base::Bind(&ClientVideoDispatcherTest::OnMessageReceived, | 81 base::Bind(&ClientVideoDispatcherTest::OnMessageReceived, |
80 base::Unretained(this)), | 82 base::Unretained(this)), |
81 base::Bind(&ClientVideoDispatcherTest::OnReadError, | 83 base::Bind(&ClientVideoDispatcherTest::OnReadError, |
82 base::Unretained(this))); | 84 base::Unretained(this))); |
83 writer_.Start( | 85 writer_.Start( |
84 base::Bind(&P2PStreamSocket::Write, base::Unretained(&host_socket_)), | 86 base::Bind(&P2PStreamSocket::Write, base::Unretained(&host_socket_)), |
85 BufferedSocketWriter::WriteFailedCallback()); | 87 BufferedSocketWriter::WriteFailedCallback()); |
86 } | 88 } |
87 | 89 |
88 void ClientVideoDispatcherTest::ProcessVideoPacket( | 90 void ClientVideoDispatcherTest::ProcessVideoPacket( |
89 std::unique_ptr<VideoPacket> video_packet, | 91 std::unique_ptr<VideoPacket> video_packet, |
90 const base::Closure& done) { | 92 const base::Closure& done) { |
91 video_packets_.push_back(video_packet.release()); | 93 video_packets_.push_back(std::move(video_packet)); |
92 packet_done_callbacks_.push_back(done); | 94 packet_done_callbacks_.push_back(done); |
93 } | 95 } |
94 | 96 |
95 void ClientVideoDispatcherTest::OnChannelInitialized( | 97 void ClientVideoDispatcherTest::OnChannelInitialized( |
96 ChannelDispatcherBase* channel_dispatcher) { | 98 ChannelDispatcherBase* channel_dispatcher) { |
97 initialized_ = true; | 99 initialized_ = true; |
98 } | 100 } |
99 | 101 |
100 void ClientVideoDispatcherTest::OnChannelClosed( | 102 void ClientVideoDispatcherTest::OnChannelClosed( |
101 ChannelDispatcherBase* channel_dispatcher) { | 103 ChannelDispatcherBase* channel_dispatcher) { |
102 // Don't expect channels to be closed. | 104 // Don't expect channels to be closed. |
103 FAIL(); | 105 FAIL(); |
104 } | 106 } |
105 | 107 |
106 void ClientVideoDispatcherTest::OnChannelError(int error) { | 108 void ClientVideoDispatcherTest::OnChannelError(int error) { |
107 // Don't expect channel creation to fail. | 109 // Don't expect channel creation to fail. |
108 FAIL(); | 110 FAIL(); |
109 } | 111 } |
110 | 112 |
111 void ClientVideoDispatcherTest::OnMessageReceived( | 113 void ClientVideoDispatcherTest::OnMessageReceived( |
112 std::unique_ptr<CompoundBuffer> buffer) { | 114 std::unique_ptr<CompoundBuffer> buffer) { |
113 std::unique_ptr<VideoAck> ack = ParseMessage<VideoAck>(buffer.get()); | 115 std::unique_ptr<VideoAck> ack = ParseMessage<VideoAck>(buffer.get()); |
114 EXPECT_TRUE(ack); | 116 EXPECT_TRUE(ack); |
115 ack_messages_.push_back(ack.release()); | 117 ack_messages_.push_back(std::move(ack)); |
116 } | 118 } |
117 | 119 |
118 void ClientVideoDispatcherTest::OnReadError(int error) { | 120 void ClientVideoDispatcherTest::OnReadError(int error) { |
119 LOG(FATAL) << "Unexpected read error: " << error; | 121 LOG(FATAL) << "Unexpected read error: " << error; |
120 } | 122 } |
121 | 123 |
122 // Verify that the client can receive video packets and acks are not sent for | 124 // Verify that the client can receive video packets and acks are not sent for |
123 // VideoPackets that don't have frame_id field set. | 125 // VideoPackets that don't have frame_id field set. |
124 TEST_F(ClientVideoDispatcherTest, WithoutAcks) { | 126 TEST_F(ClientVideoDispatcherTest, WithoutAcks) { |
125 VideoPacket packet; | 127 VideoPacket packet; |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 base::RunLoop().RunUntilIdle(); | 222 base::RunLoop().RunUntilIdle(); |
221 | 223 |
222 // Verify order of Ack messages. | 224 // Verify order of Ack messages. |
223 ASSERT_EQ(2U, ack_messages_.size()); | 225 ASSERT_EQ(2U, ack_messages_.size()); |
224 EXPECT_EQ(kTestFrameId, ack_messages_[0]->frame_id()); | 226 EXPECT_EQ(kTestFrameId, ack_messages_[0]->frame_id()); |
225 EXPECT_EQ(kTestFrameId + 1, ack_messages_[1]->frame_id()); | 227 EXPECT_EQ(kTestFrameId + 1, ack_messages_[1]->frame_id()); |
226 } | 228 } |
227 | 229 |
228 } // namespace protocol | 230 } // namespace protocol |
229 } // namespace remoting | 231 } // namespace remoting |
OLD | NEW |