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

Side by Side Diff: net/http/bidirectional_stream_unittest.cc

Issue 1817583002: Process Alternative Service headers in net::BidirectionalStream (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@toggle2
Patch Set: Address comments and rebased Created 4 years, 9 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/http/bidirectional_stream.cc ('k') | net/http/http_network_transaction.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/http/bidirectional_stream.h" 5 #include "net/http/bidirectional_stream.h"
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
11 #include "base/strings/string_piece.h" 11 #include "base/strings/string_piece.h"
12 #include "base/time/time.h" 12 #include "base/time/time.h"
13 #include "base/timer/mock_timer.h" 13 #include "base/timer/mock_timer.h"
14 #include "net/base/net_errors.h" 14 #include "net/base/net_errors.h"
15 #include "net/base/test_data_directory.h" 15 #include "net/base/test_data_directory.h"
16 #include "net/http/bidirectional_stream_request_info.h" 16 #include "net/http/bidirectional_stream_request_info.h"
17 #include "net/http/http_network_session.h" 17 #include "net/http/http_network_session.h"
18 #include "net/http/http_response_headers.h" 18 #include "net/http/http_response_headers.h"
19 #include "net/http/http_server_properties.h"
19 #include "net/log/net_log.h" 20 #include "net/log/net_log.h"
20 #include "net/socket/socket_test_util.h" 21 #include "net/socket/socket_test_util.h"
21 #include "net/spdy/spdy_session.h" 22 #include "net/spdy/spdy_session.h"
22 #include "net/spdy/spdy_test_util_common.h" 23 #include "net/spdy/spdy_test_util_common.h"
23 #include "net/test/cert_test_util.h" 24 #include "net/test/cert_test_util.h"
24 #include "net/url_request/url_request_test_util.h" 25 #include "net/url_request/url_request_test_util.h"
25 #include "testing/gtest/include/gtest/gtest.h" 26 #include "testing/gtest/include/gtest/gtest.h"
26 27
27 namespace net { 28 namespace net {
28 29
(...skipping 1159 matching lines...) Expand 10 before | Expand all | Expand 10 after
1188 EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, delegate->error()); 1189 EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, delegate->error());
1189 1190
1190 // If stream is destroyed, do not call into stream. 1191 // If stream is destroyed, do not call into stream.
1191 if (!GetParam()) 1192 if (!GetParam())
1192 return; 1193 return;
1193 EXPECT_EQ(0, delegate->GetTotalSentBytes()); 1194 EXPECT_EQ(0, delegate->GetTotalSentBytes());
1194 EXPECT_EQ(0, delegate->GetTotalReceivedBytes()); 1195 EXPECT_EQ(0, delegate->GetTotalReceivedBytes());
1195 EXPECT_EQ(kProtoUnknown, delegate->GetProtocol()); 1196 EXPECT_EQ(kProtoUnknown, delegate->GetProtocol());
1196 } 1197 }
1197 1198
1199 TEST_F(BidirectionalStreamTest, TestHonorAlternativeServiceHeader) {
1200 scoped_ptr<SpdyFrame> req(
1201 spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST));
1202 // Empty DATA frame with an END_STREAM flag.
1203 scoped_ptr<SpdyFrame> end_stream(
1204 spdy_util_.ConstructSpdyBodyFrame(1, nullptr, 0, true));
1205
1206 MockWrite writes[] = {CreateMockWrite(*req.get(), 0)};
1207
1208 std::string alt_svc_header_value = AlternateProtocolToString(QUIC);
1209 alt_svc_header_value.append("=\"www.example.org:443\"");
1210 const char* const kExtraResponseHeaders[] = {"alt-svc",
1211 alt_svc_header_value.c_str()};
1212
1213 scoped_ptr<SpdyFrame> resp(
1214 spdy_util_.ConstructSpdyGetSynReply(kExtraResponseHeaders, 1, 1));
1215 scoped_ptr<SpdyFrame> body_frame(spdy_util_.ConstructSpdyBodyFrame(1, true));
1216
1217 MockRead reads[] = {
1218 CreateMockRead(*resp, 1), CreateMockRead(*body_frame, 2),
1219 MockRead(SYNCHRONOUS, 0, 3),
1220 };
1221
1222 HostPortPair host_port_pair("www.example.org", 443);
1223 SpdySessionKey key(host_port_pair, ProxyServer::Direct(),
1224 PRIVACY_MODE_DISABLED);
1225 session_deps_.parse_alternative_services = true;
1226 // Enable QUIC so that the alternative service header can be added to
1227 // HttpServerProperties.
1228 session_deps_.enable_quic = true;
1229 InitSession(reads, arraysize(reads), writes, arraysize(writes), key);
1230
1231 scoped_ptr<BidirectionalStreamRequestInfo> request_info(
1232 new BidirectionalStreamRequestInfo);
1233 request_info->method = "GET";
1234 request_info->url = GURL("https://www.example.org/");
1235 request_info->priority = LOWEST;
1236 request_info->end_stream_on_headers = true;
1237
1238 scoped_refptr<IOBuffer> read_buffer(new IOBuffer(kReadBufferSize));
1239 MockTimer* timer = new MockTimer();
1240 scoped_ptr<TestDelegateBase> delegate(new TestDelegateBase(
1241 read_buffer.get(), kReadBufferSize, make_scoped_ptr(timer)));
1242 delegate->SetRunUntilCompletion(true);
1243 delegate->Start(std::move(request_info), http_session_.get());
1244
1245 const SpdyHeaderBlock response_headers = delegate->response_headers();
1246 EXPECT_EQ("200", response_headers.find(":status")->second);
1247 EXPECT_EQ(alt_svc_header_value, response_headers.find("alt-svc")->second);
1248 EXPECT_EQ(0, delegate->on_data_sent_count());
1249 EXPECT_EQ(kProtoHTTP2, delegate->GetProtocol());
1250 EXPECT_EQ(kUploadData, delegate->data_received());
1251 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)),
1252 delegate->GetTotalSentBytes());
1253 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)),
1254 delegate->GetTotalReceivedBytes());
1255
1256 AlternativeServiceVector alternative_service_vector =
1257 http_session_->http_server_properties()->GetAlternativeServices(
1258 host_port_pair);
1259 ASSERT_EQ(1u, alternative_service_vector.size());
1260 EXPECT_EQ(AlternateProtocolFromNextProto(kProtoQUIC1SPDY3),
1261 alternative_service_vector[0].protocol);
1262 EXPECT_EQ("www.example.org", alternative_service_vector[0].host);
1263 EXPECT_EQ(443, alternative_service_vector[0].port);
1264 }
1265
1198 } // namespace net 1266 } // namespace net
OLDNEW
« no previous file with comments | « net/http/bidirectional_stream.cc ('k') | net/http/http_network_transaction.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698