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

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

Issue 1403643003: Network transaction test for "Alt-Svc: clear" header. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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 | « no previous file | 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/http_network_transaction.h" 5 #include "net/http/http_network_transaction.h"
6 6
7 #include <math.h> // ceil 7 #include <math.h> // ceil
8 #include <stdarg.h> 8 #include <stdarg.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
(...skipping 9443 matching lines...) Expand 10 before | Expand all | Expand 10 after
9454 9454
9455 alternative_service_vector = 9455 alternative_service_vector =
9456 http_server_properties.GetAlternativeServices(http_host_port_pair); 9456 http_server_properties.GetAlternativeServices(http_host_port_pair);
9457 ASSERT_EQ(1u, alternative_service_vector.size()); 9457 ASSERT_EQ(1u, alternative_service_vector.size());
9458 EXPECT_EQ(AlternateProtocolFromNextProto(GetParam()), 9458 EXPECT_EQ(AlternateProtocolFromNextProto(GetParam()),
9459 alternative_service_vector[0].protocol); 9459 alternative_service_vector[0].protocol);
9460 EXPECT_EQ("www.example.com", alternative_service_vector[0].host); 9460 EXPECT_EQ("www.example.com", alternative_service_vector[0].host);
9461 EXPECT_EQ(443, alternative_service_vector[0].port); 9461 EXPECT_EQ(443, alternative_service_vector[0].port);
9462 } 9462 }
9463 9463
9464 TEST_P(HttpNetworkTransactionTest, ClearAlternativeServices) {
9465 session_deps_.next_protos = SpdyNextProtos();
9466 session_deps_.use_alternative_services = true;
9467
9468 // Set an alternative service for origin.
9469 scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
9470 HttpServerProperties& http_server_properties =
9471 *session->http_server_properties();
9472 HostPortPair http_host_port_pair("www.example.org", 80);
9473 AlternativeService alternative_service(QUIC, "", 80);
9474 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1);
9475 http_server_properties.SetAlternativeService(
9476 http_host_port_pair, alternative_service, 1.0, expiration);
9477 AlternativeServiceVector alternative_service_vector =
9478 http_server_properties.GetAlternativeServices(http_host_port_pair);
9479 EXPECT_EQ(1u, alternative_service_vector.size());
9480
9481 // Send a clear header.
9482 MockRead data_reads[] = {
9483 MockRead("HTTP/1.1 200 OK\r\n"),
9484 MockRead("Alt-Svc: clear\r\n"),
9485 MockRead("\r\n"),
9486 MockRead("hello world"),
9487 MockRead(SYNCHRONOUS, OK),
9488 };
9489 StaticSocketDataProvider data(data_reads, arraysize(data_reads), nullptr, 0);
9490 session_deps_.socket_factory->AddSocketDataProvider(&data);
9491
9492 HttpRequestInfo request;
9493 request.method = "GET";
9494 request.url = GURL("http://www.example.org/");
9495 request.load_flags = 0;
9496
9497 TestCompletionCallback callback;
9498
9499 scoped_ptr<HttpTransaction> trans(
9500 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
9501
9502 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
9503 EXPECT_EQ(OK, callback.GetResult(rv));
9504
9505 const HttpResponseInfo* response = trans->GetResponseInfo();
9506 ASSERT_TRUE(response != nullptr);
9507 ASSERT_TRUE(response->headers.get() != nullptr);
9508 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
9509 EXPECT_FALSE(response->was_fetched_via_spdy);
9510 EXPECT_FALSE(response->was_npn_negotiated);
9511
9512 std::string response_data;
9513 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data));
9514 EXPECT_EQ("hello world", response_data);
9515
9516 alternative_service_vector =
9517 http_server_properties.GetAlternativeServices(http_host_port_pair);
9518 EXPECT_TRUE(alternative_service_vector.empty());
9519 }
9520
9464 // Alternative Service headers must be ignored when |use_alternative_services| 9521 // Alternative Service headers must be ignored when |use_alternative_services|
9465 // is false. 9522 // is false.
9466 TEST_P(HttpNetworkTransactionTest, DoNotHonorAlternativeServiceHeader) { 9523 TEST_P(HttpNetworkTransactionTest, DoNotHonorAlternativeServiceHeader) {
9467 session_deps_.next_protos = SpdyNextProtos(); 9524 session_deps_.next_protos = SpdyNextProtos();
9468 session_deps_.use_alternative_services = false; 9525 session_deps_.use_alternative_services = false;
9469 9526
9470 std::string alternative_service_http_header = 9527 std::string alternative_service_http_header =
9471 GetAlternativeServiceHttpHeader(); 9528 GetAlternativeServiceHttpHeader();
9472 9529
9473 MockRead data_reads[] = { 9530 MockRead data_reads[] = {
(...skipping 5835 matching lines...) Expand 10 before | Expand all | Expand 10 after
15309 std::string response_data; 15366 std::string response_data;
15310 EXPECT_EQ(OK, ReadTransaction(trans.get(), &response_data)); 15367 EXPECT_EQ(OK, ReadTransaction(trans.get(), &response_data));
15311 15368
15312 EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), 15369 EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)),
15313 trans->GetTotalSentBytes()); 15370 trans->GetTotalSentBytes());
15314 EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), 15371 EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)),
15315 trans->GetTotalReceivedBytes()); 15372 trans->GetTotalReceivedBytes());
15316 } 15373 }
15317 15374
15318 } // namespace net 15375 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698