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 <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <memory> | 10 #include <memory> |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
158 DCHECK(cm); | 158 DCHECK(cm); |
159 ResultSavingCookieCallback<bool> callback; | 159 ResultSavingCookieCallback<bool> callback; |
160 cm->SetCanonicalCookieAsync( | 160 cm->SetCanonicalCookieAsync( |
161 std::move(cookie), secure_source, modify_http_only, | 161 std::move(cookie), secure_source, modify_http_only, |
162 base::Bind(&ResultSavingCookieCallback<bool>::Run, | 162 base::Bind(&ResultSavingCookieCallback<bool>::Run, |
163 base::Unretained(&callback))); | 163 base::Unretained(&callback))); |
164 callback.WaitUntilDone(); | 164 callback.WaitUntilDone(); |
165 return callback.result(); | 165 return callback.result(); |
166 } | 166 } |
167 | 167 |
168 bool SetCookieWithCreationTime(CookieMonster* cm, | |
169 const GURL& url, | |
170 std::string cookie_line, | |
mmenke
2017/07/12 18:29:05
nit: const std::string& cookie_line
Randy Smith (Not in Mondays)
2017/07/12 19:47:35
Done.
| |
171 base::Time creation_time) { | |
172 DCHECK(cm); | |
173 ResultSavingCookieCallback<bool> callback; | |
174 cm->SetCookieWithCreationTimeForTesting( | |
175 url, cookie_line, creation_time, | |
176 base::Bind(&ResultSavingCookieCallback<bool>::Run, | |
177 base::Unretained(&callback))); | |
178 callback.WaitUntilDone(); | |
179 return callback.result(); | |
180 } | |
181 | |
168 uint32_t DeleteAllCreatedBetween(CookieMonster* cm, | 182 uint32_t DeleteAllCreatedBetween(CookieMonster* cm, |
169 const base::Time& delete_begin, | 183 const base::Time& delete_begin, |
170 const base::Time& delete_end) { | 184 const base::Time& delete_end) { |
171 DCHECK(cm); | 185 DCHECK(cm); |
172 ResultSavingCookieCallback<uint32_t> callback; | 186 ResultSavingCookieCallback<uint32_t> callback; |
173 cm->DeleteAllCreatedBetweenAsync( | 187 cm->DeleteAllCreatedBetweenAsync( |
174 delete_begin, delete_end, | 188 delete_begin, delete_end, |
175 base::Bind(&ResultSavingCookieCallback<uint32_t>::Run, | 189 base::Bind(&ResultSavingCookieCallback<uint32_t>::Run, |
176 base::Unretained(&callback))); | 190 base::Unretained(&callback))); |
177 callback.WaitUntilDone(); | 191 callback.WaitUntilDone(); |
(...skipping 1202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1380 TEST_F(CookieMonsterTest, TestCookieDeleteAllCreatedBetweenTimestamps) { | 1394 TEST_F(CookieMonsterTest, TestCookieDeleteAllCreatedBetweenTimestamps) { |
1381 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); | 1395 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
1382 Time now = Time::Now(); | 1396 Time now = Time::Now(); |
1383 | 1397 |
1384 // Nothing has been added so nothing should be deleted. | 1398 // Nothing has been added so nothing should be deleted. |
1385 EXPECT_EQ(0u, DeleteAllCreatedBetween(cm.get(), now - TimeDelta::FromDays(99), | 1399 EXPECT_EQ(0u, DeleteAllCreatedBetween(cm.get(), now - TimeDelta::FromDays(99), |
1386 Time())); | 1400 Time())); |
1387 | 1401 |
1388 // Create 5 cookies with different creation dates. | 1402 // Create 5 cookies with different creation dates. |
1389 EXPECT_TRUE( | 1403 EXPECT_TRUE( |
1390 cm->SetCookieWithCreationTime(http_www_foo_.url(), "T-0=Now", now)); | 1404 SetCookieWithCreationTime(cm.get(), http_www_foo_.url(), "T-0=Now", now)); |
1391 EXPECT_TRUE(cm->SetCookieWithCreationTime( | 1405 EXPECT_TRUE(SetCookieWithCreationTime(cm.get(), http_www_foo_.url(), |
1392 http_www_foo_.url(), "T-1=Yesterday", now - TimeDelta::FromDays(1))); | 1406 "T-1=Yesterday", |
1393 EXPECT_TRUE(cm->SetCookieWithCreationTime( | 1407 now - TimeDelta::FromDays(1))); |
1394 http_www_foo_.url(), "T-2=DayBefore", now - TimeDelta::FromDays(2))); | 1408 EXPECT_TRUE(SetCookieWithCreationTime(cm.get(), http_www_foo_.url(), |
1395 EXPECT_TRUE(cm->SetCookieWithCreationTime( | 1409 "T-2=DayBefore", |
1396 http_www_foo_.url(), "T-3=ThreeDays", now - TimeDelta::FromDays(3))); | 1410 now - TimeDelta::FromDays(2))); |
1397 EXPECT_TRUE(cm->SetCookieWithCreationTime(http_www_foo_.url(), "T-7=LastWeek", | 1411 EXPECT_TRUE(SetCookieWithCreationTime(cm.get(), http_www_foo_.url(), |
1398 now - TimeDelta::FromDays(7))); | 1412 "T-3=ThreeDays", |
1413 now - TimeDelta::FromDays(3))); | |
1414 EXPECT_TRUE(SetCookieWithCreationTime(cm.get(), http_www_foo_.url(), | |
1415 "T-7=LastWeek", | |
1416 now - TimeDelta::FromDays(7))); | |
1399 | 1417 |
1400 // Try to delete threedays and the daybefore. | 1418 // Try to delete threedays and the daybefore. |
1401 EXPECT_EQ(2u, DeleteAllCreatedBetween(cm.get(), now - TimeDelta::FromDays(3), | 1419 EXPECT_EQ(2u, DeleteAllCreatedBetween(cm.get(), now - TimeDelta::FromDays(3), |
1402 now - TimeDelta::FromDays(1))); | 1420 now - TimeDelta::FromDays(1))); |
1403 | 1421 |
1404 // Try to delete yesterday, also make sure that delete_end is not | 1422 // Try to delete yesterday, also make sure that delete_end is not |
1405 // inclusive. | 1423 // inclusive. |
1406 EXPECT_EQ( | 1424 EXPECT_EQ( |
1407 1u, DeleteAllCreatedBetween(cm.get(), now - TimeDelta::FromDays(2), now)); | 1425 1u, DeleteAllCreatedBetween(cm.get(), now - TimeDelta::FromDays(2), now)); |
1408 | 1426 |
(...skipping 20 matching lines...) Expand all Loading... | |
1429 CookiePredicate false_predicate = | 1447 CookiePredicate false_predicate = |
1430 base::Bind(&AlwaysFalseCookiePredicate, &test_cookie); | 1448 base::Bind(&AlwaysFalseCookiePredicate, &test_cookie); |
1431 | 1449 |
1432 // Nothing has been added so nothing should be deleted. | 1450 // Nothing has been added so nothing should be deleted. |
1433 EXPECT_EQ( | 1451 EXPECT_EQ( |
1434 0u, DeleteAllCreatedBetweenWithPredicate( | 1452 0u, DeleteAllCreatedBetweenWithPredicate( |
1435 cm.get(), now - TimeDelta::FromDays(99), Time(), true_predicate)); | 1453 cm.get(), now - TimeDelta::FromDays(99), Time(), true_predicate)); |
1436 | 1454 |
1437 // Create 5 cookies with different creation dates. | 1455 // Create 5 cookies with different creation dates. |
1438 EXPECT_TRUE( | 1456 EXPECT_TRUE( |
1439 cm->SetCookieWithCreationTime(http_www_foo_.url(), "T-0=Now", now)); | 1457 SetCookieWithCreationTime(cm.get(), http_www_foo_.url(), "T-0=Now", now)); |
1440 EXPECT_TRUE(cm->SetCookieWithCreationTime( | 1458 EXPECT_TRUE(SetCookieWithCreationTime(cm.get(), http_www_foo_.url(), |
1441 http_www_foo_.url(), "T-1=Yesterday", now - TimeDelta::FromDays(1))); | 1459 "T-1=Yesterday", |
1442 EXPECT_TRUE(cm->SetCookieWithCreationTime( | 1460 now - TimeDelta::FromDays(1))); |
1443 http_www_foo_.url(), "T-2=DayBefore", now - TimeDelta::FromDays(2))); | 1461 EXPECT_TRUE(SetCookieWithCreationTime(cm.get(), http_www_foo_.url(), |
1444 EXPECT_TRUE(cm->SetCookieWithCreationTime( | 1462 "T-2=DayBefore", |
1445 http_www_foo_.url(), "T-3=ThreeDays", now - TimeDelta::FromDays(3))); | 1463 now - TimeDelta::FromDays(2))); |
1446 EXPECT_TRUE(cm->SetCookieWithCreationTime(http_www_foo_.url(), "T-7=LastWeek", | 1464 EXPECT_TRUE(SetCookieWithCreationTime(cm.get(), http_www_foo_.url(), |
1447 now - TimeDelta::FromDays(7))); | 1465 "T-3=ThreeDays", |
1466 now - TimeDelta::FromDays(3))); | |
1467 EXPECT_TRUE(SetCookieWithCreationTime(cm.get(), http_www_foo_.url(), | |
1468 "T-7=LastWeek", | |
1469 now - TimeDelta::FromDays(7))); | |
1448 | 1470 |
1449 // Try to delete threedays and the daybefore, but we should do nothing due | 1471 // Try to delete threedays and the daybefore, but we should do nothing due |
1450 // to the predicate. | 1472 // to the predicate. |
1451 EXPECT_EQ(0u, DeleteAllCreatedBetweenWithPredicate( | 1473 EXPECT_EQ(0u, DeleteAllCreatedBetweenWithPredicate( |
1452 cm.get(), now - TimeDelta::FromDays(3), | 1474 cm.get(), now - TimeDelta::FromDays(3), |
1453 now - TimeDelta::FromDays(1), false_predicate)); | 1475 now - TimeDelta::FromDays(1), false_predicate)); |
1454 // Same as above with a null predicate, so it shouldn't delete anything. | 1476 // Same as above with a null predicate, so it shouldn't delete anything. |
1455 EXPECT_EQ(0u, DeleteAllCreatedBetweenWithPredicate( | 1477 EXPECT_EQ(0u, DeleteAllCreatedBetweenWithPredicate( |
1456 cm.get(), now - TimeDelta::FromDays(3), | 1478 cm.get(), now - TimeDelta::FromDays(3), |
1457 now - TimeDelta::FromDays(1), CookiePredicate())); | 1479 now - TimeDelta::FromDays(1), CookiePredicate())); |
(...skipping 1977 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3435 monster()->AddCallbackForCookie( | 3457 monster()->AddCallbackForCookie( |
3436 test_url_, "abc", | 3458 test_url_, "abc", |
3437 base::Bind(&RecordCookieChanges, &cookies1, nullptr))); | 3459 base::Bind(&RecordCookieChanges, &cookies1, nullptr))); |
3438 SetCookie(monster(), test_url_, "abc=def"); | 3460 SetCookie(monster(), test_url_, "abc=def"); |
3439 base::RunLoop().RunUntilIdle(); | 3461 base::RunLoop().RunUntilIdle(); |
3440 EXPECT_EQ(1U, cookies0.size()); | 3462 EXPECT_EQ(1U, cookies0.size()); |
3441 EXPECT_EQ(1U, cookies0.size()); | 3463 EXPECT_EQ(1U, cookies0.size()); |
3442 } | 3464 } |
3443 | 3465 |
3444 } // namespace net | 3466 } // namespace net |
OLD | NEW |