summaryrefslogtreecommitdiffstats
path: root/chrome/browser
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/browser
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/browser')
-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
3 files changed, 37 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