Chromium Code Reviews| Index: net/base/sdch_manager_unittest.cc |
| diff --git a/net/base/sdch_manager_unittest.cc b/net/base/sdch_manager_unittest.cc |
| index d986879aaa4c9b9928039f3290731e5ca49f0b0f..2736b523388e28cccbe4f02c85bf69935eb8ee0f 100644 |
| --- a/net/base/sdch_manager_unittest.cc |
| +++ b/net/base/sdch_manager_unittest.cc |
| @@ -8,6 +8,7 @@ |
| #include "base/logging.h" |
| #include "base/memory/scoped_ptr.h" |
| +#include "base/strings/stringprintf.h" |
| #include "net/base/sdch_manager.h" |
| #include "net/base/sdch_observer.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| @@ -73,14 +74,21 @@ class SdchManagerTest : public testing::Test { |
| // failure. |
| bool AddSdchDictionary(const std::string& dictionary_text, |
| const GURL& gurl) { |
| - std::string list; |
| - sdch_manager_->GetAvailDictionaryList(gurl, &list); |
| + scoped_ptr<SdchManager::DictionarySet> set1( |
| + sdch_manager_->GetDictionarySet(gurl)); |
| + std::string set1_hashes; |
| + if (set1) |
| + set1->GetDictionaryClientHashList(&set1_hashes); |
| + |
| sdch_manager_->AddSdchDictionary(dictionary_text, gurl); |
| - std::string list2; |
| - sdch_manager_->GetAvailDictionaryList(gurl, &list2); |
| + scoped_ptr<SdchManager::DictionarySet> set2( |
| + sdch_manager_->GetDictionarySet(gurl)); |
| + std::string set2_hashes; |
| + if (set2) |
| + set2->GetDictionaryClientHashList(&set2_hashes); |
| // The list of hashes should change iff the addition succeeds. |
| - return (list != list2); |
| + return (set1_hashes != set2_hashes); |
| } |
| private: |
| @@ -114,11 +122,11 @@ TEST_F(SdchManagerTest, DomainBlacklisting) { |
| GURL test_url("http://www.test.com"); |
| GURL google_url("http://www.google.com"); |
| - sdch_manager()->BlacklistDomain(test_url, SdchManager::MIN_PROBLEM_CODE); |
| + sdch_manager()->BlacklistDomain(test_url, SdchManager::OK); |
| EXPECT_FALSE(sdch_manager()->IsInSupportedDomain(test_url)); |
| EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(google_url)); |
| - sdch_manager()->BlacklistDomain(google_url, SdchManager::MIN_PROBLEM_CODE); |
| + sdch_manager()->BlacklistDomain(google_url, SdchManager::OK); |
| EXPECT_FALSE(sdch_manager()->IsInSupportedDomain(google_url)); |
| } |
| @@ -128,7 +136,7 @@ TEST_F(SdchManagerTest, DomainBlacklistingCaseSensitivity) { |
| EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(test_url)); |
| EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(test2_url)); |
| - sdch_manager()->BlacklistDomain(test_url, SdchManager::MIN_PROBLEM_CODE); |
| + sdch_manager()->BlacklistDomain(test_url, SdchManager::OK); |
| EXPECT_FALSE(sdch_manager()->IsInSupportedDomain(test2_url)); |
| } |
| @@ -147,7 +155,7 @@ TEST_F(SdchManagerTest, BlacklistingSingleBlacklist) { |
| std::string domain(gurl.host()); |
| sdch_manager()->ClearBlacklistings(); |
| - sdch_manager()->BlacklistDomain(gurl, SdchManager::MIN_PROBLEM_CODE); |
| + sdch_manager()->BlacklistDomain(gurl, SdchManager::OK); |
| EXPECT_EQ(sdch_manager()->BlackListDomainCount(domain), 1); |
| EXPECT_EQ(sdch_manager()->BlacklistDomainExponential(domain), 1); |
| @@ -164,7 +172,7 @@ TEST_F(SdchManagerTest, BlacklistingExponential) { |
| int exponential = 1; |
| for (int i = 1; i < 100; ++i) { |
| - sdch_manager()->BlacklistDomain(gurl, SdchManager::MIN_PROBLEM_CODE); |
| + sdch_manager()->BlacklistDomain(gurl, SdchManager::OK); |
| EXPECT_EQ(sdch_manager()->BlacklistDomainExponential(domain), exponential); |
| EXPECT_EQ(sdch_manager()->BlackListDomainCount(domain), exponential); |
| @@ -200,12 +208,9 @@ TEST_F(SdchManagerTest, CanAdvertiseDictionaryOverHTTP) { |
| EXPECT_TRUE(AddSdchDictionary(dictionary_text, |
| GURL("http://" + dictionary_domain))); |
| - std::string dictionary_list; |
| // HTTP target URL can advertise dictionary. |
| - sdch_manager()->GetAvailDictionaryList( |
| - GURL("http://" + dictionary_domain + "/test"), |
| - &dictionary_list); |
| - EXPECT_FALSE(dictionary_list.empty()); |
| + EXPECT_TRUE(sdch_manager()->GetDictionarySet( |
| + GURL("http://" + dictionary_domain + "/test"))); |
| } |
| TEST_F(SdchManagerTest, CanNotAdvertiseDictionaryOverHTTPS) { |
| @@ -215,12 +220,9 @@ TEST_F(SdchManagerTest, CanNotAdvertiseDictionaryOverHTTPS) { |
| EXPECT_TRUE(AddSdchDictionary(dictionary_text, |
| GURL("http://" + dictionary_domain))); |
| - std::string dictionary_list; |
| // HTTPS target URL should NOT advertise dictionary. |
| - sdch_manager()->GetAvailDictionaryList( |
| - GURL("https://" + dictionary_domain + "/test"), |
| - &dictionary_list); |
| - EXPECT_TRUE(dictionary_list.empty()); |
| + EXPECT_FALSE(sdch_manager()->GetDictionarySet( |
| + GURL("https://" + dictionary_domain + "/test"))); |
| } |
| TEST_F(SdchManagerTest, CanUseHTTPSDictionaryOverHTTPSIfEnabled) { |
| @@ -235,19 +237,18 @@ TEST_F(SdchManagerTest, CanUseHTTPSDictionaryOverHTTPSIfEnabled) { |
| GURL("https://" + dictionary_domain))); |
| GURL target_url("https://" + dictionary_domain + "/test"); |
| - std::string dictionary_list; |
| // HTTPS target URL should advertise dictionary if secure scheme support is |
| // enabled. |
| - sdch_manager()->GetAvailDictionaryList(target_url, &dictionary_list); |
| - EXPECT_FALSE(dictionary_list.empty()); |
| + EXPECT_TRUE(sdch_manager()->GetDictionarySet(target_url)); |
| // Dictionary should be available. |
| - scoped_refptr<SdchManager::Dictionary> dictionary; |
| std::string client_hash; |
| std::string server_hash; |
| sdch_manager()->GenerateHash(dictionary_text, &client_hash, &server_hash); |
| - sdch_manager()->GetVcdiffDictionary(server_hash, target_url, &dictionary); |
| - EXPECT_TRUE(dictionary.get() != NULL); |
| + scoped_ptr<SdchManager::DictionarySet> dict_set( |
| + sdch_manager()->GetDictionarySetByHash(target_url, server_hash)); |
| + EXPECT_TRUE(dict_set.get()); |
| + EXPECT_TRUE(dict_set->Dictionary(server_hash)); |
| } |
| TEST_F(SdchManagerTest, CanNotUseHTTPDictionaryOverHTTPS) { |
| @@ -258,19 +259,17 @@ TEST_F(SdchManagerTest, CanNotUseHTTPDictionaryOverHTTPS) { |
| GURL("http://" + dictionary_domain))); |
| GURL target_url("https://" + dictionary_domain + "/test"); |
| - std::string dictionary_list; |
| // HTTPS target URL should not advertise dictionary acquired over HTTP even if |
| // secure scheme support is enabled. |
| SdchManager::EnableSecureSchemeSupport(true); |
| - sdch_manager()->GetAvailDictionaryList(target_url, &dictionary_list); |
| - EXPECT_TRUE(dictionary_list.empty()); |
| + EXPECT_FALSE(sdch_manager()->GetDictionarySet(target_url)); |
| - scoped_refptr<SdchManager::Dictionary> dictionary; |
| std::string client_hash; |
| std::string server_hash; |
| sdch_manager()->GenerateHash(dictionary_text, &client_hash, &server_hash); |
| - sdch_manager()->GetVcdiffDictionary(server_hash, target_url, &dictionary); |
| - EXPECT_TRUE(dictionary.get() == NULL); |
| + scoped_ptr<SdchManager::DictionarySet> dict_set( |
| + sdch_manager()->GetDictionarySetByHash(target_url, server_hash)); |
| + EXPECT_FALSE(dict_set.get()); |
| } |
| TEST_F(SdchManagerTest, CanNotUseHTTPSDictionaryOverHTTP) { |
| @@ -282,18 +281,16 @@ TEST_F(SdchManagerTest, CanNotUseHTTPSDictionaryOverHTTP) { |
| GURL("https://" + dictionary_domain))); |
| GURL target_url("http://" + dictionary_domain + "/test"); |
| - std::string dictionary_list; |
| // HTTP target URL should not advertise dictionary acquired over HTTPS even if |
| // secure scheme support is enabled. |
| - sdch_manager()->GetAvailDictionaryList(target_url, &dictionary_list); |
| - EXPECT_TRUE(dictionary_list.empty()); |
| + EXPECT_FALSE(sdch_manager()->GetDictionarySet(target_url)); |
| - scoped_refptr<SdchManager::Dictionary> dictionary; |
| std::string client_hash; |
| std::string server_hash; |
| sdch_manager()->GenerateHash(dictionary_text, &client_hash, &server_hash); |
| - sdch_manager()->GetVcdiffDictionary(server_hash, target_url, &dictionary); |
| - EXPECT_TRUE(dictionary.get() == NULL); |
| + scoped_ptr<SdchManager::DictionarySet> dict_set( |
| + sdch_manager()->GetDictionarySetByHash(target_url, server_hash)); |
| + EXPECT_FALSE(dict_set.get()); |
| } |
| TEST_F(SdchManagerTest, FailToSetDomainMismatchDictionary) { |
| @@ -515,32 +512,31 @@ TEST_F(SdchManagerTest, CanUseMultipleManagers) { |
| // can't get them from the other. |
| EXPECT_TRUE(AddSdchDictionary(dictionary_text_1, |
| GURL("http://" + dictionary_domain_1))); |
| - scoped_refptr<SdchManager::Dictionary> dictionary; |
| - sdch_manager()->GetVcdiffDictionary( |
| - server_hash_1, |
| + scoped_ptr<SdchManager::DictionarySet> dict_set; |
| + |
| + dict_set = sdch_manager()->GetDictionarySetByHash( |
| GURL("http://" + dictionary_domain_1 + "/random_url"), |
| - &dictionary); |
| - EXPECT_TRUE(dictionary.get()); |
| + server_hash_1); |
| + EXPECT_TRUE(dict_set.get()); |
| + EXPECT_TRUE(dict_set->Dictionary(server_hash_1)); |
| second_manager.AddSdchDictionary( |
| dictionary_text_2, GURL("http://" + dictionary_domain_2)); |
| - second_manager.GetVcdiffDictionary( |
| - server_hash_2, |
| + dict_set = second_manager.GetDictionarySetByHash( |
| GURL("http://" + dictionary_domain_2 + "/random_url"), |
| - &dictionary); |
| - EXPECT_TRUE(dictionary.get()); |
| + server_hash_2); |
| + EXPECT_TRUE(dict_set.get()); |
| + EXPECT_TRUE(dict_set->Dictionary(server_hash_2)); |
| - sdch_manager()->GetVcdiffDictionary( |
| - server_hash_2, |
| + dict_set = sdch_manager()->GetDictionarySetByHash( |
| GURL("http://" + dictionary_domain_2 + "/random_url"), |
| - &dictionary); |
| - EXPECT_FALSE(dictionary.get()); |
| + server_hash_2); |
| + EXPECT_FALSE(dict_set.get()); |
| - second_manager.GetVcdiffDictionary( |
| - server_hash_1, |
| + dict_set = second_manager.GetDictionarySetByHash( |
| GURL("http://" + dictionary_domain_1 + "/random_url"), |
| - &dictionary); |
| - EXPECT_FALSE(dictionary.get()); |
| + server_hash_1); |
| + EXPECT_FALSE(dict_set.get()); |
| } |
| TEST_F(SdchManagerTest, HttpsCorrectlySupported) { |
| @@ -571,25 +567,24 @@ TEST_F(SdchManagerTest, ClearDictionaryData) { |
| EXPECT_TRUE(AddSdchDictionary(dictionary_text, |
| GURL("http://" + dictionary_domain))); |
| - scoped_refptr<SdchManager::Dictionary> dictionary; |
| - sdch_manager()->GetVcdiffDictionary( |
| - server_hash, |
| + |
| + scoped_ptr<SdchManager::DictionarySet> dict_set; |
| + |
| + dict_set = sdch_manager()->GetDictionarySetByHash( |
| GURL("http://" + dictionary_domain + "/random_url"), |
| - &dictionary); |
| - EXPECT_TRUE(dictionary.get()); |
| + server_hash); |
| + EXPECT_TRUE(dict_set.get()); |
| + EXPECT_TRUE(dict_set->Dictionary(server_hash)); |
| - sdch_manager()->BlacklistDomain(GURL(blacklist_url), |
| - SdchManager::MIN_PROBLEM_CODE); |
| + sdch_manager()->BlacklistDomain(GURL(blacklist_url), SdchManager::OK); |
| EXPECT_FALSE(sdch_manager()->IsInSupportedDomain(blacklist_url)); |
| sdch_manager()->ClearData(); |
| - dictionary = NULL; |
| - sdch_manager()->GetVcdiffDictionary( |
| - server_hash, |
| + dict_set = sdch_manager()->GetDictionarySetByHash( |
| GURL("http://" + dictionary_domain + "/random_url"), |
| - &dictionary); |
| - EXPECT_FALSE(dictionary.get()); |
| + server_hash); |
| + EXPECT_FALSE(dict_set.get()); |
| EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(blacklist_url)); |
| } |
| @@ -612,4 +607,23 @@ TEST_F(SdchManagerTest, GetDictionaryNotification) { |
| EXPECT_EQ(test_dictionary_gurl, observer.last_dictionary_url()); |
| } |
| +TEST_F(SdchManagerTest, ExpirationCheckedProperly) { |
| + // Create an SDCH dictionary with an expiration time in the past. |
| + std::string dictionary_domain("x.y.z.google.com"); |
| + std::string dictionary_text(base::StringPrintf( |
| + "Domain: %s\nMax-age: 0\n\n", dictionary_domain.c_str())); |
|
Ryan Sleevi
2014/11/14 03:21:25
why is a Max-age: 0 in the past?
Seems like it'd
Randy Smith (Not in Mondays)
2014/11/17 17:04:22
You and the Windows try bots are telling me the sa
|
| + dictionary_text.append( |
| + kTestVcdiffDictionary, sizeof(kTestVcdiffDictionary) - 1); |
| + std::string client_hash; |
| + std::string server_hash; |
| + SdchManager::GenerateHash(dictionary_text, &client_hash, &server_hash); |
| + GURL target_gurl("http://" + dictionary_domain); |
| + AddSdchDictionary(dictionary_text, target_gurl); |
| + |
| + // Make sure it's not visible for advertisement, but is visible |
| + // if looked up by hash. |
| + EXPECT_FALSE(sdch_manager()->GetDictionarySet(target_gurl)); |
| + EXPECT_TRUE(sdch_manager()->GetDictionarySetByHash(target_gurl, server_hash)); |
| +} |
| + |
| } // namespace net |