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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/cookie_store_unittest.h
diff --git a/net/base/cookie_store_unittest.h b/net/base/cookie_store_unittest.h
index a537c9a695e00ce7f006e773063304da8e007134..d43ff91d5191e0617e854944bb00d6e3bb82423b 100644
--- a/net/base/cookie_store_unittest.h
+++ b/net/base/cookie_store_unittest.h
@@ -162,6 +162,19 @@ class CookieStoreTest : public testing::Test {
EXPECT_TRUE(callback.did_run());
}
+ int DeleteCreatedBetween(CookieStore* cs,
+ const base::Time& delete_begin,
+ const base::Time& delete_end) {
+ DCHECK(cs);
+ DeleteCallback callback;
+ cs->DeleteAllCreatedBetweenAsync(
+ delete_begin, delete_end,
+ base::Bind(&DeleteCallback::Run, base::Unretained(&callback)));
+ RunFor(kTimeout);
+ EXPECT_TRUE(callback.did_run());
+ return callback.num_deleted();
+ }
+
void RunFor(int ms) {
// Runs the test thread message loop for up to |ms| milliseconds.
MessageLoop::current()->PostDelayedTask(
@@ -678,6 +691,44 @@ TYPED_TEST_P(CookieStoreTest, TestCookieDeletion) {
this->MatchCookieLines("", this->GetCookies(cs, this->url_google_));
}
+TYPED_TEST_P(CookieStoreTest, TestDeleteAllCreatedBetween) {
+ scoped_refptr<CookieStore> cs(this->GetCookieStore());
+ const base::Time last_month = base::Time::Now() -
+ base::TimeDelta::FromDays(30);
+ const base::Time last_minute = base::Time::Now() -
+ base::TimeDelta::FromMinutes(1);
+ const base::Time next_minute = base::Time::Now() +
+ base::TimeDelta::FromMinutes(1);
+ const base::Time next_month = base::Time::Now() +
+ base::TimeDelta::FromDays(30);
+
+ // Add a cookie.
+ EXPECT_TRUE(this->SetCookie(cs, this->url_google_, "A=B"));
+ // Check that the cookie is in the store.
+ this->MatchCookieLines("A=B", this->GetCookies(cs, this->url_google_));
+
+ // Remove cookies in empty intervals.
+ EXPECT_EQ(0, this->DeleteCreatedBetween(cs, last_month, last_minute));
+ EXPECT_EQ(0, this->DeleteCreatedBetween(cs, next_minute, next_month));
+ // Check that the cookie is still there.
+ this->MatchCookieLines("A=B", this->GetCookies(cs, this->url_google_));
+
+ // Remove the cookie with an interval defined by two dates.
+ EXPECT_EQ(1, this->DeleteCreatedBetween(cs, last_minute, next_minute));
+ // Check that the cookie disappeared.
+ this->MatchCookieLines("", this->GetCookies(cs, this->url_google_));
+
+ // Add another cookie.
+ EXPECT_TRUE(this->SetCookie(cs, this->url_google_, "C=D"));
+ // Check that the cookie is in the store.
+ this->MatchCookieLines("C=D", this->GetCookies(cs, this->url_google_));
+
+ // Remove the cookie with a null ending time.
+ EXPECT_EQ(1, this->DeleteCreatedBetween(cs, last_minute, base::Time()));
+ // Check that the cookie disappeared.
+ this->MatchCookieLines("", this->GetCookies(cs, this->url_google_));
+}
+
TYPED_TEST_P(CookieStoreTest, TestSecure) {
scoped_refptr<CookieStore> cs(this->GetCookieStore());
@@ -810,8 +861,8 @@ REGISTER_TYPED_TEST_CASE_P(CookieStoreTest,
InvalidDomainTest, DomainWithoutLeadingDotTest, CaseInsensitiveDomainTest,
TestIpAddress, TestNonDottedAndTLD, TestHostEndsWithDot, InvalidScheme,
InvalidScheme_Read, PathTest, HttpOnlyTest, TestGetCookiesWithInfo,
- TestCookieDeletion, TestSecure, NetUtilCookieTest,
- OverwritePersistentCookie, CookieOrdering);
+ TestCookieDeletion, TestDeleteAllCreatedBetween, TestSecure,
+ NetUtilCookieTest, OverwritePersistentCookie, CookieOrdering);
template<class CookieStoreTestTraits>
class MultiThreadedCookieStoreTest :
« 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