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

Unified Diff: components/subresource_filter/core/common/url_rule_test_support.cc

Issue 2865643002: Clean up IndexedRuleset tests; factor out test_support. (Closed)
Patch Set: Address comments from engedy@. Created 3 years, 7 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
« no previous file with comments | « components/subresource_filter/core/common/url_rule_test_support.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/subresource_filter/core/common/url_rule_test_support.cc
diff --git a/components/subresource_filter/core/common/url_rule_test_support.cc b/components/subresource_filter/core/common/url_rule_test_support.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ab6f7f1bfe71633caeb86e2d606159afb920b531
--- /dev/null
+++ b/components/subresource_filter/core/common/url_rule_test_support.cc
@@ -0,0 +1,56 @@
+// 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/url_rule_test_support.h"
+
+#include "base/logging.h"
+#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
+#include "url/gurl.h"
+#include "url/origin.h"
+
+namespace subresource_filter {
+namespace testing {
+
+proto::UrlRule MakeUrlRule(const UrlPattern& url_pattern) {
+ proto::UrlRule rule;
+
+ rule.set_semantics(proto::RULE_SEMANTICS_BLACKLIST);
+ rule.set_source_type(proto::SOURCE_TYPE_ANY);
+ rule.set_element_types(kAllElementTypes);
+
+ rule.set_url_pattern_type(url_pattern.type());
+ rule.set_anchor_left(url_pattern.anchor_left());
+ rule.set_anchor_right(url_pattern.anchor_right());
+ rule.set_match_case(url_pattern.match_case());
+ rule.set_url_pattern(url_pattern.url_pattern().as_string());
+
+ return rule;
+}
+
+void AddDomains(const std::vector<std::string>& domains, proto::UrlRule* rule) {
+ for (std::string domain_pattern : domains) {
+ DCHECK(!domain_pattern.empty());
+ auto* domain = rule->add_domains();
+ if (domain_pattern[0] == '~') {
+ domain_pattern.erase(0, 1);
+ domain->set_exclude(true);
+ }
+ domain->set_domain(std::move(domain_pattern));
+ }
+}
+
+url::Origin GetOrigin(base::StringPiece origin_string) {
+ return !origin_string.empty() ? url::Origin(GURL(origin_string))
+ : url::Origin();
+}
+
+bool IsThirdParty(const GURL& url, const url::Origin& first_party_origin) {
+ return first_party_origin.unique() ||
+ !net::registry_controlled_domains::SameDomainOrHost(
+ url, first_party_origin,
+ net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES);
+}
+
+} // namespace testing
+} // namespace subresource_filter
« no previous file with comments | « components/subresource_filter/core/common/url_rule_test_support.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698