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" |
(...skipping 17 matching lines...) Expand all Loading... |
28 } | 28 } |
29 | 29 |
30 SdchManager* sdch_manager() { return sdch_manager_.get(); } | 30 SdchManager* sdch_manager() { return sdch_manager_.get(); } |
31 | 31 |
32 // Reset globals back to default state. | 32 // Reset globals back to default state. |
33 virtual void TearDown() { | 33 virtual void TearDown() { |
34 SdchManager::EnableSdchSupport(true); | 34 SdchManager::EnableSdchSupport(true); |
35 SdchManager::EnableSecureSchemeSupport(false); | 35 SdchManager::EnableSecureSchemeSupport(false); |
36 } | 36 } |
37 | 37 |
| 38 // Attempt to add a dictionary to the manager and probe for success or |
| 39 // failure. |
| 40 bool AddSdchDictionary(const std::string& dictionary_text, |
| 41 const GURL& gurl) { |
| 42 std::string list; |
| 43 sdch_manager_->GetAvailDictionaryList(gurl, &list); |
| 44 sdch_manager_->AddSdchDictionary(dictionary_text, gurl); |
| 45 std::string list2; |
| 46 sdch_manager_->GetAvailDictionaryList(gurl, &list2); |
| 47 |
| 48 // The list of hashes should change iff the addition succeeds. |
| 49 return (list != list2); |
| 50 } |
| 51 |
38 private: | 52 private: |
39 scoped_ptr<SdchManager> sdch_manager_; | 53 scoped_ptr<SdchManager> sdch_manager_; |
40 }; | 54 }; |
41 | 55 |
42 //------------------------------------------------------------------------------ | 56 //------------------------------------------------------------------------------ |
43 static std::string NewSdchDictionary(const std::string& domain) { | 57 static std::string NewSdchDictionary(const std::string& domain) { |
44 std::string dictionary; | 58 std::string dictionary; |
45 if (!domain.empty()) { | 59 if (!domain.empty()) { |
46 dictionary.append("Domain: "); | 60 dictionary.append("Domain: "); |
47 dictionary.append(domain); | 61 dictionary.append(domain); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 if (exponential < 0) | 147 if (exponential < 0) |
134 exponential = INT_MAX; // We don't wrap. | 148 exponential = INT_MAX; // We don't wrap. |
135 } | 149 } |
136 } | 150 } |
137 | 151 |
138 TEST_F(SdchManagerTest, CanSetExactMatchDictionary) { | 152 TEST_F(SdchManagerTest, CanSetExactMatchDictionary) { |
139 std::string dictionary_domain("x.y.z.google.com"); | 153 std::string dictionary_domain("x.y.z.google.com"); |
140 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); | 154 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); |
141 | 155 |
142 // Perfect match should work. | 156 // Perfect match should work. |
143 EXPECT_TRUE(sdch_manager()->AddSdchDictionary(dictionary_text, | 157 EXPECT_TRUE(AddSdchDictionary(dictionary_text, |
144 GURL("http://" + dictionary_domain))); | 158 GURL("http://" + dictionary_domain))); |
145 } | 159 } |
146 | 160 |
147 TEST_F(SdchManagerTest, CanAdvertiseDictionaryOverHTTP) { | 161 TEST_F(SdchManagerTest, CanAdvertiseDictionaryOverHTTP) { |
148 std::string dictionary_domain("x.y.z.google.com"); | 162 std::string dictionary_domain("x.y.z.google.com"); |
149 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); | 163 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); |
150 | 164 |
151 EXPECT_TRUE(sdch_manager()->AddSdchDictionary(dictionary_text, | 165 EXPECT_TRUE(AddSdchDictionary(dictionary_text, |
152 GURL("http://" + dictionary_domain))); | 166 GURL("http://" + dictionary_domain))); |
153 | 167 |
154 std::string dictionary_list; | 168 std::string dictionary_list; |
155 // HTTP target URL can advertise dictionary. | 169 // HTTP target URL can advertise dictionary. |
156 sdch_manager()->GetAvailDictionaryList( | 170 sdch_manager()->GetAvailDictionaryList( |
157 GURL("http://" + dictionary_domain + "/test"), | 171 GURL("http://" + dictionary_domain + "/test"), |
158 &dictionary_list); | 172 &dictionary_list); |
159 EXPECT_FALSE(dictionary_list.empty()); | 173 EXPECT_FALSE(dictionary_list.empty()); |
160 } | 174 } |
161 | 175 |
162 TEST_F(SdchManagerTest, CanNotAdvertiseDictionaryOverHTTPS) { | 176 TEST_F(SdchManagerTest, CanNotAdvertiseDictionaryOverHTTPS) { |
163 std::string dictionary_domain("x.y.z.google.com"); | 177 std::string dictionary_domain("x.y.z.google.com"); |
164 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); | 178 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); |
165 | 179 |
166 EXPECT_TRUE(sdch_manager()->AddSdchDictionary(dictionary_text, | 180 EXPECT_TRUE(AddSdchDictionary(dictionary_text, |
167 GURL("http://" + dictionary_domain))); | 181 GURL("http://" + dictionary_domain))); |
168 | 182 |
169 std::string dictionary_list; | 183 std::string dictionary_list; |
170 // HTTPS target URL should NOT advertise dictionary. | 184 // HTTPS target URL should NOT advertise dictionary. |
171 sdch_manager()->GetAvailDictionaryList( | 185 sdch_manager()->GetAvailDictionaryList( |
172 GURL("https://" + dictionary_domain + "/test"), | 186 GURL("https://" + dictionary_domain + "/test"), |
173 &dictionary_list); | 187 &dictionary_list); |
174 EXPECT_TRUE(dictionary_list.empty()); | 188 EXPECT_TRUE(dictionary_list.empty()); |
175 } | 189 } |
176 | 190 |
177 TEST_F(SdchManagerTest, CanUseHTTPSDictionaryOverHTTPSIfEnabled) { | 191 TEST_F(SdchManagerTest, CanUseHTTPSDictionaryOverHTTPSIfEnabled) { |
178 std::string dictionary_domain("x.y.z.google.com"); | 192 std::string dictionary_domain("x.y.z.google.com"); |
179 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); | 193 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); |
180 | 194 |
181 EXPECT_FALSE(sdch_manager()->AddSdchDictionary( | 195 EXPECT_FALSE(AddSdchDictionary(dictionary_text, |
182 dictionary_text, GURL("https://" + dictionary_domain))); | 196 GURL("https://" + dictionary_domain))); |
183 SdchManager::EnableSecureSchemeSupport(true); | 197 SdchManager::EnableSecureSchemeSupport(true); |
184 EXPECT_TRUE(sdch_manager()->AddSdchDictionary( | 198 EXPECT_TRUE(AddSdchDictionary(dictionary_text, |
185 dictionary_text, GURL("https://" + dictionary_domain))); | 199 GURL("https://" + dictionary_domain))); |
186 | 200 |
187 GURL target_url("https://" + dictionary_domain + "/test"); | 201 GURL target_url("https://" + dictionary_domain + "/test"); |
188 std::string dictionary_list; | 202 std::string dictionary_list; |
189 // HTTPS target URL should advertise dictionary if secure scheme support is | 203 // HTTPS target URL should advertise dictionary if secure scheme support is |
190 // enabled. | 204 // enabled. |
191 sdch_manager()->GetAvailDictionaryList(target_url, &dictionary_list); | 205 sdch_manager()->GetAvailDictionaryList(target_url, &dictionary_list); |
192 EXPECT_FALSE(dictionary_list.empty()); | 206 EXPECT_FALSE(dictionary_list.empty()); |
193 | 207 |
194 // Dictionary should be available. | 208 // Dictionary should be available. |
195 scoped_refptr<SdchManager::Dictionary> dictionary; | 209 scoped_refptr<SdchManager::Dictionary> dictionary; |
196 std::string client_hash; | 210 std::string client_hash; |
197 std::string server_hash; | 211 std::string server_hash; |
198 sdch_manager()->GenerateHash(dictionary_text, &client_hash, &server_hash); | 212 sdch_manager()->GenerateHash(dictionary_text, &client_hash, &server_hash); |
199 sdch_manager()->GetVcdiffDictionary(server_hash, target_url, &dictionary); | 213 sdch_manager()->GetVcdiffDictionary(server_hash, target_url, &dictionary); |
200 EXPECT_TRUE(dictionary.get() != NULL); | 214 EXPECT_TRUE(dictionary.get() != NULL); |
201 } | 215 } |
202 | 216 |
203 TEST_F(SdchManagerTest, CanNotUseHTTPDictionaryOverHTTPS) { | 217 TEST_F(SdchManagerTest, CanNotUseHTTPDictionaryOverHTTPS) { |
204 std::string dictionary_domain("x.y.z.google.com"); | 218 std::string dictionary_domain("x.y.z.google.com"); |
205 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); | 219 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); |
206 | 220 |
207 EXPECT_TRUE(sdch_manager()->AddSdchDictionary(dictionary_text, | 221 EXPECT_TRUE(AddSdchDictionary(dictionary_text, |
208 GURL("http://" + dictionary_domain))); | 222 GURL("http://" + dictionary_domain))); |
209 | 223 |
210 GURL target_url("https://" + dictionary_domain + "/test"); | 224 GURL target_url("https://" + dictionary_domain + "/test"); |
211 std::string dictionary_list; | 225 std::string dictionary_list; |
212 // HTTPS target URL should not advertise dictionary acquired over HTTP even if | 226 // HTTPS target URL should not advertise dictionary acquired over HTTP even if |
213 // secure scheme support is enabled. | 227 // secure scheme support is enabled. |
214 SdchManager::EnableSecureSchemeSupport(true); | 228 SdchManager::EnableSecureSchemeSupport(true); |
215 sdch_manager()->GetAvailDictionaryList(target_url, &dictionary_list); | 229 sdch_manager()->GetAvailDictionaryList(target_url, &dictionary_list); |
216 EXPECT_TRUE(dictionary_list.empty()); | 230 EXPECT_TRUE(dictionary_list.empty()); |
217 | 231 |
218 scoped_refptr<SdchManager::Dictionary> dictionary; | 232 scoped_refptr<SdchManager::Dictionary> dictionary; |
219 std::string client_hash; | 233 std::string client_hash; |
220 std::string server_hash; | 234 std::string server_hash; |
221 sdch_manager()->GenerateHash(dictionary_text, &client_hash, &server_hash); | 235 sdch_manager()->GenerateHash(dictionary_text, &client_hash, &server_hash); |
222 sdch_manager()->GetVcdiffDictionary(server_hash, target_url, &dictionary); | 236 sdch_manager()->GetVcdiffDictionary(server_hash, target_url, &dictionary); |
223 EXPECT_TRUE(dictionary.get() == NULL); | 237 EXPECT_TRUE(dictionary.get() == NULL); |
224 } | 238 } |
225 | 239 |
226 TEST_F(SdchManagerTest, CanNotUseHTTPSDictionaryOverHTTP) { | 240 TEST_F(SdchManagerTest, CanNotUseHTTPSDictionaryOverHTTP) { |
227 std::string dictionary_domain("x.y.z.google.com"); | 241 std::string dictionary_domain("x.y.z.google.com"); |
228 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); | 242 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); |
229 | 243 |
230 SdchManager::EnableSecureSchemeSupport(true); | 244 SdchManager::EnableSecureSchemeSupport(true); |
231 EXPECT_TRUE(sdch_manager()->AddSdchDictionary(dictionary_text, | 245 EXPECT_TRUE(AddSdchDictionary(dictionary_text, |
232 GURL("https://" + dictionary_domain))); | 246 GURL("https://" + dictionary_domain))); |
233 | 247 |
234 GURL target_url("http://" + dictionary_domain + "/test"); | 248 GURL target_url("http://" + dictionary_domain + "/test"); |
235 std::string dictionary_list; | 249 std::string dictionary_list; |
236 // HTTP target URL should not advertise dictionary acquired over HTTPS even if | 250 // HTTP target URL should not advertise dictionary acquired over HTTPS even if |
237 // secure scheme support is enabled. | 251 // secure scheme support is enabled. |
238 sdch_manager()->GetAvailDictionaryList(target_url, &dictionary_list); | 252 sdch_manager()->GetAvailDictionaryList(target_url, &dictionary_list); |
239 EXPECT_TRUE(dictionary_list.empty()); | 253 EXPECT_TRUE(dictionary_list.empty()); |
240 | 254 |
241 scoped_refptr<SdchManager::Dictionary> dictionary; | 255 scoped_refptr<SdchManager::Dictionary> dictionary; |
242 std::string client_hash; | 256 std::string client_hash; |
243 std::string server_hash; | 257 std::string server_hash; |
244 sdch_manager()->GenerateHash(dictionary_text, &client_hash, &server_hash); | 258 sdch_manager()->GenerateHash(dictionary_text, &client_hash, &server_hash); |
245 sdch_manager()->GetVcdiffDictionary(server_hash, target_url, &dictionary); | 259 sdch_manager()->GetVcdiffDictionary(server_hash, target_url, &dictionary); |
246 EXPECT_TRUE(dictionary.get() == NULL); | 260 EXPECT_TRUE(dictionary.get() == NULL); |
247 } | 261 } |
248 | 262 |
249 TEST_F(SdchManagerTest, FailToSetDomainMismatchDictionary) { | 263 TEST_F(SdchManagerTest, FailToSetDomainMismatchDictionary) { |
250 std::string dictionary_domain("x.y.z.google.com"); | 264 std::string dictionary_domain("x.y.z.google.com"); |
251 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); | 265 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); |
252 | 266 |
253 // Fail the "domain match" requirement. | 267 // Fail the "domain match" requirement. |
254 EXPECT_FALSE(sdch_manager()->AddSdchDictionary(dictionary_text, | 268 EXPECT_FALSE(AddSdchDictionary(dictionary_text, |
255 GURL("http://y.z.google.com"))); | 269 GURL("http://y.z.google.com"))); |
256 } | 270 } |
257 | 271 |
258 TEST_F(SdchManagerTest, FailToSetDotHostPrefixDomainDictionary) { | 272 TEST_F(SdchManagerTest, FailToSetDotHostPrefixDomainDictionary) { |
259 std::string dictionary_domain("x.y.z.google.com"); | 273 std::string dictionary_domain("x.y.z.google.com"); |
260 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); | 274 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); |
261 | 275 |
262 // Fail the HD with D being the domain and H having a dot requirement. | 276 // Fail the HD with D being the domain and H having a dot requirement. |
263 EXPECT_FALSE(sdch_manager()->AddSdchDictionary(dictionary_text, | 277 EXPECT_FALSE(AddSdchDictionary(dictionary_text, |
264 GURL("http://w.x.y.z.google.com"))); | 278 GURL("http://w.x.y.z.google.com"))); |
265 } | 279 } |
266 | 280 |
267 TEST_F(SdchManagerTest, FailToSetRepeatPrefixWithDotDictionary) { | 281 TEST_F(SdchManagerTest, FailToSetRepeatPrefixWithDotDictionary) { |
268 // Make sure that a prefix that matches the domain postfix won't confuse | 282 // Make sure that a prefix that matches the domain postfix won't confuse |
269 // the validation checks. | 283 // the validation checks. |
270 std::string dictionary_domain("www.google.com"); | 284 std::string dictionary_domain("www.google.com"); |
271 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); | 285 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); |
272 | 286 |
273 // Fail the HD with D being the domain and H having a dot requirement. | 287 // Fail the HD with D being the domain and H having a dot requirement. |
274 EXPECT_FALSE(sdch_manager()->AddSdchDictionary(dictionary_text, | 288 EXPECT_FALSE(AddSdchDictionary(dictionary_text, |
275 GURL("http://www.google.com.www.google.com"))); | 289 GURL("http://www.google.com.www.google.com"))); |
276 } | 290 } |
277 | 291 |
278 TEST_F(SdchManagerTest, CanSetLeadingDotDomainDictionary) { | 292 TEST_F(SdchManagerTest, CanSetLeadingDotDomainDictionary) { |
279 // Make sure that a prefix that matches the domain postfix won't confuse | 293 // Make sure that a prefix that matches the domain postfix won't confuse |
280 // the validation checks. | 294 // the validation checks. |
281 std::string dictionary_domain(".google.com"); | 295 std::string dictionary_domain(".google.com"); |
282 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); | 296 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); |
283 | 297 |
284 // Verify that a leading dot in the domain is acceptable, as long as the host | 298 // Verify that a leading dot in the domain is acceptable, as long as the host |
285 // name does not contain any dots preceding the matched domain name. | 299 // name does not contain any dots preceding the matched domain name. |
286 EXPECT_TRUE(sdch_manager()->AddSdchDictionary(dictionary_text, | 300 EXPECT_TRUE(AddSdchDictionary(dictionary_text, GURL("http://www.google.com")))
; |
287 GURL("http://www.google.com"))); | |
288 } | 301 } |
289 | 302 |
290 // Make sure the order of the tests is not helping us or confusing things. | 303 // Make sure the order of the tests is not helping us or confusing things. |
291 // See test CanSetExactMatchDictionary above for first try. | 304 // See test CanSetExactMatchDictionary above for first try. |
292 TEST_F(SdchManagerTest, CanStillSetExactMatchDictionary) { | 305 TEST_F(SdchManagerTest, CanStillSetExactMatchDictionary) { |
293 std::string dictionary_domain("x.y.z.google.com"); | 306 std::string dictionary_domain("x.y.z.google.com"); |
294 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); | 307 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); |
295 | 308 |
296 // Perfect match should *STILL* work. | 309 // Perfect match should *STILL* work. |
297 EXPECT_TRUE(sdch_manager()->AddSdchDictionary(dictionary_text, | 310 EXPECT_TRUE(AddSdchDictionary(dictionary_text, |
298 GURL("http://" + dictionary_domain))); | 311 GURL("http://" + dictionary_domain))); |
299 } | 312 } |
300 | 313 |
301 // Make sure the DOS protection precludes the addition of too many dictionaries. | 314 // Make sure the DOS protection precludes the addition of too many dictionaries. |
302 TEST_F(SdchManagerTest, TooManyDictionaries) { | 315 TEST_F(SdchManagerTest, TooManyDictionaries) { |
303 std::string dictionary_domain(".google.com"); | 316 std::string dictionary_domain(".google.com"); |
304 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); | 317 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); |
305 | 318 |
306 size_t count = 0; | 319 for (size_t count = 0; count < SdchManager::kMaxDictionaryCount; ++count) { |
307 while (count <= SdchManager::kMaxDictionaryCount + 1) { | 320 EXPECT_TRUE(AddSdchDictionary(dictionary_text, |
308 if (!sdch_manager()->AddSdchDictionary(dictionary_text, | 321 GURL("http://www.google.com"))); |
309 GURL("http://www.google.com"))) | |
310 break; | |
311 | |
312 dictionary_text += " "; // Create dictionary with different SHA signature. | 322 dictionary_text += " "; // Create dictionary with different SHA signature. |
313 ++count; | |
314 } | 323 } |
315 EXPECT_EQ(SdchManager::kMaxDictionaryCount, count); | 324 EXPECT_FALSE( |
| 325 AddSdchDictionary(dictionary_text, GURL("http://www.google.com"))); |
316 } | 326 } |
317 | 327 |
318 TEST_F(SdchManagerTest, DictionaryNotTooLarge) { | 328 TEST_F(SdchManagerTest, DictionaryNotTooLarge) { |
319 std::string dictionary_domain(".google.com"); | 329 std::string dictionary_domain(".google.com"); |
320 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); | 330 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); |
321 | 331 |
322 dictionary_text.append( | 332 dictionary_text.append( |
323 SdchManager::kMaxDictionarySize - dictionary_text.size(), ' '); | 333 SdchManager::kMaxDictionarySize - dictionary_text.size(), ' '); |
324 EXPECT_TRUE(sdch_manager()->AddSdchDictionary(dictionary_text, | 334 EXPECT_TRUE(AddSdchDictionary(dictionary_text, |
325 GURL("http://" + dictionary_domain))); | 335 GURL("http://" + dictionary_domain))); |
326 } | 336 } |
327 | 337 |
328 TEST_F(SdchManagerTest, DictionaryTooLarge) { | 338 TEST_F(SdchManagerTest, DictionaryTooLarge) { |
329 std::string dictionary_domain(".google.com"); | 339 std::string dictionary_domain(".google.com"); |
330 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); | 340 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); |
331 | 341 |
332 dictionary_text.append( | 342 dictionary_text.append( |
333 SdchManager::kMaxDictionarySize + 1 - dictionary_text.size(), ' '); | 343 SdchManager::kMaxDictionarySize + 1 - dictionary_text.size(), ' '); |
334 EXPECT_FALSE(sdch_manager()->AddSdchDictionary(dictionary_text, | 344 EXPECT_FALSE(AddSdchDictionary(dictionary_text, |
335 GURL("http://" + dictionary_domain))); | 345 GURL("http://" + dictionary_domain))); |
336 } | 346 } |
337 | 347 |
338 TEST_F(SdchManagerTest, PathMatch) { | 348 TEST_F(SdchManagerTest, PathMatch) { |
339 bool (*PathMatch)(const std::string& path, const std::string& restriction) = | 349 bool (*PathMatch)(const std::string& path, const std::string& restriction) = |
340 SdchManager::Dictionary::PathMatch; | 350 SdchManager::Dictionary::PathMatch; |
341 // Perfect match is supported. | 351 // Perfect match is supported. |
342 EXPECT_TRUE(PathMatch("/search", "/search")); | 352 EXPECT_TRUE(PathMatch("/search", "/search")); |
343 EXPECT_TRUE(PathMatch("/search/", "/search/")); | 353 EXPECT_TRUE(PathMatch("/search/", "/search/")); |
344 | 354 |
345 // Prefix only works if last character of restriction is a slash, or first | 355 // Prefix only works if last character of restriction is a slash, or first |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 | 425 |
416 std::string tmp_hash; | 426 std::string tmp_hash; |
417 std::string server_hash_1; | 427 std::string server_hash_1; |
418 std::string server_hash_2; | 428 std::string server_hash_2; |
419 | 429 |
420 SdchManager::GenerateHash(dictionary_text_1, &tmp_hash, &server_hash_1); | 430 SdchManager::GenerateHash(dictionary_text_1, &tmp_hash, &server_hash_1); |
421 SdchManager::GenerateHash(dictionary_text_2, &tmp_hash, &server_hash_2); | 431 SdchManager::GenerateHash(dictionary_text_2, &tmp_hash, &server_hash_2); |
422 | 432 |
423 // Confirm that if you add directories to one manager, you | 433 // Confirm that if you add directories to one manager, you |
424 // can't get them from the other. | 434 // can't get them from the other. |
425 EXPECT_TRUE(sdch_manager()->AddSdchDictionary( | 435 EXPECT_TRUE(AddSdchDictionary(dictionary_text_1, |
426 dictionary_text_1, GURL("http://" + dictionary_domain_1))); | 436 GURL("http://" + dictionary_domain_1))); |
427 scoped_refptr<SdchManager::Dictionary> dictionary; | 437 scoped_refptr<SdchManager::Dictionary> dictionary; |
428 sdch_manager()->GetVcdiffDictionary( | 438 sdch_manager()->GetVcdiffDictionary( |
429 server_hash_1, | 439 server_hash_1, |
430 GURL("http://" + dictionary_domain_1 + "/random_url"), | 440 GURL("http://" + dictionary_domain_1 + "/random_url"), |
431 &dictionary); | 441 &dictionary); |
432 EXPECT_TRUE(dictionary.get()); | 442 EXPECT_TRUE(dictionary.get()); |
433 | 443 |
434 EXPECT_TRUE(second_manager.AddSdchDictionary( | 444 second_manager.AddSdchDictionary( |
435 dictionary_text_2, GURL("http://" + dictionary_domain_2))); | 445 dictionary_text_2, GURL("http://" + dictionary_domain_2)); |
436 second_manager.GetVcdiffDictionary( | 446 second_manager.GetVcdiffDictionary( |
437 server_hash_2, | 447 server_hash_2, |
438 GURL("http://" + dictionary_domain_2 + "/random_url"), | 448 GURL("http://" + dictionary_domain_2 + "/random_url"), |
439 &dictionary); | 449 &dictionary); |
440 EXPECT_TRUE(dictionary.get()); | 450 EXPECT_TRUE(dictionary.get()); |
441 | 451 |
442 sdch_manager()->GetVcdiffDictionary( | 452 sdch_manager()->GetVcdiffDictionary( |
443 server_hash_2, | 453 server_hash_2, |
444 GURL("http://" + dictionary_domain_2 + "/random_url"), | 454 GURL("http://" + dictionary_domain_2 + "/random_url"), |
445 &dictionary); | 455 &dictionary); |
(...skipping 21 matching lines...) Expand all Loading... |
467 TEST_F(SdchManagerTest, ClearDictionaryData) { | 477 TEST_F(SdchManagerTest, ClearDictionaryData) { |
468 std::string dictionary_domain("x.y.z.google.com"); | 478 std::string dictionary_domain("x.y.z.google.com"); |
469 GURL blacklist_url("http://bad.chromium.org"); | 479 GURL blacklist_url("http://bad.chromium.org"); |
470 | 480 |
471 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); | 481 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); |
472 std::string tmp_hash; | 482 std::string tmp_hash; |
473 std::string server_hash; | 483 std::string server_hash; |
474 | 484 |
475 SdchManager::GenerateHash(dictionary_text, &tmp_hash, &server_hash); | 485 SdchManager::GenerateHash(dictionary_text, &tmp_hash, &server_hash); |
476 | 486 |
477 EXPECT_TRUE(sdch_manager()->AddSdchDictionary( | 487 EXPECT_TRUE(AddSdchDictionary(dictionary_text, |
478 dictionary_text, GURL("http://" + dictionary_domain))); | 488 GURL("http://" + dictionary_domain))); |
479 scoped_refptr<SdchManager::Dictionary> dictionary; | 489 scoped_refptr<SdchManager::Dictionary> dictionary; |
480 sdch_manager()->GetVcdiffDictionary( | 490 sdch_manager()->GetVcdiffDictionary( |
481 server_hash, | 491 server_hash, |
482 GURL("http://" + dictionary_domain + "/random_url"), | 492 GURL("http://" + dictionary_domain + "/random_url"), |
483 &dictionary); | 493 &dictionary); |
484 EXPECT_TRUE(dictionary.get()); | 494 EXPECT_TRUE(dictionary.get()); |
485 | 495 |
486 sdch_manager()->BlacklistDomain(GURL(blacklist_url), | 496 sdch_manager()->BlacklistDomain(GURL(blacklist_url), |
487 SdchManager::MIN_PROBLEM_CODE); | 497 SdchManager::MIN_PROBLEM_CODE); |
488 EXPECT_FALSE(sdch_manager()->IsInSupportedDomain(blacklist_url)); | 498 EXPECT_FALSE(sdch_manager()->IsInSupportedDomain(blacklist_url)); |
489 | 499 |
490 sdch_manager()->ClearData(); | 500 sdch_manager()->ClearData(); |
491 | 501 |
492 dictionary = NULL; | 502 dictionary = NULL; |
493 sdch_manager()->GetVcdiffDictionary( | 503 sdch_manager()->GetVcdiffDictionary( |
494 server_hash, | 504 server_hash, |
495 GURL("http://" + dictionary_domain + "/random_url"), | 505 GURL("http://" + dictionary_domain + "/random_url"), |
496 &dictionary); | 506 &dictionary); |
497 EXPECT_FALSE(dictionary.get()); | 507 EXPECT_FALSE(dictionary.get()); |
498 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(blacklist_url)); | 508 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(blacklist_url)); |
499 } | 509 } |
500 | 510 |
501 } // namespace net | 511 } // namespace net |
502 | 512 |
OLD | NEW |