summaryrefslogtreecommitdiff
path: root/chromium/components/subresource_filter/core/common/test_ruleset_utils.cc
blob: 9ea5f66337166827da979145a3de813f297f8ab5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/subresource_filter/core/common/test_ruleset_utils.h"

namespace subresource_filter {
namespace testing {

namespace proto = url_pattern_index::proto;

proto::UrlRule CreateSuffixRule(base::StringPiece suffix) {
  proto::UrlRule rule;
  rule.set_semantics(proto::RULE_SEMANTICS_BLACKLIST);
  rule.set_source_type(proto::SOURCE_TYPE_ANY);
  rule.set_element_types(proto::ELEMENT_TYPE_ALL);
  rule.set_url_pattern_type(proto::URL_PATTERN_TYPE_SUBSTRING);
  rule.set_anchor_left(proto::ANCHOR_TYPE_NONE);
  rule.set_anchor_right(proto::ANCHOR_TYPE_BOUNDARY);
  rule.set_url_pattern(suffix.as_string());
  return rule;
}

proto::UrlRule CreateWhitelistRuleForDocument(
    base::StringPiece pattern,
    int32_t activation_types,
    std::vector<std::string> domains) {
  proto::UrlRule rule;
  rule.set_semantics(proto::RULE_SEMANTICS_WHITELIST);
  rule.set_source_type(proto::SOURCE_TYPE_ANY);
  rule.set_activation_types(activation_types);

  for (std::string& domain : domains) {
    rule.add_domains()->set_domain(std::move(domain));
  }

  rule.set_url_pattern_type(proto::URL_PATTERN_TYPE_SUBSTRING);
  rule.set_anchor_left(proto::ANCHOR_TYPE_NONE);
  rule.set_anchor_right(proto::ANCHOR_TYPE_NONE);
  rule.set_url_pattern(pattern.as_string());
  return rule;
}

}  // namespace testing
}  // namespace subresource_filter