summaryrefslogtreecommitdiffstats
path: root/net/base/host_resolver.h
diff options
context:
space:
mode:
authordarin@google.com <darin@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-09-24 06:31:34 +0000
committerdarin@google.com <darin@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-09-24 06:31:34 +0000
commit025517044b4be3ab45efc2f383e5a7b830aa7281 (patch)
treeb43566625f0702e8fa44590a7a82b3c41b56b5cc /net/base/host_resolver.h
parent8943d1c09b155984790847a849e816ffe695a91a (diff)
downloadchromium_src-025517044b4be3ab45efc2f383e5a7b830aa7281.zip
chromium_src-025517044b4be3ab45efc2f383e5a7b830aa7281.tar.gz
chromium_src-025517044b4be3ab45efc2f383e5a7b830aa7281.tar.bz2
Add support for mock DNS queries. This allows us to eliminate
flaky DNS queries from the unit tests. Note: some unit tests still connect to www.google.com. My plan is to resolve those in a subsequent CL. R=wtc BUG=2635 Review URL: http://codereview.chromium.org/4022 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@2545 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base/host_resolver.h')
-rw-r--r--net/base/host_resolver.h24
1 files changed, 24 insertions, 0 deletions
diff --git a/net/base/host_resolver.h b/net/base/host_resolver.h
index 5364d17..1f649f8 100644
--- a/net/base/host_resolver.h
+++ b/net/base/host_resolver.h
@@ -55,6 +55,30 @@ class HostResolver {
DISALLOW_COPY_AND_ASSIGN(HostResolver);
};
+// A helper class used in unit tests to alter hostname mappings. See
+// SetHostMapper for details.
+class HostMapper {
+ public:
+ virtual ~HostMapper() {}
+ virtual std::string Map(const std::string& host) = 0;
+};
+
+#ifdef UNIT_TEST
+// This function is designed to allow unit tests to override the behavior of
+// HostResolver. For example, a HostMapper instance can force all hostnames
+// to map to a fixed IP address such as 127.0.0.1.
+//
+// The previously set HostMapper (or NULL if there was none) is returned.
+//
+// NOTE: This function is not thread-safe, so take care to only call this
+// function while there are no outstanding HostResolver instances.
+//
+// NOTE: In most cases, you should use ScopedHostMapper instead, which is
+// defined in host_resolver_unittest.h
+//
+HostMapper* SetHostMapper(HostMapper* host_mapper);
+#endif
+
} // namespace net
#endif // NET_BASE_HOST_RESOLVER_H_