OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "components/subresource_filter/core/common/test_ruleset_utils.h" | 5 #include "components/subresource_filter/core/common/test_ruleset_utils.h" |
6 | 6 |
7 namespace subresource_filter { | 7 namespace subresource_filter { |
8 namespace testing { | 8 namespace testing { |
9 | 9 |
10 proto::UrlRule CreateSuffixRule(base::StringPiece suffix) { | 10 proto::UrlRule CreateUrlRule(base::StringPiece pattern, |
| 11 proto::UrlPatternType pattern_type) { |
11 proto::UrlRule rule; | 12 proto::UrlRule rule; |
12 rule.set_semantics(proto::RULE_SEMANTICS_BLACKLIST); | 13 rule.set_semantics(proto::RULE_SEMANTICS_BLACKLIST); |
13 rule.set_source_type(proto::SOURCE_TYPE_ANY); | 14 rule.set_source_type(proto::SOURCE_TYPE_ANY); |
14 rule.set_element_types(proto::ELEMENT_TYPE_ALL); | 15 rule.set_element_types(proto::ELEMENT_TYPE_ALL); |
15 rule.set_url_pattern_type(proto::URL_PATTERN_TYPE_SUBSTRING); | 16 rule.set_url_pattern_type(pattern_type); |
16 rule.set_anchor_left(proto::ANCHOR_TYPE_NONE); | 17 rule.set_anchor_left(proto::ANCHOR_TYPE_NONE); |
17 rule.set_anchor_right(proto::ANCHOR_TYPE_BOUNDARY); | 18 rule.set_anchor_right(proto::ANCHOR_TYPE_NONE); |
18 rule.set_url_pattern(suffix.as_string()); | 19 rule.set_url_pattern(pattern.as_string()); |
19 return rule; | 20 return rule; |
20 } | 21 } |
21 | 22 |
| 23 proto::UrlRule CreateSuffixRule(base::StringPiece suffix) { |
| 24 proto::UrlRule rule = |
| 25 CreateUrlRule(suffix, proto::URL_PATTERN_TYPE_SUBSTRING); |
| 26 rule.set_anchor_right(proto::ANCHOR_TYPE_BOUNDARY); |
| 27 return rule; |
| 28 } |
| 29 |
22 proto::UrlRule CreateWhitelistRuleForDocument( | 30 proto::UrlRule CreateWhitelistRuleForDocument( |
23 base::StringPiece pattern, | 31 base::StringPiece pattern, |
24 int32_t activation_types, | 32 int32_t activation_types, |
25 std::vector<std::string> domains) { | 33 std::vector<std::string> domains) { |
26 proto::UrlRule rule; | 34 proto::UrlRule rule; |
27 rule.set_semantics(proto::RULE_SEMANTICS_WHITELIST); | 35 rule.set_semantics(proto::RULE_SEMANTICS_WHITELIST); |
28 rule.set_source_type(proto::SOURCE_TYPE_ANY); | 36 rule.set_source_type(proto::SOURCE_TYPE_ANY); |
29 rule.set_activation_types(activation_types); | 37 rule.set_activation_types(activation_types); |
30 | 38 |
31 for (std::string& domain : domains) { | 39 for (std::string& domain : domains) { |
32 rule.add_domains()->set_domain(std::move(domain)); | 40 rule.add_domains()->set_domain(std::move(domain)); |
33 } | 41 } |
34 | 42 |
35 rule.set_url_pattern_type(proto::URL_PATTERN_TYPE_SUBSTRING); | 43 rule.set_url_pattern_type(proto::URL_PATTERN_TYPE_SUBSTRING); |
36 rule.set_anchor_left(proto::ANCHOR_TYPE_NONE); | 44 rule.set_anchor_left(proto::ANCHOR_TYPE_NONE); |
37 rule.set_anchor_right(proto::ANCHOR_TYPE_NONE); | 45 rule.set_anchor_right(proto::ANCHOR_TYPE_NONE); |
38 rule.set_url_pattern(pattern.as_string()); | 46 rule.set_url_pattern(pattern.as_string()); |
39 return rule; | 47 return rule; |
40 } | 48 } |
41 | 49 |
42 } // namespace testing | 50 } // namespace testing |
43 } // namespace subresource_filter | 51 } // namespace subresource_filter |
OLD | NEW |