| OLD | NEW |
| 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 <ostream> | 7 #include <ostream> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 4651 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4662 QuicEncryptedPacket(buffer, encryped_length, false)); | 4662 QuicEncryptedPacket(buffer, encryped_length, false)); |
| 4663 EXPECT_EQ(0u, writer_->last_packet_size()); | 4663 EXPECT_EQ(0u, writer_->last_packet_size()); |
| 4664 EXPECT_FALSE(connection_.HasQueuedData()); | 4664 EXPECT_FALSE(connection_.HasQueuedData()); |
| 4665 } | 4665 } |
| 4666 | 4666 |
| 4667 TEST_P(QuicConnectionTest, ClientHandlesVersionNegotiation) { | 4667 TEST_P(QuicConnectionTest, ClientHandlesVersionNegotiation) { |
| 4668 // Start out with some unsupported version. | 4668 // Start out with some unsupported version. |
| 4669 QuicConnectionPeer::GetFramer(&connection_)->set_version_for_tests( | 4669 QuicConnectionPeer::GetFramer(&connection_)->set_version_for_tests( |
| 4670 QUIC_VERSION_UNSUPPORTED); | 4670 QUIC_VERSION_UNSUPPORTED); |
| 4671 | 4671 |
| 4672 QuicPacketHeader header; | |
| 4673 header.public_header.connection_id = connection_id_; | |
| 4674 header.public_header.version_flag = true; | |
| 4675 header.packet_number = 12; | |
| 4676 | |
| 4677 QuicVersionVector supported_versions; | |
| 4678 for (size_t i = 0; i < arraysize(kSupportedQuicVersions); ++i) { | |
| 4679 supported_versions.push_back(kSupportedQuicVersions[i]); | |
| 4680 } | |
| 4681 | |
| 4682 // Send a version negotiation packet. | 4672 // Send a version negotiation packet. |
| 4683 scoped_ptr<QuicEncryptedPacket> encrypted( | 4673 scoped_ptr<QuicEncryptedPacket> encrypted( |
| 4684 framer_.BuildVersionNegotiationPacket( | 4674 framer_.BuildVersionNegotiationPacket(connection_id_, |
| 4685 header.public_header, supported_versions)); | 4675 QuicSupportedVersions())); |
| 4686 connection_.ProcessUdpPacket(kSelfAddress, kPeerAddress, *encrypted); | 4676 connection_.ProcessUdpPacket(kSelfAddress, kPeerAddress, *encrypted); |
| 4687 | 4677 |
| 4688 // Now force another packet. The connection should transition into | 4678 // Now force another packet. The connection should transition into |
| 4689 // NEGOTIATED_VERSION state and tell the packet creator to StopSendingVersion. | 4679 // NEGOTIATED_VERSION state and tell the packet creator to StopSendingVersion. |
| 4680 QuicPacketHeader header; |
| 4681 header.public_header.connection_id = connection_id_; |
| 4682 header.packet_number = 12; |
| 4690 header.public_header.version_flag = false; | 4683 header.public_header.version_flag = false; |
| 4691 QuicFrames frames; | 4684 QuicFrames frames; |
| 4692 frames.push_back(QuicFrame(&frame1_)); | 4685 frames.push_back(QuicFrame(&frame1_)); |
| 4693 scoped_ptr<QuicPacket> packet(ConstructPacket(header, frames)); | 4686 scoped_ptr<QuicPacket> packet(ConstructPacket(header, frames)); |
| 4694 char buffer[kMaxPacketSize]; | 4687 char buffer[kMaxPacketSize]; |
| 4695 size_t encrypted_length = framer_.EncryptPayload(ENCRYPTION_NONE, 12, *packet, | 4688 size_t encrypted_length = framer_.EncryptPayload(ENCRYPTION_NONE, 12, *packet, |
| 4696 buffer, kMaxPacketSize); | 4689 buffer, kMaxPacketSize); |
| 4697 ASSERT_NE(0u, encrypted_length); | 4690 ASSERT_NE(0u, encrypted_length); |
| 4698 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); | 4691 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); |
| 4699 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 4692 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 4700 connection_.ProcessUdpPacket( | 4693 connection_.ProcessUdpPacket( |
| 4701 kSelfAddress, kPeerAddress, | 4694 kSelfAddress, kPeerAddress, |
| 4702 QuicEncryptedPacket(buffer, encrypted_length, false)); | 4695 QuicEncryptedPacket(buffer, encrypted_length, false)); |
| 4703 | 4696 |
| 4704 ASSERT_FALSE(QuicPacketCreatorPeer::SendVersionInPacket(creator_)); | 4697 ASSERT_FALSE(QuicPacketCreatorPeer::SendVersionInPacket(creator_)); |
| 4705 } | 4698 } |
| 4706 | 4699 |
| 4707 TEST_P(QuicConnectionTest, BadVersionNegotiation) { | 4700 TEST_P(QuicConnectionTest, BadVersionNegotiation) { |
| 4708 QuicPacketHeader header; | |
| 4709 header.public_header.connection_id = connection_id_; | |
| 4710 header.public_header.version_flag = true; | |
| 4711 header.packet_number = 12; | |
| 4712 | |
| 4713 QuicVersionVector supported_versions; | |
| 4714 for (size_t i = 0; i < arraysize(kSupportedQuicVersions); ++i) { | |
| 4715 supported_versions.push_back(kSupportedQuicVersions[i]); | |
| 4716 } | |
| 4717 | |
| 4718 // Send a version negotiation packet with the version the client started with. | 4701 // Send a version negotiation packet with the version the client started with. |
| 4719 // It should be rejected. | 4702 // It should be rejected. |
| 4720 EXPECT_CALL(visitor_, | 4703 EXPECT_CALL(visitor_, |
| 4721 OnConnectionClosed(QUIC_INVALID_VERSION_NEGOTIATION_PACKET, | 4704 OnConnectionClosed(QUIC_INVALID_VERSION_NEGOTIATION_PACKET, |
| 4722 false)); | 4705 false)); |
| 4723 scoped_ptr<QuicEncryptedPacket> encrypted( | 4706 scoped_ptr<QuicEncryptedPacket> encrypted( |
| 4724 framer_.BuildVersionNegotiationPacket( | 4707 framer_.BuildVersionNegotiationPacket(connection_id_, |
| 4725 header.public_header, supported_versions)); | 4708 QuicSupportedVersions())); |
| 4726 connection_.ProcessUdpPacket(kSelfAddress, kPeerAddress, *encrypted); | 4709 connection_.ProcessUdpPacket(kSelfAddress, kPeerAddress, *encrypted); |
| 4727 } | 4710 } |
| 4728 | 4711 |
| 4729 TEST_P(QuicConnectionTest, CheckSendStats) { | 4712 TEST_P(QuicConnectionTest, CheckSendStats) { |
| 4730 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); | 4713 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); |
| 4731 connection_.SendStreamDataWithString(3, "first", 0, !kFin, nullptr); | 4714 connection_.SendStreamDataWithString(3, "first", 0, !kFin, nullptr); |
| 4732 size_t first_packet_size = writer_->last_packet_size(); | 4715 size_t first_packet_size = writer_->last_packet_size(); |
| 4733 | 4716 |
| 4734 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); | 4717 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); |
| 4735 connection_.SendStreamDataWithString(5, "second", 0, !kFin, nullptr); | 4718 connection_.SendStreamDataWithString(5, "second", 0, !kFin, nullptr); |
| (...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5262 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); | 5245 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); |
| 5263 connection_.SendGoAway(QUIC_PEER_GOING_AWAY, kHeadersStreamId, "Going Away."); | 5246 connection_.SendGoAway(QUIC_PEER_GOING_AWAY, kHeadersStreamId, "Going Away."); |
| 5264 EXPECT_TRUE(connection_.goaway_sent()); | 5247 EXPECT_TRUE(connection_.goaway_sent()); |
| 5265 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); | 5248 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); |
| 5266 connection_.SendGoAway(QUIC_PEER_GOING_AWAY, kHeadersStreamId, "Going Away."); | 5249 connection_.SendGoAway(QUIC_PEER_GOING_AWAY, kHeadersStreamId, "Going Away."); |
| 5267 } | 5250 } |
| 5268 | 5251 |
| 5269 } // namespace | 5252 } // namespace |
| 5270 } // namespace test | 5253 } // namespace test |
| 5271 } // namespace net | 5254 } // namespace net |
| OLD | NEW |