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

Side by Side Diff: content/browser/renderer_host/p2p/socket_host_unittest.cc

Issue 159353002: This CL adds methods to manipulate RTP header extension, particularly (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2014 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 "content/browser/renderer_host/p2p/socket_host.h"
6
7 #include <vector>
8
9 #include "base/memory/scoped_ptr.h"
10 #include "content/browser/renderer_host/p2p/socket_host_test_utils.h"
11 #include "net/base/ip_endpoint.h"
12 #include "testing/gmock/include/gmock/gmock.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14
15 // Rtp message with invalid length.
16 static unsigned char kRtpMsgWithInvalidLength[] = {
17 0x94, 0x00, 0x00, 0x00,
18 0x00, 0x00, 0x00, 0x00,
19 0xAA, 0xBB, 0xCC, 0XDD, // SSRC
20 0xDD, 0xCC, 0xBB, 0xAA // Only 1 CSRC, but CC count is 4.
21 };
22
23 // Rtp message with single byte header extension, invalid extension length.
24 static unsigned char kRtpMessageWithInvalidExtnLength[] = {
25 0x90, 0x00, 0x00, 0x00,
26 0x00, 0x00, 0x00, 0x00,
27 0x00, 0x00, 0x00, 0x00,
28 0xBE, 0xDE, 0x0A, 0x00 // Extn length - 0x0A00
29 };
30
31 // Valid rtp Message with 2 byte header extension.
32 static unsigned char kRtpMsgWith2ByteExtnHeader[] = {
33 0x90, 0x00, 0x00, 0x00,
34 0x00, 0x00, 0x00, 0x00,
35 0xAA, 0xBB, 0xCC, 0XDD, // SSRC
36 0x10, 0x00, 0x00, 0x01, // 2 Byte header extension
37 0x01, 0x00, 0x00, 0x00
38 };
39
40 // Stun Indication message with Zero length
41 static unsigned char kTurnSendIndicationMsgWithNoAttributes[] = {
42 0x00, 0x16, 0x00, 0x00, // Zero length
43 0x21, 0x12, 0xA4, 0x42, // magic cookie
44 '0', '1', '2', '3', // transaction id
45 '4', '5', '6', '7',
46 '8', '9', 'a', 'b',
47 };
48
49 // Stun Send Indication message with invalid length in stun header.
50 static unsigned char kTurnSendIndicationMsgWithInvalidLength[] = {
51 0x00, 0x16, 0xFF, 0x00, // length of 0xFF00
52 0x21, 0x12, 0xA4, 0x42, // magic cookie
53 '0', '1', '2', '3', // transaction id
54 '4', '5', '6', '7',
55 '8', '9', 'a', 'b',
56 };
57
58 // Stun Send Indication message with no DATA attribute in message.
59 static unsigned char kTurnSendIndicatinMsgWithNoDataAttribute[] = {
60 0x00, 0x16, 0x00, 0x08, // length of
61 0x21, 0x12, 0xA4, 0x42, // magic cookie
62 '0', '1', '2', '3', // transaction id
63 '4', '5', '6', '7',
64 '8', '9', 'a', 'b',
65 0x00, 0x20, 0x00, 0x04, // Mapped address.
66 0x00, 0x00, 0x00, 0x00
67 };
68
69 // A valid STUN indication message with a valid RTP header in data attribute
70 // payload field and no extension bit set.
71 static unsigned char kTurnSendIndicationMsgWithoutRtpExtension[] = {
72 0x00, 0x16, 0x00, 0x18, // length of
73 0x21, 0x12, 0xA4, 0x42, // magic cookie
74 '0', '1', '2', '3', // transaction id
75 '4', '5', '6', '7',
76 '8', '9', 'a', 'b',
77 0x00, 0x20, 0x00, 0x04, // Mapped address.
78 0x00, 0x00, 0x00, 0x00,
79 0x00, 0x13, 0x00, 0x0C, // Data attribute.
80 0x80, 0x00, 0x00, 0x00, // RTP packet.
81 0x00, 0x00, 0x00, 0x00,
82 0x00, 0x00, 0x00, 0x00,
83 };
84
85 // A valid STUN indication message with a valid RTP header and a extension
86 // header.
87 static unsigned char kTurnSendIndicationMsgWithSendTimeExtension[] = {
88 0x00, 0x16, 0x00, 0x20, // length of
89 0x21, 0x12, 0xA4, 0x42, // magic cookie
90 '0', '1', '2', '3', // transaction id
91 '4', '5', '6', '7',
92 '8', '9', 'a', 'b',
93 0x00, 0x20, 0x00, 0x04, // Mapped address.
94 0x00, 0x00, 0x00, 0x00,
95 0x00, 0x13, 0x00, 0x14, // Data attribute.
96 0x90, 0x00, 0x00, 0x00, // RTP packet.
97 0x00, 0x00, 0x00, 0x00,
98 0x00, 0x00, 0x00, 0x00,
99 0xBE, 0xDE, 0x00, 0x01,
100 0x32, 0xaa, 0xbb, 0xcc,
101 };
102
103 // A valid TURN channel header, but not RTP packet.
104 static unsigned char kTurnChannelMessage[] = {
105 0x40, 0x00, 0x00, 0x04,
106 0xaa, 0xbb, 0xcc, 0xdd,
107 };
108
109 // Turn ChannelMessage with zero length of payload.
110 static unsigned char kTurnChannelMessageWithZeroLength[] = {
111 0x40, 0x00, 0x00, 0x00
112 };
113
114 // RTP packet with single byte extension header of length 4 bytes.
115 // Extension id = 3 and length = 3
116 static unsigned char kRtpPacketWithSendTimeExtension[] = {
117 0x90, 0x00, 0x00, 0x00,
118 0x00, 0x00, 0x00, 0x00,
119 0x00, 0x00, 0x00, 0x00,
120 0xBE, 0xDE, 0x00, 0x01,
121 0x32, 0xaa, 0xbb, 0xcc,
122 };
123
124 namespace content {
125
126 class P2PSocketHostForTest : public P2PSocketHost {
127 public:
128 P2PSocketHostForTest(IPC::Sender* message_sender, int id)
129 : P2PSocketHost(message_sender, id) {}
130 virtual ~P2PSocketHostForTest() {}
131
132 virtual bool Init(const net::IPEndPoint& local_address,
133 const net::IPEndPoint& remote_address) OVERRIDE {
134 return true;
135 }
136
137 virtual void Send(const net::IPEndPoint& to,
138 const std::vector<char>& data,
139 const talk_base::PacketOptions& options,
140 uint64 packet_id) OVERRIDE {
141 }
142
143 virtual P2PSocketHost* AcceptIncomingTcpConnection(
144 const net::IPEndPoint& remote_address, int id) OVERRIDE {
145 return NULL;
146 }
147
148 virtual bool SetOption(P2PSocketOption option, int value) OVERRIDE {
149 return true;
150 }
151
152 using P2PSocketHost::MaybeUpdateRtpSendTimeExtn;
153 using P2PSocketHost::GetRtpPacketStartPositionAndLength;
154 using P2PSocketHost::UpdateSendTimeExtnValue;
155 using P2PSocketHost::MaybeUpdateRtpAuthTag;
156 };
157
158 class P2PSocketHostTest : public testing::Test {
159 public:
160 virtual void SetUp() OVERRIDE {
161 socket_host_.reset(new P2PSocketHostForTest(&sender_, 0));
162 }
163
164 MockIPCSender sender_;
165 scoped_ptr<P2PSocketHostForTest> socket_host_;
166 };
167
168 // This test verifies parsing of all invalid packets.
169 TEST_F(P2PSocketHostTest, TestInvalidRtpMessages) {
170 int start_pos, rtp_length;
171 EXPECT_FALSE(socket_host_->GetRtpPacketStartPositionAndLength(
172 reinterpret_cast<char*>(kRtpMsgWithInvalidLength),
173 sizeof(kRtpMsgWithInvalidLength),
174 &start_pos, &rtp_length));
175
176 EXPECT_FALSE(socket_host_->GetRtpPacketStartPositionAndLength(
177 reinterpret_cast<char*>(kRtpMessageWithInvalidExtnLength),
178 sizeof(kRtpMessageWithInvalidExtnLength),
179 &start_pos, &rtp_length));
180
181 EXPECT_FALSE(socket_host_->GetRtpPacketStartPositionAndLength(
182 reinterpret_cast<char*>(kTurnSendIndicationMsgWithNoAttributes),
183 sizeof(kTurnSendIndicationMsgWithNoAttributes),
184 &start_pos, &rtp_length));
185
186 EXPECT_FALSE(socket_host_->GetRtpPacketStartPositionAndLength(
187 reinterpret_cast<char*>(kTurnSendIndicationMsgWithInvalidLength),
188 sizeof(kTurnSendIndicationMsgWithInvalidLength),
189 &start_pos, &rtp_length));
190
191 EXPECT_FALSE(socket_host_->GetRtpPacketStartPositionAndLength(
192 reinterpret_cast<char*>(kTurnSendIndicatinMsgWithNoDataAttribute),
193 sizeof(kTurnSendIndicatinMsgWithNoDataAttribute),
194 &start_pos, &rtp_length));
195
196 EXPECT_FALSE(socket_host_->GetRtpPacketStartPositionAndLength(
197 reinterpret_cast<char*>(kTurnChannelMessage),
198 sizeof(kTurnChannelMessage),
199 &start_pos, &rtp_length));
200
201 EXPECT_FALSE(socket_host_->GetRtpPacketStartPositionAndLength(
202 reinterpret_cast<char*>(kTurnChannelMessageWithZeroLength),
203 sizeof(kTurnChannelMessageWithZeroLength),
204 &start_pos, &rtp_length));
205 }
206
207 // This test verifies seraching of RTP exension ID supplied as input in a
208 // RTP packet. If it finds it will be update the the timestamp.
209 TEST_F(P2PSocketHostTest, TestUpdateRtpAbsSendTimeExtension) {
210 int start_pos, rtp_length;
211 EXPECT_TRUE(socket_host_->GetRtpPacketStartPositionAndLength(
212 reinterpret_cast<char*>(kRtpMsgWith2ByteExtnHeader),
213 sizeof(kRtpMsgWith2ByteExtnHeader),
214 &start_pos, &rtp_length));
215 EXPECT_EQ(20, rtp_length);
216 EXPECT_EQ(0, start_pos);
217
218 EXPECT_FALSE(socket_host_->MaybeUpdateRtpSendTimeExtn(
219 reinterpret_cast<char*>(kRtpMsgWith2ByteExtnHeader),
220 sizeof(kRtpMsgWith2ByteExtnHeader), 3));
221
222 EXPECT_TRUE(socket_host_->GetRtpPacketStartPositionAndLength(
223 reinterpret_cast<char*>(kTurnSendIndicationMsgWithoutRtpExtension),
224 sizeof(kTurnSendIndicationMsgWithoutRtpExtension),
225 &start_pos, &rtp_length));
226 EXPECT_EQ(12, rtp_length);
227 EXPECT_EQ(32, start_pos);
228
229 EXPECT_TRUE(socket_host_->MaybeUpdateRtpSendTimeExtn(
230 reinterpret_cast<char*>(kTurnSendIndicationMsgWithoutRtpExtension),
231 sizeof(kTurnSendIndicationMsgWithoutRtpExtension), 3));
232
233 EXPECT_TRUE(socket_host_->GetRtpPacketStartPositionAndLength(
234 reinterpret_cast<char*>(kTurnSendIndicationMsgWithSendTimeExtension),
235 sizeof(kTurnSendIndicationMsgWithSendTimeExtension),
236 &start_pos, &rtp_length));
237 EXPECT_EQ(20, rtp_length);
238 EXPECT_EQ(32, start_pos);
239
240 EXPECT_TRUE(socket_host_->MaybeUpdateRtpSendTimeExtn(
241 reinterpret_cast<char*>(kTurnSendIndicationMsgWithSendTimeExtension),
242 sizeof(kTurnSendIndicationMsgWithSendTimeExtension), 3));
243
244 EXPECT_TRUE(socket_host_->GetRtpPacketStartPositionAndLength(
245 reinterpret_cast<char*>(kRtpPacketWithSendTimeExtension),
246 sizeof(kRtpPacketWithSendTimeExtension),
247 &start_pos, &rtp_length));
248 EXPECT_EQ(20, rtp_length);
249 EXPECT_EQ(0, start_pos);
250
251 EXPECT_TRUE(socket_host_->MaybeUpdateRtpSendTimeExtn(
252 reinterpret_cast<char*>(kRtpPacketWithSendTimeExtension),
253 sizeof(kRtpPacketWithSendTimeExtension), 3));
254 }
255
256 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698