summaryrefslogtreecommitdiffstats
path: root/net/http/http_network_transaction_unittest.cc
diff options
context:
space:
mode:
authorarindam@chromium.org <arindam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-26 20:00:31 +0000
committerarindam@chromium.org <arindam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-26 20:00:31 +0000
commit04e5be3837d175ad9bba54d8c111d380459c5f39 (patch)
tree116c9334cee4f200dcaa9a0a38716985b93eaa8b /net/http/http_network_transaction_unittest.cc
parent791f74e8cd6eb1204b04c23e6378daeb4f688ee6 (diff)
downloadchromium_src-04e5be3837d175ad9bba54d8c111d380459c5f39.zip
chromium_src-04e5be3837d175ad9bba54d8c111d380459c5f39.tar.gz
chromium_src-04e5be3837d175ad9bba54d8c111d380459c5f39.tar.bz2
Refactoring using_proxy_, using_tunnel_, using_socks_proxy_ into a single enum ProxyConfig in HttpNetworkTransaction.
Fixing http://crbug.com/14982 In case of SOCKS proxies we set the url to append to the group name so that the socks endpoint is at the target server and not the socks proxy server and so can be effectively reused by the socket pool. BUG=14982 TEST=unittests Review URL: http://codereview.chromium.org/146026 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@19404 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/http/http_network_transaction_unittest.cc')
-rw-r--r--net/http/http_network_transaction_unittest.cc110
1 files changed, 110 insertions, 0 deletions
diff --git a/net/http/http_network_transaction_unittest.cc b/net/http/http_network_transaction_unittest.cc
index 57ea425..ba68db1 100644
--- a/net/http/http_network_transaction_unittest.cc
+++ b/net/http/http_network_transaction_unittest.cc
@@ -164,6 +164,45 @@ std::string MockGetHostName() {
return "WTC-WIN7";
}
+class CaptureGroupNameSocketPool : public ClientSocketPool {
+ public:
+ CaptureGroupNameSocketPool() {
+ }
+ virtual int RequestSocket(const std::string& group_name,
+ const HostResolver::RequestInfo& resolve_info,
+ int priority,
+ ClientSocketHandle* handle,
+ CompletionCallback* callback) {
+ last_group_name_ = group_name;
+ return ERR_IO_PENDING;
+ }
+
+ const std::string last_group_name_received() const {
+ return last_group_name_;
+ }
+
+ virtual void CancelRequest(const std::string& group_name,
+ const ClientSocketHandle* handle) { }
+ virtual void ReleaseSocket(const std::string& group_name,
+ ClientSocket* socket) {}
+ virtual void CloseIdleSockets() {}
+ virtual HostResolver* GetHostResolver() const {
+ return NULL;
+ }
+ virtual int IdleSocketCount() const {
+ return 0;
+ }
+ virtual int IdleSocketCountInGroup(const std::string& group_name) const {
+ return 0;
+ }
+ virtual LoadState GetLoadState(const std::string& group_name,
+ const ClientSocketHandle* handle) const {
+ return LOAD_STATE_IDLE;
+ }
+ protected:
+ std::string last_group_name_;
+};
+
//-----------------------------------------------------------------------------
TEST_F(HttpNetworkTransactionTest, Basic) {
@@ -3115,6 +3154,77 @@ TEST_F(HttpNetworkTransactionTest, SOCKS4_SSL_GET) {
EXPECT_EQ("Payload", response_text);
}
+// Tests that for connection endpoints the group names are correctly set.
+TEST_F(HttpNetworkTransactionTest, GroupNameForProxyConnections) {
+ const struct {
+ const std::string proxy_server;
+ const std::string url;
+ const std::string expected_group_name;
+ } tests[] = {
+ {
+ "", // no proxy (direct)
+ "http://www.google.com/direct",
+ "http://www.google.com/",
+ },
+ {
+ "http_proxy",
+ "http://www.google.com/http_proxy_normal",
+ "proxy/http_proxy:80/",
+ },
+ {
+ "socks4://socks_proxy:1080",
+ "http://www.google.com/socks4_direct",
+ "proxy/socks4://socks_proxy:1080/http://www.google.com/",
+ },
+
+ // SSL Tests
+ {
+ "",
+ "https://www.google.com/direct_ssl",
+ "https://www.google.com/",
+ },
+ {
+ "http_proxy",
+ "https://www.google.com/http_connect_ssl",
+ "proxy/http_proxy:80/https://www.google.com/",
+ },
+ {
+ "socks4://socks_proxy:1080",
+ "https://www.google.com/socks4_ssl",
+ "proxy/socks4://socks_proxy:1080/https://www.google.com/",
+ },
+ };
+
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
+ SessionDependencies session_deps;
+ session_deps.proxy_service.reset(CreateFixedProxyService(
+ tests[i].proxy_server));
+
+ scoped_refptr<CaptureGroupNameSocketPool> conn_pool(
+ new CaptureGroupNameSocketPool());
+
+ scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
+ session->connection_pool_ = conn_pool.get();
+
+ scoped_ptr<HttpTransaction> trans(
+ new HttpNetworkTransaction(
+ session.get(),
+ &session_deps.socket_factory));
+
+ HttpRequestInfo request;
+ request.method = "GET";
+ request.url = GURL(tests[i].url);
+ request.load_flags = 0;
+
+ TestCompletionCallback callback;
+
+ // We do not complete this request, the dtor will clean the transaction up.
+ EXPECT_EQ(ERR_IO_PENDING, trans->Start(&request, &callback));
+ EXPECT_EQ(tests[i].expected_group_name,
+ conn_pool->last_group_name_received());
+ }
+}
+
TEST_F(HttpNetworkTransactionTest, ReconsiderProxyAfterFailedConnection) {
scoped_refptr<RuleBasedHostMapper> host_mapper(new RuleBasedHostMapper());
ScopedHostMapper scoped_host_mapper(host_mapper.get());