| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/extensions/api/declarative/declarative_rule.h" | 5 #include "chrome/browser/extensions/api/declarative/declarative_rule.h" |
| 6 | 6 |
| 7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "base/test/values_test_util.h" | 8 #include "base/test/values_test_util.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "chrome/common/extensions/matcher/url_matcher_constants.h" | 10 #include "chrome/common/extensions/matcher/url_matcher_constants.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 typedef int MatchData; | 28 typedef int MatchData; |
| 29 | 29 |
| 30 URLMatcherConditionFactory* factory; | 30 URLMatcherConditionFactory* factory; |
| 31 scoped_ptr<base::Value> value; | 31 scoped_ptr<base::Value> value; |
| 32 | 32 |
| 33 void GetURLMatcherConditionSets( | 33 void GetURLMatcherConditionSets( |
| 34 URLMatcherConditionSet::Vector* condition_sets) const { | 34 URLMatcherConditionSet::Vector* condition_sets) const { |
| 35 // No condition sets. | 35 // No condition sets. |
| 36 } | 36 } |
| 37 | 37 |
| 38 bool has_url_matcher_condition_set() const { | |
| 39 return false; | |
| 40 } | |
| 41 | |
| 42 static scoped_ptr<RecordingCondition> Create( | 38 static scoped_ptr<RecordingCondition> Create( |
| 43 URLMatcherConditionFactory* url_matcher_condition_factory, | 39 URLMatcherConditionFactory* url_matcher_condition_factory, |
| 44 const base::Value& condition, | 40 const base::Value& condition, |
| 45 std::string* error) { | 41 std::string* error) { |
| 46 const base::DictionaryValue* dict = NULL; | 42 const base::DictionaryValue* dict = NULL; |
| 47 if (condition.GetAsDictionary(&dict) && dict->HasKey("bad_key")) { | 43 if (condition.GetAsDictionary(&dict) && dict->HasKey("bad_key")) { |
| 48 *error = "Found error key"; | 44 *error = "Found error key"; |
| 49 return scoped_ptr<RecordingCondition>(); | 45 return scoped_ptr<RecordingCondition>(); |
| 50 } | 46 } |
| 51 | 47 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 typedef int MatchData; | 91 typedef int MatchData; |
| 96 | 92 |
| 97 scoped_refptr<URLMatcherConditionSet> condition_set; | 93 scoped_refptr<URLMatcherConditionSet> condition_set; |
| 98 int condition_set_id; | 94 int condition_set_id; |
| 99 int max_value; | 95 int max_value; |
| 100 | 96 |
| 101 URLMatcherConditionSet::ID url_matcher_condition_set_id() const { | 97 URLMatcherConditionSet::ID url_matcher_condition_set_id() const { |
| 102 return condition_set_id; | 98 return condition_set_id; |
| 103 } | 99 } |
| 104 | 100 |
| 105 bool has_url_matcher_condition_set() const { | |
| 106 return true; | |
| 107 } | |
| 108 | |
| 109 scoped_refptr<URLMatcherConditionSet> url_matcher_condition_set() const { | 101 scoped_refptr<URLMatcherConditionSet> url_matcher_condition_set() const { |
| 110 return condition_set; | 102 return condition_set; |
| 111 } | 103 } |
| 112 | 104 |
| 113 void GetURLMatcherConditionSets( | 105 void GetURLMatcherConditionSets( |
| 114 URLMatcherConditionSet::Vector* condition_sets) const { | 106 URLMatcherConditionSet::Vector* condition_sets) const { |
| 115 if (condition_set) | 107 if (condition_set) |
| 116 condition_sets->push_back(condition_set); | 108 condition_sets->push_back(condition_set); |
| 117 } | 109 } |
| 118 | 110 |
| 119 bool IsFulfilled(const std::set<URLMatcherConditionSet::ID>& url_matches, | 111 bool IsFulfilled(const std::set<URLMatcherConditionSet::ID>& url_matches, |
| 120 int match_data) const { | 112 int match_data) const { |
| 121 if (condition_set_id != -1 && !ContainsKey(url_matches, condition_set_id)) | 113 if (condition_set_id != -1 && !ContainsKey(url_matches, condition_set_id)) |
| 122 return false; | 114 return false; |
| 123 return match_data <= max_value; | 115 return match_data <= max_value; |
| 124 } | 116 } |
| 125 | 117 |
| 126 static scoped_ptr<FulfillableCondition> Create( | 118 static scoped_ptr<FulfillableCondition> Create( |
| 127 URLMatcherConditionFactory* url_matcher_condition_factory, | 119 URLMatcherConditionFactory* /*url_matcher_condition_factory*/, |
| 128 const base::Value& condition, | 120 const base::Value& condition, |
| 129 std::string* error) { | 121 std::string* error) { |
| 130 scoped_ptr<FulfillableCondition> result(new FulfillableCondition()); | 122 scoped_ptr<FulfillableCondition> result(new FulfillableCondition()); |
| 131 const base::DictionaryValue* dict; | 123 const base::DictionaryValue* dict; |
| 132 if (!condition.GetAsDictionary(&dict)) { | 124 if (!condition.GetAsDictionary(&dict)) { |
| 133 *error = "Expected dict"; | 125 *error = "Expected dict"; |
| 134 return result.Pass(); | 126 return result.Pass(); |
| 135 } | 127 } |
| 136 if (!dict->GetInteger("url_id", &result->condition_set_id)) | 128 if (!dict->GetInteger("url_id", &result->condition_set_id)) |
| 137 result->condition_set_id = -1; | 129 result->condition_set_id = -1; |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 " \"priority\": 200 \n" | 377 " \"priority\": 200 \n" |
| 386 "}"), | 378 "}"), |
| 387 json_rule.get())); | 379 json_rule.get())); |
| 388 rule = Rule::Create(matcher.condition_factory(), kExtensionId, base::Time(), | 380 rule = Rule::Create(matcher.condition_factory(), kExtensionId, base::Time(), |
| 389 json_rule, &AtLeastOneCondition, &error); | 381 json_rule, &AtLeastOneCondition, &error); |
| 390 EXPECT_FALSE(rule); | 382 EXPECT_FALSE(rule); |
| 391 EXPECT_EQ("No conditions", error); | 383 EXPECT_EQ("No conditions", error); |
| 392 } | 384 } |
| 393 | 385 |
| 394 } // namespace extensions | 386 } // namespace extensions |
| OLD | NEW |