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 10823313: Let url filter test the scheme in urlContains/Equals/Prefix/Suffix criteria (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments Created 8 years, 4 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
« no previous file with comments | « chrome/common/extensions/matcher/url_matcher.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) 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 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 // Check that all SubstringPattern singletons are freed if we call 223 // Check that all SubstringPattern singletons are freed if we call
224 // ForgetUnusedPatterns. 224 // ForgetUnusedPatterns.
225 SubstringPattern::ID old_id_1 = c1.substring_pattern()->id(); 225 SubstringPattern::ID old_id_1 = c1.substring_pattern()->id();
226 factory.ForgetUnusedPatterns(std::set<SubstringPattern::ID>()); 226 factory.ForgetUnusedPatterns(std::set<SubstringPattern::ID>());
227 EXPECT_TRUE(factory.IsEmpty()); 227 EXPECT_TRUE(factory.IsEmpty());
228 URLMatcherCondition c4 = factory.CreateHostEqualsCondition("www.google.com"); 228 URLMatcherCondition c4 = factory.CreateHostEqualsCondition("www.google.com");
229 EXPECT_NE(old_id_1, c4.substring_pattern()->id()); 229 EXPECT_NE(old_id_1, c4.substring_pattern()->id());
230 } 230 }
231 231
232 TEST(URLMatcherConditionFactoryTest, TestComponentSearches) { 232 TEST(URLMatcherConditionFactoryTest, TestComponentSearches) {
233 GURL gurl("https://www.google.com/webhp?sourceid=chrome-instant&ie=UTF-8" 233 GURL gurl("https://www.google.com:1234/webhp?sourceid=chrome-instant&ie=UTF-8"
234 "&ion=1#hl=en&output=search&sclient=psy-ab&q=chrome%20is%20awesome"); 234 "&ion=1#hl=en&output=search&sclient=psy-ab&q=chrome%20is%20awesome");
235 URLMatcherConditionFactory factory; 235 URLMatcherConditionFactory factory;
236 std::string url = factory.CanonicalizeURLForComponentSearches(gurl); 236 std::string url = factory.CanonicalizeURLForComponentSearches(gurl);
237 237
238 // Test host component. 238 // Test host component.
239 EXPECT_TRUE(Matches(factory.CreateHostPrefixCondition(""), url)); 239 EXPECT_TRUE(Matches(factory.CreateHostPrefixCondition(""), url));
240 EXPECT_TRUE(Matches(factory.CreateHostPrefixCondition("www.goog"), url)); 240 EXPECT_TRUE(Matches(factory.CreateHostPrefixCondition("www.goog"), url));
241 EXPECT_TRUE( 241 EXPECT_TRUE(
242 Matches(factory.CreateHostPrefixCondition("www.google.com"), url)); 242 Matches(factory.CreateHostPrefixCondition("www.google.com"), url));
243 EXPECT_TRUE( 243 EXPECT_TRUE(
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 "www.google.com", "/webhp"), url)); 319 "www.google.com", "/webhp"), url));
320 EXPECT_FALSE(Matches(factory.CreateHostEqualsPathPrefixCondition( 320 EXPECT_FALSE(Matches(factory.CreateHostEqualsPathPrefixCondition(
321 "", "/webhp"), url)); 321 "", "/webhp"), url));
322 EXPECT_TRUE(Matches(factory.CreateHostEqualsPathPrefixCondition( 322 EXPECT_TRUE(Matches(factory.CreateHostEqualsPathPrefixCondition(
323 "www.google.com", ""), url)); 323 "www.google.com", ""), url));
324 EXPECT_FALSE(Matches(factory.CreateHostEqualsPathPrefixCondition( 324 EXPECT_FALSE(Matches(factory.CreateHostEqualsPathPrefixCondition(
325 "google.com", ""), url)); 325 "google.com", ""), url));
326 } 326 }
327 327
328 TEST(URLMatcherConditionFactoryTest, TestFullSearches) { 328 TEST(URLMatcherConditionFactoryTest, TestFullSearches) {
329 GURL gurl("https://www.google.com/webhp?sourceid=chrome-instant&ie=UTF-8" 329 // The Port 443 is stripped because it is the default port for https.
330 GURL gurl("https://www.google.com:443/webhp?sourceid=chrome-instant&ie=UTF-8"
330 "&ion=1#hl=en&output=search&sclient=psy-ab&q=chrome%20is%20awesome"); 331 "&ion=1#hl=en&output=search&sclient=psy-ab&q=chrome%20is%20awesome");
331 URLMatcherConditionFactory factory; 332 URLMatcherConditionFactory factory;
332 std::string url = factory.CanonicalizeURLForFullSearches(gurl); 333 std::string url = factory.CanonicalizeURLForFullSearches(gurl);
333 334
334 EXPECT_TRUE(Matches(factory.CreateURLPrefixCondition(""), url)); 335 EXPECT_TRUE(Matches(factory.CreateURLPrefixCondition(""), url));
335 EXPECT_TRUE(Matches(factory.CreateURLPrefixCondition("www.goog"), url)); 336 EXPECT_TRUE(Matches(factory.CreateURLPrefixCondition(
336 EXPECT_TRUE(Matches(factory.CreateURLPrefixCondition("www.google.com"), url)); 337 "https://www.goog"), url));
337 EXPECT_TRUE( 338 EXPECT_TRUE(Matches(factory.CreateURLPrefixCondition(
338 Matches(factory.CreateURLPrefixCondition(".www.google.com"), url)); 339 "https://www.google.com"), url));
339 EXPECT_TRUE( 340 EXPECT_TRUE(Matches(factory.CreateURLPrefixCondition(
340 Matches(factory.CreateURLPrefixCondition("www.google.com/"), url)); 341 "https://www.google.com/webhp?"), url));
342 EXPECT_FALSE(Matches(factory.CreateURLPrefixCondition(
343 "http://www.google.com"), url));
341 EXPECT_FALSE(Matches(factory.CreateURLPrefixCondition("webhp"), url)); 344 EXPECT_FALSE(Matches(factory.CreateURLPrefixCondition("webhp"), url));
342 345
343 EXPECT_TRUE(Matches(factory.CreateURLSuffixCondition(""), url)); 346 EXPECT_TRUE(Matches(factory.CreateURLSuffixCondition(""), url));
344 EXPECT_TRUE(Matches(factory.CreateURLSuffixCondition("ion=1"), url)); 347 EXPECT_TRUE(Matches(factory.CreateURLSuffixCondition("ion=1"), url));
345 EXPECT_FALSE(Matches(factory.CreateURLSuffixCondition("www"), url)); 348 EXPECT_FALSE(Matches(factory.CreateURLSuffixCondition("www"), url));
346 349
347 EXPECT_TRUE(Matches(factory.CreateURLContainsCondition(""), url)); 350 EXPECT_TRUE(Matches(factory.CreateURLContainsCondition(""), url));
348 EXPECT_TRUE(Matches(factory.CreateURLContainsCondition("www.goog"), url)); 351 EXPECT_TRUE(Matches(factory.CreateURLContainsCondition("www.goog"), url));
349 EXPECT_TRUE(Matches(factory.CreateURLContainsCondition(".www.goog"), url));
350 EXPECT_TRUE(Matches(factory.CreateURLContainsCondition("webhp"), url)); 352 EXPECT_TRUE(Matches(factory.CreateURLContainsCondition("webhp"), url));
351 EXPECT_TRUE(Matches(factory.CreateURLContainsCondition("?"), url)); 353 EXPECT_TRUE(Matches(factory.CreateURLContainsCondition("?"), url));
352 EXPECT_TRUE(Matches(factory.CreateURLContainsCondition("sourceid"), url)); 354 EXPECT_TRUE(Matches(factory.CreateURLContainsCondition("sourceid"), url));
353 EXPECT_TRUE(Matches(factory.CreateURLContainsCondition("ion=1"), url)); 355 EXPECT_TRUE(Matches(factory.CreateURLContainsCondition("ion=1"), url));
356 EXPECT_FALSE(Matches(factory.CreateURLContainsCondition(".www.goog"), url));
354 EXPECT_FALSE(Matches(factory.CreateURLContainsCondition("foobar"), url)); 357 EXPECT_FALSE(Matches(factory.CreateURLContainsCondition("foobar"), url));
355 EXPECT_FALSE(Matches(factory.CreateURLContainsCondition("search"), url)); 358 EXPECT_FALSE(Matches(factory.CreateURLContainsCondition("search"), url));
359 EXPECT_FALSE(Matches(factory.CreateURLContainsCondition(":443"), url));
356 360
357 EXPECT_TRUE(Matches(factory.CreateURLEqualsCondition( 361 EXPECT_TRUE(Matches(factory.CreateURLEqualsCondition(
358 "www.google.com/webhp?sourceid=chrome-instant&ie=UTF-8&ion=1"), url)); 362 "https://www.google.com/webhp?sourceid=chrome-instant&ie=UTF-8&ion=1"),
363 url));
359 EXPECT_FALSE( 364 EXPECT_FALSE(
360 Matches(factory.CreateURLEqualsCondition("www.google.com"), url)); 365 Matches(factory.CreateURLEqualsCondition("https://www.google.com"), url));
366
367 // Same as above but this time with a non-standard port.
368 gurl = GURL("https://www.google.com:1234/webhp?sourceid=chrome-instant&"
369 "ie=UTF-8&ion=1#hl=en&output=search&sclient=psy-ab&q=chrome%20is%20"
370 "awesome");
371 url = factory.CanonicalizeURLForFullSearches(gurl);
372 EXPECT_TRUE(Matches(factory.CreateURLPrefixCondition(
373 "https://www.google.com:1234/webhp?"), url));
374 EXPECT_TRUE(Matches(factory.CreateURLContainsCondition(":1234"), url));
361 } 375 }
362 376
363 377
364 // 378 //
365 // URLMatcherConditionSet 379 // URLMatcherConditionSet
366 // 380 //
367 381
368 TEST(URLMatcherConditionSetTest, Constructor) { 382 TEST(URLMatcherConditionSetTest, Constructor) {
369 URLMatcherConditionFactory factory; 383 URLMatcherConditionFactory factory;
370 URLMatcherCondition m1 = factory.CreateHostSuffixCondition("example.com"); 384 URLMatcherCondition m1 = factory.CreateHostSuffixCondition("example.com");
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 // The cached singleton in matcher.condition_factory_ should be destroyed to 507 // The cached singleton in matcher.condition_factory_ should be destroyed to
494 // free memory. 508 // free memory.
495 int patternId2 = factory->CreateHostSuffixCondition( 509 int patternId2 = factory->CreateHostSuffixCondition(
496 "example.com").substring_pattern()->id(); 510 "example.com").substring_pattern()->id();
497 // If patternId1 and patternId2 are different that indicates that 511 // If patternId1 and patternId2 are different that indicates that
498 // matcher.condition_factory_ does not leak memory. 512 // matcher.condition_factory_ does not leak memory.
499 EXPECT_NE(patternId1, patternId2); 513 EXPECT_NE(patternId1, patternId2);
500 } 514 }
501 515
502 } // namespace extensions 516 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/common/extensions/matcher/url_matcher.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698