summaryrefslogtreecommitdiffstats
path: root/chrome/test
diff options
context:
space:
mode:
authorericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-15 22:04:32 +0000
committerericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-15 22:04:32 +0000
commitb59ff376c5d5b950774fcbe65727611d51832b75 (patch)
treea37598ddd4e9ec0530d5820bcce1f47bafa89289 /chrome/test
parent89d70652ad0bb9e7f419c17516fad279d8a4db32 (diff)
downloadchromium_src-b59ff376c5d5b950774fcbe65727611d51832b75.zip
chromium_src-b59ff376c5d5b950774fcbe65727611d51832b75.tar.gz
chromium_src-b59ff376c5d5b950774fcbe65727611d51832b75.tar.bz2
Refactorings surrounding HostResolver:
(1) Extract HostResolver to an interface. The existing concrete implementation is now named HostResolverImpl. This makes it possible to create mocks with more complex behavior (i.e. choose via rules if response will be sync vs async). (2) Transform HostMapper into HostResolverProc. Conceptually HostResolverProc maps a hostname to a socket address, whereas HostMapper mapped a hostname to another hostname (so you were still at the mercy of the system's host resolver). With HostResolverProc you can specify the exact AddressList, making it possible to run tests requiring IPv6 socketaddrs on systems (like WinXP) that don't actually support it. (3) Add a MockHostResolver implementation of HostResolver. This replaces the [ScopedHostMapper + RuleBasedHostMapper + HostResolver] combo. It is less clunky and a bit more expressive. BUG=http://crbug.com/16452 R=willchan TEST=existing Review URL: http://codereview.chromium.org/149511 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20795 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test')
-rw-r--r--chrome/test/in_process_browser_test.cc19
-rw-r--r--chrome/test/in_process_browser_test.h10
-rw-r--r--chrome/test/unit/chrome_test_suite.h24
3 files changed, 28 insertions, 25 deletions
diff --git a/chrome/test/in_process_browser_test.cc b/chrome/test/in_process_browser_test.cc
index b43edd2..7544b49 100644
--- a/chrome/test/in_process_browser_test.cc
+++ b/chrome/test/in_process_browser_test.cc
@@ -26,7 +26,7 @@
#include "chrome/common/main_function_params.h"
#include "chrome/test/testing_browser_process.h"
#include "chrome/test/ui_test_utils.h"
-#include "net/base/host_resolver_unittest.h"
+#include "net/base/mock_host_resolver.h"
#include "sandbox/src/dep.h"
extern int BrowserMain(const MainFunctionParams&);
@@ -140,10 +140,11 @@ void InProcessBrowserTest::SetUp() {
params.ui_task =
NewRunnableMethod(this, &InProcessBrowserTest::RunTestOnMainThreadLoop);
- scoped_refptr<net::RuleBasedHostMapper> host_mapper(
- new net::RuleBasedHostMapper());
- ConfigureHostMapper(host_mapper.get());
- net::ScopedHostMapper scoped_host_mapper(host_mapper.get());
+ scoped_refptr<net::RuleBasedHostResolverProc> host_resolver_proc(
+ new net::RuleBasedHostResolverProc(NULL));
+ ConfigureHostResolverProc(host_resolver_proc);
+ net::ScopedDefaultHostResolverProc scoped_host_resolver_proc(
+ host_resolver_proc);
BrowserMain(params);
}
@@ -241,12 +242,12 @@ void InProcessBrowserTest::RunTestOnMainThreadLoop() {
MessageLoopForUI::current()->Quit();
}
-void InProcessBrowserTest::ConfigureHostMapper(
- net::RuleBasedHostMapper* host_mapper) {
- host_mapper->AllowDirectLookup("*.google.com");
+void InProcessBrowserTest::ConfigureHostResolverProc(
+ net::RuleBasedHostResolverProc* host_resolver_proc) {
+ host_resolver_proc->AllowDirectLookup("*.google.com");
// See http://en.wikipedia.org/wiki/Web_Proxy_Autodiscovery_Protocol
// We don't want the test code to use it.
- host_mapper->AddSimulatedFailure("wpad");
+ host_resolver_proc->AddSimulatedFailure("wpad");
}
void InProcessBrowserTest::TimedOut() {
diff --git a/chrome/test/in_process_browser_test.h b/chrome/test/in_process_browser_test.h
index bec71d9..11a2880 100644
--- a/chrome/test/in_process_browser_test.h
+++ b/chrome/test/in_process_browser_test.h
@@ -11,7 +11,7 @@
class Browser;
class Profile;
namespace net {
-class RuleBasedHostMapper;
+class RuleBasedHostResolverProc;
}
// Base class for tests wanting to bring up a browser in the unit test process.
@@ -66,10 +66,10 @@ class InProcessBrowserTest : public testing::Test {
// main thread before the browser is torn down.
virtual void CleanUpOnMainThread() {}
- // Allows subclasses to configure the host mapper. By default this blocks
- // requests to google.com as Chrome pings that on startup and we don't want to
- // do that during testing.
- virtual void ConfigureHostMapper(net::RuleBasedHostMapper* host_mapper);
+ // Allows subclasses to configure the host resolver procedure. By default
+ // this blocks requests to google.com as Chrome pings that on startup and we
+ // don't want to do that during testing.
+ virtual void ConfigureHostResolverProc(net::RuleBasedHostResolverProc* proc);
// Invoked when a test is not finishing in a timely manner.
void TimedOut();
diff --git a/chrome/test/unit/chrome_test_suite.h b/chrome/test/unit/chrome_test_suite.h
index 7c49d72..7f8733b 100644
--- a/chrome/test/unit/chrome_test_suite.h
+++ b/chrome/test/unit/chrome_test_suite.h
@@ -28,15 +28,17 @@
#include "chrome/common/mac_app_names.h"
#endif
#include "chrome/test/testing_browser_process.h"
-#include "net/base/host_resolver_unittest.h"
+#include "net/base/mock_host_resolver.h"
#include "net/base/net_util.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 {
+// so this host resolver procedure catches external queries.
+class WarningHostResolverProc : public net::HostResolverProc {
public:
- virtual std::string Map(const std::string& host) {
+ WarningHostResolverProc() : HostResolverProc(NULL) {}
+
+ virtual int Resolve(const std::string& host, net::AddressList* addrlist) {
const char* kLocalHostNames[] = {"localhost", "127.0.0.1"};
bool local = false;
@@ -51,11 +53,11 @@ class WarningHostMapper : public net::HostMapper {
}
// 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.
+ // If you really need to make real DNS query, use
+ // net::RuleBasedHostResolverProc and its AllowDirectLookup method.
EXPECT_TRUE(local) << "Making external DNS lookup of " << host;
- return MapUsingPrevious(host);
+ return ResolveUsingPrevious(host, addrlist);
}
};
@@ -71,8 +73,8 @@ class ChromeTestSuite : public TestSuite {
TestSuite::Initialize();
- host_mapper_ = new WarningHostMapper();
- scoped_host_mapper_.Init(host_mapper_.get());
+ host_resolver_proc_ = new WarningHostResolverProc();
+ scoped_host_resolver_proc_.Init(host_resolver_proc_.get());
chrome::RegisterPathProvider();
app::RegisterPathProvider();
@@ -140,8 +142,8 @@ class ChromeTestSuite : public TestSuite {
StatsTable* stats_table_;
ScopedOleInitializer ole_initializer_;
- scoped_refptr<WarningHostMapper> host_mapper_;
- net::ScopedHostMapper scoped_host_mapper_;
+ scoped_refptr<WarningHostResolverProc> host_resolver_proc_;
+ net::ScopedDefaultHostResolverProc scoped_host_resolver_proc_;
};
#endif // CHROME_TEST_UNIT_CHROME_TEST_SUITE_H_