diff options
author | ericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-15 22:04:32 +0000 |
---|---|---|
committer | ericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-15 22:04:32 +0000 |
commit | b59ff376c5d5b950774fcbe65727611d51832b75 (patch) | |
tree | a37598ddd4e9ec0530d5820bcce1f47bafa89289 /net/socket/tcp_client_socket_pool_unittest.cc | |
parent | 89d70652ad0bb9e7f419c17516fad279d8a4db32 (diff) | |
download | chromium_src-b59ff376c5d5b950774fcbe65727611d51832b75.zip chromium_src-b59ff376c5d5b950774fcbe65727611d51832b75.tar.gz chromium_src-b59ff376c5d5b950774fcbe65727611d51832b75.tar.bz2 |
Refactorings surrounding HostResolver:
(1) Extract HostResolver to an interface.
The existing concrete implementation is now named HostResolverImpl. This makes it possible to create mocks with more complex behavior (i.e. choose via rules if response will be sync vs async).
(2) Transform HostMapper into HostResolverProc.
Conceptually HostResolverProc maps a hostname to a socket address, whereas HostMapper mapped a hostname to another hostname (so you were still at the mercy of the system's host resolver). With HostResolverProc you can specify the exact AddressList, making it possible to run tests requiring IPv6 socketaddrs on systems (like WinXP) that don't actually support it.
(3) Add a MockHostResolver implementation of HostResolver.
This replaces the [ScopedHostMapper + RuleBasedHostMapper + HostResolver] combo. It is less clunky and a bit more expressive.
BUG=http://crbug.com/16452
R=willchan
TEST=existing
Review URL: http://codereview.chromium.org/149511
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20795 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/socket/tcp_client_socket_pool_unittest.cc')
-rw-r--r-- | net/socket/tcp_client_socket_pool_unittest.cc | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/net/socket/tcp_client_socket_pool_unittest.cc b/net/socket/tcp_client_socket_pool_unittest.cc index 5d9e630..b5cce2c 100644 --- a/net/socket/tcp_client_socket_pool_unittest.cc +++ b/net/socket/tcp_client_socket_pool_unittest.cc @@ -6,7 +6,7 @@ #include "base/compiler_specific.h" #include "base/message_loop.h" -#include "net/base/host_resolver_unittest.h" +#include "net/base/mock_host_resolver.h" #include "net/base/net_errors.h" #include "net/base/test_completion_callback.h" #include "net/socket/client_socket.h" @@ -224,14 +224,16 @@ int TestSocketRequest::completion_count = 0; class TCPClientSocketPoolTest : public testing::Test { protected: TCPClientSocketPoolTest() - : pool_(new TCPClientSocketPool(kMaxSocketsPerGroup, - new HostResolver, - &client_socket_factory_)) {} + : host_resolver_(new MockHostResolver), + pool_(new TCPClientSocketPool(kMaxSocketsPerGroup, + host_resolver_, + &client_socket_factory_)) { + // We enable caching on the mock host-resolver (it is off by default), + // because some of the tests in this file expect it. + host_resolver_->Reset(NULL, 100, 60000); + } virtual void SetUp() { - RuleBasedHostMapper *host_mapper = new RuleBasedHostMapper(); - host_mapper->AddRule("*", "127.0.0.1"); - scoped_host_mapper_.Init(host_mapper); TestSocketRequest::completion_count = 0; } @@ -241,7 +243,7 @@ class TCPClientSocketPoolTest : public testing::Test { MessageLoop::current()->RunAllPending(); } - ScopedHostMapper scoped_host_mapper_; + scoped_refptr<MockHostResolver> host_resolver_; MockClientSocketFactory client_socket_factory_; scoped_refptr<ClientSocketPool> pool_; std::vector<TestSocketRequest*> request_order_; @@ -264,9 +266,7 @@ TEST_F(TCPClientSocketPoolTest, Basic) { } TEST_F(TCPClientSocketPoolTest, InitHostResolutionFailure) { - RuleBasedHostMapper* host_mapper = new RuleBasedHostMapper; - host_mapper->AddSimulatedFailure("unresolvable.host.name"); - ScopedHostMapper scoped_host_mapper(host_mapper); + host_resolver_->rules()->AddSimulatedFailure("unresolvable.host.name"); TestSocketRequest req(pool_.get(), &request_order_); HostResolver::RequestInfo info("unresolvable.host.name", 80); EXPECT_EQ(ERR_IO_PENDING, req.handle.Init("a", info, 5, &req)); |