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

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

Issue 22381012: Allow p2p UDP packages to set DSCP (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: win fix Created 7 years, 2 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/browser/renderer_host/p2p/socket_host_tcp.h" 5 #include "content/browser/renderer_host/p2p/socket_host_tcp.h"
6 6
7 #include <deque> 7 #include <deque>
8 8
9 #include "base/sys_byteorder.h" 9 #include "base/sys_byteorder.h"
10 #include "content/browser/renderer_host/p2p/socket_host_test_utils.h" 10 #include "content/browser/renderer_host/p2p/socket_host_test_utils.h"
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 // Verify that we can send STUN message and that they are formatted 87 // Verify that we can send STUN message and that they are formatted
88 // properly. 88 // properly.
89 TEST_F(P2PSocketHostTcpTest, SendStunNoAuth) { 89 TEST_F(P2PSocketHostTcpTest, SendStunNoAuth) {
90 EXPECT_CALL(sender_, Send( 90 EXPECT_CALL(sender_, Send(
91 MatchMessage(static_cast<uint32>(P2PMsg_OnSendComplete::ID)))) 91 MatchMessage(static_cast<uint32>(P2PMsg_OnSendComplete::ID))))
92 .Times(3) 92 .Times(3)
93 .WillRepeatedly(DoAll(DeleteArg<0>(), Return(true))); 93 .WillRepeatedly(DoAll(DeleteArg<0>(), Return(true)));
94 94
95 std::vector<char> packet1; 95 std::vector<char> packet1;
96 CreateStunRequest(&packet1); 96 CreateStunRequest(&packet1);
97 socket_host_->Send(dest_, packet1, 0); 97 socket_host_->Send(dest_, packet1, net::DSCP_NO_CHANGE, 0);
98 98
99 std::vector<char> packet2; 99 std::vector<char> packet2;
100 CreateStunResponse(&packet2); 100 CreateStunResponse(&packet2);
101 socket_host_->Send(dest_, packet2, 0); 101 socket_host_->Send(dest_, packet2, net::DSCP_NO_CHANGE, 0);
102 102
103 std::vector<char> packet3; 103 std::vector<char> packet3;
104 CreateStunError(&packet3); 104 CreateStunError(&packet3);
105 socket_host_->Send(dest_, packet3, 0); 105 socket_host_->Send(dest_, packet3, net::DSCP_NO_CHANGE, 0);
106 106
107 std::string expected_data; 107 std::string expected_data;
108 expected_data.append(IntToSize(packet1.size())); 108 expected_data.append(IntToSize(packet1.size()));
109 expected_data.append(packet1.begin(), packet1.end()); 109 expected_data.append(packet1.begin(), packet1.end());
110 expected_data.append(IntToSize(packet2.size())); 110 expected_data.append(IntToSize(packet2.size()));
111 expected_data.append(packet2.begin(), packet2.end()); 111 expected_data.append(packet2.begin(), packet2.end());
112 expected_data.append(IntToSize(packet3.size())); 112 expected_data.append(IntToSize(packet3.size()));
113 expected_data.append(packet3.begin(), packet3.end()); 113 expected_data.append(packet3.begin(), packet3.end());
114 114
115 EXPECT_EQ(expected_data, sent_data_); 115 EXPECT_EQ(expected_data, sent_data_);
116 } 116 }
117 117
118 // Verify that we can receive STUN messages from the socket, and that 118 // Verify that we can receive STUN messages from the socket, and that
119 // the messages are parsed properly. 119 // the messages are parsed properly.
120 TEST_F(P2PSocketHostTcpTest, ReceiveStun) { 120 TEST_F(P2PSocketHostTcpTest, ReceiveStun) {
121 EXPECT_CALL(sender_, Send( 121 EXPECT_CALL(sender_, Send(
122 MatchMessage(static_cast<uint32>(P2PMsg_OnSendComplete::ID)))) 122 MatchMessage(static_cast<uint32>(P2PMsg_OnSendComplete::ID))))
123 .Times(3) 123 .Times(3)
124 .WillRepeatedly(DoAll(DeleteArg<0>(), Return(true))); 124 .WillRepeatedly(DoAll(DeleteArg<0>(), Return(true)));
125 125
126 std::vector<char> packet1; 126 std::vector<char> packet1;
127 CreateStunRequest(&packet1); 127 CreateStunRequest(&packet1);
128 socket_host_->Send(dest_, packet1, 0); 128 socket_host_->Send(dest_, packet1, net::DSCP_NO_CHANGE, 0);
129 129
130 std::vector<char> packet2; 130 std::vector<char> packet2;
131 CreateStunResponse(&packet2); 131 CreateStunResponse(&packet2);
132 socket_host_->Send(dest_, packet2, 0); 132 socket_host_->Send(dest_, packet2, net::DSCP_NO_CHANGE, 0);
133 133
134 std::vector<char> packet3; 134 std::vector<char> packet3;
135 CreateStunError(&packet3); 135 CreateStunError(&packet3);
136 socket_host_->Send(dest_, packet3, 0); 136 socket_host_->Send(dest_, packet3, net::DSCP_NO_CHANGE, 0);
137 137
138 std::string received_data; 138 std::string received_data;
139 received_data.append(IntToSize(packet1.size())); 139 received_data.append(IntToSize(packet1.size()));
140 received_data.append(packet1.begin(), packet1.end()); 140 received_data.append(packet1.begin(), packet1.end());
141 received_data.append(IntToSize(packet2.size())); 141 received_data.append(IntToSize(packet2.size()));
142 received_data.append(packet2.begin(), packet2.end()); 142 received_data.append(packet2.begin(), packet2.end());
143 received_data.append(IntToSize(packet3.size())); 143 received_data.append(IntToSize(packet3.size()));
144 received_data.append(packet3.begin(), packet3.end()); 144 received_data.append(packet3.begin(), packet3.end());
145 145
146 EXPECT_CALL(sender_, Send(MatchPacketMessage(packet1))) 146 EXPECT_CALL(sender_, Send(MatchPacketMessage(packet1)))
(...skipping 17 matching lines...) Expand all
164 164
165 // Verify that we can't send data before we've received STUN response 165 // Verify that we can't send data before we've received STUN response
166 // from the other side. 166 // from the other side.
167 TEST_F(P2PSocketHostTcpTest, SendDataNoAuth) { 167 TEST_F(P2PSocketHostTcpTest, SendDataNoAuth) {
168 EXPECT_CALL(sender_, Send( 168 EXPECT_CALL(sender_, Send(
169 MatchMessage(static_cast<uint32>(P2PMsg_OnError::ID)))) 169 MatchMessage(static_cast<uint32>(P2PMsg_OnError::ID))))
170 .WillOnce(DoAll(DeleteArg<0>(), Return(true))); 170 .WillOnce(DoAll(DeleteArg<0>(), Return(true)));
171 171
172 std::vector<char> packet; 172 std::vector<char> packet;
173 CreateRandomPacket(&packet); 173 CreateRandomPacket(&packet);
174 socket_host_->Send(dest_, packet, 0); 174 socket_host_->Send(dest_, packet, net::DSCP_NO_CHANGE, 0);
175 175
176 EXPECT_EQ(0U, sent_data_.size()); 176 EXPECT_EQ(0U, sent_data_.size());
177 } 177 }
178 178
179 // Verify that we can send data after we've received STUN response 179 // Verify that we can send data after we've received STUN response
180 // from the other side. 180 // from the other side.
181 TEST_F(P2PSocketHostTcpTest, SendAfterStunRequest) { 181 TEST_F(P2PSocketHostTcpTest, SendAfterStunRequest) {
182 // Receive packet from |dest_|. 182 // Receive packet from |dest_|.
183 std::vector<char> request_packet; 183 std::vector<char> request_packet;
184 CreateStunRequest(&request_packet); 184 CreateStunRequest(&request_packet);
185 185
186 std::string received_data; 186 std::string received_data;
187 received_data.append(IntToSize(request_packet.size())); 187 received_data.append(IntToSize(request_packet.size()));
188 received_data.append(request_packet.begin(), request_packet.end()); 188 received_data.append(request_packet.begin(), request_packet.end());
189 189
190 EXPECT_CALL(sender_, Send( 190 EXPECT_CALL(sender_, Send(
191 MatchMessage(static_cast<uint32>(P2PMsg_OnSendComplete::ID)))) 191 MatchMessage(static_cast<uint32>(P2PMsg_OnSendComplete::ID))))
192 .WillOnce(DoAll(DeleteArg<0>(), Return(true))); 192 .WillOnce(DoAll(DeleteArg<0>(), Return(true)));
193 EXPECT_CALL(sender_, Send(MatchPacketMessage(request_packet))) 193 EXPECT_CALL(sender_, Send(MatchPacketMessage(request_packet)))
194 .WillOnce(DoAll(DeleteArg<0>(), Return(true))); 194 .WillOnce(DoAll(DeleteArg<0>(), Return(true)));
195 socket_->AppendInputData(&received_data[0], received_data.size()); 195 socket_->AppendInputData(&received_data[0], received_data.size());
196 196
197 // Now we should be able to send any data to |dest_|. 197 // Now we should be able to send any data to |dest_|.
198 std::vector<char> packet; 198 std::vector<char> packet;
199 CreateRandomPacket(&packet); 199 CreateRandomPacket(&packet);
200 socket_host_->Send(dest_, packet, 0); 200 socket_host_->Send(dest_, packet, net::DSCP_NO_CHANGE, 0);
201 201
202 std::string expected_data; 202 std::string expected_data;
203 expected_data.append(IntToSize(packet.size())); 203 expected_data.append(IntToSize(packet.size()));
204 expected_data.append(packet.begin(), packet.end()); 204 expected_data.append(packet.begin(), packet.end());
205 205
206 EXPECT_EQ(expected_data, sent_data_); 206 EXPECT_EQ(expected_data, sent_data_);
207 } 207 }
208 208
209 // Verify that asynchronous writes are handled correctly. 209 // Verify that asynchronous writes are handled correctly.
210 TEST_F(P2PSocketHostTcpTest, AsyncWrites) { 210 TEST_F(P2PSocketHostTcpTest, AsyncWrites) {
211 base::MessageLoop message_loop; 211 base::MessageLoop message_loop;
212 212
213 socket_->set_async_write(true); 213 socket_->set_async_write(true);
214 214
215 EXPECT_CALL(sender_, Send( 215 EXPECT_CALL(sender_, Send(
216 MatchMessage(static_cast<uint32>(P2PMsg_OnSendComplete::ID)))) 216 MatchMessage(static_cast<uint32>(P2PMsg_OnSendComplete::ID))))
217 .Times(2) 217 .Times(2)
218 .WillRepeatedly(DoAll(DeleteArg<0>(), Return(true))); 218 .WillRepeatedly(DoAll(DeleteArg<0>(), Return(true)));
219 219
220 std::vector<char> packet1; 220 std::vector<char> packet1;
221 CreateStunRequest(&packet1); 221 CreateStunRequest(&packet1);
222 socket_host_->Send(dest_, packet1, 0); 222
223 socket_host_->Send(dest_, packet1, net::DSCP_NO_CHANGE, 0);
223 224
224 std::vector<char> packet2; 225 std::vector<char> packet2;
225 CreateStunResponse(&packet2); 226 CreateStunResponse(&packet2);
226 socket_host_->Send(dest_, packet2, 0); 227 socket_host_->Send(dest_, packet2, net::DSCP_NO_CHANGE, 0);
227 228
228 message_loop.RunUntilIdle(); 229 message_loop.RunUntilIdle();
229 230
230 std::string expected_data; 231 std::string expected_data;
231 expected_data.append(IntToSize(packet1.size())); 232 expected_data.append(IntToSize(packet1.size()));
232 expected_data.append(packet1.begin(), packet1.end()); 233 expected_data.append(packet1.begin(), packet1.end());
233 expected_data.append(IntToSize(packet2.size())); 234 expected_data.append(IntToSize(packet2.size()));
234 expected_data.append(packet2.begin(), packet2.end()); 235 expected_data.append(packet2.begin(), packet2.end());
235 236
236 EXPECT_EQ(expected_data, sent_data_); 237 EXPECT_EQ(expected_data, sent_data_);
237 } 238 }
238 239
239 // Verify that we can send STUN message and that they are formatted 240 // Verify that we can send STUN message and that they are formatted
240 // properly. 241 // properly.
241 TEST_F(P2PSocketHostStunTcpTest, SendStunNoAuth) { 242 TEST_F(P2PSocketHostStunTcpTest, SendStunNoAuth) {
242 EXPECT_CALL(sender_, Send( 243 EXPECT_CALL(sender_, Send(
243 MatchMessage(static_cast<uint32>(P2PMsg_OnSendComplete::ID)))) 244 MatchMessage(static_cast<uint32>(P2PMsg_OnSendComplete::ID))))
244 .Times(3) 245 .Times(3)
245 .WillRepeatedly(DoAll(DeleteArg<0>(), Return(true))); 246 .WillRepeatedly(DoAll(DeleteArg<0>(), Return(true)));
246 247
247 std::vector<char> packet1; 248 std::vector<char> packet1;
248 CreateStunRequest(&packet1); 249 CreateStunRequest(&packet1);
249 socket_host_->Send(dest_, packet1, 0); 250 socket_host_->Send(dest_, packet1, net::DSCP_NO_CHANGE, 0);
250 251
251 std::vector<char> packet2; 252 std::vector<char> packet2;
252 CreateStunResponse(&packet2); 253 CreateStunResponse(&packet2);
253 socket_host_->Send(dest_, packet2, 0); 254 socket_host_->Send(dest_, packet2, net::DSCP_NO_CHANGE, 0);
254 255
255 std::vector<char> packet3; 256 std::vector<char> packet3;
256 CreateStunError(&packet3); 257 CreateStunError(&packet3);
257 socket_host_->Send(dest_, packet3, 0); 258 socket_host_->Send(dest_, packet3, net::DSCP_NO_CHANGE, 0);
258 259
259 std::string expected_data; 260 std::string expected_data;
260 expected_data.append(packet1.begin(), packet1.end()); 261 expected_data.append(packet1.begin(), packet1.end());
261 expected_data.append(packet2.begin(), packet2.end()); 262 expected_data.append(packet2.begin(), packet2.end());
262 expected_data.append(packet3.begin(), packet3.end()); 263 expected_data.append(packet3.begin(), packet3.end());
263 264
264 EXPECT_EQ(expected_data, sent_data_); 265 EXPECT_EQ(expected_data, sent_data_);
265 } 266 }
266 267
267 // Verify that we can receive STUN messages from the socket, and that 268 // Verify that we can receive STUN messages from the socket, and that
268 // the messages are parsed properly. 269 // the messages are parsed properly.
269 TEST_F(P2PSocketHostStunTcpTest, ReceiveStun) { 270 TEST_F(P2PSocketHostStunTcpTest, ReceiveStun) {
270 EXPECT_CALL(sender_, Send( 271 EXPECT_CALL(sender_, Send(
271 MatchMessage(static_cast<uint32>(P2PMsg_OnSendComplete::ID)))) 272 MatchMessage(static_cast<uint32>(P2PMsg_OnSendComplete::ID))))
272 .Times(3) 273 .Times(3)
273 .WillRepeatedly(DoAll(DeleteArg<0>(), Return(true))); 274 .WillRepeatedly(DoAll(DeleteArg<0>(), Return(true)));
274 275
275 std::vector<char> packet1; 276 std::vector<char> packet1;
276 CreateStunRequest(&packet1); 277 CreateStunRequest(&packet1);
277 socket_host_->Send(dest_, packet1, 0); 278 socket_host_->Send(dest_, packet1, net::DSCP_NO_CHANGE, 0);
278 279
279 std::vector<char> packet2; 280 std::vector<char> packet2;
280 CreateStunResponse(&packet2); 281 CreateStunResponse(&packet2);
281 socket_host_->Send(dest_, packet2, 0); 282 socket_host_->Send(dest_, packet2, net::DSCP_NO_CHANGE, 0);
282 283
283 std::vector<char> packet3; 284 std::vector<char> packet3;
284 CreateStunError(&packet3); 285 CreateStunError(&packet3);
285 socket_host_->Send(dest_, packet3, 0); 286 socket_host_->Send(dest_, packet3, net::DSCP_NO_CHANGE, 0);
286 287
287 std::string received_data; 288 std::string received_data;
288 received_data.append(packet1.begin(), packet1.end()); 289 received_data.append(packet1.begin(), packet1.end());
289 received_data.append(packet2.begin(), packet2.end()); 290 received_data.append(packet2.begin(), packet2.end());
290 received_data.append(packet3.begin(), packet3.end()); 291 received_data.append(packet3.begin(), packet3.end());
291 292
292 EXPECT_CALL(sender_, Send(MatchPacketMessage(packet1))) 293 EXPECT_CALL(sender_, Send(MatchPacketMessage(packet1)))
293 .WillOnce(DoAll(DeleteArg<0>(), Return(true))); 294 .WillOnce(DoAll(DeleteArg<0>(), Return(true)));
294 EXPECT_CALL(sender_, Send(MatchPacketMessage(packet2))) 295 EXPECT_CALL(sender_, Send(MatchPacketMessage(packet2)))
295 .WillOnce(DoAll(DeleteArg<0>(), Return(true))); 296 .WillOnce(DoAll(DeleteArg<0>(), Return(true)));
(...skipping 14 matching lines...) Expand all
310 311
311 // Verify that we can't send data before we've received STUN response 312 // Verify that we can't send data before we've received STUN response
312 // from the other side. 313 // from the other side.
313 TEST_F(P2PSocketHostStunTcpTest, SendDataNoAuth) { 314 TEST_F(P2PSocketHostStunTcpTest, SendDataNoAuth) {
314 EXPECT_CALL(sender_, Send( 315 EXPECT_CALL(sender_, Send(
315 MatchMessage(static_cast<uint32>(P2PMsg_OnError::ID)))) 316 MatchMessage(static_cast<uint32>(P2PMsg_OnError::ID))))
316 .WillOnce(DoAll(DeleteArg<0>(), Return(true))); 317 .WillOnce(DoAll(DeleteArg<0>(), Return(true)));
317 318
318 std::vector<char> packet; 319 std::vector<char> packet;
319 CreateRandomPacket(&packet); 320 CreateRandomPacket(&packet);
320 socket_host_->Send(dest_, packet, 0); 321 socket_host_->Send(dest_, packet, net::DSCP_NO_CHANGE, 0);
321 322
322 EXPECT_EQ(0U, sent_data_.size()); 323 EXPECT_EQ(0U, sent_data_.size());
323 } 324 }
324 325
325 // Verify that asynchronous writes are handled correctly. 326 // Verify that asynchronous writes are handled correctly.
326 TEST_F(P2PSocketHostStunTcpTest, AsyncWrites) { 327 TEST_F(P2PSocketHostStunTcpTest, AsyncWrites) {
327 base::MessageLoop message_loop; 328 base::MessageLoop message_loop;
328 329
329 socket_->set_async_write(true); 330 socket_->set_async_write(true);
330 331
331 EXPECT_CALL(sender_, Send( 332 EXPECT_CALL(sender_, Send(
332 MatchMessage(static_cast<uint32>(P2PMsg_OnSendComplete::ID)))) 333 MatchMessage(static_cast<uint32>(P2PMsg_OnSendComplete::ID))))
333 .Times(2) 334 .Times(2)
334 .WillRepeatedly(DoAll(DeleteArg<0>(), Return(true))); 335 .WillRepeatedly(DoAll(DeleteArg<0>(), Return(true)));
335 336
336 std::vector<char> packet1; 337 std::vector<char> packet1;
337 CreateStunRequest(&packet1); 338 CreateStunRequest(&packet1);
338 socket_host_->Send(dest_, packet1, 0); 339 socket_host_->Send(dest_, packet1, net::DSCP_NO_CHANGE,0);
339 340
340 std::vector<char> packet2; 341 std::vector<char> packet2;
341 CreateStunResponse(&packet2); 342 CreateStunResponse(&packet2);
342 socket_host_->Send(dest_, packet2, 0); 343 socket_host_->Send(dest_, packet2, net::DSCP_NO_CHANGE, 0);
343 344
344 message_loop.RunUntilIdle(); 345 message_loop.RunUntilIdle();
345 346
346 std::string expected_data; 347 std::string expected_data;
347 expected_data.append(packet1.begin(), packet1.end()); 348 expected_data.append(packet1.begin(), packet1.end());
348 expected_data.append(packet2.begin(), packet2.end()); 349 expected_data.append(packet2.begin(), packet2.end());
349 350
350 EXPECT_EQ(expected_data, sent_data_); 351 EXPECT_EQ(expected_data, sent_data_);
351 } 352 }
352 353
353 } // namespace content 354 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/p2p/socket_host_tcp_server.cc ('k') | content/browser/renderer_host/p2p/socket_host_udp.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698