Skip to content

Commit

Permalink
Move url_request_test_util into net namespace
Browse files Browse the repository at this point in the history
This file contains some rather generic names like "TestDelegate". Move it to the
net namespace to avoid collisions

BUG=none
TBR=darin@chromium.org

Review URL: https://codereview.chromium.org/11369179

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@167337 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
jochen@chromium.org committed Nov 13, 2012
1 parent d0ad6a2 commit 13b65cc
Show file tree
Hide file tree
Showing 39 changed files with 361 additions and 344 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ class GViewRequestInterceptorTest : public testing::Test {
scoped_refptr<PluginPrefs> plugin_prefs_;
net::URLRequestJobFactoryImpl job_factory_;
const net::URLRequestJobFactory* old_factory_;
TestDelegate test_delegate_;
net::TestDelegate test_delegate_;
FilePath pdf_path_;
content::MockResourceContext resource_context_;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class TestConfigurator : public ComponentUpdateService::Configurator {
virtual size_t UrlSizeLimit() OVERRIDE { return 256; }

virtual net::URLRequestContextGetter* RequestContext() OVERRIDE {
return new TestURLRequestContextGetter(
return new net::TestURLRequestContextGetter(
BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ TEST(WebRequestActionTest, PerlToRe2Style) {
TEST(WebRequestActionTest, TestPermissions) {
// Necessary for TestURLRequest.
MessageLoop message_loop(MessageLoop::TYPE_IO);
TestURLRequestContext context;
net::TestURLRequestContext context;

std::string error;
bool bad_message = false;
Expand All @@ -146,16 +146,16 @@ TEST(WebRequestActionTest, TestPermissions) {
ASSERT_TRUE(action.get());

// Check that redirect works on regular URLs but not on protected URLs.
TestURLRequest regular_request(GURL("http://test.com"), NULL, &context);
net::TestURLRequest regular_request(GURL("http://test.com"), NULL, &context);
std::list<LinkedPtrEventResponseDelta> deltas =
action_set->CreateDeltas(
NULL, "ext1",
WebRequestRule::RequestData(&regular_request, ON_BEFORE_REQUEST),
false, base::Time());
EXPECT_EQ(1u, deltas.size());

TestURLRequest protected_request(GURL("http://clients1.google.com"),
NULL, &context);
net::TestURLRequest protected_request(GURL("http://clients1.google.com"),
NULL, &context);
deltas = action_set->CreateDeltas(
NULL, "ext1",
WebRequestRule::RequestData(&protected_request, ON_BEFORE_REQUEST),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,15 @@ TEST(WebRequestConditionAttributeTest, ResourceType) {
EXPECT_EQ("", error);
ASSERT_TRUE(attribute.get());

TestURLRequestContext context;
TestURLRequest url_request_ok(GURL("http://www.example.com"), NULL, &context);
net::TestURLRequestContext context;
net::TestURLRequest url_request_ok(
GURL("http://www.example.com"), NULL, &context);
content::ResourceRequestInfo::AllocateForTesting(&url_request_ok,
ResourceType::MAIN_FRAME, NULL, -1, -1);
EXPECT_TRUE(attribute->IsFulfilled(
WebRequestRule::RequestData(&url_request_ok, ON_BEFORE_REQUEST)));

TestURLRequest url_request_fail(
net::TestURLRequest url_request_fail(
GURL("http://www.example.com"), NULL, &context);
content::ResourceRequestInfo::AllocateForTesting(&url_request_ok,
ResourceType::SUB_FRAME, NULL, -1, -1);
Expand All @@ -113,10 +114,10 @@ TEST(WebRequestConditionAttributeTest, ContentType) {
"chrome/test/data/extensions/api_test/webrequest/declarative")));
ASSERT_TRUE(test_server.Start());

TestURLRequestContext context;
TestDelegate delegate;
TestURLRequest url_request(test_server.GetURL("files/headers.html"),
&delegate, &context);
net::TestURLRequestContext context;
net::TestDelegate delegate;
net::TestURLRequest url_request(test_server.GetURL("files/headers.html"),
&delegate, &context);
url_request.Start();
MessageLoop::current()->Run();

Expand Down Expand Up @@ -190,9 +191,9 @@ TEST(WebRequestConditionAttributeTest, ThirdParty) {
const GURL url_empty;
const GURL url_a("http://a.com");
const GURL url_b("http://b.com");
TestURLRequestContext context;
TestDelegate delegate;
TestURLRequest url_request(url_a, &delegate, &context);
net::TestURLRequestContext context;
net::TestDelegate delegate;
net::TestURLRequest url_request(url_a, &delegate, &context);

for (unsigned int i = 1; i <= kLastActiveStage; i <<= 1) {
if (!(kActiveStages & i))
Expand Down Expand Up @@ -277,9 +278,9 @@ TEST(WebRequestConditionAttributeTest, Stages) {
}

const GURL url_empty;
TestURLRequestContext context;
TestDelegate delegate;
TestURLRequest url_request(url_empty, &delegate, &context);
net::TestURLRequestContext context;
net::TestDelegate delegate;
net::TestURLRequest url_request(url_empty, &delegate, &context);

for (size_t i = 0; i < arraysize(active_stages); ++i) {
EXPECT_FALSE(empty_attribute->IsFulfilled(WebRequestRule::RequestData(
Expand Down Expand Up @@ -399,10 +400,10 @@ TEST(WebRequestConditionAttributeTest, RequestHeaders) {
// Necessary for TestURLRequest.
MessageLoop message_loop(MessageLoop::TYPE_IO);

TestURLRequestContext context;
TestDelegate delegate;
TestURLRequest url_request(GURL("http://example.com"), // Dummy URL.
&delegate, &context);
net::TestURLRequestContext context;
net::TestDelegate delegate;
net::TestURLRequest url_request(GURL("http://example.com"), // Dummy URL.
&delegate, &context);
url_request.SetExtraRequestHeaderByName(
"Custom-header", "custom/value", true /* overwrite */);
url_request.Start();
Expand Down Expand Up @@ -484,10 +485,10 @@ TEST(WebRequestConditionAttributeTest, ResponseHeaders) {
"chrome/test/data/extensions/api_test/webrequest/declarative")));
ASSERT_TRUE(test_server.Start());

TestURLRequestContext context;
TestDelegate delegate;
TestURLRequest url_request(test_server.GetURL("files/headers.html"),
&delegate, &context);
net::TestURLRequestContext context;
net::TestDelegate delegate;
net::TestURLRequest url_request(test_server.GetURL("files/headers.html"),
&delegate, &context);
url_request.Start();
MessageLoop::current()->Run();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,15 @@ TEST(WebRequestConditionTest, CreateCondition) {
EXPECT_EQ("", error);
ASSERT_TRUE(result.get());

TestURLRequestContext context;
TestURLRequest match_request(GURL("http://www.example.com"), NULL, &context);
net::TestURLRequestContext context;
net::TestURLRequest match_request(
GURL("http://www.example.com"), NULL, &context);
content::ResourceRequestInfo::AllocateForTesting(&match_request,
ResourceType::MAIN_FRAME, NULL, -1, -1);
EXPECT_TRUE(result->IsFulfilled(
WebRequestRule::RequestData(&match_request, ON_BEFORE_REQUEST)));

TestURLRequest wrong_resource_type(
net::TestURLRequest wrong_resource_type(
GURL("https://www.example.com"), NULL, &context);
content::ResourceRequestInfo::AllocateForTesting(&wrong_resource_type,
ResourceType::SUB_FRAME, NULL, -1, -1);
Expand Down Expand Up @@ -140,8 +141,8 @@ TEST(WebRequestConditionTest, CreateConditionSet) {
// Test that the result is correct and matches http://www.example.com and
// https://www.example.com
GURL http_url("http://www.example.com");
TestURLRequestContext context;
TestURLRequest http_request(http_url, NULL, &context);
net::TestURLRequestContext context;
net::TestURLRequest http_request(http_url, NULL, &context);
url_match_ids = matcher.MatchURL(http_url);
for (std::set<URLMatcherConditionSet::ID>::iterator i = url_match_ids.begin();
i != url_match_ids.end(); ++i) {
Expand All @@ -153,7 +154,7 @@ TEST(WebRequestConditionTest, CreateConditionSet) {

GURL https_url("https://www.example.com");
url_match_ids = matcher.MatchURL(https_url);
TestURLRequest https_request(https_url, NULL, &context);
net::TestURLRequest https_request(https_url, NULL, &context);
number_matches = 0;
for (std::set<URLMatcherConditionSet::ID>::iterator i = url_match_ids.begin();
i != url_match_ids.end(); ++i) {
Expand All @@ -166,7 +167,7 @@ TEST(WebRequestConditionTest, CreateConditionSet) {
// Check that both, hostPrefix and hostSuffix are evaluated.
GURL https_foo_url("https://foo.example.com");
url_match_ids = matcher.MatchURL(https_foo_url);
TestURLRequest https_foo_request(https_foo_url, NULL, &context);
net::TestURLRequest https_foo_request(https_foo_url, NULL, &context);
number_matches = 0;
for (std::set<URLMatcherConditionSet::ID>::iterator i = url_match_ids.begin();
i != url_match_ids.end(); ++i) {
Expand Down Expand Up @@ -223,23 +224,23 @@ TEST(WebRequestConditionTest, TestPortFilter) {

// Test various URLs.
GURL http_url("http://www.example.com");
TestURLRequestContext context;
TestURLRequest http_request(http_url, NULL, &context);
net::TestURLRequestContext context;
net::TestURLRequest http_request(http_url, NULL, &context);
url_match_ids = matcher.MatchURL(http_url);
ASSERT_EQ(1u, url_match_ids.size());

GURL http_url_80("http://www.example.com:80");
TestURLRequest http_request_80(http_url_80, NULL, &context);
net::TestURLRequest http_request_80(http_url_80, NULL, &context);
url_match_ids = matcher.MatchURL(http_url_80);
ASSERT_EQ(1u, url_match_ids.size());

GURL http_url_1000("http://www.example.com:1000");
TestURLRequest http_request_1000(http_url_1000, NULL, &context);
net::TestURLRequest http_request_1000(http_url_1000, NULL, &context);
url_match_ids = matcher.MatchURL(http_url_1000);
ASSERT_EQ(1u, url_match_ids.size());

GURL http_url_2000("http://www.example.com:2000");
TestURLRequest http_request_2000(http_url_2000, NULL, &context);
net::TestURLRequest http_request_2000(http_url_2000, NULL, &context);
url_match_ids = matcher.MatchURL(http_url_2000);
ASSERT_EQ(0u, url_match_ids.size());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,8 @@ TEST_F(WebRequestRulesRegistryTest, AddRulesImpl) {
std::set<WebRequestRule::GlobalRuleId> matches;

GURL http_url("http://www.example.com");
TestURLRequestContext context;
TestURLRequest http_request(http_url, NULL, &context);
net::TestURLRequestContext context;
net::TestURLRequest http_request(http_url, NULL, &context);
matches = registry->GetMatches(
WebRequestRule::RequestData(&http_request, ON_BEFORE_REQUEST));
EXPECT_EQ(2u, matches.size());
Expand All @@ -238,7 +238,7 @@ TEST_F(WebRequestRulesRegistryTest, AddRulesImpl) {
matches.end());

GURL foobar_url("http://www.foobar.com");
TestURLRequest foobar_request(foobar_url, NULL, &context);
net::TestURLRequest foobar_request(foobar_url, NULL, &context);
matches = registry->GetMatches(
WebRequestRule::RequestData(&foobar_request, ON_BEFORE_REQUEST));
EXPECT_EQ(1u, matches.size());
Expand Down Expand Up @@ -359,8 +359,8 @@ TEST_F(WebRequestRulesRegistryTest, Precedences) {
EXPECT_EQ("", error);

GURL url("http://www.google.com");
TestURLRequestContext context;
TestURLRequest request(url, NULL, &context);
net::TestURLRequestContext context;
net::TestURLRequest request(url, NULL, &context);
std::list<LinkedPtrEventResponseDelta> deltas =
registry->CreateDeltas(
NULL,
Expand Down Expand Up @@ -409,8 +409,8 @@ TEST_F(WebRequestRulesRegistryTest, Priorities) {
EXPECT_EQ("", error);

GURL url("http://www.google.com/index.html");
TestURLRequestContext context;
TestURLRequest request(url, NULL, &context);
net::TestURLRequestContext context;
net::TestURLRequest request(url, NULL, &context);
std::list<LinkedPtrEventResponseDelta> deltas =
registry->CreateDeltas(
NULL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ class ExtensionWebRequestTest : public testing::Test {
event_router_.get(), NULL, NULL, NULL, &profile_,
CookieSettings::Factory::GetForProfile(&profile_), &enable_referrers_,
NULL, NULL, NULL));
context_.reset(new TestURLRequestContext(true));
context_.reset(new net::TestURLRequestContext(true));
context_->set_network_delegate(network_delegate_.get());
context_->Init();
}
Expand All @@ -180,13 +180,13 @@ class ExtensionWebRequestTest : public testing::Test {
content::TestBrowserThread ui_thread_;
content::TestBrowserThread io_thread_;
TestingProfile profile_;
TestDelegate delegate_;
net::TestDelegate delegate_;
BooleanPrefMember enable_referrers_;
TestIPCSender ipc_sender_;
scoped_refptr<extensions::EventRouterForwarder> event_router_;
scoped_refptr<ExtensionInfoMap> extension_info_map_;
scoped_ptr<ChromeNetworkDelegate> network_delegate_;
scoped_ptr<TestURLRequestContext> context_;
scoped_ptr<net::TestURLRequestContext> context_;
};

// Tests that we handle disagreements among extensions about responses to
Expand Down Expand Up @@ -707,7 +707,7 @@ class ExtensionWebRequestHeaderModificationTest :
event_router_.get(), NULL, NULL, NULL, &profile_,
CookieSettings::Factory::GetForProfile(&profile_), &enable_referrers_,
NULL, NULL, NULL));
context_.reset(new TestURLRequestContext(true));
context_.reset(new net::TestURLRequestContext(true));
host_resolver_.reset(new net::MockHostResolver());
host_resolver_->rules()->AddSimulatedFailure("doesnotexist");
context_->set_host_resolver(host_resolver_.get());
Expand All @@ -719,14 +719,14 @@ class ExtensionWebRequestHeaderModificationTest :
content::TestBrowserThread ui_thread_;
content::TestBrowserThread io_thread_;
TestingProfile profile_;
TestDelegate delegate_;
net::TestDelegate delegate_;
BooleanPrefMember enable_referrers_;
TestIPCSender ipc_sender_;
scoped_refptr<extensions::EventRouterForwarder> event_router_;
scoped_refptr<ExtensionInfoMap> extension_info_map_;
scoped_ptr<ChromeNetworkDelegate> network_delegate_;
scoped_ptr<net::MockHostResolver> host_resolver_;
scoped_ptr<TestURLRequestContext> context_;
scoped_ptr<net::TestURLRequestContext> context_;
};

TEST_P(ExtensionWebRequestHeaderModificationTest, TestModifications) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ using content::ResourceRequestInfo;

TEST(ExtensionWebRequestHelpersTest, TestHideRequestForURL) {
MessageLoopForIO message_loop;
TestURLRequestContext context;
net::TestURLRequestContext context;
scoped_refptr<ExtensionInfoMap> extension_info_map(new ExtensionInfoMap);
const char* sensitive_urls[] = {
"http://clients2.google.com",
Expand All @@ -36,15 +36,15 @@ TEST(ExtensionWebRequestHelpersTest, TestHideRequestForURL) {
// Check that requests are rejected based on the destination
for (size_t i = 0; i < arraysize(sensitive_urls); ++i) {
GURL sensitive_url(sensitive_urls[i]);
TestURLRequest request(sensitive_url, NULL, &context);
net::TestURLRequest request(sensitive_url, NULL, &context);
EXPECT_TRUE(
WebRequestPermissions::HideRequest(extension_info_map.get(), &request))
<< sensitive_urls[i];
}
// Check that requests are accepted if they don't touch sensitive urls.
for (size_t i = 0; i < arraysize(non_sensitive_urls); ++i) {
GURL non_sensitive_url(non_sensitive_urls[i]);
TestURLRequest request(non_sensitive_url, NULL, &context);
net::TestURLRequest request(non_sensitive_url, NULL, &context);
EXPECT_FALSE(
WebRequestPermissions::HideRequest(extension_info_map.get(), &request))
<< non_sensitive_urls[i];
Expand All @@ -54,14 +54,14 @@ TEST(ExtensionWebRequestHelpersTest, TestHideRequestForURL) {
// WebStore.
// Normally this request is not protected:
GURL non_sensitive_url("http://www.google.com/test.js");
TestURLRequest non_sensitive_request(non_sensitive_url, NULL, &context);
net::TestURLRequest non_sensitive_request(non_sensitive_url, NULL, &context);
EXPECT_FALSE(WebRequestPermissions::HideRequest(extension_info_map.get(),
&non_sensitive_request));
// If the origin is labeled by the WebStoreAppId, it becomes protected.
int process_id = 42;
int site_instance_id = 23;
int frame_id = 17;
TestURLRequest sensitive_request(non_sensitive_url, NULL, &context);
net::TestURLRequest sensitive_request(non_sensitive_url, NULL, &context);
ResourceRequestInfo::AllocateForTesting(&sensitive_request,
ResourceType::SCRIPT, NULL, process_id, frame_id);
extension_info_map->RegisterExtensionProcess(extension_misc::kWebStoreAppId,
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/extensions/extension_protocols_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class ExtensionProtocolTest : public testing::Test {
scoped_refptr<ExtensionInfoMap> extension_info_map_;
net::URLRequestJobFactoryImpl job_factory_;
const net::URLRequestJobFactory* old_factory_;
TestDelegate test_delegate_;
net::TestDelegate test_delegate_;
content::MockResourceContext resource_context_;
};

Expand Down
Loading

0 comments on commit 13b65cc

Please sign in to comment.