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

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

Issue 754433003: Update from https://crrev.com/305340 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years, 1 month 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
« no previous file with comments | « net/base/sdch_manager.cc ('k') | net/base/sdch_problem_code_list.h » ('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"
11 #include "base/strings/stringprintf.h"
12 #include "base/test/simple_test_clock.h"
11 #include "net/base/net_log.h" 13 #include "net/base/net_log.h"
12 #include "net/base/sdch_manager.h" 14 #include "net/base/sdch_manager.h"
13 #include "net/base/sdch_observer.h" 15 #include "net/base/sdch_observer.h"
14 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
15 #include "url/gurl.h" 17 #include "url/gurl.h"
16 18
17 namespace net { 19 namespace net {
18 20
19 //------------------------------------------------------------------------------ 21 //------------------------------------------------------------------------------
20 // Provide sample data and compression results with a sample VCDIFF dictionary. 22 // Provide sample data and compression results with a sample VCDIFF dictionary.
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 GURL("http://" + dictionary_domain))); 194 GURL("http://" + dictionary_domain)));
193 } 195 }
194 196
195 TEST_F(SdchManagerTest, CanAdvertiseDictionaryOverHTTP) { 197 TEST_F(SdchManagerTest, CanAdvertiseDictionaryOverHTTP) {
196 std::string dictionary_domain("x.y.z.google.com"); 198 std::string dictionary_domain("x.y.z.google.com");
197 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); 199 std::string dictionary_text(NewSdchDictionary(dictionary_domain));
198 200
199 EXPECT_TRUE(AddSdchDictionary(dictionary_text, 201 EXPECT_TRUE(AddSdchDictionary(dictionary_text,
200 GURL("http://" + dictionary_domain))); 202 GURL("http://" + dictionary_domain)));
201 203
202 std::string dictionary_list;
203 // HTTP target URL can advertise dictionary. 204 // HTTP target URL can advertise dictionary.
204 sdch_manager()->GetAvailDictionaryList( 205 EXPECT_TRUE(sdch_manager()->GetDictionarySet(
205 GURL("http://" + dictionary_domain + "/test"), 206 GURL("http://" + dictionary_domain + "/test")));
206 &dictionary_list);
207 EXPECT_FALSE(dictionary_list.empty());
208 } 207 }
209 208
210 TEST_F(SdchManagerTest, CanNotAdvertiseDictionaryOverHTTPS) { 209 TEST_F(SdchManagerTest, CanNotAdvertiseDictionaryOverHTTPS) {
211 std::string dictionary_domain("x.y.z.google.com"); 210 std::string dictionary_domain("x.y.z.google.com");
212 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); 211 std::string dictionary_text(NewSdchDictionary(dictionary_domain));
213 212
214 EXPECT_TRUE(AddSdchDictionary(dictionary_text, 213 EXPECT_TRUE(AddSdchDictionary(dictionary_text,
215 GURL("http://" + dictionary_domain))); 214 GURL("http://" + dictionary_domain)));
216 215
217 std::string dictionary_list;
218 // HTTPS target URL should NOT advertise dictionary. 216 // HTTPS target URL should NOT advertise dictionary.
219 sdch_manager()->GetAvailDictionaryList( 217 EXPECT_FALSE(sdch_manager()->GetDictionarySet(
220 GURL("https://" + dictionary_domain + "/test"), 218 GURL("https://" + dictionary_domain + "/test")));
221 &dictionary_list);
222 EXPECT_TRUE(dictionary_list.empty());
223 } 219 }
224 220
225 TEST_F(SdchManagerTest, CanUseHTTPSDictionaryOverHTTPSIfEnabled) { 221 TEST_F(SdchManagerTest, CanUseHTTPSDictionaryOverHTTPSIfEnabled) {
226 std::string dictionary_domain("x.y.z.google.com"); 222 std::string dictionary_domain("x.y.z.google.com");
227 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); 223 std::string dictionary_text(NewSdchDictionary(dictionary_domain));
228 224
229 SdchManager::EnableSecureSchemeSupport(false); 225 SdchManager::EnableSecureSchemeSupport(false);
230 EXPECT_FALSE(AddSdchDictionary(dictionary_text, 226 EXPECT_FALSE(AddSdchDictionary(dictionary_text,
231 GURL("https://" + dictionary_domain))); 227 GURL("https://" + dictionary_domain)));
232 SdchManager::EnableSecureSchemeSupport(true); 228 SdchManager::EnableSecureSchemeSupport(true);
233 EXPECT_TRUE(AddSdchDictionary(dictionary_text, 229 EXPECT_TRUE(AddSdchDictionary(dictionary_text,
234 GURL("https://" + dictionary_domain))); 230 GURL("https://" + dictionary_domain)));
235 231
236 GURL target_url("https://" + dictionary_domain + "/test"); 232 GURL target_url("https://" + dictionary_domain + "/test");
237 std::string dictionary_list;
238 // HTTPS target URL should advertise dictionary if secure scheme support is 233 // HTTPS target URL should advertise dictionary if secure scheme support is
239 // enabled. 234 // enabled.
240 sdch_manager()->GetAvailDictionaryList(target_url, &dictionary_list); 235 EXPECT_TRUE(sdch_manager()->GetDictionarySet(target_url));
241 EXPECT_FALSE(dictionary_list.empty());
242 236
243 // Dictionary should be available. 237 // Dictionary should be available.
244 scoped_refptr<SdchManager::Dictionary> dictionary;
245 std::string client_hash; 238 std::string client_hash;
246 std::string server_hash; 239 std::string server_hash;
247 sdch_manager()->GenerateHash(dictionary_text, &client_hash, &server_hash); 240 sdch_manager()->GenerateHash(dictionary_text, &client_hash, &server_hash);
248 EXPECT_EQ(SDCH_OK, sdch_manager()->GetVcdiffDictionary( 241 SdchProblemCode problem_code;
249 server_hash, target_url, &dictionary)); 242 scoped_ptr<SdchManager::DictionarySet> dict_set(
250 EXPECT_TRUE(dictionary.get() != NULL); 243 sdch_manager()->GetDictionarySetByHash(
244 target_url, server_hash, &problem_code));
245 EXPECT_EQ(SDCH_OK, problem_code);
246 EXPECT_TRUE(dict_set.get());
247 EXPECT_TRUE(dict_set->GetDictionary(server_hash));
251 } 248 }
252 249
253 TEST_F(SdchManagerTest, CanNotUseHTTPDictionaryOverHTTPS) { 250 TEST_F(SdchManagerTest, CanNotUseHTTPDictionaryOverHTTPS) {
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 EXPECT_TRUE(AddSdchDictionary(dictionary_text, 254 EXPECT_TRUE(AddSdchDictionary(dictionary_text,
258 GURL("http://" + dictionary_domain))); 255 GURL("http://" + dictionary_domain)));
259 256
260 GURL target_url("https://" + dictionary_domain + "/test"); 257 GURL target_url("https://" + dictionary_domain + "/test");
261 std::string dictionary_list;
262 // HTTPS target URL should not advertise dictionary acquired over HTTP even if 258 // HTTPS target URL should not advertise dictionary acquired over HTTP even if
263 // secure scheme support is enabled. 259 // secure scheme support is enabled.
264 SdchManager::EnableSecureSchemeSupport(true); 260 SdchManager::EnableSecureSchemeSupport(true);
265 sdch_manager()->GetAvailDictionaryList(target_url, &dictionary_list); 261 EXPECT_FALSE(sdch_manager()->GetDictionarySet(target_url));
266 EXPECT_TRUE(dictionary_list.empty());
267 262
268 scoped_refptr<SdchManager::Dictionary> dictionary;
269 std::string client_hash; 263 std::string client_hash;
270 std::string server_hash; 264 std::string server_hash;
271 sdch_manager()->GenerateHash(dictionary_text, &client_hash, &server_hash); 265 sdch_manager()->GenerateHash(dictionary_text, &client_hash, &server_hash);
272 EXPECT_EQ(SDCH_DICTIONARY_FOUND_HAS_WRONG_SCHEME, 266 SdchProblemCode problem_code;
273 sdch_manager()->GetVcdiffDictionary(server_hash, target_url, 267 scoped_ptr<SdchManager::DictionarySet> dict_set(
274 &dictionary)); 268 sdch_manager()->GetDictionarySetByHash(
275 EXPECT_TRUE(dictionary.get() == NULL); 269 target_url, server_hash, &problem_code));
270 EXPECT_FALSE(dict_set.get());
271 EXPECT_EQ(SDCH_DICTIONARY_FOUND_HAS_WRONG_SCHEME, problem_code);
276 } 272 }
277 273
278 TEST_F(SdchManagerTest, CanNotUseHTTPSDictionaryOverHTTP) { 274 TEST_F(SdchManagerTest, CanNotUseHTTPSDictionaryOverHTTP) {
279 std::string dictionary_domain("x.y.z.google.com"); 275 std::string dictionary_domain("x.y.z.google.com");
280 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); 276 std::string dictionary_text(NewSdchDictionary(dictionary_domain));
281 277
282 SdchManager::EnableSecureSchemeSupport(true); 278 SdchManager::EnableSecureSchemeSupport(true);
283 EXPECT_TRUE(AddSdchDictionary(dictionary_text, 279 EXPECT_TRUE(AddSdchDictionary(dictionary_text,
284 GURL("https://" + dictionary_domain))); 280 GURL("https://" + dictionary_domain)));
285 281
286 GURL target_url("http://" + dictionary_domain + "/test"); 282 GURL target_url("http://" + dictionary_domain + "/test");
287 std::string dictionary_list;
288 // HTTP target URL should not advertise dictionary acquired over HTTPS even if 283 // HTTP target URL should not advertise dictionary acquired over HTTPS even if
289 // secure scheme support is enabled. 284 // secure scheme support is enabled.
290 sdch_manager()->GetAvailDictionaryList(target_url, &dictionary_list); 285 EXPECT_FALSE(sdch_manager()->GetDictionarySet(target_url));
291 EXPECT_TRUE(dictionary_list.empty());
292 286
293 scoped_refptr<SdchManager::Dictionary> dictionary;
294 std::string client_hash; 287 std::string client_hash;
295 std::string server_hash; 288 std::string server_hash;
296 sdch_manager()->GenerateHash(dictionary_text, &client_hash, &server_hash); 289 sdch_manager()->GenerateHash(dictionary_text, &client_hash, &server_hash);
297 EXPECT_EQ(SDCH_DICTIONARY_FOUND_HAS_WRONG_SCHEME, 290 SdchProblemCode problem_code;
298 sdch_manager()->GetVcdiffDictionary(server_hash, target_url, 291 scoped_ptr<SdchManager::DictionarySet> dict_set(
299 &dictionary)); 292 sdch_manager()->GetDictionarySetByHash(
300 EXPECT_TRUE(dictionary.get() == NULL); 293 target_url, server_hash, &problem_code));
294 EXPECT_FALSE(dict_set.get());
295 EXPECT_EQ(SDCH_DICTIONARY_FOUND_HAS_WRONG_SCHEME, problem_code);
301 } 296 }
302 297
303 TEST_F(SdchManagerTest, FailToSetDomainMismatchDictionary) { 298 TEST_F(SdchManagerTest, FailToSetDomainMismatchDictionary) {
304 std::string dictionary_domain("x.y.z.google.com"); 299 std::string dictionary_domain("x.y.z.google.com");
305 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); 300 std::string dictionary_text(NewSdchDictionary(dictionary_domain));
306 301
307 // Fail the "domain match" requirement. 302 // Fail the "domain match" requirement.
308 EXPECT_FALSE(AddSdchDictionary(dictionary_text, 303 EXPECT_FALSE(AddSdchDictionary(dictionary_text,
309 GURL("http://y.z.google.com"))); 304 GURL("http://y.z.google.com")));
310 } 305 }
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 } 426 }
432 427
433 TEST_F(SdchManagerTest, PathMatch) { 428 TEST_F(SdchManagerTest, PathMatch) {
434 bool (*PathMatch)(const std::string& path, const std::string& restriction) = 429 bool (*PathMatch)(const std::string& path, const std::string& restriction) =
435 SdchManager::Dictionary::PathMatch; 430 SdchManager::Dictionary::PathMatch;
436 // Perfect match is supported. 431 // Perfect match is supported.
437 EXPECT_TRUE(PathMatch("/search", "/search")); 432 EXPECT_TRUE(PathMatch("/search", "/search"));
438 EXPECT_TRUE(PathMatch("/search/", "/search/")); 433 EXPECT_TRUE(PathMatch("/search/", "/search/"));
439 434
440 // Prefix only works if last character of restriction is a slash, or first 435 // Prefix only works if last character of restriction is a slash, or first
441 // character in path after a match is a slash. Validate each case separately. 436 // character in path after a match is a slash. Validate each case separately.
442 437
443 // Rely on the slash in the path (not at the end of the restriction). 438 // Rely on the slash in the path (not at the end of the restriction).
444 EXPECT_TRUE(PathMatch("/search/something", "/search")); 439 EXPECT_TRUE(PathMatch("/search/something", "/search"));
445 EXPECT_TRUE(PathMatch("/search/s", "/search")); 440 EXPECT_TRUE(PathMatch("/search/s", "/search"));
446 EXPECT_TRUE(PathMatch("/search/other", "/search")); 441 EXPECT_TRUE(PathMatch("/search/other", "/search"));
447 EXPECT_TRUE(PathMatch("/search/something", "/search")); 442 EXPECT_TRUE(PathMatch("/search/something", "/search"));
448 443
449 // Rely on the slash at the end of the restriction. 444 // Rely on the slash at the end of the restriction.
450 EXPECT_TRUE(PathMatch("/search/something", "/search/")); 445 EXPECT_TRUE(PathMatch("/search/something", "/search/"));
451 EXPECT_TRUE(PathMatch("/search/s", "/search/")); 446 EXPECT_TRUE(PathMatch("/search/s", "/search/"));
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 std::string server_hash_1; 507 std::string server_hash_1;
513 std::string server_hash_2; 508 std::string server_hash_2;
514 509
515 SdchManager::GenerateHash(dictionary_text_1, &tmp_hash, &server_hash_1); 510 SdchManager::GenerateHash(dictionary_text_1, &tmp_hash, &server_hash_1);
516 SdchManager::GenerateHash(dictionary_text_2, &tmp_hash, &server_hash_2); 511 SdchManager::GenerateHash(dictionary_text_2, &tmp_hash, &server_hash_2);
517 512
518 // Confirm that if you add directories to one manager, you 513 // Confirm that if you add directories to one manager, you
519 // can't get them from the other. 514 // can't get them from the other.
520 EXPECT_TRUE(AddSdchDictionary(dictionary_text_1, 515 EXPECT_TRUE(AddSdchDictionary(dictionary_text_1,
521 GURL("http://" + dictionary_domain_1))); 516 GURL("http://" + dictionary_domain_1)));
522 scoped_refptr<SdchManager::Dictionary> dictionary; 517 scoped_ptr<SdchManager::DictionarySet> dict_set;
523 EXPECT_EQ(SDCH_OK, sdch_manager()->GetVcdiffDictionary( 518
524 server_hash_1, 519 SdchProblemCode problem_code;
525 GURL("http://" + dictionary_domain_1 + "/random_url"), 520 dict_set = sdch_manager()->GetDictionarySetByHash(
526 &dictionary)); 521 GURL("http://" + dictionary_domain_1 + "/random_url"),
527 EXPECT_TRUE(dictionary.get()); 522 server_hash_1, &problem_code);
523 EXPECT_TRUE(dict_set);
524 EXPECT_TRUE(dict_set->GetDictionary(server_hash_1));
525 EXPECT_EQ(SDCH_OK, problem_code);
528 526
529 second_manager.AddSdchDictionary( 527 second_manager.AddSdchDictionary(
530 dictionary_text_2, GURL("http://" + dictionary_domain_2)); 528 dictionary_text_2, GURL("http://" + dictionary_domain_2));
531 second_manager.GetVcdiffDictionary( 529 dict_set = second_manager.GetDictionarySetByHash(
532 server_hash_2,
533 GURL("http://" + dictionary_domain_2 + "/random_url"), 530 GURL("http://" + dictionary_domain_2 + "/random_url"),
534 &dictionary); 531 server_hash_2, &problem_code);
535 EXPECT_TRUE(dictionary.get()); 532 EXPECT_TRUE(dict_set);
533 EXPECT_TRUE(dict_set->GetDictionary(server_hash_2));
534 EXPECT_EQ(SDCH_OK, problem_code);
536 535
537 EXPECT_EQ( 536 dict_set = sdch_manager()->GetDictionarySetByHash(
538 SDCH_DICTIONARY_HASH_NOT_FOUND, 537 GURL("http://" + dictionary_domain_2 + "/random_url"),
539 sdch_manager()->GetVcdiffDictionary( 538 server_hash_2, &problem_code);
540 server_hash_2, GURL("http://" + dictionary_domain_2 + "/random_url"), 539 EXPECT_FALSE(dict_set);
541 &dictionary)); 540 EXPECT_EQ(SDCH_DICTIONARY_HASH_NOT_FOUND, problem_code);
542 EXPECT_FALSE(dictionary.get());
543 541
544 EXPECT_EQ( 542 dict_set = second_manager.GetDictionarySetByHash(
545 SDCH_DICTIONARY_HASH_NOT_FOUND, 543 GURL("http://" + dictionary_domain_1 + "/random_url"),
546 second_manager.GetVcdiffDictionary( 544 server_hash_1, &problem_code);
547 server_hash_1, GURL("http://" + dictionary_domain_1 + "/random_url"), 545 EXPECT_FALSE(dict_set);
548 &dictionary)); 546 EXPECT_EQ(SDCH_DICTIONARY_HASH_NOT_FOUND, problem_code);
549 EXPECT_FALSE(dictionary.get());
550 } 547 }
551 548
552 TEST_F(SdchManagerTest, HttpsCorrectlySupported) { 549 TEST_F(SdchManagerTest, HttpsCorrectlySupported) {
553 GURL url("http://www.google.com"); 550 GURL url("http://www.google.com");
554 GURL secure_url("https://www.google.com"); 551 GURL secure_url("https://www.google.com");
555 552
556 bool expect_https_support = true; 553 bool expect_https_support = true;
557 554
558 SdchProblemCode expected_code = 555 SdchProblemCode expected_code =
559 expect_https_support ? SDCH_OK : SDCH_SECURE_SCHEME_NOT_SUPPORTED; 556 expect_https_support ? SDCH_OK : SDCH_SECURE_SCHEME_NOT_SUPPORTED;
(...skipping 11 matching lines...) Expand all
571 GURL blacklist_url("http://bad.chromium.org"); 568 GURL blacklist_url("http://bad.chromium.org");
572 569
573 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); 570 std::string dictionary_text(NewSdchDictionary(dictionary_domain));
574 std::string tmp_hash; 571 std::string tmp_hash;
575 std::string server_hash; 572 std::string server_hash;
576 573
577 SdchManager::GenerateHash(dictionary_text, &tmp_hash, &server_hash); 574 SdchManager::GenerateHash(dictionary_text, &tmp_hash, &server_hash);
578 575
579 EXPECT_TRUE(AddSdchDictionary(dictionary_text, 576 EXPECT_TRUE(AddSdchDictionary(dictionary_text,
580 GURL("http://" + dictionary_domain))); 577 GURL("http://" + dictionary_domain)));
581 scoped_refptr<SdchManager::Dictionary> dictionary; 578
582 EXPECT_EQ(SDCH_OK, sdch_manager()->GetVcdiffDictionary( 579 scoped_ptr<SdchManager::DictionarySet> dict_set;
583 server_hash, 580
584 GURL("http://" + dictionary_domain + "/random_url"), 581 SdchProblemCode problem_code;
585 &dictionary)); 582 dict_set = sdch_manager()->GetDictionarySetByHash(
586 EXPECT_TRUE(dictionary.get()); 583 GURL("http://" + dictionary_domain + "/random_url"),
584 server_hash, &problem_code);
585 EXPECT_TRUE(dict_set);
586 EXPECT_TRUE(dict_set->GetDictionary(server_hash));
587 EXPECT_EQ(SDCH_OK, problem_code);
587 588
588 sdch_manager()->BlacklistDomain(GURL(blacklist_url), SDCH_OK); 589 sdch_manager()->BlacklistDomain(GURL(blacklist_url), SDCH_OK);
589 EXPECT_EQ(SDCH_DOMAIN_BLACKLIST_INCLUDES_TARGET, 590 EXPECT_EQ(SDCH_DOMAIN_BLACKLIST_INCLUDES_TARGET,
590 sdch_manager()->IsInSupportedDomain(blacklist_url)); 591 sdch_manager()->IsInSupportedDomain(blacklist_url));
591 592
592 sdch_manager()->ClearData(); 593 sdch_manager()->ClearData();
593 594
594 dictionary = NULL; 595 dict_set = sdch_manager()->GetDictionarySetByHash(
595 EXPECT_EQ( 596 GURL("http://" + dictionary_domain + "/random_url"),
596 SDCH_DICTIONARY_HASH_NOT_FOUND, 597 server_hash, &problem_code);
597 sdch_manager()->GetVcdiffDictionary( 598 EXPECT_FALSE(dict_set);
598 server_hash, GURL("http://" + dictionary_domain + "/random_url"), 599 EXPECT_EQ(SDCH_DICTIONARY_HASH_NOT_FOUND, problem_code);
599 &dictionary));
600 EXPECT_FALSE(dictionary.get());
601 EXPECT_EQ(SDCH_OK, sdch_manager()->IsInSupportedDomain(blacklist_url)); 600 EXPECT_EQ(SDCH_OK, sdch_manager()->IsInSupportedDomain(blacklist_url));
602 } 601 }
603 602
604 TEST_F(SdchManagerTest, GetDictionaryNotification) { 603 TEST_F(SdchManagerTest, GetDictionaryNotification) {
605 GURL test_request_gurl(GURL("http://www.example.com/data")); 604 GURL test_request_gurl(GURL("http://www.example.com/data"));
606 GURL test_dictionary_gurl(GURL("http://www.example.com/dict")); 605 GURL test_dictionary_gurl(GURL("http://www.example.com/dict"));
607 MockSdchObserver observer; 606 MockSdchObserver observer;
608 sdch_manager()->AddObserver(&observer); 607 sdch_manager()->AddObserver(&observer);
609 608
610 EXPECT_EQ(0, observer.get_dictionary_notifications()); 609 EXPECT_EQ(0, observer.get_dictionary_notifications());
611 sdch_manager()->OnGetDictionary(test_request_gurl, test_dictionary_gurl); 610 sdch_manager()->OnGetDictionary(test_request_gurl, test_dictionary_gurl);
612 EXPECT_EQ(1, observer.get_dictionary_notifications()); 611 EXPECT_EQ(1, observer.get_dictionary_notifications());
613 EXPECT_EQ(test_request_gurl, observer.last_dictionary_request_url()); 612 EXPECT_EQ(test_request_gurl, observer.last_dictionary_request_url());
614 EXPECT_EQ(test_dictionary_gurl, observer.last_dictionary_url()); 613 EXPECT_EQ(test_dictionary_gurl, observer.last_dictionary_url());
615 614
616 sdch_manager()->RemoveObserver(&observer); 615 sdch_manager()->RemoveObserver(&observer);
617 sdch_manager()->OnGetDictionary(test_request_gurl, test_dictionary_gurl); 616 sdch_manager()->OnGetDictionary(test_request_gurl, test_dictionary_gurl);
618 EXPECT_EQ(1, observer.get_dictionary_notifications()); 617 EXPECT_EQ(1, observer.get_dictionary_notifications());
619 EXPECT_EQ(test_request_gurl, observer.last_dictionary_request_url()); 618 EXPECT_EQ(test_request_gurl, observer.last_dictionary_request_url());
620 EXPECT_EQ(test_dictionary_gurl, observer.last_dictionary_url()); 619 EXPECT_EQ(test_dictionary_gurl, observer.last_dictionary_url());
621 } 620 }
622 621
622 TEST_F(SdchManagerTest, ExpirationCheckedProperly) {
623 // Create an SDCH dictionary with an expiration time in the past.
624 std::string dictionary_domain("x.y.z.google.com");
625 std::string dictionary_text(base::StringPrintf(
626 "Domain: %s\nMax-age: 0\n\n", dictionary_domain.c_str()));
627 dictionary_text.append(
628 kTestVcdiffDictionary, sizeof(kTestVcdiffDictionary) - 1);
629 std::string client_hash;
630 std::string server_hash;
631 SdchManager::GenerateHash(dictionary_text, &client_hash, &server_hash);
632 GURL target_gurl("http://" + dictionary_domain);
633 AddSdchDictionary(dictionary_text, target_gurl);
634
635 // It should be visible if looked up by hash whether expired or not.
636 scoped_ptr<base::SimpleTestClock> clock(new base::SimpleTestClock);
637 clock->SetNow(base::Time::Now());
638 clock->Advance(base::TimeDelta::FromMinutes(5));
639 SdchProblemCode problem_code;
640 scoped_ptr<SdchManager::DictionarySet> hash_set(
641 sdch_manager()->GetDictionarySetByHash(
642 target_gurl, server_hash, &problem_code).Pass());
643 ASSERT_TRUE(hash_set);
644 ASSERT_EQ(SDCH_OK, problem_code);
645 const_cast<SdchManager::Dictionary*>(
646 hash_set->GetDictionary(server_hash))->SetClockForTesting(
647 clock.Pass());
648
649 // Make sure it's not visible for advertisement, but is visible
650 // if looked up by hash.
651 EXPECT_FALSE(sdch_manager()->GetDictionarySet(target_gurl));
652 EXPECT_TRUE(sdch_manager()->GetDictionarySetByHash(
653 target_gurl, server_hash, &problem_code));
654 EXPECT_EQ(SDCH_OK, problem_code);
655 }
656
623 } // namespace net 657 } // namespace net
OLDNEW
« no previous file with comments | « net/base/sdch_manager.cc ('k') | net/base/sdch_problem_code_list.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698