summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
Diffstat (limited to 'chrome')
-rwxr-xr-xchrome/browser/extensions/extension_view_unittest.cc14
-rw-r--r--chrome/browser/net/dns_master_unittest.cc15
-rw-r--r--chrome/browser/views/find_bar_win_unittest.cc13
-rw-r--r--chrome/test/unit/chrome_test_suite.h30
4 files changed, 67 insertions, 5 deletions
diff --git a/chrome/browser/extensions/extension_view_unittest.cc b/chrome/browser/extensions/extension_view_unittest.cc
index bc17d4c..3eb614f 100755
--- a/chrome/browser/extensions/extension_view_unittest.cc
+++ b/chrome/browser/extensions/extension_view_unittest.cc
@@ -3,6 +3,7 @@
// found in the LICENSE file.
#include "base/message_loop.h"
+#include "base/ref_counted.h"
#include "chrome/browser/browser.h"
#include "chrome/browser/renderer_host/render_view_host.h"
#include "chrome/browser/profile.h"
@@ -13,6 +14,7 @@
#include "chrome/common/notification_service.h"
#include "chrome/test/in_process_browser_test.h"
#include "chrome/test/ui_test_utils.h"
+#include "net/base/host_resolver_unittest.h"
namespace {
@@ -99,6 +101,14 @@ class ExtensionLoadedObserver : public NotificationObserver {
class ExtensionViewTest : public InProcessBrowserTest {
public:
+ ExtensionViewTest() {
+ host_mapper_ = new net::RuleBasedHostMapper();
+ // TODO(aa): Don't make a real dns lookup here or simulate a failing lookup.
+ // But if it's really needed then remove the TODO.
+ host_mapper_->AllowDirectLookup("*.google.com");
+ scoped_host_mapper_.Init(host_mapper_.get());
+ }
+
virtual void SetUp() {
// Initialize the error reporter here, otherwise BrowserMain will create it
// with the wrong MessageLoop.
@@ -109,6 +119,10 @@ class ExtensionViewTest : public InProcessBrowserTest {
InProcessBrowserTest::SetUp();
}
+
+ private:
+ scoped_refptr<net::RuleBasedHostMapper> host_mapper_;
+ net::ScopedHostMapper scoped_host_mapper_;
};
// Tests that ExtensionView starts an extension process and runs the script
diff --git a/chrome/browser/net/dns_master_unittest.cc b/chrome/browser/net/dns_master_unittest.cc
index b57a2f0..a997b18 100644
--- a/chrome/browser/net/dns_master_unittest.cc
+++ b/chrome/browser/net/dns_master_unittest.cc
@@ -82,9 +82,10 @@ class DnsMasterTest : public testing::Test {
MessageLoop::current()->Run();
}
+ scoped_refptr<net::RuleBasedHostMapper> mapper_;
+
private:
MessageLoop loop;
- scoped_refptr<net::RuleBasedHostMapper> mapper_;
net::ScopedHostMapper scoped_mapper_;
};
@@ -121,6 +122,8 @@ 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");
+
const Time start = Time::Now();
int all_lookups = 0;
int lookups_with_improvement = 0;
@@ -273,14 +276,16 @@ TEST_F(DnsMasterTest, SingleLookupTest) {
}
TEST_F(DnsMasterTest, ConcurrentLookupTest) {
+ mapper_->AddSimulatedFailure("*.notfound");
+
DnsMaster testing_master;
std::string goog("www.google.com"),
goog2("gmail.google.com.com"),
goog3("mail.google.com"),
goog4("gmail.com");
- std::string bad1(GetNonexistantDomain()),
- bad2(GetNonexistantDomain());
+ std::string bad1("bad1.notfound"),
+ bad2("bad2.notfound");
NameList names;
names.insert(names.end(), goog);
@@ -324,11 +329,13 @@ TEST_F(DnsMasterTest, ConcurrentLookupTest) {
}
TEST_F(DnsMasterTest, MassiveConcurrentLookupTest) {
+ mapper_->AddSimulatedFailure("*.notfound");
+
DnsMaster testing_master;
NameList names;
for (int i = 0; i < 100; i++)
- names.push_back(GetNonexistantDomain());
+ names.push_back("host" + IntToString(i) + ".notfound");
// Try to flood the master with many concurrent requests.
for (int i = 0; i < 10; i++)
diff --git a/chrome/browser/views/find_bar_win_unittest.cc b/chrome/browser/views/find_bar_win_unittest.cc
index 4ef345c..f2d2f74 100644
--- a/chrome/browser/views/find_bar_win_unittest.cc
+++ b/chrome/browser/views/find_bar_win_unittest.cc
@@ -13,6 +13,7 @@
#include "chrome/common/notification_service.h"
#include "chrome/test/in_process_browser_test.h"
#include "chrome/test/ui_test_utils.h"
+#include "net/base/host_resolver_unittest.h"
const std::wstring kFramePage = L"files/find_in_page/frames.html";
const std::wstring kFrameData = L"files/find_in_page/framedata_general.html";
@@ -79,7 +80,13 @@ typedef enum FindInPageCase { IGNORE_CASE = 0, CASE_SENSITIVE = 1 };
class FindInPageControllerTest : public InProcessBrowserTest {
public:
- FindInPageControllerTest() {}
+ FindInPageControllerTest() {
+ host_mapper_ = new net::RuleBasedHostMapper();
+ // 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());
+ }
protected:
int FindInPage(const std::wstring& search_string,
@@ -99,6 +106,10 @@ class FindInPageControllerTest : public InProcessBrowserTest {
}
return 0;
}
+
+ private:
+ scoped_refptr<net::RuleBasedHostMapper> host_mapper_;
+ net::ScopedHostMapper scoped_host_mapper_;
};
// This test loads a page with frames and starts FindInPage requests
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_