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

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

Issue 693943003: Update from https://crrev.com/302630 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years, 1 month 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 | « net/quic/quic_connection.cc ('k') | net/quic/quic_crypto_server_stream.cc » ('j') | 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 "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 2429 matching lines...) Expand 10 before | Expand all | Expand 10 after
2440 2440
2441 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(0x02)); 2441 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(0x02));
2442 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL); 2442 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL);
2443 2443
2444 SendStreamDataToPeer(2, "bar", 0, !kFin, nullptr); 2444 SendStreamDataToPeer(2, "bar", 0, !kFin, nullptr);
2445 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); 2445 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1);
2446 2446
2447 connection_.RetransmitUnackedPackets(ALL_INITIAL_RETRANSMISSION); 2447 connection_.RetransmitUnackedPackets(ALL_INITIAL_RETRANSMISSION);
2448 } 2448 }
2449 2449
2450 TEST_P(QuicConnectionTest, DelayForwardSecureEncryptionUntilClientIsReady) {
2451 ValueRestore<bool> old_flag(&FLAGS_enable_quic_delay_forward_security, true);
2452
2453 // A TaggingEncrypter puts kTagSize copies of the given byte (0x02 here) at
2454 // the end of the packet. We can test this to check which encrypter was used.
2455 use_tagging_decrypter();
2456 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(0x02));
2457 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL);
2458 SendAckPacketToPeer();
2459 EXPECT_EQ(0x02020202u, writer_->final_bytes_of_last_packet());
2460
2461 // Set a forward-secure encrypter but do not make it the default, and verify
2462 // that it is not yet used.
2463 connection_.SetEncrypter(ENCRYPTION_FORWARD_SECURE,
2464 new TaggingEncrypter(0x03));
2465 SendAckPacketToPeer();
2466 EXPECT_EQ(0x02020202u, writer_->final_bytes_of_last_packet());
2467
2468 // Now simulate receipt of a forward-secure packet and verify that the
2469 // forward-secure encrypter is now used.
2470 connection_.OnDecryptedPacket(ENCRYPTION_FORWARD_SECURE);
2471 SendAckPacketToPeer();
2472 EXPECT_EQ(0x03030303u, writer_->final_bytes_of_last_packet());
2473 }
2474
2475 TEST_P(QuicConnectionTest, DelayForwardSecureEncryptionUntilManyPacketSent) {
2476 ValueRestore<bool> old_flag(&FLAGS_enable_quic_delay_forward_security, true);
2477
2478 // Set a congestion window of 10 packets.
2479 QuicPacketCount congestion_window = 10;
2480 EXPECT_CALL(*send_algorithm_, GetCongestionWindow()).WillRepeatedly(
2481 Return(congestion_window * kDefaultMaxPacketSize));
2482
2483 // A TaggingEncrypter puts kTagSize copies of the given byte (0x02 here) at
2484 // the end of the packet. We can test this to check which encrypter was used.
2485 use_tagging_decrypter();
2486 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(0x02));
2487 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL);
2488 SendAckPacketToPeer();
2489 EXPECT_EQ(0x02020202u, writer_->final_bytes_of_last_packet());
2490
2491 // Set a forward-secure encrypter but do not make it the default, and
2492 // verify that it is not yet used.
2493 connection_.SetEncrypter(ENCRYPTION_FORWARD_SECURE,
2494 new TaggingEncrypter(0x03));
2495 SendAckPacketToPeer();
2496 EXPECT_EQ(0x02020202u, writer_->final_bytes_of_last_packet());
2497
2498 // Now send a packet "Far enough" after the encrypter was set and verify that
2499 // the forward-secure encrypter is now used.
2500 for (uint64 i = 0; i < 3 * congestion_window - 1; ++i) {
2501 EXPECT_EQ(0x02020202u, writer_->final_bytes_of_last_packet());
2502 SendAckPacketToPeer();
2503 }
2504 EXPECT_EQ(0x03030303u, writer_->final_bytes_of_last_packet());
2505 }
2506
2450 TEST_P(QuicConnectionTest, BufferNonDecryptablePackets) { 2507 TEST_P(QuicConnectionTest, BufferNonDecryptablePackets) {
2451 // SetFromConfig is always called after construction from InitializeSession. 2508 // SetFromConfig is always called after construction from InitializeSession.
2452 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); 2509 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _));
2453 QuicConfig config; 2510 QuicConfig config;
2454 connection_.SetFromConfig(config); 2511 connection_.SetFromConfig(config);
2455 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2512 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2456 use_tagging_decrypter(); 2513 use_tagging_decrypter();
2457 2514
2458 const uint8 tag = 0x07; 2515 const uint8 tag = 0x07;
2459 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); 2516 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag));
(...skipping 1545 matching lines...) Expand 10 before | Expand all | Expand 10 after
4005 QuicPacketCreator* creator = 4062 QuicPacketCreator* creator =
4006 QuicConnectionPeer::GetPacketCreator(&connection_); 4063 QuicConnectionPeer::GetPacketCreator(&connection_);
4007 size_t max_packets_per_fec_group = creator->max_packets_per_fec_group(); 4064 size_t max_packets_per_fec_group = creator->max_packets_per_fec_group();
4008 4065
4009 QuicSentPacketManager::NetworkChangeVisitor* visitor = 4066 QuicSentPacketManager::NetworkChangeVisitor* visitor =
4010 QuicSentPacketManagerPeer::GetNetworkChangeVisitor( 4067 QuicSentPacketManagerPeer::GetNetworkChangeVisitor(
4011 QuicConnectionPeer::GetSentPacketManager(&connection_)); 4068 QuicConnectionPeer::GetSentPacketManager(&connection_));
4012 EXPECT_TRUE(visitor); 4069 EXPECT_TRUE(visitor);
4013 4070
4014 // Increase FEC group size by increasing congestion window to a large number. 4071 // Increase FEC group size by increasing congestion window to a large number.
4015 visitor->OnCongestionWindowChange(1000 * kDefaultTCPMSS); 4072 EXPECT_CALL(*send_algorithm_, GetCongestionWindow()).WillRepeatedly(
4073 Return(1000 * kDefaultTCPMSS));
4074 visitor->OnCongestionWindowChange();
4016 EXPECT_LT(max_packets_per_fec_group, creator->max_packets_per_fec_group()); 4075 EXPECT_LT(max_packets_per_fec_group, creator->max_packets_per_fec_group());
4017 } 4076 }
4018 4077
4019 class MockQuicConnectionDebugVisitor 4078 class MockQuicConnectionDebugVisitor
4020 : public QuicConnectionDebugVisitor { 4079 : public QuicConnectionDebugVisitor {
4021 public: 4080 public:
4022 MOCK_METHOD1(OnFrameAddedToPacket, 4081 MOCK_METHOD1(OnFrameAddedToPacket,
4023 void(const QuicFrame&)); 4082 void(const QuicFrame&));
4024 4083
4025 MOCK_METHOD6(OnPacketSent, 4084 MOCK_METHOD6(OnPacketSent,
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
4107 QuicBlockedFrame blocked; 4166 QuicBlockedFrame blocked;
4108 blocked.stream_id = 3; 4167 blocked.stream_id = 3;
4109 EXPECT_CALL(visitor_, OnBlockedFrames(_)); 4168 EXPECT_CALL(visitor_, OnBlockedFrames(_));
4110 ProcessFramePacket(QuicFrame(&blocked)); 4169 ProcessFramePacket(QuicFrame(&blocked));
4111 EXPECT_TRUE(ack_alarm->IsSet()); 4170 EXPECT_TRUE(ack_alarm->IsSet());
4112 } 4171 }
4113 4172
4114 } // namespace 4173 } // namespace
4115 } // namespace test 4174 } // namespace test
4116 } // namespace net 4175 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_connection.cc ('k') | net/quic/quic_crypto_server_stream.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698