Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 <algorithm> | 5 #include <algorithm> |
| 6 #include <string> | 6 #include <string> |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/scoped_ptr.h" | 10 #include "base/scoped_ptr.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 42 | 42 |
| 43 std::string NewSdchCompressedData(const std::string dictionary); | 43 std::string NewSdchCompressedData(const std::string dictionary); |
| 44 | 44 |
| 45 const std::string test_vcdiff_dictionary_; | 45 const std::string test_vcdiff_dictionary_; |
| 46 const std::string vcdiff_compressed_data_; | 46 const std::string vcdiff_compressed_data_; |
| 47 const std::string expanded_; // Desired final, decompressed data. | 47 const std::string expanded_; // Desired final, decompressed data. |
| 48 | 48 |
| 49 scoped_ptr<SdchManager> sdch_manager_; // A singleton database. | 49 scoped_ptr<SdchManager> sdch_manager_; // A singleton database. |
| 50 }; | 50 }; |
| 51 | 51 |
| 52 std::string SdchFilterTest::NewSdchCompressedData(const std::string dictionary) { | 52 std::string SdchFilterTest::NewSdchCompressedData( |
| 53 const std::string dictionary) { | |
| 53 std::string client_hash; | 54 std::string client_hash; |
| 54 std::string server_hash; | 55 std::string server_hash; |
| 55 SdchManager::GenerateHash(dictionary, &client_hash, &server_hash); | 56 SdchManager::GenerateHash(dictionary, &client_hash, &server_hash); |
| 56 | 57 |
| 57 // Build compressed data that refers to our dictionary. | 58 // Build compressed data that refers to our dictionary. |
| 58 std::string compressed(server_hash); | 59 std::string compressed(server_hash); |
| 59 compressed.append("\0", 1); | 60 compressed.append("\0", 1); |
| 60 compressed.append(vcdiff_compressed_data_); | 61 compressed.append(vcdiff_compressed_data_); |
| 61 return compressed; | 62 return compressed; |
| 62 } | 63 } |
| (...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 574 GURL google_url("http://www.google.com"); | 575 GURL google_url("http://www.google.com"); |
| 575 | 576 |
| 576 SdchManager::BlacklistDomain(test_url); | 577 SdchManager::BlacklistDomain(test_url); |
| 577 EXPECT_FALSE(SdchManager::Global()->IsInSupportedDomain(test_url)); | 578 EXPECT_FALSE(SdchManager::Global()->IsInSupportedDomain(test_url)); |
| 578 EXPECT_TRUE(SdchManager::Global()->IsInSupportedDomain(google_url)); | 579 EXPECT_TRUE(SdchManager::Global()->IsInSupportedDomain(google_url)); |
| 579 | 580 |
| 580 SdchManager::BlacklistDomain(google_url); | 581 SdchManager::BlacklistDomain(google_url); |
| 581 EXPECT_FALSE(SdchManager::Global()->IsInSupportedDomain(test_url)); | 582 EXPECT_FALSE(SdchManager::Global()->IsInSupportedDomain(test_url)); |
| 582 EXPECT_FALSE(SdchManager::Global()->IsInSupportedDomain(google_url)); | 583 EXPECT_FALSE(SdchManager::Global()->IsInSupportedDomain(google_url)); |
| 583 } | 584 } |
| 585 | |
| 586 TEST_F(SdchFilterTest, CanSetExactMatchDictionary) { | |
| 587 std::string dictionary_domain("x.y.z.google.com"); | |
| 588 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); | |
| 589 | |
| 590 // Perfect match should work. | |
| 591 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary_text, | |
| 592 GURL("http://" + dictionary_domain))); | |
| 593 } | |
| 594 | |
| 595 TEST_F(SdchFilterTest, FailToSetDomainMismatchDictionary) { | |
| 596 std::string dictionary_domain("x.y.z.google.com"); | |
| 597 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); | |
| 598 | |
| 599 // Fail the "domain match" requirement. | |
| 600 EXPECT_FALSE(sdch_manager_->AddSdchDictionary(dictionary_text, | |
| 601 GURL("http://y.z.google.com"))); | |
| 602 } | |
| 603 | |
| 604 TEST_F(SdchFilterTest, FailToSetDotHostPrefixDomainDictionary) { | |
| 605 std::string dictionary_domain("x.y.z.google.com"); | |
| 606 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); | |
| 607 | |
| 608 // Fail the HD with D being the domain and H having a dot requirement. | |
| 609 EXPECT_FALSE(sdch_manager_->AddSdchDictionary(dictionary_text, | |
| 610 GURL("http://w.x.y.z.google.com"))); | |
| 611 } | |
| 612 | |
| 613 TEST_F(SdchFilterTest, FailToSetRepeatPrefixWithDotDictionary) { | |
| 614 // Make sure that a prefix that matches the domain postfix won't confuse | |
| 615 // the validation checks. | |
| 616 std::string dictionary_domain("www.google.com"); | |
| 617 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); | |
| 618 | |
| 619 // Fail the HD with D being the domain and H having a dot requirement. | |
| 620 EXPECT_FALSE(sdch_manager_->AddSdchDictionary(dictionary_text, | |
| 621 GURL("http://www.google.com.www.google.com"))); | |
| 622 } | |
| 623 | |
| 624 TEST_F(SdchFilterTest, CanSetLeadingDotDomainDictionary) { | |
| 625 // Make sure that a prefix that matches the domain postfix won't confuse | |
| 626 // the validation checks. | |
| 627 std::string dictionary_domain(".google.com"); | |
| 628 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); | |
| 629 | |
| 630 // Fail the HD with D being the domain and H having a dot requirement. | |
|
Lincoln
2008/11/15 01:37:02
Comment is not accurate -- this test should pass.
| |
| 631 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary_text, | |
| 632 GURL("http://www.google.com"))); | |
| 633 } | |
| 634 | |
| 635 // Make sure the order of the tests is not helping us or confusing things. | |
| 636 // See test CanSetExactMatchDictionary above for first try. | |
| 637 TEST_F(SdchFilterTest, CanStillSetExactMatchDictionary) { | |
| 638 std::string dictionary_domain("x.y.z.google.com"); | |
| 639 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); | |
| 640 | |
| 641 // Perfect match should *STILL* work. | |
| 642 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary_text, | |
| 643 GURL("http://" + dictionary_domain))); | |
| 644 } | |
| OLD | NEW |