Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(86)

Unified Diff: net/base/host_resolver_unittest.h

Issue 45026: Prevent making real DNS lookups by chrome tests. (Closed)
Patch Set: simplified Created 11 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/base/host_resolver.cc ('k') | net/base/ssl_client_socket_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/host_resolver_unittest.h
diff --git a/net/base/host_resolver_unittest.h b/net/base/host_resolver_unittest.h
index e7a9c1ad601c0a5f7c2aa89f72395fabc2e11228..f4c58549e4c1618083da92f61f05d5d3267629dc 100644
--- a/net/base/host_resolver_unittest.h
+++ b/net/base/host_resolver_unittest.h
@@ -51,8 +51,18 @@ class RuleBasedHostMapper : public HostMapper {
rules_.push_back(Rule(host_pattern, replacement, latency));
}
- private:
- std::string Map(const std::string& host) {
+ // Make sure that |host| will not be re-mapped or even processed by underlying
+ // host mappers. It can also be a pattern.
+ void AllowDirectLookup(const char* host) {
+ rules_.push_back(Rule(host, "", true));
+ }
+
+ // Simulate a lookup failure for |host| (it also can be a pattern).
+ void AddSimulatedFailure(const char* host) {
+ AddRule(host, "");
+ }
+
+ virtual std::string Map(const std::string& host) {
RuleList::iterator r;
for (r = rules_.begin(); r != rules_.end(); ++r) {
if (MatchPattern(host, r->host_pattern)) {
@@ -60,27 +70,36 @@ class RuleBasedHostMapper : public HostMapper {
PlatformThread::Sleep(r->latency);
r->latency = 1; // Simulate cache warmup.
}
- return r->replacement;
+ return r->direct ? host : r->replacement;
}
}
+
return MapUsingPrevious(host);
}
+ private:
struct Rule {
std::string host_pattern;
std::string replacement;
int latency; // in milliseconds
+ bool direct; // if true, don't mangle hostname and ignore replacement
Rule(const char* h, const char* r)
: host_pattern(h),
replacement(r),
- latency(0) {}
+ latency(0),
+ direct(false) {}
Rule(const char* h, const char* r, const int l)
: host_pattern(h),
replacement(r),
- latency(l) {}
+ latency(l),
+ direct(false) {}
+ Rule(const char* h, const char* r, const bool d)
+ : host_pattern(h),
+ replacement(r),
+ latency(0),
+ direct(d) {}
};
typedef std::list<Rule> RuleList;
-
RuleList rules_;
};
@@ -104,7 +123,7 @@ class WaitingHostMapper : public HostMapper {
}
private:
- std::string Map(const std::string& host) {
+ virtual std::string Map(const std::string& host) {
event_.Wait();
return MapUsingPrevious(host);
}
« no previous file with comments | « net/base/host_resolver.cc ('k') | net/base/ssl_client_socket_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698