| Index: chrome/browser/extensions/api/declarative/declarative_rule_unittest.cc
|
| diff --git a/chrome/browser/extensions/api/declarative/declarative_rule_unittest.cc b/chrome/browser/extensions/api/declarative/declarative_rule_unittest.cc
|
| index 5cadb74588932395790706defd11a7cd6258a4d3..c9658110195f00f7d716240048bec8db0cf8160d 100644
|
| --- a/chrome/browser/extensions/api/declarative/declarative_rule_unittest.cc
|
| +++ b/chrome/browser/extensions/api/declarative/declarative_rule_unittest.cc
|
| @@ -27,20 +27,19 @@ linked_ptr<T> ScopedToLinkedPtr(scoped_ptr<T> ptr) {
|
| struct RecordingCondition {
|
| typedef int MatchData;
|
|
|
| - URLMatcherConditionFactory* factory;
|
| + std::vector<URLMatcherConditionFactory*> factories;
|
| scoped_ptr<base::Value> value;
|
|
|
| - void GetURLMatcherConditionSets(
|
| - URLMatcherConditionSet::Vector* condition_sets) const {
|
| + int GetURLMatcherConditionSets(
|
| + URLMatcherConditionSet::Vector* condition_sets,
|
| + int index) const {
|
| // No condition sets.
|
| - }
|
| -
|
| - bool has_url_matcher_condition_set() const {
|
| - return false;
|
| + return -1;
|
| }
|
|
|
| static scoped_ptr<RecordingCondition> Create(
|
| - URLMatcherConditionFactory* url_matcher_condition_factory,
|
| + const std::vector<URLMatcherConditionFactory*>&
|
| + url_matcher_condition_factories,
|
| const base::Value& condition,
|
| std::string* error) {
|
| const base::DictionaryValue* dict = NULL;
|
| @@ -50,7 +49,7 @@ struct RecordingCondition {
|
| }
|
|
|
| scoped_ptr<RecordingCondition> result(new RecordingCondition());
|
| - result->factory = url_matcher_condition_factory;
|
| + result->factories = url_matcher_condition_factories;
|
| result->value.reset(condition.DeepCopy());
|
| return result.Pass();
|
| }
|
| @@ -64,9 +63,10 @@ TEST(DeclarativeConditionTest, ErrorConditionSet) {
|
| conditions.push_back(ScopedToLinkedPtr(ParseJson("{\"bad_key\": 2}")));
|
|
|
| std::string error;
|
| + std::vector<URLMatcherConditionFactory*> factories;
|
| + factories.push_back(matcher.condition_factory());
|
| scoped_ptr<RecordingConditionSet> result =
|
| - RecordingConditionSet::Create(matcher.condition_factory(),
|
| - conditions, &error);
|
| + RecordingConditionSet::Create(factories, conditions, &error);
|
| EXPECT_EQ("Found error key", error);
|
| ASSERT_FALSE(result);
|
| }
|
| @@ -79,14 +79,16 @@ TEST(DeclarativeConditionTest, CreateConditionSet) {
|
|
|
| // Test insertion
|
| std::string error;
|
| + std::vector<URLMatcherConditionFactory*> factories;
|
| + factories.push_back(matcher.condition_factory());
|
| scoped_ptr<RecordingConditionSet> result =
|
| - RecordingConditionSet::Create(matcher.condition_factory(),
|
| - conditions, &error);
|
| + RecordingConditionSet::Create(factories, conditions, &error);
|
| EXPECT_EQ("", error);
|
| ASSERT_TRUE(result);
|
| EXPECT_EQ(2u, result->conditions().size());
|
|
|
| - EXPECT_EQ(matcher.condition_factory(), result->conditions()[0]->factory);
|
| + EXPECT_EQ(1u, result->conditions()[0]->factories.size());
|
| + EXPECT_EQ(matcher.condition_factory(), result->conditions()[0]->factories[0]);
|
| EXPECT_TRUE(ParseJson("{\"key\": 1}")->Equals(
|
| result->conditions()[0]->value.get()));
|
| }
|
| @@ -102,18 +104,16 @@ struct FulfillableCondition {
|
| return condition_set_id;
|
| }
|
|
|
| - bool has_url_matcher_condition_set() const {
|
| - return true;
|
| - }
|
| -
|
| scoped_refptr<URLMatcherConditionSet> url_matcher_condition_set() const {
|
| return condition_set;
|
| }
|
|
|
| - void GetURLMatcherConditionSets(
|
| - URLMatcherConditionSet::Vector* condition_sets) const {
|
| - if (condition_set)
|
| + int GetURLMatcherConditionSets(
|
| + URLMatcherConditionSet::Vector* condition_sets,
|
| + int index) const {
|
| + if (index == 0 && condition_set)
|
| condition_sets->push_back(condition_set);
|
| + return -1;
|
| }
|
|
|
| bool IsFulfilled(const std::set<URLMatcherConditionSet::ID>& url_matches,
|
| @@ -124,7 +124,8 @@ struct FulfillableCondition {
|
| }
|
|
|
| static scoped_ptr<FulfillableCondition> Create(
|
| - URLMatcherConditionFactory* url_matcher_condition_factory,
|
| + const std::vector<URLMatcherConditionFactory*>&
|
| + url_matcher_condition_factories,
|
| const base::Value& condition,
|
| std::string* error) {
|
| scoped_ptr<FulfillableCondition> result(new FulfillableCondition());
|
| @@ -160,8 +161,9 @@ TEST(DeclarativeConditionTest, FulfillConditionSet) {
|
|
|
| // Test insertion
|
| std::string error;
|
| + std::vector<URLMatcherConditionFactory*> factories;
|
| scoped_ptr<FulfillableConditionSet> result =
|
| - FulfillableConditionSet::Create(NULL, conditions, &error);
|
| + FulfillableConditionSet::Create(factories, conditions, &error);
|
| ASSERT_EQ("", error);
|
| ASSERT_TRUE(result);
|
| EXPECT_EQ(4u, result->conditions().size());
|
| @@ -189,7 +191,7 @@ TEST(DeclarativeConditionTest, FulfillConditionSet) {
|
|
|
| // Check the condition sets:
|
| URLMatcherConditionSet::Vector condition_sets;
|
| - result->GetURLMatcherConditionSets(&condition_sets);
|
| + result->GetURLMatcherConditionSets(&condition_sets, 0);
|
| ASSERT_EQ(3U, condition_sets.size());
|
| EXPECT_EQ(1, condition_sets[0]->id());
|
| EXPECT_EQ(2, condition_sets[1]->id());
|
| @@ -305,8 +307,10 @@ TEST(DeclarativeRuleTest, Create) {
|
| base::Time install_time = base::Time::Now();
|
|
|
| URLMatcher matcher;
|
| + std::vector<URLMatcherConditionFactory*> factories;
|
| + factories.push_back(matcher.condition_factory());
|
| std::string error;
|
| - scoped_ptr<Rule> rule(Rule::Create(matcher.condition_factory(), kExtensionId,
|
| + scoped_ptr<Rule> rule(Rule::Create(factories, kExtensionId,
|
| install_time, json_rule, NULL, &error));
|
| EXPECT_EQ("", error);
|
| ASSERT_TRUE(rule.get());
|
| @@ -350,6 +354,8 @@ TEST(DeclarativeRuleTest, CheckConsistency) {
|
| std::string error;
|
| linked_ptr<Rule::JsonRule> json_rule(new Rule::JsonRule);
|
| const char kExtensionId[] = "ext1";
|
| + std::vector<URLMatcherConditionFactory*> factories;
|
| + factories.push_back(matcher.condition_factory());
|
|
|
| ASSERT_TRUE(Rule::JsonRule::Populate(
|
| *ParseJson("{ \n"
|
| @@ -366,9 +372,8 @@ TEST(DeclarativeRuleTest, CheckConsistency) {
|
| " \"priority\": 200 \n"
|
| "}"),
|
| json_rule.get()));
|
| - scoped_ptr<Rule> rule(
|
| - Rule::Create(matcher.condition_factory(), kExtensionId, base::Time(),
|
| - json_rule, &AtLeastOneCondition, &error));
|
| + scoped_ptr<Rule> rule(Rule::Create(factories, kExtensionId, base::Time(),
|
| + json_rule, &AtLeastOneCondition, &error));
|
| EXPECT_TRUE(rule);
|
| EXPECT_EQ("", error);
|
|
|
| @@ -385,7 +390,7 @@ TEST(DeclarativeRuleTest, CheckConsistency) {
|
| " \"priority\": 200 \n"
|
| "}"),
|
| json_rule.get()));
|
| - rule = Rule::Create(matcher.condition_factory(), kExtensionId, base::Time(),
|
| + rule = Rule::Create(factories, kExtensionId, base::Time(),
|
| json_rule, &AtLeastOneCondition, &error);
|
| EXPECT_FALSE(rule);
|
| EXPECT_EQ("No conditions", error);
|
|
|