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 // Provide sample data and compression results with a sample VCDIFF dictionary. | 18 // Provide sample data and compression results with a sample VCDIFF dictionary. |
18 // Note an SDCH dictionary has extra meta-data before the VCDIFF dictionary. | 19 // Note an SDCH dictionary has extra meta-data before the VCDIFF dictionary. |
19 static const char kTestVcdiffDictionary[] = "DictionaryFor" | 20 static const char kTestVcdiffDictionary[] = "DictionaryFor" |
20 "SdchCompression1SdchCompression2SdchCompression3SdchCompression\n"; | 21 "SdchCompression1SdchCompression2SdchCompression3SdchCompression\n"; |
(...skipping 13 matching lines...) Expand all Loading... |
34 SdchManager::EnableSdchSupport(true); | 35 SdchManager::EnableSdchSupport(true); |
35 SdchManager::EnableSecureSchemeSupport(false); | 36 SdchManager::EnableSecureSchemeSupport(false); |
36 } | 37 } |
37 | 38 |
38 // Attempt to add a dictionary to the manager and probe for success or | 39 // Attempt to add a dictionary to the manager and probe for success or |
39 // failure. | 40 // failure. |
40 bool AddSdchDictionary(const std::string& dictionary_text, | 41 bool AddSdchDictionary(const std::string& dictionary_text, |
41 const GURL& gurl) { | 42 const GURL& gurl) { |
42 std::string list; | 43 std::string list; |
43 sdch_manager_->GetAvailDictionaryList(gurl, &list); | 44 sdch_manager_->GetAvailDictionaryList(gurl, &list); |
44 sdch_manager_->AddSdchDictionary(dictionary_text, gurl); | 45 sdch_manager_->AddSdchDictionary(dictionary_text, gurl, BoundNetLog()); |
45 std::string list2; | 46 std::string list2; |
46 sdch_manager_->GetAvailDictionaryList(gurl, &list2); | 47 sdch_manager_->GetAvailDictionaryList(gurl, &list2); |
47 | 48 |
48 // The list of hashes should change iff the addition succeeds. | 49 // The list of hashes should change iff the addition succeeds. |
49 return (list != list2); | 50 return (list != list2); |
50 } | 51 } |
51 | 52 |
52 private: | 53 private: |
53 scoped_ptr<SdchManager> sdch_manager_; | 54 scoped_ptr<SdchManager> sdch_manager_; |
54 }; | 55 }; |
55 | 56 |
56 //------------------------------------------------------------------------------ | 57 //------------------------------------------------------------------------------ |
57 static std::string NewSdchDictionary(const std::string& domain) { | 58 static std::string NewSdchDictionary(const std::string& domain) { |
58 std::string dictionary; | 59 std::string dictionary; |
59 if (!domain.empty()) { | 60 if (!domain.empty()) { |
60 dictionary.append("Domain: "); | 61 dictionary.append("Domain: "); |
61 dictionary.append(domain); | 62 dictionary.append(domain); |
62 dictionary.append("\n"); | 63 dictionary.append("\n"); |
63 } | 64 } |
64 dictionary.append("\n"); | 65 dictionary.append("\n"); |
65 dictionary.append(kTestVcdiffDictionary, sizeof(kTestVcdiffDictionary) - 1); | 66 dictionary.append(kTestVcdiffDictionary, sizeof(kTestVcdiffDictionary) - 1); |
66 return dictionary; | 67 return dictionary; |
67 } | 68 } |
68 | 69 |
69 TEST_F(SdchManagerTest, DomainSupported) { | 70 TEST_F(SdchManagerTest, DomainSupported) { |
70 GURL google_url("http://www.google.com"); | 71 GURL google_url("http://www.google.com"); |
71 | 72 |
72 SdchManager::EnableSdchSupport(false); | 73 SdchManager::EnableSdchSupport(false); |
73 EXPECT_FALSE(sdch_manager()->IsInSupportedDomain(google_url)); | 74 EXPECT_EQ(SdchManager::SDCH_DISABLED, |
| 75 sdch_manager()->IsInSupportedDomain(google_url)); |
74 SdchManager::EnableSdchSupport(true); | 76 SdchManager::EnableSdchSupport(true); |
75 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(google_url)); | 77 EXPECT_EQ(SdchManager::PROBLEM_CODE_OK, |
| 78 sdch_manager()->IsInSupportedDomain(google_url)); |
76 } | 79 } |
77 | 80 |
78 TEST_F(SdchManagerTest, DomainBlacklisting) { | 81 TEST_F(SdchManagerTest, DomainBlacklisting) { |
79 GURL test_url("http://www.test.com"); | 82 GURL test_url("http://www.test.com"); |
80 GURL google_url("http://www.google.com"); | 83 GURL google_url("http://www.google.com"); |
81 | 84 |
82 sdch_manager()->BlacklistDomain(test_url, SdchManager::MIN_PROBLEM_CODE); | 85 sdch_manager()->BlacklistDomain(test_url, SdchManager::PROBLEM_CODE_OK); |
83 EXPECT_FALSE(sdch_manager()->IsInSupportedDomain(test_url)); | 86 EXPECT_EQ(SdchManager::DOMAIN_BLACKLIST_INCLUDES_TARGET, |
84 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(google_url)); | 87 sdch_manager()->IsInSupportedDomain(test_url)); |
| 88 EXPECT_EQ(SdchManager::PROBLEM_CODE_OK, |
| 89 sdch_manager()->IsInSupportedDomain(google_url)); |
85 | 90 |
86 sdch_manager()->BlacklistDomain(google_url, SdchManager::MIN_PROBLEM_CODE); | 91 sdch_manager()->BlacklistDomain(google_url, SdchManager::PROBLEM_CODE_OK); |
87 EXPECT_FALSE(sdch_manager()->IsInSupportedDomain(google_url)); | 92 EXPECT_EQ(SdchManager::DOMAIN_BLACKLIST_INCLUDES_TARGET, |
| 93 sdch_manager()->IsInSupportedDomain(google_url)); |
88 } | 94 } |
89 | 95 |
90 TEST_F(SdchManagerTest, DomainBlacklistingCaseSensitivity) { | 96 TEST_F(SdchManagerTest, DomainBlacklistingCaseSensitivity) { |
91 GURL test_url("http://www.TesT.com"); | 97 GURL test_url("http://www.TesT.com"); |
92 GURL test2_url("http://www.tEst.com"); | 98 GURL test2_url("http://www.tEst.com"); |
93 | 99 |
94 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(test_url)); | 100 EXPECT_EQ(SdchManager::PROBLEM_CODE_OK, |
95 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(test2_url)); | 101 sdch_manager()->IsInSupportedDomain(test_url)); |
96 sdch_manager()->BlacklistDomain(test_url, SdchManager::MIN_PROBLEM_CODE); | 102 EXPECT_EQ(SdchManager::PROBLEM_CODE_OK, |
97 EXPECT_FALSE(sdch_manager()->IsInSupportedDomain(test2_url)); | 103 sdch_manager()->IsInSupportedDomain(test2_url)); |
| 104 sdch_manager()->BlacklistDomain(test_url, SdchManager::PROBLEM_CODE_OK); |
| 105 EXPECT_EQ(SdchManager::DOMAIN_BLACKLIST_INCLUDES_TARGET, |
| 106 sdch_manager()->IsInSupportedDomain(test2_url)); |
98 } | 107 } |
99 | 108 |
100 TEST_F(SdchManagerTest, BlacklistingReset) { | 109 TEST_F(SdchManagerTest, BlacklistingReset) { |
101 GURL gurl("http://mytest.DoMain.com"); | 110 GURL gurl("http://mytest.DoMain.com"); |
102 std::string domain(gurl.host()); | 111 std::string domain(gurl.host()); |
103 | 112 |
104 sdch_manager()->ClearBlacklistings(); | 113 sdch_manager()->ClearBlacklistings(); |
105 EXPECT_EQ(sdch_manager()->BlackListDomainCount(domain), 0); | 114 EXPECT_EQ(sdch_manager()->BlackListDomainCount(domain), 0); |
106 EXPECT_EQ(sdch_manager()->BlacklistDomainExponential(domain), 0); | 115 EXPECT_EQ(sdch_manager()->BlacklistDomainExponential(domain), 0); |
107 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(gurl)); | 116 EXPECT_EQ(SdchManager::PROBLEM_CODE_OK, |
| 117 sdch_manager()->IsInSupportedDomain(gurl)); |
108 } | 118 } |
109 | 119 |
110 TEST_F(SdchManagerTest, BlacklistingSingleBlacklist) { | 120 TEST_F(SdchManagerTest, BlacklistingSingleBlacklist) { |
111 GURL gurl("http://mytest.DoMain.com"); | 121 GURL gurl("http://mytest.DoMain.com"); |
112 std::string domain(gurl.host()); | 122 std::string domain(gurl.host()); |
113 sdch_manager()->ClearBlacklistings(); | 123 sdch_manager()->ClearBlacklistings(); |
114 | 124 |
115 sdch_manager()->BlacklistDomain(gurl, SdchManager::MIN_PROBLEM_CODE); | 125 sdch_manager()->BlacklistDomain(gurl, SdchManager::PROBLEM_CODE_OK); |
116 EXPECT_EQ(sdch_manager()->BlackListDomainCount(domain), 1); | 126 EXPECT_EQ(sdch_manager()->BlackListDomainCount(domain), 1); |
117 EXPECT_EQ(sdch_manager()->BlacklistDomainExponential(domain), 1); | 127 EXPECT_EQ(sdch_manager()->BlacklistDomainExponential(domain), 1); |
118 | 128 |
119 // Check that any domain lookup reduces the blacklist counter. | 129 // Check that any domain lookup reduces the blacklist counter. |
120 EXPECT_FALSE(sdch_manager()->IsInSupportedDomain(gurl)); | 130 EXPECT_EQ(SdchManager::DOMAIN_BLACKLIST_INCLUDES_TARGET, |
| 131 sdch_manager()->IsInSupportedDomain(gurl)); |
121 EXPECT_EQ(sdch_manager()->BlackListDomainCount(domain), 0); | 132 EXPECT_EQ(sdch_manager()->BlackListDomainCount(domain), 0); |
122 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(gurl)); | 133 EXPECT_EQ(SdchManager::PROBLEM_CODE_OK, |
| 134 sdch_manager()->IsInSupportedDomain(gurl)); |
123 } | 135 } |
124 | 136 |
125 TEST_F(SdchManagerTest, BlacklistingExponential) { | 137 TEST_F(SdchManagerTest, BlacklistingExponential) { |
126 GURL gurl("http://mytest.DoMain.com"); | 138 GURL gurl("http://mytest.DoMain.com"); |
127 std::string domain(gurl.host()); | 139 std::string domain(gurl.host()); |
128 sdch_manager()->ClearBlacklistings(); | 140 sdch_manager()->ClearBlacklistings(); |
129 | 141 |
130 int exponential = 1; | 142 int exponential = 1; |
131 for (int i = 1; i < 100; ++i) { | 143 for (int i = 1; i < 100; ++i) { |
132 sdch_manager()->BlacklistDomain(gurl, SdchManager::MIN_PROBLEM_CODE); | 144 sdch_manager()->BlacklistDomain(gurl, SdchManager::PROBLEM_CODE_OK); |
133 EXPECT_EQ(sdch_manager()->BlacklistDomainExponential(domain), exponential); | 145 EXPECT_EQ(sdch_manager()->BlacklistDomainExponential(domain), exponential); |
134 | 146 |
135 EXPECT_EQ(sdch_manager()->BlackListDomainCount(domain), exponential); | 147 EXPECT_EQ(sdch_manager()->BlackListDomainCount(domain), exponential); |
136 EXPECT_FALSE(sdch_manager()->IsInSupportedDomain(gurl)); | 148 EXPECT_EQ(SdchManager::DOMAIN_BLACKLIST_INCLUDES_TARGET, |
| 149 sdch_manager()->IsInSupportedDomain(gurl)); |
137 EXPECT_EQ(sdch_manager()->BlackListDomainCount(domain), exponential - 1); | 150 EXPECT_EQ(sdch_manager()->BlackListDomainCount(domain), exponential - 1); |
138 | 151 |
139 // Simulate a large number of domain checks (which eventually remove the | 152 // Simulate a large number of domain checks (which eventually remove the |
140 // blacklisting). | 153 // blacklisting). |
141 sdch_manager()->ClearDomainBlacklisting(domain); | 154 sdch_manager()->ClearDomainBlacklisting(domain); |
142 EXPECT_EQ(sdch_manager()->BlackListDomainCount(domain), 0); | 155 EXPECT_EQ(sdch_manager()->BlackListDomainCount(domain), 0); |
143 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(gurl)); | 156 EXPECT_EQ(SdchManager::PROBLEM_CODE_OK, |
| 157 sdch_manager()->IsInSupportedDomain(gurl)); |
144 | 158 |
145 // Predict what exponential backoff will be. | 159 // Predict what exponential backoff will be. |
146 exponential = 1 + 2 * exponential; | 160 exponential = 1 + 2 * exponential; |
147 if (exponential < 0) | 161 if (exponential < 0) |
148 exponential = INT_MAX; // We don't wrap. | 162 exponential = INT_MAX; // We don't wrap. |
149 } | 163 } |
150 } | 164 } |
151 | 165 |
152 TEST_F(SdchManagerTest, CanSetExactMatchDictionary) { | 166 TEST_F(SdchManagerTest, CanSetExactMatchDictionary) { |
153 std::string dictionary_domain("x.y.z.google.com"); | 167 std::string dictionary_domain("x.y.z.google.com"); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 // HTTPS target URL should advertise dictionary if secure scheme support is | 217 // HTTPS target URL should advertise dictionary if secure scheme support is |
204 // enabled. | 218 // enabled. |
205 sdch_manager()->GetAvailDictionaryList(target_url, &dictionary_list); | 219 sdch_manager()->GetAvailDictionaryList(target_url, &dictionary_list); |
206 EXPECT_FALSE(dictionary_list.empty()); | 220 EXPECT_FALSE(dictionary_list.empty()); |
207 | 221 |
208 // Dictionary should be available. | 222 // Dictionary should be available. |
209 scoped_refptr<SdchManager::Dictionary> dictionary; | 223 scoped_refptr<SdchManager::Dictionary> dictionary; |
210 std::string client_hash; | 224 std::string client_hash; |
211 std::string server_hash; | 225 std::string server_hash; |
212 sdch_manager()->GenerateHash(dictionary_text, &client_hash, &server_hash); | 226 sdch_manager()->GenerateHash(dictionary_text, &client_hash, &server_hash); |
213 sdch_manager()->GetVcdiffDictionary(server_hash, target_url, &dictionary); | 227 EXPECT_EQ(SdchManager::PROBLEM_CODE_OK, |
| 228 sdch_manager()->GetVcdiffDictionary( |
| 229 server_hash, target_url, &dictionary)); |
214 EXPECT_TRUE(dictionary.get() != NULL); | 230 EXPECT_TRUE(dictionary.get() != NULL); |
215 } | 231 } |
216 | 232 |
217 TEST_F(SdchManagerTest, CanNotUseHTTPDictionaryOverHTTPS) { | 233 TEST_F(SdchManagerTest, CanNotUseHTTPDictionaryOverHTTPS) { |
218 std::string dictionary_domain("x.y.z.google.com"); | 234 std::string dictionary_domain("x.y.z.google.com"); |
219 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); | 235 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); |
220 | 236 |
221 EXPECT_TRUE(AddSdchDictionary(dictionary_text, | 237 EXPECT_TRUE(AddSdchDictionary(dictionary_text, |
222 GURL("http://" + dictionary_domain))); | 238 GURL("http://" + dictionary_domain))); |
223 | 239 |
224 GURL target_url("https://" + dictionary_domain + "/test"); | 240 GURL target_url("https://" + dictionary_domain + "/test"); |
225 std::string dictionary_list; | 241 std::string dictionary_list; |
226 // HTTPS target URL should not advertise dictionary acquired over HTTP even if | 242 // HTTPS target URL should not advertise dictionary acquired over HTTP even if |
227 // secure scheme support is enabled. | 243 // secure scheme support is enabled. |
228 SdchManager::EnableSecureSchemeSupport(true); | 244 SdchManager::EnableSecureSchemeSupport(true); |
229 sdch_manager()->GetAvailDictionaryList(target_url, &dictionary_list); | 245 sdch_manager()->GetAvailDictionaryList(target_url, &dictionary_list); |
230 EXPECT_TRUE(dictionary_list.empty()); | 246 EXPECT_TRUE(dictionary_list.empty()); |
231 | 247 |
232 scoped_refptr<SdchManager::Dictionary> dictionary; | 248 scoped_refptr<SdchManager::Dictionary> dictionary; |
233 std::string client_hash; | 249 std::string client_hash; |
234 std::string server_hash; | 250 std::string server_hash; |
235 sdch_manager()->GenerateHash(dictionary_text, &client_hash, &server_hash); | 251 sdch_manager()->GenerateHash(dictionary_text, &client_hash, &server_hash); |
236 sdch_manager()->GetVcdiffDictionary(server_hash, target_url, &dictionary); | 252 EXPECT_EQ(SdchManager::DICTIONARY_FOUND_HAS_WRONG_SCHEME, |
| 253 sdch_manager()->GetVcdiffDictionary( |
| 254 server_hash, target_url, &dictionary)); |
237 EXPECT_TRUE(dictionary.get() == NULL); | 255 EXPECT_TRUE(dictionary.get() == NULL); |
238 } | 256 } |
239 | 257 |
240 TEST_F(SdchManagerTest, CanNotUseHTTPSDictionaryOverHTTP) { | 258 TEST_F(SdchManagerTest, CanNotUseHTTPSDictionaryOverHTTP) { |
241 std::string dictionary_domain("x.y.z.google.com"); | 259 std::string dictionary_domain("x.y.z.google.com"); |
242 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); | 260 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); |
243 | 261 |
244 SdchManager::EnableSecureSchemeSupport(true); | 262 SdchManager::EnableSecureSchemeSupport(true); |
245 EXPECT_TRUE(AddSdchDictionary(dictionary_text, | 263 EXPECT_TRUE(AddSdchDictionary(dictionary_text, |
246 GURL("https://" + dictionary_domain))); | 264 GURL("https://" + dictionary_domain))); |
247 | 265 |
248 GURL target_url("http://" + dictionary_domain + "/test"); | 266 GURL target_url("http://" + dictionary_domain + "/test"); |
249 std::string dictionary_list; | 267 std::string dictionary_list; |
250 // HTTP target URL should not advertise dictionary acquired over HTTPS even if | 268 // HTTP target URL should not advertise dictionary acquired over HTTPS even if |
251 // secure scheme support is enabled. | 269 // secure scheme support is enabled. |
252 sdch_manager()->GetAvailDictionaryList(target_url, &dictionary_list); | 270 sdch_manager()->GetAvailDictionaryList(target_url, &dictionary_list); |
253 EXPECT_TRUE(dictionary_list.empty()); | 271 EXPECT_TRUE(dictionary_list.empty()); |
254 | 272 |
255 scoped_refptr<SdchManager::Dictionary> dictionary; | 273 scoped_refptr<SdchManager::Dictionary> dictionary; |
256 std::string client_hash; | 274 std::string client_hash; |
257 std::string server_hash; | 275 std::string server_hash; |
258 sdch_manager()->GenerateHash(dictionary_text, &client_hash, &server_hash); | 276 sdch_manager()->GenerateHash(dictionary_text, &client_hash, &server_hash); |
259 sdch_manager()->GetVcdiffDictionary(server_hash, target_url, &dictionary); | 277 EXPECT_EQ(SdchManager::DICTIONARY_FOUND_HAS_WRONG_SCHEME, |
| 278 sdch_manager()->GetVcdiffDictionary( |
| 279 server_hash, target_url, &dictionary)); |
260 EXPECT_TRUE(dictionary.get() == NULL); | 280 EXPECT_TRUE(dictionary.get() == NULL); |
261 } | 281 } |
262 | 282 |
263 TEST_F(SdchManagerTest, FailToSetDomainMismatchDictionary) { | 283 TEST_F(SdchManagerTest, FailToSetDomainMismatchDictionary) { |
264 std::string dictionary_domain("x.y.z.google.com"); | 284 std::string dictionary_domain("x.y.z.google.com"); |
265 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); | 285 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); |
266 | 286 |
267 // Fail the "domain match" requirement. | 287 // Fail the "domain match" requirement. |
268 EXPECT_FALSE(AddSdchDictionary(dictionary_text, | 288 EXPECT_FALSE(AddSdchDictionary(dictionary_text, |
269 GURL("http://y.z.google.com"))); | 289 GURL("http://y.z.google.com"))); |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 std::string server_hash_2; | 448 std::string server_hash_2; |
429 | 449 |
430 SdchManager::GenerateHash(dictionary_text_1, &tmp_hash, &server_hash_1); | 450 SdchManager::GenerateHash(dictionary_text_1, &tmp_hash, &server_hash_1); |
431 SdchManager::GenerateHash(dictionary_text_2, &tmp_hash, &server_hash_2); | 451 SdchManager::GenerateHash(dictionary_text_2, &tmp_hash, &server_hash_2); |
432 | 452 |
433 // Confirm that if you add directories to one manager, you | 453 // Confirm that if you add directories to one manager, you |
434 // can't get them from the other. | 454 // can't get them from the other. |
435 EXPECT_TRUE(AddSdchDictionary(dictionary_text_1, | 455 EXPECT_TRUE(AddSdchDictionary(dictionary_text_1, |
436 GURL("http://" + dictionary_domain_1))); | 456 GURL("http://" + dictionary_domain_1))); |
437 scoped_refptr<SdchManager::Dictionary> dictionary; | 457 scoped_refptr<SdchManager::Dictionary> dictionary; |
438 sdch_manager()->GetVcdiffDictionary( | 458 EXPECT_EQ(SdchManager::PROBLEM_CODE_OK, |
439 server_hash_1, | 459 sdch_manager()->GetVcdiffDictionary( |
440 GURL("http://" + dictionary_domain_1 + "/random_url"), | 460 server_hash_1, |
441 &dictionary); | 461 GURL("http://" + dictionary_domain_1 + "/random_url"), |
| 462 &dictionary)); |
442 EXPECT_TRUE(dictionary.get()); | 463 EXPECT_TRUE(dictionary.get()); |
443 | 464 |
444 second_manager.AddSdchDictionary( | 465 second_manager.AddSdchDictionary( |
445 dictionary_text_2, GURL("http://" + dictionary_domain_2)); | 466 dictionary_text_2, GURL("http://" + dictionary_domain_2), BoundNetLog()); |
446 second_manager.GetVcdiffDictionary( | 467 second_manager.GetVcdiffDictionary( |
447 server_hash_2, | 468 server_hash_2, |
448 GURL("http://" + dictionary_domain_2 + "/random_url"), | 469 GURL("http://" + dictionary_domain_2 + "/random_url"), |
449 &dictionary); | 470 &dictionary); |
450 EXPECT_TRUE(dictionary.get()); | 471 EXPECT_TRUE(dictionary.get()); |
451 | 472 |
452 sdch_manager()->GetVcdiffDictionary( | 473 EXPECT_EQ(SdchManager::PROBLEM_CODE_OK, |
453 server_hash_2, | 474 sdch_manager()->GetVcdiffDictionary( |
454 GURL("http://" + dictionary_domain_2 + "/random_url"), | 475 server_hash_2, |
455 &dictionary); | 476 GURL("http://" + dictionary_domain_2 + "/random_url"), |
| 477 &dictionary)); |
456 EXPECT_FALSE(dictionary.get()); | 478 EXPECT_FALSE(dictionary.get()); |
457 | 479 |
458 second_manager.GetVcdiffDictionary( | 480 EXPECT_EQ(SdchManager::PROBLEM_CODE_OK, |
459 server_hash_1, | 481 second_manager.GetVcdiffDictionary( |
460 GURL("http://" + dictionary_domain_1 + "/random_url"), | 482 server_hash_1, |
461 &dictionary); | 483 GURL("http://" + dictionary_domain_1 + "/random_url"), |
| 484 &dictionary)); |
462 EXPECT_FALSE(dictionary.get()); | 485 EXPECT_FALSE(dictionary.get()); |
463 } | 486 } |
464 | 487 |
465 TEST_F(SdchManagerTest, HttpsCorrectlySupported) { | 488 TEST_F(SdchManagerTest, HttpsCorrectlySupported) { |
466 GURL url("http://www.google.com"); | 489 GURL url("http://www.google.com"); |
467 GURL secure_url("https://www.google.com"); | 490 GURL secure_url("https://www.google.com"); |
468 | 491 |
469 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(url)); | 492 EXPECT_EQ(SdchManager::PROBLEM_CODE_OK, |
470 EXPECT_FALSE(sdch_manager()->IsInSupportedDomain(secure_url)); | 493 sdch_manager()->IsInSupportedDomain(url)); |
| 494 EXPECT_EQ(SdchManager::SECURE_SCHEME_NOT_SUPPORTED, |
| 495 sdch_manager()->IsInSupportedDomain(secure_url)); |
471 | 496 |
472 SdchManager::EnableSecureSchemeSupport(true); | 497 SdchManager::EnableSecureSchemeSupport(true); |
473 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(url)); | 498 EXPECT_EQ(SdchManager::PROBLEM_CODE_OK, |
474 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(secure_url)); | 499 sdch_manager()->IsInSupportedDomain(url)); |
| 500 EXPECT_EQ(SdchManager::PROBLEM_CODE_OK, |
| 501 sdch_manager()->IsInSupportedDomain(secure_url)); |
475 } | 502 } |
476 | 503 |
477 TEST_F(SdchManagerTest, ClearDictionaryData) { | 504 TEST_F(SdchManagerTest, ClearDictionaryData) { |
478 std::string dictionary_domain("x.y.z.google.com"); | 505 std::string dictionary_domain("x.y.z.google.com"); |
479 GURL blacklist_url("http://bad.chromium.org"); | 506 GURL blacklist_url("http://bad.chromium.org"); |
480 | 507 |
481 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); | 508 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); |
482 std::string tmp_hash; | 509 std::string tmp_hash; |
483 std::string server_hash; | 510 std::string server_hash; |
484 | 511 |
485 SdchManager::GenerateHash(dictionary_text, &tmp_hash, &server_hash); | 512 SdchManager::GenerateHash(dictionary_text, &tmp_hash, &server_hash); |
486 | 513 |
487 EXPECT_TRUE(AddSdchDictionary(dictionary_text, | 514 EXPECT_TRUE(AddSdchDictionary(dictionary_text, |
488 GURL("http://" + dictionary_domain))); | 515 GURL("http://" + dictionary_domain))); |
489 scoped_refptr<SdchManager::Dictionary> dictionary; | 516 scoped_refptr<SdchManager::Dictionary> dictionary; |
490 sdch_manager()->GetVcdiffDictionary( | 517 EXPECT_EQ(SdchManager::PROBLEM_CODE_OK, |
491 server_hash, | 518 sdch_manager()->GetVcdiffDictionary( |
492 GURL("http://" + dictionary_domain + "/random_url"), | 519 server_hash, |
493 &dictionary); | 520 GURL("http://" + dictionary_domain + "/random_url"), |
| 521 &dictionary)); |
494 EXPECT_TRUE(dictionary.get()); | 522 EXPECT_TRUE(dictionary.get()); |
495 | 523 |
496 sdch_manager()->BlacklistDomain(GURL(blacklist_url), | 524 sdch_manager()->BlacklistDomain(GURL(blacklist_url), |
497 SdchManager::MIN_PROBLEM_CODE); | 525 SdchManager::PROBLEM_CODE_OK); |
498 EXPECT_FALSE(sdch_manager()->IsInSupportedDomain(blacklist_url)); | 526 EXPECT_EQ(SdchManager::DOMAIN_BLACKLIST_INCLUDES_TARGET, |
| 527 sdch_manager()->IsInSupportedDomain(blacklist_url)); |
499 | 528 |
500 sdch_manager()->ClearData(); | 529 sdch_manager()->ClearData(); |
501 | 530 |
502 dictionary = NULL; | 531 dictionary = NULL; |
503 sdch_manager()->GetVcdiffDictionary( | 532 EXPECT_EQ(SdchManager::PROBLEM_CODE_OK, |
504 server_hash, | 533 sdch_manager()->GetVcdiffDictionary( |
505 GURL("http://" + dictionary_domain + "/random_url"), | 534 server_hash, |
506 &dictionary); | 535 GURL("http://" + dictionary_domain + "/random_url"), |
| 536 &dictionary)); |
507 EXPECT_FALSE(dictionary.get()); | 537 EXPECT_FALSE(dictionary.get()); |
508 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(blacklist_url)); | 538 EXPECT_EQ(SdchManager::PROBLEM_CODE_OK, |
| 539 sdch_manager()->IsInSupportedDomain(blacklist_url)); |
509 } | 540 } |
510 | 541 |
511 } // namespace net | 542 } // namespace net |
512 | 543 |
OLD | NEW |