| 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 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 const GURL& url, | 209 const GURL& url, |
| 210 const std::string& cookie_name) { | 210 const std::string& cookie_name) { |
| 211 DCHECK(cs); | 211 DCHECK(cs); |
| 212 NoResultCookieCallback callback; | 212 NoResultCookieCallback callback; |
| 213 cs->DeleteCookieAsync( | 213 cs->DeleteCookieAsync( |
| 214 url, cookie_name, | 214 url, cookie_name, |
| 215 base::Bind(&NoResultCookieCallback::Run, base::Unretained(&callback))); | 215 base::Bind(&NoResultCookieCallback::Run, base::Unretained(&callback))); |
| 216 callback.WaitUntilDone(); | 216 callback.WaitUntilDone(); |
| 217 } | 217 } |
| 218 | 218 |
| 219 int DeleteCanonicalCookie(CookieStore* cs, const CanonicalCookie& cookie) { |
| 220 DCHECK(cs); |
| 221 ResultSavingCookieCallback<int> callback; |
| 222 cs->DeleteCanonicalCookieAsync( |
| 223 cookie, base::Bind(&ResultSavingCookieCallback<int>::Run, |
| 224 base::Unretained(&callback))); |
| 225 callback.WaitUntilDone(); |
| 226 return callback.result(); |
| 227 } |
| 228 |
| 219 int DeleteCreatedBetween(CookieStore* cs, | 229 int DeleteCreatedBetween(CookieStore* cs, |
| 220 const base::Time& delete_begin, | 230 const base::Time& delete_begin, |
| 221 const base::Time& delete_end) { | 231 const base::Time& delete_end) { |
| 222 DCHECK(cs); | 232 DCHECK(cs); |
| 223 ResultSavingCookieCallback<int> callback; | 233 ResultSavingCookieCallback<int> callback; |
| 224 cs->DeleteAllCreatedBetweenAsync( | 234 cs->DeleteAllCreatedBetweenAsync( |
| 225 delete_begin, delete_end, | 235 delete_begin, delete_end, |
| 226 base::Bind( | 236 base::Bind( |
| 227 &ResultSavingCookieCallback<int>::Run, | 237 &ResultSavingCookieCallback<int>::Run, |
| 228 base::Unretained(&callback))); | 238 base::Unretained(&callback))); |
| (...skipping 1025 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1254 | 1264 |
| 1255 ASSERT_TRUE(++it != cookies.end()); | 1265 ASSERT_TRUE(++it != cookies.end()); |
| 1256 EXPECT_EQ(this->http_foo_com_.host(), it->Domain()); | 1266 EXPECT_EQ(this->http_foo_com_.host(), it->Domain()); |
| 1257 EXPECT_EQ("/", it->Path()); | 1267 EXPECT_EQ("/", it->Path()); |
| 1258 EXPECT_EQ("C", it->Name()); | 1268 EXPECT_EQ("C", it->Name()); |
| 1259 EXPECT_EQ("D", it->Value()); | 1269 EXPECT_EQ("D", it->Value()); |
| 1260 | 1270 |
| 1261 ASSERT_TRUE(++it == cookies.end()); | 1271 ASSERT_TRUE(++it == cookies.end()); |
| 1262 } | 1272 } |
| 1263 | 1273 |
| 1274 TYPED_TEST_P(CookieStoreTest, DeleteCanonicalCookieAsync) { |
| 1275 scoped_refptr<CookieStore> cs(this->GetCookieStore()); |
| 1276 |
| 1277 // Set two cookies with the same name, and make sure both are set. |
| 1278 EXPECT_TRUE( |
| 1279 this->SetCookie(cs.get(), this->http_www_google_.url(), "A=B;Path=/foo")); |
| 1280 EXPECT_TRUE( |
| 1281 this->SetCookie(cs.get(), this->http_www_google_.url(), "A=C;Path=/bar")); |
| 1282 EXPECT_EQ(2u, this->GetAllCookies(cs.get()).size()); |
| 1283 EXPECT_EQ("A=B", this->GetCookies(cs.get(), this->www_google_foo_.url())); |
| 1284 EXPECT_EQ("A=C", this->GetCookies(cs.get(), this->www_google_bar_.url())); |
| 1285 |
| 1286 // Delete the "/foo" cookie, and make sure only it was deleted. |
| 1287 CookieList cookies = |
| 1288 this->GetAllCookiesForURL(cs.get(), this->www_google_foo_.url()); |
| 1289 ASSERT_EQ(1u, cookies.size()); |
| 1290 EXPECT_EQ(1, this->DeleteCanonicalCookie(cs.get(), cookies[0])); |
| 1291 EXPECT_EQ(1u, this->GetAllCookies(cs.get()).size()); |
| 1292 EXPECT_EQ("", this->GetCookies(cs.get(), this->www_google_foo_.url())); |
| 1293 EXPECT_EQ("A=C", this->GetCookies(cs.get(), this->www_google_bar_.url())); |
| 1294 |
| 1295 // Deleting the "/foo" cookie again should fail. |
| 1296 EXPECT_EQ(0, this->DeleteCanonicalCookie(cs.get(), cookies[0])); |
| 1297 |
| 1298 // Try to delete the "/bar" cookie after overwriting it with a new cookie. |
| 1299 cookies = this->GetAllCookiesForURL(cs.get(), this->www_google_bar_.url()); |
| 1300 ASSERT_EQ(1u, cookies.size()); |
| 1301 EXPECT_TRUE( |
| 1302 this->SetCookie(cs.get(), this->http_www_google_.url(), "A=D;Path=/bar")); |
| 1303 EXPECT_EQ(0, this->DeleteCanonicalCookie(cs.get(), cookies[0])); |
| 1304 EXPECT_EQ(1u, this->GetAllCookies(cs.get()).size()); |
| 1305 EXPECT_EQ("A=D", this->GetCookies(cs.get(), this->www_google_bar_.url())); |
| 1306 |
| 1307 // Delete the new "/bar" cookie. |
| 1308 cookies = this->GetAllCookiesForURL(cs.get(), this->www_google_bar_.url()); |
| 1309 ASSERT_EQ(1u, cookies.size()); |
| 1310 EXPECT_EQ(1, this->DeleteCanonicalCookie(cs.get(), cookies[0])); |
| 1311 EXPECT_EQ(0u, this->GetAllCookies(cs.get()).size()); |
| 1312 EXPECT_EQ("", this->GetCookies(cs.get(), this->www_google_bar_.url())); |
| 1313 } |
| 1314 |
| 1264 TYPED_TEST_P(CookieStoreTest, DeleteSessionCookie) { | 1315 TYPED_TEST_P(CookieStoreTest, DeleteSessionCookie) { |
| 1265 scoped_refptr<CookieStore> cs(this->GetCookieStore()); | 1316 scoped_refptr<CookieStore> cs(this->GetCookieStore()); |
| 1266 // Create a session cookie and a persistent cookie. | 1317 // Create a session cookie and a persistent cookie. |
| 1267 EXPECT_TRUE(this->SetCookie(cs.get(), this->http_www_google_.url(), | 1318 EXPECT_TRUE(this->SetCookie(cs.get(), this->http_www_google_.url(), |
| 1268 std::string(kValidCookieLine))); | 1319 std::string(kValidCookieLine))); |
| 1269 EXPECT_TRUE(this->SetCookie( | 1320 EXPECT_TRUE(this->SetCookie( |
| 1270 cs.get(), this->http_www_google_.url(), | 1321 cs.get(), this->http_www_google_.url(), |
| 1271 this->http_www_google_.Format("C=D; path=/; domain=%D;" | 1322 this->http_www_google_.Format("C=D; path=/; domain=%D;" |
| 1272 "expires=Mon, 18-Apr-22 22:50:13 GMT"))); | 1323 "expires=Mon, 18-Apr-22 22:50:13 GMT"))); |
| 1273 this->MatchCookieLines( | 1324 this->MatchCookieLines( |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1297 HttpOnlyTest, | 1348 HttpOnlyTest, |
| 1298 TestCookieDeletion, | 1349 TestCookieDeletion, |
| 1299 TestDeleteAll, | 1350 TestDeleteAll, |
| 1300 TestDeleteAllCreatedBetween, | 1351 TestDeleteAllCreatedBetween, |
| 1301 TestDeleteAllCreatedBetweenForHost, | 1352 TestDeleteAllCreatedBetweenForHost, |
| 1302 TestSecure, | 1353 TestSecure, |
| 1303 NetUtilCookieTest, | 1354 NetUtilCookieTest, |
| 1304 OverwritePersistentCookie, | 1355 OverwritePersistentCookie, |
| 1305 CookieOrdering, | 1356 CookieOrdering, |
| 1306 GetAllCookiesAsync, | 1357 GetAllCookiesAsync, |
| 1358 DeleteCanonicalCookieAsync, |
| 1307 DeleteSessionCookie); | 1359 DeleteSessionCookie); |
| 1308 | 1360 |
| 1309 template<class CookieStoreTestTraits> | 1361 template<class CookieStoreTestTraits> |
| 1310 class MultiThreadedCookieStoreTest : | 1362 class MultiThreadedCookieStoreTest : |
| 1311 public CookieStoreTest<CookieStoreTestTraits> { | 1363 public CookieStoreTest<CookieStoreTestTraits> { |
| 1312 public: | 1364 public: |
| 1313 MultiThreadedCookieStoreTest() : other_thread_("CMTthread") {} | 1365 MultiThreadedCookieStoreTest() : other_thread_("CMTthread") {} |
| 1314 | 1366 |
| 1315 // Helper methods for calling the asynchronous CookieStore methods | 1367 // Helper methods for calling the asynchronous CookieStore methods |
| 1316 // from a different thread. | 1368 // from a different thread. |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1475 REGISTER_TYPED_TEST_CASE_P(MultiThreadedCookieStoreTest, | 1527 REGISTER_TYPED_TEST_CASE_P(MultiThreadedCookieStoreTest, |
| 1476 ThreadCheckGetCookies, | 1528 ThreadCheckGetCookies, |
| 1477 ThreadCheckGetCookiesWithOptions, | 1529 ThreadCheckGetCookiesWithOptions, |
| 1478 ThreadCheckSetCookieWithOptions, | 1530 ThreadCheckSetCookieWithOptions, |
| 1479 ThreadCheckDeleteCookie, | 1531 ThreadCheckDeleteCookie, |
| 1480 ThreadCheckDeleteSessionCookies); | 1532 ThreadCheckDeleteSessionCookies); |
| 1481 | 1533 |
| 1482 } // namespace net | 1534 } // namespace net |
| 1483 | 1535 |
| 1484 #endif // NET_COOKIES_COOKIE_STORE_UNITTEST_H_ | 1536 #endif // NET_COOKIES_COOKIE_STORE_UNITTEST_H_ |
| OLD | NEW |