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

Unified Diff: net/cookies/cookie_store_unittest.h

Issue 1844243002: [CookieStore] Upgrading host-based deleting to predicate-based deleting. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added android changes Created 4 years, 9 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
Index: net/cookies/cookie_store_unittest.h
diff --git a/net/cookies/cookie_store_unittest.h b/net/cookies/cookie_store_unittest.h
index ce8008f21b517539fbe4756c87d7bc5ab8fb0017..f20ae0ec6a509deef2552e869fe1c707ee0cd341 100644
--- a/net/cookies/cookie_store_unittest.h
+++ b/net/cookies/cookie_store_unittest.h
@@ -248,11 +248,26 @@ class CookieStoreTest : public testing::Test {
const GURL& url) {
DCHECK(cs);
ResultSavingCookieCallback<int> callback;
- cs->DeleteAllCreatedBetweenForHostAsync(
- delete_begin, delete_end, url,
- base::Bind(
- &ResultSavingCookieCallback<int>::Run,
- base::Unretained(&callback)));
+ cs->DeleteAllCreatedBetweenWithPredicateAsync(
+ delete_begin, delete_end,
+ CookieStore::CreatePredicateForHostCookies(url),
+ base::Bind(&ResultSavingCookieCallback<int>::Run,
+ base::Unretained(&callback)));
+ callback.WaitUntilDone();
+ return callback.result();
+ }
+
+ int DeleteAllCreatedBetweenWithPredicate(
+ CookieStore* cs,
+ const base::Time delete_begin,
+ const base::Time delete_end,
+ const CookieStore::CookiePredicate& predicate) {
+ DCHECK(cs);
+ ResultSavingCookieCallback<int> callback;
+ cs->DeleteAllCreatedBetweenWithPredicateAsync(
+ delete_begin, delete_end, predicate,
+ base::Bind(&ResultSavingCookieCallback<int>::Run,
+ base::Unretained(&callback)));
callback.WaitUntilDone();
return callback.result();
}
@@ -1063,6 +1078,34 @@ TYPED_TEST_P(CookieStoreTest, TestDeleteAllCreatedBetweenForHost) {
this->http_www_google_.url()));
}
+namespace {
+static bool CookieHasValue(const std::string& value,
+ const CanonicalCookie& cookie) {
+ return cookie.Value() == value;
+}
+}
+
+TYPED_TEST_P(CookieStoreTest, TestDeleteAllCreatedBetweenWithPredicate) {
+ CookieStore* cs = this->GetCookieStore();
+ GURL url_not_google("http://www.notgoogle.com");
Mike West 2016/04/01 07:40:52 Nit: You could use `this->http_foo_com_.url()` ins
dmurph 2016/04/01 23:16:46 done.
+ base::Time now = base::Time::Now();
+ std::string desired_value("B");
+
+ // These 3 cookies match the time range and host.
+ EXPECT_TRUE(this->SetCookie(cs, this->http_www_google_.url(), "A=B"));
+ EXPECT_TRUE(this->SetCookie(cs, this->http_www_google_.url(), "C=D"));
+ EXPECT_TRUE(this->SetCookie(cs, this->http_www_google_.url(), "Y=Z"));
+
+ // This cookie does not match host.
+ EXPECT_TRUE(this->SetCookie(cs, url_not_google, "E=B"));
+
+ // Delete cookies.
+ EXPECT_EQ(2, // Deletes A=B, C=D, Y=Z
Mike West 2016/04/01 07:40:52 This doesn't delete `A=B`, does it? It would be g
dmurph 2016/04/01 23:16:46 Done.
+ this->DeleteAllCreatedBetweenWithPredicate(
+ cs, now, base::Time::Max(),
+ base::Bind(&CookieHasValue, desired_value)));
+}
+
TYPED_TEST_P(CookieStoreTest, TestSecure) {
CookieStore* cs = this->GetCookieStore();
@@ -1373,6 +1416,7 @@ REGISTER_TYPED_TEST_CASE_P(CookieStoreTest,
TestDeleteAll,
TestDeleteAllCreatedBetween,
TestDeleteAllCreatedBetweenForHost,
+ TestDeleteAllCreatedBetweenWithPredicate,
TestSecure,
NetUtilCookieTest,
OverwritePersistentCookie,

Powered by Google App Engine
This is Rietveld 408576698