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

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

Issue 377063002: Revert of Add a probability to Alternate-Protocol support. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « net/http/http_network_transaction.cc ('k') | net/http/http_server_properties.h » ('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 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 <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 7518 matching lines...) Expand 10 before | Expand all | Expand 10 after
7529 7529
7530 scoped_refptr<HttpNetworkSession> SetupSessionForGroupNameTests( 7530 scoped_refptr<HttpNetworkSession> SetupSessionForGroupNameTests(
7531 NextProto next_proto, 7531 NextProto next_proto,
7532 SpdySessionDependencies* session_deps_) { 7532 SpdySessionDependencies* session_deps_) {
7533 scoped_refptr<HttpNetworkSession> session(CreateSession(session_deps_)); 7533 scoped_refptr<HttpNetworkSession> session(CreateSession(session_deps_));
7534 7534
7535 base::WeakPtr<HttpServerProperties> http_server_properties = 7535 base::WeakPtr<HttpServerProperties> http_server_properties =
7536 session->http_server_properties(); 7536 session->http_server_properties();
7537 http_server_properties->SetAlternateProtocol( 7537 http_server_properties->SetAlternateProtocol(
7538 HostPortPair("host.with.alternate", 80), 443, 7538 HostPortPair("host.with.alternate", 80), 443,
7539 AlternateProtocolFromNextProto(next_proto), 1); 7539 AlternateProtocolFromNextProto(next_proto));
7540 7540
7541 return session; 7541 return session;
7542 } 7542 }
7543 7543
7544 int GroupNameTransactionHelper( 7544 int GroupNameTransactionHelper(
7545 const std::string& url, 7545 const std::string& url,
7546 const scoped_refptr<HttpNetworkSession>& session) { 7546 const scoped_refptr<HttpNetworkSession>& session) {
7547 HttpRequestInfo request; 7547 HttpRequestInfo request;
7548 request.method = "GET"; 7548 request.method = "GET";
7549 request.url = GURL(url); 7549 request.url = GURL(url);
(...skipping 891 matching lines...) Expand 10 before | Expand all | Expand 10 after
8441 ASSERT_TRUE(response->headers.get() != NULL); 8441 ASSERT_TRUE(response->headers.get() != NULL);
8442 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); 8442 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
8443 EXPECT_FALSE(response->was_fetched_via_spdy); 8443 EXPECT_FALSE(response->was_fetched_via_spdy);
8444 EXPECT_FALSE(response->was_npn_negotiated); 8444 EXPECT_FALSE(response->was_npn_negotiated);
8445 8445
8446 std::string response_data; 8446 std::string response_data;
8447 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); 8447 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data));
8448 EXPECT_EQ("hello world", response_data); 8448 EXPECT_EQ("hello world", response_data);
8449 8449
8450 ASSERT_TRUE(http_server_properties.HasAlternateProtocol(http_host_port_pair)); 8450 ASSERT_TRUE(http_server_properties.HasAlternateProtocol(http_host_port_pair));
8451 const AlternateProtocolInfo alternate = 8451 const PortAlternateProtocolPair alternate =
8452 http_server_properties.GetAlternateProtocol(http_host_port_pair); 8452 http_server_properties.GetAlternateProtocol(http_host_port_pair);
8453 AlternateProtocolInfo expected_alternate( 8453 PortAlternateProtocolPair expected_alternate;
8454 443, AlternateProtocolFromNextProto(GetParam()), 1); 8454 expected_alternate.port = 443;
8455 expected_alternate.protocol = AlternateProtocolFromNextProto(GetParam());
8455 EXPECT_TRUE(expected_alternate.Equals(alternate)); 8456 EXPECT_TRUE(expected_alternate.Equals(alternate));
8456 } 8457 }
8457 8458
8458 TEST_P(HttpNetworkTransactionTest, 8459 TEST_P(HttpNetworkTransactionTest,
8459 MarkBrokenAlternateProtocolAndFallback) { 8460 MarkBrokenAlternateProtocolAndFallback) {
8460 session_deps_.use_alternate_protocols = true; 8461 session_deps_.use_alternate_protocols = true;
8461 8462
8462 HttpRequestInfo request; 8463 HttpRequestInfo request;
8463 request.method = "GET"; 8464 request.method = "GET";
8464 request.url = GURL("http://www.google.com/"); 8465 request.url = GURL("http://www.google.com/");
(...skipping 15 matching lines...) Expand all
8480 8481
8481 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 8482 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
8482 8483
8483 base::WeakPtr<HttpServerProperties> http_server_properties = 8484 base::WeakPtr<HttpServerProperties> http_server_properties =
8484 session->http_server_properties(); 8485 session->http_server_properties();
8485 // Port must be < 1024, or the header will be ignored (since initial port was 8486 // Port must be < 1024, or the header will be ignored (since initial port was
8486 // port 80 (another restricted port). 8487 // port 80 (another restricted port).
8487 http_server_properties->SetAlternateProtocol( 8488 http_server_properties->SetAlternateProtocol(
8488 HostPortPair::FromURL(request.url), 8489 HostPortPair::FromURL(request.url),
8489 666 /* port is ignored by MockConnect anyway */, 8490 666 /* port is ignored by MockConnect anyway */,
8490 AlternateProtocolFromNextProto(GetParam()), 1); 8491 AlternateProtocolFromNextProto(GetParam()));
8491 8492
8492 scoped_ptr<HttpTransaction> trans( 8493 scoped_ptr<HttpTransaction> trans(
8493 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); 8494 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
8494 TestCompletionCallback callback; 8495 TestCompletionCallback callback;
8495 8496
8496 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); 8497 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
8497 EXPECT_EQ(ERR_IO_PENDING, rv); 8498 EXPECT_EQ(ERR_IO_PENDING, rv);
8498 EXPECT_EQ(OK, callback.WaitForResult()); 8499 EXPECT_EQ(OK, callback.WaitForResult());
8499 8500
8500 const HttpResponseInfo* response = trans->GetResponseInfo(); 8501 const HttpResponseInfo* response = trans->GetResponseInfo();
8501 ASSERT_TRUE(response != NULL); 8502 ASSERT_TRUE(response != NULL);
8502 ASSERT_TRUE(response->headers.get() != NULL); 8503 ASSERT_TRUE(response->headers.get() != NULL);
8503 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); 8504 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
8504 8505
8505 std::string response_data; 8506 std::string response_data;
8506 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); 8507 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data));
8507 EXPECT_EQ("hello world", response_data); 8508 EXPECT_EQ("hello world", response_data);
8508 8509
8509 ASSERT_TRUE(http_server_properties->HasAlternateProtocol( 8510 ASSERT_TRUE(http_server_properties->HasAlternateProtocol(
8510 HostPortPair::FromURL(request.url))); 8511 HostPortPair::FromURL(request.url)));
8511 const AlternateProtocolInfo alternate = 8512 const PortAlternateProtocolPair alternate =
8512 http_server_properties->GetAlternateProtocol( 8513 http_server_properties->GetAlternateProtocol(
8513 HostPortPair::FromURL(request.url)); 8514 HostPortPair::FromURL(request.url));
8514 EXPECT_EQ(ALTERNATE_PROTOCOL_BROKEN, alternate.protocol); 8515 EXPECT_EQ(ALTERNATE_PROTOCOL_BROKEN, alternate.protocol);
8515 } 8516 }
8516 8517
8517 TEST_P(HttpNetworkTransactionTest, 8518 TEST_P(HttpNetworkTransactionTest,
8518 AlternateProtocolPortRestrictedBlocked) { 8519 AlternateProtocolPortRestrictedBlocked) {
8519 // Ensure that we're not allowed to redirect traffic via an alternate 8520 // Ensure that we're not allowed to redirect traffic via an alternate
8520 // protocol to an unrestricted (port >= 1024) when the original traffic was 8521 // protocol to an unrestricted (port >= 1024) when the original traffic was
8521 // on a restricted port (port < 1024). Ensure that we can redirect in all 8522 // on a restricted port (port < 1024). Ensure that we can redirect in all
(...skipping 20 matching lines...) Expand all
8542 session_deps_.socket_factory->AddSocketDataProvider(&second_data); 8543 session_deps_.socket_factory->AddSocketDataProvider(&second_data);
8543 8544
8544 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 8545 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
8545 8546
8546 base::WeakPtr<HttpServerProperties> http_server_properties = 8547 base::WeakPtr<HttpServerProperties> http_server_properties =
8547 session->http_server_properties(); 8548 session->http_server_properties();
8548 const int kUnrestrictedAlternatePort = 1024; 8549 const int kUnrestrictedAlternatePort = 1024;
8549 http_server_properties->SetAlternateProtocol( 8550 http_server_properties->SetAlternateProtocol(
8550 HostPortPair::FromURL(restricted_port_request.url), 8551 HostPortPair::FromURL(restricted_port_request.url),
8551 kUnrestrictedAlternatePort, 8552 kUnrestrictedAlternatePort,
8552 AlternateProtocolFromNextProto(GetParam()), 1); 8553 AlternateProtocolFromNextProto(GetParam()));
8553 8554
8554 scoped_ptr<HttpTransaction> trans( 8555 scoped_ptr<HttpTransaction> trans(
8555 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); 8556 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
8556 TestCompletionCallback callback; 8557 TestCompletionCallback callback;
8557 8558
8558 int rv = trans->Start( 8559 int rv = trans->Start(
8559 &restricted_port_request, 8560 &restricted_port_request,
8560 callback.callback(), BoundNetLog()); 8561 callback.callback(), BoundNetLog());
8561 EXPECT_EQ(ERR_IO_PENDING, rv); 8562 EXPECT_EQ(ERR_IO_PENDING, rv);
8562 // Invalid change to unrestricted port should fail. 8563 // Invalid change to unrestricted port should fail.
(...skipping 30 matching lines...) Expand all
8593 session_deps_.socket_factory->AddSocketDataProvider(&second_data); 8594 session_deps_.socket_factory->AddSocketDataProvider(&second_data);
8594 8595
8595 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 8596 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
8596 8597
8597 base::WeakPtr<HttpServerProperties> http_server_properties = 8598 base::WeakPtr<HttpServerProperties> http_server_properties =
8598 session->http_server_properties(); 8599 session->http_server_properties();
8599 const int kUnrestrictedAlternatePort = 1024; 8600 const int kUnrestrictedAlternatePort = 1024;
8600 http_server_properties->SetAlternateProtocol( 8601 http_server_properties->SetAlternateProtocol(
8601 HostPortPair::FromURL(restricted_port_request.url), 8602 HostPortPair::FromURL(restricted_port_request.url),
8602 kUnrestrictedAlternatePort, 8603 kUnrestrictedAlternatePort,
8603 AlternateProtocolFromNextProto(GetParam()), 1); 8604 AlternateProtocolFromNextProto(GetParam()));
8604 8605
8605 scoped_ptr<HttpTransaction> trans( 8606 scoped_ptr<HttpTransaction> trans(
8606 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); 8607 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
8607 TestCompletionCallback callback; 8608 TestCompletionCallback callback;
8608 8609
8609 EXPECT_EQ(ERR_IO_PENDING, trans->Start( 8610 EXPECT_EQ(ERR_IO_PENDING, trans->Start(
8610 &restricted_port_request, 8611 &restricted_port_request,
8611 callback.callback(), BoundNetLog())); 8612 callback.callback(), BoundNetLog()));
8612 // Change to unrestricted port should succeed. 8613 // Change to unrestricted port should succeed.
8613 EXPECT_EQ(OK, callback.WaitForResult()); 8614 EXPECT_EQ(OK, callback.WaitForResult());
(...skipping 27 matching lines...) Expand all
8641 session_deps_.socket_factory->AddSocketDataProvider(&second_data); 8642 session_deps_.socket_factory->AddSocketDataProvider(&second_data);
8642 8643
8643 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 8644 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
8644 8645
8645 base::WeakPtr<HttpServerProperties> http_server_properties = 8646 base::WeakPtr<HttpServerProperties> http_server_properties =
8646 session->http_server_properties(); 8647 session->http_server_properties();
8647 const int kRestrictedAlternatePort = 80; 8648 const int kRestrictedAlternatePort = 80;
8648 http_server_properties->SetAlternateProtocol( 8649 http_server_properties->SetAlternateProtocol(
8649 HostPortPair::FromURL(restricted_port_request.url), 8650 HostPortPair::FromURL(restricted_port_request.url),
8650 kRestrictedAlternatePort, 8651 kRestrictedAlternatePort,
8651 AlternateProtocolFromNextProto(GetParam()), 1); 8652 AlternateProtocolFromNextProto(GetParam()));
8652 8653
8653 scoped_ptr<HttpTransaction> trans( 8654 scoped_ptr<HttpTransaction> trans(
8654 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); 8655 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
8655 TestCompletionCallback callback; 8656 TestCompletionCallback callback;
8656 8657
8657 int rv = trans->Start( 8658 int rv = trans->Start(
8658 &restricted_port_request, 8659 &restricted_port_request,
8659 callback.callback(), BoundNetLog()); 8660 callback.callback(), BoundNetLog());
8660 EXPECT_EQ(ERR_IO_PENDING, rv); 8661 EXPECT_EQ(ERR_IO_PENDING, rv);
8661 // Valid change to restricted port should pass. 8662 // Valid change to restricted port should pass.
(...skipping 28 matching lines...) Expand all
8690 session_deps_.socket_factory->AddSocketDataProvider(&second_data); 8691 session_deps_.socket_factory->AddSocketDataProvider(&second_data);
8691 8692
8692 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 8693 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
8693 8694
8694 base::WeakPtr<HttpServerProperties> http_server_properties = 8695 base::WeakPtr<HttpServerProperties> http_server_properties =
8695 session->http_server_properties(); 8696 session->http_server_properties();
8696 const int kRestrictedAlternatePort = 80; 8697 const int kRestrictedAlternatePort = 80;
8697 http_server_properties->SetAlternateProtocol( 8698 http_server_properties->SetAlternateProtocol(
8698 HostPortPair::FromURL(unrestricted_port_request.url), 8699 HostPortPair::FromURL(unrestricted_port_request.url),
8699 kRestrictedAlternatePort, 8700 kRestrictedAlternatePort,
8700 AlternateProtocolFromNextProto(GetParam()), 1); 8701 AlternateProtocolFromNextProto(GetParam()));
8701 8702
8702 scoped_ptr<HttpTransaction> trans( 8703 scoped_ptr<HttpTransaction> trans(
8703 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); 8704 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
8704 TestCompletionCallback callback; 8705 TestCompletionCallback callback;
8705 8706
8706 int rv = trans->Start( 8707 int rv = trans->Start(
8707 &unrestricted_port_request, callback.callback(), BoundNetLog()); 8708 &unrestricted_port_request, callback.callback(), BoundNetLog());
8708 EXPECT_EQ(ERR_IO_PENDING, rv); 8709 EXPECT_EQ(ERR_IO_PENDING, rv);
8709 // Valid change to restricted port should pass. 8710 // Valid change to restricted port should pass.
8710 EXPECT_EQ(OK, callback.WaitForResult()); 8711 EXPECT_EQ(OK, callback.WaitForResult());
(...skipping 27 matching lines...) Expand all
8738 session_deps_.socket_factory->AddSocketDataProvider(&second_data); 8739 session_deps_.socket_factory->AddSocketDataProvider(&second_data);
8739 8740
8740 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 8741 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
8741 8742
8742 base::WeakPtr<HttpServerProperties> http_server_properties = 8743 base::WeakPtr<HttpServerProperties> http_server_properties =
8743 session->http_server_properties(); 8744 session->http_server_properties();
8744 const int kUnrestrictedAlternatePort = 1024; 8745 const int kUnrestrictedAlternatePort = 1024;
8745 http_server_properties->SetAlternateProtocol( 8746 http_server_properties->SetAlternateProtocol(
8746 HostPortPair::FromURL(unrestricted_port_request.url), 8747 HostPortPair::FromURL(unrestricted_port_request.url),
8747 kUnrestrictedAlternatePort, 8748 kUnrestrictedAlternatePort,
8748 AlternateProtocolFromNextProto(GetParam()), 1); 8749 AlternateProtocolFromNextProto(GetParam()));
8749 8750
8750 scoped_ptr<HttpTransaction> trans( 8751 scoped_ptr<HttpTransaction> trans(
8751 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); 8752 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
8752 TestCompletionCallback callback; 8753 TestCompletionCallback callback;
8753 8754
8754 int rv = trans->Start( 8755 int rv = trans->Start(
8755 &unrestricted_port_request, callback.callback(), BoundNetLog()); 8756 &unrestricted_port_request, callback.callback(), BoundNetLog());
8756 EXPECT_EQ(ERR_IO_PENDING, rv); 8757 EXPECT_EQ(ERR_IO_PENDING, rv);
8757 // Valid change to an unrestricted port should pass. 8758 // Valid change to an unrestricted port should pass.
8758 EXPECT_EQ(OK, callback.WaitForResult()); 8759 EXPECT_EQ(OK, callback.WaitForResult());
(...skipping 22 matching lines...) Expand all
8781 session_deps_.socket_factory->AddSocketDataProvider(&data); 8782 session_deps_.socket_factory->AddSocketDataProvider(&data);
8782 8783
8783 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 8784 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
8784 8785
8785 base::WeakPtr<HttpServerProperties> http_server_properties = 8786 base::WeakPtr<HttpServerProperties> http_server_properties =
8786 session->http_server_properties(); 8787 session->http_server_properties();
8787 const int kUnsafePort = 7; 8788 const int kUnsafePort = 7;
8788 http_server_properties->SetAlternateProtocol( 8789 http_server_properties->SetAlternateProtocol(
8789 HostPortPair::FromURL(request.url), 8790 HostPortPair::FromURL(request.url),
8790 kUnsafePort, 8791 kUnsafePort,
8791 AlternateProtocolFromNextProto(GetParam()), 1); 8792 AlternateProtocolFromNextProto(GetParam()));
8792 8793
8793 scoped_ptr<HttpTransaction> trans( 8794 scoped_ptr<HttpTransaction> trans(
8794 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); 8795 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
8795 TestCompletionCallback callback; 8796 TestCompletionCallback callback;
8796 8797
8797 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); 8798 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
8798 EXPECT_EQ(ERR_IO_PENDING, rv); 8799 EXPECT_EQ(ERR_IO_PENDING, rv);
8799 // The HTTP request should succeed. 8800 // The HTTP request should succeed.
8800 EXPECT_EQ(OK, callback.WaitForResult()); 8801 EXPECT_EQ(OK, callback.WaitForResult());
8801 8802
(...skipping 4401 matching lines...) Expand 10 before | Expand all | Expand 10 after
13203 EXPECT_EQ(ERR_IO_PENDING, rv); 13204 EXPECT_EQ(ERR_IO_PENDING, rv);
13204 13205
13205 rv = callback.WaitForResult(); 13206 rv = callback.WaitForResult();
13206 EXPECT_EQ(ERR_CONNECTION_RESET, rv); 13207 EXPECT_EQ(ERR_CONNECTION_RESET, rv);
13207 13208
13208 const HttpResponseInfo* response = trans->GetResponseInfo(); 13209 const HttpResponseInfo* response = trans->GetResponseInfo();
13209 EXPECT_TRUE(response == NULL); 13210 EXPECT_TRUE(response == NULL);
13210 } 13211 }
13211 13212
13212 } // namespace net 13213 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_network_transaction.cc ('k') | net/http/http_server_properties.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698