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

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

Issue 18546008: [SPDY] Use WeakPtr<SpdySession> everywhere but SpdySessionPool (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix test, other minor formatting/comment changes Created 7 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 | « no previous file | net/http/http_proxy_client_socket_pool.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 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 #include "net/spdy/spdy_framer.h" 56 #include "net/spdy/spdy_framer.h"
57 #include "net/spdy/spdy_session.h" 57 #include "net/spdy/spdy_session.h"
58 #include "net/spdy/spdy_session_pool.h" 58 #include "net/spdy/spdy_session_pool.h"
59 #include "net/spdy/spdy_test_util_common.h" 59 #include "net/spdy/spdy_test_util_common.h"
60 #include "net/ssl/ssl_cert_request_info.h" 60 #include "net/ssl/ssl_cert_request_info.h"
61 #include "net/ssl/ssl_config_service_defaults.h" 61 #include "net/ssl/ssl_config_service_defaults.h"
62 #include "net/ssl/ssl_info.h" 62 #include "net/ssl/ssl_info.h"
63 #include "net/test/cert_test_util.h" 63 #include "net/test/cert_test_util.h"
64 #include "testing/gtest/include/gtest/gtest.h" 64 #include "testing/gtest/include/gtest/gtest.h"
65 #include "testing/platform_test.h" 65 #include "testing/platform_test.h"
66 #include "url/gurl.h"
66 67
67 //----------------------------------------------------------------------------- 68 //-----------------------------------------------------------------------------
68 69
69 namespace { 70 namespace {
70 71
71 const base::string16 kBar(ASCIIToUTF16("bar")); 72 const base::string16 kBar(ASCIIToUTF16("bar"));
72 const base::string16 kBar2(ASCIIToUTF16("bar2")); 73 const base::string16 kBar2(ASCIIToUTF16("bar2"));
73 const base::string16 kBar3(ASCIIToUTF16("bar3")); 74 const base::string16 kBar3(ASCIIToUTF16("bar3"));
74 const base::string16 kBaz(ASCIIToUTF16("baz")); 75 const base::string16 kBaz(ASCIIToUTF16("baz"));
75 const base::string16 kFirst(ASCIIToUTF16("first")); 76 const base::string16 kFirst(ASCIIToUTF16("first"));
(...skipping 8772 matching lines...) Expand 10 before | Expand all | Expand 10 after
8848 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); 8849 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
8849 8850
8850 std::string response_data; 8851 std::string response_data;
8851 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); 8852 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data));
8852 EXPECT_EQ("hello world", response_data); 8853 EXPECT_EQ("hello world", response_data);
8853 8854
8854 // Set up an initial SpdySession in the pool to reuse. 8855 // Set up an initial SpdySession in the pool to reuse.
8855 HostPortPair host_port_pair("www.google.com", 443); 8856 HostPortPair host_port_pair("www.google.com", 443);
8856 SpdySessionKey key(host_port_pair, ProxyServer::Direct(), 8857 SpdySessionKey key(host_port_pair, ProxyServer::Direct(),
8857 kPrivacyModeDisabled); 8858 kPrivacyModeDisabled);
8858 scoped_refptr<SpdySession> spdy_session = 8859 base::WeakPtr<SpdySession> spdy_session =
8859 CreateSecureSpdySession(session, key, BoundNetLog()); 8860 CreateSecureSpdySession(session, key, BoundNetLog());
8860 8861
8861 trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); 8862 trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
8862 8863
8863 rv = trans->Start(&request, callback.callback(), BoundNetLog()); 8864 rv = trans->Start(&request, callback.callback(), BoundNetLog());
8864 EXPECT_EQ(ERR_IO_PENDING, rv); 8865 EXPECT_EQ(ERR_IO_PENDING, rv);
8865 EXPECT_EQ(OK, callback.WaitForResult()); 8866 EXPECT_EQ(OK, callback.WaitForResult());
8866 8867
8867 response = trans->GetResponseInfo(); 8868 response = trans->GetResponseInfo();
8868 ASSERT_TRUE(response != NULL); 8869 ASSERT_TRUE(response != NULL);
(...skipping 702 matching lines...) Expand 10 before | Expand all | Expand 10 after
9571 9572
9572 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 9573 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
9573 scoped_ptr<HttpTransaction> trans( 9574 scoped_ptr<HttpTransaction> trans(
9574 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); 9575 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
9575 9576
9576 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); 9577 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
9577 EXPECT_EQ(ERR_IO_PENDING, rv); 9578 EXPECT_EQ(ERR_IO_PENDING, rv);
9578 EXPECT_EQ(ERR_CONNECTION_CLOSED, callback.WaitForResult()); 9579 EXPECT_EQ(ERR_CONNECTION_CLOSED, callback.WaitForResult());
9579 } 9580 }
9580 9581
9582 // A subclass of HttpAuthHandlerMock that records the request URL when
9583 // it gets it. This is needed since the auth handler may get destroyed
9584 // before we get a chance to query it.
9585 class UrlRecordingHttpAuthHandlerMock : public HttpAuthHandlerMock {
9586 public:
9587 explicit UrlRecordingHttpAuthHandlerMock(GURL* url) : url_(url) {}
9588
9589 virtual ~UrlRecordingHttpAuthHandlerMock() {}
9590
9591 protected:
9592 virtual int GenerateAuthTokenImpl(const AuthCredentials* credentials,
9593 const HttpRequestInfo* request,
9594 const CompletionCallback& callback,
9595 std::string* auth_token) OVERRIDE {
9596 *url_ = request->url;
9597 return HttpAuthHandlerMock::GenerateAuthTokenImpl(
9598 credentials, request, callback, auth_token);
9599 }
9600
9601 private:
9602 GURL* url_;
9603 };
9604
9581 TEST_P(HttpNetworkTransactionTest, SpdyAlternateProtocolThroughProxy) { 9605 TEST_P(HttpNetworkTransactionTest, SpdyAlternateProtocolThroughProxy) {
9582 // This test ensures that the URL passed into the proxy is upgraded 9606 // This test ensures that the URL passed into the proxy is upgraded
9583 // to https when doing an Alternate Protocol upgrade. 9607 // to https when doing an Alternate Protocol upgrade.
9584 HttpStreamFactory::set_use_alternate_protocols(true); 9608 HttpStreamFactory::set_use_alternate_protocols(true);
9585 HttpStreamFactory::SetNextProtos(SpdyNextProtos()); 9609 HttpStreamFactory::SetNextProtos(SpdyNextProtos());
9586 9610
9587 session_deps_.proxy_service.reset( 9611 session_deps_.proxy_service.reset(
9588 ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); 9612 ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"));
9589 CapturingNetLog net_log; 9613 CapturingNetLog net_log;
9590 session_deps_.net_log = &net_log; 9614 session_deps_.net_log = &net_log;
9591 HttpAuthHandlerMock::Factory* auth_factory = 9615 GURL request_url;
9592 new HttpAuthHandlerMock::Factory(); 9616 {
9593 HttpAuthHandlerMock* auth_handler = new HttpAuthHandlerMock(); 9617 HttpAuthHandlerMock::Factory* auth_factory =
9594 auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); 9618 new HttpAuthHandlerMock::Factory();
9595 auth_factory->set_do_init_from_challenge(true); 9619 UrlRecordingHttpAuthHandlerMock* auth_handler =
9596 session_deps_.http_auth_handler_factory.reset(auth_factory); 9620 new UrlRecordingHttpAuthHandlerMock(&request_url);
9621 auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY);
9622 auth_factory->set_do_init_from_challenge(true);
9623 session_deps_.http_auth_handler_factory.reset(auth_factory);
9624 }
9597 9625
9598 HttpRequestInfo request; 9626 HttpRequestInfo request;
9599 request.method = "GET"; 9627 request.method = "GET";
9600 request.url = GURL("http://www.google.com"); 9628 request.url = GURL("http://www.google.com");
9601 request.load_flags = 0; 9629 request.load_flags = 0;
9602 9630
9603 // First round goes unauthenticated through the proxy. 9631 // First round goes unauthenticated through the proxy.
9604 MockWrite data_writes_1[] = { 9632 MockWrite data_writes_1[] = {
9605 MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" 9633 MockWrite("GET http://www.google.com/ HTTP/1.1\r\n"
9606 "Host: www.google.com\r\n" 9634 "Host: www.google.com\r\n"
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
9717 9745
9718 // Restart with auth. Tunnel should work and response received. 9746 // Restart with auth. Tunnel should work and response received.
9719 TestCompletionCallback callback_3; 9747 TestCompletionCallback callback_3;
9720 rv = trans_2->RestartWithAuth( 9748 rv = trans_2->RestartWithAuth(
9721 AuthCredentials(kFoo, kBar), callback_3.callback()); 9749 AuthCredentials(kFoo, kBar), callback_3.callback());
9722 EXPECT_EQ(ERR_IO_PENDING, rv); 9750 EXPECT_EQ(ERR_IO_PENDING, rv);
9723 EXPECT_EQ(OK, callback_3.WaitForResult()); 9751 EXPECT_EQ(OK, callback_3.WaitForResult());
9724 9752
9725 // After all that work, these two lines (or actually, just the scheme) are 9753 // After all that work, these two lines (or actually, just the scheme) are
9726 // what this test is all about. Make sure it happens correctly. 9754 // what this test is all about. Make sure it happens correctly.
9727 const GURL& request_url = auth_handler->request_url();
9728 EXPECT_EQ("https", request_url.scheme()); 9755 EXPECT_EQ("https", request_url.scheme());
9729 EXPECT_EQ("www.google.com", request_url.host()); 9756 EXPECT_EQ("www.google.com", request_url.host());
9730 9757
9731 LoadTimingInfo load_timing_info; 9758 LoadTimingInfo load_timing_info;
9732 EXPECT_TRUE(trans_2->GetLoadTimingInfo(&load_timing_info)); 9759 EXPECT_TRUE(trans_2->GetLoadTimingInfo(&load_timing_info));
9733 TestLoadTimingNotReusedWithPac(load_timing_info, 9760 TestLoadTimingNotReusedWithPac(load_timing_info,
9734 CONNECT_TIMING_HAS_SSL_TIMES); 9761 CONNECT_TIMING_HAS_SSL_TIMES);
9735 } 9762 }
9736 9763
9737 // Test that if we cancel the transaction as the connection is completing, that 9764 // Test that if we cancel the transaction as the connection is completing, that
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
9980 SSLSocketDataProvider ssl(ASYNC, OK); 10007 SSLSocketDataProvider ssl(ASYNC, OK);
9981 ssl.SetNextProto(GetParam()); 10008 ssl.SetNextProto(GetParam());
9982 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); 10009 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
9983 10010
9984 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 10011 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
9985 10012
9986 // Set up an initial SpdySession in the pool to reuse. 10013 // Set up an initial SpdySession in the pool to reuse.
9987 HostPortPair host_port_pair("www.google.com", 443); 10014 HostPortPair host_port_pair("www.google.com", 443);
9988 SpdySessionKey key(host_port_pair, ProxyServer::Direct(), 10015 SpdySessionKey key(host_port_pair, ProxyServer::Direct(),
9989 kPrivacyModeDisabled); 10016 kPrivacyModeDisabled);
9990 scoped_refptr<SpdySession> spdy_session = 10017 base::WeakPtr<SpdySession> spdy_session =
9991 CreateInsecureSpdySession(session, key, BoundNetLog()); 10018 CreateInsecureSpdySession(session, key, BoundNetLog());
9992 10019
9993 HttpRequestInfo request; 10020 HttpRequestInfo request;
9994 request.method = "GET"; 10021 request.method = "GET";
9995 request.url = GURL("https://www.google.com/"); 10022 request.url = GURL("https://www.google.com/");
9996 request.load_flags = 0; 10023 request.load_flags = 0;
9997 10024
9998 // This is the important line that marks this as a preconnect. 10025 // This is the important line that marks this as a preconnect.
9999 request.motivation = HttpRequestInfo::PRECONNECT_MOTIVATED; 10026 request.motivation = HttpRequestInfo::PRECONNECT_MOTIVATED;
10000 10027
(...skipping 1668 matching lines...) Expand 10 before | Expand all | Expand 10 after
11669 EXPECT_EQ(OK, rv); 11696 EXPECT_EQ(OK, rv);
11670 11697
11671 HttpRequestHeaders request_headers; 11698 HttpRequestHeaders request_headers;
11672 EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); 11699 EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers));
11673 std::string foo; 11700 std::string foo;
11674 EXPECT_TRUE(request_headers.GetHeader("X-Foo", &foo)); 11701 EXPECT_TRUE(request_headers.GetHeader("X-Foo", &foo));
11675 EXPECT_EQ("bar", foo); 11702 EXPECT_EQ("bar", foo);
11676 } 11703 }
11677 11704
11678 } // namespace net 11705 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/http/http_proxy_client_socket_pool.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698