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

Unified Diff: chrome/browser/extensions/api/declarative/url_matcher_unittest.cc

Issue 10052035: Implemented port filter for URLMatcher (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comment Created 8 years, 8 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
Index: chrome/browser/extensions/api/declarative/url_matcher_unittest.cc
diff --git a/chrome/browser/extensions/api/declarative/url_matcher_unittest.cc b/chrome/browser/extensions/api/declarative/url_matcher_unittest.cc
index c32b78a52a69afc07a8927d1fd1c17a9f941d721..35c81834b29ee6e74162870e07211ae0374215a1 100644
--- a/chrome/browser/extensions/api/declarative/url_matcher_unittest.cc
+++ b/chrome/browser/extensions/api/declarative/url_matcher_unittest.cc
@@ -45,6 +45,21 @@ TEST(URLMatcherSchemeFilter, TestMatching) {
EXPECT_TRUE(filter2.IsMatch(non_matching_url));
}
+TEST(URLMatcherPortFilter, TestMatching) {
+ std::vector<URLMatcherPortFilter::Range> ranges;
+ ranges.push_back(URLMatcherPortFilter::CreateRange(80, 90));
+ ranges.push_back(URLMatcherPortFilter::CreateRange(8080));
+ URLMatcherPortFilter filter(ranges);
+ EXPECT_TRUE(filter.IsMatch(GURL("http://www.example.com")));
+ EXPECT_TRUE(filter.IsMatch(GURL("http://www.example.com:80")));
+ EXPECT_TRUE(filter.IsMatch(GURL("http://www.example.com:81")));
+ EXPECT_TRUE(filter.IsMatch(GURL("http://www.example.com:90")));
+ EXPECT_TRUE(filter.IsMatch(GURL("http://www.example.com:8080")));
+ EXPECT_FALSE(filter.IsMatch(GURL("http://www.example.com:79")));
+ EXPECT_FALSE(filter.IsMatch(GURL("http://www.example.com:91")));
+ EXPECT_FALSE(filter.IsMatch(GURL("https://www.example.com")));
+}
+
TEST(URLMatcherConditionTest, IsFullURLCondition) {
SubstringPattern pattern("example.com", 1);
EXPECT_FALSE(URLMatcherCondition(URLMatcherCondition::HOST_SUFFIX,
@@ -317,6 +332,8 @@ TEST(URLMatcherConditionSetTest, Constructor) {
TEST(URLMatcherConditionSetTest, Matching) {
GURL url1("http://www.example.com/foo?bar=1");
GURL url2("http://foo.example.com/index.html");
+ GURL url3("http://www.example.com:80/foo?bar=1");
+ GURL url4("http://www.example.com:8080/foo?bar=1");
URLMatcherConditionFactory factory;
URLMatcherCondition m1 = factory.CreateHostSuffixCondition("example.com");
@@ -339,18 +356,30 @@ TEST(URLMatcherConditionSetTest, Matching) {
EXPECT_TRUE(condition_set->IsMatch(matching_substring_patterns, url1));
EXPECT_FALSE(condition_set->IsMatch(matching_substring_patterns, url2));
-
// Test scheme filters.
scoped_refptr<URLMatcherConditionSet> condition_set2(
new URLMatcherConditionSet(1, conditions,
scoped_ptr<URLMatcherSchemeFilter>(
- new URLMatcherSchemeFilter("https"))));
+ new URLMatcherSchemeFilter("https")),
+ scoped_ptr<URLMatcherPortFilter>(NULL)));
EXPECT_FALSE(condition_set2->IsMatch(matching_substring_patterns, url1));
scoped_refptr<URLMatcherConditionSet> condition_set3(
new URLMatcherConditionSet(1, conditions,
scoped_ptr<URLMatcherSchemeFilter>(
- new URLMatcherSchemeFilter("http"))));
+ new URLMatcherSchemeFilter("http")),
+ scoped_ptr<URLMatcherPortFilter>(NULL)));
EXPECT_TRUE(condition_set3->IsMatch(matching_substring_patterns, url1));
+
+ // Test port filters.
+ std::vector<URLMatcherPortFilter::Range> ranges;
+ ranges.push_back(URLMatcherPortFilter::CreateRange(80));
+ scoped_ptr<URLMatcherPortFilter> filter(new URLMatcherPortFilter(ranges));
+ scoped_refptr<URLMatcherConditionSet> condition_set4(
+ new URLMatcherConditionSet(1, conditions,
+ scoped_ptr<URLMatcherSchemeFilter>(NULL), filter.Pass()));
+ EXPECT_TRUE(condition_set4->IsMatch(matching_substring_patterns, url1));
+ EXPECT_TRUE(condition_set4->IsMatch(matching_substring_patterns, url3));
+ EXPECT_FALSE(condition_set4->IsMatch(matching_substring_patterns, url4));
}

Powered by Google App Engine
This is Rietveld 408576698