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

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

Issue 734063004: Update from https://crrev.com/304418 (Closed) Base URL: https://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 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 TestConnectionHelper* helper, 401 TestConnectionHelper* helper,
402 const PacketWriterFactory& factory, 402 const PacketWriterFactory& factory,
403 bool is_server, 403 bool is_server,
404 QuicVersion version) 404 QuicVersion version)
405 : QuicConnection(connection_id, 405 : QuicConnection(connection_id,
406 address, 406 address,
407 helper, 407 helper,
408 factory, 408 factory,
409 /* owns_writer= */ false, 409 /* owns_writer= */ false,
410 is_server, 410 is_server,
411 /* is_secure= */ false,
411 SupportedVersions(version)) { 412 SupportedVersions(version)) {
412 // Disable tail loss probes for most tests. 413 // Disable tail loss probes for most tests.
413 QuicSentPacketManagerPeer::SetMaxTailLossProbes( 414 QuicSentPacketManagerPeer::SetMaxTailLossProbes(
414 QuicConnectionPeer::GetSentPacketManager(this), 0); 415 QuicConnectionPeer::GetSentPacketManager(this), 0);
415 writer()->set_is_server(is_server); 416 writer()->set_is_server(is_server);
416 } 417 }
417 418
418 void SendAck() { 419 void SendAck() {
419 QuicConnectionPeer::SendAck(this); 420 QuicConnectionPeer::SendAck(this);
420 } 421 }
(...skipping 2078 matching lines...) Expand 10 before | Expand all | Expand 10 after
2499 // the forward-secure encrypter is now used. 2500 // the forward-secure encrypter is now used.
2500 for (uint64 i = 0; i < 3 * congestion_window - 1; ++i) { 2501 for (uint64 i = 0; i < 3 * congestion_window - 1; ++i) {
2501 EXPECT_EQ(0x02020202u, writer_->final_bytes_of_last_packet()); 2502 EXPECT_EQ(0x02020202u, writer_->final_bytes_of_last_packet());
2502 SendAckPacketToPeer(); 2503 SendAckPacketToPeer();
2503 } 2504 }
2504 EXPECT_EQ(0x03030303u, writer_->final_bytes_of_last_packet()); 2505 EXPECT_EQ(0x03030303u, writer_->final_bytes_of_last_packet());
2505 } 2506 }
2506 2507
2507 TEST_P(QuicConnectionTest, BufferNonDecryptablePackets) { 2508 TEST_P(QuicConnectionTest, BufferNonDecryptablePackets) {
2508 // SetFromConfig is always called after construction from InitializeSession. 2509 // SetFromConfig is always called after construction from InitializeSession.
2509 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); 2510 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _, _));
2510 QuicConfig config; 2511 QuicConfig config;
2511 connection_.SetFromConfig(config); 2512 connection_.SetFromConfig(config);
2512 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2513 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2513 use_tagging_decrypter(); 2514 use_tagging_decrypter();
2514 2515
2515 const uint8 tag = 0x07; 2516 const uint8 tag = 0x07;
2516 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); 2517 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag));
2517 2518
2518 // Process an encrypted packet which can not yet be decrypted which should 2519 // Process an encrypted packet which can not yet be decrypted which should
2519 // result in the packet being buffered. 2520 // result in the packet being buffered.
2520 ProcessDataPacketAtLevel(1, 0, kEntropyFlag, ENCRYPTION_INITIAL); 2521 ProcessDataPacketAtLevel(1, 0, kEntropyFlag, ENCRYPTION_INITIAL);
2521 2522
2522 // Transition to the new encryption state and process another encrypted packet 2523 // Transition to the new encryption state and process another encrypted packet
2523 // which should result in the original packet being processed. 2524 // which should result in the original packet being processed.
2524 connection_.SetDecrypter(new StrictTaggingDecrypter(tag), 2525 connection_.SetDecrypter(new StrictTaggingDecrypter(tag),
2525 ENCRYPTION_INITIAL); 2526 ENCRYPTION_INITIAL);
2526 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL); 2527 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL);
2527 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); 2528 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag));
2528 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(2); 2529 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(2);
2529 ProcessDataPacketAtLevel(2, 0, kEntropyFlag, ENCRYPTION_INITIAL); 2530 ProcessDataPacketAtLevel(2, 0, kEntropyFlag, ENCRYPTION_INITIAL);
2530 2531
2531 // Finally, process a third packet and note that we do not reprocess the 2532 // Finally, process a third packet and note that we do not reprocess the
2532 // buffered packet. 2533 // buffered packet.
2533 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(1); 2534 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(1);
2534 ProcessDataPacketAtLevel(3, 0, kEntropyFlag, ENCRYPTION_INITIAL); 2535 ProcessDataPacketAtLevel(3, 0, kEntropyFlag, ENCRYPTION_INITIAL);
2535 } 2536 }
2536 2537
2537 TEST_P(QuicConnectionTest, Buffer100NonDecryptablePackets) { 2538 TEST_P(QuicConnectionTest, Buffer100NonDecryptablePackets) {
2538 // SetFromConfig is always called after construction from InitializeSession. 2539 // SetFromConfig is always called after construction from InitializeSession.
2539 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); 2540 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _, _));
2540 QuicConfig config; 2541 QuicConfig config;
2541 config.set_max_undecryptable_packets(100); 2542 config.set_max_undecryptable_packets(100);
2542 connection_.SetFromConfig(config); 2543 connection_.SetFromConfig(config);
2543 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2544 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2544 use_tagging_decrypter(); 2545 use_tagging_decrypter();
2545 2546
2546 const uint8 tag = 0x07; 2547 const uint8 tag = 0x07;
2547 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); 2548 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag));
2548 2549
2549 // Process an encrypted packet which can not yet be decrypted which should 2550 // Process an encrypted packet which can not yet be decrypted which should
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
2768 TEST_P(QuicConnectionTest, DontUpdateQuicCongestionFeedbackFrameForRevived) { 2769 TEST_P(QuicConnectionTest, DontUpdateQuicCongestionFeedbackFrameForRevived) {
2769 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2770 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2770 SendAckPacketToPeer(); 2771 SendAckPacketToPeer();
2771 // Process an FEC packet, and revive the missing data packet 2772 // Process an FEC packet, and revive the missing data packet
2772 // but only contact the receive_algorithm once. 2773 // but only contact the receive_algorithm once.
2773 EXPECT_CALL(*receive_algorithm_, RecordIncomingPacket(_, _, _)); 2774 EXPECT_CALL(*receive_algorithm_, RecordIncomingPacket(_, _, _));
2774 ProcessFecPacket(2, 1, true, !kEntropyFlag, nullptr); 2775 ProcessFecPacket(2, 1, true, !kEntropyFlag, nullptr);
2775 } 2776 }
2776 2777
2777 TEST_P(QuicConnectionTest, InitialTimeout) { 2778 TEST_P(QuicConnectionTest, InitialTimeout) {
2778 if (!FLAGS_quic_unified_timeouts) {
2779 EXPECT_TRUE(connection_.connected());
2780 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_CONNECTION_TIMED_OUT, false));
2781 EXPECT_CALL(*send_algorithm_,
2782 OnPacketSent(_, _, _, _, _)).Times(AnyNumber());
2783
2784 QuicTime default_timeout = clock_.ApproximateNow().Add(
2785 QuicTime::Delta::FromSeconds(kDefaultIdleTimeoutSecs));
2786 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline());
2787
2788 // Simulate the timeout alarm firing.
2789 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(kDefaultIdleTimeoutSecs));
2790 connection_.GetTimeoutAlarm()->Fire();
2791
2792 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet());
2793 EXPECT_FALSE(connection_.connected());
2794
2795 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet());
2796 EXPECT_FALSE(connection_.GetPingAlarm()->IsSet());
2797 EXPECT_FALSE(connection_.GetResumeWritesAlarm()->IsSet());
2798 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet());
2799 EXPECT_FALSE(connection_.GetSendAlarm()->IsSet());
2800 return;
2801 }
2802 EXPECT_TRUE(connection_.connected()); 2779 EXPECT_TRUE(connection_.connected());
2803 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(AnyNumber()); 2780 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(AnyNumber());
2804 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); 2781 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet());
2805 2782
2806 // SetFromConfig sets the initial timeouts before negotiation. 2783 // SetFromConfig sets the initial timeouts before negotiation.
2807 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); 2784 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _, _));
2808 QuicConfig config; 2785 QuicConfig config;
2809 connection_.SetFromConfig(config); 2786 connection_.SetFromConfig(config);
2810 // Subtract a second from the idle timeout on the client side. 2787 // Subtract a second from the idle timeout on the client side.
2811 QuicTime default_timeout = clock_.ApproximateNow().Add( 2788 QuicTime default_timeout = clock_.ApproximateNow().Add(
2812 QuicTime::Delta::FromSeconds(kInitialIdleTimeoutSecs - 1)); 2789 QuicTime::Delta::FromSeconds(kInitialIdleTimeoutSecs - 1));
2813 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline()); 2790 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline());
2814 2791
2815 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_CONNECTION_TIMED_OUT, false)); 2792 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_CONNECTION_TIMED_OUT, false));
2816 // Simulate the timeout alarm firing. 2793 // Simulate the timeout alarm firing.
2817 clock_.AdvanceTime( 2794 clock_.AdvanceTime(
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
2906 writer_->Reset(); 2883 writer_->Reset();
2907 2884
2908 EXPECT_CALL(visitor_, HasOpenDataStreams()).WillRepeatedly(Return(false)); 2885 EXPECT_CALL(visitor_, HasOpenDataStreams()).WillRepeatedly(Return(false));
2909 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); 2886 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5));
2910 SendAckPacketToPeer(); 2887 SendAckPacketToPeer();
2911 2888
2912 EXPECT_FALSE(connection_.GetPingAlarm()->IsSet()); 2889 EXPECT_FALSE(connection_.GetPingAlarm()->IsSet());
2913 } 2890 }
2914 2891
2915 TEST_P(QuicConnectionTest, TimeoutAfterSend) { 2892 TEST_P(QuicConnectionTest, TimeoutAfterSend) {
2916 if (!FLAGS_quic_unified_timeouts) {
2917 EXPECT_TRUE(connection_.connected());
2918
2919 QuicTime default_timeout = clock_.ApproximateNow().Add(
2920 QuicTime::Delta::FromSeconds(kDefaultIdleTimeoutSecs));
2921
2922 // When we send a packet, the timeout will change to 5000 +
2923 // kDefaultInitialTimeoutSecs.
2924 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5));
2925
2926 // Send an ack so we don't set the retransmission alarm.
2927 SendAckPacketToPeer();
2928 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline());
2929
2930 // The original alarm will fire. We should not time out because we had a
2931 // network event at t=5000. The alarm will reregister.
2932 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds(
2933 kDefaultIdleTimeoutSecs * 1000000 - 5000));
2934 EXPECT_EQ(default_timeout, clock_.ApproximateNow());
2935 connection_.GetTimeoutAlarm()->Fire();
2936 EXPECT_TRUE(connection_.GetTimeoutAlarm()->IsSet());
2937 EXPECT_TRUE(connection_.connected());
2938 EXPECT_EQ(default_timeout.Add(QuicTime::Delta::FromMilliseconds(5)),
2939 connection_.GetTimeoutAlarm()->deadline());
2940
2941 // This time, we should time out.
2942 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_CONNECTION_TIMED_OUT, false));
2943 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _));
2944 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5));
2945 EXPECT_EQ(default_timeout.Add(QuicTime::Delta::FromMilliseconds(5)),
2946 clock_.ApproximateNow());
2947 connection_.GetTimeoutAlarm()->Fire();
2948 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet());
2949 EXPECT_FALSE(connection_.connected());
2950 return;
2951 }
2952 EXPECT_TRUE(connection_.connected()); 2893 EXPECT_TRUE(connection_.connected());
2953 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); 2894 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _, _));
2954 QuicConfig config; 2895 QuicConfig config;
2955 connection_.SetFromConfig(config); 2896 connection_.SetFromConfig(config);
2956 2897
2957 const QuicTime::Delta initial_idle_timeout = 2898 const QuicTime::Delta initial_idle_timeout =
2958 QuicTime::Delta::FromSeconds(kInitialIdleTimeoutSecs - 1); 2899 QuicTime::Delta::FromSeconds(kInitialIdleTimeoutSecs - 1);
2959 const QuicTime::Delta five_ms = QuicTime::Delta::FromMilliseconds(5); 2900 const QuicTime::Delta five_ms = QuicTime::Delta::FromMilliseconds(5);
2960 QuicTime default_timeout = clock_.ApproximateNow().Add(initial_idle_timeout); 2901 QuicTime default_timeout = clock_.ApproximateNow().Add(initial_idle_timeout);
2961 2902
2962 // When we send a packet, the timeout will change to 5ms + 2903 // When we send a packet, the timeout will change to 5ms +
2963 // kInitialIdleTimeoutSecs. 2904 // kInitialIdleTimeoutSecs.
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
3048 connection_.SendStreamDataWithString(1, payload, 0, !kFin, nullptr) 2989 connection_.SendStreamDataWithString(1, payload, 0, !kFin, nullptr)
3049 .bytes_consumed); 2990 .bytes_consumed);
3050 } 2991 }
3051 2992
3052 TEST_P(QuicConnectionTest, LoopThroughSendingPacketsWithTruncation) { 2993 TEST_P(QuicConnectionTest, LoopThroughSendingPacketsWithTruncation) {
3053 ValueRestore<bool> old_flag(&FLAGS_allow_truncated_connection_ids_for_quic, 2994 ValueRestore<bool> old_flag(&FLAGS_allow_truncated_connection_ids_for_quic,
3054 true); 2995 true);
3055 2996
3056 // Set up a larger payload than will fit in one packet. 2997 // Set up a larger payload than will fit in one packet.
3057 const string payload(connection_.max_packet_length(), 'a'); 2998 const string payload(connection_.max_packet_length(), 'a');
3058 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)).Times(AnyNumber()); 2999 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _, _)).Times(AnyNumber());
3059 3000
3060 // Now send some packets with no truncation. 3001 // Now send some packets with no truncation.
3061 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); 3002 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2);
3062 EXPECT_EQ(payload.size(), 3003 EXPECT_EQ(payload.size(),
3063 connection_.SendStreamDataWithString( 3004 connection_.SendStreamDataWithString(
3064 3, payload, 0, !kFin, nullptr).bytes_consumed); 3005 3, payload, 0, !kFin, nullptr).bytes_consumed);
3065 // Track the size of the second packet here. The overhead will be the largest 3006 // Track the size of the second packet here. The overhead will be the largest
3066 // we see in this test, due to the non-truncated CID. 3007 // we see in this test, due to the non-truncated CID.
3067 size_t non_truncated_packet_size = writer_->last_packet_size(); 3008 size_t non_truncated_packet_size = writer_->last_packet_size();
3068 3009
(...skipping 1086 matching lines...) Expand 10 before | Expand all | Expand 10 after
4155 QuicBlockedFrame blocked; 4096 QuicBlockedFrame blocked;
4156 blocked.stream_id = 3; 4097 blocked.stream_id = 3;
4157 EXPECT_CALL(visitor_, OnBlockedFrames(_)); 4098 EXPECT_CALL(visitor_, OnBlockedFrames(_));
4158 ProcessFramePacket(QuicFrame(&blocked)); 4099 ProcessFramePacket(QuicFrame(&blocked));
4159 EXPECT_TRUE(ack_alarm->IsSet()); 4100 EXPECT_TRUE(ack_alarm->IsSet());
4160 } 4101 }
4161 4102
4162 } // namespace 4103 } // namespace
4163 } // namespace test 4104 } // namespace test
4164 } // namespace net 4105 } // 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