summaryrefslogtreecommitdiffstats
path: root/net/base/host_resolver_unittest.h
diff options
context:
space:
mode:
authordarin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-09-24 18:34:35 +0000
committerdarin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-09-24 18:34:35 +0000
commit2d3baf01ef4f8ec59e7be0e253158dfdb2a98a35 (patch)
tree47b26732ab7c34a6fd961690ee3a755e33c877f9 /net/base/host_resolver_unittest.h
parente16d397e25dd8a0a3f07e81528c1f9619051cf19 (diff)
downloadchromium_src-2d3baf01ef4f8ec59e7be0e253158dfdb2a98a35.zip
chromium_src-2d3baf01ef4f8ec59e7be0e253158dfdb2a98a35.tar.gz
chromium_src-2d3baf01ef4f8ec59e7be0e253158dfdb2a98a35.tar.bz2
Apply minor tweaks to ScopedHostMapper per review feedback.
R=wtc Review URL: http://codereview.chromium.org/4253 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@2557 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base/host_resolver_unittest.h')
-rw-r--r--net/base/host_resolver_unittest.h86
1 files changed, 0 insertions, 86 deletions
diff --git a/net/base/host_resolver_unittest.h b/net/base/host_resolver_unittest.h
deleted file mode 100644
index c7ecea81..0000000
--- a/net/base/host_resolver_unittest.h
+++ /dev/null
@@ -1,86 +0,0 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// This file defines ScopedHostMapper, which is a helper class for writing
-// tests that use HostResolver either directly or indirectly.
-//
-// In most cases, it is important that unit tests avoid making actual DNS
-// queries since the resulting tests can be flaky, especially if the network is
-// unreliable for some reason. To simplify writing tests that avoid making
-// actual DNS queries, the following helper class may be used:
-//
-// ScopedHostMapper scoped_host_mapper;
-// scoped_host_mapper.AddRule("foo.com", "1.2.3.4");
-// scoped_host_mapper.AddRule("bar.com", "2.3.4.5");
-// ...
-//
-// The above rules define a static mapping from hostnames to IP address
-// literals. The first parameter to AddRule specifies a host pattern to match
-// against, and the second parameter indicates what value should be used to
-// replace the given hostname. So, the following is also supported:
-//
-// scoped_host_mapper.AddRule("*.com", "127.0.0.1");
-//
-// If there are multiple ScopedHostMappers on the stack, then the last one
-// allocated will be used. However, if it does not provide a matching rule,
-// then it will delegate to the previously allocated ScopedHostMapper.
-// Finally, if no HostMapper matches a given hostname, then the hostname will
-// be unmodified.
-
-#ifndef NET_BASE_HOST_RESOLVER_UNITTEST_H_
-#define NET_BASE_HOST_RESOLVER_UNITTEST_H_
-
-#ifdef UNIT_TEST
-
-#include <list>
-
-#include "base/string_util.h"
-#include "net/base/host_resolver.h"
-#include "net/base/net_errors.h"
-
-namespace net {
-
-// This class sets the HostResolverProc for a particular scope.
-class ScopedHostMapper : public HostMapper {
- public:
- ScopedHostMapper() {
- previous_host_mapper_ = SetHostMapper(this);
- }
-
- ~ScopedHostMapper() {
- SetHostMapper(previous_host_mapper_);
- }
-
- // Any hostname matching the given pattern will be replaced with the given
- // replacement value. Usually, replacement should be an IP address literal.
- void AddRule(const char* host_pattern, const char* replacement) {
- rules_.push_back(Rule(host_pattern, replacement));
- }
-
- private:
- std::string Map(const std::string& host) {
- RuleList::const_iterator r;
- for (r = rules_.begin(); r != rules_.end(); ++r) {
- if (MatchPattern(host, r->host_pattern))
- return r->replacement;
- }
- return previous_host_mapper_ ? previous_host_mapper_->Map(host) : host;
- }
-
- struct Rule {
- std::string host_pattern;
- std::string replacement;
- Rule(const char* h, const char* r) : host_pattern(h), replacement(r) {}
- };
- typedef std::list<Rule> RuleList;
-
- HostMapper* previous_host_mapper_;
- RuleList rules_;
-};
-
-} // namespace net
-
-#endif // UNIT_TEST
-
-#endif // NET_BASE_HOST_RESOLVER_UNITTEST_H_