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

Side by Side Diff: trunk/src/content/browser/renderer_host/p2p/socket_host_udp_unittest.cc

Issue 177603002: Revert 252408 "Adding talk_base::PacketOptions to P2P IPC Send m..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 6 years, 9 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_udp.h" 5 #include "content/browser/renderer_host/p2p/socket_host_udp.h"
6 6
7 #include <deque> 7 #include <deque>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 }; 210 };
211 211
212 // Verify that we can send STUN messages before we receive anything 212 // Verify that we can send STUN messages before we receive anything
213 // from the other side. 213 // from the other side.
214 TEST_F(P2PSocketHostUdpTest, SendStunNoAuth) { 214 TEST_F(P2PSocketHostUdpTest, SendStunNoAuth) {
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(3) 217 .Times(3)
218 .WillRepeatedly(DoAll(DeleteArg<0>(), Return(true))); 218 .WillRepeatedly(DoAll(DeleteArg<0>(), Return(true)));
219 219
220 talk_base::PacketOptions options;
221 std::vector<char> packet1; 220 std::vector<char> packet1;
222 CreateStunRequest(&packet1); 221 CreateStunRequest(&packet1);
223 socket_host_->Send(dest1_, packet1, options, 0); 222 socket_host_->Send(dest1_, packet1, net::DSCP_NO_CHANGE, 0);
224 223
225 std::vector<char> packet2; 224 std::vector<char> packet2;
226 CreateStunResponse(&packet2); 225 CreateStunResponse(&packet2);
227 socket_host_->Send(dest1_, packet2, options, 0); 226 socket_host_->Send(dest1_, packet2, net::DSCP_NO_CHANGE, 0);
228 227
229 std::vector<char> packet3; 228 std::vector<char> packet3;
230 CreateStunError(&packet3); 229 CreateStunError(&packet3);
231 socket_host_->Send(dest1_, packet3, options, 0); 230 socket_host_->Send(dest1_, packet3, net::DSCP_NO_CHANGE, 0);
232 231
233 ASSERT_EQ(sent_packets_.size(), 3U); 232 ASSERT_EQ(sent_packets_.size(), 3U);
234 ASSERT_EQ(sent_packets_[0].second, packet1); 233 ASSERT_EQ(sent_packets_[0].second, packet1);
235 ASSERT_EQ(sent_packets_[1].second, packet2); 234 ASSERT_EQ(sent_packets_[1].second, packet2);
236 ASSERT_EQ(sent_packets_[2].second, packet3); 235 ASSERT_EQ(sent_packets_[2].second, packet3);
237 } 236 }
238 237
239 // Verify that no data packets can be sent before STUN binding has 238 // Verify that no data packets can be sent before STUN binding has
240 // finished. 239 // finished.
241 TEST_F(P2PSocketHostUdpTest, SendDataNoAuth) { 240 TEST_F(P2PSocketHostUdpTest, SendDataNoAuth) {
242 EXPECT_CALL(sender_, Send( 241 EXPECT_CALL(sender_, Send(
243 MatchMessage(static_cast<uint32>(P2PMsg_OnError::ID)))) 242 MatchMessage(static_cast<uint32>(P2PMsg_OnError::ID))))
244 .WillOnce(DoAll(DeleteArg<0>(), Return(true))); 243 .WillOnce(DoAll(DeleteArg<0>(), Return(true)));
245 244
246 talk_base::PacketOptions options;
247 std::vector<char> packet; 245 std::vector<char> packet;
248 CreateRandomPacket(&packet); 246 CreateRandomPacket(&packet);
249 socket_host_->Send(dest1_, packet, options, 0); 247 socket_host_->Send(dest1_, packet, net::DSCP_NO_CHANGE, 0);
250 248
251 ASSERT_EQ(sent_packets_.size(), 0U); 249 ASSERT_EQ(sent_packets_.size(), 0U);
252 } 250 }
253 251
254 // Verify that we can send data after we've received STUN request 252 // Verify that we can send data after we've received STUN request
255 // from the other side. 253 // from the other side.
256 TEST_F(P2PSocketHostUdpTest, SendAfterStunRequest) { 254 TEST_F(P2PSocketHostUdpTest, SendAfterStunRequest) {
257 // Receive packet from |dest1_|. 255 // Receive packet from |dest1_|.
258 std::vector<char> request_packet; 256 std::vector<char> request_packet;
259 CreateStunRequest(&request_packet); 257 CreateStunRequest(&request_packet);
260 258
261 EXPECT_CALL(sender_, Send(MatchPacketMessage(request_packet))) 259 EXPECT_CALL(sender_, Send(MatchPacketMessage(request_packet)))
262 .WillOnce(DoAll(DeleteArg<0>(), Return(true))); 260 .WillOnce(DoAll(DeleteArg<0>(), Return(true)));
263 socket_->ReceivePacket(dest1_, request_packet); 261 socket_->ReceivePacket(dest1_, request_packet);
264 262
265 // Now we should be able to send any data to |dest1_|. 263 // Now we should be able to send any data to |dest1_|.
266 EXPECT_CALL(sender_, Send( 264 EXPECT_CALL(sender_, Send(
267 MatchMessage(static_cast<uint32>(P2PMsg_OnSendComplete::ID)))) 265 MatchMessage(static_cast<uint32>(P2PMsg_OnSendComplete::ID))))
268 .WillOnce(DoAll(DeleteArg<0>(), Return(true))); 266 .WillOnce(DoAll(DeleteArg<0>(), Return(true)));
269
270 talk_base::PacketOptions options;
271 std::vector<char> packet; 267 std::vector<char> packet;
272 CreateRandomPacket(&packet); 268 CreateRandomPacket(&packet);
273 socket_host_->Send(dest1_, packet, options, 0); 269 socket_host_->Send(dest1_, packet, net::DSCP_NO_CHANGE, 0);
274 270
275 ASSERT_EQ(1U, sent_packets_.size()); 271 ASSERT_EQ(1U, sent_packets_.size());
276 ASSERT_EQ(dest1_, sent_packets_[0].first); 272 ASSERT_EQ(dest1_, sent_packets_[0].first);
277 } 273 }
278 274
279 // Verify that we can send data after we've received STUN response 275 // Verify that we can send data after we've received STUN response
280 // from the other side. 276 // from the other side.
281 TEST_F(P2PSocketHostUdpTest, SendAfterStunResponse) { 277 TEST_F(P2PSocketHostUdpTest, SendAfterStunResponse) {
282 // Receive packet from |dest1_|. 278 // Receive packet from |dest1_|.
283 std::vector<char> request_packet; 279 std::vector<char> request_packet;
284 CreateStunRequest(&request_packet); 280 CreateStunRequest(&request_packet);
285 281
286 EXPECT_CALL(sender_, Send(MatchPacketMessage(request_packet))) 282 EXPECT_CALL(sender_, Send(MatchPacketMessage(request_packet)))
287 .WillOnce(DoAll(DeleteArg<0>(), Return(true))); 283 .WillOnce(DoAll(DeleteArg<0>(), Return(true)));
288 socket_->ReceivePacket(dest1_, request_packet); 284 socket_->ReceivePacket(dest1_, request_packet);
289 285
290 // Now we should be able to send any data to |dest1_|. 286 // Now we should be able to send any data to |dest1_|.
291 EXPECT_CALL(sender_, Send( 287 EXPECT_CALL(sender_, Send(
292 MatchMessage(static_cast<uint32>(P2PMsg_OnSendComplete::ID)))) 288 MatchMessage(static_cast<uint32>(P2PMsg_OnSendComplete::ID))))
293 .WillOnce(DoAll(DeleteArg<0>(), Return(true))); 289 .WillOnce(DoAll(DeleteArg<0>(), Return(true)));
294
295 talk_base::PacketOptions options;
296 std::vector<char> packet; 290 std::vector<char> packet;
297 CreateRandomPacket(&packet); 291 CreateRandomPacket(&packet);
298 socket_host_->Send(dest1_, packet, options, 0); 292 socket_host_->Send(dest1_, packet, net::DSCP_NO_CHANGE, 0);
299 293
300 ASSERT_EQ(1U, sent_packets_.size()); 294 ASSERT_EQ(1U, sent_packets_.size());
301 ASSERT_EQ(dest1_, sent_packets_[0].first); 295 ASSERT_EQ(dest1_, sent_packets_[0].first);
302 } 296 }
303 297
304 // Verify messages still cannot be sent to an unathorized host after 298 // Verify messages still cannot be sent to an unathorized host after
305 // successful binding with different host. 299 // successful binding with different host.
306 TEST_F(P2PSocketHostUdpTest, SendAfterStunResponseDifferentHost) { 300 TEST_F(P2PSocketHostUdpTest, SendAfterStunResponseDifferentHost) {
307 // Receive packet from |dest1_|. 301 // Receive packet from |dest1_|.
308 std::vector<char> request_packet; 302 std::vector<char> request_packet;
309 CreateStunRequest(&request_packet); 303 CreateStunRequest(&request_packet);
310 304
311 EXPECT_CALL(sender_, Send(MatchPacketMessage(request_packet))) 305 EXPECT_CALL(sender_, Send(MatchPacketMessage(request_packet)))
312 .WillOnce(DoAll(DeleteArg<0>(), Return(true))); 306 .WillOnce(DoAll(DeleteArg<0>(), Return(true)));
313 socket_->ReceivePacket(dest1_, request_packet); 307 socket_->ReceivePacket(dest1_, request_packet);
314 308
315 // Should fail when trying to send the same packet to |dest2_|. 309 // Should fail when trying to send the same packet to |dest2_|.
316 talk_base::PacketOptions options;
317 std::vector<char> packet; 310 std::vector<char> packet;
318 CreateRandomPacket(&packet); 311 CreateRandomPacket(&packet);
319 EXPECT_CALL(sender_, Send( 312 EXPECT_CALL(sender_, Send(
320 MatchMessage(static_cast<uint32>(P2PMsg_OnError::ID)))) 313 MatchMessage(static_cast<uint32>(P2PMsg_OnError::ID))))
321 .WillOnce(DoAll(DeleteArg<0>(), Return(true))); 314 .WillOnce(DoAll(DeleteArg<0>(), Return(true)));
322 socket_host_->Send(dest2_, packet, options, 0); 315 socket_host_->Send(dest2_, packet, net::DSCP_NO_CHANGE, 0);
323 } 316 }
324 317
325 // Verify throttler not allowing unlimited sending of ICE messages to 318 // Verify throttler not allowing unlimited sending of ICE messages to
326 // any destination. 319 // any destination.
327 TEST_F(P2PSocketHostUdpTest, ThrottleAfterLimit) { 320 TEST_F(P2PSocketHostUdpTest, ThrottleAfterLimit) {
328 EXPECT_CALL(sender_, Send( 321 EXPECT_CALL(sender_, Send(
329 MatchMessage(static_cast<uint32>(P2PMsg_OnSendComplete::ID)))) 322 MatchMessage(static_cast<uint32>(P2PMsg_OnSendComplete::ID))))
330 .Times(2) 323 .Times(2)
331 .WillRepeatedly(DoAll(DeleteArg<0>(), Return(true))); 324 .WillRepeatedly(DoAll(DeleteArg<0>(), Return(true)));
332 325
333 talk_base::PacketOptions options;
334 std::vector<char> packet1; 326 std::vector<char> packet1;
335 CreateStunRequest(&packet1); 327 CreateStunRequest(&packet1);
336 throttler_.SetSendIceBandwidth(packet1.size() * 2); 328 throttler_.SetSendIceBandwidth(packet1.size() * 2);
337 socket_host_->Send(dest1_, packet1, options, 0); 329 socket_host_->Send(dest1_, packet1, net::DSCP_NO_CHANGE, 0);
338 socket_host_->Send(dest2_, packet1, options, 0); 330 socket_host_->Send(dest2_, packet1, net::DSCP_NO_CHANGE, 0);
339 331
340 net::IPEndPoint dest3 = ParseAddress(kTestIpAddress1, 2222); 332 net::IPEndPoint dest3 = ParseAddress(kTestIpAddress1, 2222);
341 // This packet must be dropped by the throttler. 333 // This packet must be dropped by the throttler.
342 socket_host_->Send(dest3, packet1, options, 0); 334 socket_host_->Send(dest3, packet1, net::DSCP_NO_CHANGE, 0);
343 ASSERT_EQ(sent_packets_.size(), 2U); 335 ASSERT_EQ(sent_packets_.size(), 2U);
344 } 336 }
345 337
346 // Verify we can send packets to a known destination when ICE throttling is 338 // Verify we can send packets to a known destination when ICE throttling is
347 // active. 339 // active.
348 TEST_F(P2PSocketHostUdpTest, ThrottleAfterLimitAfterReceive) { 340 TEST_F(P2PSocketHostUdpTest, ThrottleAfterLimitAfterReceive) {
349 // Receive packet from |dest1_|. 341 // Receive packet from |dest1_|.
350 std::vector<char> request_packet; 342 std::vector<char> request_packet;
351 CreateStunRequest(&request_packet); 343 CreateStunRequest(&request_packet);
352 344
353 EXPECT_CALL(sender_, Send(MatchPacketMessage(request_packet))) 345 EXPECT_CALL(sender_, Send(MatchPacketMessage(request_packet)))
354 .WillOnce(DoAll(DeleteArg<0>(), Return(true))); 346 .WillOnce(DoAll(DeleteArg<0>(), Return(true)));
355 socket_->ReceivePacket(dest1_, request_packet); 347 socket_->ReceivePacket(dest1_, request_packet);
356 348
357 EXPECT_CALL(sender_, Send( 349 EXPECT_CALL(sender_, Send(
358 MatchMessage(static_cast<uint32>(P2PMsg_OnSendComplete::ID)))) 350 MatchMessage(static_cast<uint32>(P2PMsg_OnSendComplete::ID))))
359 .Times(4) 351 .Times(4)
360 .WillRepeatedly(DoAll(DeleteArg<0>(), Return(true))); 352 .WillRepeatedly(DoAll(DeleteArg<0>(), Return(true)));
361 353
362 talk_base::PacketOptions options;
363 std::vector<char> packet1; 354 std::vector<char> packet1;
364 CreateStunRequest(&packet1); 355 CreateStunRequest(&packet1);
365 throttler_.SetSendIceBandwidth(packet1.size()); 356 throttler_.SetSendIceBandwidth(packet1.size());
366 // |dest1_| is known address, throttling will not be applied. 357 // |dest1_| is known address, throttling will not be applied.
367 socket_host_->Send(dest1_, packet1, options, 0); 358 socket_host_->Send(dest1_, packet1, net::DSCP_NO_CHANGE, 0);
368 // Trying to send the packet to dest1_ in the same window. It should go. 359 // Trying to send the packet to dest1_ in the same window. It should go.
369 socket_host_->Send(dest1_, packet1, options, 0); 360 socket_host_->Send(dest1_, packet1, net::DSCP_NO_CHANGE, 0);
370 361
371 // Throttler should allow this packet to go through. 362 // Throttler should allow this packet to go through.
372 socket_host_->Send(dest2_, packet1, options, 0); 363 socket_host_->Send(dest2_, packet1, net::DSCP_NO_CHANGE, 0);
373 364
374 net::IPEndPoint dest3 = ParseAddress(kTestIpAddress1, 2223); 365 net::IPEndPoint dest3 = ParseAddress(kTestIpAddress1, 2223);
375 // This packet will be dropped, as limit only for a single packet. 366 // This packet will be dropped, as limit only for a single packet.
376 socket_host_->Send(dest3, packet1, options, 0); 367 socket_host_->Send(dest3, packet1, net::DSCP_NO_CHANGE, 0);
377 net::IPEndPoint dest4 = ParseAddress(kTestIpAddress1, 2224); 368 net::IPEndPoint dest4 = ParseAddress(kTestIpAddress1, 2224);
378 // This packet should also be dropped. 369 // This packet should also be dropped.
379 socket_host_->Send(dest4, packet1, options, 0); 370 socket_host_->Send(dest4, packet1, net::DSCP_NO_CHANGE, 0);
380 // |dest1| is known, we can send as many packets to it. 371 // |dest1| is known, we can send as many packets to it.
381 socket_host_->Send(dest1_, packet1, options, 0); 372 socket_host_->Send(dest1_, packet1, net::DSCP_NO_CHANGE, 0);
382 ASSERT_EQ(sent_packets_.size(), 4U); 373 ASSERT_EQ(sent_packets_.size(), 4U);
383 } 374 }
384 375
385 } // namespace content 376 } // namespace content
OLDNEW
« no previous file with comments | « trunk/src/content/browser/renderer_host/p2p/socket_host_udp.cc ('k') | trunk/src/content/common/p2p_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698