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

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

Issue 11414230: Declarative Web Request: firstPartyForCookiesUrl (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Easy comments addressed. :) Created 7 years, 11 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_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 2fa6268a3a7b03e66386f9145ef24e6bf5c63da3..351bc44682fb42b141adc71eea47130cb11c40d4 100644
--- a/chrome/browser/extensions/api/declarative_webrequest/webrequest_condition_unittest.cc
+++ b/chrome/browser/extensions/api/declarative_webrequest/webrequest_condition_unittest.cc
@@ -5,6 +5,7 @@
#include "chrome/browser/extensions/api/declarative_webrequest/webrequest_condition.h"
#include <set>
+#include <vector>
#include "base/message_loop.h"
#include "base/test/values_test_util.h"
@@ -24,15 +25,19 @@ TEST(WebRequestConditionTest, CreateCondition) {
// Necessary for TestURLRequest.
MessageLoop message_loop(MessageLoop::TYPE_IO);
URLMatcher matcher;
+ URLMatcher first_party_matcher;
std::string error;
scoped_ptr<WebRequestCondition> result;
+ std::vector<URLMatcherConditionFactory*> factories;
+ factories.push_back(matcher.condition_factory());
+ factories.push_back(first_party_matcher.condition_factory());
// Test wrong condition name passed.
error.clear();
result = WebRequestCondition::Create(
- matcher.condition_factory(),
+ factories,
*base::test::ParseJson(
"{ \"invalid\": \"foobar\", \n"
" \"instanceType\": \"declarativeWebRequest.RequestMatcher\", \n"
@@ -44,7 +49,7 @@ TEST(WebRequestConditionTest, CreateCondition) {
// Test wrong datatype in host_suffix.
error.clear();
result = WebRequestCondition::Create(
- matcher.condition_factory(),
+ factories,
*base::test::ParseJson(
"{ \n"
" \"url\": [], \n"
@@ -57,11 +62,12 @@ TEST(WebRequestConditionTest, CreateCondition) {
// Test success (can we support multiple criteria?)
error.clear();
result = WebRequestCondition::Create(
- matcher.condition_factory(),
+ factories,
*base::test::ParseJson(
"{ \n"
" \"resourceType\": [\"main_frame\"], \n"
" \"url\": { \"hostSuffix\": \"example.com\" }, \n"
+ " \"firstPartyForCookiesUrl\": { \"hostPrefix\": \"fpfc\"}, \n"
" \"instanceType\": \"declarativeWebRequest.RequestMatcher\", \n"
"}"),
&error);
@@ -69,15 +75,25 @@ TEST(WebRequestConditionTest, CreateCondition) {
ASSERT_TRUE(result.get());
URLMatcherConditionSet::Vector url_matcher_condition_set;
- result->GetURLMatcherConditionSets(&url_matcher_condition_set);
+ ASSERT_EQ(1,
+ result->GetURLMatcherConditionSets(&url_matcher_condition_set, 0));
matcher.AddConditionSets(url_matcher_condition_set);
- std::set<URLMatcherConditionSet::ID> url_match_ids;
+ url_matcher_condition_set.clear();
+ ASSERT_EQ(-1,
+ result->GetURLMatcherConditionSets(&url_matcher_condition_set, 1));
+ first_party_matcher.AddConditionSets(url_matcher_condition_set);
net::TestURLRequestContext context;
GURL http_url("http://www.example.com");
+ GURL first_party_url("http://fpfc.example.com");
net::TestURLRequest match_request(http_url, NULL, &context);
- url_match_ids = matcher.MatchURL(http_url);
- EXPECT_EQ(1u, url_match_ids.size());
+ std::set<URLMatcherConditionSet::ID> url_match_ids =
+ matcher.MatchURL(http_url);
+ std::set<URLMatcherConditionSet::ID> first_party_url_match_ids =
+ first_party_matcher.MatchURL(first_party_url);
+ url_match_ids.insert(first_party_url_match_ids.begin(),
+ first_party_url_match_ids.end());
+ EXPECT_EQ(2u, url_match_ids.size());
content::ResourceRequestInfo::AllocateForTesting(&match_request,
ResourceType::MAIN_FRAME, NULL, -1, -1);
EXPECT_TRUE(result->IsFulfilled(
@@ -87,8 +103,10 @@ TEST(WebRequestConditionTest, CreateCondition) {
GURL https_url("https://www.example.com");
net::TestURLRequest wrong_resource_type(https_url, NULL, &context);
url_match_ids = matcher.MatchURL(https_url);
+ url_match_ids.insert(first_party_url_match_ids.begin(),
+ first_party_url_match_ids.end());
// Make sure IsFulfilled does not fail because of URL matching.
- EXPECT_EQ(1u, url_match_ids.size());
+ EXPECT_EQ(2u, url_match_ids.size());
content::ResourceRequestInfo::AllocateForTesting(&wrong_resource_type,
ResourceType::SUB_FRAME, NULL, -1, -1);
EXPECT_FALSE(result->IsFulfilled(
@@ -108,10 +126,16 @@ TEST(WebRequestConditionTest, NoUrlAttributes) {
URLMatcher matcher;
std::string error;
+ std::vector<URLMatcherConditionFactory*> factories;
+ factories.push_back(matcher.condition_factory());
+ // The second factory is usually from a different matcher, but in this test
+ // we don't care, since we never use it.
+ factories.push_back(matcher.condition_factory());
+
// The empty condition.
error.clear();
scoped_ptr<WebRequestCondition> condition_empty = WebRequestCondition::Create(
- matcher.condition_factory(),
+ factories,
*base::test::ParseJson(
"{ \n"
" \"instanceType\": \"declarativeWebRequest.RequestMatcher\", \n"
@@ -124,7 +148,7 @@ TEST(WebRequestConditionTest, NoUrlAttributes) {
error.clear();
scoped_ptr<WebRequestCondition> condition_no_url_true =
WebRequestCondition::Create(
- matcher.condition_factory(),
+ factories,
*base::test::ParseJson(
"{ \n"
" \"instanceType\": \"declarativeWebRequest.RequestMatcher\", \n"
@@ -140,7 +164,7 @@ TEST(WebRequestConditionTest, NoUrlAttributes) {
error.clear();
scoped_ptr<WebRequestCondition> condition_no_url_false =
WebRequestCondition::Create(
- matcher.condition_factory(),
+ factories,
*base::test::ParseJson(
"{ \n"
" \"instanceType\": \"declarativeWebRequest.RequestMatcher\", \n"
@@ -177,6 +201,12 @@ TEST(WebRequestConditionTest, CreateConditionSet) {
MessageLoop message_loop(MessageLoop::TYPE_IO);
URLMatcher matcher;
+ std::vector<URLMatcherConditionFactory*> factories;
+ factories.push_back(matcher.condition_factory());
+ // The second factory is usually from a different matcher, but in this test
+ // we don't care, since we never use it.
+ factories.push_back(matcher.condition_factory());
+
WebRequestConditionSet::AnyVector conditions;
conditions.push_back(linked_ptr<base::Value>(base::test::ParseJson(
"{ \n"
@@ -199,15 +229,14 @@ TEST(WebRequestConditionTest, CreateConditionSet) {
// Test insertion
std::string error;
scoped_ptr<WebRequestConditionSet> result =
- WebRequestConditionSet::Create(matcher.condition_factory(),
- conditions, &error);
+ WebRequestConditionSet::Create(factories, conditions, &error);
EXPECT_EQ("", error);
ASSERT_TRUE(result.get());
EXPECT_EQ(2u, result->conditions().size());
// Tell the URLMatcher about our shiny new patterns.
URLMatcherConditionSet::Vector url_matcher_condition_set;
- result->GetURLMatcherConditionSets(&url_matcher_condition_set);
+ result->GetURLMatcherConditionSets(&url_matcher_condition_set, 0);
matcher.AddConditionSets(url_matcher_condition_set);
std::set<URLMatcherConditionSet::ID> url_match_ids;
@@ -249,6 +278,12 @@ TEST(WebRequestConditionTest, TestPortFilter) {
MessageLoop message_loop(MessageLoop::TYPE_IO);
URLMatcher matcher;
+ std::vector<URLMatcherConditionFactory*> factories;
+ factories.push_back(matcher.condition_factory());
+ // The second factory is usually from a different matcher, but in this test
+ // we don't care, since we never use it.
+ factories.push_back(matcher.condition_factory());
+
WebRequestConditionSet::AnyVector conditions;
conditions.push_back(linked_ptr<base::Value>(base::test::ParseJson(
"{ \n"
@@ -262,15 +297,14 @@ TEST(WebRequestConditionTest, TestPortFilter) {
// Test insertion
std::string error;
scoped_ptr<WebRequestConditionSet> result =
- WebRequestConditionSet::Create(matcher.condition_factory(),
- conditions, &error);
+ WebRequestConditionSet::Create(factories, conditions, &error);
EXPECT_EQ("", error);
ASSERT_TRUE(result.get());
EXPECT_EQ(1u, result->conditions().size());
// Tell the URLMatcher about our shiny new patterns.
URLMatcherConditionSet::Vector url_matcher_condition_set;
- result->GetURLMatcherConditionSets(&url_matcher_condition_set);
+ result->GetURLMatcherConditionSets(&url_matcher_condition_set, 0);
matcher.AddConditionSets(url_matcher_condition_set);
std::set<URLMatcherConditionSet::ID> url_match_ids;
@@ -309,14 +343,16 @@ TEST(WebRequestConditionTest, ConditionsWithConflictingStages) {
std::string error;
scoped_ptr<WebRequestCondition> result;
- DictionaryValue condition_value;
- condition_value.SetString(keys::kInstanceTypeKey, keys::kRequestMatcherType);
-
+ std::vector<URLMatcherConditionFactory*> factories;
+ factories.push_back(matcher.condition_factory());
+ // The second factory is usually from a different matcher, but in this test
+ // we don't care, since we never use it.
+ factories.push_back(matcher.condition_factory());
// Test error on incompatible application stages for involved attributes.
error.clear();
result = WebRequestCondition::Create(
- matcher.condition_factory(),
+ factories,
*base::test::ParseJson(
"{ \n"
" \"instanceType\": \"declarativeWebRequest.RequestMatcher\", \n"

Powered by Google App Engine
This is Rietveld 408576698