| OLD | NEW |
| 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_COOKIES_COOKIE_STORE_UNITTEST_H_ | 5 #ifndef NET_COOKIES_COOKIE_STORE_UNITTEST_H_ |
| 6 #define NET_COOKIES_COOKIE_STORE_UNITTEST_H_ | 6 #define NET_COOKIES_COOKIE_STORE_UNITTEST_H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 ResultSavingCookieCallback<int> callback; | 235 ResultSavingCookieCallback<int> callback; |
| 236 cs->DeleteAllCreatedBetweenAsync( | 236 cs->DeleteAllCreatedBetweenAsync( |
| 237 delete_begin, delete_end, | 237 delete_begin, delete_end, |
| 238 base::Bind( | 238 base::Bind( |
| 239 &ResultSavingCookieCallback<int>::Run, | 239 &ResultSavingCookieCallback<int>::Run, |
| 240 base::Unretained(&callback))); | 240 base::Unretained(&callback))); |
| 241 callback.WaitUntilDone(); | 241 callback.WaitUntilDone(); |
| 242 return callback.result(); | 242 return callback.result(); |
| 243 } | 243 } |
| 244 | 244 |
| 245 int DeleteAllCreatedBetweenForHost(CookieStore* cs, | 245 int DeleteAllCreatedBetweenWithPredicate( |
| 246 const base::Time delete_begin, | 246 CookieStore* cs, |
| 247 const base::Time delete_end, | 247 const base::Time delete_begin, |
| 248 const GURL& url) { | 248 const base::Time delete_end, |
| 249 const CookieStore::CookiePredicate& predicate) { |
| 249 DCHECK(cs); | 250 DCHECK(cs); |
| 250 ResultSavingCookieCallback<int> callback; | 251 ResultSavingCookieCallback<int> callback; |
| 251 cs->DeleteAllCreatedBetweenForHostAsync( | 252 cs->DeleteAllCreatedBetweenWithPredicateAsync( |
| 252 delete_begin, delete_end, url, | 253 delete_begin, delete_end, predicate, |
| 253 base::Bind( | 254 base::Bind(&ResultSavingCookieCallback<int>::Run, |
| 254 &ResultSavingCookieCallback<int>::Run, | 255 base::Unretained(&callback))); |
| 255 base::Unretained(&callback))); | |
| 256 callback.WaitUntilDone(); | 256 callback.WaitUntilDone(); |
| 257 return callback.result(); | 257 return callback.result(); |
| 258 } | 258 } |
| 259 | 259 |
| 260 int DeleteSessionCookies(CookieStore* cs) { | 260 int DeleteSessionCookies(CookieStore* cs) { |
| 261 DCHECK(cs); | 261 DCHECK(cs); |
| 262 ResultSavingCookieCallback<int> callback; | 262 ResultSavingCookieCallback<int> callback; |
| 263 cs->DeleteSessionCookiesAsync( | 263 cs->DeleteSessionCookiesAsync( |
| 264 base::Bind( | 264 base::Bind( |
| 265 &ResultSavingCookieCallback<int>::Run, | 265 &ResultSavingCookieCallback<int>::Run, |
| (...skipping 771 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1037 this->MatchCookieLines("C=D", | 1037 this->MatchCookieLines("C=D", |
| 1038 this->GetCookies(cs, this->http_www_google_.url())); | 1038 this->GetCookies(cs, this->http_www_google_.url())); |
| 1039 | 1039 |
| 1040 // Remove the cookie with a null ending time. | 1040 // Remove the cookie with a null ending time. |
| 1041 EXPECT_EQ(1, this->DeleteCreatedBetween(cs, last_minute, base::Time())); | 1041 EXPECT_EQ(1, this->DeleteCreatedBetween(cs, last_minute, base::Time())); |
| 1042 // Check that the cookie disappeared. | 1042 // Check that the cookie disappeared. |
| 1043 this->MatchCookieLines(std::string(), | 1043 this->MatchCookieLines(std::string(), |
| 1044 this->GetCookies(cs, this->http_www_google_.url())); | 1044 this->GetCookies(cs, this->http_www_google_.url())); |
| 1045 } | 1045 } |
| 1046 | 1046 |
| 1047 TYPED_TEST_P(CookieStoreTest, TestDeleteAllCreatedBetweenForHost) { | 1047 namespace { |
| 1048 static bool CookieHasValue(const std::string& value, |
| 1049 const CanonicalCookie& cookie) { |
| 1050 return cookie.Value() == value; |
| 1051 } |
| 1052 } |
| 1053 |
| 1054 TYPED_TEST_P(CookieStoreTest, TestDeleteAllCreatedBetweenWithPredicate) { |
| 1048 CookieStore* cs = this->GetCookieStore(); | 1055 CookieStore* cs = this->GetCookieStore(); |
| 1049 GURL url_not_google("http://www.notgoogle.com"); | |
| 1050 base::Time now = base::Time::Now(); | 1056 base::Time now = base::Time::Now(); |
| 1057 base::Time last_month = base::Time::Now() - base::TimeDelta::FromDays(30); |
| 1058 base::Time last_minute = base::Time::Now() - base::TimeDelta::FromMinutes(1); |
| 1059 std::string desired_value("B"); |
| 1051 | 1060 |
| 1052 // These 3 cookies match the time range and host. | 1061 // These 3 cookies match the time range and host. |
| 1053 EXPECT_TRUE(this->SetCookie(cs, this->http_www_google_.url(), "A=B")); | 1062 EXPECT_TRUE(this->SetCookie(cs, this->http_www_google_.url(), "A=B")); |
| 1054 EXPECT_TRUE(this->SetCookie(cs, this->http_www_google_.url(), "C=D")); | 1063 EXPECT_TRUE(this->SetCookie(cs, this->http_www_google_.url(), "C=D")); |
| 1055 EXPECT_TRUE(this->SetCookie(cs, this->http_www_google_.url(), "Y=Z")); | 1064 EXPECT_TRUE(this->SetCookie(cs, this->http_www_google_.url(), "Y=Z")); |
| 1056 | 1065 EXPECT_TRUE(this->SetCookie(cs, this->https_www_google_.url(), "E=B")); |
| 1057 // This cookie does not match host. | |
| 1058 EXPECT_TRUE(this->SetCookie(cs, url_not_google, "E=F")); | |
| 1059 | 1066 |
| 1060 // Delete cookies. | 1067 // Delete cookies. |
| 1061 EXPECT_EQ(3, // Deletes A=B, C=D, Y=Z | 1068 EXPECT_EQ(2, // Deletes A=B, E=B |
| 1062 this->DeleteAllCreatedBetweenForHost(cs, now, base::Time::Max(), | 1069 this->DeleteAllCreatedBetweenWithPredicate( |
| 1063 this->http_www_google_.url())); | 1070 cs, now, base::Time::Max(), |
| 1071 base::Bind(&CookieHasValue, desired_value))); |
| 1072 |
| 1073 // Check that we deleted the right ones. |
| 1074 this->MatchCookieLines("C=D;Y=Z", |
| 1075 this->GetCookies(cs, this->https_www_google_.url())); |
| 1076 |
| 1077 // Now check that using a null predicate will do nothing. |
| 1078 EXPECT_EQ(0, this->DeleteAllCreatedBetweenWithPredicate( |
| 1079 cs, now, base::Time::Max(), CookieStore::CookiePredicate())); |
| 1080 |
| 1081 // Finally, check that we don't delete cookies when our time range is off. |
| 1082 desired_value = "D"; |
| 1083 EXPECT_EQ(0, this->DeleteAllCreatedBetweenWithPredicate( |
| 1084 cs, last_month, last_minute, |
| 1085 base::Bind(&CookieHasValue, desired_value))); |
| 1086 this->MatchCookieLines("C=D;Y=Z", |
| 1087 this->GetCookies(cs, this->https_www_google_.url())); |
| 1088 // Same thing, but with a good time range. |
| 1089 EXPECT_EQ(1, this->DeleteAllCreatedBetweenWithPredicate( |
| 1090 cs, now, base::Time::Max(), |
| 1091 base::Bind(&CookieHasValue, desired_value))); |
| 1092 this->MatchCookieLines("Y=Z", |
| 1093 this->GetCookies(cs, this->https_www_google_.url())); |
| 1064 } | 1094 } |
| 1065 | 1095 |
| 1066 TYPED_TEST_P(CookieStoreTest, TestSecure) { | 1096 TYPED_TEST_P(CookieStoreTest, TestSecure) { |
| 1067 CookieStore* cs = this->GetCookieStore(); | 1097 CookieStore* cs = this->GetCookieStore(); |
| 1068 | 1098 |
| 1069 EXPECT_TRUE(this->SetCookie(cs, this->http_www_google_.url(), "A=B")); | 1099 EXPECT_TRUE(this->SetCookie(cs, this->http_www_google_.url(), "A=B")); |
| 1070 this->MatchCookieLines("A=B", | 1100 this->MatchCookieLines("A=B", |
| 1071 this->GetCookies(cs, this->http_www_google_.url())); | 1101 this->GetCookies(cs, this->http_www_google_.url())); |
| 1072 this->MatchCookieLines("A=B", | 1102 this->MatchCookieLines("A=B", |
| 1073 this->GetCookies(cs, this->https_www_google_.url())); | 1103 this->GetCookies(cs, this->https_www_google_.url())); |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1365 TestSettingCookiesWithHostDomainOnUnknownTLD, | 1395 TestSettingCookiesWithHostDomainOnUnknownTLD, |
| 1366 TestHostEndsWithDot, | 1396 TestHostEndsWithDot, |
| 1367 InvalidScheme, | 1397 InvalidScheme, |
| 1368 InvalidScheme_Read, | 1398 InvalidScheme_Read, |
| 1369 PathTest, | 1399 PathTest, |
| 1370 EmptyExpires, | 1400 EmptyExpires, |
| 1371 HttpOnlyTest, | 1401 HttpOnlyTest, |
| 1372 TestCookieDeletion, | 1402 TestCookieDeletion, |
| 1373 TestDeleteAll, | 1403 TestDeleteAll, |
| 1374 TestDeleteAllCreatedBetween, | 1404 TestDeleteAllCreatedBetween, |
| 1375 TestDeleteAllCreatedBetweenForHost, | 1405 TestDeleteAllCreatedBetweenWithPredicate, |
| 1376 TestSecure, | 1406 TestSecure, |
| 1377 NetUtilCookieTest, | 1407 NetUtilCookieTest, |
| 1378 OverwritePersistentCookie, | 1408 OverwritePersistentCookie, |
| 1379 CookieOrdering, | 1409 CookieOrdering, |
| 1380 GetAllCookiesAsync, | 1410 GetAllCookiesAsync, |
| 1381 DeleteCookieAsync, | 1411 DeleteCookieAsync, |
| 1382 DeleteCanonicalCookieAsync, | 1412 DeleteCanonicalCookieAsync, |
| 1383 DeleteSessionCookie); | 1413 DeleteSessionCookie); |
| 1384 | 1414 |
| 1385 } // namespace net | 1415 } // namespace net |
| 1386 | 1416 |
| 1387 #endif // NET_COOKIES_COOKIE_STORE_UNITTEST_H_ | 1417 #endif // NET_COOKIES_COOKIE_STORE_UNITTEST_H_ |
| OLD | NEW |