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

Side by Side Diff: chrome/common/extensions/matcher/url_matcher_unittest.cc

Issue 10692158: Refactor URLBlacklistManager to use URLMatcher. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review Created 8 years, 5 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 | Annotate | Revision Log
OLDNEW
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 "chrome/common/extensions/matcher/url_matcher.h" 5 #include "chrome/common/extensions/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 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 // GURL guarantees that neither domain, nor path, nor query may contain 158 // GURL guarantees that neither domain, nor path, nor query may contain
159 // non ASCII-7 characters. We test this here, because a change to this 159 // non ASCII-7 characters. We test this here, because a change to this
160 // guarantee breaks this implementation horribly. 160 // guarantee breaks this implementation horribly.
161 GURL url("http://www.föö.com/föö?föö#föö"); 161 GURL url("http://www.föö.com/föö?föö#föö");
162 EXPECT_TRUE(IsStringASCII(url.host())); 162 EXPECT_TRUE(IsStringASCII(url.host()));
163 EXPECT_TRUE(IsStringASCII(url.path())); 163 EXPECT_TRUE(IsStringASCII(url.path()));
164 EXPECT_TRUE(IsStringASCII(url.query())); 164 EXPECT_TRUE(IsStringASCII(url.query()));
165 EXPECT_FALSE(IsStringASCII(url.ref())); 165 EXPECT_FALSE(IsStringASCII(url.ref()));
166 } 166 }
167 167
168 TEST(URLMatcherConditionFactoryTest, Criteria) {
169 URLMatcherConditionFactory factory;
170 EXPECT_EQ(URLMatcherCondition::HOST_PREFIX,
171 factory.CreateHostPrefixCondition("foo").criterion());
172 EXPECT_EQ(URLMatcherCondition::HOST_SUFFIX,
173 factory.CreateHostSuffixCondition("foo").criterion());
174 EXPECT_EQ(URLMatcherCondition::HOST_CONTAINS,
175 factory.CreateHostContainsCondition("foo").criterion());
176 EXPECT_EQ(URLMatcherCondition::HOST_EQUALS,
177 factory.CreateHostEqualsCondition("foo").criterion());
178 EXPECT_EQ(URLMatcherCondition::PATH_PREFIX,
179 factory.CreatePathPrefixCondition("foo").criterion());
180 EXPECT_EQ(URLMatcherCondition::PATH_SUFFIX,
181 factory.CreatePathSuffixCondition("foo").criterion());
182 EXPECT_EQ(URLMatcherCondition::PATH_CONTAINS,
183 factory.CreatePathContainsCondition("foo").criterion());
184 EXPECT_EQ(URLMatcherCondition::PATH_EQUALS,
185 factory.CreatePathEqualsCondition("foo").criterion());
186 EXPECT_EQ(URLMatcherCondition::QUERY_PREFIX,
187 factory.CreateQueryPrefixCondition("foo").criterion());
188 EXPECT_EQ(URLMatcherCondition::QUERY_SUFFIX,
189 factory.CreateQuerySuffixCondition("foo").criterion());
190 EXPECT_EQ(URLMatcherCondition::QUERY_CONTAINS,
191 factory.CreateQueryContainsCondition("foo").criterion());
192 EXPECT_EQ(URLMatcherCondition::QUERY_EQUALS,
193 factory.CreateQueryEqualsCondition("foo").criterion());
194 EXPECT_EQ(URLMatcherCondition::HOST_SUFFIX_PATH_PREFIX,
195 factory.CreateHostSuffixPathPrefixCondition("foo",
196 "bar").criterion());
197 EXPECT_EQ(URLMatcherCondition::HOST_EQUALS_PATH_PREFIX,
198 factory.CreateHostEqualsPathPrefixCondition("foo",
199 "bar").criterion());
200 EXPECT_EQ(URLMatcherCondition::URL_PREFIX,
201 factory.CreateURLPrefixCondition("foo").criterion());
202 EXPECT_EQ(URLMatcherCondition::URL_SUFFIX,
203 factory.CreateURLSuffixCondition("foo").criterion());
204 EXPECT_EQ(URLMatcherCondition::URL_CONTAINS,
205 factory.CreateURLContainsCondition("foo").criterion());
206 EXPECT_EQ(URLMatcherCondition::URL_EQUALS,
207 factory.CreateURLEqualsCondition("foo").criterion());
208 }
209
168 TEST(URLMatcherConditionFactoryTest, TestSingletonProperty) { 210 TEST(URLMatcherConditionFactoryTest, TestSingletonProperty) {
169 URLMatcherConditionFactory factory; 211 URLMatcherConditionFactory factory;
170 URLMatcherCondition c1 = factory.CreateHostEqualsCondition("www.google.com"); 212 URLMatcherCondition c1 = factory.CreateHostEqualsCondition("www.google.com");
171 URLMatcherCondition c2 = factory.CreateHostEqualsCondition("www.google.com"); 213 URLMatcherCondition c2 = factory.CreateHostEqualsCondition("www.google.com");
172 EXPECT_EQ(c1.criterion(), c2.criterion()); 214 EXPECT_EQ(c1.criterion(), c2.criterion());
173 EXPECT_EQ(c1.substring_pattern(), c2.substring_pattern()); 215 EXPECT_EQ(c1.substring_pattern(), c2.substring_pattern());
174 URLMatcherCondition c3 = factory.CreateHostEqualsCondition("www.google.de"); 216 URLMatcherCondition c3 = factory.CreateHostEqualsCondition("www.google.de");
175 EXPECT_EQ(c2.criterion(), c3.criterion()); 217 EXPECT_EQ(c2.criterion(), c3.criterion());
176 EXPECT_NE(c2.substring_pattern(), c3.substring_pattern()); 218 EXPECT_NE(c2.substring_pattern(), c3.substring_pattern());
177 EXPECT_NE(c2.substring_pattern()->id(), c3.substring_pattern()->id()); 219 EXPECT_NE(c2.substring_pattern()->id(), c3.substring_pattern()->id());
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 307
266 // Test adjacent components 308 // Test adjacent components
267 EXPECT_TRUE(Matches(factory.CreateHostSuffixPathPrefixCondition( 309 EXPECT_TRUE(Matches(factory.CreateHostSuffixPathPrefixCondition(
268 "google.com", "/webhp"), url)); 310 "google.com", "/webhp"), url));
269 EXPECT_TRUE(Matches(factory.CreateHostSuffixPathPrefixCondition( 311 EXPECT_TRUE(Matches(factory.CreateHostSuffixPathPrefixCondition(
270 "", "/webhp"), url)); 312 "", "/webhp"), url));
271 EXPECT_TRUE(Matches(factory.CreateHostSuffixPathPrefixCondition( 313 EXPECT_TRUE(Matches(factory.CreateHostSuffixPathPrefixCondition(
272 "google.com", ""), url)); 314 "google.com", ""), url));
273 EXPECT_FALSE(Matches(factory.CreateHostSuffixPathPrefixCondition( 315 EXPECT_FALSE(Matches(factory.CreateHostSuffixPathPrefixCondition(
274 "www", ""), url)); 316 "www", ""), url));
317
318 EXPECT_TRUE(Matches(factory.CreateHostEqualsPathPrefixCondition(
319 "www.google.com", "/webhp"), url));
320 EXPECT_FALSE(Matches(factory.CreateHostEqualsPathPrefixCondition(
321 "", "/webhp"), url));
322 EXPECT_TRUE(Matches(factory.CreateHostEqualsPathPrefixCondition(
323 "www.google.com", ""), url));
324 EXPECT_FALSE(Matches(factory.CreateHostEqualsPathPrefixCondition(
325 "google.com", ""), url));
275 } 326 }
276 327
277 TEST(URLMatcherConditionFactoryTest, TestFullSearches) { 328 TEST(URLMatcherConditionFactoryTest, TestFullSearches) {
278 GURL gurl("https://www.google.com/webhp?sourceid=chrome-instant&ie=UTF-8" 329 GURL gurl("https://www.google.com/webhp?sourceid=chrome-instant&ie=UTF-8"
279 "&ion=1#hl=en&output=search&sclient=psy-ab&q=chrome%20is%20awesome"); 330 "&ion=1#hl=en&output=search&sclient=psy-ab&q=chrome%20is%20awesome");
280 URLMatcherConditionFactory factory; 331 URLMatcherConditionFactory factory;
281 std::string url = factory.CanonicalizeURLForFullSearches(gurl); 332 std::string url = factory.CanonicalizeURLForFullSearches(gurl);
282 333
283 EXPECT_TRUE(Matches(factory.CreateURLPrefixCondition(""), url)); 334 EXPECT_TRUE(Matches(factory.CreateURLPrefixCondition(""), url));
284 EXPECT_TRUE(Matches(factory.CreateURLPrefixCondition("www.goog"), url)); 335 EXPECT_TRUE(Matches(factory.CreateURLPrefixCondition("www.goog"), url));
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 // The cached singleton in matcher.condition_factory_ should be destroyed to 493 // The cached singleton in matcher.condition_factory_ should be destroyed to
443 // free memory. 494 // free memory.
444 int patternId2 = factory->CreateHostSuffixCondition( 495 int patternId2 = factory->CreateHostSuffixCondition(
445 "example.com").substring_pattern()->id(); 496 "example.com").substring_pattern()->id();
446 // If patternId1 and patternId2 are different that indicates that 497 // If patternId1 and patternId2 are different that indicates that
447 // matcher.condition_factory_ does not leak memory. 498 // matcher.condition_factory_ does not leak memory.
448 EXPECT_NE(patternId1, patternId2); 499 EXPECT_NE(patternId1, patternId2);
449 } 500 }
450 501
451 } // namespace extensions 502 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698