OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "extensions/common/matcher/url_matcher.h" | 5 #include "extensions/common/matcher/url_matcher.h" |
6 | 6 |
7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
8 #include "googleurl/src/gurl.h" | 8 #include "googleurl/src/gurl.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
482 EXPECT_FALSE(condition_set5->IsMatch(matching_patterns, url1)); | 482 EXPECT_FALSE(condition_set5->IsMatch(matching_patterns, url1)); |
483 matching_patterns.insert(r1.string_pattern()->id()); | 483 matching_patterns.insert(r1.string_pattern()->id()); |
484 EXPECT_TRUE(condition_set5->IsMatch(matching_patterns, url1)); | 484 EXPECT_TRUE(condition_set5->IsMatch(matching_patterns, url1)); |
485 | 485 |
486 regex_conditions.insert(m1); | 486 regex_conditions.insert(m1); |
487 scoped_refptr<URLMatcherConditionSet> condition_set6( | 487 scoped_refptr<URLMatcherConditionSet> condition_set6( |
488 new URLMatcherConditionSet(1, regex_conditions)); | 488 new URLMatcherConditionSet(1, regex_conditions)); |
489 EXPECT_FALSE(condition_set6->IsMatch(matching_patterns, url1)); | 489 EXPECT_FALSE(condition_set6->IsMatch(matching_patterns, url1)); |
490 matching_patterns.insert(m1.string_pattern()->id()); | 490 matching_patterns.insert(m1.string_pattern()->id()); |
491 EXPECT_TRUE(condition_set6->IsMatch(matching_patterns, url1)); | 491 EXPECT_TRUE(condition_set6->IsMatch(matching_patterns, url1)); |
| 492 |
| 493 matching_patterns.clear(); |
| 494 regex_conditions.clear(); |
| 495 URLMatcherCondition r2 = factory.CreateOriginAndPathMatchesCondition("b[a]r"); |
| 496 regex_conditions.insert(r2); |
| 497 scoped_refptr<URLMatcherConditionSet> condition_set7( |
| 498 new URLMatcherConditionSet(1, regex_conditions)); |
| 499 EXPECT_FALSE(condition_set7->IsMatch(matching_patterns, url1)); |
| 500 matching_patterns.insert(r2.string_pattern()->id()); |
| 501 EXPECT_TRUE(condition_set7->IsMatch(matching_patterns, url1)); |
492 } | 502 } |
493 | 503 |
494 | 504 |
495 // | 505 // |
496 // URLMatcher | 506 // URLMatcher |
497 // | 507 // |
498 | 508 |
499 TEST(URLMatcherTest, FullTest) { | 509 TEST(URLMatcherTest, FullTest) { |
500 GURL url1("http://www.example.com/foo?bar=1"); | 510 GURL url1("http://www.example.com/foo?bar=1"); |
501 GURL url2("http://foo.example.com/index.html"); | 511 GURL url2("http://foo.example.com/index.html"); |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
624 conditions.insert(factory->CreateQueryContainsCondition("?test=val&a=b")); | 634 conditions.insert(factory->CreateQueryContainsCondition("?test=val&a=b")); |
625 | 635 |
626 const int kConditionSetId = 1; | 636 const int kConditionSetId = 1; |
627 URLMatcherConditionSet::Vector insert; | 637 URLMatcherConditionSet::Vector insert; |
628 insert.push_back(make_scoped_refptr( | 638 insert.push_back(make_scoped_refptr( |
629 new URLMatcherConditionSet(kConditionSetId, conditions))); | 639 new URLMatcherConditionSet(kConditionSetId, conditions))); |
630 matcher.AddConditionSets(insert); | 640 matcher.AddConditionSets(insert); |
631 EXPECT_EQ(1u, matcher.MatchURL(url).size()); | 641 EXPECT_EQ(1u, matcher.MatchURL(url).size()); |
632 } | 642 } |
633 | 643 |
| 644 // Check that matches in everything but the query are found. |
| 645 TEST(URLMatcherTest, TestOriginAndPathRegExPositive) { |
| 646 GURL url("https://www.google.com:1234/webhp?test=val&a=b"); |
| 647 |
| 648 URLMatcher matcher; |
| 649 URLMatcherConditionFactory* factory = matcher.condition_factory(); |
| 650 |
| 651 URLMatcherConditionSet::Conditions conditions; |
| 652 |
| 653 conditions.insert(factory->CreateOriginAndPathMatchesCondition("w..hp")); |
| 654 const int kConditionSetId = 1; |
| 655 URLMatcherConditionSet::Vector insert; |
| 656 insert.push_back(make_scoped_refptr( |
| 657 new URLMatcherConditionSet(kConditionSetId, conditions))); |
| 658 matcher.AddConditionSets(insert); |
| 659 EXPECT_EQ(1u, matcher.MatchURL(url).size()); |
| 660 } |
| 661 |
| 662 // Check that matches in the query are ignored. |
| 663 TEST(URLMatcherTest, TestOriginAndPathRegExNegative) { |
| 664 GURL url("https://www.google.com:1234/webhp?test=val&a=b"); |
| 665 |
| 666 URLMatcher matcher; |
| 667 URLMatcherConditionFactory* factory = matcher.condition_factory(); |
| 668 |
| 669 URLMatcherConditionSet::Conditions conditions; |
| 670 |
| 671 conditions.insert(factory->CreateOriginAndPathMatchesCondition("val")); |
| 672 const int kConditionSetId = 1; |
| 673 URLMatcherConditionSet::Vector insert; |
| 674 insert.push_back(make_scoped_refptr( |
| 675 new URLMatcherConditionSet(kConditionSetId, conditions))); |
| 676 matcher.AddConditionSets(insert); |
| 677 EXPECT_EQ(0u, matcher.MatchURL(url).size()); |
| 678 } |
| 679 |
634 } // namespace extensions | 680 } // namespace extensions |
OLD | NEW |