Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(279)

Side by Side Diff: net/base/sdch_manager_unittest.cc

Issue 321283002: Clear SDCH information on "Clear browsing data" path. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Incorporated comments. Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/base/sdch_manager.cc ('k') | net/filter/sdch_filter.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 dictionary_text, GURL("https://" + dictionary_domain))); 185 dictionary_text, GURL("https://" + dictionary_domain)));
186 186
187 GURL target_url("https://" + dictionary_domain + "/test"); 187 GURL target_url("https://" + dictionary_domain + "/test");
188 std::string dictionary_list; 188 std::string dictionary_list;
189 // HTTPS target URL should advertise dictionary if secure scheme support is 189 // HTTPS target URL should advertise dictionary if secure scheme support is
190 // enabled. 190 // enabled.
191 sdch_manager()->GetAvailDictionaryList(target_url, &dictionary_list); 191 sdch_manager()->GetAvailDictionaryList(target_url, &dictionary_list);
192 EXPECT_FALSE(dictionary_list.empty()); 192 EXPECT_FALSE(dictionary_list.empty());
193 193
194 // Dictionary should be available. 194 // Dictionary should be available.
195 SdchManager::Dictionary* dictionary = NULL; 195 scoped_refptr<SdchManager::Dictionary> dictionary;
196 std::string client_hash; 196 std::string client_hash;
197 std::string server_hash; 197 std::string server_hash;
198 sdch_manager()->GenerateHash(dictionary_text, &client_hash, &server_hash); 198 sdch_manager()->GenerateHash(dictionary_text, &client_hash, &server_hash);
199 sdch_manager()->GetVcdiffDictionary(server_hash, target_url, &dictionary); 199 sdch_manager()->GetVcdiffDictionary(server_hash, target_url, &dictionary);
200 EXPECT_TRUE(dictionary != NULL); 200 EXPECT_TRUE(dictionary != NULL);
201 } 201 }
202 202
203 TEST_F(SdchManagerTest, CanNotUseHTTPDictionaryOverHTTPS) { 203 TEST_F(SdchManagerTest, CanNotUseHTTPDictionaryOverHTTPS) {
204 std::string dictionary_domain("x.y.z.google.com"); 204 std::string dictionary_domain("x.y.z.google.com");
205 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); 205 std::string dictionary_text(NewSdchDictionary(dictionary_domain));
206 206
207 EXPECT_TRUE(sdch_manager()->AddSdchDictionary(dictionary_text, 207 EXPECT_TRUE(sdch_manager()->AddSdchDictionary(dictionary_text,
208 GURL("http://" + dictionary_domain))); 208 GURL("http://" + dictionary_domain)));
209 209
210 GURL target_url("https://" + dictionary_domain + "/test"); 210 GURL target_url("https://" + dictionary_domain + "/test");
211 std::string dictionary_list; 211 std::string dictionary_list;
212 // HTTPS target URL should not advertise dictionary acquired over HTTP even if 212 // HTTPS target URL should not advertise dictionary acquired over HTTP even if
213 // secure scheme support is enabled. 213 // secure scheme support is enabled.
214 SdchManager::EnableSecureSchemeSupport(true); 214 SdchManager::EnableSecureSchemeSupport(true);
215 sdch_manager()->GetAvailDictionaryList(target_url, &dictionary_list); 215 sdch_manager()->GetAvailDictionaryList(target_url, &dictionary_list);
216 EXPECT_TRUE(dictionary_list.empty()); 216 EXPECT_TRUE(dictionary_list.empty());
217 217
218 SdchManager::Dictionary* dictionary = NULL; 218 scoped_refptr<SdchManager::Dictionary> dictionary;
219 std::string client_hash; 219 std::string client_hash;
220 std::string server_hash; 220 std::string server_hash;
221 sdch_manager()->GenerateHash(dictionary_text, &client_hash, &server_hash); 221 sdch_manager()->GenerateHash(dictionary_text, &client_hash, &server_hash);
222 sdch_manager()->GetVcdiffDictionary(server_hash, target_url, &dictionary); 222 sdch_manager()->GetVcdiffDictionary(server_hash, target_url, &dictionary);
223 EXPECT_TRUE(dictionary == NULL); 223 EXPECT_TRUE(dictionary == NULL);
224 } 224 }
225 225
226 TEST_F(SdchManagerTest, FailToSetDomainMismatchDictionary) { 226 TEST_F(SdchManagerTest, FailToSetDomainMismatchDictionary) {
227 std::string dictionary_domain("x.y.z.google.com"); 227 std::string dictionary_domain("x.y.z.google.com");
228 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); 228 std::string dictionary_text(NewSdchDictionary(dictionary_domain));
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 std::string server_hash_1; 394 std::string server_hash_1;
395 std::string server_hash_2; 395 std::string server_hash_2;
396 396
397 SdchManager::GenerateHash(dictionary_text_1, &tmp_hash, &server_hash_1); 397 SdchManager::GenerateHash(dictionary_text_1, &tmp_hash, &server_hash_1);
398 SdchManager::GenerateHash(dictionary_text_2, &tmp_hash, &server_hash_2); 398 SdchManager::GenerateHash(dictionary_text_2, &tmp_hash, &server_hash_2);
399 399
400 // Confirm that if you add directories to one manager, you 400 // Confirm that if you add directories to one manager, you
401 // can't get them from the other. 401 // can't get them from the other.
402 EXPECT_TRUE(sdch_manager()->AddSdchDictionary( 402 EXPECT_TRUE(sdch_manager()->AddSdchDictionary(
403 dictionary_text_1, GURL("http://" + dictionary_domain_1))); 403 dictionary_text_1, GURL("http://" + dictionary_domain_1)));
404 SdchManager::Dictionary* dictionary = NULL; 404 scoped_refptr<SdchManager::Dictionary> dictionary;
405 sdch_manager()->GetVcdiffDictionary( 405 sdch_manager()->GetVcdiffDictionary(
406 server_hash_1, 406 server_hash_1,
407 GURL("http://" + dictionary_domain_1 + "/random_url"), 407 GURL("http://" + dictionary_domain_1 + "/random_url"),
408 &dictionary); 408 &dictionary);
409 EXPECT_TRUE(dictionary); 409 EXPECT_TRUE(dictionary);
410 410
411 EXPECT_TRUE(second_manager.AddSdchDictionary( 411 EXPECT_TRUE(second_manager.AddSdchDictionary(
412 dictionary_text_2, GURL("http://" + dictionary_domain_2))); 412 dictionary_text_2, GURL("http://" + dictionary_domain_2)));
413 second_manager.GetVcdiffDictionary( 413 second_manager.GetVcdiffDictionary(
414 server_hash_2, 414 server_hash_2,
(...skipping 19 matching lines...) Expand all
434 GURL secure_url("https://www.google.com"); 434 GURL secure_url("https://www.google.com");
435 435
436 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(url)); 436 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(url));
437 EXPECT_FALSE(sdch_manager()->IsInSupportedDomain(secure_url)); 437 EXPECT_FALSE(sdch_manager()->IsInSupportedDomain(secure_url));
438 438
439 SdchManager::EnableSecureSchemeSupport(true); 439 SdchManager::EnableSecureSchemeSupport(true);
440 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(url)); 440 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(url));
441 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(secure_url)); 441 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(secure_url));
442 } 442 }
443 443
444 TEST_F(SdchManagerTest, ClearDictionaryData) {
445 std::string dictionary_domain("x.y.z.google.com");
446 GURL blacklist_url("http://bad.chromium.org");
447
448 std::string dictionary_text(NewSdchDictionary(dictionary_domain));
449 std::string tmp_hash;
450 std::string server_hash;
451
452 SdchManager::GenerateHash(dictionary_text, &tmp_hash, &server_hash);
453
454 EXPECT_TRUE(sdch_manager()->AddSdchDictionary(
455 dictionary_text, GURL("http://" + dictionary_domain)));
456 scoped_refptr<SdchManager::Dictionary> dictionary;
457 sdch_manager()->GetVcdiffDictionary(
458 server_hash,
459 GURL("http://" + dictionary_domain + "/random_url"),
460 &dictionary);
461 EXPECT_TRUE(dictionary);
462
463 sdch_manager()->BlacklistDomain(GURL(blacklist_url));
464 EXPECT_FALSE(sdch_manager()->IsInSupportedDomain(blacklist_url));
465
466 sdch_manager()->ClearData();
467
468 dictionary = NULL;
469 sdch_manager()->GetVcdiffDictionary(
470 server_hash,
471 GURL("http://" + dictionary_domain + "/random_url"),
472 &dictionary);
473 EXPECT_FALSE(dictionary);
474 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(blacklist_url));
475 }
476
444 } // namespace net 477 } // namespace net
445 478
OLDNEW
« no previous file with comments | « net/base/sdch_manager.cc ('k') | net/filter/sdch_filter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698