summaryrefslogtreecommitdiffstats
path: root/net/base/mock_host_resolver.h
diff options
context:
space:
mode:
authorericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-18 07:31:04 +0000
committerericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-18 07:31:04 +0000
commita2c2fb9ff48cd37dbed258dca5b40461c92b71a8 (patch)
tree4526d3db799c1e1f49b1f5387d8d8b267f006a5a /net/base/mock_host_resolver.h
parenteb5f5505a0b430c27f64c44f4928a0a50faf5f3d (diff)
downloadchromium_src-a2c2fb9ff48cd37dbed258dca5b40461c92b71a8.zip
chromium_src-a2c2fb9ff48cd37dbed258dca5b40461c92b71a8.tar.gz
chromium_src-a2c2fb9ff48cd37dbed258dca5b40461c92b71a8.tar.bz2
Add synchronous-mode operation to MockHostResolver; this helps clarify some tests, which were using caching to get synchronous resolutions.TEST=existingBUG=NONE (addresses a TODO however).
Review URL: http://codereview.chromium.org/155620 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@21052 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base/mock_host_resolver.h')
-rw-r--r--net/base/mock_host_resolver.h40
1 files changed, 30 insertions, 10 deletions
diff --git a/net/base/mock_host_resolver.h b/net/base/mock_host_resolver.h
index ee83105..1d29684 100644
--- a/net/base/mock_host_resolver.h
+++ b/net/base/mock_host_resolver.h
@@ -34,14 +34,11 @@ class RuleBasedHostResolverProc;
//
// Replacement doesn't have to be string representing an IP address. It can
// re-map one hostname to another as well.
-class MockHostResolver : public HostResolver {
- public:
- // Creates a MockHostResolver that does NOT cache entries
- // (the HostResolverProc will be called for every lookup). If you need
- // caching behavior, call Reset() with non-zero cache size.
- MockHostResolver();
- virtual ~MockHostResolver() {}
+// Base class shared by MockHostResolver and MockCachingHostResolver.
+class MockHostResolverBase : public HostResolver {
+ public:
+ virtual ~MockHostResolverBase() {}
// HostResolver methods:
virtual int Resolve(const RequestInfo& info, AddressList* addresses,
@@ -54,14 +51,37 @@ class MockHostResolver : public HostResolver {
RuleBasedHostResolverProc* rules() { return rules_; }
+ // Controls whether resolutions complete synchronously or asynchronously.
+ void set_synchronous_mode(bool is_synchronous) {
+ synchronous_mode_ = is_synchronous;
+ }
+
// Resets the mock.
- void Reset(HostResolverProc* interceptor,
- int max_cache_entries,
- int max_cache_age_ms);
+ void Reset(HostResolverProc* interceptor);
+
+ protected:
+ MockHostResolverBase(bool use_caching);
private:
scoped_refptr<HostResolverImpl> impl_;
scoped_refptr<RuleBasedHostResolverProc> rules_;
+ bool synchronous_mode_;
+ bool use_caching_;
+};
+
+class MockHostResolver : public MockHostResolverBase {
+ public:
+ MockHostResolver() : MockHostResolverBase(false /*use_caching*/) {}
+};
+
+// Same as MockHostResolver, except internally it uses a host-cache.
+//
+// Note that tests are advised to use MockHostResolver instead, since it is
+// more predictable. (MockHostResolver also can be put into synchronous
+// operation mode in case that is what you needed from the caching version).
+class MockCachingHostResolver : public MockHostResolverBase {
+ public:
+ MockCachingHostResolver() : MockHostResolverBase(true /*use_caching*/) {}
};
// RuleBasedHostResolverProc applies a set of rules to map a host string to