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