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

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

Issue 11572061: Create DeclarativeConditionSet, DeclarativeActionSet, and DeclarativeRule templates (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase to Vaclav's CL and fix Dominic's comments Created 8 years 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_condition_unittest.cc
diff --git a/chrome/browser/extensions/api/declarative_webrequest/webrequest_condition_unittest.cc b/chrome/browser/extensions/api/declarative_webrequest/webrequest_condition_unittest.cc
index f040e1a5b7bead987e1130e0058ede25841ecd70..d57a68669b438691573c6a37476573f9cad07dd2 100644
--- a/chrome/browser/extensions/api/declarative_webrequest/webrequest_condition_unittest.cc
+++ b/chrome/browser/extensions/api/declarative_webrequest/webrequest_condition_unittest.cc
@@ -10,7 +10,6 @@
#include "base/test/values_test_util.h"
#include "base/values.h"
#include "chrome/browser/extensions/api/declarative_webrequest/webrequest_constants.h"
-#include "chrome/browser/extensions/api/declarative_webrequest/webrequest_rule.h"
#include "chrome/common/extensions/matcher/url_matcher_constants.h"
#include "content/public/browser/resource_request_info.h"
#include "net/url_request/url_request_test_util.h"
@@ -72,22 +71,24 @@ TEST(WebRequestConditionTest, CreateCondition) {
net::TestURLRequestContext context;
net::TestURLRequest match_request(
GURL("http://www.example.com"), NULL, &context);
+ URLMatcherConditionSet::Vector condition_sets;
+ result->GetURLMatcherConditionSets(&condition_sets);
+ ASSERT_EQ(1U, condition_sets.size());
std::set<URLMatcherConditionSet::ID> url_matches;
- url_matches.insert(result->url_matcher_condition_set_id());
+ url_matches.insert(condition_sets[0]->id());
content::ResourceRequestInfo::AllocateForTesting(&match_request,
ResourceType::MAIN_FRAME, NULL, -1, -1);
- EXPECT_TRUE(result->IsFulfilled(
- url_matches,
- WebRequestRule::RequestData(&match_request, ON_BEFORE_REQUEST)));
+ DeclarativeWebRequestData request_data(&match_request, ON_BEFORE_REQUEST);
+ request_data.url_matches = &url_matches;
+ EXPECT_TRUE(result->IsFulfilled(request_data));
net::TestURLRequest wrong_resource_type(
GURL("https://www.example.com"), NULL, &context);
content::ResourceRequestInfo::AllocateForTesting(&wrong_resource_type,
ResourceType::SUB_FRAME, NULL, -1, -1);
- EXPECT_FALSE(result->IsFulfilled(
- url_matches,
- WebRequestRule::RequestData(&wrong_resource_type, ON_BEFORE_REQUEST)));
+ request_data.request = &wrong_resource_type;
+ EXPECT_FALSE(result->IsFulfilled(request_data));
}
// The IsFulfilledIndependentlyOfURL method tests that a condition has no
@@ -189,33 +190,26 @@ TEST(WebRequestConditionTest, IsFulfilledIndependentlyOfURL) {
net::TestURLRequestContext context;
net::TestURLRequest https_request(GURL(kUrl), NULL, &context);
std::set<URLMatcherConditionSet::ID> empty_url_matches;
+ DeclarativeWebRequestData request_data(NULL, ON_BEFORE_REQUEST);
+ request_data.url_matches = &empty_url_matches;
Jeffrey Yasskin 2012/12/19 08:23:06 These assignments into request_data are somewhat a
Jeffrey Yasskin 2012/12/20 01:27:35 And I've reverted them since ConditionSet needed t
// 1. A non-empty condition without UrlFilter attributes is fulfilled iff its
// attributes are fulfilled.
- EXPECT_FALSE(condition_no_url_false->IsFulfilled(
- empty_url_matches,
- WebRequestRule::RequestData(&https_request, ON_BEFORE_REQUEST)));
+ request_data.request = &https_request;
+ EXPECT_FALSE(condition_no_url_false->IsFulfilled(request_data));
- EXPECT_TRUE(condition_no_url_true->IsFulfilled(
- empty_url_matches,
- WebRequestRule::RequestData(&https_request, ON_BEFORE_REQUEST)));
+ EXPECT_TRUE(condition_no_url_true->IsFulfilled(request_data));
// 2. An empty condition (in particular, without UrlFilter attributes) is
// always fulfilled.
- EXPECT_TRUE(condition_empty->IsFulfilled(
- empty_url_matches,
- WebRequestRule::RequestData(&https_request, ON_BEFORE_REQUEST)));
+ EXPECT_TRUE(condition_empty->IsFulfilled(request_data));
// 3. A condition with a UrlFilter and a non-UrlFilter attribute is never
// fulfilled.
- EXPECT_FALSE(condition_both->IsFulfilled(
- empty_url_matches,
- WebRequestRule::RequestData(&https_request, ON_BEFORE_REQUEST)));
+ EXPECT_FALSE(condition_both->IsFulfilled(request_data));
// 4. A condition with only a UrlFilter attribute is never fulfilled.
- EXPECT_FALSE(condition_url->IsFulfilled(
- empty_url_matches,
- WebRequestRule::RequestData(&https_request, ON_BEFORE_REQUEST)));
+ EXPECT_FALSE(condition_url->IsFulfilled(request_data));
}
TEST(WebRequestConditionTest, CreateConditionSet) {
@@ -272,24 +266,26 @@ TEST(WebRequestConditionTest, CreateConditionSet) {
net::TestURLRequestContext context;
net::TestURLRequest http_request(http_url, NULL, &context);
url_match_ids = matcher.MatchURL(http_url);
- EXPECT_TRUE(result->IsFulfilled(
- url_match_ids,
- WebRequestRule::RequestData(&http_request, ON_BEFORE_REQUEST)));
+ DeclarativeWebRequestData request_data(NULL, ON_BEFORE_REQUEST);
+
+ request_data.request = &http_request;
+ request_data.url_matches = &url_match_ids;
+ EXPECT_TRUE(result->IsFulfilled(request_data));
GURL https_url("https://www.example.com");
url_match_ids = matcher.MatchURL(https_url);
net::TestURLRequest https_request(https_url, NULL, &context);
- EXPECT_TRUE(result->IsFulfilled(
- url_match_ids,
- WebRequestRule::RequestData(&https_request, ON_BEFORE_REQUEST)));
+ request_data.request = &https_request;
+ request_data.url_matches = &url_match_ids;
+ EXPECT_TRUE(result->IsFulfilled(request_data));
// Check that both, hostPrefix and hostSuffix are evaluated.
GURL https_foo_url("https://foo.example.com");
url_match_ids = matcher.MatchURL(https_foo_url);
net::TestURLRequest https_foo_request(https_foo_url, NULL, &context);
- EXPECT_FALSE(result->IsFulfilled(
- url_match_ids,
- WebRequestRule::RequestData(&https_foo_request, ON_BEFORE_REQUEST)));
+ request_data.request = &https_foo_request;
+ request_data.url_matches = &url_match_ids;
+ EXPECT_FALSE(result->IsFulfilled(request_data));
}
TEST(WebRequestConditionTest, TestPortFilter) {

Powered by Google App Engine
This is Rietveld 408576698