summaryrefslogtreecommitdiffstats
path: root/chrome/test/unit
diff options
context:
space:
mode:
authorisherman@chromium.org <isherman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-05 00:45:22 +0000
committerisherman@chromium.org <isherman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-05 00:45:22 +0000
commitc4566249d7c9ebffc4a0f4c53eb7bdf086a7773c (patch)
tree439132f4c12b9285197657b4c86b2bc69ea35af5 /chrome/test/unit
parent7e412003eabecd5987073bbe0496bd500ad4ab39 (diff)
downloadchromium_src-c4566249d7c9ebffc4a0f4c53eb7bdf086a7773c.zip
chromium_src-c4566249d7c9ebffc4a0f4c53eb7bdf086a7773c.tar.gz
chromium_src-c4566249d7c9ebffc4a0f4c53eb7bdf086a7773c.tar.bz2
Automatically fail external DNS queries in tests, but don't abort the test.
Test code should not go out of its way to disable external DNS queries, so we should not cause tests to fail when such queries are made. However, to avoid external depenencies in tests, we simulate failure for the queries themselves. See http://codereview.chromium.org/3396022/show for some backstory. BUG=none TEST=none Review URL: http://codereview.chromium.org/3535003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@61456 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test/unit')
-rw-r--r--chrome/test/unit/chrome_test_suite.cc31
-rw-r--r--chrome/test/unit/chrome_test_suite.h11
2 files changed, 25 insertions, 17 deletions
diff --git a/chrome/test/unit/chrome_test_suite.cc b/chrome/test/unit/chrome_test_suite.cc
index 016e582..5f8d911 100644
--- a/chrome/test/unit/chrome_test_suite.cc
+++ b/chrome/test/unit/chrome_test_suite.cc
@@ -18,6 +18,7 @@
#include "chrome/common/url_constants.h"
#include "chrome/test/test_timeouts.h"
#include "chrome/test/testing_browser_process.h"
+#include "net/base/net_errors.h"
#if defined(OS_MACOSX)
#include "base/mac_util.h"
@@ -36,19 +37,19 @@ static void RemoveSharedMemoryFile(const std::string& filename) {
#endif
}
-WarningHostResolverProc::WarningHostResolverProc()
+LocalHostResolverProc::LocalHostResolverProc()
: HostResolverProc(NULL) {
}
-WarningHostResolverProc::~WarningHostResolverProc() {
+LocalHostResolverProc::~LocalHostResolverProc() {
}
-int WarningHostResolverProc::Resolve(const std::string& host,
- net::AddressFamily address_family,
- net::HostResolverFlags host_resolver_flags,
- net::AddressList* addrlist,
- int* os_error) {
- const char* kLocalHostNames[] = {"localhost", "127.0.0.1"};
+int LocalHostResolverProc::Resolve(const std::string& host,
+ net::AddressFamily address_family,
+ net::HostResolverFlags host_resolver_flags,
+ net::AddressList* addrlist,
+ int* os_error) {
+ const char* kLocalHostNames[] = {"localhost", "127.0.0.1", "::1"};
bool local = false;
if (host == net::GetHostName()) {
@@ -61,10 +62,16 @@ int WarningHostResolverProc::Resolve(const std::string& host,
}
}
- // Make the test fail so it's harder to ignore.
- // If you really need to make real DNS query, use
+ // To avoid depending on external resources and to reduce (if not preclude)
+ // network interactions from tests, we simulate failure for non-local DNS
+ // queries, rather than perform them.
+ // If you really need to make an external DNS query, use
// net::RuleBasedHostResolverProc and its AllowDirectLookup method.
- EXPECT_TRUE(local) << "Making external DNS lookup of " << host;
+ if (!local) {
+ DLOG(INFO) << "To avoid external dependencies, simulating failure for "
+ << "external DNS lookup of " << host;
+ return net::ERR_NOT_IMPLEMENTED;
+ }
return ResolveUsingPrevious(host, address_family, host_resolver_flags,
addrlist, os_error);
@@ -84,7 +91,7 @@ void ChromeTestSuite::Initialize() {
base::TestSuite::Initialize();
chrome::RegisterChromeSchemes();
- host_resolver_proc_ = new WarningHostResolverProc();
+ host_resolver_proc_ = new LocalHostResolverProc();
scoped_host_resolver_proc_.Init(host_resolver_proc_.get());
chrome::RegisterPathProvider();
diff --git a/chrome/test/unit/chrome_test_suite.h b/chrome/test/unit/chrome_test_suite.h
index e9c76f1..7f63c4e 100644
--- a/chrome/test/unit/chrome_test_suite.h
+++ b/chrome/test/unit/chrome_test_suite.h
@@ -23,11 +23,12 @@ class StatsTable;
// In many cases it may be not obvious that a test makes a real DNS lookup.
// We generally don't want to rely on external DNS servers for our tests,
-// so this host resolver procedure catches external queries.
-class WarningHostResolverProc : public net::HostResolverProc {
+// so this host resolver procedure catches external queries and returns a failed
+// lookup result.
+class LocalHostResolverProc : public net::HostResolverProc {
public:
- WarningHostResolverProc();
- virtual ~WarningHostResolverProc();
+ LocalHostResolverProc();
+ virtual ~LocalHostResolverProc();
virtual int Resolve(const std::string& host,
net::AddressFamily address_family,
@@ -58,7 +59,7 @@ class ChromeTestSuite : public base::TestSuite {
FilePath browser_dir_;
ScopedOleInitializer ole_initializer_;
- scoped_refptr<WarningHostResolverProc> host_resolver_proc_;
+ scoped_refptr<LocalHostResolverProc> host_resolver_proc_;
net::ScopedDefaultHostResolverProc scoped_host_resolver_proc_;
};