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

Side by Side Diff: chrome/common/extensions/url_pattern_unittest.cc

Issue 2876009: Re-implement app overlap detection with new extent syntax. (Closed) Base URL: git://codf21.jail/chromium.git
Patch Set: donk Created 10 years, 6 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 unified diff | Download patch
« no previous file with comments | « chrome/common/extensions/url_pattern.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2009 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 "base/scoped_ptr.h"
5 #include "chrome/common/extensions/url_pattern.h" 6 #include "chrome/common/extensions/url_pattern.h"
6 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
7 8
8 // See url_pattern.h for examples of valid and invalid patterns. 9 // See url_pattern.h for examples of valid and invalid patterns.
9 10
10 TEST(URLPatternTest, ParseInvalid) { 11 TEST(URLPatternTest, ParseInvalid) {
11 const char* kInvalidPatterns[] = { 12 const char* kInvalidPatterns[] = {
12 "http", // no scheme 13 "http", // no scheme
13 "http://", // no path separator 14 "http://", // no path separator
14 "http://foo", // no path separator 15 "http://foo", // no path separator
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 URLPattern pattern; 126 URLPattern pattern;
126 EXPECT_TRUE(pattern.Parse("chrome://favicon/*")); 127 EXPECT_TRUE(pattern.Parse("chrome://favicon/*"));
127 EXPECT_EQ("chrome", pattern.scheme()); 128 EXPECT_EQ("chrome", pattern.scheme());
128 EXPECT_EQ("favicon", pattern.host()); 129 EXPECT_EQ("favicon", pattern.host());
129 EXPECT_FALSE(pattern.match_subdomains()); 130 EXPECT_FALSE(pattern.match_subdomains());
130 EXPECT_EQ("/*", pattern.path()); 131 EXPECT_EQ("/*", pattern.path());
131 EXPECT_TRUE(pattern.MatchesUrl(GURL("chrome://favicon/http://google.com"))); 132 EXPECT_TRUE(pattern.MatchesUrl(GURL("chrome://favicon/http://google.com")));
132 EXPECT_TRUE(pattern.MatchesUrl(GURL("chrome://favicon/https://google.com"))); 133 EXPECT_TRUE(pattern.MatchesUrl(GURL("chrome://favicon/https://google.com")));
133 EXPECT_FALSE(pattern.MatchesUrl(GURL("chrome://history"))); 134 EXPECT_FALSE(pattern.MatchesUrl(GURL("chrome://history")));
134 }; 135 };
136
137 void TestPatternOverlap(URLPattern* pattern1, URLPattern* pattern2,
138 bool expect_overlap) {
139 EXPECT_EQ(expect_overlap, pattern1->OverlapsWith(*pattern2))
140 << pattern1->GetAsString() << ", " << pattern2->GetAsString();
141 EXPECT_EQ(expect_overlap, pattern2->OverlapsWith(*pattern1))
142 << pattern2->GetAsString() << ", " << pattern1->GetAsString();
143 }
144
145 TEST(URLPatternTest, OverlapsWith) {
146 scoped_ptr<URLPattern> pattern1(
147 URLPattern::CreateFromString("http://www.google.com/foo/*"));
148 scoped_ptr<URLPattern> pattern2(
149 URLPattern::CreateFromString("https://www.google.com/foo/*"));
150 scoped_ptr<URLPattern> pattern3(
151 URLPattern::CreateFromString("http://*.google.com/foo/*"));
152 scoped_ptr<URLPattern> pattern4(
153 URLPattern::CreateFromString("http://*.yahooo.com/foo/*"));
154 scoped_ptr<URLPattern> pattern5(
155 URLPattern::CreateFromString("http://www.yahooo.com/bar/*"));
156 scoped_ptr<URLPattern> pattern6(
157 URLPattern::CreateFromString("http://www.yahooo.com/bar/baz/*"));
158
159 TestPatternOverlap(pattern1.get(), pattern1.get(), true);
160 TestPatternOverlap(pattern1.get(), pattern2.get(), false);
161 TestPatternOverlap(pattern1.get(), pattern3.get(), true);
162 TestPatternOverlap(pattern1.get(), pattern4.get(), false);
163 TestPatternOverlap(pattern3.get(), pattern4.get(), false);
164 TestPatternOverlap(pattern4.get(), pattern5.get(), false);
165 TestPatternOverlap(pattern5.get(), pattern6.get(), true);
166 }
OLDNEW
« no previous file with comments | « chrome/common/extensions/url_pattern.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698