Chromium Code Reviews| 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 #include "net/cookies/cookie_monster.h" | 5 #include "net/cookies/cookie_monster.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cstdint> | |
|
mmenke
2017/07/05 16:58:49
stdint.h?
Randy Smith (Not in Mondays)
2017/07/08 13:03:26
Done.
| |
| 8 #include <memory> | 9 #include <memory> |
| 9 #include <string> | 10 #include <string> |
| 10 #include <vector> | 11 #include <vector> |
| 11 | 12 |
| 12 #include "base/bind.h" | 13 #include "base/bind.h" |
| 13 #include "base/location.h" | 14 #include "base/location.h" |
| 14 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
| 15 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
| 16 #include "base/metrics/histogram.h" | 17 #include "base/metrics/histogram.h" |
| 17 #include "base/metrics/histogram_samples.h" | 18 #include "base/metrics/histogram_samples.h" |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 156 DCHECK(cm); | 157 DCHECK(cm); |
| 157 ResultSavingCookieCallback<bool> callback; | 158 ResultSavingCookieCallback<bool> callback; |
| 158 cm->SetCanonicalCookieAsync( | 159 cm->SetCanonicalCookieAsync( |
| 159 std::move(cookie), secure_source, modify_http_only, | 160 std::move(cookie), secure_source, modify_http_only, |
| 160 base::Bind(&ResultSavingCookieCallback<bool>::Run, | 161 base::Bind(&ResultSavingCookieCallback<bool>::Run, |
| 161 base::Unretained(&callback))); | 162 base::Unretained(&callback))); |
| 162 callback.WaitUntilDone(); | 163 callback.WaitUntilDone(); |
| 163 return callback.result(); | 164 return callback.result(); |
| 164 } | 165 } |
| 165 | 166 |
| 166 int DeleteAllCreatedBetween(CookieMonster* cm, | 167 uint32_t DeleteAllCreatedBetween(CookieMonster* cm, |
| 167 const base::Time& delete_begin, | 168 const base::Time& delete_begin, |
| 168 const base::Time& delete_end) { | 169 const base::Time& delete_end) { |
| 169 DCHECK(cm); | 170 DCHECK(cm); |
| 170 ResultSavingCookieCallback<int> callback; | 171 ResultSavingCookieCallback<uint32_t> callback; |
| 171 cm->DeleteAllCreatedBetweenAsync( | 172 cm->DeleteAllCreatedBetweenAsync( |
| 172 delete_begin, delete_end, | 173 delete_begin, delete_end, |
| 173 base::Bind(&ResultSavingCookieCallback<int>::Run, | 174 base::Bind(&ResultSavingCookieCallback<uint32_t>::Run, |
| 174 base::Unretained(&callback))); | 175 base::Unretained(&callback))); |
| 175 callback.WaitUntilDone(); | 176 callback.WaitUntilDone(); |
| 176 return callback.result(); | 177 return callback.result(); |
| 177 } | 178 } |
| 178 | 179 |
| 179 int DeleteAllCreatedBetweenWithPredicate(CookieMonster* cm, | 180 uint32_t DeleteAllCreatedBetweenWithPredicate( |
| 180 const base::Time delete_begin, | 181 CookieMonster* cm, |
| 181 const base::Time delete_end, | 182 const base::Time delete_begin, |
| 182 const CookiePredicate& predicate) { | 183 const base::Time delete_end, |
| 184 const CookiePredicate& predicate) { | |
| 183 DCHECK(cm); | 185 DCHECK(cm); |
| 184 ResultSavingCookieCallback<int> callback; | 186 ResultSavingCookieCallback<uint32_t> callback; |
| 185 cm->DeleteAllCreatedBetweenWithPredicateAsync( | 187 cm->DeleteAllCreatedBetweenWithPredicateAsync( |
| 186 delete_begin, delete_end, predicate, | 188 delete_begin, delete_end, predicate, |
| 187 base::Bind(&ResultSavingCookieCallback<int>::Run, | 189 base::Bind(&ResultSavingCookieCallback<uint32_t>::Run, |
| 188 base::Unretained(&callback))); | 190 base::Unretained(&callback))); |
| 189 callback.WaitUntilDone(); | 191 callback.WaitUntilDone(); |
| 190 return callback.result(); | 192 return callback.result(); |
| 191 } | 193 } |
| 192 | 194 |
| 193 // Helper for PredicateSeesAllCookies test; repopulates CM with same layout | 195 // Helper for PredicateSeesAllCookies test; repopulates CM with same layout |
| 194 // each time. | 196 // each time. |
| 195 void PopulateCmForPredicateCheck(CookieMonster* cm) { | 197 void PopulateCmForPredicateCheck(CookieMonster* cm) { |
| 196 GURL url_top_level_domain_plus_1(kTopLevelDomainPlus1); | 198 GURL url_top_level_domain_plus_1(kTopLevelDomainPlus1); |
| 197 GURL url_top_level_domain_plus_2(kTopLevelDomainPlus2); | 199 GURL url_top_level_domain_plus_2(kTopLevelDomainPlus2); |
| (...skipping 1151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1349 options.set_include_httponly(); | 1351 options.set_include_httponly(); |
| 1350 | 1352 |
| 1351 EXPECT_TRUE(SetCookie(cm.get(), http_www_foo_.url(), kValidCookieLine)); | 1353 EXPECT_TRUE(SetCookie(cm.get(), http_www_foo_.url(), kValidCookieLine)); |
| 1352 EXPECT_EQ("A=B", GetCookies(cm.get(), http_www_foo_.url())); | 1354 EXPECT_EQ("A=B", GetCookies(cm.get(), http_www_foo_.url())); |
| 1353 | 1355 |
| 1354 EXPECT_TRUE(SetCookieWithOptions(cm.get(), http_www_foo_.url(), | 1356 EXPECT_TRUE(SetCookieWithOptions(cm.get(), http_www_foo_.url(), |
| 1355 "C=D; httponly", options)); | 1357 "C=D; httponly", options)); |
| 1356 EXPECT_EQ("A=B; C=D", | 1358 EXPECT_EQ("A=B; C=D", |
| 1357 GetCookiesWithOptions(cm.get(), http_www_foo_.url(), options)); | 1359 GetCookiesWithOptions(cm.get(), http_www_foo_.url(), options)); |
| 1358 | 1360 |
| 1359 EXPECT_EQ(2, DeleteAll(cm.get())); | 1361 EXPECT_EQ(2u, DeleteAll(cm.get())); |
| 1360 EXPECT_EQ("", GetCookiesWithOptions(cm.get(), http_www_foo_.url(), options)); | 1362 EXPECT_EQ("", GetCookiesWithOptions(cm.get(), http_www_foo_.url(), options)); |
| 1361 EXPECT_EQ(0u, store->commands().size()); | 1363 EXPECT_EQ(0u, store->commands().size()); |
| 1362 | 1364 |
| 1363 // Create a persistent cookie. | 1365 // Create a persistent cookie. |
| 1364 EXPECT_TRUE(SetCookie( | 1366 EXPECT_TRUE(SetCookie( |
| 1365 cm.get(), http_www_foo_.url(), | 1367 cm.get(), http_www_foo_.url(), |
| 1366 std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-22 22:50:13 GMT")); | 1368 std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-22 22:50:13 GMT")); |
| 1367 ASSERT_EQ(1u, store->commands().size()); | 1369 ASSERT_EQ(1u, store->commands().size()); |
| 1368 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[0].type); | 1370 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[0].type); |
| 1369 | 1371 |
| 1370 EXPECT_EQ(1, DeleteAll(cm.get())); // sync_to_store = true. | 1372 EXPECT_EQ(1u, DeleteAll(cm.get())); // sync_to_store = true. |
| 1371 ASSERT_EQ(2u, store->commands().size()); | 1373 ASSERT_EQ(2u, store->commands().size()); |
| 1372 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[1].type); | 1374 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[1].type); |
| 1373 | 1375 |
| 1374 EXPECT_EQ("", GetCookiesWithOptions(cm.get(), http_www_foo_.url(), options)); | 1376 EXPECT_EQ("", GetCookiesWithOptions(cm.get(), http_www_foo_.url(), options)); |
| 1375 } | 1377 } |
| 1376 | 1378 |
| 1377 TEST_F(CookieMonsterTest, TestCookieDeleteAllCreatedBetweenTimestamps) { | 1379 TEST_F(CookieMonsterTest, TestCookieDeleteAllCreatedBetweenTimestamps) { |
| 1378 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); | 1380 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
| 1379 Time now = Time::Now(); | 1381 Time now = Time::Now(); |
| 1380 | 1382 |
| 1381 // Nothing has been added so nothing should be deleted. | 1383 // Nothing has been added so nothing should be deleted. |
| 1382 EXPECT_EQ(0, DeleteAllCreatedBetween(cm.get(), now - TimeDelta::FromDays(99), | 1384 EXPECT_EQ(0u, DeleteAllCreatedBetween(cm.get(), now - TimeDelta::FromDays(99), |
| 1383 Time())); | 1385 Time())); |
| 1384 | 1386 |
| 1385 // Create 5 cookies with different creation dates. | 1387 // Create 5 cookies with different creation dates. |
| 1386 EXPECT_TRUE( | 1388 EXPECT_TRUE( |
| 1387 cm->SetCookieWithCreationTime(http_www_foo_.url(), "T-0=Now", now)); | 1389 cm->SetCookieWithCreationTime(http_www_foo_.url(), "T-0=Now", now)); |
| 1388 EXPECT_TRUE(cm->SetCookieWithCreationTime( | 1390 EXPECT_TRUE(cm->SetCookieWithCreationTime( |
| 1389 http_www_foo_.url(), "T-1=Yesterday", now - TimeDelta::FromDays(1))); | 1391 http_www_foo_.url(), "T-1=Yesterday", now - TimeDelta::FromDays(1))); |
| 1390 EXPECT_TRUE(cm->SetCookieWithCreationTime( | 1392 EXPECT_TRUE(cm->SetCookieWithCreationTime( |
| 1391 http_www_foo_.url(), "T-2=DayBefore", now - TimeDelta::FromDays(2))); | 1393 http_www_foo_.url(), "T-2=DayBefore", now - TimeDelta::FromDays(2))); |
| 1392 EXPECT_TRUE(cm->SetCookieWithCreationTime( | 1394 EXPECT_TRUE(cm->SetCookieWithCreationTime( |
| 1393 http_www_foo_.url(), "T-3=ThreeDays", now - TimeDelta::FromDays(3))); | 1395 http_www_foo_.url(), "T-3=ThreeDays", now - TimeDelta::FromDays(3))); |
| 1394 EXPECT_TRUE(cm->SetCookieWithCreationTime(http_www_foo_.url(), "T-7=LastWeek", | 1396 EXPECT_TRUE(cm->SetCookieWithCreationTime(http_www_foo_.url(), "T-7=LastWeek", |
| 1395 now - TimeDelta::FromDays(7))); | 1397 now - TimeDelta::FromDays(7))); |
| 1396 | 1398 |
| 1397 // Try to delete threedays and the daybefore. | 1399 // Try to delete threedays and the daybefore. |
| 1398 EXPECT_EQ(2, DeleteAllCreatedBetween(cm.get(), now - TimeDelta::FromDays(3), | 1400 EXPECT_EQ(2u, DeleteAllCreatedBetween(cm.get(), now - TimeDelta::FromDays(3), |
| 1399 now - TimeDelta::FromDays(1))); | 1401 now - TimeDelta::FromDays(1))); |
| 1400 | 1402 |
| 1401 // Try to delete yesterday, also make sure that delete_end is not | 1403 // Try to delete yesterday, also make sure that delete_end is not |
| 1402 // inclusive. | 1404 // inclusive. |
| 1403 EXPECT_EQ( | 1405 EXPECT_EQ( |
| 1404 1, DeleteAllCreatedBetween(cm.get(), now - TimeDelta::FromDays(2), now)); | 1406 1u, DeleteAllCreatedBetween(cm.get(), now - TimeDelta::FromDays(2), now)); |
| 1405 | 1407 |
| 1406 // Make sure the delete_begin is inclusive. | 1408 // Make sure the delete_begin is inclusive. |
| 1407 EXPECT_EQ( | 1409 EXPECT_EQ( |
| 1408 1, DeleteAllCreatedBetween(cm.get(), now - TimeDelta::FromDays(7), now)); | 1410 1u, DeleteAllCreatedBetween(cm.get(), now - TimeDelta::FromDays(7), now)); |
| 1409 | 1411 |
| 1410 // Delete the last (now) item. | 1412 // Delete the last (now) item. |
| 1411 EXPECT_EQ(1, DeleteAllCreatedBetween(cm.get(), Time(), Time())); | 1413 EXPECT_EQ(1u, DeleteAllCreatedBetween(cm.get(), Time(), Time())); |
| 1412 | 1414 |
| 1413 // Really make sure everything is gone. | 1415 // Really make sure everything is gone. |
| 1414 EXPECT_EQ(0, DeleteAll(cm.get())); | 1416 EXPECT_EQ(0u, DeleteAll(cm.get())); |
| 1415 } | 1417 } |
| 1416 | 1418 |
| 1417 TEST_F(CookieMonsterTest, | 1419 TEST_F(CookieMonsterTest, |
| 1418 TestCookieDeleteAllCreatedBetweenTimestampsWithPredicate) { | 1420 TestCookieDeleteAllCreatedBetweenTimestampsWithPredicate) { |
| 1419 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); | 1421 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
| 1420 Time now = Time::Now(); | 1422 Time now = Time::Now(); |
| 1421 | 1423 |
| 1422 CanonicalCookie test_cookie; | 1424 CanonicalCookie test_cookie; |
| 1423 CookiePredicate true_predicate = | 1425 CookiePredicate true_predicate = |
| 1424 base::Bind(&AlwaysTrueCookiePredicate, &test_cookie); | 1426 base::Bind(&AlwaysTrueCookiePredicate, &test_cookie); |
| 1425 | 1427 |
| 1426 CookiePredicate false_predicate = | 1428 CookiePredicate false_predicate = |
| 1427 base::Bind(&AlwaysFalseCookiePredicate, &test_cookie); | 1429 base::Bind(&AlwaysFalseCookiePredicate, &test_cookie); |
| 1428 | 1430 |
| 1429 // Nothing has been added so nothing should be deleted. | 1431 // Nothing has been added so nothing should be deleted. |
| 1430 EXPECT_EQ( | 1432 EXPECT_EQ( |
| 1431 0, DeleteAllCreatedBetweenWithPredicate( | 1433 0u, DeleteAllCreatedBetweenWithPredicate( |
| 1432 cm.get(), now - TimeDelta::FromDays(99), Time(), true_predicate)); | 1434 cm.get(), now - TimeDelta::FromDays(99), Time(), true_predicate)); |
| 1433 | 1435 |
| 1434 // Create 5 cookies with different creation dates. | 1436 // Create 5 cookies with different creation dates. |
| 1435 EXPECT_TRUE( | 1437 EXPECT_TRUE( |
| 1436 cm->SetCookieWithCreationTime(http_www_foo_.url(), "T-0=Now", now)); | 1438 cm->SetCookieWithCreationTime(http_www_foo_.url(), "T-0=Now", now)); |
| 1437 EXPECT_TRUE(cm->SetCookieWithCreationTime( | 1439 EXPECT_TRUE(cm->SetCookieWithCreationTime( |
| 1438 http_www_foo_.url(), "T-1=Yesterday", now - TimeDelta::FromDays(1))); | 1440 http_www_foo_.url(), "T-1=Yesterday", now - TimeDelta::FromDays(1))); |
| 1439 EXPECT_TRUE(cm->SetCookieWithCreationTime( | 1441 EXPECT_TRUE(cm->SetCookieWithCreationTime( |
| 1440 http_www_foo_.url(), "T-2=DayBefore", now - TimeDelta::FromDays(2))); | 1442 http_www_foo_.url(), "T-2=DayBefore", now - TimeDelta::FromDays(2))); |
| 1441 EXPECT_TRUE(cm->SetCookieWithCreationTime( | 1443 EXPECT_TRUE(cm->SetCookieWithCreationTime( |
| 1442 http_www_foo_.url(), "T-3=ThreeDays", now - TimeDelta::FromDays(3))); | 1444 http_www_foo_.url(), "T-3=ThreeDays", now - TimeDelta::FromDays(3))); |
| 1443 EXPECT_TRUE(cm->SetCookieWithCreationTime(http_www_foo_.url(), "T-7=LastWeek", | 1445 EXPECT_TRUE(cm->SetCookieWithCreationTime(http_www_foo_.url(), "T-7=LastWeek", |
| 1444 now - TimeDelta::FromDays(7))); | 1446 now - TimeDelta::FromDays(7))); |
| 1445 | 1447 |
| 1446 // Try to delete threedays and the daybefore, but we should do nothing due | 1448 // Try to delete threedays and the daybefore, but we should do nothing due |
| 1447 // to the predicate. | 1449 // to the predicate. |
| 1448 EXPECT_EQ(0, DeleteAllCreatedBetweenWithPredicate( | 1450 EXPECT_EQ(0u, DeleteAllCreatedBetweenWithPredicate( |
| 1449 cm.get(), now - TimeDelta::FromDays(3), | 1451 cm.get(), now - TimeDelta::FromDays(3), |
| 1450 now - TimeDelta::FromDays(1), false_predicate)); | 1452 now - TimeDelta::FromDays(1), false_predicate)); |
| 1451 // Same as above with a null predicate, so it shouldn't delete anything. | 1453 // Same as above with a null predicate, so it shouldn't delete anything. |
| 1452 EXPECT_EQ(0, DeleteAllCreatedBetweenWithPredicate( | 1454 EXPECT_EQ(0u, DeleteAllCreatedBetweenWithPredicate( |
| 1453 cm.get(), now - TimeDelta::FromDays(3), | 1455 cm.get(), now - TimeDelta::FromDays(3), |
| 1454 now - TimeDelta::FromDays(1), CookiePredicate())); | 1456 now - TimeDelta::FromDays(1), CookiePredicate())); |
| 1455 // Same as above, but we use the true_predicate, so it works. | 1457 // Same as above, but we use the true_predicate, so it works. |
| 1456 EXPECT_EQ(2, DeleteAllCreatedBetweenWithPredicate( | 1458 EXPECT_EQ(2u, DeleteAllCreatedBetweenWithPredicate( |
| 1457 cm.get(), now - TimeDelta::FromDays(3), | 1459 cm.get(), now - TimeDelta::FromDays(3), |
| 1458 now - TimeDelta::FromDays(1), true_predicate)); | 1460 now - TimeDelta::FromDays(1), true_predicate)); |
| 1459 | 1461 |
| 1460 // Try to delete yesterday, also make sure that delete_end is not | 1462 // Try to delete yesterday, also make sure that delete_end is not |
| 1461 // inclusive. | 1463 // inclusive. |
| 1462 EXPECT_EQ(0, | 1464 EXPECT_EQ(0u, |
| 1463 DeleteAllCreatedBetweenWithPredicate( | 1465 DeleteAllCreatedBetweenWithPredicate( |
| 1464 cm.get(), now - TimeDelta::FromDays(2), now, false_predicate)); | 1466 cm.get(), now - TimeDelta::FromDays(2), now, false_predicate)); |
| 1465 EXPECT_EQ(1, | 1467 EXPECT_EQ(1u, |
| 1466 DeleteAllCreatedBetweenWithPredicate( | 1468 DeleteAllCreatedBetweenWithPredicate( |
| 1467 cm.get(), now - TimeDelta::FromDays(2), now, true_predicate)); | 1469 cm.get(), now - TimeDelta::FromDays(2), now, true_predicate)); |
| 1468 // Check our cookie values. | 1470 // Check our cookie values. |
| 1469 std::unique_ptr<CanonicalCookie> expected_cookie = | 1471 std::unique_ptr<CanonicalCookie> expected_cookie = |
| 1470 CanonicalCookie::Create(http_www_foo_.url(), "T-1=Yesterday", | 1472 CanonicalCookie::Create(http_www_foo_.url(), "T-1=Yesterday", |
| 1471 now - TimeDelta::FromDays(1), CookieOptions()); | 1473 now - TimeDelta::FromDays(1), CookieOptions()); |
| 1472 EXPECT_THAT(test_cookie, CookieEquals(*expected_cookie)) | 1474 EXPECT_THAT(test_cookie, CookieEquals(*expected_cookie)) |
| 1473 << "Actual:\n" | 1475 << "Actual:\n" |
| 1474 << test_cookie.DebugString() << "\nExpected:\n" | 1476 << test_cookie.DebugString() << "\nExpected:\n" |
| 1475 << expected_cookie->DebugString(); | 1477 << expected_cookie->DebugString(); |
| 1476 | 1478 |
| 1477 // Make sure the delete_begin is inclusive. | 1479 // Make sure the delete_begin is inclusive. |
| 1478 EXPECT_EQ(0, | 1480 EXPECT_EQ(0u, |
| 1479 DeleteAllCreatedBetweenWithPredicate( | 1481 DeleteAllCreatedBetweenWithPredicate( |
| 1480 cm.get(), now - TimeDelta::FromDays(7), now, false_predicate)); | 1482 cm.get(), now - TimeDelta::FromDays(7), now, false_predicate)); |
| 1481 EXPECT_EQ(1, | 1483 EXPECT_EQ(1u, |
| 1482 DeleteAllCreatedBetweenWithPredicate( | 1484 DeleteAllCreatedBetweenWithPredicate( |
| 1483 cm.get(), now - TimeDelta::FromDays(7), now, true_predicate)); | 1485 cm.get(), now - TimeDelta::FromDays(7), now, true_predicate)); |
| 1484 | 1486 |
| 1485 // Delete the last (now) item. | 1487 // Delete the last (now) item. |
| 1486 EXPECT_EQ(0, DeleteAllCreatedBetweenWithPredicate(cm.get(), Time(), Time(), | 1488 EXPECT_EQ(0u, DeleteAllCreatedBetweenWithPredicate(cm.get(), Time(), Time(), |
| 1487 false_predicate)); | 1489 false_predicate)); |
| 1488 EXPECT_EQ(1, DeleteAllCreatedBetweenWithPredicate(cm.get(), Time(), Time(), | 1490 EXPECT_EQ(1u, DeleteAllCreatedBetweenWithPredicate(cm.get(), Time(), Time(), |
| 1489 true_predicate)); | 1491 true_predicate)); |
| 1490 expected_cookie = CanonicalCookie::Create(http_www_foo_.url(), "T-0=Now", now, | 1492 expected_cookie = CanonicalCookie::Create(http_www_foo_.url(), "T-0=Now", now, |
| 1491 CookieOptions()); | 1493 CookieOptions()); |
| 1492 EXPECT_THAT(test_cookie, CookieEquals(*expected_cookie)) | 1494 EXPECT_THAT(test_cookie, CookieEquals(*expected_cookie)) |
| 1493 << "Actual:\n" | 1495 << "Actual:\n" |
| 1494 << test_cookie.DebugString() << "\nExpected:\n" | 1496 << test_cookie.DebugString() << "\nExpected:\n" |
| 1495 << expected_cookie->DebugString(); | 1497 << expected_cookie->DebugString(); |
| 1496 | 1498 |
| 1497 // Really make sure everything is gone. | 1499 // Really make sure everything is gone. |
| 1498 EXPECT_EQ(0, DeleteAll(cm.get())); | 1500 EXPECT_EQ(0u, DeleteAll(cm.get())); |
| 1499 } | 1501 } |
| 1500 | 1502 |
| 1501 static const base::TimeDelta kLastAccessThreshold = | 1503 static const base::TimeDelta kLastAccessThreshold = |
| 1502 base::TimeDelta::FromMilliseconds(200); | 1504 base::TimeDelta::FromMilliseconds(200); |
| 1503 static const base::TimeDelta kAccessDelay = | 1505 static const base::TimeDelta kAccessDelay = |
| 1504 kLastAccessThreshold + base::TimeDelta::FromMilliseconds(20); | 1506 kLastAccessThreshold + base::TimeDelta::FromMilliseconds(20); |
| 1505 | 1507 |
| 1506 TEST_F(CookieMonsterTest, TestLastAccess) { | 1508 TEST_F(CookieMonsterTest, TestLastAccess) { |
| 1507 std::unique_ptr<CookieMonster> cm( | 1509 std::unique_ptr<CookieMonster> cm( |
| 1508 new CookieMonster(nullptr, nullptr, kLastAccessThreshold)); | 1510 new CookieMonster(nullptr, nullptr, kLastAccessThreshold)); |
| (...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1930 } | 1932 } |
| 1931 | 1933 |
| 1932 TEST_F(CookieMonsterTest, PredicateSeesAllCookies) { | 1934 TEST_F(CookieMonsterTest, PredicateSeesAllCookies) { |
| 1933 const std::string kTrueValue = "A"; | 1935 const std::string kTrueValue = "A"; |
| 1934 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); | 1936 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
| 1935 // We test that we can see all cookies with our predicated. This includes | 1937 // We test that we can see all cookies with our predicated. This includes |
| 1936 // host, http_only, host secure, and all domain cookies. | 1938 // host, http_only, host secure, and all domain cookies. |
| 1937 CookiePredicate value_matcher = base::Bind(&CookieValuePredicate, kTrueValue); | 1939 CookiePredicate value_matcher = base::Bind(&CookieValuePredicate, kTrueValue); |
| 1938 | 1940 |
| 1939 PopulateCmForPredicateCheck(cm.get()); | 1941 PopulateCmForPredicateCheck(cm.get()); |
| 1940 EXPECT_EQ(7, DeleteAllCreatedBetweenWithPredicate( | 1942 EXPECT_EQ(7u, DeleteAllCreatedBetweenWithPredicate( |
| 1941 cm.get(), base::Time(), base::Time::Now(), value_matcher)); | 1943 cm.get(), base::Time(), base::Time::Now(), value_matcher)); |
| 1942 | 1944 |
| 1943 EXPECT_EQ("dom_2=B; dom_3=C; host_3=C", | 1945 EXPECT_EQ("dom_2=B; dom_3=C; host_3=C", |
| 1944 GetCookies(cm.get(), GURL(kTopLevelDomainPlus3))); | 1946 GetCookies(cm.get(), GURL(kTopLevelDomainPlus3))); |
| 1945 EXPECT_EQ("dom_2=B; host_2=B; sec_host=B", | 1947 EXPECT_EQ("dom_2=B; host_2=B; sec_host=B", |
| 1946 GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure))); | 1948 GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure))); |
| 1947 EXPECT_EQ("", GetCookies(cm.get(), GURL(kTopLevelDomainPlus1))); | 1949 EXPECT_EQ("", GetCookies(cm.get(), GURL(kTopLevelDomainPlus1))); |
| 1948 EXPECT_EQ("dom_path_2=B; host_path_2=B; dom_2=B; host_2=B; sec_host=B", | 1950 EXPECT_EQ("dom_path_2=B; host_path_2=B; dom_2=B; host_2=B; sec_host=B", |
| 1949 GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure + | 1951 GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure + |
| 1950 std::string("/dir1/dir2/xxx")))); | 1952 std::string("/dir1/dir2/xxx")))); |
| 1951 } | 1953 } |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2293 // Tests that case that DeleteAll is waiting for load to complete, and then a | 2295 // Tests that case that DeleteAll is waiting for load to complete, and then a |
| 2294 // get is queued. The get should wait to run until after all the cookies are | 2296 // get is queued. The get should wait to run until after all the cookies are |
| 2295 // retrieved, and should return nothing, since all cookies were just deleted. | 2297 // retrieved, and should return nothing, since all cookies were just deleted. |
| 2296 TEST_F(CookieMonsterTest, WhileLoadingDeleteAllGetForURL) { | 2298 TEST_F(CookieMonsterTest, WhileLoadingDeleteAllGetForURL) { |
| 2297 const GURL kUrl = GURL(kTopLevelDomainPlus1); | 2299 const GURL kUrl = GURL(kTopLevelDomainPlus1); |
| 2298 | 2300 |
| 2299 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); | 2301 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); |
| 2300 store->set_store_load_commands(true); | 2302 store->set_store_load_commands(true); |
| 2301 std::unique_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); | 2303 std::unique_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); |
| 2302 | 2304 |
| 2303 ResultSavingCookieCallback<int> delete_callback; | 2305 ResultSavingCookieCallback<uint32_t> delete_callback; |
| 2304 cm->DeleteAllAsync(base::Bind(&ResultSavingCookieCallback<int>::Run, | 2306 cm->DeleteAllAsync(base::Bind(&ResultSavingCookieCallback<uint32_t>::Run, |
| 2305 base::Unretained(&delete_callback))); | 2307 base::Unretained(&delete_callback))); |
| 2306 | 2308 |
| 2307 GetCookieListCallback get_cookie_list_callback; | 2309 GetCookieListCallback get_cookie_list_callback; |
| 2308 cm->GetCookieListWithOptionsAsync( | 2310 cm->GetCookieListWithOptionsAsync( |
| 2309 kUrl, CookieOptions(), | 2311 kUrl, CookieOptions(), |
| 2310 base::Bind(&GetCookieListCallback::Run, | 2312 base::Bind(&GetCookieListCallback::Run, |
| 2311 base::Unretained(&get_cookie_list_callback))); | 2313 base::Unretained(&get_cookie_list_callback))); |
| 2312 | 2314 |
| 2313 // Only the main load should have been queued. | 2315 // Only the main load should have been queued. |
| 2314 ASSERT_EQ(1u, store->commands().size()); | 2316 ASSERT_EQ(1u, store->commands().size()); |
| 2315 ASSERT_EQ(CookieStoreCommand::LOAD, store->commands()[0].type); | 2317 ASSERT_EQ(CookieStoreCommand::LOAD, store->commands()[0].type); |
| 2316 | 2318 |
| 2317 std::vector<std::unique_ptr<CanonicalCookie>> cookies; | 2319 std::vector<std::unique_ptr<CanonicalCookie>> cookies; |
| 2318 // When passed to the CookieMonster, it takes ownership of the pointed to | 2320 // When passed to the CookieMonster, it takes ownership of the pointed to |
| 2319 // cookies. | 2321 // cookies. |
| 2320 cookies.push_back( | 2322 cookies.push_back( |
| 2321 CanonicalCookie::Create(kUrl, "a=b", base::Time::Now(), CookieOptions())); | 2323 CanonicalCookie::Create(kUrl, "a=b", base::Time::Now(), CookieOptions())); |
| 2322 ASSERT_TRUE(cookies[0]); | 2324 ASSERT_TRUE(cookies[0]); |
| 2323 store->commands()[0].loaded_callback.Run(std::move(cookies)); | 2325 store->commands()[0].loaded_callback.Run(std::move(cookies)); |
| 2324 | 2326 |
| 2325 delete_callback.WaitUntilDone(); | 2327 delete_callback.WaitUntilDone(); |
| 2326 EXPECT_EQ(1, delete_callback.result()); | 2328 EXPECT_EQ(1u, delete_callback.result()); |
| 2327 | 2329 |
| 2328 get_cookie_list_callback.WaitUntilDone(); | 2330 get_cookie_list_callback.WaitUntilDone(); |
| 2329 EXPECT_EQ(0u, get_cookie_list_callback.cookies().size()); | 2331 EXPECT_EQ(0u, get_cookie_list_callback.cookies().size()); |
| 2330 } | 2332 } |
| 2331 | 2333 |
| 2332 // Tests that a set cookie call sandwiched between two get all cookies, all | 2334 // Tests that a set cookie call sandwiched between two get all cookies, all |
| 2333 // before load completes, affects the first but not the second. The set should | 2335 // before load completes, affects the first but not the second. The set should |
| 2334 // also not trigger a LoadCookiesForKey (As that could complete only after the | 2336 // also not trigger a LoadCookiesForKey (As that could complete only after the |
| 2335 // main load for the store). | 2337 // main load for the store). |
| 2336 TEST_F(CookieMonsterTest, WhileLoadingGetAllSetGetAll) { | 2338 TEST_F(CookieMonsterTest, WhileLoadingGetAllSetGetAll) { |
| (...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2757 // Check that DeleteAll does flush (as a sanity check that flush_count() | 2759 // Check that DeleteAll does flush (as a sanity check that flush_count() |
| 2758 // works). | 2760 // works). |
| 2759 TEST_F(CookieMonsterTest, DeleteAll) { | 2761 TEST_F(CookieMonsterTest, DeleteAll) { |
| 2760 scoped_refptr<FlushablePersistentStore> store(new FlushablePersistentStore()); | 2762 scoped_refptr<FlushablePersistentStore> store(new FlushablePersistentStore()); |
| 2761 std::unique_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); | 2763 std::unique_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); |
| 2762 cm->SetPersistSessionCookies(true); | 2764 cm->SetPersistSessionCookies(true); |
| 2763 | 2765 |
| 2764 EXPECT_TRUE(SetCookie(cm.get(), http_www_foo_.url(), "X=Y; path=/")); | 2766 EXPECT_TRUE(SetCookie(cm.get(), http_www_foo_.url(), "X=Y; path=/")); |
| 2765 | 2767 |
| 2766 ASSERT_EQ(0, store->flush_count()); | 2768 ASSERT_EQ(0, store->flush_count()); |
| 2767 EXPECT_EQ(1, DeleteAll(cm.get())); | 2769 EXPECT_EQ(1u, DeleteAll(cm.get())); |
| 2768 EXPECT_EQ(1, store->flush_count()); | 2770 EXPECT_EQ(1, store->flush_count()); |
| 2769 } | 2771 } |
| 2770 | 2772 |
| 2771 TEST_F(CookieMonsterTest, HistogramCheck) { | 2773 TEST_F(CookieMonsterTest, HistogramCheck) { |
| 2772 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); | 2774 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
| 2773 // Should match call in InitializeHistograms, but doesn't really matter | 2775 // Should match call in InitializeHistograms, but doesn't really matter |
| 2774 // since the histogram should have been initialized by the CM construction | 2776 // since the histogram should have been initialized by the CM construction |
| 2775 // above. | 2777 // above. |
| 2776 base::HistogramBase* expired_histogram = base::Histogram::FactoryGet( | 2778 base::HistogramBase* expired_histogram = base::Histogram::FactoryGet( |
| 2777 "Cookie.ExpirationDurationMinutes", 1, 10 * 365 * 24 * 60, 50, | 2779 "Cookie.ExpirationDurationMinutes", 1, 10 * 365 * 24 * 60, 50, |
| (...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3432 monster()->AddCallbackForCookie( | 3434 monster()->AddCallbackForCookie( |
| 3433 test_url_, "abc", | 3435 test_url_, "abc", |
| 3434 base::Bind(&RecordCookieChanges, &cookies1, nullptr))); | 3436 base::Bind(&RecordCookieChanges, &cookies1, nullptr))); |
| 3435 SetCookie(monster(), test_url_, "abc=def"); | 3437 SetCookie(monster(), test_url_, "abc=def"); |
| 3436 base::RunLoop().RunUntilIdle(); | 3438 base::RunLoop().RunUntilIdle(); |
| 3437 EXPECT_EQ(1U, cookies0.size()); | 3439 EXPECT_EQ(1U, cookies0.size()); |
| 3438 EXPECT_EQ(1U, cookies0.size()); | 3440 EXPECT_EQ(1U, cookies0.size()); |
| 3439 } | 3441 } |
| 3440 | 3442 |
| 3441 } // namespace net | 3443 } // namespace net |
| OLD | NEW |