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

Unified Diff: net/quic/quic_http_stream_test.cc

Issue 1626703002: QUIC - fix crash when writing part of the request body fails (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/quic/quic_http_stream.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/quic/quic_http_stream_test.cc
diff --git a/net/quic/quic_http_stream_test.cc b/net/quic/quic_http_stream_test.cc
index a92266b1d6edf1e39ced4154abb353a390f4eb6d..be3364c59aa70d8133223125d80db4ad4d059b4d 100644
--- a/net/quic/quic_http_stream_test.cc
+++ b/net/quic/quic_http_stream_test.cc
@@ -125,8 +125,10 @@ class QuicHttpStreamTest : public ::testing::TestWithParam<QuicVersion> {
struct PacketToWrite {
PacketToWrite(IoMode mode, QuicEncryptedPacket* packet)
: mode(mode), packet(packet) {}
+ PacketToWrite(IoMode mode, int rv) : mode(mode), packet(nullptr), rv(rv) {}
IoMode mode;
QuicEncryptedPacket* packet;
+ int rv;
};
QuicHttpStreamTest()
@@ -157,6 +159,10 @@ class QuicHttpStreamTest : public ::testing::TestWithParam<QuicVersion> {
writes_.push_back(PacketToWrite(SYNCHRONOUS, packet.release()));
}
+ void AddWrite(IoMode mode, int rv) {
+ writes_.push_back(PacketToWrite(mode, rv));
+ }
+
// Returns the packet to be written at position |pos|.
QuicEncryptedPacket* GetWrite(size_t pos) { return writes_[pos].packet; }
@@ -173,8 +179,12 @@ class QuicHttpStreamTest : public ::testing::TestWithParam<QuicVersion> {
void Initialize() {
mock_writes_.reset(new MockWrite[writes_.size()]);
for (size_t i = 0; i < writes_.size(); i++) {
- mock_writes_[i] = MockWrite(writes_[i].mode, writes_[i].packet->data(),
- writes_[i].packet->length());
+ if (writes_[i].packet == nullptr) {
+ mock_writes_[i] = MockWrite(writes_[i].mode, writes_[i].rv, i);
+ } else {
+ mock_writes_[i] = MockWrite(writes_[i].mode, writes_[i].packet->data(),
+ writes_[i].packet->length());
+ }
};
socket_data_.reset(new StaticSocketDataProvider(
@@ -936,5 +946,48 @@ TEST_P(QuicHttpStreamTest, CheckPriorityWithNoDelegate) {
EXPECT_EQ(0, stream_->GetTotalReceivedBytes());
}
+TEST_P(QuicHttpStreamTest, SessionClosedBeforeSendHeadersComplete) {
+ SetRequest("POST", "/", DEFAULT_PRIORITY);
+ AddWrite(SYNCHRONOUS, ERR_FAILED);
+ Initialize();
+
+ ChunkedUploadDataStream upload_data_stream(0);
+
+ request_.method = "POST";
+ request_.url = GURL("http://www.google.com/");
+ request_.upload_data_stream = &upload_data_stream;
+ ASSERT_EQ(OK, request_.upload_data_stream->Init(
+ TestCompletionCallback().callback()));
+
+ ASSERT_EQ(OK, stream_->InitializeStream(&request_, DEFAULT_PRIORITY, net_log_,
+ callback_.callback()));
+ ASSERT_EQ(ERR_QUIC_PROTOCOL_ERROR,
+ stream_->SendRequest(headers_, &response_, callback_.callback()));
+}
+
+TEST_P(QuicHttpStreamTest, SessionClosedBeforeSendBodyComplete) {
+ SetRequest("POST", "/", DEFAULT_PRIORITY);
+ size_t spdy_request_headers_frame_length;
+ AddWrite(ConstructRequestHeadersPacket(1, !kFin, DEFAULT_PRIORITY,
+ &spdy_request_headers_frame_length));
+ AddWrite(SYNCHRONOUS, ERR_FAILED);
+ Initialize();
+
+ ChunkedUploadDataStream upload_data_stream(0);
+ size_t chunk_size = strlen(kUploadData);
+ upload_data_stream.AppendData(kUploadData, chunk_size, false);
+
+ request_.method = "POST";
+ request_.url = GURL("http://www.google.com/");
+ request_.upload_data_stream = &upload_data_stream;
+ ASSERT_EQ(OK, request_.upload_data_stream->Init(
+ TestCompletionCallback().callback()));
+
+ ASSERT_EQ(OK, stream_->InitializeStream(&request_, DEFAULT_PRIORITY, net_log_,
+ callback_.callback()));
+ ASSERT_EQ(ERR_QUIC_PROTOCOL_ERROR,
+ stream_->SendRequest(headers_, &response_, callback_.callback()));
+}
+
} // namespace test
} // namespace net
« no previous file with comments | « net/quic/quic_http_stream.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698