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

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

Issue 968513002: Land Recent QUIC Changes until 2/21/2015. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed const from members of TransmissionInfo struct. Created 5 years, 9 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
« no previous file with comments | « net/quic/quic_connection_stats.cc ('k') | net/quic/quic_flags.h » ('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/memory/scoped_ptr.h"
9 #include "base/stl_util.h" 10 #include "base/stl_util.h"
10 #include "net/base/net_errors.h" 11 #include "net/base/net_errors.h"
11 #include "net/quic/congestion_control/loss_detection_interface.h" 12 #include "net/quic/congestion_control/loss_detection_interface.h"
12 #include "net/quic/congestion_control/send_algorithm_interface.h" 13 #include "net/quic/congestion_control/send_algorithm_interface.h"
13 #include "net/quic/crypto/null_encrypter.h" 14 #include "net/quic/crypto/null_encrypter.h"
14 #include "net/quic/crypto/quic_decrypter.h" 15 #include "net/quic/crypto/quic_decrypter.h"
15 #include "net/quic/crypto/quic_encrypter.h" 16 #include "net/quic/crypto/quic_encrypter.h"
16 #include "net/quic/quic_ack_notifier.h" 17 #include "net/quic/quic_ack_notifier.h"
17 #include "net/quic/quic_flags.h" 18 #include "net/quic/quic_flags.h"
18 #include "net/quic/quic_protocol.h" 19 #include "net/quic/quic_protocol.h"
(...skipping 1553 matching lines...) Expand 10 before | Expand all | Expand 10 after
1572 SendAckPacketToPeer(); // Packet 7 1573 SendAckPacketToPeer(); // Packet 7
1573 EXPECT_EQ(7u, least_unacked()); 1574 EXPECT_EQ(7u, least_unacked());
1574 1575
1575 // But if we send more data it should. 1576 // But if we send more data it should.
1576 SendStreamDataToPeer(1, "eep", 6, !kFin, &last_packet); // Packet 8 1577 SendStreamDataToPeer(1, "eep", 6, !kFin, &last_packet); // Packet 8
1577 EXPECT_EQ(8u, last_packet); 1578 EXPECT_EQ(8u, last_packet);
1578 SendAckPacketToPeer(); // Packet 9 1579 SendAckPacketToPeer(); // Packet 9
1579 EXPECT_EQ(7u, least_unacked()); 1580 EXPECT_EQ(7u, least_unacked());
1580 } 1581 }
1581 1582
1582 // If FLAGS_quic_record_send_time_before_write is disabled, QuicConnection 1583 // QuicConnection should record the the packet sent-time prior to sending the
1583 // should record the packet sen-tdime after the packet is sent. 1584 // packet.
1584 TEST_P(QuicConnectionTest, RecordSentTimeAfterPacketSent) { 1585 TEST_P(QuicConnectionTest, RecordSentTimeBeforePacketSent) {
1585 ValueRestore<bool> old_flag(&FLAGS_quic_record_send_time_before_write, false);
1586 // We're using a MockClock for the tests, so we have complete control over the 1586 // We're using a MockClock for the tests, so we have complete control over the
1587 // time. 1587 // time.
1588 // Our recorded timestamp for the last packet sent time will be passed in to 1588 // Our recorded timestamp for the last packet sent time will be passed in to
1589 // the send_algorithm. Make sure that it is set to the correct value.
1590 QuicTime actual_recorded_send_time = QuicTime::Zero();
1591 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _))
1592 .WillOnce(DoAll(SaveArg<0>(&actual_recorded_send_time), Return(true)));
1593
1594 // First send without any pause and check the result.
1595 QuicTime expected_recorded_send_time = clock_.Now();
1596 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, nullptr);
1597 EXPECT_EQ(expected_recorded_send_time, actual_recorded_send_time)
1598 << "Expected time = " << expected_recorded_send_time.ToDebuggingValue()
1599 << ". Actual time = " << actual_recorded_send_time.ToDebuggingValue();
1600
1601 // Now pause during the write, and check the results.
1602 actual_recorded_send_time = QuicTime::Zero();
1603 const QuicTime::Delta kWritePauseTimeDelta =
1604 QuicTime::Delta::FromMilliseconds(5000);
1605 SetWritePauseTimeDelta(kWritePauseTimeDelta);
1606 expected_recorded_send_time = clock_.Now().Add(kWritePauseTimeDelta);
1607
1608 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _))
1609 .WillOnce(DoAll(SaveArg<0>(&actual_recorded_send_time), Return(true)));
1610 connection_.SendStreamDataWithString(2, "baz", 0, !kFin, nullptr);
1611 EXPECT_EQ(expected_recorded_send_time, actual_recorded_send_time)
1612 << "Expected time = " << expected_recorded_send_time.ToDebuggingValue()
1613 << ". Actual time = " << actual_recorded_send_time.ToDebuggingValue();
1614 }
1615
1616 // If FLAGS_quic_record_send_time_before_write is enabled, QuicConnection should
1617 // record the the packet sent-time prior to sending the packet.
1618 TEST_P(QuicConnectionTest, RecordSentTimeBeforePacketSent) {
1619 ValueRestore<bool> old_flag(&FLAGS_quic_record_send_time_before_write, true);
1620 // We're using a MockClock for the tests, so we have complete control over the
1621 // time.
1622 // Our recorded timestamp for the last packet sent time will be passed in to
1623 // the send_algorithm. Make sure that it is set to the correct value. 1589 // the send_algorithm. Make sure that it is set to the correct value.
1624 QuicTime actual_recorded_send_time = QuicTime::Zero(); 1590 QuicTime actual_recorded_send_time = QuicTime::Zero();
1625 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) 1591 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _))
1626 .WillOnce(DoAll(SaveArg<0>(&actual_recorded_send_time), Return(true))); 1592 .WillOnce(DoAll(SaveArg<0>(&actual_recorded_send_time), Return(true)));
1627 1593
1628 // First send without any pause and check the result. 1594 // First send without any pause and check the result.
1629 QuicTime expected_recorded_send_time = clock_.Now(); 1595 QuicTime expected_recorded_send_time = clock_.Now();
1630 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, nullptr); 1596 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, nullptr);
1631 EXPECT_EQ(expected_recorded_send_time, actual_recorded_send_time) 1597 EXPECT_EQ(expected_recorded_send_time, actual_recorded_send_time)
1632 << "Expected time = " << expected_recorded_send_time.ToDebuggingValue() 1598 << "Expected time = " << expected_recorded_send_time.ToDebuggingValue()
(...skipping 890 matching lines...) Expand 10 before | Expand all | Expand 10 after
2523 // Don't send missing packet 1. 2489 // Don't send missing packet 1.
2524 ProcessFecPacket(2, 1, true, !kEntropyFlag, nullptr); 2490 ProcessFecPacket(2, 1, true, !kEntropyFlag, nullptr);
2525 // Entropy flag should be false, so entropy should be 0. 2491 // Entropy flag should be false, so entropy should be 0.
2526 EXPECT_EQ(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 2)); 2492 EXPECT_EQ(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 2));
2527 } 2493 }
2528 2494
2529 TEST_P(QuicConnectionTest, ReviveMissingPacketWithVaryingSeqNumLengths) { 2495 TEST_P(QuicConnectionTest, ReviveMissingPacketWithVaryingSeqNumLengths) {
2530 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2496 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2531 2497
2532 // Set up a debug visitor to the connection. 2498 // Set up a debug visitor to the connection.
2533 FecQuicConnectionDebugVisitor* fec_visitor = 2499 scoped_ptr<FecQuicConnectionDebugVisitor> fec_visitor(
2534 new FecQuicConnectionDebugVisitor(); 2500 new FecQuicConnectionDebugVisitor());
2535 connection_.set_debug_visitor(fec_visitor); 2501 connection_.set_debug_visitor(fec_visitor.get());
2536 2502
2537 QuicPacketSequenceNumber fec_packet = 0; 2503 QuicPacketSequenceNumber fec_packet = 0;
2538 QuicSequenceNumberLength lengths[] = {PACKET_6BYTE_SEQUENCE_NUMBER, 2504 QuicSequenceNumberLength lengths[] = {PACKET_6BYTE_SEQUENCE_NUMBER,
2539 PACKET_4BYTE_SEQUENCE_NUMBER, 2505 PACKET_4BYTE_SEQUENCE_NUMBER,
2540 PACKET_2BYTE_SEQUENCE_NUMBER, 2506 PACKET_2BYTE_SEQUENCE_NUMBER,
2541 PACKET_1BYTE_SEQUENCE_NUMBER}; 2507 PACKET_1BYTE_SEQUENCE_NUMBER};
2542 // For each sequence number length size, revive a packet and check sequence 2508 // For each sequence number length size, revive a packet and check sequence
2543 // number length in the revived packet. 2509 // number length in the revived packet.
2544 for (size_t i = 0; i < arraysize(lengths); ++i) { 2510 for (size_t i = 0; i < arraysize(lengths); ++i) {
2545 // Set sequence_number_length_ (for data and FEC packets). 2511 // Set sequence_number_length_ (for data and FEC packets).
2546 sequence_number_length_ = lengths[i]; 2512 sequence_number_length_ = lengths[i];
2547 fec_packet += 2; 2513 fec_packet += 2;
2548 // Don't send missing packet, but send fec packet right after it. 2514 // Don't send missing packet, but send fec packet right after it.
2549 ProcessFecPacket(fec_packet, fec_packet - 1, true, !kEntropyFlag, nullptr); 2515 ProcessFecPacket(fec_packet, fec_packet - 1, true, !kEntropyFlag, nullptr);
2550 // Sequence number length in the revived header should be the same as 2516 // Sequence number length in the revived header should be the same as
2551 // in the original data/fec packet headers. 2517 // in the original data/fec packet headers.
2552 EXPECT_EQ(sequence_number_length_, fec_visitor->revived_header(). 2518 EXPECT_EQ(sequence_number_length_, fec_visitor->revived_header().
2553 public_header.sequence_number_length); 2519 public_header.sequence_number_length);
2554 } 2520 }
2555 } 2521 }
2556 2522
2557 TEST_P(QuicConnectionTest, ReviveMissingPacketWithVaryingConnectionIdLengths) { 2523 TEST_P(QuicConnectionTest, ReviveMissingPacketWithVaryingConnectionIdLengths) {
2558 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2524 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2559 2525
2560 // Set up a debug visitor to the connection. 2526 // Set up a debug visitor to the connection.
2561 FecQuicConnectionDebugVisitor* fec_visitor = 2527 scoped_ptr<FecQuicConnectionDebugVisitor> fec_visitor(
2562 new FecQuicConnectionDebugVisitor(); 2528 new FecQuicConnectionDebugVisitor());
2563 connection_.set_debug_visitor(fec_visitor); 2529 connection_.set_debug_visitor(fec_visitor.get());
2564 2530
2565 QuicPacketSequenceNumber fec_packet = 0; 2531 QuicPacketSequenceNumber fec_packet = 0;
2566 QuicConnectionIdLength lengths[] = {PACKET_8BYTE_CONNECTION_ID, 2532 QuicConnectionIdLength lengths[] = {PACKET_8BYTE_CONNECTION_ID,
2567 PACKET_4BYTE_CONNECTION_ID, 2533 PACKET_4BYTE_CONNECTION_ID,
2568 PACKET_1BYTE_CONNECTION_ID, 2534 PACKET_1BYTE_CONNECTION_ID,
2569 PACKET_0BYTE_CONNECTION_ID}; 2535 PACKET_0BYTE_CONNECTION_ID};
2570 // For each connection id length size, revive a packet and check connection 2536 // For each connection id length size, revive a packet and check connection
2571 // id length in the revived packet. 2537 // id length in the revived packet.
2572 for (size_t i = 0; i < arraysize(lengths); ++i) { 2538 for (size_t i = 0; i < arraysize(lengths); ++i) {
2573 // Set connection id length (for data and FEC packets). 2539 // Set connection id length (for data and FEC packets).
(...skipping 1787 matching lines...) Expand 10 before | Expand all | Expand 10 after
4361 MOCK_METHOD1(OnVersionNegotiationPacket, 4327 MOCK_METHOD1(OnVersionNegotiationPacket,
4362 void(const QuicVersionNegotiationPacket&)); 4328 void(const QuicVersionNegotiationPacket&));
4363 4329
4364 MOCK_METHOD2(OnRevivedPacket, 4330 MOCK_METHOD2(OnRevivedPacket,
4365 void(const QuicPacketHeader&, StringPiece payload)); 4331 void(const QuicPacketHeader&, StringPiece payload));
4366 }; 4332 };
4367 4333
4368 TEST_P(QuicConnectionTest, OnPacketHeaderDebugVisitor) { 4334 TEST_P(QuicConnectionTest, OnPacketHeaderDebugVisitor) {
4369 QuicPacketHeader header; 4335 QuicPacketHeader header;
4370 4336
4371 MockQuicConnectionDebugVisitor* debug_visitor = 4337 scoped_ptr<MockQuicConnectionDebugVisitor> debug_visitor(
4372 new MockQuicConnectionDebugVisitor(); 4338 new MockQuicConnectionDebugVisitor());
4373 connection_.set_debug_visitor(debug_visitor); 4339 connection_.set_debug_visitor(debug_visitor.get());
4374 EXPECT_CALL(*debug_visitor, OnPacketHeader(Ref(header))).Times(1); 4340 EXPECT_CALL(*debug_visitor, OnPacketHeader(Ref(header))).Times(1);
4375 connection_.OnPacketHeader(header); 4341 connection_.OnPacketHeader(header);
4376 } 4342 }
4377 4343
4378 TEST_P(QuicConnectionTest, Pacing) { 4344 TEST_P(QuicConnectionTest, Pacing) {
4379 TestConnection server(connection_id_, IPEndPoint(), helper_.get(), 4345 TestConnection server(connection_id_, IPEndPoint(), helper_.get(),
4380 factory_, /* is_server= */ true, version()); 4346 factory_, /* is_server= */ true, version());
4381 TestConnection client(connection_id_, IPEndPoint(), helper_.get(), 4347 TestConnection client(connection_id_, IPEndPoint(), helper_.get(),
4382 factory_, /* is_server= */ false, version()); 4348 factory_, /* is_server= */ false, version());
4383 EXPECT_FALSE(client.sent_packet_manager().using_pacing()); 4349 EXPECT_FALSE(client.sent_packet_manager().using_pacing());
(...skipping 29 matching lines...) Expand all
4413 // Regression test for b/18594622 4379 // Regression test for b/18594622
4414 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); 4380 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate);
4415 EXPECT_DFATAL( 4381 EXPECT_DFATAL(
4416 connection_.SendStreamDataWithString(3, "", 0, !kFin, delegate.get()), 4382 connection_.SendStreamDataWithString(3, "", 0, !kFin, delegate.get()),
4417 "Attempt to send empty stream frame"); 4383 "Attempt to send empty stream frame");
4418 } 4384 }
4419 4385
4420 } // namespace 4386 } // namespace
4421 } // namespace test 4387 } // namespace test
4422 } // namespace net 4388 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_connection_stats.cc ('k') | net/quic/quic_flags.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698