url_matcher: Treat FQDN hosts as if they were relative.
This changes URLMatcher to not make a difference between
fully-qualified and relative URLs. Patterns that specify
fully-qualified host names now also match the corresponding relative
host name in URLs and fully-qualified host names in URLs now match
patterns that use relative host names.
BUG=chromium:493142
TEST=Added unit and browser test coverage.
Review URL: https://codereview.chromium.org/1167483002
Cr-Commit-Position: refs/heads/master@{#331963}
diff --git a/components/url_matcher/url_matcher_unittest.cc b/components/url_matcher/url_matcher_unittest.cc
index b69364c2..328c633 100644
--- a/components/url_matcher/url_matcher_unittest.cc
+++ b/components/url_matcher/url_matcher_unittest.cc
@@ -241,10 +241,14 @@
}
TEST(URLMatcherConditionFactoryTest, TestComponentSearches) {
+ URLMatcherConditionFactory factory;
GURL gurl("https://www.google.com:1234/webhp?sourceid=chrome-instant&ie=UTF-8"
"&ion=1#hl=en&output=search&sclient=psy-ab&q=chrome%20is%20awesome");
- URLMatcherConditionFactory factory;
std::string url = factory.CanonicalizeURLForComponentSearches(gurl);
+ GURL gurl2("https://www.google.com.:1234/webhp?sourceid=chrome-instant"
+ "&ie=UTF-8&ion=1#hl=en&output=search&sclient=psy-ab"
+ "&q=chrome%20is%20awesome");
+ std::string url2 = factory.CanonicalizeURLForComponentSearches(gurl2);
// Test host component.
EXPECT_TRUE(Matches(factory.CreateHostPrefixCondition(std::string()), url));
@@ -259,12 +263,18 @@
EXPECT_FALSE(Matches(factory.CreateHostPrefixCondition("webhp"), url));
EXPECT_TRUE(Matches(factory.CreateHostSuffixCondition(std::string()), url));
+ EXPECT_TRUE(Matches(factory.CreateHostSuffixCondition(std::string()), url2));
EXPECT_TRUE(Matches(factory.CreateHostSuffixCondition("com"), url));
+ EXPECT_TRUE(Matches(factory.CreateHostSuffixCondition("com"), url2));
EXPECT_TRUE(Matches(factory.CreateHostSuffixCondition(".com"), url));
EXPECT_TRUE(
Matches(factory.CreateHostSuffixCondition("www.google.com"), url));
EXPECT_TRUE(
Matches(factory.CreateHostSuffixCondition(".www.google.com"), url));
+ EXPECT_TRUE(
+ Matches(factory.CreateHostSuffixCondition(".www.google.com"), url2));
+ EXPECT_TRUE(
+ Matches(factory.CreateHostSuffixCondition(".www.google.com."), url));
EXPECT_FALSE(Matches(factory.CreateHostSuffixCondition("www"), url));
EXPECT_FALSE(
Matches(factory.CreateHostSuffixCondition("www.google.com/"), url));
@@ -274,9 +284,14 @@
EXPECT_FALSE(Matches(factory.CreateHostEqualsCondition("www"), url));
EXPECT_TRUE(
Matches(factory.CreateHostEqualsCondition("www.google.com"), url));
+ EXPECT_TRUE(
+ Matches(factory.CreateHostEqualsCondition("www.google.com"), url2));
EXPECT_FALSE(
Matches(factory.CreateHostEqualsCondition("www.google.com/"), url));
-
+ EXPECT_TRUE(
+ Matches(factory.CreateHostEqualsCondition(".www.google.com."), url));
+ EXPECT_TRUE(
+ Matches(factory.CreateHostEqualsCondition(".www.google.com."), url2));
// Test path component.
EXPECT_TRUE(Matches(factory.CreatePathPrefixCondition(std::string()), url));
@@ -330,6 +345,12 @@
// Test adjacent components
EXPECT_TRUE(Matches(factory.CreateHostSuffixPathPrefixCondition(
"google.com", "/webhp"), url));
+ EXPECT_TRUE(Matches(factory.CreateHostSuffixPathPrefixCondition(
+ "google.com", "/webhp"), url2));
+ EXPECT_TRUE(Matches(factory.CreateHostSuffixPathPrefixCondition(
+ "google.com.", "/webhp"), url));
+ EXPECT_TRUE(Matches(factory.CreateHostSuffixPathPrefixCondition(
+ "google.com.", "/webhp"), url2));
EXPECT_TRUE(Matches(
factory.CreateHostSuffixPathPrefixCondition(std::string(), "/webhp"),
url));
@@ -341,6 +362,12 @@
EXPECT_TRUE(Matches(factory.CreateHostEqualsPathPrefixCondition(
"www.google.com", "/webhp"), url));
+ EXPECT_TRUE(Matches(factory.CreateHostEqualsPathPrefixCondition(
+ "www.google.com", "/webhp"), url2));
+ EXPECT_TRUE(Matches(factory.CreateHostEqualsPathPrefixCondition(
+ ".www.google.com.", "/webhp"), url));
+ EXPECT_TRUE(Matches(factory.CreateHostEqualsPathPrefixCondition(
+ ".www.google.com.", "/webhp"), url2));
EXPECT_FALSE(Matches(
factory.CreateHostEqualsPathPrefixCondition(std::string(), "/webhp"),
url));