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

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

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