| 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" |
| 11 #include "net/base/net_log.h" |
| 11 #include "net/base/sdch_manager.h" | 12 #include "net/base/sdch_manager.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 14 |
| 14 namespace net { | 15 namespace net { |
| 15 | 16 |
| 16 //------------------------------------------------------------------------------ | 17 //------------------------------------------------------------------------------ |
| 17 // Workaround for http://crbug.com/418975; remove when fixed. | 18 // Workaround for http://crbug.com/418975; remove when fixed. |
| 18 #if !defined(OS_IOS) | 19 #if !defined(OS_IOS) |
| 19 | 20 |
| 20 //------------------------------------------------------------------------------ | 21 //------------------------------------------------------------------------------ |
| (...skipping 19 matching lines...) Expand all Loading... |
| 40 // Reset globals back to default state. | 41 // Reset globals back to default state. |
| 41 void TearDown() override { | 42 void TearDown() override { |
| 42 SdchManager::EnableSdchSupport(default_support_); | 43 SdchManager::EnableSdchSupport(default_support_); |
| 43 SdchManager::EnableSecureSchemeSupport(default_https_support_); | 44 SdchManager::EnableSecureSchemeSupport(default_https_support_); |
| 44 } | 45 } |
| 45 | 46 |
| 46 // Attempt to add a dictionary to the manager and probe for success or | 47 // Attempt to add a dictionary to the manager and probe for success or |
| 47 // failure. | 48 // failure. |
| 48 bool AddSdchDictionary(const std::string& dictionary_text, | 49 bool AddSdchDictionary(const std::string& dictionary_text, |
| 49 const GURL& gurl) { | 50 const GURL& gurl) { |
| 50 std::string list; | 51 return sdch_manager_->AddSdchDictionary(dictionary_text, gurl) == SDCH_OK; |
| 51 sdch_manager_->GetAvailDictionaryList(gurl, &list); | |
| 52 sdch_manager_->AddSdchDictionary(dictionary_text, gurl); | |
| 53 std::string list2; | |
| 54 sdch_manager_->GetAvailDictionaryList(gurl, &list2); | |
| 55 | |
| 56 // The list of hashes should change iff the addition succeeds. | |
| 57 return (list != list2); | |
| 58 } | 52 } |
| 59 | 53 |
| 60 private: | 54 private: |
| 61 scoped_ptr<SdchManager> sdch_manager_; | 55 scoped_ptr<SdchManager> sdch_manager_; |
| 62 bool default_support_; | 56 bool default_support_; |
| 63 bool default_https_support_; | 57 bool default_https_support_; |
| 64 }; | 58 }; |
| 65 | 59 |
| 66 static std::string NewSdchDictionary(const std::string& domain) { | 60 static std::string NewSdchDictionary(const std::string& domain) { |
| 67 std::string dictionary; | 61 std::string dictionary; |
| 68 if (!domain.empty()) { | 62 if (!domain.empty()) { |
| 69 dictionary.append("Domain: "); | 63 dictionary.append("Domain: "); |
| 70 dictionary.append(domain); | 64 dictionary.append(domain); |
| 71 dictionary.append("\n"); | 65 dictionary.append("\n"); |
| 72 } | 66 } |
| 73 dictionary.append("\n"); | 67 dictionary.append("\n"); |
| 74 dictionary.append(kTestVcdiffDictionary, sizeof(kTestVcdiffDictionary) - 1); | 68 dictionary.append(kTestVcdiffDictionary, sizeof(kTestVcdiffDictionary) - 1); |
| 75 return dictionary; | 69 return dictionary; |
| 76 } | 70 } |
| 77 | 71 |
| 78 TEST_F(SdchManagerTest, DomainSupported) { | 72 TEST_F(SdchManagerTest, DomainSupported) { |
| 79 GURL google_url("http://www.google.com"); | 73 GURL google_url("http://www.google.com"); |
| 80 | 74 |
| 81 SdchManager::EnableSdchSupport(false); | 75 SdchManager::EnableSdchSupport(false); |
| 82 EXPECT_FALSE(sdch_manager()->IsInSupportedDomain(google_url)); | 76 EXPECT_EQ(SDCH_DISABLED, sdch_manager()->IsInSupportedDomain(google_url)); |
| 83 SdchManager::EnableSdchSupport(true); | 77 SdchManager::EnableSdchSupport(true); |
| 84 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(google_url)); | 78 EXPECT_EQ(SDCH_OK, sdch_manager()->IsInSupportedDomain(google_url)); |
| 85 } | 79 } |
| 86 | 80 |
| 87 TEST_F(SdchManagerTest, DomainBlacklisting) { | 81 TEST_F(SdchManagerTest, DomainBlacklisting) { |
| 88 GURL test_url("http://www.test.com"); | 82 GURL test_url("http://www.test.com"); |
| 89 GURL google_url("http://www.google.com"); | 83 GURL google_url("http://www.google.com"); |
| 90 | 84 |
| 91 sdch_manager()->BlacklistDomain(test_url, SdchManager::MIN_PROBLEM_CODE); | 85 sdch_manager()->BlacklistDomain(test_url, SDCH_OK); |
| 92 EXPECT_FALSE(sdch_manager()->IsInSupportedDomain(test_url)); | 86 EXPECT_EQ(SDCH_DOMAIN_BLACKLIST_INCLUDES_TARGET, |
| 93 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(google_url)); | 87 sdch_manager()->IsInSupportedDomain(test_url)); |
| 88 EXPECT_EQ(SDCH_OK, sdch_manager()->IsInSupportedDomain(google_url)); |
| 94 | 89 |
| 95 sdch_manager()->BlacklistDomain(google_url, SdchManager::MIN_PROBLEM_CODE); | 90 sdch_manager()->BlacklistDomain(google_url, SDCH_OK); |
| 96 EXPECT_FALSE(sdch_manager()->IsInSupportedDomain(google_url)); | 91 EXPECT_EQ(SDCH_DOMAIN_BLACKLIST_INCLUDES_TARGET, |
| 92 sdch_manager()->IsInSupportedDomain(google_url)); |
| 97 } | 93 } |
| 98 | 94 |
| 99 TEST_F(SdchManagerTest, DomainBlacklistingCaseSensitivity) { | 95 TEST_F(SdchManagerTest, DomainBlacklistingCaseSensitivity) { |
| 100 GURL test_url("http://www.TesT.com"); | 96 GURL test_url("http://www.TesT.com"); |
| 101 GURL test2_url("http://www.tEst.com"); | 97 GURL test2_url("http://www.tEst.com"); |
| 102 | 98 |
| 103 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(test_url)); | 99 EXPECT_EQ(SDCH_OK, sdch_manager()->IsInSupportedDomain(test_url)); |
| 104 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(test2_url)); | 100 EXPECT_EQ(SDCH_OK, sdch_manager()->IsInSupportedDomain(test2_url)); |
| 105 sdch_manager()->BlacklistDomain(test_url, SdchManager::MIN_PROBLEM_CODE); | 101 sdch_manager()->BlacklistDomain(test_url, SDCH_OK); |
| 106 EXPECT_FALSE(sdch_manager()->IsInSupportedDomain(test2_url)); | 102 EXPECT_EQ(SDCH_DOMAIN_BLACKLIST_INCLUDES_TARGET, |
| 103 sdch_manager()->IsInSupportedDomain(test2_url)); |
| 107 } | 104 } |
| 108 | 105 |
| 109 TEST_F(SdchManagerTest, BlacklistingReset) { | 106 TEST_F(SdchManagerTest, BlacklistingReset) { |
| 110 GURL gurl("http://mytest.DoMain.com"); | 107 GURL gurl("http://mytest.DoMain.com"); |
| 111 std::string domain(gurl.host()); | 108 std::string domain(gurl.host()); |
| 112 | 109 |
| 113 sdch_manager()->ClearBlacklistings(); | 110 sdch_manager()->ClearBlacklistings(); |
| 114 EXPECT_EQ(sdch_manager()->BlackListDomainCount(domain), 0); | 111 EXPECT_EQ(sdch_manager()->BlackListDomainCount(domain), 0); |
| 115 EXPECT_EQ(sdch_manager()->BlacklistDomainExponential(domain), 0); | 112 EXPECT_EQ(sdch_manager()->BlacklistDomainExponential(domain), 0); |
| 116 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(gurl)); | 113 EXPECT_EQ(SDCH_OK, sdch_manager()->IsInSupportedDomain(gurl)); |
| 117 } | 114 } |
| 118 | 115 |
| 119 TEST_F(SdchManagerTest, BlacklistingSingleBlacklist) { | 116 TEST_F(SdchManagerTest, BlacklistingSingleBlacklist) { |
| 120 GURL gurl("http://mytest.DoMain.com"); | 117 GURL gurl("http://mytest.DoMain.com"); |
| 121 std::string domain(gurl.host()); | 118 std::string domain(gurl.host()); |
| 122 sdch_manager()->ClearBlacklistings(); | 119 sdch_manager()->ClearBlacklistings(); |
| 123 | 120 |
| 124 sdch_manager()->BlacklistDomain(gurl, SdchManager::MIN_PROBLEM_CODE); | 121 sdch_manager()->BlacklistDomain(gurl, SDCH_OK); |
| 125 EXPECT_EQ(sdch_manager()->BlackListDomainCount(domain), 1); | 122 EXPECT_EQ(sdch_manager()->BlackListDomainCount(domain), 1); |
| 126 EXPECT_EQ(sdch_manager()->BlacklistDomainExponential(domain), 1); | 123 EXPECT_EQ(sdch_manager()->BlacklistDomainExponential(domain), 1); |
| 127 | 124 |
| 128 // Check that any domain lookup reduces the blacklist counter. | 125 // Check that any domain lookup reduces the blacklist counter. |
| 129 EXPECT_FALSE(sdch_manager()->IsInSupportedDomain(gurl)); | 126 EXPECT_EQ(SDCH_DOMAIN_BLACKLIST_INCLUDES_TARGET, |
| 127 sdch_manager()->IsInSupportedDomain(gurl)); |
| 130 EXPECT_EQ(sdch_manager()->BlackListDomainCount(domain), 0); | 128 EXPECT_EQ(sdch_manager()->BlackListDomainCount(domain), 0); |
| 131 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(gurl)); | 129 EXPECT_EQ(SDCH_OK, sdch_manager()->IsInSupportedDomain(gurl)); |
| 132 } | 130 } |
| 133 | 131 |
| 134 TEST_F(SdchManagerTest, BlacklistingExponential) { | 132 TEST_F(SdchManagerTest, BlacklistingExponential) { |
| 135 GURL gurl("http://mytest.DoMain.com"); | 133 GURL gurl("http://mytest.DoMain.com"); |
| 136 std::string domain(gurl.host()); | 134 std::string domain(gurl.host()); |
| 137 sdch_manager()->ClearBlacklistings(); | 135 sdch_manager()->ClearBlacklistings(); |
| 138 | 136 |
| 139 int exponential = 1; | 137 int exponential = 1; |
| 140 for (int i = 1; i < 100; ++i) { | 138 for (int i = 1; i < 100; ++i) { |
| 141 sdch_manager()->BlacklistDomain(gurl, SdchManager::MIN_PROBLEM_CODE); | 139 sdch_manager()->BlacklistDomain(gurl, SDCH_OK); |
| 142 EXPECT_EQ(sdch_manager()->BlacklistDomainExponential(domain), exponential); | 140 EXPECT_EQ(sdch_manager()->BlacklistDomainExponential(domain), exponential); |
| 143 | 141 |
| 144 EXPECT_EQ(sdch_manager()->BlackListDomainCount(domain), exponential); | 142 EXPECT_EQ(sdch_manager()->BlackListDomainCount(domain), exponential); |
| 145 EXPECT_FALSE(sdch_manager()->IsInSupportedDomain(gurl)); | 143 EXPECT_EQ(SDCH_DOMAIN_BLACKLIST_INCLUDES_TARGET, |
| 144 sdch_manager()->IsInSupportedDomain(gurl)); |
| 146 EXPECT_EQ(sdch_manager()->BlackListDomainCount(domain), exponential - 1); | 145 EXPECT_EQ(sdch_manager()->BlackListDomainCount(domain), exponential - 1); |
| 147 | 146 |
| 148 // Simulate a large number of domain checks (which eventually remove the | 147 // Simulate a large number of domain checks (which eventually remove the |
| 149 // blacklisting). | 148 // blacklisting). |
| 150 sdch_manager()->ClearDomainBlacklisting(domain); | 149 sdch_manager()->ClearDomainBlacklisting(domain); |
| 151 EXPECT_EQ(sdch_manager()->BlackListDomainCount(domain), 0); | 150 EXPECT_EQ(sdch_manager()->BlackListDomainCount(domain), 0); |
| 152 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(gurl)); | 151 EXPECT_EQ(SDCH_OK, sdch_manager()->IsInSupportedDomain(gurl)); |
| 153 | 152 |
| 154 // Predict what exponential backoff will be. | 153 // Predict what exponential backoff will be. |
| 155 exponential = 1 + 2 * exponential; | 154 exponential = 1 + 2 * exponential; |
| 156 if (exponential < 0) | 155 if (exponential < 0) |
| 157 exponential = INT_MAX; // We don't wrap. | 156 exponential = INT_MAX; // We don't wrap. |
| 158 } | 157 } |
| 159 } | 158 } |
| 160 | 159 |
| 161 TEST_F(SdchManagerTest, CanSetExactMatchDictionary) { | 160 TEST_F(SdchManagerTest, CanSetExactMatchDictionary) { |
| 162 std::string dictionary_domain("x.y.z.google.com"); | 161 std::string dictionary_domain("x.y.z.google.com"); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 // HTTPS target URL should advertise dictionary if secure scheme support is | 212 // HTTPS target URL should advertise dictionary if secure scheme support is |
| 214 // enabled. | 213 // enabled. |
| 215 sdch_manager()->GetAvailDictionaryList(target_url, &dictionary_list); | 214 sdch_manager()->GetAvailDictionaryList(target_url, &dictionary_list); |
| 216 EXPECT_FALSE(dictionary_list.empty()); | 215 EXPECT_FALSE(dictionary_list.empty()); |
| 217 | 216 |
| 218 // Dictionary should be available. | 217 // Dictionary should be available. |
| 219 scoped_refptr<SdchManager::Dictionary> dictionary; | 218 scoped_refptr<SdchManager::Dictionary> dictionary; |
| 220 std::string client_hash; | 219 std::string client_hash; |
| 221 std::string server_hash; | 220 std::string server_hash; |
| 222 sdch_manager()->GenerateHash(dictionary_text, &client_hash, &server_hash); | 221 sdch_manager()->GenerateHash(dictionary_text, &client_hash, &server_hash); |
| 223 sdch_manager()->GetVcdiffDictionary(server_hash, target_url, &dictionary); | 222 EXPECT_EQ(SDCH_OK, |
| 223 sdch_manager()->GetVcdiffDictionary( |
| 224 server_hash, target_url, &dictionary)); |
| 224 EXPECT_TRUE(dictionary.get() != NULL); | 225 EXPECT_TRUE(dictionary.get() != NULL); |
| 225 } | 226 } |
| 226 | 227 |
| 227 TEST_F(SdchManagerTest, CanNotUseHTTPDictionaryOverHTTPS) { | 228 TEST_F(SdchManagerTest, CanNotUseHTTPDictionaryOverHTTPS) { |
| 228 std::string dictionary_domain("x.y.z.google.com"); | 229 std::string dictionary_domain("x.y.z.google.com"); |
| 229 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); | 230 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); |
| 230 | 231 |
| 231 EXPECT_TRUE(AddSdchDictionary(dictionary_text, | 232 EXPECT_TRUE(AddSdchDictionary(dictionary_text, |
| 232 GURL("http://" + dictionary_domain))); | 233 GURL("http://" + dictionary_domain))); |
| 233 | 234 |
| 234 GURL target_url("https://" + dictionary_domain + "/test"); | 235 GURL target_url("https://" + dictionary_domain + "/test"); |
| 235 std::string dictionary_list; | 236 std::string dictionary_list; |
| 236 // HTTPS target URL should not advertise dictionary acquired over HTTP even if | 237 // HTTPS target URL should not advertise dictionary acquired over HTTP even if |
| 237 // secure scheme support is enabled. | 238 // secure scheme support is enabled. |
| 238 SdchManager::EnableSecureSchemeSupport(true); | 239 SdchManager::EnableSecureSchemeSupport(true); |
| 239 sdch_manager()->GetAvailDictionaryList(target_url, &dictionary_list); | 240 sdch_manager()->GetAvailDictionaryList(target_url, &dictionary_list); |
| 240 EXPECT_TRUE(dictionary_list.empty()); | 241 EXPECT_TRUE(dictionary_list.empty()); |
| 241 | 242 |
| 242 scoped_refptr<SdchManager::Dictionary> dictionary; | 243 scoped_refptr<SdchManager::Dictionary> dictionary; |
| 243 std::string client_hash; | 244 std::string client_hash; |
| 244 std::string server_hash; | 245 std::string server_hash; |
| 245 sdch_manager()->GenerateHash(dictionary_text, &client_hash, &server_hash); | 246 sdch_manager()->GenerateHash(dictionary_text, &client_hash, &server_hash); |
| 246 sdch_manager()->GetVcdiffDictionary(server_hash, target_url, &dictionary); | 247 EXPECT_EQ(SDCH_DICTIONARY_FOUND_HAS_WRONG_SCHEME, |
| 248 sdch_manager()->GetVcdiffDictionary( |
| 249 server_hash, target_url, &dictionary)); |
| 247 EXPECT_TRUE(dictionary.get() == NULL); | 250 EXPECT_TRUE(dictionary.get() == NULL); |
| 248 } | 251 } |
| 249 | 252 |
| 250 TEST_F(SdchManagerTest, CanNotUseHTTPSDictionaryOverHTTP) { | 253 TEST_F(SdchManagerTest, CanNotUseHTTPSDictionaryOverHTTP) { |
| 251 std::string dictionary_domain("x.y.z.google.com"); | 254 std::string dictionary_domain("x.y.z.google.com"); |
| 252 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); | 255 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); |
| 253 | 256 |
| 254 SdchManager::EnableSecureSchemeSupport(true); | 257 SdchManager::EnableSecureSchemeSupport(true); |
| 255 EXPECT_TRUE(AddSdchDictionary(dictionary_text, | 258 EXPECT_TRUE(AddSdchDictionary(dictionary_text, |
| 256 GURL("https://" + dictionary_domain))); | 259 GURL("https://" + dictionary_domain))); |
| 257 | 260 |
| 258 GURL target_url("http://" + dictionary_domain + "/test"); | 261 GURL target_url("http://" + dictionary_domain + "/test"); |
| 259 std::string dictionary_list; | 262 std::string dictionary_list; |
| 260 // HTTP target URL should not advertise dictionary acquired over HTTPS even if | 263 // HTTP target URL should not advertise dictionary acquired over HTTPS even if |
| 261 // secure scheme support is enabled. | 264 // secure scheme support is enabled. |
| 262 sdch_manager()->GetAvailDictionaryList(target_url, &dictionary_list); | 265 sdch_manager()->GetAvailDictionaryList(target_url, &dictionary_list); |
| 263 EXPECT_TRUE(dictionary_list.empty()); | 266 EXPECT_TRUE(dictionary_list.empty()); |
| 264 | 267 |
| 265 scoped_refptr<SdchManager::Dictionary> dictionary; | 268 scoped_refptr<SdchManager::Dictionary> dictionary; |
| 266 std::string client_hash; | 269 std::string client_hash; |
| 267 std::string server_hash; | 270 std::string server_hash; |
| 268 sdch_manager()->GenerateHash(dictionary_text, &client_hash, &server_hash); | 271 sdch_manager()->GenerateHash(dictionary_text, &client_hash, &server_hash); |
| 269 sdch_manager()->GetVcdiffDictionary(server_hash, target_url, &dictionary); | 272 EXPECT_EQ(SDCH_DICTIONARY_FOUND_HAS_WRONG_SCHEME, |
| 273 sdch_manager()->GetVcdiffDictionary( |
| 274 server_hash, target_url, &dictionary)); |
| 270 EXPECT_TRUE(dictionary.get() == NULL); | 275 EXPECT_TRUE(dictionary.get() == NULL); |
| 271 } | 276 } |
| 272 | 277 |
| 273 TEST_F(SdchManagerTest, FailToSetDomainMismatchDictionary) { | 278 TEST_F(SdchManagerTest, FailToSetDomainMismatchDictionary) { |
| 274 std::string dictionary_domain("x.y.z.google.com"); | 279 std::string dictionary_domain("x.y.z.google.com"); |
| 275 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); | 280 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); |
| 276 | 281 |
| 277 // Fail the "domain match" requirement. | 282 // Fail the "domain match" requirement. |
| 278 EXPECT_FALSE(AddSdchDictionary(dictionary_text, | 283 EXPECT_FALSE(AddSdchDictionary(dictionary_text, |
| 279 GURL("http://y.z.google.com"))); | 284 GURL("http://y.z.google.com"))); |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 483 std::string server_hash_2; | 488 std::string server_hash_2; |
| 484 | 489 |
| 485 SdchManager::GenerateHash(dictionary_text_1, &tmp_hash, &server_hash_1); | 490 SdchManager::GenerateHash(dictionary_text_1, &tmp_hash, &server_hash_1); |
| 486 SdchManager::GenerateHash(dictionary_text_2, &tmp_hash, &server_hash_2); | 491 SdchManager::GenerateHash(dictionary_text_2, &tmp_hash, &server_hash_2); |
| 487 | 492 |
| 488 // Confirm that if you add directories to one manager, you | 493 // Confirm that if you add directories to one manager, you |
| 489 // can't get them from the other. | 494 // can't get them from the other. |
| 490 EXPECT_TRUE(AddSdchDictionary(dictionary_text_1, | 495 EXPECT_TRUE(AddSdchDictionary(dictionary_text_1, |
| 491 GURL("http://" + dictionary_domain_1))); | 496 GURL("http://" + dictionary_domain_1))); |
| 492 scoped_refptr<SdchManager::Dictionary> dictionary; | 497 scoped_refptr<SdchManager::Dictionary> dictionary; |
| 493 sdch_manager()->GetVcdiffDictionary( | 498 EXPECT_EQ(SDCH_OK, |
| 494 server_hash_1, | 499 sdch_manager()->GetVcdiffDictionary( |
| 495 GURL("http://" + dictionary_domain_1 + "/random_url"), | 500 server_hash_1, |
| 496 &dictionary); | 501 GURL("http://" + dictionary_domain_1 + "/random_url"), |
| 502 &dictionary)); |
| 497 EXPECT_TRUE(dictionary.get()); | 503 EXPECT_TRUE(dictionary.get()); |
| 498 | 504 |
| 499 second_manager.AddSdchDictionary( | 505 second_manager.AddSdchDictionary( |
| 500 dictionary_text_2, GURL("http://" + dictionary_domain_2)); | 506 dictionary_text_2, GURL("http://" + dictionary_domain_2)); |
| 501 second_manager.GetVcdiffDictionary( | 507 second_manager.GetVcdiffDictionary( |
| 502 server_hash_2, | 508 server_hash_2, |
| 503 GURL("http://" + dictionary_domain_2 + "/random_url"), | 509 GURL("http://" + dictionary_domain_2 + "/random_url"), |
| 504 &dictionary); | 510 &dictionary); |
| 505 EXPECT_TRUE(dictionary.get()); | 511 EXPECT_TRUE(dictionary.get()); |
| 506 | 512 |
| 507 sdch_manager()->GetVcdiffDictionary( | 513 EXPECT_EQ(SDCH_DICTIONARY_HASH_NOT_FOUND, |
| 508 server_hash_2, | 514 sdch_manager()->GetVcdiffDictionary( |
| 509 GURL("http://" + dictionary_domain_2 + "/random_url"), | 515 server_hash_2, |
| 510 &dictionary); | 516 GURL("http://" + dictionary_domain_2 + "/random_url"), |
| 517 &dictionary)); |
| 511 EXPECT_FALSE(dictionary.get()); | 518 EXPECT_FALSE(dictionary.get()); |
| 512 | 519 |
| 513 second_manager.GetVcdiffDictionary( | 520 EXPECT_EQ(SDCH_DICTIONARY_HASH_NOT_FOUND, |
| 514 server_hash_1, | 521 second_manager.GetVcdiffDictionary( |
| 515 GURL("http://" + dictionary_domain_1 + "/random_url"), | 522 server_hash_1, |
| 516 &dictionary); | 523 GURL("http://" + dictionary_domain_1 + "/random_url"), |
| 524 &dictionary)); |
| 517 EXPECT_FALSE(dictionary.get()); | 525 EXPECT_FALSE(dictionary.get()); |
| 518 } | 526 } |
| 519 | 527 |
| 520 TEST_F(SdchManagerTest, HttpsCorrectlySupported) { | 528 TEST_F(SdchManagerTest, HttpsCorrectlySupported) { |
| 521 GURL url("http://www.google.com"); | 529 GURL url("http://www.google.com"); |
| 522 GURL secure_url("https://www.google.com"); | 530 GURL secure_url("https://www.google.com"); |
| 523 | 531 |
| 524 #if !defined(OS_IOS) | 532 #if !defined(OS_IOS) |
| 525 // Workaround for http://crbug.com/418975; remove when fixed. | 533 // Workaround for http://crbug.com/418975; remove when fixed. |
| 526 bool expect_https_support = true; | 534 bool expect_https_support = true; |
| 527 #else | 535 #else |
| 528 bool expect_https_support = false; | 536 bool expect_https_support = false; |
| 529 #endif | 537 #endif |
| 530 | 538 |
| 531 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(url)); | 539 SdchProblemCode expected_code = |
| 532 EXPECT_EQ(expect_https_support, | 540 expect_https_support ? SDCH_OK : SDCH_SECURE_SCHEME_NOT_SUPPORTED; |
| 533 sdch_manager()->IsInSupportedDomain(secure_url)); | 541 |
| 542 EXPECT_EQ(SDCH_OK, sdch_manager()->IsInSupportedDomain(url)); |
| 543 EXPECT_EQ(expected_code, sdch_manager()->IsInSupportedDomain(secure_url)); |
| 534 | 544 |
| 535 SdchManager::EnableSecureSchemeSupport(!expect_https_support); | 545 SdchManager::EnableSecureSchemeSupport(!expect_https_support); |
| 536 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(url)); | 546 EXPECT_EQ(SDCH_OK, sdch_manager()->IsInSupportedDomain(url)); |
| 537 EXPECT_NE(expect_https_support, | 547 EXPECT_NE(expected_code, sdch_manager()->IsInSupportedDomain(secure_url)); |
| 538 sdch_manager()->IsInSupportedDomain(secure_url)); | |
| 539 } | 548 } |
| 540 | 549 |
| 541 TEST_F(SdchManagerTest, ClearDictionaryData) { | 550 TEST_F(SdchManagerTest, ClearDictionaryData) { |
| 542 std::string dictionary_domain("x.y.z.google.com"); | 551 std::string dictionary_domain("x.y.z.google.com"); |
| 543 GURL blacklist_url("http://bad.chromium.org"); | 552 GURL blacklist_url("http://bad.chromium.org"); |
| 544 | 553 |
| 545 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); | 554 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); |
| 546 std::string tmp_hash; | 555 std::string tmp_hash; |
| 547 std::string server_hash; | 556 std::string server_hash; |
| 548 | 557 |
| 549 SdchManager::GenerateHash(dictionary_text, &tmp_hash, &server_hash); | 558 SdchManager::GenerateHash(dictionary_text, &tmp_hash, &server_hash); |
| 550 | 559 |
| 551 EXPECT_TRUE(AddSdchDictionary(dictionary_text, | 560 EXPECT_TRUE(AddSdchDictionary(dictionary_text, |
| 552 GURL("http://" + dictionary_domain))); | 561 GURL("http://" + dictionary_domain))); |
| 553 scoped_refptr<SdchManager::Dictionary> dictionary; | 562 scoped_refptr<SdchManager::Dictionary> dictionary; |
| 554 sdch_manager()->GetVcdiffDictionary( | 563 EXPECT_EQ(SDCH_OK, |
| 555 server_hash, | 564 sdch_manager()->GetVcdiffDictionary( |
| 556 GURL("http://" + dictionary_domain + "/random_url"), | 565 server_hash, |
| 557 &dictionary); | 566 GURL("http://" + dictionary_domain + "/random_url"), |
| 567 &dictionary)); |
| 558 EXPECT_TRUE(dictionary.get()); | 568 EXPECT_TRUE(dictionary.get()); |
| 559 | 569 |
| 560 sdch_manager()->BlacklistDomain(GURL(blacklist_url), | 570 sdch_manager()->BlacklistDomain(GURL(blacklist_url), SDCH_OK); |
| 561 SdchManager::MIN_PROBLEM_CODE); | 571 EXPECT_EQ(SDCH_DOMAIN_BLACKLIST_INCLUDES_TARGET, |
| 562 EXPECT_FALSE(sdch_manager()->IsInSupportedDomain(blacklist_url)); | 572 sdch_manager()->IsInSupportedDomain(blacklist_url)); |
| 563 | 573 |
| 564 sdch_manager()->ClearData(); | 574 sdch_manager()->ClearData(); |
| 565 | 575 |
| 566 dictionary = NULL; | 576 dictionary = NULL; |
| 567 sdch_manager()->GetVcdiffDictionary( | 577 EXPECT_EQ(SDCH_DICTIONARY_HASH_NOT_FOUND, |
| 568 server_hash, | 578 sdch_manager()->GetVcdiffDictionary( |
| 569 GURL("http://" + dictionary_domain + "/random_url"), | 579 server_hash, |
| 570 &dictionary); | 580 GURL("http://" + dictionary_domain + "/random_url"), |
| 581 &dictionary)); |
| 571 EXPECT_FALSE(dictionary.get()); | 582 EXPECT_FALSE(dictionary.get()); |
| 572 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(blacklist_url)); | 583 EXPECT_EQ(SDCH_OK, sdch_manager()->IsInSupportedDomain(blacklist_url)); |
| 573 } | 584 } |
| 574 | 585 |
| 575 #else | 586 #else |
| 576 | 587 |
| 577 TEST(SdchManagerTest, SdchOffByDefault) { | 588 TEST(SdchManagerTest, SdchOffByDefault) { |
| 578 GURL google_url("http://www.google.com"); | 589 GURL google_url("http://www.google.com"); |
| 579 SdchManager* sdch_manager(new SdchManager); | 590 SdchManager* sdch_manager(new SdchManager); |
| 580 | 591 |
| 581 EXPECT_FALSE(sdch_manager->IsInSupportedDomain(google_url)); | 592 EXPECT_FALSE(sdch_manager->IsInSupportedDomain(google_url)); |
| 582 SdchManager::EnableSdchSupport(true); | 593 SdchManager::EnableSdchSupport(true); |
| 583 EXPECT_TRUE(sdch_manager->IsInSupportedDomain(google_url)); | 594 EXPECT_TRUE(sdch_manager->IsInSupportedDomain(google_url)); |
| 584 } | 595 } |
| 585 | 596 |
| 586 #endif // !defined(OS_IOS) | 597 #endif // !defined(OS_IOS) |
| 587 | 598 |
| 588 } // namespace net | 599 } // namespace net |
| OLD | NEW |