| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <limits.h> | 5 #include <limits.h> |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 // See test CanSetExactMatchDictionary above for first try. | 412 // See test CanSetExactMatchDictionary above for first try. |
| 413 TEST_F(SdchManagerTest, CanStillSetExactMatchDictionary) { | 413 TEST_F(SdchManagerTest, CanStillSetExactMatchDictionary) { |
| 414 std::string dictionary_domain("x.y.z.google.com"); | 414 std::string dictionary_domain("x.y.z.google.com"); |
| 415 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); | 415 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); |
| 416 | 416 |
| 417 // Perfect match should *STILL* work. | 417 // Perfect match should *STILL* work. |
| 418 EXPECT_TRUE(AddSdchDictionary(dictionary_text, | 418 EXPECT_TRUE(AddSdchDictionary(dictionary_text, |
| 419 GURL("http://" + dictionary_domain))); | 419 GURL("http://" + dictionary_domain))); |
| 420 } | 420 } |
| 421 | 421 |
| 422 TEST_F(SdchManagerTest, PathMatch) { | |
| 423 bool (*PathMatch)(const std::string& path, const std::string& restriction) = | |
| 424 SdchManager::Dictionary::PathMatch; | |
| 425 // Perfect match is supported. | |
| 426 EXPECT_TRUE(PathMatch("/search", "/search")); | |
| 427 EXPECT_TRUE(PathMatch("/search/", "/search/")); | |
| 428 | |
| 429 // Prefix only works if last character of restriction is a slash, or first | |
| 430 // character in path after a match is a slash. Validate each case separately. | |
| 431 | |
| 432 // Rely on the slash in the path (not at the end of the restriction). | |
| 433 EXPECT_TRUE(PathMatch("/search/something", "/search")); | |
| 434 EXPECT_TRUE(PathMatch("/search/s", "/search")); | |
| 435 EXPECT_TRUE(PathMatch("/search/other", "/search")); | |
| 436 EXPECT_TRUE(PathMatch("/search/something", "/search")); | |
| 437 | |
| 438 // Rely on the slash at the end of the restriction. | |
| 439 EXPECT_TRUE(PathMatch("/search/something", "/search/")); | |
| 440 EXPECT_TRUE(PathMatch("/search/s", "/search/")); | |
| 441 EXPECT_TRUE(PathMatch("/search/other", "/search/")); | |
| 442 EXPECT_TRUE(PathMatch("/search/something", "/search/")); | |
| 443 | |
| 444 // Make sure less that sufficient prefix match is false. | |
| 445 EXPECT_FALSE(PathMatch("/sear", "/search")); | |
| 446 EXPECT_FALSE(PathMatch("/", "/search")); | |
| 447 EXPECT_FALSE(PathMatch(std::string(), "/search")); | |
| 448 | |
| 449 // Add examples with several levels of direcories in the restriction. | |
| 450 EXPECT_FALSE(PathMatch("/search/something", "search/s")); | |
| 451 EXPECT_FALSE(PathMatch("/search/", "/search/s")); | |
| 452 | |
| 453 // Make sure adding characters to path will also fail. | |
| 454 EXPECT_FALSE(PathMatch("/searching", "/search/")); | |
| 455 EXPECT_FALSE(PathMatch("/searching", "/search")); | |
| 456 | |
| 457 // Make sure we're case sensitive. | |
| 458 EXPECT_FALSE(PathMatch("/ABC", "/abc")); | |
| 459 EXPECT_FALSE(PathMatch("/abc", "/ABC")); | |
| 460 } | |
| 461 | |
| 462 // The following are only applicable while we have a latency test in the code, | 422 // The following are only applicable while we have a latency test in the code, |
| 463 // and can be removed when that functionality is stripped. | 423 // and can be removed when that functionality is stripped. |
| 464 TEST_F(SdchManagerTest, LatencyTestControls) { | 424 TEST_F(SdchManagerTest, LatencyTestControls) { |
| 465 GURL url("http://www.google.com"); | 425 GURL url("http://www.google.com"); |
| 466 GURL url2("http://www.google2.com"); | 426 GURL url2("http://www.google2.com"); |
| 467 | 427 |
| 468 // First make sure we default to false. | 428 // First make sure we default to false. |
| 469 EXPECT_FALSE(sdch_manager()->AllowLatencyExperiment(url)); | 429 EXPECT_FALSE(sdch_manager()->AllowLatencyExperiment(url)); |
| 470 EXPECT_FALSE(sdch_manager()->AllowLatencyExperiment(url2)); | 430 EXPECT_FALSE(sdch_manager()->AllowLatencyExperiment(url2)); |
| 471 | 431 |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 629 // It should be visible if looked up by hash whether expired or not. | 589 // It should be visible if looked up by hash whether expired or not. |
| 630 scoped_ptr<base::SimpleTestClock> clock(new base::SimpleTestClock); | 590 scoped_ptr<base::SimpleTestClock> clock(new base::SimpleTestClock); |
| 631 clock->SetNow(base::Time::Now()); | 591 clock->SetNow(base::Time::Now()); |
| 632 clock->Advance(base::TimeDelta::FromMinutes(5)); | 592 clock->Advance(base::TimeDelta::FromMinutes(5)); |
| 633 SdchProblemCode problem_code; | 593 SdchProblemCode problem_code; |
| 634 scoped_ptr<SdchManager::DictionarySet> hash_set( | 594 scoped_ptr<SdchManager::DictionarySet> hash_set( |
| 635 sdch_manager()->GetDictionarySetByHash( | 595 sdch_manager()->GetDictionarySetByHash( |
| 636 target_gurl, server_hash, &problem_code).Pass()); | 596 target_gurl, server_hash, &problem_code).Pass()); |
| 637 ASSERT_TRUE(hash_set); | 597 ASSERT_TRUE(hash_set); |
| 638 ASSERT_EQ(SDCH_OK, problem_code); | 598 ASSERT_EQ(SDCH_OK, problem_code); |
| 639 const_cast<SdchManager::Dictionary*>( | 599 const_cast<SdchDictionary*>(hash_set->GetDictionary(server_hash)) |
| 640 hash_set->GetDictionary(server_hash))->SetClockForTesting( | 600 ->SetClockForTesting(clock.Pass()); |
| 641 clock.Pass()); | |
| 642 | 601 |
| 643 // Make sure it's not visible for advertisement, but is visible | 602 // Make sure it's not visible for advertisement, but is visible |
| 644 // if looked up by hash. | 603 // if looked up by hash. |
| 645 EXPECT_FALSE(sdch_manager()->GetDictionarySet(target_gurl)); | 604 EXPECT_FALSE(sdch_manager()->GetDictionarySet(target_gurl)); |
| 646 EXPECT_TRUE(sdch_manager()->GetDictionarySetByHash( | 605 EXPECT_TRUE(sdch_manager()->GetDictionarySetByHash( |
| 647 target_gurl, server_hash, &problem_code)); | 606 target_gurl, server_hash, &problem_code)); |
| 648 EXPECT_EQ(SDCH_OK, problem_code); | 607 EXPECT_EQ(SDCH_OK, problem_code); |
| 649 } | 608 } |
| 650 | 609 |
| 651 TEST_F(SdchManagerTest, SdchOnByDefault) { | 610 TEST_F(SdchManagerTest, SdchOnByDefault) { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 683 | 642 |
| 684 sdch_manager()->RemoveObserver(&observer); | 643 sdch_manager()->RemoveObserver(&observer); |
| 685 EXPECT_EQ(1, observer.dictionary_used_notifications()); | 644 EXPECT_EQ(1, observer.dictionary_used_notifications()); |
| 686 EXPECT_EQ("xyzzy", observer.last_server_hash()); | 645 EXPECT_EQ("xyzzy", observer.last_server_hash()); |
| 687 sdch_manager()->OnDictionaryUsed("plugh"); | 646 sdch_manager()->OnDictionaryUsed("plugh"); |
| 688 EXPECT_EQ(1, observer.dictionary_used_notifications()); | 647 EXPECT_EQ(1, observer.dictionary_used_notifications()); |
| 689 EXPECT_EQ("xyzzy", observer.last_server_hash()); | 648 EXPECT_EQ("xyzzy", observer.last_server_hash()); |
| 690 } | 649 } |
| 691 | 650 |
| 692 } // namespace net | 651 } // namespace net |
| OLD | NEW |