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

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

Issue 2315223004: Fix P2PSocketHostUdp to handle dropped packets properly. (Closed)
Patch Set: Created 4 years, 3 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 | « content/browser/renderer_host/p2p/socket_host_udp.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <stdint.h> 7 #include <stdint.h>
8 #include <deque> 8 #include <deque>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 .WillOnce(DoAll(DeleteArg<0>(), Return(true))); 348 .WillOnce(DoAll(DeleteArg<0>(), Return(true)));
349 socket_host_->Send(dest2_, packet, options, 0); 349 socket_host_->Send(dest2_, packet, options, 0);
350 } 350 }
351 351
352 // Verify throttler not allowing unlimited sending of ICE messages to 352 // Verify throttler not allowing unlimited sending of ICE messages to
353 // any destination. 353 // any destination.
354 TEST_F(P2PSocketHostUdpTest, ThrottleAfterLimit) { 354 TEST_F(P2PSocketHostUdpTest, ThrottleAfterLimit) {
355 EXPECT_CALL( 355 EXPECT_CALL(
356 sender_, 356 sender_,
357 Send(MatchMessage(static_cast<uint32_t>(P2PMsg_OnSendComplete::ID)))) 357 Send(MatchMessage(static_cast<uint32_t>(P2PMsg_OnSendComplete::ID))))
358 .Times(2) 358 .Times(3)
359 .WillRepeatedly(DoAll(DeleteArg<0>(), Return(true))); 359 .WillRepeatedly(DoAll(DeleteArg<0>(), Return(true)));
360 360
361 rtc::PacketOptions options; 361 rtc::PacketOptions options;
362 std::vector<char> packet1; 362 std::vector<char> packet1;
363 CreateStunRequest(&packet1); 363 CreateStunRequest(&packet1);
364 throttler_.SetSendIceBandwidth(packet1.size() * 2); 364 throttler_.SetSendIceBandwidth(packet1.size() * 2);
365 socket_host_->Send(dest1_, packet1, options, 0); 365 socket_host_->Send(dest1_, packet1, options, 0);
366 socket_host_->Send(dest2_, packet1, options, 0); 366 socket_host_->Send(dest2_, packet1, options, 0);
367 367
368 net::IPEndPoint dest3 = ParseAddress(kTestIpAddress1, 2222); 368 net::IPEndPoint dest3 = ParseAddress(kTestIpAddress1, 2222);
369 // This packet must be dropped by the throttler. 369 // This packet must be dropped by the throttler.
370 socket_host_->Send(dest3, packet1, options, 0); 370 socket_host_->Send(dest3, packet1, options, 0);
371 ASSERT_EQ(sent_packets_.size(), 2U); 371 ASSERT_EQ(sent_packets_.size(), 2U);
372 } 372 }
373 373
374 // Verify we can send packets to a known destination when ICE throttling is 374 // Verify we can send packets to a known destination when ICE throttling is
375 // active. 375 // active.
376 TEST_F(P2PSocketHostUdpTest, ThrottleAfterLimitAfterReceive) { 376 TEST_F(P2PSocketHostUdpTest, ThrottleAfterLimitAfterReceive) {
377 // Receive packet from |dest1_|. 377 // Receive packet from |dest1_|.
378 std::vector<char> request_packet; 378 std::vector<char> request_packet;
379 CreateStunRequest(&request_packet); 379 CreateStunRequest(&request_packet);
380 380
381 EXPECT_CALL(sender_, Send(MatchPacketMessage(request_packet))) 381 EXPECT_CALL(sender_, Send(MatchPacketMessage(request_packet)))
382 .WillOnce(DoAll(DeleteArg<0>(), Return(true))); 382 .WillOnce(DoAll(DeleteArg<0>(), Return(true)));
383 socket_->ReceivePacket(dest1_, request_packet); 383 socket_->ReceivePacket(dest1_, request_packet);
384 384
385 EXPECT_CALL( 385 EXPECT_CALL(
386 sender_, 386 sender_,
387 Send(MatchMessage(static_cast<uint32_t>(P2PMsg_OnSendComplete::ID)))) 387 Send(MatchMessage(static_cast<uint32_t>(P2PMsg_OnSendComplete::ID))))
388 .Times(4) 388 .Times(6)
389 .WillRepeatedly(DoAll(DeleteArg<0>(), Return(true))); 389 .WillRepeatedly(DoAll(DeleteArg<0>(), Return(true)));
390 390
391 rtc::PacketOptions options; 391 rtc::PacketOptions options;
392 std::vector<char> packet1; 392 std::vector<char> packet1;
393 CreateStunRequest(&packet1); 393 CreateStunRequest(&packet1);
394 throttler_.SetSendIceBandwidth(packet1.size()); 394 throttler_.SetSendIceBandwidth(packet1.size());
395 // |dest1_| is known address, throttling will not be applied. 395 // |dest1_| is known address, throttling will not be applied.
396 socket_host_->Send(dest1_, packet1, options, 0); 396 socket_host_->Send(dest1_, packet1, options, 0);
397 // Trying to send the packet to dest1_ in the same window. It should go. 397 // Trying to send the packet to dest1_ in the same window. It should go.
398 socket_host_->Send(dest1_, packet1, options, 0); 398 socket_host_->Send(dest1_, packet1, options, 0);
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 std::unique_ptr<P2PSocketHostUdp> socket_host( 502 std::unique_ptr<P2PSocketHostUdp> socket_host(
503 new P2PSocketHostUdp(&sender, 0, &throttler, fake_socket_factory)); 503 new P2PSocketHostUdp(&sender, 0, &throttler, fake_socket_factory));
504 net::IPEndPoint local_address = 504 net::IPEndPoint local_address =
505 ParseAddress(kTestLocalIpAddress, invalid_port); 505 ParseAddress(kTestLocalIpAddress, invalid_port);
506 bool rv = socket_host->Init(local_address, min_port, max_port, 506 bool rv = socket_host->Init(local_address, min_port, max_port,
507 P2PHostAndIPEndPoint()); 507 P2PHostAndIPEndPoint());
508 EXPECT_FALSE(rv); 508 EXPECT_FALSE(rv);
509 } 509 }
510 510
511 } // namespace content 511 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/p2p/socket_host_udp.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698