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

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

Issue 2351513002: net: rename BoundNetLog to NetLogWithSource (Closed)
Patch Set: one more fix, content bound_net_log_ Created 4 years, 3 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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 enum class FailureMode { SYNC, ASYNC }; 120 enum class FailureMode { SYNC, ASYNC };
121 121
122 explicit ReadErrorUploadDataStream(FailureMode mode) 122 explicit ReadErrorUploadDataStream(FailureMode mode)
123 : UploadDataStream(true, 0), async_(mode), weak_factory_(this) {} 123 : UploadDataStream(true, 0), async_(mode), weak_factory_(this) {}
124 ~ReadErrorUploadDataStream() override {} 124 ~ReadErrorUploadDataStream() override {}
125 125
126 private: 126 private:
127 void CompleteRead() { UploadDataStream::OnReadCompleted(ERR_FAILED); } 127 void CompleteRead() { UploadDataStream::OnReadCompleted(ERR_FAILED); }
128 128
129 // UploadDataStream implementation: 129 // UploadDataStream implementation:
130 int InitInternal(const BoundNetLog& net_log) override { return OK; } 130 int InitInternal(const NetLogWithSource& net_log) override { return OK; }
131 131
132 int ReadInternal(IOBuffer* buf, int buf_len) override { 132 int ReadInternal(IOBuffer* buf, int buf_len) override {
133 if (async_ == FailureMode::ASYNC) { 133 if (async_ == FailureMode::ASYNC) {
134 base::ThreadTaskRunnerHandle::Get()->PostTask( 134 base::ThreadTaskRunnerHandle::Get()->PostTask(
135 FROM_HERE, base::Bind(&ReadErrorUploadDataStream::CompleteRead, 135 FROM_HERE, base::Bind(&ReadErrorUploadDataStream::CompleteRead,
136 weak_factory_.GetWeakPtr())); 136 weak_factory_.GetWeakPtr()));
137 return ERR_IO_PENDING; 137 return ERR_IO_PENDING;
138 } 138 }
139 return ERR_FAILED; 139 return ERR_FAILED;
140 } 140 }
(...skipping 922 matching lines...) Expand 10 before | Expand all | Expand 10 after
1063 1063
1064 Initialize(); 1064 Initialize();
1065 1065
1066 std::vector<std::unique_ptr<UploadElementReader>> element_readers; 1066 std::vector<std::unique_ptr<UploadElementReader>> element_readers;
1067 element_readers.push_back(base::MakeUnique<UploadBytesElementReader>( 1067 element_readers.push_back(base::MakeUnique<UploadBytesElementReader>(
1068 kUploadData, strlen(kUploadData))); 1068 kUploadData, strlen(kUploadData)));
1069 ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); 1069 ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0);
1070 request_.method = "POST"; 1070 request_.method = "POST";
1071 request_.url = GURL("http://www.example.org/"); 1071 request_.url = GURL("http://www.example.org/");
1072 request_.upload_data_stream = &upload_data_stream; 1072 request_.upload_data_stream = &upload_data_stream;
1073 ASSERT_THAT( 1073 ASSERT_THAT(request_.upload_data_stream->Init(CompletionCallback(),
1074 request_.upload_data_stream->Init(CompletionCallback(), BoundNetLog()), 1074 NetLogWithSource()),
1075 IsOk()); 1075 IsOk());
1076 1076
1077 EXPECT_EQ(OK, 1077 EXPECT_EQ(OK,
1078 stream_->InitializeStream(&request_, DEFAULT_PRIORITY, 1078 stream_->InitializeStream(&request_, DEFAULT_PRIORITY,
1079 net_log_.bound(), callback_.callback())); 1079 net_log_.bound(), callback_.callback()));
1080 EXPECT_EQ(OK, 1080 EXPECT_EQ(OK,
1081 stream_->SendRequest(headers_, &response_, callback_.callback())); 1081 stream_->SendRequest(headers_, &response_, callback_.callback()));
1082 1082
1083 // Ack both packets in the request. 1083 // Ack both packets in the request.
1084 ProcessPacket(ConstructServerAckPacket(1, 0, 0)); 1084 ProcessPacket(ConstructServerAckPacket(1, 0, 0));
1085 1085
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1131 AddWrite(ConstructClientAckPacket(4, 3, 1)); 1131 AddWrite(ConstructClientAckPacket(4, 3, 1));
1132 Initialize(); 1132 Initialize();
1133 1133
1134 ChunkedUploadDataStream upload_data_stream(0); 1134 ChunkedUploadDataStream upload_data_stream(0);
1135 upload_data_stream.AppendData(kUploadData, chunk_size, false); 1135 upload_data_stream.AppendData(kUploadData, chunk_size, false);
1136 1136
1137 request_.method = "POST"; 1137 request_.method = "POST";
1138 request_.url = GURL("http://www.example.org/"); 1138 request_.url = GURL("http://www.example.org/");
1139 request_.upload_data_stream = &upload_data_stream; 1139 request_.upload_data_stream = &upload_data_stream;
1140 ASSERT_EQ(OK, request_.upload_data_stream->Init( 1140 ASSERT_EQ(OK, request_.upload_data_stream->Init(
1141 TestCompletionCallback().callback(), BoundNetLog())); 1141 TestCompletionCallback().callback(), NetLogWithSource()));
1142 1142
1143 ASSERT_EQ(OK, 1143 ASSERT_EQ(OK,
1144 stream_->InitializeStream(&request_, DEFAULT_PRIORITY, 1144 stream_->InitializeStream(&request_, DEFAULT_PRIORITY,
1145 net_log_.bound(), callback_.callback())); 1145 net_log_.bound(), callback_.callback()));
1146 ASSERT_EQ(ERR_IO_PENDING, 1146 ASSERT_EQ(ERR_IO_PENDING,
1147 stream_->SendRequest(headers_, &response_, callback_.callback())); 1147 stream_->SendRequest(headers_, &response_, callback_.callback()));
1148 1148
1149 upload_data_stream.AppendData(kUploadData, chunk_size, true); 1149 upload_data_stream.AppendData(kUploadData, chunk_size, true);
1150 EXPECT_THAT(callback_.WaitForResult(), IsOk()); 1150 EXPECT_THAT(callback_.WaitForResult(), IsOk());
1151 1151
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1201 AddWrite(ConstructClientAckPacket(4, 3, 1)); 1201 AddWrite(ConstructClientAckPacket(4, 3, 1));
1202 Initialize(); 1202 Initialize();
1203 1203
1204 ChunkedUploadDataStream upload_data_stream(0); 1204 ChunkedUploadDataStream upload_data_stream(0);
1205 upload_data_stream.AppendData(kUploadData, chunk_size, false); 1205 upload_data_stream.AppendData(kUploadData, chunk_size, false);
1206 1206
1207 request_.method = "POST"; 1207 request_.method = "POST";
1208 request_.url = GURL("http://www.example.org/"); 1208 request_.url = GURL("http://www.example.org/");
1209 request_.upload_data_stream = &upload_data_stream; 1209 request_.upload_data_stream = &upload_data_stream;
1210 ASSERT_EQ(OK, request_.upload_data_stream->Init( 1210 ASSERT_EQ(OK, request_.upload_data_stream->Init(
1211 TestCompletionCallback().callback(), BoundNetLog())); 1211 TestCompletionCallback().callback(), NetLogWithSource()));
1212 1212
1213 ASSERT_EQ(OK, 1213 ASSERT_EQ(OK,
1214 stream_->InitializeStream(&request_, DEFAULT_PRIORITY, 1214 stream_->InitializeStream(&request_, DEFAULT_PRIORITY,
1215 net_log_.bound(), callback_.callback())); 1215 net_log_.bound(), callback_.callback()));
1216 ASSERT_EQ(ERR_IO_PENDING, 1216 ASSERT_EQ(ERR_IO_PENDING,
1217 stream_->SendRequest(headers_, &response_, callback_.callback())); 1217 stream_->SendRequest(headers_, &response_, callback_.callback()));
1218 1218
1219 upload_data_stream.AppendData(nullptr, 0, true); 1219 upload_data_stream.AppendData(nullptr, 0, true);
1220 EXPECT_THAT(callback_.WaitForResult(), IsOk()); 1220 EXPECT_THAT(callback_.WaitForResult(), IsOk());
1221 1221
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1265 AddWrite(ConstructClientDataPacket(2, kIncludeVersion, kFin, 0, "")); 1265 AddWrite(ConstructClientDataPacket(2, kIncludeVersion, kFin, 0, ""));
1266 AddWrite(ConstructClientAckPacket(3, 3, 1)); 1266 AddWrite(ConstructClientAckPacket(3, 3, 1));
1267 Initialize(); 1267 Initialize();
1268 1268
1269 ChunkedUploadDataStream upload_data_stream(0); 1269 ChunkedUploadDataStream upload_data_stream(0);
1270 1270
1271 request_.method = "POST"; 1271 request_.method = "POST";
1272 request_.url = GURL("http://www.example.org/"); 1272 request_.url = GURL("http://www.example.org/");
1273 request_.upload_data_stream = &upload_data_stream; 1273 request_.upload_data_stream = &upload_data_stream;
1274 ASSERT_EQ(OK, request_.upload_data_stream->Init( 1274 ASSERT_EQ(OK, request_.upload_data_stream->Init(
1275 TestCompletionCallback().callback(), BoundNetLog())); 1275 TestCompletionCallback().callback(), NetLogWithSource()));
1276 1276
1277 ASSERT_EQ(OK, 1277 ASSERT_EQ(OK,
1278 stream_->InitializeStream(&request_, DEFAULT_PRIORITY, 1278 stream_->InitializeStream(&request_, DEFAULT_PRIORITY,
1279 net_log_.bound(), callback_.callback())); 1279 net_log_.bound(), callback_.callback()));
1280 ASSERT_EQ(ERR_IO_PENDING, 1280 ASSERT_EQ(ERR_IO_PENDING,
1281 stream_->SendRequest(headers_, &response_, callback_.callback())); 1281 stream_->SendRequest(headers_, &response_, callback_.callback()));
1282 1282
1283 upload_data_stream.AppendData(nullptr, 0, true); 1283 upload_data_stream.AppendData(nullptr, 0, true);
1284 EXPECT_THAT(callback_.WaitForResult(), IsOk()); 1284 EXPECT_THAT(callback_.WaitForResult(), IsOk());
1285 1285
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
1455 // the session. 1455 // the session.
1456 AddWrite(SYNCHRONOUS, ERR_FAILED); 1456 AddWrite(SYNCHRONOUS, ERR_FAILED);
1457 Initialize(); 1457 Initialize();
1458 1458
1459 ChunkedUploadDataStream upload_data_stream(0); 1459 ChunkedUploadDataStream upload_data_stream(0);
1460 1460
1461 request_.method = "POST"; 1461 request_.method = "POST";
1462 request_.url = GURL("http://www.example.org/"); 1462 request_.url = GURL("http://www.example.org/");
1463 request_.upload_data_stream = &upload_data_stream; 1463 request_.upload_data_stream = &upload_data_stream;
1464 ASSERT_EQ(OK, request_.upload_data_stream->Init( 1464 ASSERT_EQ(OK, request_.upload_data_stream->Init(
1465 TestCompletionCallback().callback(), BoundNetLog())); 1465 TestCompletionCallback().callback(), NetLogWithSource()));
1466 1466
1467 size_t chunk_size = strlen(kUploadData); 1467 size_t chunk_size = strlen(kUploadData);
1468 upload_data_stream.AppendData(kUploadData, chunk_size, false); 1468 upload_data_stream.AppendData(kUploadData, chunk_size, false);
1469 ASSERT_EQ(OK, 1469 ASSERT_EQ(OK,
1470 stream_->InitializeStream(&request_, DEFAULT_PRIORITY, 1470 stream_->InitializeStream(&request_, DEFAULT_PRIORITY,
1471 net_log_.bound(), callback_.callback())); 1471 net_log_.bound(), callback_.callback()));
1472 QuicHttpStream* stream = stream_.get(); 1472 QuicHttpStream* stream = stream_.get();
1473 DeleteStreamCallback delete_stream_callback(std::move(stream_)); 1473 DeleteStreamCallback delete_stream_callback(std::move(stream_));
1474 // SendRequest() completes asynchronously after the final chunk is added. 1474 // SendRequest() completes asynchronously after the final chunk is added.
1475 ASSERT_EQ(ERR_IO_PENDING, 1475 ASSERT_EQ(ERR_IO_PENDING,
1476 stream->SendRequest(headers_, &response_, callback_.callback())); 1476 stream->SendRequest(headers_, &response_, callback_.callback()));
1477 upload_data_stream.AppendData(kUploadData, chunk_size, true); 1477 upload_data_stream.AppendData(kUploadData, chunk_size, true);
1478 int rv = callback_.WaitForResult(); 1478 int rv = callback_.WaitForResult();
1479 EXPECT_EQ(ERR_QUIC_PROTOCOL_ERROR, rv); 1479 EXPECT_EQ(ERR_QUIC_PROTOCOL_ERROR, rv);
1480 } 1480 }
1481 1481
1482 TEST_P(QuicHttpStreamTest, SessionClosedBeforeSendHeadersComplete) { 1482 TEST_P(QuicHttpStreamTest, SessionClosedBeforeSendHeadersComplete) {
1483 SetRequest("POST", "/", DEFAULT_PRIORITY); 1483 SetRequest("POST", "/", DEFAULT_PRIORITY);
1484 AddWrite(SYNCHRONOUS, ERR_FAILED); 1484 AddWrite(SYNCHRONOUS, ERR_FAILED);
1485 Initialize(); 1485 Initialize();
1486 1486
1487 ChunkedUploadDataStream upload_data_stream(0); 1487 ChunkedUploadDataStream upload_data_stream(0);
1488 1488
1489 request_.method = "POST"; 1489 request_.method = "POST";
1490 request_.url = GURL("http://www.example.org/"); 1490 request_.url = GURL("http://www.example.org/");
1491 request_.upload_data_stream = &upload_data_stream; 1491 request_.upload_data_stream = &upload_data_stream;
1492 ASSERT_EQ(OK, request_.upload_data_stream->Init( 1492 ASSERT_EQ(OK, request_.upload_data_stream->Init(
1493 TestCompletionCallback().callback(), BoundNetLog())); 1493 TestCompletionCallback().callback(), NetLogWithSource()));
1494 1494
1495 ASSERT_EQ(OK, 1495 ASSERT_EQ(OK,
1496 stream_->InitializeStream(&request_, DEFAULT_PRIORITY, 1496 stream_->InitializeStream(&request_, DEFAULT_PRIORITY,
1497 net_log_.bound(), callback_.callback())); 1497 net_log_.bound(), callback_.callback()));
1498 ASSERT_EQ(ERR_QUIC_PROTOCOL_ERROR, 1498 ASSERT_EQ(ERR_QUIC_PROTOCOL_ERROR,
1499 stream_->SendRequest(headers_, &response_, callback_.callback())); 1499 stream_->SendRequest(headers_, &response_, callback_.callback()));
1500 } 1500 }
1501 1501
1502 TEST_P(QuicHttpStreamTest, SessionClosedBeforeSendBodyComplete) { 1502 TEST_P(QuicHttpStreamTest, SessionClosedBeforeSendBodyComplete) {
1503 SetRequest("POST", "/", DEFAULT_PRIORITY); 1503 SetRequest("POST", "/", DEFAULT_PRIORITY);
1504 size_t spdy_request_headers_frame_length; 1504 size_t spdy_request_headers_frame_length;
1505 AddWrite(ConstructRequestHeadersPacket(1, !kFin, DEFAULT_PRIORITY, 1505 AddWrite(ConstructRequestHeadersPacket(1, !kFin, DEFAULT_PRIORITY,
1506 &spdy_request_headers_frame_length)); 1506 &spdy_request_headers_frame_length));
1507 AddWrite(SYNCHRONOUS, ERR_FAILED); 1507 AddWrite(SYNCHRONOUS, ERR_FAILED);
1508 Initialize(); 1508 Initialize();
1509 1509
1510 ChunkedUploadDataStream upload_data_stream(0); 1510 ChunkedUploadDataStream upload_data_stream(0);
1511 size_t chunk_size = strlen(kUploadData); 1511 size_t chunk_size = strlen(kUploadData);
1512 upload_data_stream.AppendData(kUploadData, chunk_size, false); 1512 upload_data_stream.AppendData(kUploadData, chunk_size, false);
1513 1513
1514 request_.method = "POST"; 1514 request_.method = "POST";
1515 request_.url = GURL("http://www.example.org/"); 1515 request_.url = GURL("http://www.example.org/");
1516 request_.upload_data_stream = &upload_data_stream; 1516 request_.upload_data_stream = &upload_data_stream;
1517 ASSERT_EQ(OK, request_.upload_data_stream->Init( 1517 ASSERT_EQ(OK, request_.upload_data_stream->Init(
1518 TestCompletionCallback().callback(), BoundNetLog())); 1518 TestCompletionCallback().callback(), NetLogWithSource()));
1519 1519
1520 ASSERT_EQ(OK, 1520 ASSERT_EQ(OK,
1521 stream_->InitializeStream(&request_, DEFAULT_PRIORITY, 1521 stream_->InitializeStream(&request_, DEFAULT_PRIORITY,
1522 net_log_.bound(), callback_.callback())); 1522 net_log_.bound(), callback_.callback()));
1523 ASSERT_EQ(ERR_QUIC_PROTOCOL_ERROR, 1523 ASSERT_EQ(ERR_QUIC_PROTOCOL_ERROR,
1524 stream_->SendRequest(headers_, &response_, callback_.callback())); 1524 stream_->SendRequest(headers_, &response_, callback_.callback()));
1525 } 1525 }
1526 1526
1527 TEST_P(QuicHttpStreamTest, ServerPushGetRequest) { 1527 TEST_P(QuicHttpStreamTest, ServerPushGetRequest) {
1528 SetRequest("GET", "/", DEFAULT_PRIORITY); 1528 SetRequest("GET", "/", DEFAULT_PRIORITY);
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after
2006 AddWrite(ConstructClientRstStreamErrorPacket(2, kIncludeVersion)); 2006 AddWrite(ConstructClientRstStreamErrorPacket(2, kIncludeVersion));
2007 2007
2008 Initialize(); 2008 Initialize();
2009 2009
2010 ReadErrorUploadDataStream upload_data_stream( 2010 ReadErrorUploadDataStream upload_data_stream(
2011 ReadErrorUploadDataStream::FailureMode::SYNC); 2011 ReadErrorUploadDataStream::FailureMode::SYNC);
2012 request_.method = "POST"; 2012 request_.method = "POST";
2013 request_.url = GURL("http://www.example.org/"); 2013 request_.url = GURL("http://www.example.org/");
2014 request_.upload_data_stream = &upload_data_stream; 2014 request_.upload_data_stream = &upload_data_stream;
2015 ASSERT_EQ(OK, request_.upload_data_stream->Init( 2015 ASSERT_EQ(OK, request_.upload_data_stream->Init(
2016 TestCompletionCallback().callback(), BoundNetLog())); 2016 TestCompletionCallback().callback(), NetLogWithSource()));
2017 2017
2018 EXPECT_EQ(OK, 2018 EXPECT_EQ(OK,
2019 stream_->InitializeStream(&request_, DEFAULT_PRIORITY, 2019 stream_->InitializeStream(&request_, DEFAULT_PRIORITY,
2020 net_log_.bound(), callback_.callback())); 2020 net_log_.bound(), callback_.callback()));
2021 2021
2022 int result = stream_->SendRequest(headers_, &response_, callback_.callback()); 2022 int result = stream_->SendRequest(headers_, &response_, callback_.callback());
2023 EXPECT_THAT(result, IsError(ERR_FAILED)); 2023 EXPECT_THAT(result, IsError(ERR_FAILED));
2024 2024
2025 EXPECT_TRUE(AtEof()); 2025 EXPECT_TRUE(AtEof());
2026 2026
(...skipping 11 matching lines...) Expand all
2038 AddWrite(ConstructClientRstStreamErrorPacket(2, !kIncludeVersion)); 2038 AddWrite(ConstructClientRstStreamErrorPacket(2, !kIncludeVersion));
2039 2039
2040 Initialize(); 2040 Initialize();
2041 2041
2042 ReadErrorUploadDataStream upload_data_stream( 2042 ReadErrorUploadDataStream upload_data_stream(
2043 ReadErrorUploadDataStream::FailureMode::ASYNC); 2043 ReadErrorUploadDataStream::FailureMode::ASYNC);
2044 request_.method = "POST"; 2044 request_.method = "POST";
2045 request_.url = GURL("http://www.example.org/"); 2045 request_.url = GURL("http://www.example.org/");
2046 request_.upload_data_stream = &upload_data_stream; 2046 request_.upload_data_stream = &upload_data_stream;
2047 ASSERT_EQ(OK, request_.upload_data_stream->Init( 2047 ASSERT_EQ(OK, request_.upload_data_stream->Init(
2048 TestCompletionCallback().callback(), BoundNetLog())); 2048 TestCompletionCallback().callback(), NetLogWithSource()));
2049 2049
2050 EXPECT_EQ(OK, 2050 EXPECT_EQ(OK,
2051 stream_->InitializeStream(&request_, DEFAULT_PRIORITY, 2051 stream_->InitializeStream(&request_, DEFAULT_PRIORITY,
2052 net_log_.bound(), callback_.callback())); 2052 net_log_.bound(), callback_.callback()));
2053 2053
2054 int result = stream_->SendRequest(headers_, &response_, callback_.callback()); 2054 int result = stream_->SendRequest(headers_, &response_, callback_.callback());
2055 2055
2056 ProcessPacket(ConstructServerAckPacket(1, 0, 0)); 2056 ProcessPacket(ConstructServerAckPacket(1, 0, 0));
2057 SetResponse("200 OK", string()); 2057 SetResponse("200 OK", string());
2058 2058
2059 EXPECT_THAT(result, IsError(ERR_IO_PENDING)); 2059 EXPECT_THAT(result, IsError(ERR_IO_PENDING));
2060 EXPECT_THAT(callback_.GetResult(result), IsError(ERR_FAILED)); 2060 EXPECT_THAT(callback_.GetResult(result), IsError(ERR_FAILED));
2061 2061
2062 EXPECT_TRUE(AtEof()); 2062 EXPECT_TRUE(AtEof());
2063 2063
2064 // QuicHttpStream::GetTotalSent/ReceivedBytes includes only headers. 2064 // QuicHttpStream::GetTotalSent/ReceivedBytes includes only headers.
2065 EXPECT_EQ(static_cast<int64_t>(spdy_request_headers_frame_length), 2065 EXPECT_EQ(static_cast<int64_t>(spdy_request_headers_frame_length),
2066 stream_->GetTotalSentBytes()); 2066 stream_->GetTotalSentBytes());
2067 EXPECT_EQ(0, stream_->GetTotalReceivedBytes()); 2067 EXPECT_EQ(0, stream_->GetTotalReceivedBytes());
2068 } 2068 }
2069 2069
2070 } // namespace test 2070 } // namespace test
2071 } // namespace net 2071 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698