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

Side by Side Diff: net/quic/quic_connection_test.cc

Issue 822713002: Update from https://crrev.com/309415 (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 12 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 (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 "net/quic/quic_connection.h" 5 #include "net/quic/quic_connection.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "net/base/net_errors.h" 10 #include "net/base/net_errors.h"
(...skipping 1328 matching lines...) Expand 10 before | Expand all | Expand 10 after
1339 1339
1340 TEST_P(QuicConnectionTest, TooManySentPackets) { 1340 TEST_P(QuicConnectionTest, TooManySentPackets) {
1341 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1341 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1342 1342
1343 for (int i = 0; i < 1100; ++i) { 1343 for (int i = 0; i < 1100; ++i) {
1344 SendStreamDataToPeer(1, "foo", 3 * i, !kFin, nullptr); 1344 SendStreamDataToPeer(1, "foo", 3 * i, !kFin, nullptr);
1345 } 1345 }
1346 1346
1347 // Ack packet 1, which leaves more than the limit outstanding. 1347 // Ack packet 1, which leaves more than the limit outstanding.
1348 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); 1348 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
1349 if (FLAGS_quic_too_many_outstanding_packets) { 1349 EXPECT_CALL(visitor_, OnConnectionClosed(
1350 EXPECT_CALL(visitor_, 1350 QUIC_TOO_MANY_OUTSTANDING_SENT_PACKETS, false));
1351 OnConnectionClosed(QUIC_TOO_MANY_OUTSTANDING_SENT_PACKETS,
1352 false));
1353 }
1354 // We're receive buffer limited, so the connection won't try to write more. 1351 // We're receive buffer limited, so the connection won't try to write more.
1355 EXPECT_CALL(visitor_, OnCanWrite()).Times(0); 1352 EXPECT_CALL(visitor_, OnCanWrite()).Times(0);
1356 1353
1357 // Nack every packet except the last one, leaving a huge gap. 1354 // Nack every packet except the last one, leaving a huge gap.
1358 QuicAckFrame frame1 = InitAckFrame(1100); 1355 QuicAckFrame frame1 = InitAckFrame(1100);
1359 for (QuicPacketSequenceNumber i = 1; i < 1100; ++i) { 1356 for (QuicPacketSequenceNumber i = 1; i < 1100; ++i) {
1360 NackPacket(i, &frame1); 1357 NackPacket(i, &frame1);
1361 } 1358 }
1362 ProcessAckPacket(&frame1); 1359 ProcessAckPacket(&frame1);
1363 } 1360 }
1364 1361
1365 TEST_P(QuicConnectionTest, TooManyReceivedPackets) { 1362 TEST_P(QuicConnectionTest, TooManyReceivedPackets) {
1366 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1363 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1367 1364 EXPECT_CALL(visitor_, OnConnectionClosed(
1368 if (FLAGS_quic_too_many_outstanding_packets) { 1365 QUIC_TOO_MANY_OUTSTANDING_RECEIVED_PACKETS, false));
1369 EXPECT_CALL(visitor_,
1370 OnConnectionClosed(QUIC_TOO_MANY_OUTSTANDING_RECEIVED_PACKETS,
1371 false));
1372 }
1373 1366
1374 // Miss every other packet for 1000 packets. 1367 // Miss every other packet for 1000 packets.
1375 for (QuicPacketSequenceNumber i = 1; i < 1000; ++i) { 1368 for (QuicPacketSequenceNumber i = 1; i < 1000; ++i) {
1376 ProcessPacket(i * 2); 1369 ProcessPacket(i * 2);
1377 if (!connection_.connected()) { 1370 if (!connection_.connected()) {
1378 break; 1371 break;
1379 } 1372 }
1380 } 1373 }
1381 } 1374 }
1382 1375
(...skipping 1153 matching lines...) Expand 10 before | Expand all | Expand 10 after
2536 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(0x02)); 2529 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(0x02));
2537 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL); 2530 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL);
2538 2531
2539 SendStreamDataToPeer(2, "bar", 0, !kFin, nullptr); 2532 SendStreamDataToPeer(2, "bar", 0, !kFin, nullptr);
2540 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); 2533 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1);
2541 2534
2542 connection_.RetransmitUnackedPackets(ALL_INITIAL_RETRANSMISSION); 2535 connection_.RetransmitUnackedPackets(ALL_INITIAL_RETRANSMISSION);
2543 } 2536 }
2544 2537
2545 TEST_P(QuicConnectionTest, DelayForwardSecureEncryptionUntilClientIsReady) { 2538 TEST_P(QuicConnectionTest, DelayForwardSecureEncryptionUntilClientIsReady) {
2546 ValueRestore<bool> old_flag(&FLAGS_enable_quic_delay_forward_security, true);
2547
2548 // A TaggingEncrypter puts kTagSize copies of the given byte (0x02 here) at 2539 // A TaggingEncrypter puts kTagSize copies of the given byte (0x02 here) at
2549 // the end of the packet. We can test this to check which encrypter was used. 2540 // the end of the packet. We can test this to check which encrypter was used.
2550 use_tagging_decrypter(); 2541 use_tagging_decrypter();
2551 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(0x02)); 2542 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(0x02));
2552 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL); 2543 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL);
2553 SendAckPacketToPeer(); 2544 SendAckPacketToPeer();
2554 EXPECT_EQ(0x02020202u, writer_->final_bytes_of_last_packet()); 2545 EXPECT_EQ(0x02020202u, writer_->final_bytes_of_last_packet());
2555 2546
2556 // Set a forward-secure encrypter but do not make it the default, and verify 2547 // Set a forward-secure encrypter but do not make it the default, and verify
2557 // that it is not yet used. 2548 // that it is not yet used.
2558 connection_.SetEncrypter(ENCRYPTION_FORWARD_SECURE, 2549 connection_.SetEncrypter(ENCRYPTION_FORWARD_SECURE,
2559 new TaggingEncrypter(0x03)); 2550 new TaggingEncrypter(0x03));
2560 SendAckPacketToPeer(); 2551 SendAckPacketToPeer();
2561 EXPECT_EQ(0x02020202u, writer_->final_bytes_of_last_packet()); 2552 EXPECT_EQ(0x02020202u, writer_->final_bytes_of_last_packet());
2562 2553
2563 // Now simulate receipt of a forward-secure packet and verify that the 2554 // Now simulate receipt of a forward-secure packet and verify that the
2564 // forward-secure encrypter is now used. 2555 // forward-secure encrypter is now used.
2565 connection_.OnDecryptedPacket(ENCRYPTION_FORWARD_SECURE); 2556 connection_.OnDecryptedPacket(ENCRYPTION_FORWARD_SECURE);
2566 SendAckPacketToPeer(); 2557 SendAckPacketToPeer();
2567 EXPECT_EQ(0x03030303u, writer_->final_bytes_of_last_packet()); 2558 EXPECT_EQ(0x03030303u, writer_->final_bytes_of_last_packet());
2568 } 2559 }
2569 2560
2570 TEST_P(QuicConnectionTest, DelayForwardSecureEncryptionUntilManyPacketSent) { 2561 TEST_P(QuicConnectionTest, DelayForwardSecureEncryptionUntilManyPacketSent) {
2571 ValueRestore<bool> old_flag(&FLAGS_enable_quic_delay_forward_security, true);
2572
2573 // Set a congestion window of 10 packets. 2562 // Set a congestion window of 10 packets.
2574 QuicPacketCount congestion_window = 10; 2563 QuicPacketCount congestion_window = 10;
2575 EXPECT_CALL(*send_algorithm_, GetCongestionWindow()).WillRepeatedly( 2564 EXPECT_CALL(*send_algorithm_, GetCongestionWindow()).WillRepeatedly(
2576 Return(congestion_window * kDefaultMaxPacketSize)); 2565 Return(congestion_window * kDefaultMaxPacketSize));
2577 2566
2578 // A TaggingEncrypter puts kTagSize copies of the given byte (0x02 here) at 2567 // A TaggingEncrypter puts kTagSize copies of the given byte (0x02 here) at
2579 // the end of the packet. We can test this to check which encrypter was used. 2568 // the end of the packet. We can test this to check which encrypter was used.
2580 use_tagging_decrypter(); 2569 use_tagging_decrypter();
2581 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(0x02)); 2570 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(0x02));
2582 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL); 2571 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL);
(...skipping 1672 matching lines...) Expand 10 before | Expand all | Expand 10 after
4255 QuicBlockedFrame blocked; 4244 QuicBlockedFrame blocked;
4256 blocked.stream_id = 3; 4245 blocked.stream_id = 3;
4257 EXPECT_CALL(visitor_, OnBlockedFrames(_)); 4246 EXPECT_CALL(visitor_, OnBlockedFrames(_));
4258 ProcessFramePacket(QuicFrame(&blocked)); 4247 ProcessFramePacket(QuicFrame(&blocked));
4259 EXPECT_TRUE(ack_alarm->IsSet()); 4248 EXPECT_TRUE(ack_alarm->IsSet());
4260 } 4249 }
4261 4250
4262 } // namespace 4251 } // namespace
4263 } // namespace test 4252 } // namespace test
4264 } // namespace net 4253 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698