Index: net/quic/quic_connection_test.cc |
diff --git a/net/quic/quic_connection_test.cc b/net/quic/quic_connection_test.cc |
index 1225d185db263d51d3ef4ae2f82efba4a706f2d6..441c46cb5da8691cd8171e307c43cb74e701f88b 100644 |
--- a/net/quic/quic_connection_test.cc |
+++ b/net/quic/quic_connection_test.cc |
@@ -239,6 +239,7 @@ class TestPacketWriter : public QuicPacketWriter { |
framer_(SupportedVersions(version_)), |
last_packet_size_(0), |
write_blocked_(false), |
+ write_should_fail_(false), |
block_on_next_write_(false), |
is_write_blocked_data_buffered_(false), |
final_bytes_of_last_packet_(0), |
@@ -274,6 +275,11 @@ class TestPacketWriter : public QuicPacketWriter { |
if (IsWriteBlocked()) { |
return WriteResult(WRITE_STATUS_BLOCKED, -1); |
} |
+ |
+ if (ShouldWriteFail()) { |
+ return WriteResult(WRITE_STATUS_ERROR, 0); |
+ } |
+ |
last_packet_size_ = packet.length(); |
if (!write_pause_time_delta_.IsZero()) { |
@@ -286,10 +292,14 @@ class TestPacketWriter : public QuicPacketWriter { |
return is_write_blocked_data_buffered_; |
} |
+ bool ShouldWriteFail() { return write_should_fail_; } |
+ |
bool IsWriteBlocked() const override { return write_blocked_; } |
void SetWritable() override { write_blocked_ = false; } |
+ void SetShouldWriteFail() { write_should_fail_ = true; } |
+ |
QuicByteCount GetMaxPacketSize( |
const IPEndPoint& /*peer_address*/) const override { |
return max_packet_size_; |
@@ -383,6 +393,7 @@ class TestPacketWriter : public QuicPacketWriter { |
SimpleQuicFramer framer_; |
size_t last_packet_size_; |
bool write_blocked_; |
+ bool write_should_fail_; |
bool block_on_next_write_; |
bool is_write_blocked_data_buffered_; |
uint32 final_bytes_of_last_packet_; |
@@ -3649,6 +3660,16 @@ TEST_P(QuicConnectionTest, SendScheduler) { |
EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
} |
+TEST_P(QuicConnectionTest, FailToSendFirstPacket) { |
+ // Test that the connection does not crash when it fails to send the first |
+ // packet at which point self_address_ might be uninitialized. |
+ EXPECT_CALL(visitor_, OnConnectionClosed(_, _)).Times(1); |
+ QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); |
+ writer_->SetShouldWriteFail(); |
+ connection_.SendPacket(ENCRYPTION_NONE, 1, packet, kTestEntropyHash, |
+ HAS_RETRANSMITTABLE_DATA, false, false); |
+} |
+ |
TEST_P(QuicConnectionTest, SendSchedulerEAGAIN) { |
QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); |
BlockOnNextWrite(); |