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

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

Issue 19858003: * Removed QuicTag kQuicVersion1 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix compiler errors Created 7 years, 5 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 | Annotate | Revision Log
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 "net/base/net_errors.h" 9 #include "net/base/net_errors.h"
10 #include "net/quic/congestion_control/receive_algorithm_interface.h" 10 #include "net/quic/congestion_control/receive_algorithm_interface.h"
11 #include "net/quic/congestion_control/send_algorithm_interface.h" 11 #include "net/quic/congestion_control/send_algorithm_interface.h"
12 #include "net/quic/crypto/null_encrypter.h" 12 #include "net/quic/crypto/null_encrypter.h"
13 #include "net/quic/crypto/quic_decrypter.h" 13 #include "net/quic/crypto/quic_decrypter.h"
14 #include "net/quic/crypto/quic_encrypter.h" 14 #include "net/quic/crypto/quic_encrypter.h"
15 #include "net/quic/crypto/quic_random.h" 15 #include "net/quic/crypto/quic_random.h"
16 #include "net/quic/quic_protocol.h"
16 #include "net/quic/quic_utils.h" 17 #include "net/quic/quic_utils.h"
17 #include "net/quic/test_tools/mock_clock.h" 18 #include "net/quic/test_tools/mock_clock.h"
18 #include "net/quic/test_tools/mock_random.h" 19 #include "net/quic/test_tools/mock_random.h"
19 #include "net/quic/test_tools/quic_connection_peer.h" 20 #include "net/quic/test_tools/quic_connection_peer.h"
20 #include "net/quic/test_tools/quic_framer_peer.h" 21 #include "net/quic/test_tools/quic_framer_peer.h"
21 #include "net/quic/test_tools/quic_packet_creator_peer.h" 22 #include "net/quic/test_tools/quic_packet_creator_peer.h"
22 #include "net/quic/test_tools/quic_test_utils.h" 23 #include "net/quic/test_tools/quic_test_utils.h"
23 #include "testing/gmock/include/gmock/gmock.h" 24 #include "testing/gmock/include/gmock/gmock.h"
24 #include "testing/gtest/include/gtest/gtest.h" 25 #include "testing/gtest/include/gtest/gtest.h"
25 26
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 return random_generator_; 244 return random_generator_;
244 } 245 }
245 246
246 virtual int WritePacketToWire(const QuicEncryptedPacket& packet, 247 virtual int WritePacketToWire(const QuicEncryptedPacket& packet,
247 int* error) OVERRIDE { 248 int* error) OVERRIDE {
248 if (packet.length() >= sizeof(final_bytes_of_last_packet_)) { 249 if (packet.length() >= sizeof(final_bytes_of_last_packet_)) {
249 memcpy(&final_bytes_of_last_packet_, packet.data() + packet.length() - 4, 250 memcpy(&final_bytes_of_last_packet_, packet.data() + packet.length() - 4,
250 sizeof(final_bytes_of_last_packet_)); 251 sizeof(final_bytes_of_last_packet_));
251 } 252 }
252 253
253 QuicFramer framer(kQuicVersion1, QuicTime::Zero(), is_server_); 254 QuicFramer framer(QuicVersionMax(), QuicTime::Zero(), is_server_);
254 if (use_tagging_decrypter_) { 255 if (use_tagging_decrypter_) {
255 framer.SetDecrypter(new TaggingDecrypter); 256 framer.SetDecrypter(new TaggingDecrypter);
256 } 257 }
257 FramerVisitorCapturingFrames visitor; 258 FramerVisitorCapturingFrames visitor;
258 framer.set_visitor(&visitor); 259 framer.set_visitor(&visitor);
259 EXPECT_TRUE(framer.ProcessPacket(packet)); 260 EXPECT_TRUE(framer.ProcessPacket(packet));
260 header_ = *visitor.header(); 261 header_ = *visitor.header();
261 frame_count_ = visitor.frame_count(); 262 frame_count_ = visitor.frame_count();
262 if (visitor.ack()) { 263 if (visitor.ack()) {
263 ack_.reset(new QuicAckFrame(*visitor.ack())); 264 ack_.reset(new QuicAckFrame(*visitor.ack()));
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 374
374 DISALLOW_COPY_AND_ASSIGN(TestConnectionHelper); 375 DISALLOW_COPY_AND_ASSIGN(TestConnectionHelper);
375 }; 376 };
376 377
377 class TestConnection : public QuicConnection { 378 class TestConnection : public QuicConnection {
378 public: 379 public:
379 TestConnection(QuicGuid guid, 380 TestConnection(QuicGuid guid,
380 IPEndPoint address, 381 IPEndPoint address,
381 TestConnectionHelper* helper, 382 TestConnectionHelper* helper,
382 bool is_server) 383 bool is_server)
383 : QuicConnection(guid, address, helper, is_server), 384 : QuicConnection(guid, address, helper, is_server, QuicVersionMax()),
384 helper_(helper) { 385 helper_(helper) {
385 helper_->set_is_server(!is_server); 386 helper_->set_is_server(!is_server);
386 } 387 }
387 388
388 void SendAck() { 389 void SendAck() {
389 QuicConnectionPeer::SendAck(this); 390 QuicConnectionPeer::SendAck(this);
390 } 391 }
391 392
392 void SetReceiveAlgorithm(TestReceiveAlgorithm* receive_algorithm) { 393 void SetReceiveAlgorithm(TestReceiveAlgorithm* receive_algorithm) {
393 QuicConnectionPeer::SetReceiveAlgorithm(this, receive_algorithm); 394 QuicConnectionPeer::SetReceiveAlgorithm(this, receive_algorithm);
394 } 395 }
395 396
396 void SetSendAlgorithm(SendAlgorithmInterface* send_algorithm) { 397 void SetSendAlgorithm(SendAlgorithmInterface* send_algorithm) {
397 QuicConnectionPeer::SetSendAlgorithm(this, send_algorithm); 398 QuicConnectionPeer::SetSendAlgorithm(this, send_algorithm);
398 } 399 }
399 400
400 QuicConsumedData SendStreamData1() { 401 QuicConsumedData SendStreamData1() {
401 return SendStreamData(1u, "food", 0, !kFin); 402 return SendStreamData(1u, "food", 0, !kFin);
402 } 403 }
403 404
404 QuicConsumedData SendStreamData2() { 405 QuicConsumedData SendStreamData2() {
405 return SendStreamData(2u, "food2", 0, !kFin); 406 return SendStreamData(2u, "food2", 0, !kFin);
406 } 407 }
407 408
408 bool is_server() { 409 bool is_server() {
409 return QuicConnectionPeer::IsServer(this); 410 return QuicConnectionPeer::IsServer(this);
410 } 411 }
411 412
413 void set_version(QuicVersion version) {
414 framer_.set_version(version);
415 }
416
412 void set_is_server(bool is_server) { 417 void set_is_server(bool is_server) {
413 helper_->set_is_server(!is_server); 418 helper_->set_is_server(!is_server);
414 QuicPacketCreatorPeer::SetIsServer( 419 QuicPacketCreatorPeer::SetIsServer(
415 QuicConnectionPeer::GetPacketCreator(this), is_server); 420 QuicConnectionPeer::GetPacketCreator(this), is_server);
416 QuicConnectionPeer::SetIsServer(this, is_server); 421 QuicConnectionPeer::SetIsServer(this, is_server);
417 } 422 }
418 423
419 using QuicConnection::SendOrQueuePacket; 424 using QuicConnection::SendOrQueuePacket;
420 using QuicConnection::DontWaitForPacketsBefore; 425 using QuicConnection::DontWaitForPacketsBefore;
426 using QuicConnection::SelectMutualVersion;
421 427
422 private: 428 private:
423 TestConnectionHelper* helper_; 429 TestConnectionHelper* helper_;
424 430
425 DISALLOW_COPY_AND_ASSIGN(TestConnection); 431 DISALLOW_COPY_AND_ASSIGN(TestConnection);
426 }; 432 };
427 433
428 class QuicConnectionTest : public ::testing::Test { 434 class QuicConnectionTest : public ::testing::Test {
429 protected: 435 protected:
430 QuicConnectionTest() 436 QuicConnectionTest()
431 : guid_(42), 437 : guid_(42),
432 framer_(kQuicVersion1, QuicTime::Zero(), false), 438 framer_(QuicVersionMax(), QuicTime::Zero(), false),
433 creator_(guid_, &framer_, QuicRandom::GetInstance(), false), 439 creator_(guid_, &framer_, QuicRandom::GetInstance(), false),
434 send_algorithm_(new StrictMock<MockSendAlgorithm>), 440 send_algorithm_(new StrictMock<MockSendAlgorithm>),
435 helper_(new TestConnectionHelper(&clock_, &random_generator_)), 441 helper_(new TestConnectionHelper(&clock_, &random_generator_)),
436 connection_(guid_, IPEndPoint(), helper_, false), 442 connection_(guid_, IPEndPoint(), helper_, false),
437 frame1_(1, false, 0, data1), 443 frame1_(1, false, 0, data1),
438 frame2_(1, false, 3, data2), 444 frame2_(1, false, 3, data2),
439 accept_packet_(true) { 445 accept_packet_(true) {
440 connection_.set_visitor(&visitor_); 446 connection_.set_visitor(&visitor_);
441 connection_.SetSendAlgorithm(send_algorithm_); 447 connection_.SetSendAlgorithm(send_algorithm_);
442 // Simplify tests by not sending feedback unless specifically configured. 448 // Simplify tests by not sending feedback unless specifically configured.
(...skipping 1643 matching lines...) Expand 10 before | Expand all | Expand 10 after
2086 2092
2087 entropy_hash ^= packet_entropy_hash; 2093 entropy_hash ^= packet_entropy_hash;
2088 } 2094 }
2089 EXPECT_TRUE(QuicConnectionPeer::IsValidEntropy( 2095 EXPECT_TRUE(QuicConnectionPeer::IsValidEntropy(
2090 &connection_, max_sequence_number, missing_packets, entropy_hash)) 2096 &connection_, max_sequence_number, missing_packets, entropy_hash))
2091 << ""; 2097 << "";
2092 } 2098 }
2093 2099
2094 // TODO(satyamsehkhar): Add more test when we start supporting more versions. 2100 // TODO(satyamsehkhar): Add more test when we start supporting more versions.
2095 TEST_F(QuicConnectionTest, SendVersionNegotiationPacket) { 2101 TEST_F(QuicConnectionTest, SendVersionNegotiationPacket) {
2096 QuicTag kRandomVersion = 143; 2102 framer_.set_version_for_tests(QUIC_VERSION_UNSUPPORTED);
2097 QuicFramerPeer::SetVersion(&framer_, kRandomVersion);
2098 2103
2099 QuicPacketHeader header; 2104 QuicPacketHeader header;
2100 header.public_header.guid = guid_; 2105 header.public_header.guid = guid_;
2101 header.public_header.reset_flag = false; 2106 header.public_header.reset_flag = false;
2102 header.public_header.version_flag = true; 2107 header.public_header.version_flag = true;
2103 header.entropy_flag = false; 2108 header.entropy_flag = false;
2104 header.fec_flag = false; 2109 header.fec_flag = false;
2105 header.packet_sequence_number = 12; 2110 header.packet_sequence_number = 12;
2106 header.fec_group = 0; 2111 header.fec_group = 0;
2107 2112
2108 QuicFrames frames; 2113 QuicFrames frames;
2109 QuicFrame frame(&frame1_); 2114 QuicFrame frame(&frame1_);
2110 frames.push_back(frame); 2115 frames.push_back(frame);
2111 scoped_ptr<QuicPacket> packet( 2116 scoped_ptr<QuicPacket> packet(
2112 framer_.ConstructFrameDataPacket(header, frames).packet); 2117 framer_.ConstructFrameDataPacket(header, frames).packet);
2113 scoped_ptr<QuicEncryptedPacket> encrypted( 2118 scoped_ptr<QuicEncryptedPacket> encrypted(
2114 framer_.EncryptPacket(ENCRYPTION_NONE, 12, *packet)); 2119 framer_.EncryptPacket(ENCRYPTION_NONE, 12, *packet));
2115 2120
2116 QuicFramerPeer::SetVersion(&framer_, kQuicVersion1); 2121 framer_.set_version(QuicVersionMax());
2117 connection_.set_is_server(true); 2122 connection_.set_is_server(true);
2118 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); 2123 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted);
2119 EXPECT_TRUE(helper_->version_negotiation_packet() != NULL); 2124 EXPECT_TRUE(helper_->version_negotiation_packet() != NULL);
2120 EXPECT_EQ(1u, 2125
2126 size_t num_versions = ARRAYSIZE_UNSAFE(kSupportedQuicVersions);
2127 EXPECT_EQ(num_versions,
2121 helper_->version_negotiation_packet()->versions.size()); 2128 helper_->version_negotiation_packet()->versions.size());
2122 EXPECT_EQ(kQuicVersion1, 2129
2123 helper_->version_negotiation_packet()->versions[0]); 2130 // We expect all versions in kSupportedQuicVersions to be
2131 // included in the packet.
2132 for (size_t i = 0; i < num_versions; ++i) {
2133 EXPECT_EQ(kSupportedQuicVersions[i],
2134 helper_->version_negotiation_packet()->versions[i]);
2135 }
2124 } 2136 }
2125 2137
2126 TEST_F(QuicConnectionTest, CheckSendStats) { 2138 TEST_F(QuicConnectionTest, CheckSendStats) {
2127 EXPECT_CALL(*send_algorithm_, AbandoningPacket(_, _)).Times(3); 2139 EXPECT_CALL(*send_algorithm_, AbandoningPacket(_, _)).Times(3);
2128 EXPECT_CALL(*send_algorithm_, 2140 EXPECT_CALL(*send_algorithm_,
2129 SentPacket(_, _, _, NOT_RETRANSMISSION)); 2141 SentPacket(_, _, _, NOT_RETRANSMISSION));
2130 connection_.SendStreamData(1u, "first", 0, !kFin); 2142 connection_.SendStreamData(1u, "first", 0, !kFin);
2131 size_t first_packet_size = last_sent_packet_size(); 2143 size_t first_packet_size = last_sent_packet_size();
2132 2144
2133 EXPECT_CALL(*send_algorithm_, 2145 EXPECT_CALL(*send_algorithm_,
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
2244 scoped_ptr<QuicEncryptedPacket> encrypted(framer_.EncryptPacket( 2256 scoped_ptr<QuicEncryptedPacket> encrypted(framer_.EncryptPacket(
2245 ENCRYPTION_NONE, 1, *packet)); 2257 ENCRYPTION_NONE, 1, *packet));
2246 2258
2247 EXPECT_CALL(visitor_, OnCanWrite()).Times(1).WillOnce(Return(true)); 2259 EXPECT_CALL(visitor_, OnCanWrite()).Times(1).WillOnce(Return(true));
2248 EXPECT_CALL(visitor_, ConnectionClose(QUIC_PEER_GOING_AWAY, true)); 2260 EXPECT_CALL(visitor_, ConnectionClose(QUIC_PEER_GOING_AWAY, true));
2249 EXPECT_CALL(visitor_, OnPacket(_, _, _, _)).Times(0); 2261 EXPECT_CALL(visitor_, OnPacket(_, _, _, _)).Times(0);
2250 2262
2251 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); 2263 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted);
2252 } 2264 }
2253 2265
2266 //// The QUIC_VERSION_X versions are deliberately set, rather than using all
Ryan Hamilton 2013/07/23 03:40:18 Is this commented out internally?
ramant (doing other things) 2013/07/23 05:05:22 Yes. It was commented out internally (in the origi
2267 //// values in kSupportedQuicVersions.
2268 //TEST_F(QuicConnectionTest, SelectMutualVersion) {
2269 // // Set the connection to speak QUIC_VERSION_6.
2270 // connection_.set_version(QUIC_VERSION_6);
2271 // EXPECT_EQ(connection_.version(), QUIC_VERSION_6);
2272 //
2273 // // Pass in available versions which includes a higher mutually supported
2274 // // version. The higher mutually supported version should be selected.
2275 // EXPECT_TRUE(
2276 // connection_.SelectMutualVersion({QUIC_VERSION_6, QUIC_VERSION_7}));
2277 // EXPECT_EQ(connection_.version(), QUIC_VERSION_7);
2278 //
2279 // // Expect that the lower version is selected.
2280 // EXPECT_TRUE(connection_.SelectMutualVersion({QUIC_VERSION_6}));
2281 // EXPECT_EQ(connection_.version(), QUIC_VERSION_6);
2282 //
2283 // // Shouldn't be able to find a mutually supported version.
2284 // EXPECT_FALSE(connection_.SelectMutualVersion({QUIC_VERSION_UNSUPPORTED}));
2285 //}
2286
2254 } // namespace 2287 } // namespace
2255 } // namespace test 2288 } // namespace test
2256 } // namespace net 2289 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698