Chromium Code Reviews| 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 "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 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 GURL gurl("https://www.google.com:1234/webhp?sourceid=chrome-instant&ie=UTF-8" |
|
Yoyo Zhou
2012/08/14 15:40:11
Hmm, you added a port here, but none of the tests
battre
2012/08/16 13:16:25
Done.
| |
| 330 "&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"); |
| 331 URLMatcherConditionFactory factory; | 331 URLMatcherConditionFactory factory; |
| 332 std::string url = factory.CanonicalizeURLForFullSearches(gurl); | 332 std::string url = factory.CanonicalizeURLForFullSearches(gurl); |
| 333 | 333 |
| 334 EXPECT_TRUE(Matches(factory.CreateURLPrefixCondition(""), url)); | 334 EXPECT_TRUE(Matches(factory.CreateURLPrefixCondition(""), url)); |
| 335 EXPECT_TRUE(Matches(factory.CreateURLPrefixCondition("www.goog"), url)); | 335 EXPECT_TRUE(Matches(factory.CreateURLPrefixCondition( |
| 336 EXPECT_TRUE(Matches(factory.CreateURLPrefixCondition("www.google.com"), url)); | 336 "https://www.goog"), url)); |
| 337 EXPECT_TRUE( | 337 EXPECT_TRUE(Matches(factory.CreateURLPrefixCondition( |
| 338 Matches(factory.CreateURLPrefixCondition(".www.google.com"), url)); | 338 "https://www.google.com"), url)); |
| 339 EXPECT_TRUE( | 339 EXPECT_TRUE(Matches(factory.CreateURLPrefixCondition( |
| 340 Matches(factory.CreateURLPrefixCondition("www.google.com/"), url)); | 340 "https://www.google.com/"), url)); |
| 341 EXPECT_FALSE( Matches(factory.CreateURLPrefixCondition( | |
|
Yoyo Zhou
2012/08/14 15:40:11
nit: extra space after (
battre
2012/08/16 13:16:25
Done.
| |
| 342 "http://www.google.com"), url)); | |
| 341 EXPECT_FALSE(Matches(factory.CreateURLPrefixCondition("webhp"), url)); | 343 EXPECT_FALSE(Matches(factory.CreateURLPrefixCondition("webhp"), url)); |
| 342 | 344 |
| 343 EXPECT_TRUE(Matches(factory.CreateURLSuffixCondition(""), url)); | 345 EXPECT_TRUE(Matches(factory.CreateURLSuffixCondition(""), url)); |
| 344 EXPECT_TRUE(Matches(factory.CreateURLSuffixCondition("ion=1"), url)); | 346 EXPECT_TRUE(Matches(factory.CreateURLSuffixCondition("ion=1"), url)); |
| 345 EXPECT_FALSE(Matches(factory.CreateURLSuffixCondition("www"), url)); | 347 EXPECT_FALSE(Matches(factory.CreateURLSuffixCondition("www"), url)); |
| 346 | 348 |
| 347 EXPECT_TRUE(Matches(factory.CreateURLContainsCondition(""), url)); | 349 EXPECT_TRUE(Matches(factory.CreateURLContainsCondition(""), url)); |
| 348 EXPECT_TRUE(Matches(factory.CreateURLContainsCondition("www.goog"), url)); | 350 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)); | 351 EXPECT_TRUE(Matches(factory.CreateURLContainsCondition("webhp"), url)); |
| 351 EXPECT_TRUE(Matches(factory.CreateURLContainsCondition("?"), url)); | 352 EXPECT_TRUE(Matches(factory.CreateURLContainsCondition("?"), url)); |
| 352 EXPECT_TRUE(Matches(factory.CreateURLContainsCondition("sourceid"), url)); | 353 EXPECT_TRUE(Matches(factory.CreateURLContainsCondition("sourceid"), url)); |
| 353 EXPECT_TRUE(Matches(factory.CreateURLContainsCondition("ion=1"), url)); | 354 EXPECT_TRUE(Matches(factory.CreateURLContainsCondition("ion=1"), url)); |
| 355 EXPECT_FALSE(Matches(factory.CreateURLContainsCondition(".www.goog"), url)); | |
| 354 EXPECT_FALSE(Matches(factory.CreateURLContainsCondition("foobar"), url)); | 356 EXPECT_FALSE(Matches(factory.CreateURLContainsCondition("foobar"), url)); |
| 355 EXPECT_FALSE(Matches(factory.CreateURLContainsCondition("search"), url)); | 357 EXPECT_FALSE(Matches(factory.CreateURLContainsCondition("search"), url)); |
| 356 | 358 |
| 357 EXPECT_TRUE(Matches(factory.CreateURLEqualsCondition( | 359 EXPECT_TRUE(Matches(factory.CreateURLEqualsCondition( |
| 358 "www.google.com/webhp?sourceid=chrome-instant&ie=UTF-8&ion=1"), url)); | 360 "https://www.google.com/webhp?sourceid=chrome-instant&ie=UTF-8&ion=1"), |
| 361 url)); | |
| 359 EXPECT_FALSE( | 362 EXPECT_FALSE( |
| 360 Matches(factory.CreateURLEqualsCondition("www.google.com"), url)); | 363 Matches(factory.CreateURLEqualsCondition("https://www.google.com"), url)); |
| 361 } | 364 } |
| 362 | 365 |
| 363 | 366 |
| 364 // | 367 // |
| 365 // URLMatcherConditionSet | 368 // URLMatcherConditionSet |
| 366 // | 369 // |
| 367 | 370 |
| 368 TEST(URLMatcherConditionSetTest, Constructor) { | 371 TEST(URLMatcherConditionSetTest, Constructor) { |
| 369 URLMatcherConditionFactory factory; | 372 URLMatcherConditionFactory factory; |
| 370 URLMatcherCondition m1 = factory.CreateHostSuffixCondition("example.com"); | 373 URLMatcherCondition m1 = factory.CreateHostSuffixCondition("example.com"); |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 493 // The cached singleton in matcher.condition_factory_ should be destroyed to | 496 // The cached singleton in matcher.condition_factory_ should be destroyed to |
| 494 // free memory. | 497 // free memory. |
| 495 int patternId2 = factory->CreateHostSuffixCondition( | 498 int patternId2 = factory->CreateHostSuffixCondition( |
| 496 "example.com").substring_pattern()->id(); | 499 "example.com").substring_pattern()->id(); |
| 497 // If patternId1 and patternId2 are different that indicates that | 500 // If patternId1 and patternId2 are different that indicates that |
| 498 // matcher.condition_factory_ does not leak memory. | 501 // matcher.condition_factory_ does not leak memory. |
| 499 EXPECT_NE(patternId1, patternId2); | 502 EXPECT_NE(patternId1, patternId2); |
| 500 } | 503 } |
| 501 | 504 |
| 502 } // namespace extensions | 505 } // namespace extensions |
| OLD | NEW |