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

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

Issue 2873963003: Add an async ReadInitialHeaders method to QuicChromiumClientStream::Handle (Closed)
Patch Set: Rebase Created 3 years, 7 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/chromium/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/chromium/quic_http_stream.h" 5 #include "net/quic/chromium/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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 }; 98 };
99 99
100 // Subclass of QuicHttpStream that closes itself when the first piece of data 100 // Subclass of QuicHttpStream that closes itself when the first piece of data
101 // is received. 101 // is received.
102 class AutoClosingStream : public QuicHttpStream { 102 class AutoClosingStream : public QuicHttpStream {
103 public: 103 public:
104 explicit AutoClosingStream( 104 explicit AutoClosingStream(
105 std::unique_ptr<QuicChromiumClientSession::Handle> session) 105 std::unique_ptr<QuicChromiumClientSession::Handle> session)
106 : QuicHttpStream(std::move(session)) {} 106 : QuicHttpStream(std::move(session)) {}
107 107
108 void OnInitialHeadersAvailable(const SpdyHeaderBlock& headers,
109 size_t frame_len) override {
110 Close(false);
111 }
112
113 void OnTrailingHeadersAvailable(const SpdyHeaderBlock& headers, 108 void OnTrailingHeadersAvailable(const SpdyHeaderBlock& headers,
114 size_t frame_len) override { 109 size_t frame_len) override {
115 Close(false); 110 Close(false);
116 } 111 }
117 112
118 void OnDataAvailable() override { Close(false); } 113 void OnDataAvailable() override { Close(false); }
119 }; 114 };
120 115
121 // UploadDataStream that always returns errors on data read. 116 // UploadDataStream that always returns errors on data read.
122 class ReadErrorUploadDataStream : public UploadDataStream { 117 class ReadErrorUploadDataStream : public UploadDataStream {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 171
177 class QuicHttpStreamPeer { 172 class QuicHttpStreamPeer {
178 public: 173 public:
179 static QuicChromiumClientStream::Handle* GetQuicChromiumClientStream( 174 static QuicChromiumClientStream::Handle* GetQuicChromiumClientStream(
180 QuicHttpStream* stream) { 175 QuicHttpStream* stream) {
181 return stream->stream_.get(); 176 return stream->stream_.get();
182 } 177 }
183 }; 178 };
184 179
185 class QuicHttpStreamTest : public ::testing::TestWithParam<QuicVersion> { 180 class QuicHttpStreamTest : public ::testing::TestWithParam<QuicVersion> {
181 public:
182 void CloseStream(QuicHttpStream* stream, int /*rv*/) { stream->Close(false); }
183
186 protected: 184 protected:
187 static const bool kFin = true; 185 static const bool kFin = true;
188 static const bool kIncludeVersion = true; 186 static const bool kIncludeVersion = true;
189 static const bool kIncludeCongestionFeedback = true; 187 static const bool kIncludeCongestionFeedback = true;
190 188
191 // Holds a packet to be written to the wire, and the IO mode that should 189 // Holds a packet to be written to the wire, and the IO mode that should
192 // be used by the mock socket when performing the write. 190 // be used by the mock socket when performing the write.
193 struct PacketToWrite { 191 struct PacketToWrite {
194 PacketToWrite(IoMode mode, QuicReceivedPacket* packet) 192 PacketToWrite(IoMode mode, QuicReceivedPacket* packet)
195 : mode(mode), packet(packet) {} 193 : mode(mode), packet(packet) {}
(...skipping 949 matching lines...) Expand 10 before | Expand all | Expand 10 after
1145 1143
1146 // Ack both packets in the request. 1144 // Ack both packets in the request.
1147 ProcessPacket(ConstructServerAckPacket(1, 0, 0, 0)); 1145 ProcessPacket(ConstructServerAckPacket(1, 0, 0, 0));
1148 1146
1149 // Send the response headers (but not the body). 1147 // Send the response headers (but not the body).
1150 SetResponse("200 OK", string()); 1148 SetResponse("200 OK", string());
1151 size_t spdy_response_headers_frame_length; 1149 size_t spdy_response_headers_frame_length;
1152 ProcessPacket(ConstructResponseHeadersPacket( 1150 ProcessPacket(ConstructResponseHeadersPacket(
1153 2, !kFin, &spdy_response_headers_frame_length)); 1151 2, !kFin, &spdy_response_headers_frame_length));
1154 1152
1155 // The headers have arrived, but they are delivered asynchronously. 1153 // The headers have already arrived.
1156 EXPECT_THAT(stream_->ReadResponseHeaders(callback_.callback()), 1154 EXPECT_THAT(stream_->ReadResponseHeaders(callback_.callback()), IsOk());
1157 IsError(ERR_IO_PENDING));
1158 EXPECT_THAT(callback_.WaitForResult(), IsOk());
1159 ASSERT_TRUE(response_.headers.get()); 1155 ASSERT_TRUE(response_.headers.get());
1160 EXPECT_EQ(200, response_.headers->response_code()); 1156 EXPECT_EQ(200, response_.headers->response_code());
1161 EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain")); 1157 EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain"));
1162 1158
1163 // Send the response body. 1159 // Send the response body.
1164 const char kResponseBody[] = "Hello world!"; 1160 const char kResponseBody[] = "Hello world!";
1165 ProcessPacket(ConstructServerDataPacket(3, false, kFin, 0, kResponseBody)); 1161 ProcessPacket(ConstructServerDataPacket(3, false, kFin, 0, kResponseBody));
1166 // Since the body has already arrived, this should return immediately. 1162 // Since the body has already arrived, this should return immediately.
1167 EXPECT_EQ(static_cast<int>(strlen(kResponseBody)), 1163 EXPECT_EQ(static_cast<int>(strlen(kResponseBody)),
1168 stream_->ReadResponseBody(read_buffer_.get(), read_buffer_->size(), 1164 stream_->ReadResponseBody(read_buffer_.get(), read_buffer_->size(),
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1218 1214
1219 // Ack both packets in the request. 1215 // Ack both packets in the request.
1220 ProcessPacket(ConstructServerAckPacket(1, 0, 0, 0)); 1216 ProcessPacket(ConstructServerAckPacket(1, 0, 0, 0));
1221 1217
1222 // Send the response headers (but not the body). 1218 // Send the response headers (but not the body).
1223 SetResponse("200 OK", string()); 1219 SetResponse("200 OK", string());
1224 size_t spdy_response_headers_frame_length; 1220 size_t spdy_response_headers_frame_length;
1225 ProcessPacket(ConstructResponseHeadersPacket( 1221 ProcessPacket(ConstructResponseHeadersPacket(
1226 2, !kFin, &spdy_response_headers_frame_length)); 1222 2, !kFin, &spdy_response_headers_frame_length));
1227 1223
1228 // The headers have arrived, but they are delivered asynchronously 1224 // The headers have already arrived.
1229 EXPECT_THAT(stream_->ReadResponseHeaders(callback_.callback()), 1225 EXPECT_THAT(stream_->ReadResponseHeaders(callback_.callback()), IsOk());
1230 IsError(ERR_IO_PENDING));
1231 EXPECT_THAT(callback_.WaitForResult(), IsOk());
1232 ASSERT_TRUE(response_.headers.get()); 1226 ASSERT_TRUE(response_.headers.get());
1233 EXPECT_EQ(200, response_.headers->response_code()); 1227 EXPECT_EQ(200, response_.headers->response_code());
1234 EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain")); 1228 EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain"));
1235 1229
1236 // Send the response body. 1230 // Send the response body.
1237 const char kResponseBody[] = "Hello world!"; 1231 const char kResponseBody[] = "Hello world!";
1238 ProcessPacket(ConstructServerDataPacket( 1232 ProcessPacket(ConstructServerDataPacket(
1239 3, false, kFin, response_data_.length(), kResponseBody)); 1233 3, false, kFin, response_data_.length(), kResponseBody));
1240 1234
1241 // Since the body has already arrived, this should return immediately. 1235 // Since the body has already arrived, this should return immediately.
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1291 EXPECT_THAT(callback_.WaitForResult(), IsOk()); 1285 EXPECT_THAT(callback_.WaitForResult(), IsOk());
1292 1286
1293 ProcessPacket(ConstructServerAckPacket(1, 0, 0, 0)); 1287 ProcessPacket(ConstructServerAckPacket(1, 0, 0, 0));
1294 1288
1295 // Send the response headers (but not the body). 1289 // Send the response headers (but not the body).
1296 SetResponse("200 OK", string()); 1290 SetResponse("200 OK", string());
1297 size_t spdy_response_headers_frame_length; 1291 size_t spdy_response_headers_frame_length;
1298 ProcessPacket(ConstructResponseHeadersPacket( 1292 ProcessPacket(ConstructResponseHeadersPacket(
1299 2, !kFin, &spdy_response_headers_frame_length)); 1293 2, !kFin, &spdy_response_headers_frame_length));
1300 1294
1301 // The headers have arrived, but they are delivered asynchronously 1295 // The headers have already arrived.
1302 EXPECT_THAT(stream_->ReadResponseHeaders(callback_.callback()), 1296 EXPECT_THAT(stream_->ReadResponseHeaders(callback_.callback()), IsOk());
1303 IsError(ERR_IO_PENDING));
1304 EXPECT_THAT(callback_.WaitForResult(), IsOk());
1305 ASSERT_TRUE(response_.headers.get()); 1297 ASSERT_TRUE(response_.headers.get());
1306 EXPECT_EQ(200, response_.headers->response_code()); 1298 EXPECT_EQ(200, response_.headers->response_code());
1307 EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain")); 1299 EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain"));
1308 1300
1309 // Send the response body. 1301 // Send the response body.
1310 const char kResponseBody[] = "Hello world!"; 1302 const char kResponseBody[] = "Hello world!";
1311 ProcessPacket(ConstructServerDataPacket( 1303 ProcessPacket(ConstructServerDataPacket(
1312 3, false, kFin, response_data_.length(), kResponseBody)); 1304 3, false, kFin, response_data_.length(), kResponseBody));
1313 1305
1314 // The body has arrived, but it is delivered asynchronously 1306 // The body has arrived, but it is delivered asynchronously
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1359 EXPECT_THAT(callback_.WaitForResult(), IsOk()); 1351 EXPECT_THAT(callback_.WaitForResult(), IsOk());
1360 1352
1361 ProcessPacket(ConstructServerAckPacket(1, 0, 0, 0)); 1353 ProcessPacket(ConstructServerAckPacket(1, 0, 0, 0));
1362 1354
1363 // Send the response headers (but not the body). 1355 // Send the response headers (but not the body).
1364 SetResponse("200 OK", string()); 1356 SetResponse("200 OK", string());
1365 size_t spdy_response_headers_frame_length; 1357 size_t spdy_response_headers_frame_length;
1366 ProcessPacket(ConstructResponseHeadersPacket( 1358 ProcessPacket(ConstructResponseHeadersPacket(
1367 2, !kFin, &spdy_response_headers_frame_length)); 1359 2, !kFin, &spdy_response_headers_frame_length));
1368 1360
1369 // The headers have arrived, but they are delivered asynchronously 1361 // The headers have already arrived.
1370 EXPECT_THAT(stream_->ReadResponseHeaders(callback_.callback()), 1362 EXPECT_THAT(stream_->ReadResponseHeaders(callback_.callback()), IsOk());
1371 IsError(ERR_IO_PENDING));
1372 EXPECT_THAT(callback_.WaitForResult(), IsOk());
1373 ASSERT_TRUE(response_.headers.get()); 1363 ASSERT_TRUE(response_.headers.get());
1374 EXPECT_EQ(200, response_.headers->response_code()); 1364 EXPECT_EQ(200, response_.headers->response_code());
1375 EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain")); 1365 EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain"));
1376 1366
1377 // Send the response body. 1367 // Send the response body.
1378 const char kResponseBody[] = "Hello world!"; 1368 const char kResponseBody[] = "Hello world!";
1379 ProcessPacket(ConstructServerDataPacket( 1369 ProcessPacket(ConstructServerDataPacket(
1380 3, false, kFin, response_data_.length(), kResponseBody)); 1370 3, false, kFin, response_data_.length(), kResponseBody));
1381 1371
1382 // The body has arrived, but it is delivered asynchronously 1372 // The body has arrived, but it is delivered asynchronously
(...skipping 30 matching lines...) Expand all
1413 request_.url = GURL("https://www.example.org/"); 1403 request_.url = GURL("https://www.example.org/");
1414 1404
1415 EXPECT_EQ(OK, 1405 EXPECT_EQ(OK,
1416 stream_->InitializeStream(&request_, DEFAULT_PRIORITY, 1406 stream_->InitializeStream(&request_, DEFAULT_PRIORITY,
1417 net_log_.bound(), callback_.callback())); 1407 net_log_.bound(), callback_.callback()));
1418 EXPECT_EQ(OK, 1408 EXPECT_EQ(OK,
1419 stream_->SendRequest(headers_, &response_, callback_.callback())); 1409 stream_->SendRequest(headers_, &response_, callback_.callback()));
1420 1410
1421 // Ack the request. 1411 // Ack the request.
1422 ProcessPacket(ConstructServerAckPacket(1, 0, 0, 0)); 1412 ProcessPacket(ConstructServerAckPacket(1, 0, 0, 0));
1423 EXPECT_THAT(stream_->ReadResponseHeaders(callback_.callback()), 1413 EXPECT_THAT(stream_->ReadResponseHeaders(
1414 base::Bind(&QuicHttpStreamTest::CloseStream,
1415 base::Unretained(this), stream_.get())),
1424 IsError(ERR_IO_PENDING)); 1416 IsError(ERR_IO_PENDING));
1425 1417
1426 // Send the response with a body. 1418 // Send the response with a body.
1427 SetResponse("404 OK", "hello world!"); 1419 SetResponse("404 OK", "hello world!");
1428 // In the course of processing this packet, the QuicHttpStream close itself. 1420 // In the course of processing this packet, the QuicHttpStream close itself.
1429 ProcessPacket(ConstructResponseHeadersPacket(2, kFin, nullptr)); 1421 size_t response_size = 0;
1422 ProcessPacket(ConstructResponseHeadersPacket(2, kFin, &response_size));
1430 1423
1431 base::RunLoop().RunUntilIdle(); 1424 base::RunLoop().RunUntilIdle();
1432 1425
1433 EXPECT_TRUE(AtEof()); 1426 EXPECT_TRUE(AtEof());
1434 1427
1435 // QuicHttpStream::GetTotalSent/ReceivedBytes currently only includes the 1428 // QuicHttpStream::GetTotalSent/ReceivedBytes currently only includes the
1436 // headers and payload. 1429 // headers and payload.
1437 EXPECT_EQ(static_cast<int64_t>(spdy_request_headers_frame_length), 1430 EXPECT_EQ(static_cast<int64_t>(spdy_request_headers_frame_length),
1438 stream_->GetTotalSentBytes()); 1431 stream_->GetTotalSentBytes());
1439 // Zero since the stream is closed before processing the headers. 1432 // The stream was closed after receiving the headers.
1440 EXPECT_EQ(0, stream_->GetTotalReceivedBytes()); 1433 EXPECT_EQ(static_cast<int64_t>(response_size),
1434 stream_->GetTotalReceivedBytes());
1441 } 1435 }
1442 1436
1443 TEST_P(QuicHttpStreamTest, Priority) { 1437 TEST_P(QuicHttpStreamTest, Priority) {
1444 SetRequest("GET", "/", MEDIUM); 1438 SetRequest("GET", "/", MEDIUM);
1445 size_t spdy_request_headers_frame_length; 1439 size_t spdy_request_headers_frame_length;
1446 QuicStreamOffset header_stream_offset = 0; 1440 QuicStreamOffset header_stream_offset = 0;
1447 AddWrite(ConstructInitialSettingsPacket(&header_stream_offset)); 1441 AddWrite(ConstructInitialSettingsPacket(&header_stream_offset));
1448 AddWrite(InnerConstructRequestHeadersPacket( 1442 AddWrite(InnerConstructRequestHeadersPacket(
1449 2, GetNthClientInitiatedStreamId(0), kIncludeVersion, kFin, MEDIUM, 1443 2, GetNthClientInitiatedStreamId(0), kIncludeVersion, kFin, MEDIUM,
1450 &spdy_request_headers_frame_length, &header_stream_offset)); 1444 &spdy_request_headers_frame_length, &header_stream_offset));
1451 AddWrite(ConstructAckAndRstStreamPacket(3));
1452 use_closing_stream_ = true; 1445 use_closing_stream_ = true;
1453 Initialize(); 1446 Initialize();
1454 1447
1455 request_.method = "GET"; 1448 request_.method = "GET";
1456 request_.url = GURL("https://www.example.org/"); 1449 request_.url = GURL("https://www.example.org/");
1457 1450
1458 EXPECT_EQ(OK, stream_->InitializeStream(&request_, MEDIUM, net_log_.bound(), 1451 EXPECT_EQ(OK, stream_->InitializeStream(&request_, MEDIUM, net_log_.bound(),
1459 callback_.callback())); 1452 callback_.callback()));
1460 1453
1461 // Check that priority is highest. 1454 // Check that priority is highest.
1462 QuicChromiumClientStream::Handle* reliable_stream = 1455 QuicChromiumClientStream::Handle* reliable_stream =
1463 QuicHttpStreamPeer::GetQuicChromiumClientStream(stream_.get()); 1456 QuicHttpStreamPeer::GetQuicChromiumClientStream(stream_.get());
1464 DCHECK(reliable_stream); 1457 DCHECK(reliable_stream);
1465 DCHECK_EQ(kV3HighestPriority, reliable_stream->priority()); 1458 DCHECK_EQ(kV3HighestPriority, reliable_stream->priority());
1466 1459
1467 EXPECT_EQ(OK, 1460 EXPECT_EQ(OK,
1468 stream_->SendRequest(headers_, &response_, callback_.callback())); 1461 stream_->SendRequest(headers_, &response_, callback_.callback()));
1469 1462
1470 // Check that priority has now dropped back to MEDIUM. 1463 // Check that priority has now dropped back to MEDIUM.
1471 DCHECK_EQ(MEDIUM, 1464 DCHECK_EQ(MEDIUM,
1472 ConvertQuicPriorityToRequestPriority(reliable_stream->priority())); 1465 ConvertQuicPriorityToRequestPriority(reliable_stream->priority()));
1473 1466
1474 // Ack the request. 1467 // Ack the request.
1475 ProcessPacket(ConstructServerAckPacket(1, 0, 0, 0)); 1468 ProcessPacket(ConstructServerAckPacket(1, 0, 0, 0));
1476 EXPECT_THAT(stream_->ReadResponseHeaders(callback_.callback()), 1469 EXPECT_THAT(stream_->ReadResponseHeaders(callback_.callback()),
1477 IsError(ERR_IO_PENDING)); 1470 IsError(ERR_IO_PENDING));
1478 1471
1479 // Send the response with a body. 1472 // Send the response with a body.
1480 SetResponse("404 OK", "hello world!"); 1473 SetResponse("404 OK", "hello world!");
1481 // In the course of processing this packet, the QuicHttpStream close itself. 1474 size_t response_size = 0;
1482 ProcessPacket(ConstructResponseHeadersPacket(2, kFin, nullptr)); 1475 ProcessPacket(ConstructResponseHeadersPacket(2, kFin, &response_size));
1483 1476
1484 base::RunLoop().RunUntilIdle(); 1477 EXPECT_EQ(OK, callback_.WaitForResult());
1485 1478
1486 EXPECT_TRUE(AtEof()); 1479 EXPECT_TRUE(AtEof());
1487 1480
1488 // QuicHttpStream::GetTotalSent/ReceivedBytes currently only includes the 1481 // QuicHttpStream::GetTotalSent/ReceivedBytes currently only includes the
1489 // headers and payload. 1482 // headers and payload.
1490 EXPECT_EQ(static_cast<int64_t>(spdy_request_headers_frame_length), 1483 EXPECT_EQ(static_cast<int64_t>(spdy_request_headers_frame_length),
1491 stream_->GetTotalSentBytes()); 1484 stream_->GetTotalSentBytes());
1492 // Zero since the stream is closed before processing the headers. 1485 EXPECT_EQ(static_cast<int64_t>(response_size),
1493 EXPECT_EQ(0, stream_->GetTotalReceivedBytes()); 1486 stream_->GetTotalReceivedBytes());
1494 } 1487 }
1495 1488
1496 // Regression test for http://crbug.com/294870 1489 // Regression test for http://crbug.com/294870
1497 TEST_P(QuicHttpStreamTest, CheckPriorityWithNoDelegate) { 1490 TEST_P(QuicHttpStreamTest, CheckPriorityWithNoDelegate) {
1498 SetRequest("GET", "/", MEDIUM); 1491 SetRequest("GET", "/", MEDIUM);
1499 use_closing_stream_ = true; 1492 use_closing_stream_ = true;
1500 QuicStreamOffset header_stream_offset = 0; 1493 QuicStreamOffset header_stream_offset = 0;
1501 AddWrite(ConstructInitialSettingsPacket(&header_stream_offset)); 1494 AddWrite(ConstructInitialSettingsPacket(&header_stream_offset));
1502 AddWrite(ConstructClientRstStreamPacket(2)); 1495 AddWrite(ConstructClientRstStreamPacket(2));
1503 1496
(...skipping 660 matching lines...) Expand 10 before | Expand all | Expand 10 after
2164 EXPECT_TRUE(AtEof()); 2157 EXPECT_TRUE(AtEof());
2165 2158
2166 // QuicHttpStream::GetTotalSent/ReceivedBytes includes only headers. 2159 // QuicHttpStream::GetTotalSent/ReceivedBytes includes only headers.
2167 EXPECT_EQ(static_cast<int64_t>(spdy_request_headers_frame_length), 2160 EXPECT_EQ(static_cast<int64_t>(spdy_request_headers_frame_length),
2168 stream_->GetTotalSentBytes()); 2161 stream_->GetTotalSentBytes());
2169 EXPECT_EQ(0, stream_->GetTotalReceivedBytes()); 2162 EXPECT_EQ(0, stream_->GetTotalReceivedBytes());
2170 } 2163 }
2171 2164
2172 } // namespace test 2165 } // namespace test
2173 } // namespace net 2166 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/chromium/quic_http_stream.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698