OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "components/url_matcher/url_matcher.h" | 5 #include "components/url_matcher/url_matcher.h" |
6 | 6 |
7 #include "base/strings/string_util.h" | 7 #include "base/strings/string_util.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 #include "url/gurl.h" | 9 #include "url/gurl.h" |
10 | 10 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
62 | 62 |
63 TEST(URLMatcherConditionTest, IsFullURLCondition) { | 63 TEST(URLMatcherConditionTest, IsFullURLCondition) { |
64 StringPattern pattern("example.com", 1); | 64 StringPattern pattern("example.com", 1); |
65 EXPECT_FALSE(URLMatcherCondition(URLMatcherCondition::HOST_SUFFIX, | 65 EXPECT_FALSE(URLMatcherCondition(URLMatcherCondition::HOST_SUFFIX, |
66 &pattern).IsFullURLCondition()); | 66 &pattern).IsFullURLCondition()); |
67 | 67 |
68 EXPECT_TRUE(URLMatcherCondition(URLMatcherCondition::HOST_CONTAINS, | 68 EXPECT_TRUE(URLMatcherCondition(URLMatcherCondition::HOST_CONTAINS, |
69 &pattern).IsFullURLCondition()); | 69 &pattern).IsFullURLCondition()); |
70 EXPECT_TRUE(URLMatcherCondition(URLMatcherCondition::PATH_CONTAINS, | 70 EXPECT_TRUE(URLMatcherCondition(URLMatcherCondition::PATH_CONTAINS, |
71 &pattern).IsFullURLCondition()); | 71 &pattern).IsFullURLCondition()); |
72 EXPECT_TRUE(URLMatcherCondition(URLMatcherCondition::QUERY_CONTAINS, | 72 EXPECT_FALSE(URLMatcherCondition(URLMatcherCondition::QUERY_CONTAINS, |
73 &pattern).IsFullURLCondition()); | 73 &pattern).IsFullURLCondition()); |
74 | 74 |
75 EXPECT_TRUE(URLMatcherCondition(URLMatcherCondition::URL_PREFIX, | 75 EXPECT_TRUE(URLMatcherCondition(URLMatcherCondition::URL_PREFIX, |
76 &pattern).IsFullURLCondition()); | 76 &pattern).IsFullURLCondition()); |
77 EXPECT_TRUE(URLMatcherCondition(URLMatcherCondition::URL_SUFFIX, | 77 EXPECT_TRUE(URLMatcherCondition(URLMatcherCondition::URL_SUFFIX, |
78 &pattern).IsFullURLCondition()); | 78 &pattern).IsFullURLCondition()); |
79 EXPECT_TRUE(URLMatcherCondition(URLMatcherCondition::URL_CONTAINS, | 79 EXPECT_TRUE(URLMatcherCondition(URLMatcherCondition::URL_CONTAINS, |
80 &pattern).IsFullURLCondition()); | 80 &pattern).IsFullURLCondition()); |
81 EXPECT_TRUE(URLMatcherCondition(URLMatcherCondition::URL_EQUALS, | 81 EXPECT_TRUE(URLMatcherCondition(URLMatcherCondition::URL_EQUALS, |
82 &pattern).IsFullURLCondition()); | 82 &pattern).IsFullURLCondition()); |
83 } | 83 } |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
319 EXPECT_FALSE(Matches(factory.CreateQueryEqualsCondition( | 319 EXPECT_FALSE(Matches(factory.CreateQueryEqualsCondition( |
320 "sourceid=chrome-instant&ie=UTF-8&ion="), url)); | 320 "sourceid=chrome-instant&ie=UTF-8&ion="), url)); |
321 EXPECT_TRUE(Matches(factory.CreateQueryEqualsCondition( | 321 EXPECT_TRUE(Matches(factory.CreateQueryEqualsCondition( |
322 "sourceid=chrome-instant&ie=UTF-8&ion=1"), url)); | 322 "sourceid=chrome-instant&ie=UTF-8&ion=1"), url)); |
323 // The '?' at the beginning is just ignored. | 323 // The '?' at the beginning is just ignored. |
324 EXPECT_TRUE(Matches(factory.CreateQueryEqualsCondition( | 324 EXPECT_TRUE(Matches(factory.CreateQueryEqualsCondition( |
325 "?sourceid=chrome-instant&ie=UTF-8&ion=1"), url)); | 325 "?sourceid=chrome-instant&ie=UTF-8&ion=1"), url)); |
326 EXPECT_FALSE( | 326 EXPECT_FALSE( |
327 Matches(factory.CreateQueryEqualsCondition("www.google.com"), url)); | 327 Matches(factory.CreateQueryEqualsCondition("www.google.com"), url)); |
328 | 328 |
329 EXPECT_FALSE( | |
330 Matches(factory.CreateQueryContainsCondition("www.google.com"), url)); | |
331 EXPECT_TRUE(Matches( | |
332 factory.CreateQueryContainsCondition("sourceid=chrome-instant"), url)); | |
333 // The '?' at the beginning is just ignored. | |
334 EXPECT_TRUE(Matches( | |
335 factory.CreateQueryContainsCondition("?sourceid=chrome-instant"), url)); | |
336 EXPECT_TRUE(Matches(factory.CreateQueryContainsCondition("?ie=UTF-8"), url)); | |
337 EXPECT_TRUE(Matches(factory.CreateQueryContainsCondition("ie=UTF-8"), url)); | |
338 // Partial key value pairs not supported | |
339 EXPECT_FALSE( | |
340 Matches(factory.CreateQueryContainsCondition("t&ie=UTF-8"), url)); | |
341 // Looks for an exact match, i.e., looks for "&e=UTF-8" or "?e=UTF-8" below | |
342 // and fails. | |
343 EXPECT_FALSE(Matches(factory.CreateQueryContainsCondition("e=UTF-8"), url)); | |
344 // Multiple key value pairs are supported (though not very useful) | |
battre
2014/04/01 08:23:00
I think the two previous occurrences are not 100%
kaliamoorthi
2014/04/01 13:11:17
Done.
| |
345 EXPECT_TRUE(Matches( | |
346 factory.CreateQueryContainsCondition("sourceid=chrome-instant&ie=UTF-8"), | |
347 url)); | |
329 | 348 |
330 // Test adjacent components | 349 // Test adjacent components |
331 EXPECT_TRUE(Matches(factory.CreateHostSuffixPathPrefixCondition( | 350 EXPECT_TRUE(Matches(factory.CreateHostSuffixPathPrefixCondition( |
332 "google.com", "/webhp"), url)); | 351 "google.com", "/webhp"), url)); |
333 EXPECT_TRUE(Matches( | 352 EXPECT_TRUE(Matches( |
334 factory.CreateHostSuffixPathPrefixCondition(std::string(), "/webhp"), | 353 factory.CreateHostSuffixPathPrefixCondition(std::string(), "/webhp"), |
335 url)); | 354 url)); |
336 EXPECT_TRUE(Matches( | 355 EXPECT_TRUE(Matches( |
337 factory.CreateHostSuffixPathPrefixCondition("google.com", std::string()), | 356 factory.CreateHostSuffixPathPrefixCondition("google.com", std::string()), |
338 url)); | 357 url)); |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
621 conditions.insert(factory->CreatePathSuffixCondition("hp")); | 640 conditions.insert(factory->CreatePathSuffixCondition("hp")); |
622 conditions.insert(factory->CreatePathContainsCondition("hp")); | 641 conditions.insert(factory->CreatePathContainsCondition("hp")); |
623 | 642 |
624 conditions.insert(factory->CreateQueryEqualsCondition("test=val&a=b")); | 643 conditions.insert(factory->CreateQueryEqualsCondition("test=val&a=b")); |
625 conditions.insert(factory->CreateQueryContainsCondition("test=val&a=b")); | 644 conditions.insert(factory->CreateQueryContainsCondition("test=val&a=b")); |
626 | 645 |
627 conditions.insert(factory->CreateQueryPrefixCondition("test=v")); | 646 conditions.insert(factory->CreateQueryPrefixCondition("test=v")); |
628 conditions.insert(factory->CreateQueryContainsCondition("test=v")); | 647 conditions.insert(factory->CreateQueryContainsCondition("test=v")); |
629 | 648 |
630 conditions.insert(factory->CreateQuerySuffixCondition("l&a=b")); | 649 conditions.insert(factory->CreateQuerySuffixCondition("l&a=b")); |
631 conditions.insert(factory->CreateQueryContainsCondition("l&a=b")); | |
632 | 650 |
633 // The '?' for equality is just ignored. | 651 // The '?' for equality is just ignored. |
634 conditions.insert(factory->CreateQueryEqualsCondition("?test=val&a=b")); | 652 conditions.insert(factory->CreateQueryEqualsCondition("?test=val&a=b")); |
635 // Due to '?' the condition created here is a prefix-testing condition. | 653 // Due to '?' the condition created here is a prefix-testing condition. |
636 conditions.insert(factory->CreateQueryContainsCondition("?test=val&a=b")); | 654 conditions.insert(factory->CreateQueryContainsCondition("?test=val&a=b")); |
637 | 655 |
638 const int kConditionSetId = 1; | 656 const int kConditionSetId = 1; |
639 URLMatcherConditionSet::Vector insert; | 657 URLMatcherConditionSet::Vector insert; |
640 insert.push_back(make_scoped_refptr( | 658 insert.push_back(make_scoped_refptr( |
641 new URLMatcherConditionSet(kConditionSetId, conditions))); | 659 new URLMatcherConditionSet(kConditionSetId, conditions))); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
673 conditions.insert(factory->CreateOriginAndPathMatchesCondition("val")); | 691 conditions.insert(factory->CreateOriginAndPathMatchesCondition("val")); |
674 const int kConditionSetId = 1; | 692 const int kConditionSetId = 1; |
675 URLMatcherConditionSet::Vector insert; | 693 URLMatcherConditionSet::Vector insert; |
676 insert.push_back(make_scoped_refptr( | 694 insert.push_back(make_scoped_refptr( |
677 new URLMatcherConditionSet(kConditionSetId, conditions))); | 695 new URLMatcherConditionSet(kConditionSetId, conditions))); |
678 matcher.AddConditionSets(insert); | 696 matcher.AddConditionSets(insert); |
679 EXPECT_EQ(0u, matcher.MatchURL(url).size()); | 697 EXPECT_EQ(0u, matcher.MatchURL(url).size()); |
680 } | 698 } |
681 | 699 |
682 } // namespace url_matcher | 700 } // namespace url_matcher |
OLD | NEW |