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

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

Issue 1654513003: Simplify message parsing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@no_done
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
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"
(...skipping 17 matching lines...) Expand all
28 // VideoStub interface. 28 // VideoStub interface.
29 void ProcessVideoPacket(scoped_ptr<VideoPacket> video_packet, 29 void ProcessVideoPacket(scoped_ptr<VideoPacket> video_packet,
30 const base::Closure& done) override; 30 const base::Closure& done) override;
31 31
32 // ChannelDispatcherBase::EventHandler interface. 32 // ChannelDispatcherBase::EventHandler interface.
33 void OnChannelInitialized(ChannelDispatcherBase* channel_dispatcher) override; 33 void OnChannelInitialized(ChannelDispatcherBase* channel_dispatcher) override;
34 void OnChannelError(ChannelDispatcherBase* channel_dispatcher, 34 void OnChannelError(ChannelDispatcherBase* channel_dispatcher,
35 ErrorCode error) override; 35 ErrorCode error) override;
36 36
37 protected: 37 protected:
38 void OnVideoAck(scoped_ptr<VideoAck> ack); 38 void OnMessageReceived(scoped_ptr<CompoundBuffer> buffer);
39 void OnReadError(int error); 39 void OnReadError(int error);
40 40
41 base::MessageLoop message_loop_; 41 base::MessageLoop message_loop_;
42 42
43 // Set to true in OnChannelInitialized(). 43 // Set to true in OnChannelInitialized().
44 bool initialized_; 44 bool initialized_;
45 45
46 // Client side. 46 // Client side.
47 FakeStreamChannelFactory client_channel_factory_; 47 FakeStreamChannelFactory client_channel_factory_;
48 ClientVideoDispatcher dispatcher_; 48 ClientVideoDispatcher dispatcher_;
49 49
50 // Host side. 50 // Host side.
51 FakeStreamSocket host_socket_; 51 FakeStreamSocket host_socket_;
52 MessageReader reader_; 52 MessageReader reader_;
53 ProtobufMessageParser<VideoAck> parser_;
54 BufferedSocketWriter writer_; 53 BufferedSocketWriter writer_;
55 54
56 ScopedVector<VideoPacket> video_packets_; 55 ScopedVector<VideoPacket> video_packets_;
57 std::vector<base::Closure> packet_done_callbacks_; 56 std::vector<base::Closure> packet_done_callbacks_;
58 57
59 ScopedVector<VideoAck> ack_messages_; 58 ScopedVector<VideoAck> ack_messages_;
60 }; 59 };
61 60
62 ClientVideoDispatcherTest::ClientVideoDispatcherTest() 61 ClientVideoDispatcherTest::ClientVideoDispatcherTest()
63 : initialized_(false), 62 : initialized_(false),
64 dispatcher_(this), 63 dispatcher_(this) {
65 parser_(base::Bind(&ClientVideoDispatcherTest::OnVideoAck,
66 base::Unretained(this)),
67 &reader_) {
68 dispatcher_.Init(&client_channel_factory_, this); 64 dispatcher_.Init(&client_channel_factory_, this);
69 base::RunLoop().RunUntilIdle(); 65 base::RunLoop().RunUntilIdle();
70 DCHECK(initialized_); 66 DCHECK(initialized_);
71 host_socket_.PairWith( 67 host_socket_.PairWith(
72 client_channel_factory_.GetFakeChannel(kVideoChannelName)); 68 client_channel_factory_.GetFakeChannel(kVideoChannelName));
73 reader_.StartReading(&host_socket_, 69 reader_.StartReading(&host_socket_,
70 base::Bind(&ClientVideoDispatcherTest::OnMessageReceived,
71 base::Unretained(this)),
74 base::Bind(&ClientVideoDispatcherTest::OnReadError, 72 base::Bind(&ClientVideoDispatcherTest::OnReadError,
75 base::Unretained(this))); 73 base::Unretained(this)));
76 writer_.Start( 74 writer_.Start(
77 base::Bind(&P2PStreamSocket::Write, base::Unretained(&host_socket_)), 75 base::Bind(&P2PStreamSocket::Write, base::Unretained(&host_socket_)),
78 BufferedSocketWriter::WriteFailedCallback()); 76 BufferedSocketWriter::WriteFailedCallback());
79 } 77 }
80 78
81 void ClientVideoDispatcherTest::ProcessVideoPacket( 79 void ClientVideoDispatcherTest::ProcessVideoPacket(
82 scoped_ptr<VideoPacket> video_packet, 80 scoped_ptr<VideoPacket> video_packet,
83 const base::Closure& done) { 81 const base::Closure& done) {
84 video_packets_.push_back(video_packet.release()); 82 video_packets_.push_back(video_packet.release());
85 packet_done_callbacks_.push_back(done); 83 packet_done_callbacks_.push_back(done);
86 } 84 }
87 85
88 void ClientVideoDispatcherTest::OnChannelInitialized( 86 void ClientVideoDispatcherTest::OnChannelInitialized(
89 ChannelDispatcherBase* channel_dispatcher) { 87 ChannelDispatcherBase* channel_dispatcher) {
90 initialized_ = true; 88 initialized_ = true;
91 } 89 }
92 90
93 void ClientVideoDispatcherTest::OnChannelError( 91 void ClientVideoDispatcherTest::OnChannelError(
94 ChannelDispatcherBase* channel_dispatcher, 92 ChannelDispatcherBase* channel_dispatcher,
95 ErrorCode error) { 93 ErrorCode error) {
96 // Don't expect channel creation to fail. 94 // Don't expect channel creation to fail.
97 FAIL(); 95 FAIL();
98 } 96 }
99 97
100 void ClientVideoDispatcherTest::OnVideoAck(scoped_ptr<VideoAck> ack) { 98 void ClientVideoDispatcherTest::OnMessageReceived(
99 scoped_ptr<CompoundBuffer> buffer) {
100 scoped_ptr<VideoAck> ack = ParseMessage<VideoAck>(buffer.get());
101 EXPECT_TRUE(ack);
101 ack_messages_.push_back(ack.release()); 102 ack_messages_.push_back(ack.release());
102 } 103 }
103 104
104 void ClientVideoDispatcherTest::OnReadError(int error) { 105 void ClientVideoDispatcherTest::OnReadError(int error) {
105 LOG(FATAL) << "Unexpected read error: " << error; 106 LOG(FATAL) << "Unexpected read error: " << error;
106 } 107 }
107 108
108 // Verify that the client can receive video packets and acks are not sent for 109 // Verify that the client can receive video packets and acks are not sent for
109 // VideoPackets that don't have frame_id field set. 110 // VideoPackets that don't have frame_id field set.
110 TEST_F(ClientVideoDispatcherTest, WithoutAcks) { 111 TEST_F(ClientVideoDispatcherTest, WithoutAcks) {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 base::RunLoop().RunUntilIdle(); 176 base::RunLoop().RunUntilIdle();
176 177
177 // Verify order of Ack messages. 178 // Verify order of Ack messages.
178 ASSERT_EQ(2U, ack_messages_.size()); 179 ASSERT_EQ(2U, ack_messages_.size());
179 EXPECT_EQ(kTestFrameId, ack_messages_[0]->frame_id()); 180 EXPECT_EQ(kTestFrameId, ack_messages_[0]->frame_id());
180 EXPECT_EQ(kTestFrameId + 1, ack_messages_[1]->frame_id()); 181 EXPECT_EQ(kTestFrameId + 1, ack_messages_[1]->frame_id());
181 } 182 }
182 183
183 } // namespace protocol 184 } // namespace protocol
184 } // namespace remoting 185 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/protocol/client_video_dispatcher.cc ('k') | remoting/protocol/host_control_dispatcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698