summaryrefslogtreecommitdiffstats
path: root/chrome/test/unit/chrome_test_suite.h
diff options
context:
space:
mode:
authorphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-27 16:22:26 +0000
committerphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-27 16:22:26 +0000
commit5e05717cbf0ff0fe8d3396522b07e8e23de21604 (patch)
tree50f714711c6a4e404730e75f4bf46d5a1d6282d9 /chrome/test/unit/chrome_test_suite.h
parent80847f3446c37f784fbd724fc11f099d40ebe14c (diff)
downloadchromium_src-5e05717cbf0ff0fe8d3396522b07e8e23de21604.zip
chromium_src-5e05717cbf0ff0fe8d3396522b07e8e23de21604.tar.gz
chromium_src-5e05717cbf0ff0fe8d3396522b07e8e23de21604.tar.bz2
Prevent making real DNS lookups by chrome tests.
- by default a test which makes external DNS lookup directly or indirectly will fail - added a quite simple way to allow a test to make external queries - added a way to make external queries fail (for tests which don't need them to succeed but it's hard to not make the query) - made neccessary adjustments to existing tests so that they still pass http://crbug.com/9109 Review URL: http://codereview.chromium.org/45026 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@12653 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test/unit/chrome_test_suite.h')
-rw-r--r--chrome/test/unit/chrome_test_suite.h30
1 files changed, 30 insertions, 0 deletions
diff --git a/chrome/test/unit/chrome_test_suite.h b/chrome/test/unit/chrome_test_suite.h
index 8dcdbf6..1d7947f 100644
--- a/chrome/test/unit/chrome_test_suite.h
+++ b/chrome/test/unit/chrome_test_suite.h
@@ -13,6 +13,7 @@
#include "base/mac_util.h"
#endif
#include "base/path_service.h"
+#include "base/ref_counted.h"
#include "base/scoped_nsautorelease_pool.h"
#include "base/test_suite.h"
#include "chrome/app/scoped_ole_initializer.h"
@@ -21,6 +22,30 @@
#include "chrome/common/chrome_switches.h"
#include "chrome/common/resource_bundle.h"
#include "chrome/test/testing_browser_process.h"
+#include "net/base/host_resolver_unittest.h"
+
+// 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 mapper catches external queries.
+class WarningHostMapper : public net::HostMapper {
+ public:
+ virtual std::string Map(const std::string& host) {
+ const char* kLocalHostNames[] = {"localhost", "127.0.0.1"};
+ bool local = false;
+ for (size_t i = 0; i < arraysize(kLocalHostNames); i++)
+ if (host == kLocalHostNames[i]) {
+ local = true;
+ break;
+ }
+
+ // Make the test fail so it's harder to ignore.
+ // If you really need to make real DNS query, use net::RuleBasedHostMapper
+ // and its AllowDirectLookup method.
+ EXPECT_TRUE(local) << "Making external DNS lookup of " << host;
+
+ return MapUsingPrevious(host);
+ }
+};
class ChromeTestSuite : public TestSuite {
public:
@@ -34,6 +59,9 @@ protected:
TestSuite::Initialize();
+ host_mapper_ = new WarningHostMapper();
+ scoped_host_mapper_.Init(host_mapper_.get());
+
chrome::RegisterPathProvider();
g_browser_process = new TestingBrowserProcess;
@@ -90,6 +118,8 @@ protected:
StatsTable* stats_table_;
ScopedOleInitializer ole_initializer_;
+ scoped_refptr<WarningHostMapper> host_mapper_;
+ net::ScopedHostMapper scoped_host_mapper_;
};
#endif // CHROME_TEST_UNIT_CHROME_TEST_SUITE_H_