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 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
477 EXPECT_FALSE(condition_set5->IsMatch(matching_patterns, url1)); | 477 EXPECT_FALSE(condition_set5->IsMatch(matching_patterns, url1)); |
478 matching_patterns.insert(r1.string_pattern()->id()); | 478 matching_patterns.insert(r1.string_pattern()->id()); |
479 EXPECT_TRUE(condition_set5->IsMatch(matching_patterns, url1)); | 479 EXPECT_TRUE(condition_set5->IsMatch(matching_patterns, url1)); |
480 | 480 |
481 regex_conditions.insert(m1); | 481 regex_conditions.insert(m1); |
482 scoped_refptr<URLMatcherConditionSet> condition_set6( | 482 scoped_refptr<URLMatcherConditionSet> condition_set6( |
483 new URLMatcherConditionSet(1, regex_conditions)); | 483 new URLMatcherConditionSet(1, regex_conditions)); |
484 EXPECT_FALSE(condition_set6->IsMatch(matching_patterns, url1)); | 484 EXPECT_FALSE(condition_set6->IsMatch(matching_patterns, url1)); |
485 matching_patterns.insert(m1.string_pattern()->id()); | 485 matching_patterns.insert(m1.string_pattern()->id()); |
486 EXPECT_TRUE(condition_set6->IsMatch(matching_patterns, url1)); | 486 EXPECT_TRUE(condition_set6->IsMatch(matching_patterns, url1)); |
| 487 |
| 488 matching_patterns.clear(); |
| 489 regex_conditions.clear(); |
| 490 URLMatcherCondition r2 = factory.CreateStrippedURLMatchesCondition("b[a]r"); |
| 491 regex_conditions.insert(r2); |
| 492 scoped_refptr<URLMatcherConditionSet> condition_set7( |
| 493 new URLMatcherConditionSet(1, regex_conditions)); |
| 494 EXPECT_FALSE(condition_set7->IsMatch(matching_patterns, url1)); |
| 495 matching_patterns.insert(r2.string_pattern()->id()); |
| 496 EXPECT_TRUE(condition_set7->IsMatch(matching_patterns, url1)); |
487 } | 497 } |
488 | 498 |
489 | 499 |
490 // | 500 // |
491 // URLMatcher | 501 // URLMatcher |
492 // | 502 // |
493 | 503 |
494 TEST(URLMatcherTest, FullTest) { | 504 TEST(URLMatcherTest, FullTest) { |
495 GURL url1("http://www.example.com/foo?bar=1"); | 505 GURL url1("http://www.example.com/foo?bar=1"); |
496 GURL url2("http://foo.example.com/index.html"); | 506 GURL url2("http://foo.example.com/index.html"); |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
619 conditions.insert(factory->CreateQueryContainsCondition("?test=val&a=b")); | 629 conditions.insert(factory->CreateQueryContainsCondition("?test=val&a=b")); |
620 | 630 |
621 const int kConditionSetId = 1; | 631 const int kConditionSetId = 1; |
622 URLMatcherConditionSet::Vector insert; | 632 URLMatcherConditionSet::Vector insert; |
623 insert.push_back(make_scoped_refptr( | 633 insert.push_back(make_scoped_refptr( |
624 new URLMatcherConditionSet(kConditionSetId, conditions))); | 634 new URLMatcherConditionSet(kConditionSetId, conditions))); |
625 matcher.AddConditionSets(insert); | 635 matcher.AddConditionSets(insert); |
626 EXPECT_EQ(1u, matcher.MatchURL(url).size()); | 636 EXPECT_EQ(1u, matcher.MatchURL(url).size()); |
627 } | 637 } |
628 | 638 |
| 639 // Check that matches in everything but the query are found. |
| 640 TEST(URLMatcherTest, TestStrippedUrlRegExPositive) { |
| 641 GURL url("https://www.google.com:1234/webhp?test=val&a=b"); |
| 642 |
| 643 URLMatcher matcher; |
| 644 URLMatcherConditionFactory* factory = matcher.condition_factory(); |
| 645 |
| 646 URLMatcherConditionSet::Conditions conditions; |
| 647 |
| 648 conditions.insert(factory->CreateStrippedURLMatchesCondition("w..hp")); |
| 649 const int kConditionSetId = 1; |
| 650 URLMatcherConditionSet::Vector insert; |
| 651 insert.push_back(make_scoped_refptr( |
| 652 new URLMatcherConditionSet(kConditionSetId, conditions))); |
| 653 matcher.AddConditionSets(insert); |
| 654 EXPECT_EQ(1u, matcher.MatchURL(url).size()); |
| 655 } |
| 656 |
| 657 // Check that matches in the query are ignored. |
| 658 TEST(URLMatcherTest, TestStrippedUrlRegExNegative) { |
| 659 GURL url("https://www.google.com:1234/webhp?test=val&a=b"); |
| 660 |
| 661 URLMatcher matcher; |
| 662 URLMatcherConditionFactory* factory = matcher.condition_factory(); |
| 663 |
| 664 URLMatcherConditionSet::Conditions conditions; |
| 665 |
| 666 conditions.insert(factory->CreateStrippedURLMatchesCondition("val")); |
| 667 const int kConditionSetId = 1; |
| 668 URLMatcherConditionSet::Vector insert; |
| 669 insert.push_back(make_scoped_refptr( |
| 670 new URLMatcherConditionSet(kConditionSetId, conditions))); |
| 671 matcher.AddConditionSets(insert); |
| 672 EXPECT_EQ(0u, matcher.MatchURL(url).size()); |
| 673 } |
| 674 |
629 } // namespace extensions | 675 } // namespace extensions |
OLD | NEW |