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

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

Issue 2163883004: Do not invoke QuicHttpStream::DoCallback when in DoLoop (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add a test which crashes with the exact call stack without the patch Created 4 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
« net/quic/quic_http_stream.cc ('K') | « net/quic/quic_http_stream.cc ('k') | no next file » | 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_http_stream.h" 5 #include "net/quic/quic_http_stream.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <utility> 10 #include <utility>
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 137
138 void ResetInternal() override {} 138 void ResetInternal() override {}
139 139
140 const FailureMode async_; 140 const FailureMode async_;
141 141
142 base::WeakPtrFactory<ReadErrorUploadDataStream> weak_factory_; 142 base::WeakPtrFactory<ReadErrorUploadDataStream> weak_factory_;
143 143
144 DISALLOW_COPY_AND_ASSIGN(ReadErrorUploadDataStream); 144 DISALLOW_COPY_AND_ASSIGN(ReadErrorUploadDataStream);
145 }; 145 };
146 146
147 // A Callback that deletes the QuicHttpStream.
148 class DeleteStreamCallback : public TestCompletionCallbackBase {
149 public:
150 DeleteStreamCallback(std::unique_ptr<QuicHttpStream> stream)
151 : stream_(std::move(stream)),
152 callback_(base::Bind(&DeleteStreamCallback::DeleteStream,
153 base::Unretained(this))) {}
154
155 const CompletionCallback& callback() const { return callback_; }
156
157 private:
158 void DeleteStream(int result) {
159 stream_.reset();
160 SetResult(result);
161 }
162
163 std::unique_ptr<QuicHttpStream> stream_;
164 CompletionCallback callback_;
165 };
166
147 } // namespace 167 } // namespace
148 168
149 class QuicHttpStreamPeer { 169 class QuicHttpStreamPeer {
150 public: 170 public:
151 static QuicChromiumClientStream* GetQuicChromiumClientStream( 171 static QuicChromiumClientStream* GetQuicChromiumClientStream(
152 QuicHttpStream* stream) { 172 QuicHttpStream* stream) {
153 return stream->stream_; 173 return stream->stream_;
154 } 174 }
155 175
156 static bool WasHandshakeConfirmed(QuicHttpStream* stream) { 176 static bool WasHandshakeConfirmed(QuicHttpStream* stream) {
(...skipping 1148 matching lines...) Expand 10 before | Expand all | Expand 10 after
1305 // Set Delegate to nullptr and make sure Priority returns highest 1325 // Set Delegate to nullptr and make sure Priority returns highest
1306 // priority. 1326 // priority.
1307 reliable_stream->SetDelegate(nullptr); 1327 reliable_stream->SetDelegate(nullptr);
1308 DCHECK_EQ(kV3HighestPriority, reliable_stream->priority()); 1328 DCHECK_EQ(kV3HighestPriority, reliable_stream->priority());
1309 reliable_stream->SetDelegate(delegate); 1329 reliable_stream->SetDelegate(delegate);
1310 1330
1311 EXPECT_EQ(0, stream_->GetTotalSentBytes()); 1331 EXPECT_EQ(0, stream_->GetTotalSentBytes());
1312 EXPECT_EQ(0, stream_->GetTotalReceivedBytes()); 1332 EXPECT_EQ(0, stream_->GetTotalReceivedBytes());
1313 } 1333 }
1314 1334
1335 TEST_P(QuicHttpStreamTest, SessionClosedDuringDoLoop) {
1336 SetRequest("POST", "/", DEFAULT_PRIORITY);
1337 size_t spdy_request_headers_frame_length;
1338 AddWrite(ConstructRequestHeadersPacket(1, !kFin, DEFAULT_PRIORITY,
1339 &spdy_request_headers_frame_length));
1340 AddWrite(
1341 ConstructClientDataPacket(2, kIncludeVersion, !kFin, 0, kUploadData));
1342 // Second data write will result in a synchronous failure which will close
1343 // the session.
1344 AddWrite(SYNCHRONOUS, ERR_FAILED);
1345 Initialize();
1346
1347 ChunkedUploadDataStream upload_data_stream(0);
1348
1349 request_.method = "POST";
1350 request_.url = GURL("http://www.example.org/");
1351 request_.upload_data_stream = &upload_data_stream;
1352 ASSERT_EQ(OK, request_.upload_data_stream->Init(
1353 TestCompletionCallback().callback()));
1354
1355 size_t chunk_size = strlen(kUploadData);
1356 upload_data_stream.AppendData(kUploadData, chunk_size, false);
1357 ASSERT_EQ(OK,
1358 stream_->InitializeStream(&request_, DEFAULT_PRIORITY,
1359 net_log_.bound(), callback_.callback()));
1360 QuicHttpStream* stream = stream_.get();
1361 DeleteStreamCallback delete_stream_callback(std::move(stream_));
1362 // SendRequest() completes asynchronously after the final chunk is added.
1363 ASSERT_EQ(ERR_IO_PENDING,
1364 stream->SendRequest(headers_, &response_, callback_.callback()));
1365 upload_data_stream.AppendData(kUploadData, chunk_size, true);
1366 int rv = callback_.WaitForResult();
1367 EXPECT_EQ(ERR_QUIC_PROTOCOL_ERROR, rv);
1368 }
1369
1315 TEST_P(QuicHttpStreamTest, SessionClosedBeforeSendHeadersComplete) { 1370 TEST_P(QuicHttpStreamTest, SessionClosedBeforeSendHeadersComplete) {
1316 SetRequest("POST", "/", DEFAULT_PRIORITY); 1371 SetRequest("POST", "/", DEFAULT_PRIORITY);
1317 AddWrite(SYNCHRONOUS, ERR_FAILED); 1372 AddWrite(SYNCHRONOUS, ERR_FAILED);
1318 Initialize(); 1373 Initialize();
1319 1374
1320 ChunkedUploadDataStream upload_data_stream(0); 1375 ChunkedUploadDataStream upload_data_stream(0);
1321 1376
1322 request_.method = "POST"; 1377 request_.method = "POST";
1323 request_.url = GURL("http://www.example.org/"); 1378 request_.url = GURL("http://www.example.org/");
1324 request_.upload_data_stream = &upload_data_stream; 1379 request_.upload_data_stream = &upload_data_stream;
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after
1852 EXPECT_TRUE(AtEof()); 1907 EXPECT_TRUE(AtEof());
1853 1908
1854 // QuicHttpStream::GetTotalSent/ReceivedBytes includes only headers. 1909 // QuicHttpStream::GetTotalSent/ReceivedBytes includes only headers.
1855 EXPECT_EQ(static_cast<int64_t>(spdy_request_headers_frame_length), 1910 EXPECT_EQ(static_cast<int64_t>(spdy_request_headers_frame_length),
1856 stream_->GetTotalSentBytes()); 1911 stream_->GetTotalSentBytes());
1857 EXPECT_EQ(0, stream_->GetTotalReceivedBytes()); 1912 EXPECT_EQ(0, stream_->GetTotalReceivedBytes());
1858 } 1913 }
1859 1914
1860 } // namespace test 1915 } // namespace test
1861 } // namespace net 1916 } // namespace net
OLDNEW
« net/quic/quic_http_stream.cc ('K') | « net/quic/quic_http_stream.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698