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