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

Side by Side Diff: net/cookies/cookie_monster_unittest.cc

Issue 1378273003: Decouple CookieMonsterTest from CookieStoreTest. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Moved (and renamed) URLHelper into own class/file Created 5 years, 2 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
« no previous file with comments | « no previous file | net/cookies/cookie_store_test_helpers.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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "net/cookies/cookie_store_unittest.h" 5 #include "net/cookies/cookie_store_unittest.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 63
64 private: 64 private:
65 virtual ~NewMockPersistentCookieStore() {} 65 virtual ~NewMockPersistentCookieStore() {}
66 }; 66 };
67 67
68 const char kTopLevelDomainPlus1[] = "http://www.harvard.edu"; 68 const char kTopLevelDomainPlus1[] = "http://www.harvard.edu";
69 const char kTopLevelDomainPlus2[] = "http://www.math.harvard.edu"; 69 const char kTopLevelDomainPlus2[] = "http://www.math.harvard.edu";
70 const char kTopLevelDomainPlus2Secure[] = "https://www.math.harvard.edu"; 70 const char kTopLevelDomainPlus2Secure[] = "https://www.math.harvard.edu";
71 const char kTopLevelDomainPlus3[] = "http://www.bourbaki.math.harvard.edu"; 71 const char kTopLevelDomainPlus3[] = "http://www.bourbaki.math.harvard.edu";
72 const char kOtherDomain[] = "http://www.mit.edu"; 72 const char kOtherDomain[] = "http://www.mit.edu";
73 const char kUrlGoogleSpecific[] = "http://www.gmail.google.izzle";
74 73
75 class GetCookieListCallback : public CookieCallback { 74 class GetCookieListCallback : public CookieCallback {
76 public: 75 public:
77 GetCookieListCallback() {} 76 GetCookieListCallback() {}
78 explicit GetCookieListCallback(Thread* run_in_thread) 77 explicit GetCookieListCallback(Thread* run_in_thread)
79 : CookieCallback(run_in_thread) {} 78 : CookieCallback(run_in_thread) {}
80 79
81 void Run(const CookieList& cookies) { 80 void Run(const CookieList& cookies) {
82 cookies_ = cookies; 81 cookies_ = cookies;
83 CallbackEpilogue(); 82 CallbackEpilogue();
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 void TestHostGarbageCollectHelper() { 351 void TestHostGarbageCollectHelper() {
353 int domain_max_cookies = CookieMonster::kDomainMaxCookies; 352 int domain_max_cookies = CookieMonster::kDomainMaxCookies;
354 int domain_purge_cookies = CookieMonster::kDomainPurgeCookies; 353 int domain_purge_cookies = CookieMonster::kDomainPurgeCookies;
355 const int more_than_enough_cookies = 354 const int more_than_enough_cookies =
356 (domain_max_cookies + domain_purge_cookies) * 2; 355 (domain_max_cookies + domain_purge_cookies) * 2;
357 // Add a bunch of cookies on a single host, should purge them. 356 // Add a bunch of cookies on a single host, should purge them.
358 { 357 {
359 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); 358 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
360 for (int i = 0; i < more_than_enough_cookies; ++i) { 359 for (int i = 0; i < more_than_enough_cookies; ++i) {
361 std::string cookie = base::StringPrintf("a%03d=b", i); 360 std::string cookie = base::StringPrintf("a%03d=b", i);
362 EXPECT_TRUE(SetCookie(cm.get(), url_google_, cookie)); 361 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), cookie));
363 std::string cookies = this->GetCookies(cm.get(), url_google_); 362 std::string cookies =
363 this->GetCookies(cm.get(), http_www_google_.url());
364 // Make sure we find it in the cookies. 364 // Make sure we find it in the cookies.
365 EXPECT_NE(cookies.find(cookie), std::string::npos); 365 EXPECT_NE(cookies.find(cookie), std::string::npos);
366 // Count the number of cookies. 366 // Count the number of cookies.
367 EXPECT_LE(CountInString(cookies, '='), domain_max_cookies); 367 EXPECT_LE(CountInString(cookies, '='), domain_max_cookies);
368 } 368 }
369 } 369 }
370 370
371 // Add a bunch of cookies on multiple hosts within a single eTLD. 371 // Add a bunch of cookies on multiple hosts within a single eTLD.
372 // Should keep at least kDomainMaxCookies - kDomainPurgeCookies 372 // Should keep at least kDomainMaxCookies - kDomainPurgeCookies
373 // between them. We shouldn't go above kDomainMaxCookies for both together. 373 // between them. We shouldn't go above kDomainMaxCookies for both together.
374 GURL url_google_specific(kUrlGoogleSpecific); 374 GURL url_google_specific(http_www_google_.Format("http://www.gmail.%D"));
375 { 375 {
376 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); 376 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
377 for (int i = 0; i < more_than_enough_cookies; ++i) { 377 for (int i = 0; i < more_than_enough_cookies; ++i) {
378 std::string cookie_general = base::StringPrintf("a%03d=b", i); 378 std::string cookie_general = base::StringPrintf("a%03d=b", i);
379 EXPECT_TRUE(SetCookie(cm.get(), url_google_, cookie_general)); 379 EXPECT_TRUE(
380 SetCookie(cm.get(), http_www_google_.url(), cookie_general));
380 std::string cookie_specific = base::StringPrintf("c%03d=b", i); 381 std::string cookie_specific = base::StringPrintf("c%03d=b", i);
381 EXPECT_TRUE(SetCookie(cm.get(), url_google_specific, cookie_specific)); 382 EXPECT_TRUE(SetCookie(cm.get(), url_google_specific, cookie_specific));
382 std::string cookies_general = this->GetCookies(cm.get(), url_google_); 383 std::string cookies_general =
384 this->GetCookies(cm.get(), http_www_google_.url());
383 EXPECT_NE(cookies_general.find(cookie_general), std::string::npos); 385 EXPECT_NE(cookies_general.find(cookie_general), std::string::npos);
384 std::string cookies_specific = 386 std::string cookies_specific =
385 this->GetCookies(cm.get(), url_google_specific); 387 this->GetCookies(cm.get(), url_google_specific);
386 EXPECT_NE(cookies_specific.find(cookie_specific), std::string::npos); 388 EXPECT_NE(cookies_specific.find(cookie_specific), std::string::npos);
387 EXPECT_LE((CountInString(cookies_general, '=') + 389 EXPECT_LE((CountInString(cookies_general, '=') +
388 CountInString(cookies_specific, '=')), 390 CountInString(cookies_specific, '=')),
389 domain_max_cookies); 391 domain_max_cookies);
390 } 392 }
391 // After all this, there should be at least 393 // After all this, there should be at least
392 // kDomainMaxCookies - kDomainPurgeCookies for both URLs. 394 // kDomainMaxCookies - kDomainPurgeCookies for both URLs.
393 std::string cookies_general = this->GetCookies(cm.get(), url_google_); 395 std::string cookies_general =
396 this->GetCookies(cm.get(), http_www_google_.url());
394 std::string cookies_specific = 397 std::string cookies_specific =
395 this->GetCookies(cm.get(), url_google_specific); 398 this->GetCookies(cm.get(), url_google_specific);
396 int total_cookies = (CountInString(cookies_general, '=') + 399 int total_cookies = (CountInString(cookies_general, '=') +
397 CountInString(cookies_specific, '=')); 400 CountInString(cookies_specific, '='));
398 EXPECT_GE(total_cookies, domain_max_cookies - domain_purge_cookies); 401 EXPECT_GE(total_cookies, domain_max_cookies - domain_purge_cookies);
399 EXPECT_LE(total_cookies, domain_max_cookies); 402 EXPECT_LE(total_cookies, domain_max_cookies);
400 } 403 }
401 } 404 }
402 405
403 CookiePriority CharToPriority(char ch) { 406 CookiePriority CharToPriority(char ch) {
404 switch (ch) { 407 switch (ch) {
405 case 'L': 408 case 'L':
406 return COOKIE_PRIORITY_LOW; 409 return COOKIE_PRIORITY_LOW;
407 case 'M': 410 case 'M':
408 return COOKIE_PRIORITY_MEDIUM; 411 return COOKIE_PRIORITY_MEDIUM;
409 case 'H': 412 case 'H':
410 return COOKIE_PRIORITY_HIGH; 413 return COOKIE_PRIORITY_HIGH;
411 } 414 }
412 NOTREACHED(); 415 NOTREACHED();
413 return COOKIE_PRIORITY_DEFAULT; 416 return COOKIE_PRIORITY_DEFAULT;
414 } 417 }
415 418
416 // Instantiates a CookieMonster, adds multiple cookies (to url_google_) with 419 // Instantiates a CookieMonster, adds multiple cookies (to http_www_google_)
417 // priorities specified by |coded_priority_str|, and tests priority-aware 420 // with priorities specified by |coded_priority_str|, and tests priority-aware
418 // domain cookie eviction. 421 // domain cookie eviction.
419 // |coded_priority_str| specifies a run-length-encoded string of priorities. 422 // |coded_priority_str| specifies a run-length-encoded string of priorities.
420 // Example: "2M 3L M 4H" means "MMLLLMHHHH", and speicifies sequential (i.e., 423 // Example: "2M 3L M 4H" means "MMLLLMHHHH", and speicifies sequential (i.e.,
421 // from least- to most-recently accessed) insertion of 2 medium-priority 424 // from least- to most-recently accessed) insertion of 2 medium-priority
422 // cookies, 3 low-priority cookies, 1 medium-priority cookie, and 4 425 // cookies, 3 low-priority cookies, 1 medium-priority cookie, and 4
423 // high-priority cookies. 426 // high-priority cookies.
424 // Within each priority, only the least-accessed cookies should be evicted. 427 // Within each priority, only the least-accessed cookies should be evicted.
425 // Thus, to describe expected suriving cookies, it suffices to specify the 428 // Thus, to describe expected suriving cookies, it suffices to specify the
426 // expected population of surviving cookies per priority, i.e., 429 // expected population of surviving cookies per priority, i.e.,
427 // |expected_low_count|, |expected_medium_count|, and |expected_high_count|. 430 // |expected_low_count|, |expected_medium_count|, and |expected_high_count|.
(...skipping 18 matching lines...) Expand all
446 // The rest of the string (possibly empty) specifies repetition. 449 // The rest of the string (possibly empty) specifies repetition.
447 int rep = 1; 450 int rep = 1;
448 if (!token.empty()) { 451 if (!token.empty()) {
449 bool result = base::StringToInt( 452 bool result = base::StringToInt(
450 base::StringPiece(token.begin(), token.end() - 1), &rep); 453 base::StringPiece(token.begin(), token.end() - 1), &rep);
451 DCHECK(result); 454 DCHECK(result);
452 } 455 }
453 for (; rep > 0; --rep, ++next_cookie_id) { 456 for (; rep > 0; --rep, ++next_cookie_id) {
454 std::string cookie = base::StringPrintf( 457 std::string cookie = base::StringPrintf(
455 "a%d=b;priority=%s", next_cookie_id, priority_str.c_str()); 458 "a%d=b;priority=%s", next_cookie_id, priority_str.c_str());
456 EXPECT_TRUE(SetCookie(cm, url_google_, cookie)); 459 EXPECT_TRUE(SetCookie(cm, http_www_google_.url(), cookie));
457 priority_list.push_back(priority); 460 priority_list.push_back(priority);
458 id_list[priority].push_back(next_cookie_id); 461 id_list[priority].push_back(next_cookie_id);
459 } 462 }
460 } 463 }
461 464
462 int num_cookies = static_cast<int>(priority_list.size()); 465 int num_cookies = static_cast<int>(priority_list.size());
463 std::vector<int> surviving_id_list[3]; // Indexed by CookiePriority. 466 std::vector<int> surviving_id_list[3]; // Indexed by CookiePriority.
464 467
465 // Parse the list of cookies 468 // Parse the list of cookies
466 std::string cookie_str = this->GetCookies(cm, url_google_); 469 std::string cookie_str = this->GetCookies(cm, http_www_google_.url());
467 for (const std::string& token : base::SplitString( 470 for (const std::string& token : base::SplitString(
468 cookie_str, ";", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) { 471 cookie_str, ";", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) {
469 // Assuming *it is "a#=b", so extract and parse "#" portion. 472 // Assuming *it is "a#=b", so extract and parse "#" portion.
470 int id = -1; 473 int id = -1;
471 bool result = base::StringToInt( 474 bool result = base::StringToInt(
472 base::StringPiece(token.begin() + 1, token.end() - 2), &id); 475 base::StringPiece(token.begin() + 1, token.end() - 2), &id);
473 DCHECK(result); 476 DCHECK(result);
474 DCHECK_GE(id, 0); 477 DCHECK_GE(id, 0);
475 DCHECK_LT(id, num_cookies); 478 DCHECK_LT(id, num_cookies);
476 surviving_id_list[priority_list[id]].push_back(id); 479 surviving_id_list[priority_list[id]].push_back(id);
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
809 std::queue<CookieMonster::PersistentCookieStore::LoadedCallback> 812 std::queue<CookieMonster::PersistentCookieStore::LoadedCallback>
810 loaded_for_key_callbacks_; 813 loaded_for_key_callbacks_;
811 814
812 // Stores the CookieMonster under test. 815 // Stores the CookieMonster under test.
813 scoped_refptr<CookieMonster> cookie_monster_; 816 scoped_refptr<CookieMonster> cookie_monster_;
814 // Stores the mock PersistentCookieStore. 817 // Stores the mock PersistentCookieStore.
815 scoped_refptr<NewMockPersistentCookieStore> persistent_store_; 818 scoped_refptr<NewMockPersistentCookieStore> persistent_store_;
816 }; 819 };
817 820
818 TEST_F(DeferredCookieTaskTest, DeferredGetCookies) { 821 TEST_F(DeferredCookieTaskTest, DeferredGetCookies) {
819 DeclareLoadedCookie("www.google.izzle", 822 DeclareLoadedCookie(http_www_google_.host(),
820 "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", 823 "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT",
821 Time::Now() + TimeDelta::FromDays(3)); 824 Time::Now() + TimeDelta::FromDays(3));
822 825
823 MockGetCookiesCallback get_cookies_callback; 826 MockGetCookiesCallback get_cookies_callback;
824 827
825 BeginWithForDomainKey( 828 BeginWithForDomainKey(
826 "google.izzle", 829 http_www_google_.domain(),
827 GetCookiesAction(&cookie_monster(), url_google_, &get_cookies_callback)); 830 GetCookiesAction(&cookie_monster(), http_www_google_.url(),
831 &get_cookies_callback));
828 832
829 WaitForLoadCall(); 833 WaitForLoadCall();
830 834
831 EXPECT_CALL(get_cookies_callback, Invoke("X=1")) 835 EXPECT_CALL(get_cookies_callback, Invoke("X=1"))
832 .WillOnce(GetCookiesAction(&cookie_monster(), url_google_, 836 .WillOnce(GetCookiesAction(&cookie_monster(), http_www_google_.url(),
833 &get_cookies_callback)); 837 &get_cookies_callback));
834 EXPECT_CALL(get_cookies_callback, Invoke("X=1")) 838 EXPECT_CALL(get_cookies_callback, Invoke("X=1"))
835 .WillOnce(QuitCurrentMessageLoop()); 839 .WillOnce(QuitCurrentMessageLoop());
836 840
837 CompleteLoadingAndWait(); 841 CompleteLoadingAndWait();
838 } 842 }
839 843
840 TEST_F(DeferredCookieTaskTest, DeferredSetCookie) { 844 TEST_F(DeferredCookieTaskTest, DeferredSetCookie) {
841 MockSetCookiesCallback set_cookies_callback; 845 MockSetCookiesCallback set_cookies_callback;
842 846
843 BeginWithForDomainKey("google.izzle", 847 BeginWithForDomainKey(
844 SetCookieAction(&cookie_monster(), url_google_, "A=B", 848 http_www_google_.domain(),
845 &set_cookies_callback)); 849 SetCookieAction(&cookie_monster(), http_www_google_.url(), "A=B",
850 &set_cookies_callback));
846 851
847 WaitForLoadCall(); 852 WaitForLoadCall();
848 853
849 EXPECT_CALL(set_cookies_callback, Invoke(true)) 854 EXPECT_CALL(set_cookies_callback, Invoke(true))
850 .WillOnce(SetCookieAction(&cookie_monster(), url_google_, "X=Y", 855 .WillOnce(SetCookieAction(&cookie_monster(), http_www_google_.url(),
851 &set_cookies_callback)); 856 "X=Y", &set_cookies_callback));
852 EXPECT_CALL(set_cookies_callback, Invoke(true)) 857 EXPECT_CALL(set_cookies_callback, Invoke(true))
853 .WillOnce(QuitCurrentMessageLoop()); 858 .WillOnce(QuitCurrentMessageLoop());
854 859
855 CompleteLoadingAndWait(); 860 CompleteLoadingAndWait();
856 } 861 }
857 862
858 TEST_F(DeferredCookieTaskTest, DeferredSetAllCookies) { 863 TEST_F(DeferredCookieTaskTest, DeferredSetAllCookies) {
859 MockSetCookiesCallback set_cookies_callback; 864 MockSetCookiesCallback set_cookies_callback;
860 CookieList list; 865 CookieList list;
861 list.push_back(CanonicalCookie(url_google_, "A", "B", "google.izzle", "/", 866 list.push_back(CanonicalCookie(http_www_google_.url(), "A", "B",
867 http_www_google_.domain(), "/",
862 base::Time::Now(), base::Time(), base::Time(), 868 base::Time::Now(), base::Time(), base::Time(),
863 false, true, false, COOKIE_PRIORITY_DEFAULT)); 869 false, true, false, COOKIE_PRIORITY_DEFAULT));
864 list.push_back(CanonicalCookie(url_google_, "C", "D", "google.izzle", "/", 870 list.push_back(CanonicalCookie(http_www_google_.url(), "C", "D",
871 http_www_google_.domain(), "/",
865 base::Time::Now(), base::Time(), base::Time(), 872 base::Time::Now(), base::Time(), base::Time(),
866 false, true, false, COOKIE_PRIORITY_DEFAULT)); 873 false, true, false, COOKIE_PRIORITY_DEFAULT));
867 874
868 BeginWith( 875 BeginWith(
869 SetAllCookiesAction(&cookie_monster(), list, &set_cookies_callback)); 876 SetAllCookiesAction(&cookie_monster(), list, &set_cookies_callback));
870 877
871 WaitForLoadCall(); 878 WaitForLoadCall();
872 879
873 EXPECT_CALL(set_cookies_callback, Invoke(true)) 880 EXPECT_CALL(set_cookies_callback, Invoke(true))
874 .WillOnce( 881 .WillOnce(
875 SetAllCookiesAction(&cookie_monster(), list, &set_cookies_callback)); 882 SetAllCookiesAction(&cookie_monster(), list, &set_cookies_callback));
876 EXPECT_CALL(set_cookies_callback, Invoke(true)) 883 EXPECT_CALL(set_cookies_callback, Invoke(true))
877 .WillOnce(QuitCurrentMessageLoop()); 884 .WillOnce(QuitCurrentMessageLoop());
878 885
879 CompleteLoadingAndWait(); 886 CompleteLoadingAndWait();
880 } 887 }
881 888
882 TEST_F(DeferredCookieTaskTest, DeferredDeleteCookie) { 889 TEST_F(DeferredCookieTaskTest, DeferredDeleteCookie) {
883 MockClosure delete_cookie_callback; 890 MockClosure delete_cookie_callback;
884 891
885 BeginWithForDomainKey("google.izzle", 892 BeginWithForDomainKey(
886 DeleteCookieAction(&cookie_monster(), url_google_, "A", 893 http_www_google_.domain(),
887 &delete_cookie_callback)); 894 DeleteCookieAction(&cookie_monster(), http_www_google_.url(), "A",
895 &delete_cookie_callback));
888 896
889 WaitForLoadCall(); 897 WaitForLoadCall();
890 898
891 EXPECT_CALL(delete_cookie_callback, Invoke()) 899 EXPECT_CALL(delete_cookie_callback, Invoke())
892 .WillOnce(DeleteCookieAction(&cookie_monster(), url_google_, "X", 900 .WillOnce(DeleteCookieAction(&cookie_monster(), http_www_google_.url(),
893 &delete_cookie_callback)); 901 "X", &delete_cookie_callback));
894 EXPECT_CALL(delete_cookie_callback, Invoke()) 902 EXPECT_CALL(delete_cookie_callback, Invoke())
895 .WillOnce(QuitCurrentMessageLoop()); 903 .WillOnce(QuitCurrentMessageLoop());
896 904
897 CompleteLoadingAndWait(); 905 CompleteLoadingAndWait();
898 } 906 }
899 907
900 TEST_F(DeferredCookieTaskTest, DeferredSetCookieWithDetails) { 908 TEST_F(DeferredCookieTaskTest, DeferredSetCookieWithDetails) {
901 MockSetCookiesCallback set_cookies_callback; 909 MockSetCookiesCallback set_cookies_callback;
902 910
903 CookiesInputInfo cookie_info = {url_google_foo_, 911 CookiesInputInfo cookie_info = {www_google_foo_.url(),
904 "A", 912 "A",
905 "B", 913 "B",
906 std::string(), 914 std::string(),
907 "/foo", 915 "/foo",
908 base::Time(), 916 base::Time(),
909 false, 917 false,
910 false, 918 false,
911 false, 919 false,
912 COOKIE_PRIORITY_DEFAULT}; 920 COOKIE_PRIORITY_DEFAULT};
913 BeginWithForDomainKey( 921 BeginWithForDomainKey(
914 "google.izzle", SetCookieWithDetailsAction(&cookie_monster(), cookie_info, 922 http_www_google_.domain(),
915 &set_cookies_callback)); 923 SetCookieWithDetailsAction(&cookie_monster(), cookie_info,
924 &set_cookies_callback));
916 925
917 WaitForLoadCall(); 926 WaitForLoadCall();
918 927
919 CookiesInputInfo cookie_info_exp = {url_google_foo_, 928 CookiesInputInfo cookie_info_exp = {www_google_foo_.url(),
920 "A", 929 "A",
921 "B", 930 "B",
922 std::string(), 931 std::string(),
923 "/foo", 932 "/foo",
924 base::Time(), 933 base::Time(),
925 false, 934 false,
926 false, 935 false,
927 false, 936 false,
928 COOKIE_PRIORITY_DEFAULT}; 937 COOKIE_PRIORITY_DEFAULT};
929 EXPECT_CALL(set_cookies_callback, Invoke(true)) 938 EXPECT_CALL(set_cookies_callback, Invoke(true))
930 .WillOnce(SetCookieWithDetailsAction(&cookie_monster(), cookie_info_exp, 939 .WillOnce(SetCookieWithDetailsAction(&cookie_monster(), cookie_info_exp,
931 &set_cookies_callback)); 940 &set_cookies_callback));
932 EXPECT_CALL(set_cookies_callback, Invoke(true)) 941 EXPECT_CALL(set_cookies_callback, Invoke(true))
933 .WillOnce(QuitCurrentMessageLoop()); 942 .WillOnce(QuitCurrentMessageLoop());
934 943
935 CompleteLoadingAndWait(); 944 CompleteLoadingAndWait();
936 } 945 }
937 946
938 TEST_F(DeferredCookieTaskTest, DeferredGetAllCookies) { 947 TEST_F(DeferredCookieTaskTest, DeferredGetAllCookies) {
939 DeclareLoadedCookie("www.google.izzle", 948 DeclareLoadedCookie(http_www_google_.host(),
940 "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", 949 "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT",
941 Time::Now() + TimeDelta::FromDays(3)); 950 Time::Now() + TimeDelta::FromDays(3));
942 951
943 MockGetCookieListCallback get_cookie_list_callback; 952 MockGetCookieListCallback get_cookie_list_callback;
944 953
945 BeginWith(GetAllCookiesAction(&cookie_monster(), &get_cookie_list_callback)); 954 BeginWith(GetAllCookiesAction(&cookie_monster(), &get_cookie_list_callback));
946 955
947 WaitForLoadCall(); 956 WaitForLoadCall();
948 957
949 EXPECT_CALL(get_cookie_list_callback, Invoke(testing::_)) 958 EXPECT_CALL(get_cookie_list_callback, Invoke(testing::_))
950 .WillOnce( 959 .WillOnce(
951 GetAllCookiesAction(&cookie_monster(), &get_cookie_list_callback)); 960 GetAllCookiesAction(&cookie_monster(), &get_cookie_list_callback));
952 EXPECT_CALL(get_cookie_list_callback, Invoke(testing::_)) 961 EXPECT_CALL(get_cookie_list_callback, Invoke(testing::_))
953 .WillOnce(QuitCurrentMessageLoop()); 962 .WillOnce(QuitCurrentMessageLoop());
954 963
955 CompleteLoadingAndWait(); 964 CompleteLoadingAndWait();
956 } 965 }
957 966
958 TEST_F(DeferredCookieTaskTest, DeferredGetAllForUrlCookies) { 967 TEST_F(DeferredCookieTaskTest, DeferredGetAllForUrlCookies) {
959 DeclareLoadedCookie("www.google.izzle", 968 DeclareLoadedCookie(http_www_google_.host(),
960 "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", 969 "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT",
961 Time::Now() + TimeDelta::FromDays(3)); 970 Time::Now() + TimeDelta::FromDays(3));
962 971
963 MockGetCookieListCallback get_cookie_list_callback; 972 MockGetCookieListCallback get_cookie_list_callback;
964 973
965 BeginWithForDomainKey( 974 BeginWithForDomainKey(
966 "google.izzle", GetAllCookiesForUrlAction(&cookie_monster(), url_google_, 975 http_www_google_.domain(),
967 &get_cookie_list_callback)); 976 GetAllCookiesForUrlAction(&cookie_monster(), http_www_google_.url(),
977 &get_cookie_list_callback));
968 978
969 WaitForLoadCall(); 979 WaitForLoadCall();
970 980
971 EXPECT_CALL(get_cookie_list_callback, Invoke(testing::_)) 981 EXPECT_CALL(get_cookie_list_callback, Invoke(testing::_))
972 .WillOnce(GetAllCookiesForUrlAction(&cookie_monster(), url_google_, 982 .WillOnce(GetAllCookiesForUrlAction(&cookie_monster(),
983 http_www_google_.url(),
973 &get_cookie_list_callback)); 984 &get_cookie_list_callback));
974 EXPECT_CALL(get_cookie_list_callback, Invoke(testing::_)) 985 EXPECT_CALL(get_cookie_list_callback, Invoke(testing::_))
975 .WillOnce(QuitCurrentMessageLoop()); 986 .WillOnce(QuitCurrentMessageLoop());
976 987
977 CompleteLoadingAndWait(); 988 CompleteLoadingAndWait();
978 } 989 }
979 990
980 TEST_F(DeferredCookieTaskTest, DeferredGetAllForUrlWithOptionsCookies) { 991 TEST_F(DeferredCookieTaskTest, DeferredGetAllForUrlWithOptionsCookies) {
981 DeclareLoadedCookie("www.google.izzle", 992 DeclareLoadedCookie(http_www_google_.host(),
982 "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", 993 "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT",
983 Time::Now() + TimeDelta::FromDays(3)); 994 Time::Now() + TimeDelta::FromDays(3));
984 995
985 MockGetCookieListCallback get_cookie_list_callback; 996 MockGetCookieListCallback get_cookie_list_callback;
986 997
987 BeginWithForDomainKey("google.izzle", GetAllCookiesForUrlWithOptionsAction( 998 BeginWithForDomainKey(http_www_google_.domain(),
988 &cookie_monster(), url_google_, 999 GetAllCookiesForUrlWithOptionsAction(
989 &get_cookie_list_callback)); 1000 &cookie_monster(), http_www_google_.url(),
1001 &get_cookie_list_callback));
990 1002
991 WaitForLoadCall(); 1003 WaitForLoadCall();
992 1004
993 EXPECT_CALL(get_cookie_list_callback, Invoke(testing::_)) 1005 EXPECT_CALL(get_cookie_list_callback, Invoke(testing::_))
994 .WillOnce(GetAllCookiesForUrlWithOptionsAction( 1006 .WillOnce(GetAllCookiesForUrlWithOptionsAction(
995 &cookie_monster(), url_google_, &get_cookie_list_callback)); 1007 &cookie_monster(), http_www_google_.url(),
1008 &get_cookie_list_callback));
996 EXPECT_CALL(get_cookie_list_callback, Invoke(testing::_)) 1009 EXPECT_CALL(get_cookie_list_callback, Invoke(testing::_))
997 .WillOnce(QuitCurrentMessageLoop()); 1010 .WillOnce(QuitCurrentMessageLoop());
998 1011
999 CompleteLoadingAndWait(); 1012 CompleteLoadingAndWait();
1000 } 1013 }
1001 1014
1002 TEST_F(DeferredCookieTaskTest, DeferredDeleteAllCookies) { 1015 TEST_F(DeferredCookieTaskTest, DeferredDeleteAllCookies) {
1003 MockDeleteCallback delete_callback; 1016 MockDeleteCallback delete_callback;
1004 1017
1005 BeginWith(DeleteAllAction(&cookie_monster(), &delete_callback)); 1018 BeginWith(DeleteAllAction(&cookie_monster(), &delete_callback));
(...skipping 23 matching lines...) Expand all
1029 EXPECT_CALL(delete_callback, Invoke(false)) 1042 EXPECT_CALL(delete_callback, Invoke(false))
1030 .WillOnce(QuitCurrentMessageLoop()); 1043 .WillOnce(QuitCurrentMessageLoop());
1031 1044
1032 CompleteLoadingAndWait(); 1045 CompleteLoadingAndWait();
1033 } 1046 }
1034 1047
1035 TEST_F(DeferredCookieTaskTest, DeferredDeleteAllForHostCookies) { 1048 TEST_F(DeferredCookieTaskTest, DeferredDeleteAllForHostCookies) {
1036 MockDeleteCallback delete_callback; 1049 MockDeleteCallback delete_callback;
1037 1050
1038 BeginWithForDomainKey( 1051 BeginWithForDomainKey(
1039 "google.izzle", 1052 http_www_google_.domain(),
1040 DeleteAllForHostAction(&cookie_monster(), url_google_, &delete_callback)); 1053 DeleteAllForHostAction(&cookie_monster(), http_www_google_.url(),
1054 &delete_callback));
1041 1055
1042 WaitForLoadCall(); 1056 WaitForLoadCall();
1043 1057
1044 EXPECT_CALL(delete_callback, Invoke(false)) 1058 EXPECT_CALL(delete_callback, Invoke(false))
1045 .WillOnce(DeleteAllForHostAction(&cookie_monster(), url_google_, 1059 .WillOnce(DeleteAllForHostAction(
1046 &delete_callback)); 1060 &cookie_monster(), http_www_google_.url(), &delete_callback));
1047 EXPECT_CALL(delete_callback, Invoke(false)) 1061 EXPECT_CALL(delete_callback, Invoke(false))
1048 .WillOnce(QuitCurrentMessageLoop()); 1062 .WillOnce(QuitCurrentMessageLoop());
1049 1063
1050 CompleteLoadingAndWait(); 1064 CompleteLoadingAndWait();
1051 } 1065 }
1052 1066
1053 TEST_F(DeferredCookieTaskTest, DeferredDeleteCanonicalCookie) { 1067 TEST_F(DeferredCookieTaskTest, DeferredDeleteCanonicalCookie) {
1054 std::vector<CanonicalCookie*> cookies; 1068 std::vector<CanonicalCookie*> cookies;
1055 CanonicalCookie cookie = 1069 CanonicalCookie cookie = BuildCanonicalCookie(
1056 BuildCanonicalCookie("www.google.com", "X=1; path=/", base::Time::Now()); 1070 http_www_google_.host(), "X=1; path=/", base::Time::Now());
1057 1071
1058 MockDeleteCookieCallback delete_cookie_callback; 1072 MockDeleteCookieCallback delete_cookie_callback;
1059 1073
1060 BeginWith(DeleteCanonicalCookieAction(&cookie_monster(), cookie, 1074 BeginWith(DeleteCanonicalCookieAction(&cookie_monster(), cookie,
1061 &delete_cookie_callback)); 1075 &delete_cookie_callback));
1062 1076
1063 WaitForLoadCall(); 1077 WaitForLoadCall();
1064 1078
1065 EXPECT_CALL(delete_cookie_callback, Invoke(false)) 1079 EXPECT_CALL(delete_cookie_callback, Invoke(false))
1066 .WillOnce(DeleteCanonicalCookieAction(&cookie_monster(), cookie, 1080 .WillOnce(DeleteCanonicalCookieAction(&cookie_monster(), cookie,
(...skipping 17 matching lines...) Expand all
1084 EXPECT_CALL(delete_callback, Invoke(false)) 1098 EXPECT_CALL(delete_callback, Invoke(false))
1085 .WillOnce(QuitCurrentMessageLoop()); 1099 .WillOnce(QuitCurrentMessageLoop());
1086 1100
1087 CompleteLoadingAndWait(); 1101 CompleteLoadingAndWait();
1088 } 1102 }
1089 1103
1090 // Verify that a series of queued tasks are executed in order upon loading of 1104 // Verify that a series of queued tasks are executed in order upon loading of
1091 // the backing store and that new tasks received while the queued tasks are 1105 // the backing store and that new tasks received while the queued tasks are
1092 // being dispatched go to the end of the queue. 1106 // being dispatched go to the end of the queue.
1093 TEST_F(DeferredCookieTaskTest, DeferredTaskOrder) { 1107 TEST_F(DeferredCookieTaskTest, DeferredTaskOrder) {
1094 DeclareLoadedCookie("www.google.izzle", 1108 DeclareLoadedCookie(http_www_google_.host(),
1095 "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", 1109 "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT",
1096 Time::Now() + TimeDelta::FromDays(3)); 1110 Time::Now() + TimeDelta::FromDays(3));
1097 1111
1098 MockGetCookiesCallback get_cookies_callback; 1112 MockGetCookiesCallback get_cookies_callback;
1099 MockSetCookiesCallback set_cookies_callback; 1113 MockSetCookiesCallback set_cookies_callback;
1100 MockGetCookiesCallback get_cookies_callback_deferred; 1114 MockGetCookiesCallback get_cookies_callback_deferred;
1101 1115
1102 EXPECT_CALL(*this, Begin()) 1116 EXPECT_CALL(*this, Begin())
1103 .WillOnce(testing::DoAll(GetCookiesAction(&cookie_monster(), url_google_, 1117 .WillOnce(testing::DoAll(
1104 &get_cookies_callback), 1118 GetCookiesAction(&cookie_monster(), http_www_google_.url(),
1105 SetCookieAction(&cookie_monster(), url_google_, 1119 &get_cookies_callback),
1106 "A=B", &set_cookies_callback))); 1120 SetCookieAction(&cookie_monster(), http_www_google_.url(), "A=B",
1121 &set_cookies_callback)));
1107 ExpectLoadCall(); 1122 ExpectLoadCall();
1108 ExpectLoadForKeyCall("google.izzle", false); 1123 ExpectLoadForKeyCall(http_www_google_.domain(), false);
1109 Begin(); 1124 Begin();
1110 1125
1111 WaitForLoadCall(); 1126 WaitForLoadCall();
1112 EXPECT_CALL(get_cookies_callback, Invoke("X=1")) 1127 EXPECT_CALL(get_cookies_callback, Invoke("X=1"))
1113 .WillOnce(GetCookiesAction(&cookie_monster(), url_google_, 1128 .WillOnce(GetCookiesAction(&cookie_monster(), http_www_google_.url(),
1114 &get_cookies_callback_deferred)); 1129 &get_cookies_callback_deferred));
1115 EXPECT_CALL(set_cookies_callback, Invoke(true)); 1130 EXPECT_CALL(set_cookies_callback, Invoke(true));
1116 EXPECT_CALL(get_cookies_callback_deferred, Invoke("A=B; X=1")) 1131 EXPECT_CALL(get_cookies_callback_deferred, Invoke("A=B; X=1"))
1117 .WillOnce(QuitCurrentMessageLoop()); 1132 .WillOnce(QuitCurrentMessageLoop());
1118 1133
1119 CompleteLoadingAndWait(); 1134 CompleteLoadingAndWait();
1120 } 1135 }
1121 1136
1122 TEST_F(CookieMonsterTest, TestCookieDeleteAll) { 1137 TEST_F(CookieMonsterTest, TestCookieDeleteAll) {
1123 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); 1138 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore);
1124 scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL)); 1139 scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL));
1125 CookieOptions options; 1140 CookieOptions options;
1126 options.set_include_httponly(); 1141 options.set_include_httponly();
1127 1142
1128 EXPECT_TRUE(SetCookie(cm.get(), url_google_, kValidCookieLine)); 1143 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), kValidCookieLine));
1129 EXPECT_EQ("A=B", GetCookies(cm.get(), url_google_)); 1144 EXPECT_EQ("A=B", GetCookies(cm.get(), http_www_google_.url()));
1130 1145
1131 EXPECT_TRUE( 1146 EXPECT_TRUE(SetCookieWithOptions(cm.get(), http_www_google_.url(),
1132 SetCookieWithOptions(cm.get(), url_google_, "C=D; httponly", options)); 1147 "C=D; httponly", options));
1133 EXPECT_EQ("A=B; C=D", GetCookiesWithOptions(cm.get(), url_google_, options)); 1148 EXPECT_EQ("A=B; C=D",
1149 GetCookiesWithOptions(cm.get(), http_www_google_.url(), options));
1134 1150
1135 EXPECT_EQ(2, DeleteAll(cm.get())); 1151 EXPECT_EQ(2, DeleteAll(cm.get()));
1136 EXPECT_EQ("", GetCookiesWithOptions(cm.get(), url_google_, options)); 1152 EXPECT_EQ("",
1153 GetCookiesWithOptions(cm.get(), http_www_google_.url(), options));
1137 EXPECT_EQ(0u, store->commands().size()); 1154 EXPECT_EQ(0u, store->commands().size());
1138 1155
1139 // Create a persistent cookie. 1156 // Create a persistent cookie.
1140 EXPECT_TRUE(SetCookie( 1157 EXPECT_TRUE(SetCookie(
1141 cm.get(), url_google_, 1158 cm.get(), http_www_google_.url(),
1142 std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-22 22:50:13 GMT")); 1159 std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-22 22:50:13 GMT"));
1143 ASSERT_EQ(1u, store->commands().size()); 1160 ASSERT_EQ(1u, store->commands().size());
1144 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[0].type); 1161 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[0].type);
1145 1162
1146 EXPECT_EQ(1, DeleteAll(cm.get())); // sync_to_store = true. 1163 EXPECT_EQ(1, DeleteAll(cm.get())); // sync_to_store = true.
1147 ASSERT_EQ(2u, store->commands().size()); 1164 ASSERT_EQ(2u, store->commands().size());
1148 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[1].type); 1165 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[1].type);
1149 1166
1150 EXPECT_EQ("", GetCookiesWithOptions(cm.get(), url_google_, options)); 1167 EXPECT_EQ("",
1168 GetCookiesWithOptions(cm.get(), http_www_google_.url(), options));
1151 } 1169 }
1152 1170
1153 TEST_F(CookieMonsterTest, TestCookieDeleteAllCreatedBetweenTimestamps) { 1171 TEST_F(CookieMonsterTest, TestCookieDeleteAllCreatedBetweenTimestamps) {
1154 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); 1172 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
1155 Time now = Time::Now(); 1173 Time now = Time::Now();
1156 1174
1157 // Nothing has been added so nothing should be deleted. 1175 // Nothing has been added so nothing should be deleted.
1158 EXPECT_EQ(0, DeleteAllCreatedBetween(cm.get(), now - TimeDelta::FromDays(99), 1176 EXPECT_EQ(0, DeleteAllCreatedBetween(cm.get(), now - TimeDelta::FromDays(99),
1159 Time())); 1177 Time()));
1160 1178
1161 // Create 3 cookies with creation date of today, yesterday and the day before. 1179 // Create 3 cookies with creation date of today, yesterday and the day before.
1162 EXPECT_TRUE(cm->SetCookieWithCreationTime(url_google_, "T-0=Now", now)); 1180 EXPECT_TRUE(
1163 EXPECT_TRUE(cm->SetCookieWithCreationTime(url_google_, "T-1=Yesterday", 1181 cm->SetCookieWithCreationTime(http_www_google_.url(), "T-0=Now", now));
1164 now - TimeDelta::FromDays(1))); 1182 EXPECT_TRUE(cm->SetCookieWithCreationTime(
1165 EXPECT_TRUE(cm->SetCookieWithCreationTime(url_google_, "T-2=DayBefore", 1183 http_www_google_.url(), "T-1=Yesterday", now - TimeDelta::FromDays(1)));
1166 now - TimeDelta::FromDays(2))); 1184 EXPECT_TRUE(cm->SetCookieWithCreationTime(
1167 EXPECT_TRUE(cm->SetCookieWithCreationTime(url_google_, "T-3=ThreeDays", 1185 http_www_google_.url(), "T-2=DayBefore", now - TimeDelta::FromDays(2)));
1168 now - TimeDelta::FromDays(3))); 1186 EXPECT_TRUE(cm->SetCookieWithCreationTime(
1169 EXPECT_TRUE(cm->SetCookieWithCreationTime(url_google_, "T-7=LastWeek", 1187 http_www_google_.url(), "T-3=ThreeDays", now - TimeDelta::FromDays(3)));
1170 now - TimeDelta::FromDays(7))); 1188 EXPECT_TRUE(cm->SetCookieWithCreationTime(
1189 http_www_google_.url(), "T-7=LastWeek", now - TimeDelta::FromDays(7)));
1171 1190
1172 // Try to delete threedays and the daybefore. 1191 // Try to delete threedays and the daybefore.
1173 EXPECT_EQ(2, DeleteAllCreatedBetween(cm.get(), now - TimeDelta::FromDays(3), 1192 EXPECT_EQ(2, DeleteAllCreatedBetween(cm.get(), now - TimeDelta::FromDays(3),
1174 now - TimeDelta::FromDays(1))); 1193 now - TimeDelta::FromDays(1)));
1175 1194
1176 // Try to delete yesterday, also make sure that delete_end is not 1195 // Try to delete yesterday, also make sure that delete_end is not
1177 // inclusive. 1196 // inclusive.
1178 EXPECT_EQ( 1197 EXPECT_EQ(
1179 1, DeleteAllCreatedBetween(cm.get(), now - TimeDelta::FromDays(2), now)); 1198 1, DeleteAllCreatedBetween(cm.get(), now - TimeDelta::FromDays(2), now));
1180 1199
1181 // Make sure the delete_begin is inclusive. 1200 // Make sure the delete_begin is inclusive.
1182 EXPECT_EQ( 1201 EXPECT_EQ(
1183 1, DeleteAllCreatedBetween(cm.get(), now - TimeDelta::FromDays(7), now)); 1202 1, DeleteAllCreatedBetween(cm.get(), now - TimeDelta::FromDays(7), now));
1184 1203
1185 // Delete the last (now) item. 1204 // Delete the last (now) item.
1186 EXPECT_EQ(1, DeleteAllCreatedBetween(cm.get(), Time(), Time())); 1205 EXPECT_EQ(1, DeleteAllCreatedBetween(cm.get(), Time(), Time()));
1187 1206
1188 // Really make sure everything is gone. 1207 // Really make sure everything is gone.
1189 EXPECT_EQ(0, DeleteAll(cm.get())); 1208 EXPECT_EQ(0, DeleteAll(cm.get()));
1190 } 1209 }
1191 1210
1192 static const int kAccessDelayMs = kLastAccessThresholdMilliseconds + 20; 1211 static const int kAccessDelayMs = kLastAccessThresholdMilliseconds + 20;
1193 1212
1194 TEST_F(CookieMonsterTest, TestLastAccess) { 1213 TEST_F(CookieMonsterTest, TestLastAccess) {
1195 scoped_refptr<CookieMonster> cm( 1214 scoped_refptr<CookieMonster> cm(
1196 new CookieMonster(NULL, NULL, kLastAccessThresholdMilliseconds)); 1215 new CookieMonster(NULL, NULL, kLastAccessThresholdMilliseconds));
1197 1216
1198 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "A=B")); 1217 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=B"));
1199 const Time last_access_date(GetFirstCookieAccessDate(cm.get())); 1218 const Time last_access_date(GetFirstCookieAccessDate(cm.get()));
1200 1219
1201 // Reading the cookie again immediately shouldn't update the access date, 1220 // Reading the cookie again immediately shouldn't update the access date,
1202 // since we're inside the threshold. 1221 // since we're inside the threshold.
1203 EXPECT_EQ("A=B", GetCookies(cm.get(), url_google_)); 1222 EXPECT_EQ("A=B", GetCookies(cm.get(), http_www_google_.url()));
1204 EXPECT_TRUE(last_access_date == GetFirstCookieAccessDate(cm.get())); 1223 EXPECT_TRUE(last_access_date == GetFirstCookieAccessDate(cm.get()));
1205 1224
1206 // Reading after a short wait should update the access date. 1225 // Reading after a short wait should update the access date.
1207 base::PlatformThread::Sleep( 1226 base::PlatformThread::Sleep(
1208 base::TimeDelta::FromMilliseconds(kAccessDelayMs)); 1227 base::TimeDelta::FromMilliseconds(kAccessDelayMs));
1209 EXPECT_EQ("A=B", GetCookies(cm.get(), url_google_)); 1228 EXPECT_EQ("A=B", GetCookies(cm.get(), http_www_google_.url()));
1210 EXPECT_FALSE(last_access_date == GetFirstCookieAccessDate(cm.get())); 1229 EXPECT_FALSE(last_access_date == GetFirstCookieAccessDate(cm.get()));
1211 } 1230 }
1212 1231
1213 TEST_F(CookieMonsterTest, TestHostGarbageCollection) { 1232 TEST_F(CookieMonsterTest, TestHostGarbageCollection) {
1214 TestHostGarbageCollectHelper(); 1233 TestHostGarbageCollectHelper();
1215 } 1234 }
1216 1235
1217 TEST_F(CookieMonsterTest, TestPriorityAwareGarbageCollection) { 1236 TEST_F(CookieMonsterTest, TestPriorityAwareGarbageCollection) {
1218 TestPriorityAwareGarbageCollectHelper(); 1237 TestPriorityAwareGarbageCollectHelper();
1219 } 1238 }
1220 1239
1221 TEST_F(CookieMonsterTest, TestDeleteSingleCookie) { 1240 TEST_F(CookieMonsterTest, TestDeleteSingleCookie) {
1222 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); 1241 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
1223 1242
1224 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "A=B")); 1243 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=B"));
1225 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "C=D")); 1244 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "C=D"));
1226 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "E=F")); 1245 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "E=F"));
1227 EXPECT_EQ("A=B; C=D; E=F", GetCookies(cm.get(), url_google_)); 1246 EXPECT_EQ("A=B; C=D; E=F", GetCookies(cm.get(), http_www_google_.url()));
1228 1247
1229 EXPECT_TRUE(FindAndDeleteCookie(cm.get(), url_google_.host(), "C")); 1248 EXPECT_TRUE(
1230 EXPECT_EQ("A=B; E=F", GetCookies(cm.get(), url_google_)); 1249 FindAndDeleteCookie(cm.get(), http_www_google_.url().host(), "C"));
1250 EXPECT_EQ("A=B; E=F", GetCookies(cm.get(), http_www_google_.url()));
1231 1251
1232 EXPECT_FALSE(FindAndDeleteCookie(cm.get(), "random.host", "E")); 1252 EXPECT_FALSE(FindAndDeleteCookie(cm.get(), "random.host", "E"));
1233 EXPECT_EQ("A=B; E=F", GetCookies(cm.get(), url_google_)); 1253 EXPECT_EQ("A=B; E=F", GetCookies(cm.get(), http_www_google_.url()));
1234 } 1254 }
1235 1255
1236 TEST_F(CookieMonsterTest, SetCookieableSchemes) { 1256 TEST_F(CookieMonsterTest, SetCookieableSchemes) {
1237 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); 1257 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
1238 scoped_refptr<CookieMonster> cm_foo(new CookieMonster(NULL, NULL)); 1258 scoped_refptr<CookieMonster> cm_foo(new CookieMonster(NULL, NULL));
1239 1259
1240 // Only cm_foo should allow foo:// cookies. 1260 // Only cm_foo should allow foo:// cookies.
1241 const char* const kSchemes[] = {"foo"}; 1261 const char* const kSchemes[] = {"foo"};
1242 cm_foo->SetCookieableSchemes(kSchemes, 1); 1262 cm_foo->SetCookieableSchemes(kSchemes, 1);
1243 1263
1244 GURL foo_url("foo://host/path"); 1264 GURL foo_url("foo://host/path");
1245 GURL http_url("http://host/path"); 1265 GURL http_url("http://host/path");
1246 1266
1247 EXPECT_TRUE(SetCookie(cm.get(), http_url, "x=1")); 1267 EXPECT_TRUE(SetCookie(cm.get(), http_url, "x=1"));
1248 EXPECT_FALSE(SetCookie(cm.get(), foo_url, "x=1")); 1268 EXPECT_FALSE(SetCookie(cm.get(), foo_url, "x=1"));
1249 EXPECT_TRUE(SetCookie(cm_foo.get(), foo_url, "x=1")); 1269 EXPECT_TRUE(SetCookie(cm_foo.get(), foo_url, "x=1"));
1250 EXPECT_FALSE(SetCookie(cm_foo.get(), http_url, "x=1")); 1270 EXPECT_FALSE(SetCookie(cm_foo.get(), http_url, "x=1"));
1251 } 1271 }
1252 1272
1253 TEST_F(CookieMonsterTest, GetAllCookiesForURL) { 1273 TEST_F(CookieMonsterTest, GetAllCookiesForURL) {
1254 scoped_refptr<CookieMonster> cm( 1274 scoped_refptr<CookieMonster> cm(
1255 new CookieMonster(NULL, NULL, kLastAccessThresholdMilliseconds)); 1275 new CookieMonster(NULL, NULL, kLastAccessThresholdMilliseconds));
1256 1276
1257 // Create an httponly cookie. 1277 // Create an httponly cookie.
1258 CookieOptions options; 1278 CookieOptions options;
1259 options.set_include_httponly(); 1279 options.set_include_httponly();
1260 1280
1261 EXPECT_TRUE( 1281 EXPECT_TRUE(SetCookieWithOptions(cm.get(), http_www_google_.url(),
1262 SetCookieWithOptions(cm.get(), url_google_, "A=B; httponly", options)); 1282 "A=B; httponly", options));
1263 EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_, 1283 EXPECT_TRUE(SetCookieWithOptions(cm.get(), http_www_google_.url(),
1264 "C=D; domain=.google.izzle", options)); 1284 http_www_google_.Format("C=D; domain=.%D"),
1265 EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_secure_,
1266 "E=F; domain=.google.izzle; secure",
1267 options)); 1285 options));
1286 EXPECT_TRUE(SetCookieWithOptions(
1287 cm.get(), https_www_google_.url(),
1288 http_www_google_.Format("E=F; domain=.%D; secure"), options));
1268 1289
1269 const Time last_access_date(GetFirstCookieAccessDate(cm.get())); 1290 const Time last_access_date(GetFirstCookieAccessDate(cm.get()));
1270 1291
1271 base::PlatformThread::Sleep( 1292 base::PlatformThread::Sleep(
1272 base::TimeDelta::FromMilliseconds(kAccessDelayMs)); 1293 base::TimeDelta::FromMilliseconds(kAccessDelayMs));
1273 1294
1274 // Check cookies for url. 1295 // Check cookies for url.
1275 CookieList cookies = GetAllCookiesForURL(cm.get(), url_google_); 1296 CookieList cookies = GetAllCookiesForURL(cm.get(), http_www_google_.url());
1276 CookieList::iterator it = cookies.begin(); 1297 CookieList::iterator it = cookies.begin();
1277 1298
1278 ASSERT_TRUE(it != cookies.end()); 1299 ASSERT_TRUE(it != cookies.end());
1279 EXPECT_EQ("www.google.izzle", it->Domain()); 1300 EXPECT_EQ(http_www_google_.host(), it->Domain());
1280 EXPECT_EQ("A", it->Name()); 1301 EXPECT_EQ("A", it->Name());
1281 1302
1282 ASSERT_TRUE(++it != cookies.end()); 1303 ASSERT_TRUE(++it != cookies.end());
1283 EXPECT_EQ(".google.izzle", it->Domain()); 1304 EXPECT_EQ(http_www_google_.Format(".%D"), it->Domain());
1284 EXPECT_EQ("C", it->Name()); 1305 EXPECT_EQ("C", it->Name());
1285 1306
1286 ASSERT_TRUE(++it == cookies.end()); 1307 ASSERT_TRUE(++it == cookies.end());
1287 1308
1288 // Check cookies for url excluding http-only cookies. 1309 // Check cookies for url excluding http-only cookies.
1289 cookies = 1310 cookies = GetAllCookiesForURLWithOptions(cm.get(), http_www_google_.url(),
1290 GetAllCookiesForURLWithOptions(cm.get(), url_google_, CookieOptions()); 1311 CookieOptions());
1291 it = cookies.begin(); 1312 it = cookies.begin();
1292 1313
1293 ASSERT_TRUE(it != cookies.end()); 1314 ASSERT_TRUE(it != cookies.end());
1294 EXPECT_EQ(".google.izzle", it->Domain()); 1315 EXPECT_EQ(http_www_google_.Format(".%D"), it->Domain());
1295 EXPECT_EQ("C", it->Name()); 1316 EXPECT_EQ("C", it->Name());
1296 1317
1297 ASSERT_TRUE(++it == cookies.end()); 1318 ASSERT_TRUE(++it == cookies.end());
1298 1319
1299 // Test secure cookies. 1320 // Test secure cookies.
1300 cookies = GetAllCookiesForURL(cm.get(), url_google_secure_); 1321 cookies = GetAllCookiesForURL(cm.get(), https_www_google_.url());
1301 it = cookies.begin(); 1322 it = cookies.begin();
1302 1323
1303 ASSERT_TRUE(it != cookies.end()); 1324 ASSERT_TRUE(it != cookies.end());
1304 EXPECT_EQ("www.google.izzle", it->Domain()); 1325 EXPECT_EQ(http_www_google_.host(), it->Domain());
1305 EXPECT_EQ("A", it->Name()); 1326 EXPECT_EQ("A", it->Name());
1306 1327
1307 ASSERT_TRUE(++it != cookies.end()); 1328 ASSERT_TRUE(++it != cookies.end());
1308 EXPECT_EQ(".google.izzle", it->Domain()); 1329 EXPECT_EQ(http_www_google_.Format(".%D"), it->Domain());
1309 EXPECT_EQ("C", it->Name()); 1330 EXPECT_EQ("C", it->Name());
1310 1331
1311 ASSERT_TRUE(++it != cookies.end()); 1332 ASSERT_TRUE(++it != cookies.end());
1312 EXPECT_EQ(".google.izzle", it->Domain()); 1333 EXPECT_EQ(http_www_google_.Format(".%D"), it->Domain());
1313 EXPECT_EQ("E", it->Name()); 1334 EXPECT_EQ("E", it->Name());
1314 1335
1315 ASSERT_TRUE(++it == cookies.end()); 1336 ASSERT_TRUE(++it == cookies.end());
1316 1337
1317 // Reading after a short wait should not update the access date. 1338 // Reading after a short wait should not update the access date.
1318 EXPECT_TRUE(last_access_date == GetFirstCookieAccessDate(cm.get())); 1339 EXPECT_TRUE(last_access_date == GetFirstCookieAccessDate(cm.get()));
1319 } 1340 }
1320 1341
1321 TEST_F(CookieMonsterTest, GetAllCookiesForURLPathMatching) { 1342 TEST_F(CookieMonsterTest, GetAllCookiesForURLPathMatching) {
1322 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); 1343 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
1323 CookieOptions options; 1344 CookieOptions options;
1324 1345
1325 EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_foo_, "A=B; path=/foo;", 1346 EXPECT_TRUE(SetCookieWithOptions(cm.get(), www_google_foo_.url(),
1326 options)); 1347 "A=B; path=/foo;", options));
1327 EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_bar_, "C=D; path=/bar;", 1348 EXPECT_TRUE(SetCookieWithOptions(cm.get(), www_google_bar_.url(),
1328 options)); 1349 "C=D; path=/bar;", options));
1329 EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_, "E=F;", options)); 1350 EXPECT_TRUE(
1351 SetCookieWithOptions(cm.get(), http_www_google_.url(), "E=F;", options));
1330 1352
1331 CookieList cookies = GetAllCookiesForURL(cm.get(), url_google_foo_); 1353 CookieList cookies = GetAllCookiesForURL(cm.get(), www_google_foo_.url());
1332 CookieList::iterator it = cookies.begin(); 1354 CookieList::iterator it = cookies.begin();
1333 1355
1334 ASSERT_TRUE(it != cookies.end()); 1356 ASSERT_TRUE(it != cookies.end());
1335 EXPECT_EQ("A", it->Name()); 1357 EXPECT_EQ("A", it->Name());
1336 EXPECT_EQ("/foo", it->Path()); 1358 EXPECT_EQ("/foo", it->Path());
1337 1359
1338 ASSERT_TRUE(++it != cookies.end()); 1360 ASSERT_TRUE(++it != cookies.end());
1339 EXPECT_EQ("E", it->Name()); 1361 EXPECT_EQ("E", it->Name());
1340 EXPECT_EQ("/", it->Path()); 1362 EXPECT_EQ("/", it->Path());
1341 1363
1342 ASSERT_TRUE(++it == cookies.end()); 1364 ASSERT_TRUE(++it == cookies.end());
1343 1365
1344 cookies = GetAllCookiesForURL(cm.get(), url_google_bar_); 1366 cookies = GetAllCookiesForURL(cm.get(), www_google_bar_.url());
1345 it = cookies.begin(); 1367 it = cookies.begin();
1346 1368
1347 ASSERT_TRUE(it != cookies.end()); 1369 ASSERT_TRUE(it != cookies.end());
1348 EXPECT_EQ("C", it->Name()); 1370 EXPECT_EQ("C", it->Name());
1349 EXPECT_EQ("/bar", it->Path()); 1371 EXPECT_EQ("/bar", it->Path());
1350 1372
1351 ASSERT_TRUE(++it != cookies.end()); 1373 ASSERT_TRUE(++it != cookies.end());
1352 EXPECT_EQ("E", it->Name()); 1374 EXPECT_EQ("E", it->Name());
1353 EXPECT_EQ("/", it->Path()); 1375 EXPECT_EQ("/", it->Path());
1354 1376
1355 ASSERT_TRUE(++it == cookies.end()); 1377 ASSERT_TRUE(++it == cookies.end());
1356 } 1378 }
1357 1379
1358 TEST_F(CookieMonsterTest, CookieSorting) { 1380 TEST_F(CookieMonsterTest, CookieSorting) {
1359 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); 1381 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
1360 1382
1361 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "B=B1; path=/")); 1383 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "B=B1; path=/"));
1362 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "B=B2; path=/foo")); 1384 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "B=B2; path=/foo"));
1363 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "B=B3; path=/foo/bar")); 1385 EXPECT_TRUE(
1364 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "A=A1; path=/")); 1386 SetCookie(cm.get(), http_www_google_.url(), "B=B3; path=/foo/bar"));
1365 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "A=A2; path=/foo")); 1387 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=A1; path=/"));
1366 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "A=A3; path=/foo/bar")); 1388 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=A2; path=/foo"));
1389 EXPECT_TRUE(
1390 SetCookie(cm.get(), http_www_google_.url(), "A=A3; path=/foo/bar"));
1367 1391
1368 // Re-set cookie which should not change sort order. 1392 // Re-set cookie which should not change sort order.
1369 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "B=B3; path=/foo/bar")); 1393 EXPECT_TRUE(
1394 SetCookie(cm.get(), http_www_google_.url(), "B=B3; path=/foo/bar"));
1370 1395
1371 CookieList cookies = GetAllCookies(cm.get()); 1396 CookieList cookies = GetAllCookies(cm.get());
1372 ASSERT_EQ(6u, cookies.size()); 1397 ASSERT_EQ(6u, cookies.size());
1373 // According to RFC 6265 5.3 (11) re-setting this cookie should retain the 1398 // According to RFC 6265 5.3 (11) re-setting this cookie should retain the
1374 // initial creation-time from above, and the sort order should not change. 1399 // initial creation-time from above, and the sort order should not change.
1375 // Chrome's current implementation deviates from the spec so capturing this to 1400 // Chrome's current implementation deviates from the spec so capturing this to
1376 // avoid any inadvertent changes to this behavior. 1401 // avoid any inadvertent changes to this behavior.
1377 EXPECT_EQ("A3", cookies[0].Value()); 1402 EXPECT_EQ("A3", cookies[0].Value());
1378 EXPECT_EQ("B3", cookies[1].Value()); 1403 EXPECT_EQ("B3", cookies[1].Value());
1379 EXPECT_EQ("B2", cookies[2].Value()); 1404 EXPECT_EQ("B2", cookies[2].Value());
1380 EXPECT_EQ("A2", cookies[3].Value()); 1405 EXPECT_EQ("A2", cookies[3].Value());
1381 EXPECT_EQ("B1", cookies[4].Value()); 1406 EXPECT_EQ("B1", cookies[4].Value());
1382 EXPECT_EQ("A1", cookies[5].Value()); 1407 EXPECT_EQ("A1", cookies[5].Value());
1383 } 1408 }
1384 1409
1385 TEST_F(CookieMonsterTest, DeleteCookieByName) { 1410 TEST_F(CookieMonsterTest, DeleteCookieByName) {
1386 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); 1411 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
1387 1412
1388 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "A=A1; path=/")); 1413 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=A1; path=/"));
1389 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "A=A2; path=/foo")); 1414 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=A2; path=/foo"));
1390 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "A=A3; path=/bar")); 1415 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=A3; path=/bar"));
1391 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "B=B1; path=/")); 1416 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "B=B1; path=/"));
1392 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "B=B2; path=/foo")); 1417 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "B=B2; path=/foo"));
1393 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "B=B3; path=/bar")); 1418 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "B=B3; path=/bar"));
1394 1419
1395 DeleteCookie(cm.get(), GURL(std::string(kUrlGoogle) + "/foo/bar"), "A"); 1420 DeleteCookie(cm.get(), http_www_google_.AppendPath("foo/bar"), "A");
1396 1421
1397 CookieList cookies = GetAllCookies(cm.get()); 1422 CookieList cookies = GetAllCookies(cm.get());
1398 size_t expected_size = 4; 1423 size_t expected_size = 4;
1399 EXPECT_EQ(expected_size, cookies.size()); 1424 EXPECT_EQ(expected_size, cookies.size());
1400 for (CookieList::iterator it = cookies.begin(); it != cookies.end(); ++it) { 1425 for (CookieList::iterator it = cookies.begin(); it != cookies.end(); ++it) {
1401 EXPECT_NE("A1", it->Value()); 1426 EXPECT_NE("A1", it->Value());
1402 EXPECT_NE("A2", it->Value()); 1427 EXPECT_NE("A2", it->Value());
1403 } 1428 }
1404 } 1429 }
1405 1430
1406 TEST_F(CookieMonsterTest, ImportCookiesFromCookieMonster) { 1431 TEST_F(CookieMonsterTest, ImportCookiesFromCookieMonster) {
1407 scoped_refptr<CookieMonster> cm_1(new CookieMonster(NULL, NULL)); 1432 scoped_refptr<CookieMonster> cm_1(new CookieMonster(NULL, NULL));
1408 CookieOptions options; 1433 CookieOptions options;
1409 1434
1410 EXPECT_TRUE(SetCookieWithOptions(cm_1.get(), url_google_foo_, 1435 EXPECT_TRUE(SetCookieWithOptions(cm_1.get(), www_google_foo_.url(),
1411 "A1=B; path=/foo;", options)); 1436 "A1=B; path=/foo;", options));
1412 EXPECT_TRUE(SetCookieWithOptions(cm_1.get(), url_google_bar_, 1437 EXPECT_TRUE(SetCookieWithOptions(cm_1.get(), www_google_bar_.url(),
1413 "A2=D; path=/bar;", options)); 1438 "A2=D; path=/bar;", options));
1414 EXPECT_TRUE(SetCookieWithOptions(cm_1.get(), url_google_, "A3=F;", options)); 1439 EXPECT_TRUE(SetCookieWithOptions(cm_1.get(), http_www_google_.url(), "A3=F;",
1440 options));
1415 1441
1416 CookieList cookies_1 = GetAllCookies(cm_1.get()); 1442 CookieList cookies_1 = GetAllCookies(cm_1.get());
1417 scoped_refptr<CookieMonster> cm_2(new CookieMonster(NULL, NULL)); 1443 scoped_refptr<CookieMonster> cm_2(new CookieMonster(NULL, NULL));
1418 ASSERT_TRUE(cm_2->ImportCookies(cookies_1)); 1444 ASSERT_TRUE(cm_2->ImportCookies(cookies_1));
1419 CookieList cookies_2 = GetAllCookies(cm_2.get()); 1445 CookieList cookies_2 = GetAllCookies(cm_2.get());
1420 1446
1421 size_t expected_size = 3; 1447 size_t expected_size = 3;
1422 EXPECT_EQ(expected_size, cookies_2.size()); 1448 EXPECT_EQ(expected_size, cookies_2.size());
1423 1449
1424 CookieList::iterator it = cookies_2.begin(); 1450 CookieList::iterator it = cookies_2.begin();
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
1552 EXPECT_NE(name1, name2); 1578 EXPECT_NE(name1, name2);
1553 } 1579 }
1554 1580
1555 TEST_F(CookieMonsterTest, CookieMonsterDelegate) { 1581 TEST_F(CookieMonsterTest, CookieMonsterDelegate) {
1556 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); 1582 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore);
1557 scoped_refptr<MockCookieMonsterDelegate> delegate( 1583 scoped_refptr<MockCookieMonsterDelegate> delegate(
1558 new MockCookieMonsterDelegate); 1584 new MockCookieMonsterDelegate);
1559 scoped_refptr<CookieMonster> cm( 1585 scoped_refptr<CookieMonster> cm(
1560 new CookieMonster(store.get(), delegate.get())); 1586 new CookieMonster(store.get(), delegate.get()));
1561 1587
1562 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "A=B")); 1588 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=B"));
1563 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "C=D")); 1589 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "C=D"));
1564 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "E=F")); 1590 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "E=F"));
1565 EXPECT_EQ("A=B; C=D; E=F", GetCookies(cm.get(), url_google_)); 1591 EXPECT_EQ("A=B; C=D; E=F", GetCookies(cm.get(), http_www_google_.url()));
1566 ASSERT_EQ(3u, delegate->changes().size()); 1592 ASSERT_EQ(3u, delegate->changes().size());
1567 EXPECT_FALSE(delegate->changes()[0].second); 1593 EXPECT_FALSE(delegate->changes()[0].second);
1568 EXPECT_EQ(url_google_.host(), delegate->changes()[0].first.Domain()); 1594 EXPECT_EQ(http_www_google_.url().host(),
1595 delegate->changes()[0].first.Domain());
1569 EXPECT_EQ("A", delegate->changes()[0].first.Name()); 1596 EXPECT_EQ("A", delegate->changes()[0].first.Name());
1570 EXPECT_EQ("B", delegate->changes()[0].first.Value()); 1597 EXPECT_EQ("B", delegate->changes()[0].first.Value());
1571 EXPECT_EQ(url_google_.host(), delegate->changes()[1].first.Domain()); 1598 EXPECT_EQ(http_www_google_.url().host(),
1599 delegate->changes()[1].first.Domain());
1572 EXPECT_FALSE(delegate->changes()[1].second); 1600 EXPECT_FALSE(delegate->changes()[1].second);
1573 EXPECT_EQ("C", delegate->changes()[1].first.Name()); 1601 EXPECT_EQ("C", delegate->changes()[1].first.Name());
1574 EXPECT_EQ("D", delegate->changes()[1].first.Value()); 1602 EXPECT_EQ("D", delegate->changes()[1].first.Value());
1575 EXPECT_EQ(url_google_.host(), delegate->changes()[2].first.Domain()); 1603 EXPECT_EQ(http_www_google_.url().host(),
1604 delegate->changes()[2].first.Domain());
1576 EXPECT_FALSE(delegate->changes()[2].second); 1605 EXPECT_FALSE(delegate->changes()[2].second);
1577 EXPECT_EQ("E", delegate->changes()[2].first.Name()); 1606 EXPECT_EQ("E", delegate->changes()[2].first.Name());
1578 EXPECT_EQ("F", delegate->changes()[2].first.Value()); 1607 EXPECT_EQ("F", delegate->changes()[2].first.Value());
1579 delegate->reset(); 1608 delegate->reset();
1580 1609
1581 EXPECT_TRUE(FindAndDeleteCookie(cm.get(), url_google_.host(), "C")); 1610 EXPECT_TRUE(
1582 EXPECT_EQ("A=B; E=F", GetCookies(cm.get(), url_google_)); 1611 FindAndDeleteCookie(cm.get(), http_www_google_.url().host(), "C"));
1612 EXPECT_EQ("A=B; E=F", GetCookies(cm.get(), http_www_google_.url()));
1583 ASSERT_EQ(1u, delegate->changes().size()); 1613 ASSERT_EQ(1u, delegate->changes().size());
1584 EXPECT_EQ(url_google_.host(), delegate->changes()[0].first.Domain()); 1614 EXPECT_EQ(http_www_google_.url().host(),
1615 delegate->changes()[0].first.Domain());
1585 EXPECT_TRUE(delegate->changes()[0].second); 1616 EXPECT_TRUE(delegate->changes()[0].second);
1586 EXPECT_EQ("C", delegate->changes()[0].first.Name()); 1617 EXPECT_EQ("C", delegate->changes()[0].first.Name());
1587 EXPECT_EQ("D", delegate->changes()[0].first.Value()); 1618 EXPECT_EQ("D", delegate->changes()[0].first.Value());
1588 delegate->reset(); 1619 delegate->reset();
1589 1620
1590 EXPECT_FALSE(FindAndDeleteCookie(cm.get(), "random.host", "E")); 1621 EXPECT_FALSE(FindAndDeleteCookie(cm.get(), "random.host", "E"));
1591 EXPECT_EQ("A=B; E=F", GetCookies(cm.get(), url_google_)); 1622 EXPECT_EQ("A=B; E=F", GetCookies(cm.get(), http_www_google_.url()));
1592 EXPECT_EQ(0u, delegate->changes().size()); 1623 EXPECT_EQ(0u, delegate->changes().size());
1593 1624
1594 // Insert a cookie "a" for path "/path1" 1625 // Insert a cookie "a" for path "/path1"
1595 EXPECT_TRUE(SetCookie(cm.get(), url_google_, 1626 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(),
1596 "a=val1; path=/path1; " 1627 "a=val1; path=/path1; "
1597 "expires=Mon, 18-Apr-22 22:50:13 GMT")); 1628 "expires=Mon, 18-Apr-22 22:50:13 GMT"));
1598 ASSERT_EQ(1u, store->commands().size()); 1629 ASSERT_EQ(1u, store->commands().size());
1599 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[0].type); 1630 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[0].type);
1600 ASSERT_EQ(1u, delegate->changes().size()); 1631 ASSERT_EQ(1u, delegate->changes().size());
1601 EXPECT_FALSE(delegate->changes()[0].second); 1632 EXPECT_FALSE(delegate->changes()[0].second);
1602 EXPECT_EQ(url_google_.host(), delegate->changes()[0].first.Domain()); 1633 EXPECT_EQ(http_www_google_.url().host(),
1634 delegate->changes()[0].first.Domain());
1603 EXPECT_EQ("a", delegate->changes()[0].first.Name()); 1635 EXPECT_EQ("a", delegate->changes()[0].first.Name());
1604 EXPECT_EQ("val1", delegate->changes()[0].first.Value()); 1636 EXPECT_EQ("val1", delegate->changes()[0].first.Value());
1605 delegate->reset(); 1637 delegate->reset();
1606 1638
1607 // Insert a cookie "a" for path "/path1", that is httponly. This should 1639 // Insert a cookie "a" for path "/path1", that is httponly. This should
1608 // overwrite the non-http-only version. 1640 // overwrite the non-http-only version.
1609 CookieOptions allow_httponly; 1641 CookieOptions allow_httponly;
1610 allow_httponly.set_include_httponly(); 1642 allow_httponly.set_include_httponly();
1611 EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_, 1643 EXPECT_TRUE(SetCookieWithOptions(cm.get(), http_www_google_.url(),
1612 "a=val2; path=/path1; httponly; " 1644 "a=val2; path=/path1; httponly; "
1613 "expires=Mon, 18-Apr-22 22:50:14 GMT", 1645 "expires=Mon, 18-Apr-22 22:50:14 GMT",
1614 allow_httponly)); 1646 allow_httponly));
1615 ASSERT_EQ(3u, store->commands().size()); 1647 ASSERT_EQ(3u, store->commands().size());
1616 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[1].type); 1648 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[1].type);
1617 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[2].type); 1649 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[2].type);
1618 ASSERT_EQ(2u, delegate->changes().size()); 1650 ASSERT_EQ(2u, delegate->changes().size());
1619 EXPECT_EQ(url_google_.host(), delegate->changes()[0].first.Domain()); 1651 EXPECT_EQ(http_www_google_.url().host(),
1652 delegate->changes()[0].first.Domain());
1620 EXPECT_TRUE(delegate->changes()[0].second); 1653 EXPECT_TRUE(delegate->changes()[0].second);
1621 EXPECT_EQ("a", delegate->changes()[0].first.Name()); 1654 EXPECT_EQ("a", delegate->changes()[0].first.Name());
1622 EXPECT_EQ("val1", delegate->changes()[0].first.Value()); 1655 EXPECT_EQ("val1", delegate->changes()[0].first.Value());
1623 EXPECT_EQ(url_google_.host(), delegate->changes()[1].first.Domain()); 1656 EXPECT_EQ(http_www_google_.url().host(),
1657 delegate->changes()[1].first.Domain());
1624 EXPECT_FALSE(delegate->changes()[1].second); 1658 EXPECT_FALSE(delegate->changes()[1].second);
1625 EXPECT_EQ("a", delegate->changes()[1].first.Name()); 1659 EXPECT_EQ("a", delegate->changes()[1].first.Name());
1626 EXPECT_EQ("val2", delegate->changes()[1].first.Value()); 1660 EXPECT_EQ("val2", delegate->changes()[1].first.Value());
1627 delegate->reset(); 1661 delegate->reset();
1628 } 1662 }
1629 1663
1630 TEST_F(CookieMonsterTest, SetCookieWithDetails) { 1664 TEST_F(CookieMonsterTest, SetCookieWithDetails) {
1631 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); 1665 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
1632 1666
1633 EXPECT_TRUE(SetCookieWithDetails(cm.get(), url_google_foo_, "A", "B", 1667 EXPECT_TRUE(SetCookieWithDetails(cm.get(), www_google_foo_.url(), "A", "B",
1634 std::string(), "/foo", base::Time(), false, 1668 std::string(), "/foo", base::Time(), false,
1635 false, false, COOKIE_PRIORITY_DEFAULT)); 1669 false, false, COOKIE_PRIORITY_DEFAULT));
1636 EXPECT_TRUE(SetCookieWithDetails(cm.get(), url_google_bar_, "C", "D",
1637 "google.izzle", "/bar", base::Time(), false,
1638 true, false, COOKIE_PRIORITY_DEFAULT));
1639 EXPECT_TRUE(SetCookieWithDetails( 1670 EXPECT_TRUE(SetCookieWithDetails(
1640 cm.get(), url_google_, "E", "F", std::string(), std::string(), 1671 cm.get(), www_google_bar_.url(), "C", "D", www_google_bar_.domain(),
1672 "/bar", base::Time(), false, true, false, COOKIE_PRIORITY_DEFAULT));
1673 EXPECT_TRUE(SetCookieWithDetails(
1674 cm.get(), http_www_google_.url(), "E", "F", std::string(), std::string(),
1641 base::Time(), true, false, false, COOKIE_PRIORITY_DEFAULT)); 1675 base::Time(), true, false, false, COOKIE_PRIORITY_DEFAULT));
1642 1676
1643 // Test that malformed attributes fail to set the cookie. 1677 // Test that malformed attributes fail to set the cookie.
1644 EXPECT_FALSE(SetCookieWithDetails(cm.get(), url_google_foo_, " A", "B", 1678 EXPECT_FALSE(SetCookieWithDetails(cm.get(), www_google_foo_.url(), " A", "B",
1645 std::string(), "/foo", base::Time(), false, 1679 std::string(), "/foo", base::Time(), false,
1646 false, false, COOKIE_PRIORITY_DEFAULT)); 1680 false, false, COOKIE_PRIORITY_DEFAULT));
1647 EXPECT_FALSE(SetCookieWithDetails(cm.get(), url_google_foo_, "A;", "B", 1681 EXPECT_FALSE(SetCookieWithDetails(cm.get(), www_google_foo_.url(), "A;", "B",
1648 std::string(), "/foo", base::Time(), false, 1682 std::string(), "/foo", base::Time(), false,
1649 false, false, COOKIE_PRIORITY_DEFAULT)); 1683 false, false, COOKIE_PRIORITY_DEFAULT));
1650 EXPECT_FALSE(SetCookieWithDetails(cm.get(), url_google_foo_, "A=", "B", 1684 EXPECT_FALSE(SetCookieWithDetails(cm.get(), www_google_foo_.url(), "A=", "B",
1651 std::string(), "/foo", base::Time(), false, 1685 std::string(), "/foo", base::Time(), false,
1652 false, false, COOKIE_PRIORITY_DEFAULT)); 1686 false, false, COOKIE_PRIORITY_DEFAULT));
1653 EXPECT_FALSE(SetCookieWithDetails( 1687 EXPECT_FALSE(SetCookieWithDetails(
1654 cm.get(), url_google_foo_, "A", "B", "google.ozzzzzzle", "foo", 1688 cm.get(), www_google_foo_.url(), "A", "B", "google.ozzzzzzle", "foo",
1655 base::Time(), false, false, false, COOKIE_PRIORITY_DEFAULT)); 1689 base::Time(), false, false, false, COOKIE_PRIORITY_DEFAULT));
1656 EXPECT_FALSE(SetCookieWithDetails(cm.get(), url_google_foo_, "A=", "B", 1690 EXPECT_FALSE(SetCookieWithDetails(cm.get(), www_google_foo_.url(), "A=", "B",
1657 std::string(), "foo", base::Time(), false, 1691 std::string(), "foo", base::Time(), false,
1658 false, false, COOKIE_PRIORITY_DEFAULT)); 1692 false, false, COOKIE_PRIORITY_DEFAULT));
1659 1693
1660 CookieList cookies = GetAllCookiesForURL(cm.get(), url_google_foo_); 1694 CookieList cookies = GetAllCookiesForURL(cm.get(), www_google_foo_.url());
1661 CookieList::iterator it = cookies.begin(); 1695 CookieList::iterator it = cookies.begin();
1662 1696
1663 ASSERT_TRUE(it != cookies.end()); 1697 ASSERT_TRUE(it != cookies.end());
1664 EXPECT_EQ("A", it->Name()); 1698 EXPECT_EQ("A", it->Name());
1665 EXPECT_EQ("B", it->Value()); 1699 EXPECT_EQ("B", it->Value());
1666 EXPECT_EQ("www.google.izzle", it->Domain()); 1700 EXPECT_EQ(www_google_foo_.host(), it->Domain());
1667 EXPECT_EQ("/foo", it->Path()); 1701 EXPECT_EQ("/foo", it->Path());
1668 EXPECT_FALSE(it->IsPersistent()); 1702 EXPECT_FALSE(it->IsPersistent());
1669 EXPECT_FALSE(it->IsSecure()); 1703 EXPECT_FALSE(it->IsSecure());
1670 EXPECT_FALSE(it->IsHttpOnly()); 1704 EXPECT_FALSE(it->IsHttpOnly());
1671 1705
1672 ASSERT_TRUE(++it == cookies.end()); 1706 ASSERT_TRUE(++it == cookies.end());
1673 1707
1674 cookies = GetAllCookiesForURL(cm.get(), url_google_bar_); 1708 cookies = GetAllCookiesForURL(cm.get(), www_google_bar_.url());
1675 it = cookies.begin(); 1709 it = cookies.begin();
1676 1710
1677 ASSERT_TRUE(it != cookies.end()); 1711 ASSERT_TRUE(it != cookies.end());
1678 EXPECT_EQ("C", it->Name()); 1712 EXPECT_EQ("C", it->Name());
1679 EXPECT_EQ("D", it->Value()); 1713 EXPECT_EQ("D", it->Value());
1680 EXPECT_EQ(".google.izzle", it->Domain()); 1714 EXPECT_EQ(www_google_bar_.Format(".%D"), it->Domain());
1681 EXPECT_EQ("/bar", it->Path()); 1715 EXPECT_EQ("/bar", it->Path());
1682 EXPECT_FALSE(it->IsSecure()); 1716 EXPECT_FALSE(it->IsSecure());
1683 EXPECT_TRUE(it->IsHttpOnly()); 1717 EXPECT_TRUE(it->IsHttpOnly());
1684 1718
1685 ASSERT_TRUE(++it == cookies.end()); 1719 ASSERT_TRUE(++it == cookies.end());
1686 1720
1687 cookies = GetAllCookiesForURL(cm.get(), url_google_secure_); 1721 cookies = GetAllCookiesForURL(cm.get(), https_www_google_.url());
1688 it = cookies.begin(); 1722 it = cookies.begin();
1689 1723
1690 ASSERT_TRUE(it != cookies.end()); 1724 ASSERT_TRUE(it != cookies.end());
1691 EXPECT_EQ("E", it->Name()); 1725 EXPECT_EQ("E", it->Name());
1692 EXPECT_EQ("F", it->Value()); 1726 EXPECT_EQ("F", it->Value());
1693 EXPECT_EQ("/", it->Path()); 1727 EXPECT_EQ("/", it->Path());
1694 EXPECT_EQ("www.google.izzle", it->Domain()); 1728 EXPECT_EQ(https_www_google_.host(), it->Domain());
1695 EXPECT_TRUE(it->IsSecure()); 1729 EXPECT_TRUE(it->IsSecure());
1696 EXPECT_FALSE(it->IsHttpOnly()); 1730 EXPECT_FALSE(it->IsHttpOnly());
1697 1731
1698 ASSERT_TRUE(++it == cookies.end()); 1732 ASSERT_TRUE(++it == cookies.end());
1699 } 1733 }
1700 1734
1701 TEST_F(CookieMonsterTest, DeleteAllForHost) { 1735 TEST_F(CookieMonsterTest, DeleteAllForHost) {
1702 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); 1736 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
1703 1737
1704 // Test probes: 1738 // Test probes:
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
1772 // Add in three cookies through every public interface to the 1806 // Add in three cookies through every public interface to the
1773 // CookieMonster and confirm that none of them have duplicate 1807 // CookieMonster and confirm that none of them have duplicate
1774 // creation times. 1808 // creation times.
1775 1809
1776 // SetCookieWithCreationTime and SetCookieWithCreationTimeAndOptions 1810 // SetCookieWithCreationTime and SetCookieWithCreationTimeAndOptions
1777 // are not included as they aren't going to be public for very much 1811 // are not included as they aren't going to be public for very much
1778 // longer. 1812 // longer.
1779 1813
1780 // SetCookie, SetCookieWithOptions, SetCookieWithDetails 1814 // SetCookie, SetCookieWithOptions, SetCookieWithDetails
1781 1815
1782 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "SetCookie1=A")); 1816 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "SetCookie1=A"));
1783 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "SetCookie2=A")); 1817 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "SetCookie2=A"));
1784 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "SetCookie3=A")); 1818 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "SetCookie3=A"));
1785 1819
1786 EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_, 1820 EXPECT_TRUE(SetCookieWithOptions(cm.get(), http_www_google_.url(),
1787 "setCookieWithOptions1=A", options)); 1821 "setCookieWithOptions1=A", options));
1788 EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_, 1822 EXPECT_TRUE(SetCookieWithOptions(cm.get(), http_www_google_.url(),
1789 "setCookieWithOptions2=A", options)); 1823 "setCookieWithOptions2=A", options));
1790 EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_, 1824 EXPECT_TRUE(SetCookieWithOptions(cm.get(), http_www_google_.url(),
1791 "setCookieWithOptions3=A", options)); 1825 "setCookieWithOptions3=A", options));
1792 1826
1793 EXPECT_TRUE(SetCookieWithDetails( 1827 EXPECT_TRUE(SetCookieWithDetails(
1794 cm.get(), url_google_, "setCookieWithDetails1", "A", ".google.izzle", "/", 1828 cm.get(), http_www_google_.url(), "setCookieWithDetails1", "A",
1795 Time(), false, false, false, COOKIE_PRIORITY_DEFAULT)); 1829 http_www_google_.Format(".%D"), "/", Time(), false, false, false,
1830 COOKIE_PRIORITY_DEFAULT));
1796 EXPECT_TRUE(SetCookieWithDetails( 1831 EXPECT_TRUE(SetCookieWithDetails(
1797 cm.get(), url_google_, "setCookieWithDetails2", "A", ".google.izzle", "/", 1832 cm.get(), http_www_google_.url(), "setCookieWithDetails2", "A",
1798 Time(), false, false, false, COOKIE_PRIORITY_DEFAULT)); 1833 http_www_google_.Format(".%D"), "/", Time(), false, false, false,
1834 COOKIE_PRIORITY_DEFAULT));
1799 EXPECT_TRUE(SetCookieWithDetails( 1835 EXPECT_TRUE(SetCookieWithDetails(
1800 cm.get(), url_google_, "setCookieWithDetails3", "A", ".google.izzle", "/", 1836 cm.get(), http_www_google_.url(), "setCookieWithDetails3", "A",
1801 Time(), false, false, false, COOKIE_PRIORITY_DEFAULT)); 1837 http_www_google_.Format(".%D"), "/", Time(), false, false, false,
1838 COOKIE_PRIORITY_DEFAULT));
1802 1839
1803 // Now we check 1840 // Now we check
1804 CookieList cookie_list(GetAllCookies(cm.get())); 1841 CookieList cookie_list(GetAllCookies(cm.get()));
1805 EXPECT_EQ(9u, cookie_list.size()); 1842 EXPECT_EQ(9u, cookie_list.size());
1806 typedef std::map<int64, CanonicalCookie> TimeCookieMap; 1843 typedef std::map<int64, CanonicalCookie> TimeCookieMap;
1807 TimeCookieMap check_map; 1844 TimeCookieMap check_map;
1808 for (CookieList::const_iterator it = cookie_list.begin(); 1845 for (CookieList::const_iterator it = cookie_list.begin();
1809 it != cookie_list.end(); it++) { 1846 it != cookie_list.end(); it++) {
1810 const int64 creation_date = it->CreationDate().ToInternalValue(); 1847 const int64 creation_date = it->CreationDate().ToInternalValue();
1811 TimeCookieMap::const_iterator existing_cookie_it( 1848 TimeCookieMap::const_iterator existing_cookie_it(
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
2052 } 2089 }
2053 2090
2054 // This test checks that keep expired cookies flag is working. 2091 // This test checks that keep expired cookies flag is working.
2055 TEST_F(CookieMonsterTest, KeepExpiredCookies) { 2092 TEST_F(CookieMonsterTest, KeepExpiredCookies) {
2056 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); 2093 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
2057 cm->SetKeepExpiredCookies(); 2094 cm->SetKeepExpiredCookies();
2058 CookieOptions options; 2095 CookieOptions options;
2059 2096
2060 // Set a persistent cookie. 2097 // Set a persistent cookie.
2061 ASSERT_TRUE(SetCookieWithOptions( 2098 ASSERT_TRUE(SetCookieWithOptions(
2062 cm.get(), url_google_, 2099 cm.get(), http_www_google_.url(),
2063 std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-22 22:50:13 GMT", 2100 std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-22 22:50:13 GMT",
2064 options)); 2101 options));
2065 2102
2066 // Get the canonical cookie. 2103 // Get the canonical cookie.
2067 CookieList cookie_list = GetAllCookies(cm.get()); 2104 CookieList cookie_list = GetAllCookies(cm.get());
2068 ASSERT_EQ(1U, cookie_list.size()); 2105 ASSERT_EQ(1U, cookie_list.size());
2069 2106
2070 // Use a past expiry date to delete the cookie. 2107 // Use a past expiry date to delete the cookie.
2071 ASSERT_TRUE(SetCookieWithOptions( 2108 ASSERT_TRUE(SetCookieWithOptions(
2072 cm.get(), url_google_, 2109 cm.get(), http_www_google_.url(),
2073 std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-1977 22:50:13 GMT", 2110 std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-1977 22:50:13 GMT",
2074 options)); 2111 options));
2075 2112
2076 // Check that the cookie with the past expiry date is still there. 2113 // Check that the cookie with the past expiry date is still there.
2077 // GetAllCookies() also triggers garbage collection. 2114 // GetAllCookies() also triggers garbage collection.
2078 cookie_list = GetAllCookies(cm.get()); 2115 cookie_list = GetAllCookies(cm.get());
2079 ASSERT_EQ(1U, cookie_list.size()); 2116 ASSERT_EQ(1U, cookie_list.size());
2080 ASSERT_TRUE(cookie_list[0].IsExpired(Time::Now())); 2117 ASSERT_TRUE(cookie_list[0].IsExpired(Time::Now()));
2081 } 2118 }
2082 2119
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
2187 base::MessageLoop::current()->RunUntilIdle(); 2224 base::MessageLoop::current()->RunUntilIdle();
2188 2225
2189 ASSERT_EQ(3, counter->callback_count()); 2226 ASSERT_EQ(3, counter->callback_count());
2190 } 2227 }
2191 2228
2192 TEST_F(CookieMonsterTest, SetAllCookies) { 2229 TEST_F(CookieMonsterTest, SetAllCookies) {
2193 scoped_refptr<FlushablePersistentStore> store(new FlushablePersistentStore()); 2230 scoped_refptr<FlushablePersistentStore> store(new FlushablePersistentStore());
2194 scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL)); 2231 scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL));
2195 cm->SetPersistSessionCookies(true); 2232 cm->SetPersistSessionCookies(true);
2196 2233
2197 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "U=V; path=/")); 2234 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "U=V; path=/"));
2198 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "W=X; path=/foo")); 2235 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "W=X; path=/foo"));
2199 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "Y=Z; path=/")); 2236 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "Y=Z; path=/"));
2200 2237
2201 CookieList list; 2238 CookieList list;
2202 list.push_back(CanonicalCookie(url_google_, "A", "B", url_google_.host(), "/", 2239 list.push_back(CanonicalCookie(http_www_google_.url(), "A", "B",
2240 http_www_google_.url().host(), "/",
2203 base::Time::Now(), base::Time(), base::Time(), 2241 base::Time::Now(), base::Time(), base::Time(),
2204 false, false, false, COOKIE_PRIORITY_DEFAULT)); 2242 false, false, false, COOKIE_PRIORITY_DEFAULT));
2205 list.push_back(CanonicalCookie(url_google_, "W", "X", url_google_.host(), 2243 list.push_back(CanonicalCookie(http_www_google_.url(), "W", "X",
2206 "/bar", base::Time::Now(), base::Time(), 2244 http_www_google_.url().host(), "/bar",
2207 base::Time(), false, false, false, 2245 base::Time::Now(), base::Time(), base::Time(),
2208 COOKIE_PRIORITY_DEFAULT)); 2246 false, false, false, COOKIE_PRIORITY_DEFAULT));
2209 list.push_back(CanonicalCookie(url_google_, "Y", "Z", url_google_.host(), "/", 2247 list.push_back(CanonicalCookie(http_www_google_.url(), "Y", "Z",
2248 http_www_google_.url().host(), "/",
2210 base::Time::Now(), base::Time(), base::Time(), 2249 base::Time::Now(), base::Time(), base::Time(),
2211 false, false, false, COOKIE_PRIORITY_DEFAULT)); 2250 false, false, false, COOKIE_PRIORITY_DEFAULT));
2212 2251
2213 // SetAllCookies must not flush. 2252 // SetAllCookies must not flush.
2214 ASSERT_EQ(0, store->flush_count()); 2253 ASSERT_EQ(0, store->flush_count());
2215 EXPECT_TRUE(SetAllCookies(cm.get(), list)); 2254 EXPECT_TRUE(SetAllCookies(cm.get(), list));
2216 EXPECT_EQ(0, store->flush_count()); 2255 EXPECT_EQ(0, store->flush_count());
2217 2256
2218 CookieList cookies = GetAllCookies(cm.get()); 2257 CookieList cookies = GetAllCookies(cm.get());
2219 size_t expected_size = 3; // "A", "W" and "Y". "U" is gone. 2258 size_t expected_size = 3; // "A", "W" and "Y". "U" is gone.
(...skipping 13 matching lines...) Expand all
2233 EXPECT_EQ("Y", it->Name()); 2272 EXPECT_EQ("Y", it->Name());
2234 EXPECT_EQ("Z", it->Value()); 2273 EXPECT_EQ("Z", it->Value());
2235 } 2274 }
2236 2275
2237 TEST_F(CookieMonsterTest, ComputeCookieDiff) { 2276 TEST_F(CookieMonsterTest, ComputeCookieDiff) {
2238 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); 2277 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
2239 2278
2240 base::Time now = base::Time::Now(); 2279 base::Time now = base::Time::Now();
2241 base::Time creation_time = now - base::TimeDelta::FromSeconds(1); 2280 base::Time creation_time = now - base::TimeDelta::FromSeconds(1);
2242 2281
2243 CanonicalCookie cookie1(url_google_, "A", "B", url_google_.host(), "/", 2282 CanonicalCookie cookie1(http_www_google_.url(), "A", "B",
2244 creation_time, base::Time(), base::Time(), false, 2283 http_www_google_.url().host(), "/", creation_time,
2245 false, false, COOKIE_PRIORITY_DEFAULT); 2284 base::Time(), base::Time(), false, false, false,
2246 CanonicalCookie cookie2(url_google_, "C", "D", url_google_.host(), "/", 2285 COOKIE_PRIORITY_DEFAULT);
2247 creation_time, base::Time(), base::Time(), false, 2286 CanonicalCookie cookie2(http_www_google_.url(), "C", "D",
2248 false, false, COOKIE_PRIORITY_DEFAULT); 2287 http_www_google_.url().host(), "/", creation_time,
2249 CanonicalCookie cookie3(url_google_, "E", "F", url_google_.host(), "/", 2288 base::Time(), base::Time(), false, false, false,
2250 creation_time, base::Time(), base::Time(), false, 2289 COOKIE_PRIORITY_DEFAULT);
2251 false, false, COOKIE_PRIORITY_DEFAULT); 2290 CanonicalCookie cookie3(http_www_google_.url(), "E", "F",
2252 CanonicalCookie cookie4(url_google_, "G", "H", url_google_.host(), "/", 2291 http_www_google_.url().host(), "/", creation_time,
2253 creation_time, base::Time(), base::Time(), false, 2292 base::Time(), base::Time(), false, false, false,
2254 false, false, COOKIE_PRIORITY_DEFAULT); 2293 COOKIE_PRIORITY_DEFAULT);
2294 CanonicalCookie cookie4(http_www_google_.url(), "G", "H",
2295 http_www_google_.url().host(), "/", creation_time,
2296 base::Time(), base::Time(), false, false, false,
2297 COOKIE_PRIORITY_DEFAULT);
2255 CanonicalCookie cookie4_with_new_value( 2298 CanonicalCookie cookie4_with_new_value(
2256 url_google_, "G", "iamnew", url_google_.host(), "/", creation_time, 2299 http_www_google_.url(), "G", "iamnew", http_www_google_.url().host(), "/",
2300 creation_time, base::Time(), base::Time(), false, false, false,
2301 COOKIE_PRIORITY_DEFAULT);
2302 CanonicalCookie cookie5(http_www_google_.url(), "I", "J",
2303 http_www_google_.url().host(), "/", creation_time,
2304 base::Time(), base::Time(), false, false, false,
2305 COOKIE_PRIORITY_DEFAULT);
2306 CanonicalCookie cookie5_with_new_creation_time(
2307 http_www_google_.url(), "I", "J", http_www_google_.url().host(), "/", now,
2257 base::Time(), base::Time(), false, false, false, COOKIE_PRIORITY_DEFAULT); 2308 base::Time(), base::Time(), false, false, false, COOKIE_PRIORITY_DEFAULT);
2258 CanonicalCookie cookie5(url_google_, "I", "J", url_google_.host(), "/", 2309 CanonicalCookie cookie6(http_www_google_.url(), "K", "L",
2259 creation_time, base::Time(), base::Time(), false, 2310 http_www_google_.url().host(), "/foo", creation_time,
2260 false, false, COOKIE_PRIORITY_DEFAULT); 2311 base::Time(), base::Time(), false, false, false,
2261 CanonicalCookie cookie5_with_new_creation_time( 2312 COOKIE_PRIORITY_DEFAULT);
2262 url_google_, "I", "J", url_google_.host(), "/", now, base::Time(),
2263 base::Time(), false, false, false, COOKIE_PRIORITY_DEFAULT);
2264 CanonicalCookie cookie6(url_google_, "K", "L", url_google_.host(), "/foo",
2265 creation_time, base::Time(), base::Time(), false,
2266 false, false, COOKIE_PRIORITY_DEFAULT);
2267 CanonicalCookie cookie6_with_new_path( 2313 CanonicalCookie cookie6_with_new_path(
2268 url_google_, "K", "L", url_google_.host(), "/bar", creation_time, 2314 http_www_google_.url(), "K", "L", http_www_google_.url().host(), "/bar",
2269 base::Time(), base::Time(), false, false, false, COOKIE_PRIORITY_DEFAULT); 2315 creation_time, base::Time(), base::Time(), false, false, false,
2270 CanonicalCookie cookie7(url_google_, "M", "N", url_google_.host(), "/foo", 2316 COOKIE_PRIORITY_DEFAULT);
2271 creation_time, base::Time(), base::Time(), false, 2317 CanonicalCookie cookie7(http_www_google_.url(), "M", "N",
2272 false, false, COOKIE_PRIORITY_DEFAULT); 2318 http_www_google_.url().host(), "/foo", creation_time,
2319 base::Time(), base::Time(), false, false, false,
2320 COOKIE_PRIORITY_DEFAULT);
2273 CanonicalCookie cookie7_with_new_path( 2321 CanonicalCookie cookie7_with_new_path(
2274 url_google_, "M", "N", url_google_.host(), "/bar", creation_time, 2322 http_www_google_.url(), "M", "N", http_www_google_.url().host(), "/bar",
2275 base::Time(), base::Time(), false, false, false, COOKIE_PRIORITY_DEFAULT); 2323 creation_time, base::Time(), base::Time(), false, false, false,
2324 COOKIE_PRIORITY_DEFAULT);
2276 2325
2277 CookieList old_cookies; 2326 CookieList old_cookies;
2278 old_cookies.push_back(cookie1); 2327 old_cookies.push_back(cookie1);
2279 old_cookies.push_back(cookie2); 2328 old_cookies.push_back(cookie2);
2280 old_cookies.push_back(cookie4); 2329 old_cookies.push_back(cookie4);
2281 old_cookies.push_back(cookie5); 2330 old_cookies.push_back(cookie5);
2282 old_cookies.push_back(cookie6); 2331 old_cookies.push_back(cookie6);
2283 old_cookies.push_back(cookie7); 2332 old_cookies.push_back(cookie7);
2284 2333
2285 CookieList new_cookies; 2334 CookieList new_cookies;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
2338 EXPECT_FALSE(IsCookieInList(cookie7_with_new_path, cookies_to_delete)); 2387 EXPECT_FALSE(IsCookieInList(cookie7_with_new_path, cookies_to_delete));
2339 } 2388 }
2340 2389
2341 // Check that DeleteAll does flush (as a sanity check that flush_count() 2390 // Check that DeleteAll does flush (as a sanity check that flush_count()
2342 // works). 2391 // works).
2343 TEST_F(CookieMonsterTest, DeleteAll) { 2392 TEST_F(CookieMonsterTest, DeleteAll) {
2344 scoped_refptr<FlushablePersistentStore> store(new FlushablePersistentStore()); 2393 scoped_refptr<FlushablePersistentStore> store(new FlushablePersistentStore());
2345 scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL)); 2394 scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL));
2346 cm->SetPersistSessionCookies(true); 2395 cm->SetPersistSessionCookies(true);
2347 2396
2348 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "X=Y; path=/")); 2397 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "X=Y; path=/"));
2349 2398
2350 ASSERT_EQ(0, store->flush_count()); 2399 ASSERT_EQ(0, store->flush_count());
2351 EXPECT_EQ(1, DeleteAll(cm.get())); 2400 EXPECT_EQ(1, DeleteAll(cm.get()));
2352 EXPECT_EQ(1, store->flush_count()); 2401 EXPECT_EQ(1, store->flush_count());
2353 } 2402 }
2354 2403
2355 TEST_F(CookieMonsterTest, HistogramCheck) { 2404 TEST_F(CookieMonsterTest, HistogramCheck) {
2356 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); 2405 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
2357 // Should match call in InitializeHistograms, but doesn't really matter 2406 // Should match call in InitializeHistograms, but doesn't really matter
2358 // since the histogram should have been initialized by the CM construction 2407 // since the histogram should have been initialized by the CM construction
2359 // above. 2408 // above.
2360 base::HistogramBase* expired_histogram = base::Histogram::FactoryGet( 2409 base::HistogramBase* expired_histogram = base::Histogram::FactoryGet(
2361 "Cookie.ExpirationDurationMinutes", 1, 10 * 365 * 24 * 60, 50, 2410 "Cookie.ExpirationDurationMinutes", 1, 10 * 365 * 24 * 60, 50,
2362 base::Histogram::kUmaTargetedHistogramFlag); 2411 base::Histogram::kUmaTargetedHistogramFlag);
2363 2412
2364 scoped_ptr<base::HistogramSamples> samples1( 2413 scoped_ptr<base::HistogramSamples> samples1(
2365 expired_histogram->SnapshotSamples()); 2414 expired_histogram->SnapshotSamples());
2366 ASSERT_TRUE(SetCookieWithDetails( 2415 ASSERT_TRUE(SetCookieWithDetails(
2367 cm.get(), GURL("http://fake.a.url"), "a", "b", "a.url", "/", 2416 cm.get(), GURL("http://fake.a.url"), "a", "b", "a.url", "/",
2368 base::Time::Now() + base::TimeDelta::FromMinutes(59), false, false, false, 2417 base::Time::Now() + base::TimeDelta::FromMinutes(59), false, false, false,
2369 COOKIE_PRIORITY_DEFAULT)); 2418 COOKIE_PRIORITY_DEFAULT));
2370 2419
2371 scoped_ptr<base::HistogramSamples> samples2( 2420 scoped_ptr<base::HistogramSamples> samples2(
2372 expired_histogram->SnapshotSamples()); 2421 expired_histogram->SnapshotSamples());
2373 EXPECT_EQ(samples1->TotalCount() + 1, samples2->TotalCount()); 2422 EXPECT_EQ(samples1->TotalCount() + 1, samples2->TotalCount());
2374 2423
2375 // kValidCookieLine creates a session cookie. 2424 // kValidCookieLine creates a session cookie.
2376 ASSERT_TRUE(SetCookie(cm.get(), url_google_, kValidCookieLine)); 2425 ASSERT_TRUE(SetCookie(cm.get(), http_www_google_.url(), kValidCookieLine));
2377 2426
2378 scoped_ptr<base::HistogramSamples> samples3( 2427 scoped_ptr<base::HistogramSamples> samples3(
2379 expired_histogram->SnapshotSamples()); 2428 expired_histogram->SnapshotSamples());
2380 EXPECT_EQ(samples2->TotalCount(), samples3->TotalCount()); 2429 EXPECT_EQ(samples2->TotalCount(), samples3->TotalCount());
2381 } 2430 }
2382 2431
2383 namespace { 2432 namespace {
2384 2433
2385 class MultiThreadedCookieMonsterTest : public CookieMonsterTest { 2434 class MultiThreadedCookieMonsterTest : public CookieMonsterTest {
2386 public: 2435 public:
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
2477 other_thread_.Stop(); 2526 other_thread_.Stop();
2478 } 2527 }
2479 2528
2480 Thread other_thread_; 2529 Thread other_thread_;
2481 }; 2530 };
2482 2531
2483 } // namespace 2532 } // namespace
2484 2533
2485 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckGetAllCookies) { 2534 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckGetAllCookies) {
2486 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); 2535 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
2487 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "A=B")); 2536 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=B"));
2488 CookieList cookies = GetAllCookies(cm.get()); 2537 CookieList cookies = GetAllCookies(cm.get());
2489 CookieList::const_iterator it = cookies.begin(); 2538 CookieList::const_iterator it = cookies.begin();
2490 ASSERT_TRUE(it != cookies.end()); 2539 ASSERT_TRUE(it != cookies.end());
2491 EXPECT_EQ("www.google.izzle", it->Domain()); 2540 EXPECT_EQ(http_www_google_.host(), it->Domain());
2492 EXPECT_EQ("A", it->Name()); 2541 EXPECT_EQ("A", it->Name());
2493 ASSERT_TRUE(++it == cookies.end()); 2542 ASSERT_TRUE(++it == cookies.end());
2494 GetCookieListCallback callback(&other_thread_); 2543 GetCookieListCallback callback(&other_thread_);
2495 base::Closure task = 2544 base::Closure task =
2496 base::Bind(&MultiThreadedCookieMonsterTest::GetAllCookiesTask, 2545 base::Bind(&MultiThreadedCookieMonsterTest::GetAllCookiesTask,
2497 base::Unretained(this), cm, &callback); 2546 base::Unretained(this), cm, &callback);
2498 RunOnOtherThread(task); 2547 RunOnOtherThread(task);
2499 EXPECT_TRUE(callback.did_run()); 2548 EXPECT_TRUE(callback.did_run());
2500 it = callback.cookies().begin(); 2549 it = callback.cookies().begin();
2501 ASSERT_TRUE(it != callback.cookies().end()); 2550 ASSERT_TRUE(it != callback.cookies().end());
2502 EXPECT_EQ("www.google.izzle", it->Domain()); 2551 EXPECT_EQ(http_www_google_.host(), it->Domain());
2503 EXPECT_EQ("A", it->Name()); 2552 EXPECT_EQ("A", it->Name());
2504 ASSERT_TRUE(++it == callback.cookies().end()); 2553 ASSERT_TRUE(++it == callback.cookies().end());
2505 } 2554 }
2506 2555
2507 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckGetAllCookiesForURL) { 2556 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckGetAllCookiesForURL) {
2508 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); 2557 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
2509 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "A=B")); 2558 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=B"));
2510 CookieList cookies = GetAllCookiesForURL(cm.get(), url_google_); 2559 CookieList cookies = GetAllCookiesForURL(cm.get(), http_www_google_.url());
2511 CookieList::const_iterator it = cookies.begin(); 2560 CookieList::const_iterator it = cookies.begin();
2512 ASSERT_TRUE(it != cookies.end()); 2561 ASSERT_TRUE(it != cookies.end());
2513 EXPECT_EQ("www.google.izzle", it->Domain()); 2562 EXPECT_EQ(http_www_google_.host(), it->Domain());
2514 EXPECT_EQ("A", it->Name()); 2563 EXPECT_EQ("A", it->Name());
2515 ASSERT_TRUE(++it == cookies.end()); 2564 ASSERT_TRUE(++it == cookies.end());
2516 GetCookieListCallback callback(&other_thread_); 2565 GetCookieListCallback callback(&other_thread_);
2517 base::Closure task = 2566 base::Closure task =
2518 base::Bind(&MultiThreadedCookieMonsterTest::GetAllCookiesForURLTask, 2567 base::Bind(&MultiThreadedCookieMonsterTest::GetAllCookiesForURLTask,
2519 base::Unretained(this), cm, url_google_, &callback); 2568 base::Unretained(this), cm, http_www_google_.url(), &callback);
2520 RunOnOtherThread(task); 2569 RunOnOtherThread(task);
2521 EXPECT_TRUE(callback.did_run()); 2570 EXPECT_TRUE(callback.did_run());
2522 it = callback.cookies().begin(); 2571 it = callback.cookies().begin();
2523 ASSERT_TRUE(it != callback.cookies().end()); 2572 ASSERT_TRUE(it != callback.cookies().end());
2524 EXPECT_EQ("www.google.izzle", it->Domain()); 2573 EXPECT_EQ(http_www_google_.host(), it->Domain());
2525 EXPECT_EQ("A", it->Name()); 2574 EXPECT_EQ("A", it->Name());
2526 ASSERT_TRUE(++it == callback.cookies().end()); 2575 ASSERT_TRUE(++it == callback.cookies().end());
2527 } 2576 }
2528 2577
2529 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckGetAllCookiesForURLWithOpt) { 2578 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckGetAllCookiesForURLWithOpt) {
2530 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); 2579 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
2531 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "A=B")); 2580 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=B"));
2532 CookieOptions options; 2581 CookieOptions options;
2533 CookieList cookies = 2582 CookieList cookies =
2534 GetAllCookiesForURLWithOptions(cm.get(), url_google_, options); 2583 GetAllCookiesForURLWithOptions(cm.get(), http_www_google_.url(), options);
2535 CookieList::const_iterator it = cookies.begin(); 2584 CookieList::const_iterator it = cookies.begin();
2536 ASSERT_TRUE(it != cookies.end()); 2585 ASSERT_TRUE(it != cookies.end());
2537 EXPECT_EQ("www.google.izzle", it->Domain()); 2586 EXPECT_EQ(http_www_google_.host(), it->Domain());
2538 EXPECT_EQ("A", it->Name()); 2587 EXPECT_EQ("A", it->Name());
2539 ASSERT_TRUE(++it == cookies.end()); 2588 ASSERT_TRUE(++it == cookies.end());
2540 GetCookieListCallback callback(&other_thread_); 2589 GetCookieListCallback callback(&other_thread_);
2541 base::Closure task = base::Bind( 2590 base::Closure task = base::Bind(
2542 &MultiThreadedCookieMonsterTest::GetAllCookiesForURLWithOptionsTask, 2591 &MultiThreadedCookieMonsterTest::GetAllCookiesForURLWithOptionsTask,
2543 base::Unretained(this), cm, url_google_, options, &callback); 2592 base::Unretained(this), cm, http_www_google_.url(), options, &callback);
2544 RunOnOtherThread(task); 2593 RunOnOtherThread(task);
2545 EXPECT_TRUE(callback.did_run()); 2594 EXPECT_TRUE(callback.did_run());
2546 it = callback.cookies().begin(); 2595 it = callback.cookies().begin();
2547 ASSERT_TRUE(it != callback.cookies().end()); 2596 ASSERT_TRUE(it != callback.cookies().end());
2548 EXPECT_EQ("www.google.izzle", it->Domain()); 2597 EXPECT_EQ(http_www_google_.host(), it->Domain());
2549 EXPECT_EQ("A", it->Name()); 2598 EXPECT_EQ("A", it->Name());
2550 ASSERT_TRUE(++it == callback.cookies().end()); 2599 ASSERT_TRUE(++it == callback.cookies().end());
2551 } 2600 }
2552 2601
2553 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckSetCookieWithDetails) { 2602 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckSetCookieWithDetails) {
2554 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); 2603 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
2555 EXPECT_TRUE(SetCookieWithDetails(cm.get(), url_google_foo_, "A", "B", 2604 EXPECT_TRUE(SetCookieWithDetails(cm.get(), www_google_foo_.url(), "A", "B",
2556 std::string(), "/foo", base::Time(), false, 2605 std::string(), "/foo", base::Time(), false,
2557 false, false, COOKIE_PRIORITY_DEFAULT)); 2606 false, false, COOKIE_PRIORITY_DEFAULT));
2558 ResultSavingCookieCallback<bool> callback(&other_thread_); 2607 ResultSavingCookieCallback<bool> callback(&other_thread_);
2559 base::Closure task = 2608 base::Closure task =
2560 base::Bind(&MultiThreadedCookieMonsterTest::SetCookieWithDetailsTask, 2609 base::Bind(&MultiThreadedCookieMonsterTest::SetCookieWithDetailsTask,
2561 base::Unretained(this), cm, url_google_foo_, &callback); 2610 base::Unretained(this), cm, www_google_foo_.url(), &callback);
2562 RunOnOtherThread(task); 2611 RunOnOtherThread(task);
2563 EXPECT_TRUE(callback.did_run()); 2612 EXPECT_TRUE(callback.did_run());
2564 EXPECT_TRUE(callback.result()); 2613 EXPECT_TRUE(callback.result());
2565 } 2614 }
2566 2615
2567 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckDeleteAllCreatedBetween) { 2616 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckDeleteAllCreatedBetween) {
2568 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); 2617 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
2569 CookieOptions options; 2618 CookieOptions options;
2570 Time now = Time::Now(); 2619 Time now = Time::Now();
2571 EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_, "A=B", options)); 2620 EXPECT_TRUE(
2621 SetCookieWithOptions(cm.get(), http_www_google_.url(), "A=B", options));
2572 EXPECT_EQ(1, DeleteAllCreatedBetween(cm.get(), now - TimeDelta::FromDays(99), 2622 EXPECT_EQ(1, DeleteAllCreatedBetween(cm.get(), now - TimeDelta::FromDays(99),
2573 Time())); 2623 Time()));
2574 EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_, "A=B", options)); 2624 EXPECT_TRUE(
2625 SetCookieWithOptions(cm.get(), http_www_google_.url(), "A=B", options));
2575 ResultSavingCookieCallback<int> callback(&other_thread_); 2626 ResultSavingCookieCallback<int> callback(&other_thread_);
2576 base::Closure task = 2627 base::Closure task =
2577 base::Bind(&MultiThreadedCookieMonsterTest::DeleteAllCreatedBetweenTask, 2628 base::Bind(&MultiThreadedCookieMonsterTest::DeleteAllCreatedBetweenTask,
2578 base::Unretained(this), cm, now - TimeDelta::FromDays(99), 2629 base::Unretained(this), cm, now - TimeDelta::FromDays(99),
2579 Time(), &callback); 2630 Time(), &callback);
2580 RunOnOtherThread(task); 2631 RunOnOtherThread(task);
2581 EXPECT_TRUE(callback.did_run()); 2632 EXPECT_TRUE(callback.did_run());
2582 EXPECT_EQ(1, callback.result()); 2633 EXPECT_EQ(1, callback.result());
2583 } 2634 }
2584 2635
2585 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckDeleteAllForHost) { 2636 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckDeleteAllForHost) {
2586 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); 2637 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
2587 CookieOptions options; 2638 CookieOptions options;
2588 EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_, "A=B", options)); 2639 EXPECT_TRUE(
2589 EXPECT_EQ(1, DeleteAllForHost(cm.get(), url_google_)); 2640 SetCookieWithOptions(cm.get(), http_www_google_.url(), "A=B", options));
2590 EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_, "A=B", options)); 2641 EXPECT_EQ(1, DeleteAllForHost(cm.get(), http_www_google_.url()));
2642 EXPECT_TRUE(
2643 SetCookieWithOptions(cm.get(), http_www_google_.url(), "A=B", options));
2591 ResultSavingCookieCallback<int> callback(&other_thread_); 2644 ResultSavingCookieCallback<int> callback(&other_thread_);
2592 base::Closure task = 2645 base::Closure task =
2593 base::Bind(&MultiThreadedCookieMonsterTest::DeleteAllForHostTask, 2646 base::Bind(&MultiThreadedCookieMonsterTest::DeleteAllForHostTask,
2594 base::Unretained(this), cm, url_google_, &callback); 2647 base::Unretained(this), cm, http_www_google_.url(), &callback);
2595 RunOnOtherThread(task); 2648 RunOnOtherThread(task);
2596 EXPECT_TRUE(callback.did_run()); 2649 EXPECT_TRUE(callback.did_run());
2597 EXPECT_EQ(1, callback.result()); 2650 EXPECT_EQ(1, callback.result());
2598 } 2651 }
2599 2652
2600 TEST_F(MultiThreadedCookieMonsterTest, 2653 TEST_F(MultiThreadedCookieMonsterTest,
2601 ThreadCheckDeleteAllCreatedBetweenForHost) { 2654 ThreadCheckDeleteAllCreatedBetweenForHost) {
2602 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); 2655 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
2603 GURL url_not_google("http://www.notgoogle.com"); 2656 GURL url_not_google("http://www.notgoogle.com");
2604 2657
2605 CookieOptions options; 2658 CookieOptions options;
2606 Time now = Time::Now(); 2659 Time now = Time::Now();
2607 // ago1 < ago2 < ago3 < now. 2660 // ago1 < ago2 < ago3 < now.
2608 Time ago1 = now - TimeDelta::FromDays(101); 2661 Time ago1 = now - TimeDelta::FromDays(101);
2609 Time ago2 = now - TimeDelta::FromDays(100); 2662 Time ago2 = now - TimeDelta::FromDays(100);
2610 Time ago3 = now - TimeDelta::FromDays(99); 2663 Time ago3 = now - TimeDelta::FromDays(99);
2611 2664
2612 // These 3 cookies match the first deletion. 2665 // These 3 cookies match the first deletion.
2613 EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_, "A=B", options)); 2666 EXPECT_TRUE(
2614 EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_, "C=D", options)); 2667 SetCookieWithOptions(cm.get(), http_www_google_.url(), "A=B", options));
2615 EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_, "Y=Z", options)); 2668 EXPECT_TRUE(
2669 SetCookieWithOptions(cm.get(), http_www_google_.url(), "C=D", options));
2670 EXPECT_TRUE(
2671 SetCookieWithOptions(cm.get(), http_www_google_.url(), "Y=Z", options));
2616 2672
2617 // This cookie does not match host. 2673 // This cookie does not match host.
2618 EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_not_google, "E=F", options)); 2674 EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_not_google, "E=F", options));
2619 2675
2620 // This cookie does not match time range: [ago3, inf], for first deletion, but 2676 // This cookie does not match time range: [ago3, inf], for first deletion, but
2621 // matches for the second deletion. 2677 // matches for the second deletion.
2622 EXPECT_TRUE(cm->SetCookieWithCreationTime(url_google_, "G=H", ago2)); 2678 EXPECT_TRUE(
2679 cm->SetCookieWithCreationTime(http_www_google_.url(), "G=H", ago2));
2623 2680
2624 // 1. First set of deletions. 2681 // 1. First set of deletions.
2625 EXPECT_EQ( 2682 EXPECT_EQ(3, // Deletes A=B, C=D, Y=Z
2626 3, // Deletes A=B, C=D, Y=Z 2683 DeleteAllCreatedBetweenForHost(cm.get(), ago3, Time::Max(),
2627 DeleteAllCreatedBetweenForHost(cm.get(), ago3, Time::Max(), url_google_)); 2684 http_www_google_.url()));
2628 2685
2629 EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_, "A=B", options)); 2686 EXPECT_TRUE(
2687 SetCookieWithOptions(cm.get(), http_www_google_.url(), "A=B", options));
2630 ResultSavingCookieCallback<int> callback(&other_thread_); 2688 ResultSavingCookieCallback<int> callback(&other_thread_);
2631 2689
2632 // 2. Second set of deletions. 2690 // 2. Second set of deletions.
2633 base::Closure task = base::Bind( 2691 base::Closure task = base::Bind(
2634 &MultiThreadedCookieMonsterTest::DeleteAllCreatedBetweenForHostTask, 2692 &MultiThreadedCookieMonsterTest::DeleteAllCreatedBetweenForHostTask,
2635 base::Unretained(this), cm, ago1, Time(), url_google_, &callback); 2693 base::Unretained(this), cm, ago1, Time(), http_www_google_.url(),
2694 &callback);
2636 RunOnOtherThread(task); 2695 RunOnOtherThread(task);
2637 EXPECT_TRUE(callback.did_run()); 2696 EXPECT_TRUE(callback.did_run());
2638 EXPECT_EQ(2, callback.result()); // Deletes A=B, G=H. 2697 EXPECT_EQ(2, callback.result()); // Deletes A=B, G=H.
2639 } 2698 }
2640 2699
2641 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckDeleteCanonicalCookie) { 2700 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckDeleteCanonicalCookie) {
2642 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); 2701 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
2643 CookieOptions options; 2702 CookieOptions options;
2644 EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_, "A=B", options)); 2703 EXPECT_TRUE(
2704 SetCookieWithOptions(cm.get(), http_www_google_.url(), "A=B", options));
2645 CookieList cookies = GetAllCookies(cm.get()); 2705 CookieList cookies = GetAllCookies(cm.get());
2646 CookieList::iterator it = cookies.begin(); 2706 CookieList::iterator it = cookies.begin();
2647 EXPECT_TRUE(DeleteCanonicalCookie(cm.get(), *it)); 2707 EXPECT_TRUE(DeleteCanonicalCookie(cm.get(), *it));
2648 2708
2649 EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_, "A=B", options)); 2709 EXPECT_TRUE(
2710 SetCookieWithOptions(cm.get(), http_www_google_.url(), "A=B", options));
2650 ResultSavingCookieCallback<bool> callback(&other_thread_); 2711 ResultSavingCookieCallback<bool> callback(&other_thread_);
2651 cookies = GetAllCookies(cm.get()); 2712 cookies = GetAllCookies(cm.get());
2652 it = cookies.begin(); 2713 it = cookies.begin();
2653 base::Closure task = 2714 base::Closure task =
2654 base::Bind(&MultiThreadedCookieMonsterTest::DeleteCanonicalCookieTask, 2715 base::Bind(&MultiThreadedCookieMonsterTest::DeleteCanonicalCookieTask,
2655 base::Unretained(this), cm, *it, &callback); 2716 base::Unretained(this), cm, *it, &callback);
2656 RunOnOtherThread(task); 2717 RunOnOtherThread(task);
2657 EXPECT_TRUE(callback.did_run()); 2718 EXPECT_TRUE(callback.did_run());
2658 EXPECT_TRUE(callback.result()); 2719 EXPECT_TRUE(callback.result());
2659 } 2720 }
2660 2721
2661 // Ensure that cookies for http, https, ws, and wss all share the same storage 2722 // Ensure that cookies for http, https, ws, and wss all share the same storage
2662 // and policies when GetAllCookiesForURLAsync is used. This test is part of 2723 // and policies when GetAllCookiesForURLAsync is used. This test is part of
2663 // MultiThreadedCookieMonsterTest in order to test and use 2724 // MultiThreadedCookieMonsterTest in order to test and use
2664 // GetAllCookiesForURLAsync, but it does not use any additional threads. 2725 // GetAllCookiesForURLAsync, but it does not use any additional threads.
2665 TEST_F(MultiThreadedCookieMonsterTest, GetAllCookiesForURLEffectiveDomain) { 2726 TEST_F(MultiThreadedCookieMonsterTest, GetAllCookiesForURLEffectiveDomain) {
2666 std::vector<CanonicalCookie*> cookies; 2727 std::vector<CanonicalCookie*> cookies;
2667 // This cookie will be freed by the CookieMonster. 2728 // This cookie will be freed by the CookieMonster.
2668 cookies.push_back(CanonicalCookie::Create(url_google_, kValidCookieLine, 2729 cookies.push_back(CanonicalCookie::Create(
2669 Time::Now(), CookieOptions())); 2730 http_www_google_.url(), kValidCookieLine, Time::Now(), CookieOptions()));
2670 CanonicalCookie cookie = *cookies[0]; 2731 CanonicalCookie cookie = *cookies[0];
2671 scoped_refptr<NewMockPersistentCookieStore> store( 2732 scoped_refptr<NewMockPersistentCookieStore> store(
2672 new NewMockPersistentCookieStore); 2733 new NewMockPersistentCookieStore);
2673 scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL)); 2734 scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL));
2674 2735
2675 CookieMonster::PersistentCookieStore::LoadedCallback loaded_callback; 2736 CookieMonster::PersistentCookieStore::LoadedCallback loaded_callback;
2676 ::testing::StrictMock<::testing::MockFunction<void(int)>> checkpoint; 2737 ::testing::StrictMock<::testing::MockFunction<void(int)>> checkpoint;
2677 const std::string key = 2738 const std::string key = cookie_util::GetEffectiveDomain(
2678 cookie_util::GetEffectiveDomain(url_google_.scheme(), url_google_.host()); 2739 http_www_google_.url().scheme(), http_www_google_.url().host());
2679 2740
2680 ::testing::InSequence s; 2741 ::testing::InSequence s;
2681 EXPECT_CALL(checkpoint, Call(0)); 2742 EXPECT_CALL(checkpoint, Call(0));
2682 EXPECT_CALL(*store, Load(::testing::_)); 2743 EXPECT_CALL(*store, Load(::testing::_));
2683 EXPECT_CALL(*store, LoadCookiesForKey(key, ::testing::_)) 2744 EXPECT_CALL(*store, LoadCookiesForKey(key, ::testing::_))
2684 .WillOnce(::testing::SaveArg<1>(&loaded_callback)); 2745 .WillOnce(::testing::SaveArg<1>(&loaded_callback));
2685 EXPECT_CALL(checkpoint, Call(1)); 2746 EXPECT_CALL(checkpoint, Call(1));
2686 // LoadCookiesForKey will never be called after checkpoint.Call(1) although 2747 // LoadCookiesForKey will never be called after checkpoint.Call(1) although
2687 // we will call GetAllCookiesForURLAsync again, because all URLs below share 2748 // we will call GetAllCookiesForURLAsync again, because all URLs below share
2688 // the same key. 2749 // the same key.
2689 EXPECT_CALL(*store, LoadCookiesForKey(::testing::_, ::testing::_)).Times(0); 2750 EXPECT_CALL(*store, LoadCookiesForKey(::testing::_, ::testing::_)).Times(0);
2690 2751
2691 GetCookieListCallback callback; 2752 GetCookieListCallback callback;
2692 checkpoint.Call(0); 2753 checkpoint.Call(0);
2693 GetAllCookiesForURLTask(cm.get(), url_google_, &callback); 2754 GetAllCookiesForURLTask(cm.get(), http_www_google_.url(), &callback);
2694 checkpoint.Call(1); 2755 checkpoint.Call(1);
2695 ASSERT_FALSE(callback.did_run()); 2756 ASSERT_FALSE(callback.did_run());
2696 // Pass the cookies to the CookieMonster. 2757 // Pass the cookies to the CookieMonster.
2697 loaded_callback.Run(cookies); 2758 loaded_callback.Run(cookies);
2698 // Now GetAllCookiesForURLTask is done. 2759 // Now GetAllCookiesForURLTask is done.
2699 ASSERT_TRUE(callback.did_run()); 2760 ASSERT_TRUE(callback.did_run());
2700 // See that the callback was called with the cookies. 2761 // See that the callback was called with the cookies.
2701 ASSERT_EQ(1u, callback.cookies().size()); 2762 ASSERT_EQ(1u, callback.cookies().size());
2702 EXPECT_TRUE(cookie.IsEquivalent(callback.cookies()[0])); 2763 EXPECT_TRUE(cookie.IsEquivalent(callback.cookies()[0]));
2703 2764
2704 // All urls in |urls| should share the same cookie domain. 2765 // All urls in |urls| should share the same cookie domain.
2705 const GURL kUrls[] = { 2766 const GURL kUrls[] = {
2706 url_google_, 2767 http_www_google_.url(), https_www_google_.url(), ws_www_google_.url(),
2707 url_google_secure_, 2768 wss_www_google_.url(),
2708 GURL(kUrlGoogleWebSocket),
2709 GURL(kUrlGoogleWebSocketSecure),
2710 }; 2769 };
2711 for (const GURL& url : kUrls) { 2770 for (const GURL& url : kUrls) {
2712 // Call the function with |url| and verify it is done synchronously without 2771 // Call the function with |url| and verify it is done synchronously without
2713 // calling LoadCookiesForKey. 2772 // calling LoadCookiesForKey.
2714 GetCookieListCallback callback; 2773 GetCookieListCallback callback;
2715 GetAllCookiesForURLTask(cm.get(), url, &callback); 2774 GetAllCookiesForURLTask(cm.get(), url, &callback);
2716 ASSERT_TRUE(callback.did_run()); 2775 ASSERT_TRUE(callback.did_run());
2717 ASSERT_EQ(1u, callback.cookies().size()); 2776 ASSERT_EQ(1u, callback.cookies().size());
2718 EXPECT_TRUE(cookie.IsEquivalent(callback.cookies()[0])); 2777 EXPECT_TRUE(cookie.IsEquivalent(callback.cookies()[0]));
2719 } 2778 }
2720 } 2779 }
2721 2780
2722 TEST_F(CookieMonsterTest, InvalidExpiryTime) { 2781 TEST_F(CookieMonsterTest, InvalidExpiryTime) {
2723 std::string cookie_line = 2782 std::string cookie_line =
2724 std::string(kValidCookieLine) + "; expires=Blarg arg arg"; 2783 std::string(kValidCookieLine) + "; expires=Blarg arg arg";
2725 scoped_ptr<CanonicalCookie> cookie(CanonicalCookie::Create( 2784 scoped_ptr<CanonicalCookie> cookie(CanonicalCookie::Create(
2726 url_google_, cookie_line, Time::Now(), CookieOptions())); 2785 http_www_google_.url(), cookie_line, Time::Now(), CookieOptions()));
2727 ASSERT_FALSE(cookie->IsPersistent()); 2786 ASSERT_FALSE(cookie->IsPersistent());
2728 } 2787 }
2729 2788
2730 // Test that CookieMonster writes session cookies into the underlying 2789 // Test that CookieMonster writes session cookies into the underlying
2731 // CookieStore if the "persist session cookies" option is on. 2790 // CookieStore if the "persist session cookies" option is on.
2732 TEST_F(CookieMonsterTest, PersistSessionCookies) { 2791 TEST_F(CookieMonsterTest, PersistSessionCookies) {
2733 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); 2792 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore);
2734 scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL)); 2793 scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL));
2735 cm->SetPersistSessionCookies(true); 2794 cm->SetPersistSessionCookies(true);
2736 2795
2737 // All cookies set with SetCookie are session cookies. 2796 // All cookies set with SetCookie are session cookies.
2738 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "A=B")); 2797 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=B"));
2739 EXPECT_EQ("A=B", GetCookies(cm.get(), url_google_)); 2798 EXPECT_EQ("A=B", GetCookies(cm.get(), http_www_google_.url()));
2740 2799
2741 // The cookie was written to the backing store. 2800 // The cookie was written to the backing store.
2742 EXPECT_EQ(1u, store->commands().size()); 2801 EXPECT_EQ(1u, store->commands().size());
2743 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[0].type); 2802 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[0].type);
2744 EXPECT_EQ("A", store->commands()[0].cookie.Name()); 2803 EXPECT_EQ("A", store->commands()[0].cookie.Name());
2745 EXPECT_EQ("B", store->commands()[0].cookie.Value()); 2804 EXPECT_EQ("B", store->commands()[0].cookie.Value());
2746 2805
2747 // Modify the cookie. 2806 // Modify the cookie.
2748 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "A=C")); 2807 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=C"));
2749 EXPECT_EQ("A=C", GetCookies(cm.get(), url_google_)); 2808 EXPECT_EQ("A=C", GetCookies(cm.get(), http_www_google_.url()));
2750 EXPECT_EQ(3u, store->commands().size()); 2809 EXPECT_EQ(3u, store->commands().size());
2751 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[1].type); 2810 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[1].type);
2752 EXPECT_EQ("A", store->commands()[1].cookie.Name()); 2811 EXPECT_EQ("A", store->commands()[1].cookie.Name());
2753 EXPECT_EQ("B", store->commands()[1].cookie.Value()); 2812 EXPECT_EQ("B", store->commands()[1].cookie.Value());
2754 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[2].type); 2813 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[2].type);
2755 EXPECT_EQ("A", store->commands()[2].cookie.Name()); 2814 EXPECT_EQ("A", store->commands()[2].cookie.Name());
2756 EXPECT_EQ("C", store->commands()[2].cookie.Value()); 2815 EXPECT_EQ("C", store->commands()[2].cookie.Value());
2757 2816
2758 // Delete the cookie. 2817 // Delete the cookie.
2759 DeleteCookie(cm.get(), url_google_, "A"); 2818 DeleteCookie(cm.get(), http_www_google_.url(), "A");
2760 EXPECT_EQ("", GetCookies(cm.get(), url_google_)); 2819 EXPECT_EQ("", GetCookies(cm.get(), http_www_google_.url()));
2761 EXPECT_EQ(4u, store->commands().size()); 2820 EXPECT_EQ(4u, store->commands().size());
2762 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[3].type); 2821 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[3].type);
2763 EXPECT_EQ("A", store->commands()[3].cookie.Name()); 2822 EXPECT_EQ("A", store->commands()[3].cookie.Name());
2764 EXPECT_EQ("C", store->commands()[3].cookie.Value()); 2823 EXPECT_EQ("C", store->commands()[3].cookie.Value());
2765 } 2824 }
2766 2825
2767 // Test the commands sent to the persistent cookie store. 2826 // Test the commands sent to the persistent cookie store.
2768 TEST_F(CookieMonsterTest, PersisentCookieStorageTest) { 2827 TEST_F(CookieMonsterTest, PersisentCookieStorageTest) {
2769 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); 2828 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore);
2770 scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL)); 2829 scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL));
2771 2830
2772 // Add a cookie. 2831 // Add a cookie.
2773 EXPECT_TRUE(SetCookie(cm.get(), url_google_, 2832 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(),
2774 "A=B; expires=Mon, 18-Apr-22 22:50:13 GMT")); 2833 "A=B; expires=Mon, 18-Apr-22 22:50:13 GMT"));
2775 this->MatchCookieLines("A=B", GetCookies(cm.get(), url_google_)); 2834 this->MatchCookieLines("A=B", GetCookies(cm.get(), http_www_google_.url()));
2776 ASSERT_EQ(1u, store->commands().size()); 2835 ASSERT_EQ(1u, store->commands().size());
2777 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[0].type); 2836 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[0].type);
2778 // Remove it. 2837 // Remove it.
2779 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "A=B; max-age=0")); 2838 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=B; max-age=0"));
2780 this->MatchCookieLines(std::string(), GetCookies(cm.get(), url_google_)); 2839 this->MatchCookieLines(std::string(),
2840 GetCookies(cm.get(), http_www_google_.url()));
2781 ASSERT_EQ(2u, store->commands().size()); 2841 ASSERT_EQ(2u, store->commands().size());
2782 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[1].type); 2842 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[1].type);
2783 2843
2784 // Add a cookie. 2844 // Add a cookie.
2785 EXPECT_TRUE(SetCookie(cm.get(), url_google_, 2845 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(),
2786 "A=B; expires=Mon, 18-Apr-22 22:50:13 GMT")); 2846 "A=B; expires=Mon, 18-Apr-22 22:50:13 GMT"));
2787 this->MatchCookieLines("A=B", GetCookies(cm.get(), url_google_)); 2847 this->MatchCookieLines("A=B", GetCookies(cm.get(), http_www_google_.url()));
2788 ASSERT_EQ(3u, store->commands().size()); 2848 ASSERT_EQ(3u, store->commands().size());
2789 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[2].type); 2849 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[2].type);
2790 // Overwrite it. 2850 // Overwrite it.
2791 EXPECT_TRUE(SetCookie(cm.get(), url_google_, 2851 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(),
2792 "A=Foo; expires=Mon, 18-Apr-22 22:50:14 GMT")); 2852 "A=Foo; expires=Mon, 18-Apr-22 22:50:14 GMT"));
2793 this->MatchCookieLines("A=Foo", GetCookies(cm.get(), url_google_)); 2853 this->MatchCookieLines("A=Foo", GetCookies(cm.get(), http_www_google_.url()));
2794 ASSERT_EQ(5u, store->commands().size()); 2854 ASSERT_EQ(5u, store->commands().size());
2795 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[3].type); 2855 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[3].type);
2796 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[4].type); 2856 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[4].type);
2797 2857
2798 // Create some non-persistent cookies and check that they don't go to the 2858 // Create some non-persistent cookies and check that they don't go to the
2799 // persistent storage. 2859 // persistent storage.
2800 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "B=Bar")); 2860 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "B=Bar"));
2801 this->MatchCookieLines("A=Foo; B=Bar", GetCookies(cm.get(), url_google_)); 2861 this->MatchCookieLines("A=Foo; B=Bar",
2862 GetCookies(cm.get(), http_www_google_.url()));
2802 EXPECT_EQ(5u, store->commands().size()); 2863 EXPECT_EQ(5u, store->commands().size());
2803 } 2864 }
2804 2865
2805 // Test to assure that cookies with control characters are purged appropriately. 2866 // Test to assure that cookies with control characters are purged appropriately.
2806 // See http://crbug.com/238041 for background. 2867 // See http://crbug.com/238041 for background.
2807 TEST_F(CookieMonsterTest, ControlCharacterPurge) { 2868 TEST_F(CookieMonsterTest, ControlCharacterPurge) {
2808 const Time now1(Time::Now()); 2869 const Time now1(Time::Now());
2809 const Time now2(Time::Now() + TimeDelta::FromSeconds(1)); 2870 const Time now2(Time::Now() + TimeDelta::FromSeconds(1));
2810 const Time now3(Time::Now() + TimeDelta::FromSeconds(2)); 2871 const Time now3(Time::Now() + TimeDelta::FromSeconds(2));
2811 const Time later(now1 + TimeDelta::FromDays(1)); 2872 const Time later(now1 + TimeDelta::FromDays(1));
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
2843 TEST_F(CookieMonsterTest, CookieSourceHistogram) { 2904 TEST_F(CookieMonsterTest, CookieSourceHistogram) {
2844 base::HistogramTester histograms; 2905 base::HistogramTester histograms;
2845 const std::string cookie_source_histogram = "Cookie.CookieSourceScheme"; 2906 const std::string cookie_source_histogram = "Cookie.CookieSourceScheme";
2846 2907
2847 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); 2908 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore);
2848 scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL)); 2909 scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL));
2849 2910
2850 histograms.ExpectTotalCount(cookie_source_histogram, 0); 2911 histograms.ExpectTotalCount(cookie_source_histogram, 0);
2851 2912
2852 // Set a Secure cookie on a cryptographic scheme. 2913 // Set a Secure cookie on a cryptographic scheme.
2853 EXPECT_TRUE(SetCookie(cm.get(), url_google_secure_, "A=B; path=/; Secure")); 2914 EXPECT_TRUE(
2915 SetCookie(cm.get(), https_www_google_.url(), "A=B; path=/; Secure"));
2854 histograms.ExpectTotalCount(cookie_source_histogram, 1); 2916 histograms.ExpectTotalCount(cookie_source_histogram, 1);
2855 histograms.ExpectBucketCount( 2917 histograms.ExpectBucketCount(
2856 cookie_source_histogram, 2918 cookie_source_histogram,
2857 CookieMonster::COOKIE_SOURCE_SECURE_COOKIE_CRYPTOGRAPHIC_SCHEME, 1); 2919 CookieMonster::COOKIE_SOURCE_SECURE_COOKIE_CRYPTOGRAPHIC_SCHEME, 1);
2858 2920
2859 // Set a non-Secure cookie on a cryptographic scheme. 2921 // Set a non-Secure cookie on a cryptographic scheme.
2860 EXPECT_TRUE(SetCookie(cm.get(), url_google_secure_, "C=D; path=/;")); 2922 EXPECT_TRUE(SetCookie(cm.get(), https_www_google_.url(), "C=D; path=/;"));
2861 histograms.ExpectTotalCount(cookie_source_histogram, 2); 2923 histograms.ExpectTotalCount(cookie_source_histogram, 2);
2862 histograms.ExpectBucketCount( 2924 histograms.ExpectBucketCount(
2863 cookie_source_histogram, 2925 cookie_source_histogram,
2864 CookieMonster::COOKIE_SOURCE_NONSECURE_COOKIE_CRYPTOGRAPHIC_SCHEME, 1); 2926 CookieMonster::COOKIE_SOURCE_NONSECURE_COOKIE_CRYPTOGRAPHIC_SCHEME, 1);
2865 2927
2866 // Set a Secure cookie on a non-cryptographic scheme. 2928 // Set a Secure cookie on a non-cryptographic scheme.
2867 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "D=E; path=/; Secure")); 2929 EXPECT_TRUE(
2930 SetCookie(cm.get(), http_www_google_.url(), "D=E; path=/; Secure"));
2868 histograms.ExpectTotalCount(cookie_source_histogram, 3); 2931 histograms.ExpectTotalCount(cookie_source_histogram, 3);
2869 histograms.ExpectBucketCount( 2932 histograms.ExpectBucketCount(
2870 cookie_source_histogram, 2933 cookie_source_histogram,
2871 CookieMonster::COOKIE_SOURCE_SECURE_COOKIE_NONCRYPTOGRAPHIC_SCHEME, 1); 2934 CookieMonster::COOKIE_SOURCE_SECURE_COOKIE_NONCRYPTOGRAPHIC_SCHEME, 1);
2872 2935
2873 // Overwrite a Secure cookie (set by a cryptographic scheme) on a 2936 // Overwrite a Secure cookie (set by a cryptographic scheme) on a
2874 // non-cryptographic scheme. 2937 // non-cryptographic scheme.
2875 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "A=B; path=/; Secure")); 2938 EXPECT_TRUE(
2939 SetCookie(cm.get(), http_www_google_.url(), "A=B; path=/; Secure"));
2876 histograms.ExpectTotalCount(cookie_source_histogram, 4); 2940 histograms.ExpectTotalCount(cookie_source_histogram, 4);
2877 histograms.ExpectBucketCount( 2941 histograms.ExpectBucketCount(
2878 cookie_source_histogram, 2942 cookie_source_histogram,
2879 CookieMonster::COOKIE_SOURCE_SECURE_COOKIE_CRYPTOGRAPHIC_SCHEME, 1); 2943 CookieMonster::COOKIE_SOURCE_SECURE_COOKIE_CRYPTOGRAPHIC_SCHEME, 1);
2880 histograms.ExpectBucketCount( 2944 histograms.ExpectBucketCount(
2881 cookie_source_histogram, 2945 cookie_source_histogram,
2882 CookieMonster::COOKIE_SOURCE_SECURE_COOKIE_NONCRYPTOGRAPHIC_SCHEME, 2); 2946 CookieMonster::COOKIE_SOURCE_SECURE_COOKIE_NONCRYPTOGRAPHIC_SCHEME, 2);
2883 2947
2884 // Test that clearing a Secure cookie on a http:// URL does not get 2948 // Test that clearing a Secure cookie on a http:// URL does not get
2885 // counted. 2949 // counted.
2886 EXPECT_TRUE(SetCookie(cm.get(), url_google_secure_, "F=G; path=/; Secure")); 2950 EXPECT_TRUE(
2951 SetCookie(cm.get(), https_www_google_.url(), "F=G; path=/; Secure"));
2887 histograms.ExpectTotalCount(cookie_source_histogram, 5); 2952 histograms.ExpectTotalCount(cookie_source_histogram, 5);
2888 std::string cookies1 = GetCookies(cm.get(), url_google_secure_); 2953 std::string cookies1 = GetCookies(cm.get(), https_www_google_.url());
2889 EXPECT_NE(std::string::npos, cookies1.find("F=G")); 2954 EXPECT_NE(std::string::npos, cookies1.find("F=G"));
2890 EXPECT_TRUE(SetCookie(cm.get(), url_google_, 2955 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(),
2891 "F=G; path=/; Expires=Thu, 01-Jan-1970 00:00:01 GMT")); 2956 "F=G; path=/; Expires=Thu, 01-Jan-1970 00:00:01 GMT"));
2892 std::string cookies2 = GetCookies(cm.get(), url_google_secure_); 2957 std::string cookies2 = GetCookies(cm.get(), https_www_google_.url());
2893 EXPECT_EQ(std::string::npos, cookies2.find("F=G")); 2958 EXPECT_EQ(std::string::npos, cookies2.find("F=G"));
2894 histograms.ExpectTotalCount(cookie_source_histogram, 5); 2959 histograms.ExpectTotalCount(cookie_source_histogram, 5);
2895 2960
2896 // Set a non-Secure cookie on a non-cryptographic scheme. 2961 // Set a non-Secure cookie on a non-cryptographic scheme.
2897 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "H=I; path=/")); 2962 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "H=I; path=/"));
2898 histograms.ExpectTotalCount(cookie_source_histogram, 6); 2963 histograms.ExpectTotalCount(cookie_source_histogram, 6);
2899 histograms.ExpectBucketCount( 2964 histograms.ExpectBucketCount(
2900 cookie_source_histogram, 2965 cookie_source_histogram,
2901 CookieMonster::COOKIE_SOURCE_NONSECURE_COOKIE_NONCRYPTOGRAPHIC_SCHEME, 1); 2966 CookieMonster::COOKIE_SOURCE_NONSECURE_COOKIE_NONCRYPTOGRAPHIC_SCHEME, 1);
2902 } 2967 }
2903 2968
2904 class CookieMonsterNotificationTest : public CookieMonsterTest { 2969 class CookieMonsterNotificationTest : public CookieMonsterTest {
2905 public: 2970 public:
2906 CookieMonsterNotificationTest() 2971 CookieMonsterNotificationTest()
2907 : test_url_("http://www.google.com/foo"), 2972 : test_url_("http://www.google.com/foo"),
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
3051 monster()->AddCallbackForCookie( 3116 monster()->AddCallbackForCookie(
3052 test_url_, "abc", 3117 test_url_, "abc",
3053 base::Bind(&RecordCookieChanges, &cookies1, nullptr))); 3118 base::Bind(&RecordCookieChanges, &cookies1, nullptr)));
3054 SetCookie(monster(), test_url_, "abc=def"); 3119 SetCookie(monster(), test_url_, "abc=def");
3055 base::MessageLoop::current()->RunUntilIdle(); 3120 base::MessageLoop::current()->RunUntilIdle();
3056 EXPECT_EQ(1U, cookies0.size()); 3121 EXPECT_EQ(1U, cookies0.size());
3057 EXPECT_EQ(1U, cookies0.size()); 3122 EXPECT_EQ(1U, cookies0.size());
3058 } 3123 }
3059 3124
3060 } // namespace net 3125 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/cookies/cookie_store_test_helpers.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698