diff options
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/browser_unittest.cc | 20 | ||||
-rw-r--r-- | chrome/browser/net/dns_global.cc | 6 | ||||
-rw-r--r-- | chrome/browser/net/dns_master_unittest.cc | 88 | ||||
-rw-r--r-- | chrome/browser/search_engines/template_url_scraper_unittest.cc | 8 | ||||
-rw-r--r-- | chrome/test/in_process_browser_test.cc | 19 | ||||
-rw-r--r-- | chrome/test/in_process_browser_test.h | 10 | ||||
-rw-r--r-- | chrome/test/unit/chrome_test_suite.h | 24 |
7 files changed, 87 insertions, 88 deletions
diff --git a/chrome/browser/browser_unittest.cc b/chrome/browser/browser_unittest.cc index 1ef86da..702d1dce 100644 --- a/chrome/browser/browser_unittest.cc +++ b/chrome/browser/browser_unittest.cc @@ -4,21 +4,21 @@ #include "chrome/browser/browser.h" #include "chrome/test/in_process_browser_test.h" -#include "net/base/host_resolver_unittest.h" +#include "net/base/mock_host_resolver.h" class BrowserTest : public InProcessBrowserTest { public: BrowserTest() { - host_mapper_ = new net::RuleBasedHostMapper(); + host_resolver_proc_ = new net::RuleBasedHostResolverProc(NULL); // Avoid making external DNS lookups. In this test we don't need this // to succeed. - host_mapper_->AddSimulatedFailure("*.google.com"); - scoped_host_mapper_.Init(host_mapper_.get()); + host_resolver_proc_->AddSimulatedFailure("*.google.com"); + scoped_host_resolver_proc_.Init(host_resolver_proc_.get()); } private: - scoped_refptr<net::RuleBasedHostMapper> host_mapper_; - net::ScopedHostMapper scoped_host_mapper_; + scoped_refptr<net::RuleBasedHostResolverProc> host_resolver_proc_; + net::ScopedDefaultHostResolverProc scoped_host_resolver_proc_; }; /* @@ -38,7 +38,7 @@ IN_PROC_BROWSER_TEST_F(BrowserTest, NoTabsInPopups) { // Now try opening another tab in the popup browser. popup_browser->AddTabWithURL(GURL("about:blank"), GURL(), PageTransition::TYPED, true, -1, NULL); - + // The popup should still only have one tab. EXPECT_EQ(1, popup_browser->tab_count()); @@ -54,7 +54,7 @@ IN_PROC_BROWSER_TEST_F(BrowserTest, NoTabsInPopups) { // Now try opening another tab in the app browser. app_browser->AddTabWithURL(GURL("about:blank"), GURL(), PageTransition::TYPED, true, -1, NULL); - + // The popup should still only have one tab. EXPECT_EQ(1, app_browser->tab_count()); @@ -70,7 +70,7 @@ IN_PROC_BROWSER_TEST_F(BrowserTest, NoTabsInPopups) { // Now try opening another tab in the app popup browser. app_popup_browser->AddTabWithURL(GURL("about:blank"), GURL(), PageTransition::TYPED, true, -1, NULL); - + // The popup should still only have one tab. EXPECT_EQ(1, app_popup_browser->tab_count()); @@ -82,4 +82,4 @@ IN_PROC_BROWSER_TEST_F(BrowserTest, NoTabsInPopups) { app_browser->CloseAllTabs(); app_popup_browser->CloseAllTabs(); } -*/
\ No newline at end of file +*/ diff --git a/chrome/browser/net/dns_global.cc b/chrome/browser/net/dns_global.cc index d18ea45..25829e7 100644 --- a/chrome/browser/net/dns_global.cc +++ b/chrome/browser/net/dns_global.cc @@ -476,11 +476,7 @@ static void DiscardAllPrefetchState() { net::HostResolver* GetGlobalHostResolver() { // Called from UI thread. if (!global_host_resolver) { - static const size_t kMaxHostCacheEntries = 100; - static const size_t kHostCacheExpirationSeconds = 60; // 1 minute. - - global_host_resolver = new net::HostResolver( - kMaxHostCacheEntries, kHostCacheExpirationSeconds * 1000); + global_host_resolver = net::CreateSystemHostResolver(); } return global_host_resolver; } diff --git a/chrome/browser/net/dns_master_unittest.cc b/chrome/browser/net/dns_master_unittest.cc index 61ffd68..c3746bb 100644 --- a/chrome/browser/net/dns_master_unittest.cc +++ b/chrome/browser/net/dns_master_unittest.cc @@ -10,13 +10,13 @@ #include "base/message_loop.h" #include "base/scoped_ptr.h" +#include "base/string_util.h" #include "base/timer.h" #include "chrome/browser/net/dns_global.h" #include "chrome/browser/net/dns_host_info.h" #include "chrome/common/net/dns.h" #include "net/base/address_list.h" -#include "net/base/host_resolver.h" -#include "net/base/host_resolver_unittest.h" +#include "net/base/mock_host_resolver.h" #include "net/base/winsock_init.h" #include "testing/gtest/include/gtest/gtest.h" @@ -59,10 +59,9 @@ class WaitForResolutionHelper { class DnsMasterTest : public testing::Test { public: DnsMasterTest() - : mapper_(new net::RuleBasedHostMapper()), + : host_resolver_(new net::MockHostResolver()), default_max_queueing_delay_(TimeDelta::FromMilliseconds( - DnsPrefetcherInit::kMaxQueueingDelayMs)), - scoped_mapper_(mapper_.get()) { + DnsPrefetcherInit::kMaxQueueingDelayMs)) { } protected: @@ -70,10 +69,11 @@ class DnsMasterTest : public testing::Test { #if defined(OS_WIN) net::EnsureWinsockInit(); #endif - mapper_->AddRuleWithLatency("www.google.com", "127.0.0.1", 50); - mapper_->AddRuleWithLatency("gmail.google.com.com", "127.0.0.1", 70); - mapper_->AddRuleWithLatency("mail.google.com", "127.0.0.1", 44); - mapper_->AddRuleWithLatency("gmail.com", "127.0.0.1", 63); + net::RuleBasedHostResolverProc* rules = host_resolver_->rules(); + rules->AddRuleWithLatency("www.google.com", "127.0.0.1", 50); + rules->AddRuleWithLatency("gmail.google.com.com", "127.0.0.1", 70); + rules->AddRuleWithLatency("mail.google.com", "127.0.0.1", 44); + rules->AddRuleWithLatency("gmail.com", "127.0.0.1", 63); } void WaitForResolution(DnsMaster* master, const NameList& hosts) { @@ -84,15 +84,18 @@ class DnsMasterTest : public testing::Test { MessageLoop::current()->Run(); } - scoped_refptr<net::RuleBasedHostMapper> mapper_; + private: + // IMPORTANT: do not move this below |host_resolver_|; the host resolver + // must not outlive the message loop, otherwise bad things can happen + // (like posting to a deleted message loop). + MessageLoop loop; + + protected: + scoped_refptr<net::MockHostResolver> host_resolver_; // Shorthand to access TimeDelta of DnsPrefetcherInit::kMaxQueueingDelayMs. // (It would be a static constant... except style rules preclude that :-/ ). const TimeDelta default_max_queueing_delay_; - - private: - MessageLoop loop; - net::ScopedHostMapper scoped_mapper_; }; //------------------------------------------------------------------------------ @@ -113,15 +116,15 @@ static std::string GetNonexistantDomain() { //------------------------------------------------------------------------------ // Use a blocking function to contrast results we get via async services. //------------------------------------------------------------------------------ -TimeDelta BlockingDnsLookup(const std::string& hostname) { - Time start = Time::Now(); +TimeDelta BlockingDnsLookup(net::HostResolver* resolver, + const std::string& hostname) { + Time start = Time::Now(); - scoped_refptr<net::HostResolver> resolver(new net::HostResolver); - net::AddressList addresses; - net::HostResolver::RequestInfo info(hostname, 80); - resolver->Resolve(info, &addresses, NULL, NULL); + net::AddressList addresses; + net::HostResolver::RequestInfo info(hostname, 80); + resolver->Resolve(info, &addresses, NULL, NULL); - return Time::Now() - start; + return Time::Now() - start; } //------------------------------------------------------------------------------ @@ -129,7 +132,9 @@ TimeDelta BlockingDnsLookup(const std::string& hostname) { // First test to be sure the OS is caching lookups, which is the whole premise // of DNS prefetching. TEST_F(DnsMasterTest, OsCachesLookupsTest) { - mapper_->AllowDirectLookup("*.google.com"); + // Make sure caching is disabled in the mock host resolver. + host_resolver_->Reset(NULL, 0, 0); + host_resolver_->rules()->AllowDirectLookup("*.google.com"); const Time start = Time::Now(); int all_lookups = 0; @@ -140,13 +145,13 @@ TEST_F(DnsMasterTest, OsCachesLookupsTest) { std::string badname; badname = GetNonexistantDomain(); - TimeDelta duration = BlockingDnsLookup(badname); + TimeDelta duration = BlockingDnsLookup(host_resolver_, badname); // Produce more than one result and remove the largest one // to reduce flakiness. std::vector<TimeDelta> cached_results; for (int j = 0; j < 3; j++) - cached_results.push_back(BlockingDnsLookup(badname)); + cached_results.push_back(BlockingDnsLookup(host_resolver_, badname)); std::sort(cached_results.begin(), cached_results.end()); cached_results.pop_back(); @@ -168,14 +173,14 @@ TEST_F(DnsMasterTest, OsCachesLookupsTest) { } TEST_F(DnsMasterTest, StartupShutdownTest) { - scoped_refptr<DnsMaster> testing_master = new DnsMaster(new net::HostResolver, + scoped_refptr<DnsMaster> testing_master = new DnsMaster(host_resolver_, MessageLoop::current(), default_max_queueing_delay_, DnsPrefetcherInit::kMaxConcurrentLookups); testing_master->Shutdown(); } TEST_F(DnsMasterTest, BenefitLookupTest) { - scoped_refptr<DnsMaster> testing_master = new DnsMaster(new net::HostResolver, + scoped_refptr<DnsMaster> testing_master = new DnsMaster(host_resolver_, MessageLoop::current(), default_max_queueing_delay_, DnsPrefetcherInit::kMaxConcurrentLookups); @@ -236,10 +241,11 @@ TEST_F(DnsMasterTest, BenefitLookupTest) { } TEST_F(DnsMasterTest, ShutdownWhenResolutionIsPendingTest) { - scoped_refptr<net::WaitingHostMapper> mapper = new net::WaitingHostMapper(); - net::ScopedHostMapper scoped_mapper(mapper.get()); + scoped_refptr<net::WaitingHostResolverProc> resolver_proc = + new net::WaitingHostResolverProc(NULL); + host_resolver_->Reset(resolver_proc, 0, 0); - scoped_refptr<DnsMaster> testing_master = new DnsMaster(new net::HostResolver, + scoped_refptr<DnsMaster> testing_master = new DnsMaster(host_resolver_, MessageLoop::current(), default_max_queueing_delay_, DnsPrefetcherInit::kMaxConcurrentLookups); @@ -258,12 +264,12 @@ TEST_F(DnsMasterTest, ShutdownWhenResolutionIsPendingTest) { testing_master->Shutdown(); // Clean up after ourselves. - mapper->Signal(); + resolver_proc->Signal(); MessageLoop::current()->RunAllPending(); } TEST_F(DnsMasterTest, SingleLookupTest) { - scoped_refptr<DnsMaster> testing_master = new DnsMaster(new net::HostResolver, + scoped_refptr<DnsMaster> testing_master = new DnsMaster(host_resolver_, MessageLoop::current(), default_max_queueing_delay_, DnsPrefetcherInit::kMaxConcurrentLookups); @@ -291,9 +297,9 @@ TEST_F(DnsMasterTest, SingleLookupTest) { } TEST_F(DnsMasterTest, ConcurrentLookupTest) { - mapper_->AddSimulatedFailure("*.notfound"); + host_resolver_->rules()->AddSimulatedFailure("*.notfound"); - scoped_refptr<DnsMaster> testing_master = new DnsMaster(new net::HostResolver, + scoped_refptr<DnsMaster> testing_master = new DnsMaster(host_resolver_, MessageLoop::current(), default_max_queueing_delay_, DnsPrefetcherInit::kMaxConcurrentLookups); @@ -313,12 +319,6 @@ TEST_F(DnsMasterTest, ConcurrentLookupTest) { names.insert(names.end(), goog4); names.insert(names.end(), goog); - // Warm up the *OS* cache for all the goog domains. - BlockingDnsLookup(goog); - BlockingDnsLookup(goog2); - BlockingDnsLookup(goog3); - BlockingDnsLookup(goog4); - // Try to flood the master with many concurrent requests. for (int i = 0; i < 10; i++) testing_master->ResolveList(names, DnsHostInfo::PAGE_SCAN_MOTIVATED); @@ -346,9 +346,9 @@ TEST_F(DnsMasterTest, ConcurrentLookupTest) { } TEST_F(DnsMasterTest, DISABLED_MassiveConcurrentLookupTest) { - mapper_->AddSimulatedFailure("*.notfound"); + host_resolver_->rules()->AddSimulatedFailure("*.notfound"); - scoped_refptr<DnsMaster> testing_master = new DnsMaster(new net::HostResolver, + scoped_refptr<DnsMaster> testing_master = new DnsMaster(host_resolver_, MessageLoop::current(), default_max_queueing_delay_, DnsPrefetcherInit::kMaxConcurrentLookups); @@ -453,7 +453,7 @@ int GetLatencyFromSerialization(const std::string& motivation, // Make sure nil referral lists really have no entries, and no latency listed. TEST_F(DnsMasterTest, ReferrerSerializationNilTest) { - scoped_refptr<DnsMaster> master = new DnsMaster(new net::HostResolver, + scoped_refptr<DnsMaster> master = new DnsMaster(host_resolver_, MessageLoop::current(), default_max_queueing_delay_, DnsPrefetcherInit::kMaxConcurrentLookups); ListValue referral_list; @@ -469,7 +469,7 @@ TEST_F(DnsMasterTest, ReferrerSerializationNilTest) { // deserialized into the database, and can be extracted back out via // serialization without being changed. TEST_F(DnsMasterTest, ReferrerSerializationSingleReferrerTest) { - scoped_refptr<DnsMaster> master = new DnsMaster(new net::HostResolver, + scoped_refptr<DnsMaster> master = new DnsMaster(host_resolver_, MessageLoop::current(), default_max_queueing_delay_, DnsPrefetcherInit::kMaxConcurrentLookups); std::string motivation_hostname = "www.google.com"; @@ -494,7 +494,7 @@ TEST_F(DnsMasterTest, ReferrerSerializationSingleReferrerTest) { // Make sure the Trim() functionality works as expected. TEST_F(DnsMasterTest, ReferrerSerializationTrimTest) { - scoped_refptr<DnsMaster> master = new DnsMaster(new net::HostResolver, + scoped_refptr<DnsMaster> master = new DnsMaster(host_resolver_, MessageLoop::current(), default_max_queueing_delay_, DnsPrefetcherInit::kMaxConcurrentLookups); std::string motivation_hostname = "www.google.com"; diff --git a/chrome/browser/search_engines/template_url_scraper_unittest.cc b/chrome/browser/search_engines/template_url_scraper_unittest.cc index 71aace7..a93790f 100644 --- a/chrome/browser/search_engines/template_url_scraper_unittest.cc +++ b/chrome/browser/search_engines/template_url_scraper_unittest.cc @@ -11,7 +11,7 @@ #include "chrome/common/notification_type.h" #include "chrome/test/in_process_browser_test.h" #include "chrome/test/ui_test_utils.h" -#include "net/base/host_resolver_unittest.h" +#include "net/base/mock_host_resolver.h" #include "net/base/net_util.h" namespace { @@ -21,10 +21,10 @@ class TemplateURLScraperTest : public InProcessBrowserTest { } protected: - virtual void ConfigureHostMapper(net::RuleBasedHostMapper* host_mapper) { - InProcessBrowserTest::ConfigureHostMapper(host_mapper); + virtual void ConfigureHostResolverProc(net::RuleBasedHostResolverProc* proc) { + InProcessBrowserTest::ConfigureHostResolverProc(proc); // We use foo.com in our tests. - host_mapper->AddRule("*.foo.com", "localhost"); + proc->AddRule("*.foo.com", "localhost"); } private: 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_ |