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 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 DeleteAllCreatedBetweenForHost(CookieStore* cs, |
246 const base::Time delete_begin, | 246 const base::Time delete_begin, |
247 const base::Time delete_end, | 247 const base::Time delete_end, |
248 const GURL& url) { | 248 const GURL& url) { |
249 DCHECK(cs); | 249 DCHECK(cs); |
250 ResultSavingCookieCallback<int> callback; | 250 ResultSavingCookieCallback<int> callback; |
251 cs->DeleteAllCreatedBetweenForHostAsync( | 251 cs->DeleteAllCreatedBetweenWithPredicateAsync( |
252 delete_begin, delete_end, url, | 252 delete_begin, delete_end, |
253 base::Bind( | 253 CookieStore::CreatePredicateForHostCookies(url), |
254 &ResultSavingCookieCallback<int>::Run, | 254 base::Bind(&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 | |
260 int DeleteAllCreatedBetweenWithPredicate( | |
261 CookieStore* cs, | |
262 const base::Time delete_begin, | |
263 const base::Time delete_end, | |
264 const CookieStore::CookiePredicate& predicate) { | |
265 DCHECK(cs); | |
266 ResultSavingCookieCallback<int> callback; | |
267 cs->DeleteAllCreatedBetweenWithPredicateAsync( | |
268 delete_begin, delete_end, predicate, | |
269 base::Bind(&ResultSavingCookieCallback<int>::Run, | |
270 base::Unretained(&callback))); | |
271 callback.WaitUntilDone(); | |
272 return callback.result(); | |
273 } | |
259 | 274 |
260 int DeleteSessionCookies(CookieStore* cs) { | 275 int DeleteSessionCookies(CookieStore* cs) { |
261 DCHECK(cs); | 276 DCHECK(cs); |
262 ResultSavingCookieCallback<int> callback; | 277 ResultSavingCookieCallback<int> callback; |
263 cs->DeleteSessionCookiesAsync( | 278 cs->DeleteSessionCookiesAsync( |
264 base::Bind( | 279 base::Bind( |
265 &ResultSavingCookieCallback<int>::Run, | 280 &ResultSavingCookieCallback<int>::Run, |
266 base::Unretained(&callback))); | 281 base::Unretained(&callback))); |
267 callback.WaitUntilDone(); | 282 callback.WaitUntilDone(); |
268 return callback.result(); | 283 return callback.result(); |
(...skipping 787 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1056 | 1071 |
1057 // This cookie does not match host. | 1072 // This cookie does not match host. |
1058 EXPECT_TRUE(this->SetCookie(cs, url_not_google, "E=F")); | 1073 EXPECT_TRUE(this->SetCookie(cs, url_not_google, "E=F")); |
1059 | 1074 |
1060 // Delete cookies. | 1075 // Delete cookies. |
1061 EXPECT_EQ(3, // Deletes A=B, C=D, Y=Z | 1076 EXPECT_EQ(3, // Deletes A=B, C=D, Y=Z |
1062 this->DeleteAllCreatedBetweenForHost(cs, now, base::Time::Max(), | 1077 this->DeleteAllCreatedBetweenForHost(cs, now, base::Time::Max(), |
1063 this->http_www_google_.url())); | 1078 this->http_www_google_.url())); |
1064 } | 1079 } |
1065 | 1080 |
1081 namespace { | |
1082 static bool CookieHasValue(const std::string& value, | |
1083 const CanonicalCookie& cookie) { | |
1084 return cookie.Value() == value; | |
1085 } | |
1086 } | |
1087 | |
1088 TYPED_TEST_P(CookieStoreTest, TestDeleteAllCreatedBetweenWithPredicate) { | |
1089 CookieStore* cs = this->GetCookieStore(); | |
1090 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.
| |
1091 base::Time now = base::Time::Now(); | |
1092 std::string desired_value("B"); | |
1093 | |
1094 // These 3 cookies match the time range and host. | |
1095 EXPECT_TRUE(this->SetCookie(cs, this->http_www_google_.url(), "A=B")); | |
1096 EXPECT_TRUE(this->SetCookie(cs, this->http_www_google_.url(), "C=D")); | |
1097 EXPECT_TRUE(this->SetCookie(cs, this->http_www_google_.url(), "Y=Z")); | |
1098 | |
1099 // This cookie does not match host. | |
1100 EXPECT_TRUE(this->SetCookie(cs, url_not_google, "E=B")); | |
1101 | |
1102 // Delete cookies. | |
1103 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.
| |
1104 this->DeleteAllCreatedBetweenWithPredicate( | |
1105 cs, now, base::Time::Max(), | |
1106 base::Bind(&CookieHasValue, desired_value))); | |
1107 } | |
1108 | |
1066 TYPED_TEST_P(CookieStoreTest, TestSecure) { | 1109 TYPED_TEST_P(CookieStoreTest, TestSecure) { |
1067 CookieStore* cs = this->GetCookieStore(); | 1110 CookieStore* cs = this->GetCookieStore(); |
1068 | 1111 |
1069 EXPECT_TRUE(this->SetCookie(cs, this->http_www_google_.url(), "A=B")); | 1112 EXPECT_TRUE(this->SetCookie(cs, this->http_www_google_.url(), "A=B")); |
1070 this->MatchCookieLines("A=B", | 1113 this->MatchCookieLines("A=B", |
1071 this->GetCookies(cs, this->http_www_google_.url())); | 1114 this->GetCookies(cs, this->http_www_google_.url())); |
1072 this->MatchCookieLines("A=B", | 1115 this->MatchCookieLines("A=B", |
1073 this->GetCookies(cs, this->https_www_google_.url())); | 1116 this->GetCookies(cs, this->https_www_google_.url())); |
1074 | 1117 |
1075 EXPECT_TRUE( | 1118 EXPECT_TRUE( |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1366 TestHostEndsWithDot, | 1409 TestHostEndsWithDot, |
1367 InvalidScheme, | 1410 InvalidScheme, |
1368 InvalidScheme_Read, | 1411 InvalidScheme_Read, |
1369 PathTest, | 1412 PathTest, |
1370 EmptyExpires, | 1413 EmptyExpires, |
1371 HttpOnlyTest, | 1414 HttpOnlyTest, |
1372 TestCookieDeletion, | 1415 TestCookieDeletion, |
1373 TestDeleteAll, | 1416 TestDeleteAll, |
1374 TestDeleteAllCreatedBetween, | 1417 TestDeleteAllCreatedBetween, |
1375 TestDeleteAllCreatedBetweenForHost, | 1418 TestDeleteAllCreatedBetweenForHost, |
1419 TestDeleteAllCreatedBetweenWithPredicate, | |
1376 TestSecure, | 1420 TestSecure, |
1377 NetUtilCookieTest, | 1421 NetUtilCookieTest, |
1378 OverwritePersistentCookie, | 1422 OverwritePersistentCookie, |
1379 CookieOrdering, | 1423 CookieOrdering, |
1380 GetAllCookiesAsync, | 1424 GetAllCookiesAsync, |
1381 DeleteCookieAsync, | 1425 DeleteCookieAsync, |
1382 DeleteCanonicalCookieAsync, | 1426 DeleteCanonicalCookieAsync, |
1383 DeleteSessionCookie); | 1427 DeleteSessionCookie); |
1384 | 1428 |
1385 } // namespace net | 1429 } // namespace net |
1386 | 1430 |
1387 #endif // NET_COOKIES_COOKIE_STORE_UNITTEST_H_ | 1431 #endif // NET_COOKIES_COOKIE_STORE_UNITTEST_H_ |
OLD | NEW |