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

Side by Side Diff: net/base/cookie_store_unittest.h

Issue 9309117: Unittest for CookieStore::DeleteAllCreatedBetweenAsync(). (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Attempt at fixing windows build Created 8 years, 10 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 | no next file » | 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 #ifndef NET_BASE_COOKIE_STORE_UNITTEST_H_ 5 #ifndef NET_BASE_COOKIE_STORE_UNITTEST_H_
6 #define NET_BASE_COOKIE_STORE_UNITTEST_H_ 6 #define NET_BASE_COOKIE_STORE_UNITTEST_H_
7 #pragma once 7 #pragma once
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 const std::string& cookie_name) { 155 const std::string& cookie_name) {
156 DCHECK(cs); 156 DCHECK(cs);
157 DeleteCookieCallback callback; 157 DeleteCookieCallback callback;
158 cs->DeleteCookieAsync( 158 cs->DeleteCookieAsync(
159 url, cookie_name, 159 url, cookie_name,
160 base::Bind(&DeleteCookieCallback::Run, base::Unretained(&callback))); 160 base::Bind(&DeleteCookieCallback::Run, base::Unretained(&callback)));
161 RunFor(kTimeout); 161 RunFor(kTimeout);
162 EXPECT_TRUE(callback.did_run()); 162 EXPECT_TRUE(callback.did_run());
163 } 163 }
164 164
165 int DeleteCreatedBetween(CookieStore* cs,
166 const base::Time& delete_begin,
167 const base::Time& delete_end) {
168 DCHECK(cs);
169 DeleteCallback callback;
170 cs->DeleteAllCreatedBetweenAsync(
171 delete_begin, delete_end,
172 base::Bind(&DeleteCallback::Run, base::Unretained(&callback)));
173 RunFor(kTimeout);
174 EXPECT_TRUE(callback.did_run());
175 return callback.num_deleted();
176 }
177
165 void RunFor(int ms) { 178 void RunFor(int ms) {
166 // Runs the test thread message loop for up to |ms| milliseconds. 179 // Runs the test thread message loop for up to |ms| milliseconds.
167 MessageLoop::current()->PostDelayedTask( 180 MessageLoop::current()->PostDelayedTask(
168 FROM_HERE, base::Bind(&MessageLoop::Quit, weak_factory_.GetWeakPtr()), 181 FROM_HERE, base::Bind(&MessageLoop::Quit, weak_factory_.GetWeakPtr()),
169 base::TimeDelta::FromMilliseconds(ms)); 182 base::TimeDelta::FromMilliseconds(ms));
170 MessageLoop::current()->Run(); 183 MessageLoop::current()->Run();
171 weak_factory_.InvalidateWeakPtrs(); 184 weak_factory_.InvalidateWeakPtrs();
172 } 185 }
173 186
174 scoped_refptr<CookieStore> GetCookieStore() { 187 scoped_refptr<CookieStore> GetCookieStore() {
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after
671 std::string(kValidCookieLine) + 684 std::string(kValidCookieLine) +
672 "; expires=Mon, 18-Apr-22 22:50:13 GMT")); 685 "; expires=Mon, 18-Apr-22 22:50:13 GMT"));
673 this->MatchCookieLines("A=B", this->GetCookies(cs, this->url_google_)); 686 this->MatchCookieLines("A=B", this->GetCookies(cs, this->url_google_));
674 // Delete it via Expires, with a unix epoch of 0. 687 // Delete it via Expires, with a unix epoch of 0.
675 EXPECT_TRUE(this->SetCookie(cs, this->url_google_, 688 EXPECT_TRUE(this->SetCookie(cs, this->url_google_,
676 std::string(kValidCookieLine) + 689 std::string(kValidCookieLine) +
677 "; expires=Thu, 1-Jan-1970 00:00:00 GMT")); 690 "; expires=Thu, 1-Jan-1970 00:00:00 GMT"));
678 this->MatchCookieLines("", this->GetCookies(cs, this->url_google_)); 691 this->MatchCookieLines("", this->GetCookies(cs, this->url_google_));
679 } 692 }
680 693
694 TYPED_TEST_P(CookieStoreTest, TestDeleteAllCreatedBetween) {
695 scoped_refptr<CookieStore> cs(this->GetCookieStore());
696 const base::Time last_month = base::Time::Now() -
697 base::TimeDelta::FromDays(30);
698 const base::Time last_minute = base::Time::Now() -
699 base::TimeDelta::FromMinutes(1);
700 const base::Time next_minute = base::Time::Now() +
701 base::TimeDelta::FromMinutes(1);
702 const base::Time next_month = base::Time::Now() +
703 base::TimeDelta::FromDays(30);
704
705 // Add a cookie.
706 EXPECT_TRUE(this->SetCookie(cs, this->url_google_, "A=B"));
707 // Check that the cookie is in the store.
708 this->MatchCookieLines("A=B", this->GetCookies(cs, this->url_google_));
709
710 // Remove cookies in empty intervals.
711 EXPECT_EQ(0, this->DeleteCreatedBetween(cs, last_month, last_minute));
712 EXPECT_EQ(0, this->DeleteCreatedBetween(cs, next_minute, next_month));
713 // Check that the cookie is still there.
714 this->MatchCookieLines("A=B", this->GetCookies(cs, this->url_google_));
715
716 // Remove the cookie with an interval defined by two dates.
717 EXPECT_EQ(1, this->DeleteCreatedBetween(cs, last_minute, next_minute));
718 // Check that the cookie disappeared.
719 this->MatchCookieLines("", this->GetCookies(cs, this->url_google_));
720
721 // Add another cookie.
722 EXPECT_TRUE(this->SetCookie(cs, this->url_google_, "C=D"));
723 // Check that the cookie is in the store.
724 this->MatchCookieLines("C=D", this->GetCookies(cs, this->url_google_));
725
726 // Remove the cookie with a null ending time.
727 EXPECT_EQ(1, this->DeleteCreatedBetween(cs, last_minute, base::Time()));
728 // Check that the cookie disappeared.
729 this->MatchCookieLines("", this->GetCookies(cs, this->url_google_));
730 }
731
681 TYPED_TEST_P(CookieStoreTest, TestSecure) { 732 TYPED_TEST_P(CookieStoreTest, TestSecure) {
682 scoped_refptr<CookieStore> cs(this->GetCookieStore()); 733 scoped_refptr<CookieStore> cs(this->GetCookieStore());
683 734
684 EXPECT_TRUE(this->SetCookie(cs, this->url_google_, "A=B")); 735 EXPECT_TRUE(this->SetCookie(cs, this->url_google_, "A=B"));
685 this->MatchCookieLines("A=B", this->GetCookies(cs, this->url_google_)); 736 this->MatchCookieLines("A=B", this->GetCookies(cs, this->url_google_));
686 this->MatchCookieLines("A=B", this->GetCookies(cs, this->url_google_secure_)); 737 this->MatchCookieLines("A=B", this->GetCookies(cs, this->url_google_secure_));
687 738
688 EXPECT_TRUE(this->SetCookie(cs, this->url_google_secure_, "A=B; secure")); 739 EXPECT_TRUE(this->SetCookie(cs, this->url_google_secure_, "A=B; secure"));
689 // The secure should overwrite the non-secure. 740 // The secure should overwrite the non-secure.
690 this->MatchCookieLines("", this->GetCookies(cs, this->url_google_)); 741 this->MatchCookieLines("", this->GetCookies(cs, this->url_google_));
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
803 "g=10")); 854 "g=10"));
804 EXPECT_EQ("d=1; a=4; e=1; b=1; c=1", 855 EXPECT_EQ("d=1; a=4; e=1; b=1; c=1",
805 this->GetCookies(cs, GURL("http://d.c.b.a.google.com/aa/bb/cc/dd"))); 856 this->GetCookies(cs, GURL("http://d.c.b.a.google.com/aa/bb/cc/dd")));
806 } 857 }
807 858
808 REGISTER_TYPED_TEST_CASE_P(CookieStoreTest, 859 REGISTER_TYPED_TEST_CASE_P(CookieStoreTest,
809 TypeTest, DomainTest, DomainWithTrailingDotTest, ValidSubdomainTest, 860 TypeTest, DomainTest, DomainWithTrailingDotTest, ValidSubdomainTest,
810 InvalidDomainTest, DomainWithoutLeadingDotTest, CaseInsensitiveDomainTest, 861 InvalidDomainTest, DomainWithoutLeadingDotTest, CaseInsensitiveDomainTest,
811 TestIpAddress, TestNonDottedAndTLD, TestHostEndsWithDot, InvalidScheme, 862 TestIpAddress, TestNonDottedAndTLD, TestHostEndsWithDot, InvalidScheme,
812 InvalidScheme_Read, PathTest, HttpOnlyTest, TestGetCookiesWithInfo, 863 InvalidScheme_Read, PathTest, HttpOnlyTest, TestGetCookiesWithInfo,
813 TestCookieDeletion, TestSecure, NetUtilCookieTest, 864 TestCookieDeletion, TestDeleteAllCreatedBetween, TestSecure,
814 OverwritePersistentCookie, CookieOrdering); 865 NetUtilCookieTest, OverwritePersistentCookie, CookieOrdering);
815 866
816 template<class CookieStoreTestTraits> 867 template<class CookieStoreTestTraits>
817 class MultiThreadedCookieStoreTest : 868 class MultiThreadedCookieStoreTest :
818 public CookieStoreTest<CookieStoreTestTraits> { 869 public CookieStoreTest<CookieStoreTestTraits> {
819 public: 870 public:
820 MultiThreadedCookieStoreTest() : other_thread_("CMTthread") {} 871 MultiThreadedCookieStoreTest() : other_thread_("CMTthread") {}
821 872
822 // Helper methods for calling the asynchronous CookieStore methods 873 // Helper methods for calling the asynchronous CookieStore methods
823 // from a different thread. 874 // from a different thread.
824 875
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
984 } 1035 }
985 1036
986 REGISTER_TYPED_TEST_CASE_P(MultiThreadedCookieStoreTest, 1037 REGISTER_TYPED_TEST_CASE_P(MultiThreadedCookieStoreTest,
987 ThreadCheckGetCookies, ThreadCheckGetCookiesWithOptions, 1038 ThreadCheckGetCookies, ThreadCheckGetCookiesWithOptions,
988 ThreadCheckGetCookiesWithInfo, ThreadCheckSetCookieWithOptions, 1039 ThreadCheckGetCookiesWithInfo, ThreadCheckSetCookieWithOptions,
989 ThreadCheckDeleteCookie); 1040 ThreadCheckDeleteCookie);
990 1041
991 } // namespace net 1042 } // namespace net
992 1043
993 #endif // NET_BASE_COOKIE_STORE_UNITTEST_H_ 1044 #endif // NET_BASE_COOKIE_STORE_UNITTEST_H_
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698