Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2945)

Unified Diff: chrome/browser/extensions/api/declarative_webrequest/webrequest_rules_registry_unittest.cc

Issue 501163002: Make URLRequest's constructor private, and make URLRequestContext a friend class. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge yet again Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/api/declarative_webrequest/webrequest_rules_registry_unittest.cc
diff --git a/chrome/browser/extensions/api/declarative_webrequest/webrequest_rules_registry_unittest.cc b/chrome/browser/extensions/api/declarative_webrequest/webrequest_rules_registry_unittest.cc
index 0678307bcadabf378d10cc28b5827b4b8809b594..5539aa91540acdb3deff7851e51bc2784b4b606d 100644
--- a/chrome/browser/extensions/api/declarative_webrequest/webrequest_rules_registry_unittest.cc
+++ b/chrome/browser/extensions/api/declarative_webrequest/webrequest_rules_registry_unittest.cc
@@ -10,6 +10,7 @@
#include "base/basictypes.h"
#include "base/json/json_reader.h"
#include "base/memory/linked_ptr.h"
+#include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_loop.h"
#include "base/stl_util.h"
#include "base/test/values_test_util.h"
@@ -20,6 +21,7 @@
#include "content/public/test/test_browser_thread.h"
#include "extensions/browser/api/declarative_webrequest/webrequest_constants.h"
#include "net/base/request_priority.h"
+#include "net/url_request/url_request.h"
#include "net/url_request/url_request_test_util.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest-message.h"
@@ -281,9 +283,9 @@ TEST_F(WebRequestRulesRegistryTest, AddRulesImpl) {
GURL http_url("http://www.example.com");
net::TestURLRequestContext context;
- net::TestURLRequest http_request(
- http_url, net::DEFAULT_PRIORITY, NULL, &context);
- WebRequestData request_data(&http_request, ON_BEFORE_REQUEST);
+ scoped_ptr<net::URLRequest> http_request(context.CreateRequest(
+ http_url, net::DEFAULT_PRIORITY, NULL, NULL));
+ WebRequestData request_data(http_request.get(), ON_BEFORE_REQUEST);
matches = registry->GetMatches(request_data);
EXPECT_EQ(2u, matches.size());
@@ -295,9 +297,9 @@ TEST_F(WebRequestRulesRegistryTest, AddRulesImpl) {
EXPECT_TRUE(ContainsKey(matches_ids, std::make_pair(kExtensionId, kRuleId2)));
GURL foobar_url("http://www.foobar.com");
- net::TestURLRequest foobar_request(
- foobar_url, net::DEFAULT_PRIORITY, NULL, &context);
- request_data.request = &foobar_request;
+ scoped_ptr<net::URLRequest> foobar_request(context.CreateRequest(
+ foobar_url, net::DEFAULT_PRIORITY, NULL, NULL));
+ request_data.request = foobar_request.get();
matches = registry->GetMatches(request_data);
EXPECT_EQ(1u, matches.size());
WebRequestRule::GlobalRuleId expected_pair =
@@ -422,8 +424,9 @@ TEST_F(WebRequestRulesRegistryTest, Precedences) {
GURL url("http://www.google.com");
net::TestURLRequestContext context;
- net::TestURLRequest request(url, net::DEFAULT_PRIORITY, NULL, &context);
- WebRequestData request_data(&request, ON_BEFORE_REQUEST);
+ scoped_ptr<net::URLRequest> request(context.CreateRequest(
+ url, net::DEFAULT_PRIORITY, NULL, NULL));
+ WebRequestData request_data(request.get(), ON_BEFORE_REQUEST);
std::list<LinkedPtrEventResponseDelta> deltas =
registry->CreateDeltas(NULL, request_data, false);
@@ -470,8 +473,9 @@ TEST_F(WebRequestRulesRegistryTest, Priorities) {
GURL url("http://www.google.com/index.html");
net::TestURLRequestContext context;
- net::TestURLRequest request(url, net::DEFAULT_PRIORITY, NULL, &context);
- WebRequestData request_data(&request, ON_BEFORE_REQUEST);
+ scoped_ptr<net::URLRequest> request(context.CreateRequest(
+ url, net::DEFAULT_PRIORITY, NULL, NULL));
+ WebRequestData request_data(request.get(), ON_BEFORE_REQUEST);
std::list<LinkedPtrEventResponseDelta> deltas =
registry->CreateDeltas(NULL, request_data, false);
@@ -543,8 +547,9 @@ TEST_F(WebRequestRulesRegistryTest, IgnoreRulesByTag) {
GURL url("http://www.foo.com/test");
net::TestURLRequestContext context;
- net::TestURLRequest request(url, net::DEFAULT_PRIORITY, NULL, &context);
- WebRequestData request_data(&request, ON_BEFORE_REQUEST);
+ scoped_ptr<net::URLRequest> request(context.CreateRequest(
+ url, net::DEFAULT_PRIORITY, NULL, NULL));
+ WebRequestData request_data(request.get(), ON_BEFORE_REQUEST);
std::list<LinkedPtrEventResponseDelta> deltas =
registry->CreateDeltas(NULL, request_data, false);
@@ -592,9 +597,9 @@ TEST_F(WebRequestRulesRegistryTest, GetMatchesCheckFulfilled) {
GURL http_url("http://www.example.com");
net::TestURLRequestContext context;
- net::TestURLRequest http_request(
- http_url, net::DEFAULT_PRIORITY, NULL, &context);
- WebRequestData request_data(&http_request, ON_BEFORE_REQUEST);
+ scoped_ptr<net::URLRequest> http_request(context.CreateRequest(
+ http_url, net::DEFAULT_PRIORITY, NULL, NULL));
+ WebRequestData request_data(http_request.get(), ON_BEFORE_REQUEST);
matches = registry->GetMatches(request_data);
EXPECT_EQ(1u, matches.size());
WebRequestRule::GlobalRuleId expected_pair = std::make_pair(kExtensionId,
@@ -649,10 +654,10 @@ TEST_F(WebRequestRulesRegistryTest, GetMatchesDifferentUrls) {
for (size_t i = 0; i < arraysize(matchingRuleIds); ++i) {
// Construct the inputs.
- net::TestURLRequest http_request(
- urls[i], net::DEFAULT_PRIORITY, NULL, &context);
- WebRequestData request_data(&http_request, ON_BEFORE_REQUEST);
- http_request.set_first_party_for_cookies(firstPartyUrls[i]);
+ scoped_ptr<net::URLRequest> http_request(context.CreateRequest(
+ urls[i], net::DEFAULT_PRIORITY, NULL, NULL));
+ WebRequestData request_data(http_request.get(), ON_BEFORE_REQUEST);
+ http_request->set_first_party_for_cookies(firstPartyUrls[i]);
// Now run both rules on the input.
matches = registry->GetMatches(request_data);
SCOPED_TRACE(testing::Message("i = ") << i << ", rule id = "
@@ -799,15 +804,17 @@ TEST_F(WebRequestRulesRegistryTest, CheckOriginAndPathRegEx) {
// No match because match is in the query parameter.
GURL url1("http://bar.com/index.html?foo.com");
- net::TestURLRequest request1(url1, net::DEFAULT_PRIORITY, NULL, &context);
- WebRequestData request_data1(&request1, ON_BEFORE_REQUEST);
+ scoped_ptr<net::URLRequest> request1(context.CreateRequest(
+ url1, net::DEFAULT_PRIORITY, NULL, NULL));
+ WebRequestData request_data1(request1.get(), ON_BEFORE_REQUEST);
deltas = registry->CreateDeltas(NULL, request_data1, false);
EXPECT_EQ(0u, deltas.size());
// This is a correct match.
GURL url2("http://foo.com/index.html");
- net::TestURLRequest request2(url2, net::DEFAULT_PRIORITY, NULL, &context);
- WebRequestData request_data2(&request2, ON_BEFORE_REQUEST);
+ scoped_ptr<net::URLRequest> request2(context.CreateRequest(
+ url2, net::DEFAULT_PRIORITY, NULL, NULL));
+ WebRequestData request_data2(request2.get(), ON_BEFORE_REQUEST);
deltas = registry->CreateDeltas(NULL, request_data2, false);
EXPECT_EQ(1u, deltas.size());
}

Powered by Google App Engine
This is Rietveld 408576698