OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <string> | 5 #include <string> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "net/base/net_log_unittest.h" | 8 #include "net/base/net_log_unittest.h" |
9 #include "net/http/http_stream_handle.h" | 9 #include "net/http/http_stream_handle.h" |
10 #include "net/http/http_transaction_unittest.h" | 10 #include "net/http/http_transaction_unittest.h" |
(...skipping 3842 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3853 | 3853 |
3854 // Verify that we consumed all test data. | 3854 // Verify that we consumed all test data. |
3855 helper.VerifyDataConsumed(); | 3855 helper.VerifyDataConsumed(); |
3856 } | 3856 } |
3857 | 3857 |
3858 // Test to make sure we can correctly connect through a proxy. | 3858 // Test to make sure we can correctly connect through a proxy. |
3859 TEST_P(SpdyNetworkTransactionTest, ProxyConnect) { | 3859 TEST_P(SpdyNetworkTransactionTest, ProxyConnect) { |
3860 NormalSpdyTransactionHelper helper(CreateGetRequest(), | 3860 NormalSpdyTransactionHelper helper(CreateGetRequest(), |
3861 BoundNetLog(), GetParam()); | 3861 BoundNetLog(), GetParam()); |
3862 helper.session_deps().reset(new SpdySessionDependencies( | 3862 helper.session_deps().reset(new SpdySessionDependencies( |
3863 net::SpdyCreateFixedProxyService("myproxy:70"))); | 3863 ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"))); |
3864 helper.SetSession(SpdySessionDependencies::SpdyCreateSession( | 3864 helper.SetSession(SpdySessionDependencies::SpdyCreateSession( |
3865 helper.session_deps().get())); | 3865 helper.session_deps().get())); |
3866 helper.RunPreTestSetup(); | 3866 helper.RunPreTestSetup(); |
3867 HttpNetworkTransaction* trans = helper.trans(); | 3867 HttpNetworkTransaction* trans = helper.trans(); |
3868 | 3868 |
3869 const char kConnect443[] = {"CONNECT www.google.com:443 HTTP/1.1\r\n" | 3869 const char kConnect443[] = {"CONNECT www.google.com:443 HTTP/1.1\r\n" |
3870 "Host: www.google.com\r\n" | 3870 "Host: www.google.com\r\n" |
3871 "Proxy-Connection: keep-alive\r\n\r\n"}; | 3871 "Proxy-Connection: keep-alive\r\n\r\n"}; |
3872 const char kConnect80[] = {"CONNECT www.google.com:80 HTTP/1.1\r\n" | 3872 const char kConnect80[] = {"CONNECT www.google.com:80 HTTP/1.1\r\n" |
3873 "Host: www.google.com\r\n" | 3873 "Host: www.google.com\r\n" |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3950 } | 3950 } |
3951 | 3951 |
3952 // Test to make sure we can correctly connect through a proxy to www.google.com, | 3952 // Test to make sure we can correctly connect through a proxy to www.google.com, |
3953 // if there already exists a direct spdy connection to www.google.com. See | 3953 // if there already exists a direct spdy connection to www.google.com. See |
3954 // http://crbug.com/49874 | 3954 // http://crbug.com/49874 |
3955 TEST_P(SpdyNetworkTransactionTest, DirectConnectProxyReconnect) { | 3955 TEST_P(SpdyNetworkTransactionTest, DirectConnectProxyReconnect) { |
3956 // When setting up the first transaction, we store the SpdySessionPool so that | 3956 // When setting up the first transaction, we store the SpdySessionPool so that |
3957 // we can use the same pool in the second transaction. | 3957 // we can use the same pool in the second transaction. |
3958 NormalSpdyTransactionHelper helper(CreateGetRequest(), | 3958 NormalSpdyTransactionHelper helper(CreateGetRequest(), |
3959 BoundNetLog(), GetParam()); | 3959 BoundNetLog(), GetParam()); |
| 3960 |
| 3961 // Use a proxy service which returns a proxy fallback list from DIRECT to |
| 3962 // myproxy:70. For this test there will be no fallback, so it is equivalent |
| 3963 // to simply DIRECT. The reason for appending the second proxy is to verify |
| 3964 // that the session pool key used does is just "DIRECT". |
| 3965 helper.session_deps().reset(new SpdySessionDependencies( |
| 3966 ProxyService::CreateFixedFromPacResult("DIRECT; PROXY myproxy:70"))); |
| 3967 helper.SetSession(SpdySessionDependencies::SpdyCreateSession( |
| 3968 helper.session_deps().get())); |
| 3969 |
3960 scoped_refptr<SpdySessionPool> spdy_session_pool = | 3970 scoped_refptr<SpdySessionPool> spdy_session_pool = |
3961 helper.session_deps()->spdy_session_pool; | 3971 helper.session_deps()->spdy_session_pool; |
3962 helper.RunPreTestSetup(); | 3972 helper.RunPreTestSetup(); |
3963 | 3973 |
3964 // Construct and send a simple GET request. | 3974 // Construct and send a simple GET request. |
3965 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); | 3975 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); |
3966 MockWrite writes[] = { | 3976 MockWrite writes[] = { |
3967 CreateMockWrite(*req, 1), | 3977 CreateMockWrite(*req, 1), |
3968 }; | 3978 }; |
3969 | 3979 |
(...skipping 23 matching lines...) Expand all Loading... |
3993 EXPECT_TRUE(response->headers != NULL); | 4003 EXPECT_TRUE(response->headers != NULL); |
3994 EXPECT_TRUE(response->was_fetched_via_spdy); | 4004 EXPECT_TRUE(response->was_fetched_via_spdy); |
3995 out.rv = ReadTransaction(trans, &out.response_data); | 4005 out.rv = ReadTransaction(trans, &out.response_data); |
3996 EXPECT_EQ(OK, out.rv); | 4006 EXPECT_EQ(OK, out.rv); |
3997 out.status_line = response->headers->GetStatusLine(); | 4007 out.status_line = response->headers->GetStatusLine(); |
3998 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); | 4008 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
3999 EXPECT_EQ("hello!", out.response_data); | 4009 EXPECT_EQ("hello!", out.response_data); |
4000 | 4010 |
4001 // Check that the SpdySession is still in the SpdySessionPool. | 4011 // Check that the SpdySession is still in the SpdySessionPool. |
4002 HostPortPair host_port_pair("www.google.com", helper.port()); | 4012 HostPortPair host_port_pair("www.google.com", helper.port()); |
4003 HostPortProxyPair pair(host_port_pair, "DIRECT"); | 4013 HostPortProxyPair session_pool_key_direct(host_port_pair, "DIRECT"); |
4004 EXPECT_TRUE(spdy_session_pool->HasSession(pair)); | 4014 EXPECT_TRUE(spdy_session_pool->HasSession(session_pool_key_direct)); |
4005 HostPortProxyPair nonexistent_pair(host_port_pair, "PROXY www.foo.com"); | 4015 HostPortProxyPair session_pool_key_proxy(host_port_pair, "PROXY www.foo.com"); |
4006 EXPECT_FALSE(spdy_session_pool->HasSession(nonexistent_pair)); | 4016 EXPECT_FALSE(spdy_session_pool->HasSession(session_pool_key_proxy)); |
4007 | 4017 |
4008 // Set up data for the proxy connection. | 4018 // Set up data for the proxy connection. |
4009 const char kConnect443[] = {"CONNECT www.google.com:443 HTTP/1.1\r\n" | 4019 const char kConnect443[] = {"CONNECT www.google.com:443 HTTP/1.1\r\n" |
4010 "Host: www.google.com\r\n" | 4020 "Host: www.google.com\r\n" |
4011 "Proxy-Connection: keep-alive\r\n\r\n"}; | 4021 "Proxy-Connection: keep-alive\r\n\r\n"}; |
4012 const char kConnect80[] = {"CONNECT www.google.com:80 HTTP/1.1\r\n" | 4022 const char kConnect80[] = {"CONNECT www.google.com:80 HTTP/1.1\r\n" |
4013 "Host: www.google.com\r\n" | 4023 "Host: www.google.com\r\n" |
4014 "Proxy-Connection: keep-alive\r\n\r\n"}; | 4024 "Proxy-Connection: keep-alive\r\n\r\n"}; |
4015 const char kHTTP200[] = {"HTTP/1.1 200 OK\r\n\r\n"}; | 4025 const char kHTTP200[] = {"HTTP/1.1 200 OK\r\n\r\n"}; |
4016 scoped_ptr<spdy::SpdyFrame> req2(ConstructSpdyGet( | 4026 scoped_ptr<spdy::SpdyFrame> req2(ConstructSpdyGet( |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4072 default: | 4082 default: |
4073 NOTREACHED(); | 4083 NOTREACHED(); |
4074 } | 4084 } |
4075 | 4085 |
4076 // Create another request to www.google.com, but this time through a proxy. | 4086 // Create another request to www.google.com, but this time through a proxy. |
4077 HttpRequestInfo request_proxy; | 4087 HttpRequestInfo request_proxy; |
4078 request_proxy.method = "GET"; | 4088 request_proxy.method = "GET"; |
4079 request_proxy.url = GURL("http://www.google.com/foo.dat"); | 4089 request_proxy.url = GURL("http://www.google.com/foo.dat"); |
4080 request_proxy.load_flags = 0; | 4090 request_proxy.load_flags = 0; |
4081 scoped_ptr<SpdySessionDependencies> ssd_proxy( | 4091 scoped_ptr<SpdySessionDependencies> ssd_proxy( |
4082 new SpdySessionDependencies(net::SpdyCreateFixedProxyService( | 4092 new SpdySessionDependencies( |
4083 "myproxy:70"))); | 4093 ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"))); |
4084 // Ensure that this transaction uses the same SpdySessionPool. | 4094 // Ensure that this transaction uses the same SpdySessionPool. |
4085 ssd_proxy->spdy_session_pool = spdy_session_pool; | 4095 ssd_proxy->spdy_session_pool = spdy_session_pool; |
4086 scoped_refptr<HttpNetworkSession> session_proxy = | 4096 scoped_refptr<HttpNetworkSession> session_proxy = |
4087 SpdySessionDependencies::SpdyCreateSession(ssd_proxy.get()); | 4097 SpdySessionDependencies::SpdyCreateSession(ssd_proxy.get()); |
4088 NormalSpdyTransactionHelper helper_proxy(request_proxy, | 4098 NormalSpdyTransactionHelper helper_proxy(request_proxy, |
4089 BoundNetLog(), GetParam()); | 4099 BoundNetLog(), GetParam()); |
4090 helper_proxy.session_deps().swap(ssd_proxy); | 4100 helper_proxy.session_deps().swap(ssd_proxy); |
4091 helper_proxy.SetSession(session_proxy); | 4101 helper_proxy.SetSession(session_proxy); |
4092 helper_proxy.RunPreTestSetup(); | 4102 helper_proxy.RunPreTestSetup(); |
4093 helper_proxy.AddData(data_proxy.get()); | 4103 helper_proxy.AddData(data_proxy.get()); |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4188 rv = ReadTransaction(trans.get(), &response_data); | 4198 rv = ReadTransaction(trans.get(), &response_data); |
4189 EXPECT_EQ(OK, rv); | 4199 EXPECT_EQ(OK, rv); |
4190 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | 4200 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
4191 EXPECT_EQ("hello!", response_data); | 4201 EXPECT_EQ("hello!", response_data); |
4192 } | 4202 } |
4193 | 4203 |
4194 helper.VerifyDataConsumed(); | 4204 helper.VerifyDataConsumed(); |
4195 } | 4205 } |
4196 } | 4206 } |
4197 } // namespace net | 4207 } // namespace net |
OLD | NEW |