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

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

Issue 1662673002: Add MessageChanneFactory interface and use it in ChannelDispatcherBase. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@framing
Patch Set: Created 4 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
« no previous file with comments | « remoting/protocol/client_video_dispatcher.h ('k') | remoting/protocol/connection_tester.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/stream_message_pipe_adapter.h"
17 #include "remoting/protocol/video_stub.h" 18 #include "remoting/protocol/video_stub.h"
18 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
19 20
20 namespace remoting { 21 namespace remoting {
21 namespace protocol { 22 namespace protocol {
22 23
23 class ClientVideoDispatcherTest : public testing::Test, 24 class ClientVideoDispatcherTest : public testing::Test,
24 public VideoStub, 25 public VideoStub,
25 public ChannelDispatcherBase::EventHandler { 26 public ChannelDispatcherBase::EventHandler {
26 public: 27 public:
27 ClientVideoDispatcherTest(); 28 ClientVideoDispatcherTest();
28 29
29 // VideoStub interface. 30 // VideoStub interface.
30 void ProcessVideoPacket(scoped_ptr<VideoPacket> video_packet, 31 void ProcessVideoPacket(scoped_ptr<VideoPacket> video_packet,
31 const base::Closure& done) override; 32 const base::Closure& done) override;
32 33
33 // ChannelDispatcherBase::EventHandler interface. 34 // ChannelDispatcherBase::EventHandler interface.
34 void OnChannelInitialized(ChannelDispatcherBase* channel_dispatcher) override; 35 void OnChannelInitialized(ChannelDispatcherBase* channel_dispatcher) override;
35 void OnChannelError(ChannelDispatcherBase* channel_dispatcher,
36 ErrorCode error) override;
37 36
38 protected: 37 protected:
38 void OnChannelError(int error);
39
39 void OnMessageReceived(scoped_ptr<CompoundBuffer> buffer); 40 void OnMessageReceived(scoped_ptr<CompoundBuffer> buffer);
40 void OnReadError(int error); 41 void OnReadError(int error);
41 42
42 base::MessageLoop message_loop_; 43 base::MessageLoop message_loop_;
43 44
44 // Set to true in OnChannelInitialized(). 45 // Set to true in OnChannelInitialized().
45 bool initialized_; 46 bool initialized_ = false;
46 47
47 // Client side. 48 // Client side.
48 FakeStreamChannelFactory client_channel_factory_; 49 FakeStreamChannelFactory client_channel_factory_;
50 StreamMessageChannelFactoryAdapter channel_factory_adapter_;
49 ClientVideoDispatcher dispatcher_; 51 ClientVideoDispatcher dispatcher_;
50 52
51 // Host side. 53 // Host side.
52 FakeStreamSocket host_socket_; 54 FakeStreamSocket host_socket_;
53 MessageReader reader_; 55 MessageReader reader_;
54 BufferedSocketWriter writer_; 56 BufferedSocketWriter writer_;
55 57
56 ScopedVector<VideoPacket> video_packets_; 58 ScopedVector<VideoPacket> video_packets_;
57 std::vector<base::Closure> packet_done_callbacks_; 59 std::vector<base::Closure> packet_done_callbacks_;
58 60
59 ScopedVector<VideoAck> ack_messages_; 61 ScopedVector<VideoAck> ack_messages_;
60 }; 62 };
61 63
62 ClientVideoDispatcherTest::ClientVideoDispatcherTest() 64 ClientVideoDispatcherTest::ClientVideoDispatcherTest()
63 : initialized_(false), 65 : channel_factory_adapter_(
66 &client_channel_factory_,
67 base::Bind(&ClientVideoDispatcherTest::OnChannelError,
68 base::Unretained(this))),
64 dispatcher_(this) { 69 dispatcher_(this) {
65 dispatcher_.Init(&client_channel_factory_, this); 70 dispatcher_.Init(&channel_factory_adapter_, this);
66 base::RunLoop().RunUntilIdle(); 71 base::RunLoop().RunUntilIdle();
67 DCHECK(initialized_); 72 DCHECK(initialized_);
68 host_socket_.PairWith( 73 host_socket_.PairWith(
69 client_channel_factory_.GetFakeChannel(kVideoChannelName)); 74 client_channel_factory_.GetFakeChannel(kVideoChannelName));
70 reader_.StartReading(&host_socket_, 75 reader_.StartReading(&host_socket_,
71 base::Bind(&ClientVideoDispatcherTest::OnMessageReceived, 76 base::Bind(&ClientVideoDispatcherTest::OnMessageReceived,
72 base::Unretained(this)), 77 base::Unretained(this)),
73 base::Bind(&ClientVideoDispatcherTest::OnReadError, 78 base::Bind(&ClientVideoDispatcherTest::OnReadError,
74 base::Unretained(this))); 79 base::Unretained(this)));
75 writer_.Start( 80 writer_.Start(
76 base::Bind(&P2PStreamSocket::Write, base::Unretained(&host_socket_)), 81 base::Bind(&P2PStreamSocket::Write, base::Unretained(&host_socket_)),
77 BufferedSocketWriter::WriteFailedCallback()); 82 BufferedSocketWriter::WriteFailedCallback());
78 } 83 }
79 84
80 void ClientVideoDispatcherTest::ProcessVideoPacket( 85 void ClientVideoDispatcherTest::ProcessVideoPacket(
81 scoped_ptr<VideoPacket> video_packet, 86 scoped_ptr<VideoPacket> video_packet,
82 const base::Closure& done) { 87 const base::Closure& done) {
83 video_packets_.push_back(video_packet.release()); 88 video_packets_.push_back(video_packet.release());
84 packet_done_callbacks_.push_back(done); 89 packet_done_callbacks_.push_back(done);
85 } 90 }
86 91
87 void ClientVideoDispatcherTest::OnChannelInitialized( 92 void ClientVideoDispatcherTest::OnChannelInitialized(
88 ChannelDispatcherBase* channel_dispatcher) { 93 ChannelDispatcherBase* channel_dispatcher) {
89 initialized_ = true; 94 initialized_ = true;
90 } 95 }
91 96
92 void ClientVideoDispatcherTest::OnChannelError( 97 void ClientVideoDispatcherTest::OnChannelError(int error) {
93 ChannelDispatcherBase* channel_dispatcher,
94 ErrorCode error) {
95 // Don't expect channel creation to fail. 98 // Don't expect channel creation to fail.
96 FAIL(); 99 FAIL();
97 } 100 }
98 101
99 void ClientVideoDispatcherTest::OnMessageReceived( 102 void ClientVideoDispatcherTest::OnMessageReceived(
100 scoped_ptr<CompoundBuffer> buffer) { 103 scoped_ptr<CompoundBuffer> buffer) {
101 scoped_ptr<VideoAck> ack = ParseMessage<VideoAck>(buffer.get()); 104 scoped_ptr<VideoAck> ack = ParseMessage<VideoAck>(buffer.get());
102 EXPECT_TRUE(ack); 105 EXPECT_TRUE(ack);
103 ack_messages_.push_back(ack.release()); 106 ack_messages_.push_back(ack.release());
104 } 107 }
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 base::RunLoop().RunUntilIdle(); 180 base::RunLoop().RunUntilIdle();
178 181
179 // Verify order of Ack messages. 182 // Verify order of Ack messages.
180 ASSERT_EQ(2U, ack_messages_.size()); 183 ASSERT_EQ(2U, ack_messages_.size());
181 EXPECT_EQ(kTestFrameId, ack_messages_[0]->frame_id()); 184 EXPECT_EQ(kTestFrameId, ack_messages_[0]->frame_id());
182 EXPECT_EQ(kTestFrameId + 1, ack_messages_[1]->frame_id()); 185 EXPECT_EQ(kTestFrameId + 1, ack_messages_[1]->frame_id());
183 } 186 }
184 187
185 } // namespace protocol 188 } // namespace protocol
186 } // namespace remoting 189 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/protocol/client_video_dispatcher.h ('k') | remoting/protocol/connection_tester.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698