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

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: Fix comments 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
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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 100
101 // Subclass of QuicHttpStream that closes itself when the first piece of data 101 // Subclass of QuicHttpStream that closes itself when the first piece of data
102 // is received. 102 // is received.
103 class AutoClosingStream : public QuicHttpStream { 103 class AutoClosingStream : public QuicHttpStream {
104 public: 104 public:
105 explicit AutoClosingStream( 105 explicit AutoClosingStream(
106 std::unique_ptr<QuicChromiumClientSession::Handle> session, 106 std::unique_ptr<QuicChromiumClientSession::Handle> session,
107 HttpServerProperties* http_server_properties) 107 HttpServerProperties* http_server_properties)
108 : QuicHttpStream(std::move(session), http_server_properties) {} 108 : QuicHttpStream(std::move(session), http_server_properties) {}
109 109
110 void OnInitialHeadersAvailable(const SpdyHeaderBlock& headers,
111 size_t frame_len) override {
112 Close(false);
113 }
114
115 void OnTrailingHeadersAvailable(const SpdyHeaderBlock& headers, 110 void OnTrailingHeadersAvailable(const SpdyHeaderBlock& headers,
116 size_t frame_len) override { 111 size_t frame_len) override {
117 Close(false); 112 Close(false);
118 } 113 }
119 114
120 void OnDataAvailable() override { Close(false); } 115 void OnDataAvailable() override { Close(false); }
121 }; 116 };
122 117
123 // UploadDataStream that always returns errors on data read. 118 // UploadDataStream that always returns errors on data read.
124 class ReadErrorUploadDataStream : public UploadDataStream { 119 class ReadErrorUploadDataStream : public UploadDataStream {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 173
179 class QuicHttpStreamPeer { 174 class QuicHttpStreamPeer {
180 public: 175 public:
181 static QuicChromiumClientStream::Handle* GetQuicChromiumClientStream( 176 static QuicChromiumClientStream::Handle* GetQuicChromiumClientStream(
182 QuicHttpStream* stream) { 177 QuicHttpStream* stream) {
183 return stream->stream_.get(); 178 return stream->stream_.get();
184 } 179 }
185 }; 180 };
186 181
187 class QuicHttpStreamTest : public ::testing::TestWithParam<QuicVersion> { 182 class QuicHttpStreamTest : public ::testing::TestWithParam<QuicVersion> {
183 public:
184 void CloseStream(QuicHttpStream* stream, int /*rv*/) { stream->Close(false); }
185
188 protected: 186 protected:
189 static const bool kFin = true; 187 static const bool kFin = true;
190 static const bool kIncludeVersion = true; 188 static const bool kIncludeVersion = true;
191 static const bool kIncludeCongestionFeedback = true; 189 static const bool kIncludeCongestionFeedback = true;
192 190
193 // Holds a packet to be written to the wire, and the IO mode that should 191 // Holds a packet to be written to the wire, and the IO mode that should
194 // be used by the mock socket when performing the write. 192 // be used by the mock socket when performing the write.
195 struct PacketToWrite { 193 struct PacketToWrite {
196 PacketToWrite(IoMode mode, QuicReceivedPacket* packet) 194 PacketToWrite(IoMode mode, QuicReceivedPacket* packet)
197 : mode(mode), packet(packet) {} 195 : mode(mode), packet(packet) {}
(...skipping 954 matching lines...) Expand 10 before | Expand all | Expand 10 after
1152 1150
1153 // Ack both packets in the request. 1151 // Ack both packets in the request.
1154 ProcessPacket(ConstructServerAckPacket(1, 0, 0, 0)); 1152 ProcessPacket(ConstructServerAckPacket(1, 0, 0, 0));
1155 1153
1156 // Send the response headers (but not the body). 1154 // Send the response headers (but not the body).
1157 SetResponse("200 OK", string()); 1155 SetResponse("200 OK", string());
1158 size_t spdy_response_headers_frame_length; 1156 size_t spdy_response_headers_frame_length;
1159 ProcessPacket(ConstructResponseHeadersPacket( 1157 ProcessPacket(ConstructResponseHeadersPacket(
1160 2, !kFin, &spdy_response_headers_frame_length)); 1158 2, !kFin, &spdy_response_headers_frame_length));
1161 1159
1162 // The headers have arrived, but they are delivered asynchronously. 1160 // The headers have already arrived.
1163 EXPECT_THAT(stream_->ReadResponseHeaders(callback_.callback()), 1161 EXPECT_THAT(stream_->ReadResponseHeaders(callback_.callback()), IsOk());
1164 IsError(ERR_IO_PENDING));
1165 EXPECT_THAT(callback_.WaitForResult(), IsOk());
1166 ASSERT_TRUE(response_.headers.get()); 1162 ASSERT_TRUE(response_.headers.get());
1167 EXPECT_EQ(200, response_.headers->response_code()); 1163 EXPECT_EQ(200, response_.headers->response_code());
1168 EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain")); 1164 EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain"));
1169 1165
1170 // Send the response body. 1166 // Send the response body.
1171 const char kResponseBody[] = "Hello world!"; 1167 const char kResponseBody[] = "Hello world!";
1172 ProcessPacket(ConstructServerDataPacket(3, false, kFin, 0, kResponseBody)); 1168 ProcessPacket(ConstructServerDataPacket(3, false, kFin, 0, kResponseBody));
1173 // Since the body has already arrived, this should return immediately. 1169 // Since the body has already arrived, this should return immediately.
1174 EXPECT_EQ(static_cast<int>(strlen(kResponseBody)), 1170 EXPECT_EQ(static_cast<int>(strlen(kResponseBody)),
1175 stream_->ReadResponseBody(read_buffer_.get(), read_buffer_->size(), 1171 stream_->ReadResponseBody(read_buffer_.get(), read_buffer_->size(),
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1225 1221
1226 // Ack both packets in the request. 1222 // Ack both packets in the request.
1227 ProcessPacket(ConstructServerAckPacket(1, 0, 0, 0)); 1223 ProcessPacket(ConstructServerAckPacket(1, 0, 0, 0));
1228 1224
1229 // Send the response headers (but not the body). 1225 // Send the response headers (but not the body).
1230 SetResponse("200 OK", string()); 1226 SetResponse("200 OK", string());
1231 size_t spdy_response_headers_frame_length; 1227 size_t spdy_response_headers_frame_length;
1232 ProcessPacket(ConstructResponseHeadersPacket( 1228 ProcessPacket(ConstructResponseHeadersPacket(
1233 2, !kFin, &spdy_response_headers_frame_length)); 1229 2, !kFin, &spdy_response_headers_frame_length));
1234 1230
1235 // The headers have arrived, but they are delivered asynchronously 1231 // The headers have already arrived.
1236 EXPECT_THAT(stream_->ReadResponseHeaders(callback_.callback()), 1232 EXPECT_THAT(stream_->ReadResponseHeaders(callback_.callback()), IsOk());
1237 IsError(ERR_IO_PENDING));
1238 EXPECT_THAT(callback_.WaitForResult(), IsOk());
1239 ASSERT_TRUE(response_.headers.get()); 1233 ASSERT_TRUE(response_.headers.get());
1240 EXPECT_EQ(200, response_.headers->response_code()); 1234 EXPECT_EQ(200, response_.headers->response_code());
1241 EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain")); 1235 EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain"));
1242 1236
1243 // Send the response body. 1237 // Send the response body.
1244 const char kResponseBody[] = "Hello world!"; 1238 const char kResponseBody[] = "Hello world!";
1245 ProcessPacket(ConstructServerDataPacket( 1239 ProcessPacket(ConstructServerDataPacket(
1246 3, false, kFin, response_data_.length(), kResponseBody)); 1240 3, false, kFin, response_data_.length(), kResponseBody));
1247 1241
1248 // Since the body has already arrived, this should return immediately. 1242 // Since the body has already arrived, this should return immediately.
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1298 EXPECT_THAT(callback_.WaitForResult(), IsOk()); 1292 EXPECT_THAT(callback_.WaitForResult(), IsOk());
1299 1293
1300 ProcessPacket(ConstructServerAckPacket(1, 0, 0, 0)); 1294 ProcessPacket(ConstructServerAckPacket(1, 0, 0, 0));
1301 1295
1302 // Send the response headers (but not the body). 1296 // Send the response headers (but not the body).
1303 SetResponse("200 OK", string()); 1297 SetResponse("200 OK", string());
1304 size_t spdy_response_headers_frame_length; 1298 size_t spdy_response_headers_frame_length;
1305 ProcessPacket(ConstructResponseHeadersPacket( 1299 ProcessPacket(ConstructResponseHeadersPacket(
1306 2, !kFin, &spdy_response_headers_frame_length)); 1300 2, !kFin, &spdy_response_headers_frame_length));
1307 1301
1308 // The headers have arrived, but they are delivered asynchronously 1302 // The headers have already arrived.
1309 EXPECT_THAT(stream_->ReadResponseHeaders(callback_.callback()), 1303 EXPECT_THAT(stream_->ReadResponseHeaders(callback_.callback()), IsOk());
1310 IsError(ERR_IO_PENDING));
1311 EXPECT_THAT(callback_.WaitForResult(), IsOk());
1312 ASSERT_TRUE(response_.headers.get()); 1304 ASSERT_TRUE(response_.headers.get());
1313 EXPECT_EQ(200, response_.headers->response_code()); 1305 EXPECT_EQ(200, response_.headers->response_code());
1314 EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain")); 1306 EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain"));
1315 1307
1316 // Send the response body. 1308 // Send the response body.
1317 const char kResponseBody[] = "Hello world!"; 1309 const char kResponseBody[] = "Hello world!";
1318 ProcessPacket(ConstructServerDataPacket( 1310 ProcessPacket(ConstructServerDataPacket(
1319 3, false, kFin, response_data_.length(), kResponseBody)); 1311 3, false, kFin, response_data_.length(), kResponseBody));
1320 1312
1321 // The body has arrived, but it is delivered asynchronously 1313 // The body has arrived, but it is delivered asynchronously
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1366 EXPECT_THAT(callback_.WaitForResult(), IsOk()); 1358 EXPECT_THAT(callback_.WaitForResult(), IsOk());
1367 1359
1368 ProcessPacket(ConstructServerAckPacket(1, 0, 0, 0)); 1360 ProcessPacket(ConstructServerAckPacket(1, 0, 0, 0));
1369 1361
1370 // Send the response headers (but not the body). 1362 // Send the response headers (but not the body).
1371 SetResponse("200 OK", string()); 1363 SetResponse("200 OK", string());
1372 size_t spdy_response_headers_frame_length; 1364 size_t spdy_response_headers_frame_length;
1373 ProcessPacket(ConstructResponseHeadersPacket( 1365 ProcessPacket(ConstructResponseHeadersPacket(
1374 2, !kFin, &spdy_response_headers_frame_length)); 1366 2, !kFin, &spdy_response_headers_frame_length));
1375 1367
1376 // The headers have arrived, but they are delivered asynchronously 1368 // The headers have already arrived.
1377 EXPECT_THAT(stream_->ReadResponseHeaders(callback_.callback()), 1369 EXPECT_THAT(stream_->ReadResponseHeaders(callback_.callback()), IsOk());
1378 IsError(ERR_IO_PENDING));
1379 EXPECT_THAT(callback_.WaitForResult(), IsOk());
1380 ASSERT_TRUE(response_.headers.get()); 1370 ASSERT_TRUE(response_.headers.get());
1381 EXPECT_EQ(200, response_.headers->response_code()); 1371 EXPECT_EQ(200, response_.headers->response_code());
1382 EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain")); 1372 EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain"));
1383 1373
1384 // Send the response body. 1374 // Send the response body.
1385 const char kResponseBody[] = "Hello world!"; 1375 const char kResponseBody[] = "Hello world!";
1386 ProcessPacket(ConstructServerDataPacket( 1376 ProcessPacket(ConstructServerDataPacket(
1387 3, false, kFin, response_data_.length(), kResponseBody)); 1377 3, false, kFin, response_data_.length(), kResponseBody));
1388 1378
1389 // The body has arrived, but it is delivered asynchronously 1379 // The body has arrived, but it is delivered asynchronously
(...skipping 30 matching lines...) Expand all
1420 request_.url = GURL("https://www.example.org/"); 1410 request_.url = GURL("https://www.example.org/");
1421 1411
1422 EXPECT_EQ(OK, 1412 EXPECT_EQ(OK,
1423 stream_->InitializeStream(&request_, DEFAULT_PRIORITY, 1413 stream_->InitializeStream(&request_, DEFAULT_PRIORITY,
1424 net_log_.bound(), callback_.callback())); 1414 net_log_.bound(), callback_.callback()));
1425 EXPECT_EQ(OK, 1415 EXPECT_EQ(OK,
1426 stream_->SendRequest(headers_, &response_, callback_.callback())); 1416 stream_->SendRequest(headers_, &response_, callback_.callback()));
1427 1417
1428 // Ack the request. 1418 // Ack the request.
1429 ProcessPacket(ConstructServerAckPacket(1, 0, 0, 0)); 1419 ProcessPacket(ConstructServerAckPacket(1, 0, 0, 0));
1430 EXPECT_THAT(stream_->ReadResponseHeaders(callback_.callback()), 1420 EXPECT_THAT(stream_->ReadResponseHeaders(
1421 base::Bind(&QuicHttpStreamTest::CloseStream,
1422 base::Unretained(this), stream_.get())),
1431 IsError(ERR_IO_PENDING)); 1423 IsError(ERR_IO_PENDING));
1432 1424
1433 // Send the response with a body. 1425 // Send the response with a body.
1434 SetResponse("404 OK", "hello world!"); 1426 SetResponse("404 OK", "hello world!");
1435 // In the course of processing this packet, the QuicHttpStream close itself. 1427 // In the course of processing this packet, the QuicHttpStream close itself.
xunjieli 2017/05/10 18:58:08 This test is no longer testing what it claims to d
Ryan Hamilton 2017/05/10 19:33:46 The test says that the QuicHttpStream will be clos
xunjieli 2017/05/10 19:46:58 Acknowledged. The comment that confused me is line
Ryan Hamilton 2017/05/10 19:57:55 Ah good point. Yeah, that's confusing. Done.
1436 ProcessPacket(ConstructResponseHeadersPacket(2, kFin, nullptr)); 1428 ProcessPacket(ConstructResponseHeadersPacket(2, kFin, nullptr));
1437 1429
1438 base::RunLoop().RunUntilIdle(); 1430 base::RunLoop().RunUntilIdle();
1439 1431
1440 EXPECT_TRUE(AtEof()); 1432 EXPECT_TRUE(AtEof());
1441 1433
1442 // QuicHttpStream::GetTotalSent/ReceivedBytes currently only includes the 1434 // QuicHttpStream::GetTotalSent/ReceivedBytes currently only includes the
1443 // headers and payload. 1435 // headers and payload.
1444 EXPECT_EQ(static_cast<int64_t>(spdy_request_headers_frame_length), 1436 EXPECT_EQ(static_cast<int64_t>(spdy_request_headers_frame_length),
1445 stream_->GetTotalSentBytes()); 1437 stream_->GetTotalSentBytes());
1446 // Zero since the stream is closed before processing the headers. 1438 // Zero since the stream is closed before processing the headers.
1447 EXPECT_EQ(0, stream_->GetTotalReceivedBytes()); 1439 EXPECT_EQ(31, stream_->GetTotalReceivedBytes());
1448 } 1440 }
1449 1441
1450 TEST_P(QuicHttpStreamTest, Priority) { 1442 TEST_P(QuicHttpStreamTest, Priority) {
1451 SetRequest("GET", "/", MEDIUM); 1443 SetRequest("GET", "/", MEDIUM);
1452 size_t spdy_request_headers_frame_length; 1444 size_t spdy_request_headers_frame_length;
1453 QuicStreamOffset header_stream_offset = 0; 1445 QuicStreamOffset header_stream_offset = 0;
1454 AddWrite(ConstructInitialSettingsPacket(&header_stream_offset)); 1446 AddWrite(ConstructInitialSettingsPacket(&header_stream_offset));
1455 AddWrite(InnerConstructRequestHeadersPacket( 1447 AddWrite(InnerConstructRequestHeadersPacket(
1456 2, GetNthClientInitiatedStreamId(0), kIncludeVersion, kFin, MEDIUM, 1448 2, GetNthClientInitiatedStreamId(0), kIncludeVersion, kFin, MEDIUM,
1457 &spdy_request_headers_frame_length, &header_stream_offset)); 1449 &spdy_request_headers_frame_length, &header_stream_offset));
(...skipping 15 matching lines...) Expand all
1473 1465
1474 EXPECT_EQ(OK, 1466 EXPECT_EQ(OK,
1475 stream_->SendRequest(headers_, &response_, callback_.callback())); 1467 stream_->SendRequest(headers_, &response_, callback_.callback()));
1476 1468
1477 // Check that priority has now dropped back to MEDIUM. 1469 // Check that priority has now dropped back to MEDIUM.
1478 DCHECK_EQ(MEDIUM, 1470 DCHECK_EQ(MEDIUM,
1479 ConvertQuicPriorityToRequestPriority(reliable_stream->priority())); 1471 ConvertQuicPriorityToRequestPriority(reliable_stream->priority()));
1480 1472
1481 // Ack the request. 1473 // Ack the request.
1482 ProcessPacket(ConstructServerAckPacket(1, 0, 0, 0)); 1474 ProcessPacket(ConstructServerAckPacket(1, 0, 0, 0));
1483 EXPECT_THAT(stream_->ReadResponseHeaders(callback_.callback()), 1475 EXPECT_THAT(stream_->ReadResponseHeaders(
1476 base::Bind(&QuicHttpStreamTest::CloseStream,
xunjieli 2017/05/10 18:58:08 This test doesn't need the CloseStream/"Close earl
Ryan Hamilton 2017/05/10 19:33:46 Actually the test does rely on the stream closing
1477 base::Unretained(this), stream_.get())),
1484 IsError(ERR_IO_PENDING)); 1478 IsError(ERR_IO_PENDING));
1485 1479
1486 // Send the response with a body. 1480 // Send the response with a body.
1487 SetResponse("404 OK", "hello world!"); 1481 SetResponse("404 OK", "hello world!");
1488 // In the course of processing this packet, the QuicHttpStream close itself. 1482 // In the course of processing this packet, the QuicHttpStream close itself.
1489 ProcessPacket(ConstructResponseHeadersPacket(2, kFin, nullptr)); 1483 ProcessPacket(ConstructResponseHeadersPacket(2, kFin, nullptr));
1490 1484
1491 base::RunLoop().RunUntilIdle(); 1485 base::RunLoop().RunUntilIdle();
1492 1486
1493 EXPECT_TRUE(AtEof()); 1487 EXPECT_TRUE(AtEof());
1494 1488
1495 // QuicHttpStream::GetTotalSent/ReceivedBytes currently only includes the 1489 // QuicHttpStream::GetTotalSent/ReceivedBytes currently only includes the
1496 // headers and payload. 1490 // headers and payload.
1497 EXPECT_EQ(static_cast<int64_t>(spdy_request_headers_frame_length), 1491 EXPECT_EQ(static_cast<int64_t>(spdy_request_headers_frame_length),
1498 stream_->GetTotalSentBytes()); 1492 stream_->GetTotalSentBytes());
1499 // Zero since the stream is closed before processing the headers. 1493 // Zero since the stream is closed before processing the headers.
xunjieli 2017/05/10 18:58:08 The comment is no longer accurate. Could you updat
Ryan Hamilton 2017/05/10 19:33:46 Done.
1500 EXPECT_EQ(0, stream_->GetTotalReceivedBytes()); 1494 EXPECT_EQ(31, stream_->GetTotalReceivedBytes());
xunjieli 2017/05/10 18:58:08 Can we get "31" from ConstructResponseHeadersPacke
Ryan Hamilton 2017/05/10 19:33:46 Done.
1501 } 1495 }
1502 1496
1503 // Regression test for http://crbug.com/294870 1497 // Regression test for http://crbug.com/294870
1504 TEST_P(QuicHttpStreamTest, CheckPriorityWithNoDelegate) { 1498 TEST_P(QuicHttpStreamTest, CheckPriorityWithNoDelegate) {
1505 SetRequest("GET", "/", MEDIUM); 1499 SetRequest("GET", "/", MEDIUM);
1506 use_closing_stream_ = true; 1500 use_closing_stream_ = true;
1507 QuicStreamOffset header_stream_offset = 0; 1501 QuicStreamOffset header_stream_offset = 0;
1508 AddWrite(ConstructInitialSettingsPacket(&header_stream_offset)); 1502 AddWrite(ConstructInitialSettingsPacket(&header_stream_offset));
1509 AddWrite(ConstructClientRstStreamPacket(2)); 1503 AddWrite(ConstructClientRstStreamPacket(2));
1510 1504
(...skipping 660 matching lines...) Expand 10 before | Expand all | Expand 10 after
2171 EXPECT_TRUE(AtEof()); 2165 EXPECT_TRUE(AtEof());
2172 2166
2173 // QuicHttpStream::GetTotalSent/ReceivedBytes includes only headers. 2167 // QuicHttpStream::GetTotalSent/ReceivedBytes includes only headers.
2174 EXPECT_EQ(static_cast<int64_t>(spdy_request_headers_frame_length), 2168 EXPECT_EQ(static_cast<int64_t>(spdy_request_headers_frame_length),
2175 stream_->GetTotalSentBytes()); 2169 stream_->GetTotalSentBytes());
2176 EXPECT_EQ(0, stream_->GetTotalReceivedBytes()); 2170 EXPECT_EQ(0, stream_->GetTotalReceivedBytes());
2177 } 2171 }
2178 2172
2179 } // namespace test 2173 } // namespace test
2180 } // namespace net 2174 } // namespace net
OLDNEW
« net/quic/chromium/quic_chromium_client_stream.cc ('K') | « 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