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_store_unittest.h" | 5 #include "net/cookies/cookie_monster.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <memory> |
8 #include <string> | 9 #include <string> |
9 #include <vector> | 10 #include <vector> |
10 | 11 |
11 #include "base/bind.h" | 12 #include "base/bind.h" |
12 #include "base/location.h" | 13 #include "base/location.h" |
| 14 #include "base/memory/ptr_util.h" |
13 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
14 #include "base/memory/scoped_ptr.h" | |
15 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.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" |
18 #include "base/single_thread_task_runner.h" | 19 #include "base/single_thread_task_runner.h" |
19 #include "base/strings/string_number_conversions.h" | 20 #include "base/strings/string_number_conversions.h" |
20 #include "base/strings/string_piece.h" | 21 #include "base/strings/string_piece.h" |
21 #include "base/strings/string_split.h" | 22 #include "base/strings/string_split.h" |
22 #include "base/strings/string_tokenizer.h" | 23 #include "base/strings/string_tokenizer.h" |
23 #include "base/strings/stringprintf.h" | 24 #include "base/strings/stringprintf.h" |
24 #include "base/test/histogram_tester.h" | 25 #include "base/test/histogram_tester.h" |
25 #include "base/thread_task_runner_handle.h" | 26 #include "base/thread_task_runner_handle.h" |
26 #include "base/threading/thread.h" | 27 #include "base/threading/thread.h" |
27 #include "base/time/time.h" | 28 #include "base/time/time.h" |
28 #include "net/cookies/canonical_cookie.h" | 29 #include "net/cookies/canonical_cookie.h" |
29 #include "net/cookies/cookie_constants.h" | 30 #include "net/cookies/cookie_constants.h" |
30 #include "net/cookies/cookie_monster.h" | |
31 #include "net/cookies/cookie_monster_store_test.h" // For CookieStore mock | 31 #include "net/cookies/cookie_monster_store_test.h" // For CookieStore mock |
| 32 #include "net/cookies/cookie_store_unittest.h" |
32 #include "net/cookies/cookie_util.h" | 33 #include "net/cookies/cookie_util.h" |
33 #include "net/cookies/parsed_cookie.h" | 34 #include "net/cookies/parsed_cookie.h" |
34 #include "testing/gmock/include/gmock/gmock.h" | 35 #include "testing/gmock/include/gmock/gmock.h" |
35 #include "testing/gtest/include/gtest/gtest.h" | 36 #include "testing/gtest/include/gtest/gtest.h" |
36 #include "url/gurl.h" | 37 #include "url/gurl.h" |
37 | 38 |
38 namespace net { | 39 namespace net { |
39 | 40 |
40 using CookiePredicate = CookieStore::CookiePredicate; | 41 using CookiePredicate = CookieStore::CookiePredicate; |
41 using base::Time; | 42 using base::Time; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 *to_save = cookie; | 90 *to_save = cookie; |
90 return false; | 91 return false; |
91 } | 92 } |
92 | 93 |
93 bool CookieValuePredicate(const std::string& true_value, | 94 bool CookieValuePredicate(const std::string& true_value, |
94 const CanonicalCookie& cookie) { | 95 const CanonicalCookie& cookie) { |
95 return cookie.Value() == true_value; | 96 return cookie.Value() == true_value; |
96 } | 97 } |
97 | 98 |
98 struct CookieMonsterTestTraits { | 99 struct CookieMonsterTestTraits { |
99 static scoped_ptr<CookieStore> Create() { | 100 static std::unique_ptr<CookieStore> Create() { |
100 return make_scoped_ptr(new CookieMonster(nullptr, nullptr)); | 101 return base::WrapUnique(new CookieMonster(nullptr, nullptr)); |
101 } | 102 } |
102 | 103 |
103 static const bool supports_http_only = true; | 104 static const bool supports_http_only = true; |
104 static const bool supports_non_dotted_domains = true; | 105 static const bool supports_non_dotted_domains = true; |
105 static const bool preserves_trailing_dots = true; | 106 static const bool preserves_trailing_dots = true; |
106 static const bool filters_schemes = true; | 107 static const bool filters_schemes = true; |
107 static const bool has_path_prefix_bug = false; | 108 static const bool has_path_prefix_bug = false; |
108 static const int creation_time_granularity_in_ms = 0; | 109 static const int creation_time_granularity_in_ms = 0; |
109 static const bool enforce_strict_secure = false; | 110 static const bool enforce_strict_secure = false; |
110 }; | 111 }; |
111 | 112 |
112 struct CookieMonsterEnforcingStrictSecure { | 113 struct CookieMonsterEnforcingStrictSecure { |
113 static scoped_ptr<CookieStore> Create() { | 114 static std::unique_ptr<CookieStore> Create() { |
114 return make_scoped_ptr(new CookieMonster(nullptr, nullptr)); | 115 return base::WrapUnique(new CookieMonster(nullptr, nullptr)); |
115 } | 116 } |
116 | 117 |
117 static const bool supports_http_only = true; | 118 static const bool supports_http_only = true; |
118 static const bool supports_non_dotted_domains = true; | 119 static const bool supports_non_dotted_domains = true; |
119 static const bool preserves_trailing_dots = true; | 120 static const bool preserves_trailing_dots = true; |
120 static const bool filters_schemes = true; | 121 static const bool filters_schemes = true; |
121 static const bool has_path_prefix_bug = false; | 122 static const bool has_path_prefix_bug = false; |
122 static const int creation_time_granularity_in_ms = 0; | 123 static const int creation_time_granularity_in_ms = 0; |
123 static const bool enforce_strict_secure = true; | 124 static const bool enforce_strict_secure = true; |
124 }; | 125 }; |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 return std::count(str.begin(), str.end(), c); | 303 return std::count(str.begin(), str.end(), c); |
303 } | 304 } |
304 | 305 |
305 void TestHostGarbageCollectHelper() { | 306 void TestHostGarbageCollectHelper() { |
306 int domain_max_cookies = CookieMonster::kDomainMaxCookies; | 307 int domain_max_cookies = CookieMonster::kDomainMaxCookies; |
307 int domain_purge_cookies = CookieMonster::kDomainPurgeCookies; | 308 int domain_purge_cookies = CookieMonster::kDomainPurgeCookies; |
308 const int more_than_enough_cookies = | 309 const int more_than_enough_cookies = |
309 (domain_max_cookies + domain_purge_cookies) * 2; | 310 (domain_max_cookies + domain_purge_cookies) * 2; |
310 // Add a bunch of cookies on a single host, should purge them. | 311 // Add a bunch of cookies on a single host, should purge them. |
311 { | 312 { |
312 scoped_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); | 313 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
313 for (int i = 0; i < more_than_enough_cookies; ++i) { | 314 for (int i = 0; i < more_than_enough_cookies; ++i) { |
314 std::string cookie = base::StringPrintf("a%03d=b", i); | 315 std::string cookie = base::StringPrintf("a%03d=b", i); |
315 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), cookie)); | 316 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), cookie)); |
316 std::string cookies = | 317 std::string cookies = |
317 this->GetCookies(cm.get(), http_www_google_.url()); | 318 this->GetCookies(cm.get(), http_www_google_.url()); |
318 // Make sure we find it in the cookies. | 319 // Make sure we find it in the cookies. |
319 EXPECT_NE(cookies.find(cookie), std::string::npos); | 320 EXPECT_NE(cookies.find(cookie), std::string::npos); |
320 // Count the number of cookies. | 321 // Count the number of cookies. |
321 EXPECT_LE(CountInString(cookies, '='), domain_max_cookies); | 322 EXPECT_LE(CountInString(cookies, '='), domain_max_cookies); |
322 } | 323 } |
323 } | 324 } |
324 | 325 |
325 // Add a bunch of cookies on multiple hosts within a single eTLD. | 326 // Add a bunch of cookies on multiple hosts within a single eTLD. |
326 // Should keep at least kDomainMaxCookies - kDomainPurgeCookies | 327 // Should keep at least kDomainMaxCookies - kDomainPurgeCookies |
327 // between them. We shouldn't go above kDomainMaxCookies for both together. | 328 // between them. We shouldn't go above kDomainMaxCookies for both together. |
328 GURL url_google_specific(http_www_google_.Format("http://www.gmail.%D")); | 329 GURL url_google_specific(http_www_google_.Format("http://www.gmail.%D")); |
329 { | 330 { |
330 scoped_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); | 331 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
331 for (int i = 0; i < more_than_enough_cookies; ++i) { | 332 for (int i = 0; i < more_than_enough_cookies; ++i) { |
332 std::string cookie_general = base::StringPrintf("a%03d=b", i); | 333 std::string cookie_general = base::StringPrintf("a%03d=b", i); |
333 EXPECT_TRUE( | 334 EXPECT_TRUE( |
334 SetCookie(cm.get(), http_www_google_.url(), cookie_general)); | 335 SetCookie(cm.get(), http_www_google_.url(), cookie_general)); |
335 std::string cookie_specific = base::StringPrintf("c%03d=b", i); | 336 std::string cookie_specific = base::StringPrintf("c%03d=b", i); |
336 EXPECT_TRUE(SetCookie(cm.get(), url_google_specific, cookie_specific)); | 337 EXPECT_TRUE(SetCookie(cm.get(), url_google_specific, cookie_specific)); |
337 std::string cookies_general = | 338 std::string cookies_general = |
338 this->GetCookies(cm.get(), http_www_google_.url()); | 339 this->GetCookies(cm.get(), http_www_google_.url()); |
339 EXPECT_NE(cookies_general.find(cookie_general), std::string::npos); | 340 EXPECT_NE(cookies_general.find(cookie_general), std::string::npos); |
340 std::string cookies_specific = | 341 std::string cookies_specific = |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
464 // of cookies to create. Cookies are created in the order they appear in | 465 // of cookies to create. Cookies are created in the order they appear in |
465 // cookie_entries. The value of cookie_entries[x].num_cookies specifies how | 466 // cookie_entries. The value of cookie_entries[x].num_cookies specifies how |
466 // many cookies of that type to create consecutively, while if | 467 // many cookies of that type to create consecutively, while if |
467 // cookie_entries[x].is_secure is |true|, those cookies will be marke as | 468 // cookie_entries[x].is_secure is |true|, those cookies will be marke as |
468 // Secure. | 469 // Secure. |
469 void TestSecureCookieEviction(const CookiesEntry* cookie_entries, | 470 void TestSecureCookieEviction(const CookiesEntry* cookie_entries, |
470 size_t num_cookie_entries, | 471 size_t num_cookie_entries, |
471 size_t expected_secure_cookies, | 472 size_t expected_secure_cookies, |
472 size_t expected_non_secure_cookies, | 473 size_t expected_non_secure_cookies, |
473 const AltHosts* alt_host_entries) { | 474 const AltHosts* alt_host_entries) { |
474 scoped_ptr<CookieMonster> cm; | 475 std::unique_ptr<CookieMonster> cm; |
475 | 476 |
476 if (alt_host_entries == nullptr) { | 477 if (alt_host_entries == nullptr) { |
477 cm.reset(new CookieMonster(nullptr, nullptr)); | 478 cm.reset(new CookieMonster(nullptr, nullptr)); |
478 } else { | 479 } else { |
479 // When generating all of these cookies on alternate hosts, they need to | 480 // When generating all of these cookies on alternate hosts, they need to |
480 // be all older than the max "safe" date for GC, which is currently 30 | 481 // be all older than the max "safe" date for GC, which is currently 30 |
481 // days, so we set them to 60. | 482 // days, so we set them to 60. |
482 cm = CreateMonsterFromStoreForGC( | 483 cm = CreateMonsterFromStoreForGC( |
483 alt_host_entries->first, alt_host_entries->first, | 484 alt_host_entries->first, alt_host_entries->first, |
484 alt_host_entries->second, alt_host_entries->second, 60); | 485 alt_host_entries->second, alt_host_entries->second, 60); |
(...skipping 30 matching lines...) Expand all Loading... |
515 | 516 |
516 void TestPriorityAwareGarbageCollectHelper() { | 517 void TestPriorityAwareGarbageCollectHelper() { |
517 // Hard-coding limits in the test, but use DCHECK_EQ to enforce constraint. | 518 // Hard-coding limits in the test, but use DCHECK_EQ to enforce constraint. |
518 DCHECK_EQ(180U, CookieMonster::kDomainMaxCookies); | 519 DCHECK_EQ(180U, CookieMonster::kDomainMaxCookies); |
519 DCHECK_EQ(150U, CookieMonster::kDomainMaxCookies - | 520 DCHECK_EQ(150U, CookieMonster::kDomainMaxCookies - |
520 CookieMonster::kDomainPurgeCookies); | 521 CookieMonster::kDomainPurgeCookies); |
521 DCHECK_EQ(30U, CookieMonster::kDomainCookiesQuotaLow); | 522 DCHECK_EQ(30U, CookieMonster::kDomainCookiesQuotaLow); |
522 DCHECK_EQ(50U, CookieMonster::kDomainCookiesQuotaMedium); | 523 DCHECK_EQ(50U, CookieMonster::kDomainCookiesQuotaMedium); |
523 DCHECK_EQ(70U, CookieMonster::kDomainCookiesQuotaHigh); | 524 DCHECK_EQ(70U, CookieMonster::kDomainCookiesQuotaHigh); |
524 | 525 |
525 scoped_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); | 526 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
526 | 527 |
527 // Each test case adds 181 cookies, so 31 cookies are evicted. | 528 // Each test case adds 181 cookies, so 31 cookies are evicted. |
528 // Cookie same priority, repeated for each priority. | 529 // Cookie same priority, repeated for each priority. |
529 TestPriorityCookieCase(cm.get(), "181L", 150U, 0U, 0U); | 530 TestPriorityCookieCase(cm.get(), "181L", 150U, 0U, 0U); |
530 TestPriorityCookieCase(cm.get(), "181M", 0U, 150U, 0U); | 531 TestPriorityCookieCase(cm.get(), "181M", 0U, 150U, 0U); |
531 TestPriorityCookieCase(cm.get(), "181H", 0U, 0U, 150U); | 532 TestPriorityCookieCase(cm.get(), "181H", 0U, 0U, 150U); |
532 | 533 |
533 // Pairwise scenarios. | 534 // Pairwise scenarios. |
534 // Round 1 => none; round2 => 31M; round 3 => none. | 535 // Round 1 => none; round2 => 31M; round 3 => none. |
535 TestPriorityCookieCase(cm.get(), "10H 171M", 0U, 140U, 10U); | 536 TestPriorityCookieCase(cm.get(), "10H 171M", 0U, 140U, 10U); |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
822 CookieMonster::PersistentCookieStore::LoadedCallback loaded_callback_; | 823 CookieMonster::PersistentCookieStore::LoadedCallback loaded_callback_; |
823 // Stores the callback passed from the CookieMonster to the | 824 // Stores the callback passed from the CookieMonster to the |
824 // PersistentCookieStore::LoadCookiesForKey | 825 // PersistentCookieStore::LoadCookiesForKey |
825 std::queue<CookieMonster::PersistentCookieStore::LoadedCallback> | 826 std::queue<CookieMonster::PersistentCookieStore::LoadedCallback> |
826 loaded_for_key_callbacks_; | 827 loaded_for_key_callbacks_; |
827 // base::RunLoop used to wait for PersistentCookieStore::Load to be called. | 828 // base::RunLoop used to wait for PersistentCookieStore::Load to be called. |
828 base::RunLoop load_run_loop_; | 829 base::RunLoop load_run_loop_; |
829 // Indicates whether ExpectLoadCall() has been called. | 830 // Indicates whether ExpectLoadCall() has been called. |
830 bool expect_load_called_; | 831 bool expect_load_called_; |
831 // Stores the CookieMonster under test. | 832 // Stores the CookieMonster under test. |
832 scoped_ptr<CookieMonster> cookie_monster_; | 833 std::unique_ptr<CookieMonster> cookie_monster_; |
833 // Stores the mock PersistentCookieStore. | 834 // Stores the mock PersistentCookieStore. |
834 scoped_refptr<NewMockPersistentCookieStore> persistent_store_; | 835 scoped_refptr<NewMockPersistentCookieStore> persistent_store_; |
835 }; | 836 }; |
836 | 837 |
837 TEST_F(DeferredCookieTaskTest, DeferredGetCookies) { | 838 TEST_F(DeferredCookieTaskTest, DeferredGetCookies) { |
838 DeclareLoadedCookie(http_www_google_.url(), | 839 DeclareLoadedCookie(http_www_google_.url(), |
839 "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", | 840 "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", |
840 Time::Now() + TimeDelta::FromDays(3)); | 841 Time::Now() + TimeDelta::FromDays(3)); |
841 | 842 |
842 MockGetCookiesCallback get_cookies_callback; | 843 MockGetCookiesCallback get_cookies_callback; |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1093 &delete_callback)); | 1094 &delete_callback)); |
1094 base::RunLoop loop; | 1095 base::RunLoop loop; |
1095 EXPECT_CALL(delete_callback, Invoke(false)).WillOnce(QuitRunLoop(&loop)); | 1096 EXPECT_CALL(delete_callback, Invoke(false)).WillOnce(QuitRunLoop(&loop)); |
1096 | 1097 |
1097 CompleteLoading(); | 1098 CompleteLoading(); |
1098 loop.Run(); | 1099 loop.Run(); |
1099 } | 1100 } |
1100 | 1101 |
1101 TEST_F(DeferredCookieTaskTest, DeferredDeleteCanonicalCookie) { | 1102 TEST_F(DeferredCookieTaskTest, DeferredDeleteCanonicalCookie) { |
1102 std::vector<CanonicalCookie*> cookies; | 1103 std::vector<CanonicalCookie*> cookies; |
1103 scoped_ptr<CanonicalCookie> cookie = BuildCanonicalCookie( | 1104 std::unique_ptr<CanonicalCookie> cookie = BuildCanonicalCookie( |
1104 http_www_google_.url(), "X=1; path=/", base::Time::Now()); | 1105 http_www_google_.url(), "X=1; path=/", base::Time::Now()); |
1105 | 1106 |
1106 MockDeleteCallback delete_cookie_callback; | 1107 MockDeleteCallback delete_cookie_callback; |
1107 | 1108 |
1108 BeginWith(DeleteCanonicalCookieAction(&cookie_monster(), *cookie, | 1109 BeginWith(DeleteCanonicalCookieAction(&cookie_monster(), *cookie, |
1109 &delete_cookie_callback)); | 1110 &delete_cookie_callback)); |
1110 | 1111 |
1111 WaitForLoadCall(); | 1112 WaitForLoadCall(); |
1112 | 1113 |
1113 EXPECT_CALL(delete_cookie_callback, Invoke(0)) | 1114 EXPECT_CALL(delete_cookie_callback, Invoke(0)) |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1167 base::RunLoop loop; | 1168 base::RunLoop loop; |
1168 EXPECT_CALL(get_cookies_callback_deferred, Invoke("A=B; X=1")) | 1169 EXPECT_CALL(get_cookies_callback_deferred, Invoke("A=B; X=1")) |
1169 .WillOnce(QuitRunLoop(&loop)); | 1170 .WillOnce(QuitRunLoop(&loop)); |
1170 | 1171 |
1171 CompleteLoading(); | 1172 CompleteLoading(); |
1172 loop.Run(); | 1173 loop.Run(); |
1173 } | 1174 } |
1174 | 1175 |
1175 TEST_F(CookieMonsterTest, TestCookieDeleteAll) { | 1176 TEST_F(CookieMonsterTest, TestCookieDeleteAll) { |
1176 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); | 1177 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); |
1177 scoped_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); | 1178 std::unique_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); |
1178 CookieOptions options; | 1179 CookieOptions options; |
1179 options.set_include_httponly(); | 1180 options.set_include_httponly(); |
1180 | 1181 |
1181 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), kValidCookieLine)); | 1182 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), kValidCookieLine)); |
1182 EXPECT_EQ("A=B", GetCookies(cm.get(), http_www_google_.url())); | 1183 EXPECT_EQ("A=B", GetCookies(cm.get(), http_www_google_.url())); |
1183 | 1184 |
1184 EXPECT_TRUE(SetCookieWithOptions(cm.get(), http_www_google_.url(), | 1185 EXPECT_TRUE(SetCookieWithOptions(cm.get(), http_www_google_.url(), |
1185 "C=D; httponly", options)); | 1186 "C=D; httponly", options)); |
1186 EXPECT_EQ("A=B; C=D", | 1187 EXPECT_EQ("A=B; C=D", |
1187 GetCookiesWithOptions(cm.get(), http_www_google_.url(), options)); | 1188 GetCookiesWithOptions(cm.get(), http_www_google_.url(), options)); |
(...skipping 12 matching lines...) Expand all Loading... |
1200 | 1201 |
1201 EXPECT_EQ(1, DeleteAll(cm.get())); // sync_to_store = true. | 1202 EXPECT_EQ(1, DeleteAll(cm.get())); // sync_to_store = true. |
1202 ASSERT_EQ(2u, store->commands().size()); | 1203 ASSERT_EQ(2u, store->commands().size()); |
1203 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[1].type); | 1204 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[1].type); |
1204 | 1205 |
1205 EXPECT_EQ("", | 1206 EXPECT_EQ("", |
1206 GetCookiesWithOptions(cm.get(), http_www_google_.url(), options)); | 1207 GetCookiesWithOptions(cm.get(), http_www_google_.url(), options)); |
1207 } | 1208 } |
1208 | 1209 |
1209 TEST_F(CookieMonsterTest, TestCookieDeleteAllCreatedBetweenTimestamps) { | 1210 TEST_F(CookieMonsterTest, TestCookieDeleteAllCreatedBetweenTimestamps) { |
1210 scoped_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); | 1211 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
1211 Time now = Time::Now(); | 1212 Time now = Time::Now(); |
1212 | 1213 |
1213 // Nothing has been added so nothing should be deleted. | 1214 // Nothing has been added so nothing should be deleted. |
1214 EXPECT_EQ(0, DeleteAllCreatedBetween(cm.get(), now - TimeDelta::FromDays(99), | 1215 EXPECT_EQ(0, DeleteAllCreatedBetween(cm.get(), now - TimeDelta::FromDays(99), |
1215 Time())); | 1216 Time())); |
1216 | 1217 |
1217 // Create 5 cookies with different creation dates. | 1218 // Create 5 cookies with different creation dates. |
1218 EXPECT_TRUE( | 1219 EXPECT_TRUE( |
1219 cm->SetCookieWithCreationTime(http_www_google_.url(), "T-0=Now", now)); | 1220 cm->SetCookieWithCreationTime(http_www_google_.url(), "T-0=Now", now)); |
1220 EXPECT_TRUE(cm->SetCookieWithCreationTime( | 1221 EXPECT_TRUE(cm->SetCookieWithCreationTime( |
(...skipping 20 matching lines...) Expand all Loading... |
1241 | 1242 |
1242 // Delete the last (now) item. | 1243 // Delete the last (now) item. |
1243 EXPECT_EQ(1, DeleteAllCreatedBetween(cm.get(), Time(), Time())); | 1244 EXPECT_EQ(1, DeleteAllCreatedBetween(cm.get(), Time(), Time())); |
1244 | 1245 |
1245 // Really make sure everything is gone. | 1246 // Really make sure everything is gone. |
1246 EXPECT_EQ(0, DeleteAll(cm.get())); | 1247 EXPECT_EQ(0, DeleteAll(cm.get())); |
1247 } | 1248 } |
1248 | 1249 |
1249 TEST_F(CookieMonsterTest, | 1250 TEST_F(CookieMonsterTest, |
1250 TestCookieDeleteAllCreatedBetweenTimestampsWithPredicate) { | 1251 TestCookieDeleteAllCreatedBetweenTimestampsWithPredicate) { |
1251 scoped_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); | 1252 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
1252 Time now = Time::Now(); | 1253 Time now = Time::Now(); |
1253 | 1254 |
1254 CanonicalCookie test_cookie; | 1255 CanonicalCookie test_cookie; |
1255 CookiePredicate true_predicate = | 1256 CookiePredicate true_predicate = |
1256 base::Bind(&AlwaysTrueCookiePredicate, &test_cookie); | 1257 base::Bind(&AlwaysTrueCookiePredicate, &test_cookie); |
1257 | 1258 |
1258 CookiePredicate false_predicate = | 1259 CookiePredicate false_predicate = |
1259 base::Bind(&AlwaysFalseCookiePredicate, &test_cookie); | 1260 base::Bind(&AlwaysFalseCookiePredicate, &test_cookie); |
1260 | 1261 |
1261 // Nothing has been added so nothing should be deleted. | 1262 // Nothing has been added so nothing should be deleted. |
(...skipping 29 matching lines...) Expand all Loading... |
1291 | 1292 |
1292 // Try to delete yesterday, also make sure that delete_end is not | 1293 // Try to delete yesterday, also make sure that delete_end is not |
1293 // inclusive. | 1294 // inclusive. |
1294 EXPECT_EQ(0, | 1295 EXPECT_EQ(0, |
1295 DeleteAllCreatedBetweenWithPredicate( | 1296 DeleteAllCreatedBetweenWithPredicate( |
1296 cm.get(), now - TimeDelta::FromDays(2), now, false_predicate)); | 1297 cm.get(), now - TimeDelta::FromDays(2), now, false_predicate)); |
1297 EXPECT_EQ(1, | 1298 EXPECT_EQ(1, |
1298 DeleteAllCreatedBetweenWithPredicate( | 1299 DeleteAllCreatedBetweenWithPredicate( |
1299 cm.get(), now - TimeDelta::FromDays(2), now, true_predicate)); | 1300 cm.get(), now - TimeDelta::FromDays(2), now, true_predicate)); |
1300 // Check our cookie values. | 1301 // Check our cookie values. |
1301 scoped_ptr<CanonicalCookie> expected_cookie = | 1302 std::unique_ptr<CanonicalCookie> expected_cookie = |
1302 CanonicalCookie::Create(http_www_google_.url(), "T-1=Yesterday", | 1303 CanonicalCookie::Create(http_www_google_.url(), "T-1=Yesterday", |
1303 now - TimeDelta::FromDays(1), CookieOptions()); | 1304 now - TimeDelta::FromDays(1), CookieOptions()); |
1304 EXPECT_THAT(test_cookie, CookieEquals(*expected_cookie)) | 1305 EXPECT_THAT(test_cookie, CookieEquals(*expected_cookie)) |
1305 << "Actual:\n" | 1306 << "Actual:\n" |
1306 << test_cookie.DebugString() << "\nExpected:\n" | 1307 << test_cookie.DebugString() << "\nExpected:\n" |
1307 << expected_cookie->DebugString(); | 1308 << expected_cookie->DebugString(); |
1308 | 1309 |
1309 // Make sure the delete_begin is inclusive. | 1310 // Make sure the delete_begin is inclusive. |
1310 EXPECT_EQ(0, | 1311 EXPECT_EQ(0, |
1311 DeleteAllCreatedBetweenWithPredicate( | 1312 DeleteAllCreatedBetweenWithPredicate( |
(...skipping 14 matching lines...) Expand all Loading... |
1326 << test_cookie.DebugString() << "\nExpected:\n" | 1327 << test_cookie.DebugString() << "\nExpected:\n" |
1327 << expected_cookie->DebugString(); | 1328 << expected_cookie->DebugString(); |
1328 | 1329 |
1329 // Really make sure everything is gone. | 1330 // Really make sure everything is gone. |
1330 EXPECT_EQ(0, DeleteAll(cm.get())); | 1331 EXPECT_EQ(0, DeleteAll(cm.get())); |
1331 } | 1332 } |
1332 | 1333 |
1333 static const int kAccessDelayMs = kLastAccessThresholdMilliseconds + 20; | 1334 static const int kAccessDelayMs = kLastAccessThresholdMilliseconds + 20; |
1334 | 1335 |
1335 TEST_F(CookieMonsterTest, TestLastAccess) { | 1336 TEST_F(CookieMonsterTest, TestLastAccess) { |
1336 scoped_ptr<CookieMonster> cm( | 1337 std::unique_ptr<CookieMonster> cm( |
1337 new CookieMonster(nullptr, nullptr, kLastAccessThresholdMilliseconds)); | 1338 new CookieMonster(nullptr, nullptr, kLastAccessThresholdMilliseconds)); |
1338 | 1339 |
1339 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=B")); | 1340 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=B")); |
1340 const Time last_access_date(GetFirstCookieAccessDate(cm.get())); | 1341 const Time last_access_date(GetFirstCookieAccessDate(cm.get())); |
1341 | 1342 |
1342 // Reading the cookie again immediately shouldn't update the access date, | 1343 // Reading the cookie again immediately shouldn't update the access date, |
1343 // since we're inside the threshold. | 1344 // since we're inside the threshold. |
1344 EXPECT_EQ("A=B", GetCookies(cm.get(), http_www_google_.url())); | 1345 EXPECT_EQ("A=B", GetCookies(cm.get(), http_www_google_.url())); |
1345 EXPECT_EQ(last_access_date, GetFirstCookieAccessDate(cm.get())); | 1346 EXPECT_EQ(last_access_date, GetFirstCookieAccessDate(cm.get())); |
1346 | 1347 |
(...skipping 27 matching lines...) Expand all Loading... |
1374 | 1375 |
1375 TEST_F(CookieMonsterTest, TestHostGarbageCollection) { | 1376 TEST_F(CookieMonsterTest, TestHostGarbageCollection) { |
1376 TestHostGarbageCollectHelper(); | 1377 TestHostGarbageCollectHelper(); |
1377 } | 1378 } |
1378 | 1379 |
1379 TEST_F(CookieMonsterTest, TestPriorityAwareGarbageCollection) { | 1380 TEST_F(CookieMonsterTest, TestPriorityAwareGarbageCollection) { |
1380 TestPriorityAwareGarbageCollectHelper(); | 1381 TestPriorityAwareGarbageCollectHelper(); |
1381 } | 1382 } |
1382 | 1383 |
1383 TEST_F(CookieMonsterTest, SetCookieableSchemes) { | 1384 TEST_F(CookieMonsterTest, SetCookieableSchemes) { |
1384 scoped_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); | 1385 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
1385 scoped_ptr<CookieMonster> cm_foo(new CookieMonster(nullptr, nullptr)); | 1386 std::unique_ptr<CookieMonster> cm_foo(new CookieMonster(nullptr, nullptr)); |
1386 | 1387 |
1387 // Only cm_foo should allow foo:// cookies. | 1388 // Only cm_foo should allow foo:// cookies. |
1388 std::vector<std::string> schemes; | 1389 std::vector<std::string> schemes; |
1389 schemes.push_back("foo"); | 1390 schemes.push_back("foo"); |
1390 cm_foo->SetCookieableSchemes(schemes); | 1391 cm_foo->SetCookieableSchemes(schemes); |
1391 | 1392 |
1392 GURL foo_url("foo://host/path"); | 1393 GURL foo_url("foo://host/path"); |
1393 GURL http_url("http://host/path"); | 1394 GURL http_url("http://host/path"); |
1394 | 1395 |
1395 EXPECT_TRUE(SetCookie(cm.get(), http_url, "x=1")); | 1396 EXPECT_TRUE(SetCookie(cm.get(), http_url, "x=1")); |
1396 EXPECT_FALSE(SetCookie(cm.get(), foo_url, "x=1")); | 1397 EXPECT_FALSE(SetCookie(cm.get(), foo_url, "x=1")); |
1397 EXPECT_TRUE(SetCookie(cm_foo.get(), foo_url, "x=1")); | 1398 EXPECT_TRUE(SetCookie(cm_foo.get(), foo_url, "x=1")); |
1398 EXPECT_FALSE(SetCookie(cm_foo.get(), http_url, "x=1")); | 1399 EXPECT_FALSE(SetCookie(cm_foo.get(), http_url, "x=1")); |
1399 } | 1400 } |
1400 | 1401 |
1401 TEST_F(CookieMonsterTest, GetAllCookiesForURL) { | 1402 TEST_F(CookieMonsterTest, GetAllCookiesForURL) { |
1402 scoped_ptr<CookieMonster> cm( | 1403 std::unique_ptr<CookieMonster> cm( |
1403 new CookieMonster(nullptr, nullptr, kLastAccessThresholdMilliseconds)); | 1404 new CookieMonster(nullptr, nullptr, kLastAccessThresholdMilliseconds)); |
1404 | 1405 |
1405 // Create an httponly cookie. | 1406 // Create an httponly cookie. |
1406 CookieOptions options; | 1407 CookieOptions options; |
1407 options.set_include_httponly(); | 1408 options.set_include_httponly(); |
1408 | 1409 |
1409 EXPECT_TRUE(SetCookieWithOptions(cm.get(), http_www_google_.url(), | 1410 EXPECT_TRUE(SetCookieWithOptions(cm.get(), http_www_google_.url(), |
1410 "A=B; httponly", options)); | 1411 "A=B; httponly", options)); |
1411 EXPECT_TRUE(SetCookieWithOptions(cm.get(), http_www_google_.url(), | 1412 EXPECT_TRUE(SetCookieWithOptions(cm.get(), http_www_google_.url(), |
1412 http_www_google_.Format("C=D; domain=.%D"), | 1413 http_www_google_.Format("C=D; domain=.%D"), |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1461 EXPECT_EQ(http_www_google_.Format(".%D"), it->Domain()); | 1462 EXPECT_EQ(http_www_google_.Format(".%D"), it->Domain()); |
1462 EXPECT_EQ("E", it->Name()); | 1463 EXPECT_EQ("E", it->Name()); |
1463 | 1464 |
1464 ASSERT_TRUE(++it == cookies.end()); | 1465 ASSERT_TRUE(++it == cookies.end()); |
1465 | 1466 |
1466 // Reading after a short wait should not update the access date. | 1467 // Reading after a short wait should not update the access date. |
1467 EXPECT_EQ(last_access_date, GetFirstCookieAccessDate(cm.get())); | 1468 EXPECT_EQ(last_access_date, GetFirstCookieAccessDate(cm.get())); |
1468 } | 1469 } |
1469 | 1470 |
1470 TEST_F(CookieMonsterTest, GetAllCookiesForURLPathMatching) { | 1471 TEST_F(CookieMonsterTest, GetAllCookiesForURLPathMatching) { |
1471 scoped_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); | 1472 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
1472 CookieOptions options; | 1473 CookieOptions options; |
1473 | 1474 |
1474 EXPECT_TRUE(SetCookieWithOptions(cm.get(), www_google_foo_.url(), | 1475 EXPECT_TRUE(SetCookieWithOptions(cm.get(), www_google_foo_.url(), |
1475 "A=B; path=/foo;", options)); | 1476 "A=B; path=/foo;", options)); |
1476 EXPECT_TRUE(SetCookieWithOptions(cm.get(), www_google_bar_.url(), | 1477 EXPECT_TRUE(SetCookieWithOptions(cm.get(), www_google_bar_.url(), |
1477 "C=D; path=/bar;", options)); | 1478 "C=D; path=/bar;", options)); |
1478 EXPECT_TRUE( | 1479 EXPECT_TRUE( |
1479 SetCookieWithOptions(cm.get(), http_www_google_.url(), "E=F;", options)); | 1480 SetCookieWithOptions(cm.get(), http_www_google_.url(), "E=F;", options)); |
1480 | 1481 |
1481 CookieList cookies = GetAllCookiesForURL(cm.get(), www_google_foo_.url()); | 1482 CookieList cookies = GetAllCookiesForURL(cm.get(), www_google_foo_.url()); |
(...skipping 17 matching lines...) Expand all Loading... |
1499 EXPECT_EQ("/bar", it->Path()); | 1500 EXPECT_EQ("/bar", it->Path()); |
1500 | 1501 |
1501 ASSERT_TRUE(++it != cookies.end()); | 1502 ASSERT_TRUE(++it != cookies.end()); |
1502 EXPECT_EQ("E", it->Name()); | 1503 EXPECT_EQ("E", it->Name()); |
1503 EXPECT_EQ("/", it->Path()); | 1504 EXPECT_EQ("/", it->Path()); |
1504 | 1505 |
1505 ASSERT_TRUE(++it == cookies.end()); | 1506 ASSERT_TRUE(++it == cookies.end()); |
1506 } | 1507 } |
1507 | 1508 |
1508 TEST_F(CookieMonsterTest, CookieSorting) { | 1509 TEST_F(CookieMonsterTest, CookieSorting) { |
1509 scoped_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); | 1510 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
1510 | 1511 |
1511 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "B=B1; path=/")); | 1512 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "B=B1; path=/")); |
1512 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "B=B2; path=/foo")); | 1513 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "B=B2; path=/foo")); |
1513 EXPECT_TRUE( | 1514 EXPECT_TRUE( |
1514 SetCookie(cm.get(), http_www_google_.url(), "B=B3; path=/foo/bar")); | 1515 SetCookie(cm.get(), http_www_google_.url(), "B=B3; path=/foo/bar")); |
1515 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=A1; path=/")); | 1516 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=A1; path=/")); |
1516 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=A2; path=/foo")); | 1517 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=A2; path=/foo")); |
1517 EXPECT_TRUE( | 1518 EXPECT_TRUE( |
1518 SetCookie(cm.get(), http_www_google_.url(), "A=A3; path=/foo/bar")); | 1519 SetCookie(cm.get(), http_www_google_.url(), "A=A3; path=/foo/bar")); |
1519 | 1520 |
1520 // Re-set cookie which should not change sort order. | 1521 // Re-set cookie which should not change sort order. |
1521 EXPECT_TRUE( | 1522 EXPECT_TRUE( |
1522 SetCookie(cm.get(), http_www_google_.url(), "B=B3; path=/foo/bar")); | 1523 SetCookie(cm.get(), http_www_google_.url(), "B=B3; path=/foo/bar")); |
1523 | 1524 |
1524 CookieList cookies = GetAllCookies(cm.get()); | 1525 CookieList cookies = GetAllCookies(cm.get()); |
1525 ASSERT_EQ(6u, cookies.size()); | 1526 ASSERT_EQ(6u, cookies.size()); |
1526 // According to RFC 6265 5.3 (11) re-setting this cookie should retain the | 1527 // According to RFC 6265 5.3 (11) re-setting this cookie should retain the |
1527 // initial creation-time from above, and the sort order should not change. | 1528 // initial creation-time from above, and the sort order should not change. |
1528 // Chrome's current implementation deviates from the spec so capturing this to | 1529 // Chrome's current implementation deviates from the spec so capturing this to |
1529 // avoid any inadvertent changes to this behavior. | 1530 // avoid any inadvertent changes to this behavior. |
1530 EXPECT_EQ("A3", cookies[0].Value()); | 1531 EXPECT_EQ("A3", cookies[0].Value()); |
1531 EXPECT_EQ("B3", cookies[1].Value()); | 1532 EXPECT_EQ("B3", cookies[1].Value()); |
1532 EXPECT_EQ("B2", cookies[2].Value()); | 1533 EXPECT_EQ("B2", cookies[2].Value()); |
1533 EXPECT_EQ("A2", cookies[3].Value()); | 1534 EXPECT_EQ("A2", cookies[3].Value()); |
1534 EXPECT_EQ("B1", cookies[4].Value()); | 1535 EXPECT_EQ("B1", cookies[4].Value()); |
1535 EXPECT_EQ("A1", cookies[5].Value()); | 1536 EXPECT_EQ("A1", cookies[5].Value()); |
1536 } | 1537 } |
1537 | 1538 |
1538 TEST_F(CookieMonsterTest, DeleteCookieByName) { | 1539 TEST_F(CookieMonsterTest, DeleteCookieByName) { |
1539 scoped_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); | 1540 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
1540 | 1541 |
1541 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=A1; path=/")); | 1542 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=A1; path=/")); |
1542 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=A2; path=/foo")); | 1543 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=A2; path=/foo")); |
1543 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=A3; path=/bar")); | 1544 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=A3; path=/bar")); |
1544 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "B=B1; path=/")); | 1545 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "B=B1; path=/")); |
1545 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "B=B2; path=/foo")); | 1546 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "B=B2; path=/foo")); |
1546 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "B=B3; path=/bar")); | 1547 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "B=B3; path=/bar")); |
1547 | 1548 |
1548 DeleteCookie(cm.get(), http_www_google_.AppendPath("foo/bar"), "A"); | 1549 DeleteCookie(cm.get(), http_www_google_.AppendPath("foo/bar"), "A"); |
1549 | 1550 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1605 Time::Now() + TimeDelta::FromDays(2), &initial_cookies); | 1606 Time::Now() + TimeDelta::FromDays(2), &initial_cookies); |
1606 | 1607 |
1607 // Insert 1 cookie with name "Y" on path "/". | 1608 // Insert 1 cookie with name "Y" on path "/". |
1608 AddCookieToList(GURL("http://www.google.com"), | 1609 AddCookieToList(GURL("http://www.google.com"), |
1609 "Y=a; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", | 1610 "Y=a; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", |
1610 Time::Now() + TimeDelta::FromDays(10), &initial_cookies); | 1611 Time::Now() + TimeDelta::FromDays(10), &initial_cookies); |
1611 | 1612 |
1612 // Inject our initial cookies into the mock PersistentCookieStore. | 1613 // Inject our initial cookies into the mock PersistentCookieStore. |
1613 store->SetLoadExpectation(true, initial_cookies); | 1614 store->SetLoadExpectation(true, initial_cookies); |
1614 | 1615 |
1615 scoped_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); | 1616 std::unique_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); |
1616 | 1617 |
1617 // Verify that duplicates were not imported for path "/". | 1618 // Verify that duplicates were not imported for path "/". |
1618 // (If this had failed, GetCookies() would have also returned X=1, X=2, X=4). | 1619 // (If this had failed, GetCookies() would have also returned X=1, X=2, X=4). |
1619 EXPECT_EQ("X=3; Y=a", GetCookies(cm.get(), GURL("http://www.google.com/"))); | 1620 EXPECT_EQ("X=3; Y=a", GetCookies(cm.get(), GURL("http://www.google.com/"))); |
1620 | 1621 |
1621 // Verify that same-named cookie on a different path ("/x2") didn't get | 1622 // Verify that same-named cookie on a different path ("/x2") didn't get |
1622 // messed up. | 1623 // messed up. |
1623 EXPECT_EQ("X=a1; X=3; Y=a", | 1624 EXPECT_EQ("X=a1; X=3; Y=a", |
1624 GetCookies(cm.get(), GURL("http://www.google.com/2/x"))); | 1625 GetCookies(cm.get(), GURL("http://www.google.com/2/x"))); |
1625 | 1626 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1661 AddCookieToList(GURL("http://www.google.com"), "Y=2; path=/", earlier, | 1662 AddCookieToList(GURL("http://www.google.com"), "Y=2; path=/", earlier, |
1662 &initial_cookies); | 1663 &initial_cookies); |
1663 AddCookieToList(GURL("http://www.google.com"), "Y=3; path=/", earlier, | 1664 AddCookieToList(GURL("http://www.google.com"), "Y=3; path=/", earlier, |
1664 &initial_cookies); | 1665 &initial_cookies); |
1665 AddCookieToList(GURL("http://www.google.com"), "Y=4; path=/", earlier, | 1666 AddCookieToList(GURL("http://www.google.com"), "Y=4; path=/", earlier, |
1666 &initial_cookies); | 1667 &initial_cookies); |
1667 | 1668 |
1668 // Inject our initial cookies into the mock PersistentCookieStore. | 1669 // Inject our initial cookies into the mock PersistentCookieStore. |
1669 store->SetLoadExpectation(true, initial_cookies); | 1670 store->SetLoadExpectation(true, initial_cookies); |
1670 | 1671 |
1671 scoped_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); | 1672 std::unique_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); |
1672 | 1673 |
1673 CookieList list(GetAllCookies(cm.get())); | 1674 CookieList list(GetAllCookies(cm.get())); |
1674 EXPECT_EQ(2U, list.size()); | 1675 EXPECT_EQ(2U, list.size()); |
1675 // Confirm that we have one of each. | 1676 // Confirm that we have one of each. |
1676 std::string name1(list[0].Name()); | 1677 std::string name1(list[0].Name()); |
1677 std::string name2(list[1].Name()); | 1678 std::string name2(list[1].Name()); |
1678 EXPECT_TRUE(name1 == "X" || name2 == "X"); | 1679 EXPECT_TRUE(name1 == "X" || name2 == "X"); |
1679 EXPECT_TRUE(name1 == "Y" || name2 == "Y"); | 1680 EXPECT_TRUE(name1 == "Y" || name2 == "Y"); |
1680 EXPECT_NE(name1, name2); | 1681 EXPECT_NE(name1, name2); |
1681 } | 1682 } |
1682 | 1683 |
1683 TEST_F(CookieMonsterTest, CookieMonsterDelegate) { | 1684 TEST_F(CookieMonsterTest, CookieMonsterDelegate) { |
1684 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); | 1685 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); |
1685 scoped_refptr<MockCookieMonsterDelegate> delegate( | 1686 scoped_refptr<MockCookieMonsterDelegate> delegate( |
1686 new MockCookieMonsterDelegate); | 1687 new MockCookieMonsterDelegate); |
1687 scoped_ptr<CookieMonster> cm(new CookieMonster(store.get(), delegate.get())); | 1688 std::unique_ptr<CookieMonster> cm( |
| 1689 new CookieMonster(store.get(), delegate.get())); |
1688 | 1690 |
1689 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=B")); | 1691 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=B")); |
1690 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "C=D")); | 1692 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "C=D")); |
1691 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "E=F")); | 1693 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "E=F")); |
1692 EXPECT_EQ("A=B; C=D; E=F", GetCookies(cm.get(), http_www_google_.url())); | 1694 EXPECT_EQ("A=B; C=D; E=F", GetCookies(cm.get(), http_www_google_.url())); |
1693 ASSERT_EQ(3u, delegate->changes().size()); | 1695 ASSERT_EQ(3u, delegate->changes().size()); |
1694 EXPECT_FALSE(delegate->changes()[0].second); | 1696 EXPECT_FALSE(delegate->changes()[0].second); |
1695 EXPECT_EQ(http_www_google_.url().host(), | 1697 EXPECT_EQ(http_www_google_.url().host(), |
1696 delegate->changes()[0].first.Domain()); | 1698 delegate->changes()[0].first.Domain()); |
1697 EXPECT_EQ("A", delegate->changes()[0].first.Name()); | 1699 EXPECT_EQ("A", delegate->changes()[0].first.Name()); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1757 EXPECT_EQ(http_www_google_.url().host(), | 1759 EXPECT_EQ(http_www_google_.url().host(), |
1758 delegate->changes()[1].first.Domain()); | 1760 delegate->changes()[1].first.Domain()); |
1759 EXPECT_FALSE(delegate->changes()[1].second); | 1761 EXPECT_FALSE(delegate->changes()[1].second); |
1760 EXPECT_EQ("a", delegate->changes()[1].first.Name()); | 1762 EXPECT_EQ("a", delegate->changes()[1].first.Name()); |
1761 EXPECT_EQ("val2", delegate->changes()[1].first.Value()); | 1763 EXPECT_EQ("val2", delegate->changes()[1].first.Value()); |
1762 delegate->reset(); | 1764 delegate->reset(); |
1763 } | 1765 } |
1764 | 1766 |
1765 TEST_F(CookieMonsterTest, PredicateSeesAllCookies) { | 1767 TEST_F(CookieMonsterTest, PredicateSeesAllCookies) { |
1766 const std::string kTrueValue = "A"; | 1768 const std::string kTrueValue = "A"; |
1767 scoped_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); | 1769 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
1768 // We test that we can see all cookies with our predicated. This includes | 1770 // We test that we can see all cookies with our predicated. This includes |
1769 // host, http_only, host secure, and all domain cookies. | 1771 // host, http_only, host secure, and all domain cookies. |
1770 CookiePredicate value_matcher = base::Bind(&CookieValuePredicate, kTrueValue); | 1772 CookiePredicate value_matcher = base::Bind(&CookieValuePredicate, kTrueValue); |
1771 | 1773 |
1772 PopulateCmForPredicateCheck(cm.get()); | 1774 PopulateCmForPredicateCheck(cm.get()); |
1773 EXPECT_EQ(7, DeleteAllCreatedBetweenWithPredicate( | 1775 EXPECT_EQ(7, DeleteAllCreatedBetweenWithPredicate( |
1774 cm.get(), base::Time(), base::Time::Now(), value_matcher)); | 1776 cm.get(), base::Time(), base::Time::Now(), value_matcher)); |
1775 | 1777 |
1776 EXPECT_EQ("dom_2=B; dom_3=C; host_3=C", | 1778 EXPECT_EQ("dom_2=B; dom_3=C; host_3=C", |
1777 GetCookies(cm.get(), GURL(kTopLevelDomainPlus3))); | 1779 GetCookies(cm.get(), GURL(kTopLevelDomainPlus3))); |
1778 EXPECT_EQ("dom_2=B; host_2=B; sec_host=B", | 1780 EXPECT_EQ("dom_2=B; host_2=B; sec_host=B", |
1779 GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure))); | 1781 GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure))); |
1780 EXPECT_EQ("", GetCookies(cm.get(), GURL(kTopLevelDomainPlus1))); | 1782 EXPECT_EQ("", GetCookies(cm.get(), GURL(kTopLevelDomainPlus1))); |
1781 EXPECT_EQ("dom_path_2=B; host_path_2=B; dom_2=B; host_2=B; sec_host=B", | 1783 EXPECT_EQ("dom_path_2=B; host_path_2=B; dom_2=B; host_2=B; sec_host=B", |
1782 GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure + | 1784 GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure + |
1783 std::string("/dir1/dir2/xxx")))); | 1785 std::string("/dir1/dir2/xxx")))); |
1784 } | 1786 } |
1785 | 1787 |
1786 TEST_F(CookieMonsterTest, UniqueCreationTime) { | 1788 TEST_F(CookieMonsterTest, UniqueCreationTime) { |
1787 scoped_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); | 1789 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
1788 CookieOptions options; | 1790 CookieOptions options; |
1789 | 1791 |
1790 // Add in three cookies through every public interface to the | 1792 // Add in three cookies through every public interface to the |
1791 // CookieMonster and confirm that none of them have duplicate | 1793 // CookieMonster and confirm that none of them have duplicate |
1792 // creation times. | 1794 // creation times. |
1793 | 1795 |
1794 // SetCookieWithCreationTime and SetCookieWithCreationTimeAndOptions | 1796 // SetCookieWithCreationTime and SetCookieWithCreationTimeAndOptions |
1795 // are not included as they aren't going to be public for very much | 1797 // are not included as they aren't going to be public for very much |
1796 // longer. | 1798 // longer. |
1797 | 1799 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1840 if (existing_cookie_it == check_map.end()) { | 1842 if (existing_cookie_it == check_map.end()) { |
1841 check_map.insert( | 1843 check_map.insert( |
1842 TimeCookieMap::value_type(it->CreationDate().ToInternalValue(), *it)); | 1844 TimeCookieMap::value_type(it->CreationDate().ToInternalValue(), *it)); |
1843 } | 1845 } |
1844 } | 1846 } |
1845 } | 1847 } |
1846 | 1848 |
1847 // Mainly a test of GetEffectiveDomain, or more specifically, of the | 1849 // Mainly a test of GetEffectiveDomain, or more specifically, of the |
1848 // expected behavior of GetEffectiveDomain within the CookieMonster. | 1850 // expected behavior of GetEffectiveDomain within the CookieMonster. |
1849 TEST_F(CookieMonsterTest, GetKey) { | 1851 TEST_F(CookieMonsterTest, GetKey) { |
1850 scoped_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); | 1852 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
1851 | 1853 |
1852 // This test is really only interesting if GetKey() actually does something. | 1854 // This test is really only interesting if GetKey() actually does something. |
1853 EXPECT_EQ("google.com", cm->GetKey("www.google.com")); | 1855 EXPECT_EQ("google.com", cm->GetKey("www.google.com")); |
1854 EXPECT_EQ("google.izzie", cm->GetKey("www.google.izzie")); | 1856 EXPECT_EQ("google.izzie", cm->GetKey("www.google.izzie")); |
1855 EXPECT_EQ("google.izzie", cm->GetKey(".google.izzie")); | 1857 EXPECT_EQ("google.izzie", cm->GetKey(".google.izzie")); |
1856 EXPECT_EQ("bbc.co.uk", cm->GetKey("bbc.co.uk")); | 1858 EXPECT_EQ("bbc.co.uk", cm->GetKey("bbc.co.uk")); |
1857 EXPECT_EQ("bbc.co.uk", cm->GetKey("a.b.c.d.bbc.co.uk")); | 1859 EXPECT_EQ("bbc.co.uk", cm->GetKey("a.b.c.d.bbc.co.uk")); |
1858 EXPECT_EQ("apple.com", cm->GetKey("a.b.c.d.apple.com")); | 1860 EXPECT_EQ("apple.com", cm->GetKey("a.b.c.d.apple.com")); |
1859 EXPECT_EQ("apple.izzie", cm->GetKey("a.b.c.d.apple.izzie")); | 1861 EXPECT_EQ("apple.izzie", cm->GetKey("a.b.c.d.apple.izzie")); |
1860 | 1862 |
(...skipping 23 matching lines...) Expand all Loading... |
1884 {GURL("https://www.google.com"), "b", "2", ".google.com", | 1886 {GURL("https://www.google.com"), "b", "2", ".google.com", |
1885 "/path/from/cookie", expires + TimeDelta::FromSeconds(10), true, true, | 1887 "/path/from/cookie", expires + TimeDelta::FromSeconds(10), true, true, |
1886 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT}, | 1888 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT}, |
1887 {GURL("https://google.com"), "c", "3", "", "/another/path/to/cookie", | 1889 {GURL("https://google.com"), "c", "3", "", "/another/path/to/cookie", |
1888 base::Time::Now() + base::TimeDelta::FromSeconds(100), true, false, | 1890 base::Time::Now() + base::TimeDelta::FromSeconds(100), true, false, |
1889 CookieSameSite::STRICT_MODE, COOKIE_PRIORITY_DEFAULT}}; | 1891 CookieSameSite::STRICT_MODE, COOKIE_PRIORITY_DEFAULT}}; |
1890 const int INPUT_DELETE = 1; | 1892 const int INPUT_DELETE = 1; |
1891 | 1893 |
1892 // Create new cookies and flush them to the store. | 1894 // Create new cookies and flush them to the store. |
1893 { | 1895 { |
1894 scoped_ptr<CookieMonster> cmout(new CookieMonster(store.get(), nullptr)); | 1896 std::unique_ptr<CookieMonster> cmout( |
| 1897 new CookieMonster(store.get(), nullptr)); |
1895 for (const CookiesInputInfo* p = input_info; | 1898 for (const CookiesInputInfo* p = input_info; |
1896 p < &input_info[arraysize(input_info)]; p++) { | 1899 p < &input_info[arraysize(input_info)]; p++) { |
1897 EXPECT_TRUE(SetCookieWithDetails( | 1900 EXPECT_TRUE(SetCookieWithDetails( |
1898 cmout.get(), p->url, p->name, p->value, p->domain, p->path, | 1901 cmout.get(), p->url, p->name, p->value, p->domain, p->path, |
1899 base::Time(), p->expiration_time, base::Time(), p->secure, | 1902 base::Time(), p->expiration_time, base::Time(), p->secure, |
1900 p->http_only, p->same_site, p->priority)); | 1903 p->http_only, p->same_site, p->priority)); |
1901 } | 1904 } |
1902 GURL del_url(input_info[INPUT_DELETE] | 1905 GURL del_url(input_info[INPUT_DELETE] |
1903 .url.Resolve(input_info[INPUT_DELETE].path) | 1906 .url.Resolve(input_info[INPUT_DELETE].path) |
1904 .spec()); | 1907 .spec()); |
1905 DeleteCookie(cmout.get(), del_url, input_info[INPUT_DELETE].name); | 1908 DeleteCookie(cmout.get(), del_url, input_info[INPUT_DELETE].name); |
1906 } | 1909 } |
1907 | 1910 |
1908 // Create a new cookie monster and make sure that everything is correct | 1911 // Create a new cookie monster and make sure that everything is correct |
1909 { | 1912 { |
1910 scoped_ptr<CookieMonster> cmin(new CookieMonster(store.get(), nullptr)); | 1913 std::unique_ptr<CookieMonster> cmin( |
| 1914 new CookieMonster(store.get(), nullptr)); |
1911 CookieList cookies(GetAllCookies(cmin.get())); | 1915 CookieList cookies(GetAllCookies(cmin.get())); |
1912 ASSERT_EQ(2u, cookies.size()); | 1916 ASSERT_EQ(2u, cookies.size()); |
1913 // Ordering is path length, then creation time. So second cookie | 1917 // Ordering is path length, then creation time. So second cookie |
1914 // will come first, and we need to swap them. | 1918 // will come first, and we need to swap them. |
1915 std::swap(cookies[0], cookies[1]); | 1919 std::swap(cookies[0], cookies[1]); |
1916 for (int output_index = 0; output_index < 2; output_index++) { | 1920 for (int output_index = 0; output_index < 2; output_index++) { |
1917 int input_index = output_index * 2; | 1921 int input_index = output_index * 2; |
1918 const CookiesInputInfo* input = &input_info[input_index]; | 1922 const CookiesInputInfo* input = &input_info[input_index]; |
1919 const CanonicalCookie* output = &cookies[output_index]; | 1923 const CanonicalCookie* output = &cookies[output_index]; |
1920 | 1924 |
1921 EXPECT_EQ(input->name, output->Name()); | 1925 EXPECT_EQ(input->name, output->Name()); |
1922 EXPECT_EQ(input->value, output->Value()); | 1926 EXPECT_EQ(input->value, output->Value()); |
1923 EXPECT_EQ(input->url.host(), output->Domain()); | 1927 EXPECT_EQ(input->url.host(), output->Domain()); |
1924 EXPECT_EQ(input->path, output->Path()); | 1928 EXPECT_EQ(input->path, output->Path()); |
1925 EXPECT_LE(current.ToInternalValue(), | 1929 EXPECT_LE(current.ToInternalValue(), |
1926 output->CreationDate().ToInternalValue()); | 1930 output->CreationDate().ToInternalValue()); |
1927 EXPECT_EQ(input->secure, output->IsSecure()); | 1931 EXPECT_EQ(input->secure, output->IsSecure()); |
1928 EXPECT_EQ(input->http_only, output->IsHttpOnly()); | 1932 EXPECT_EQ(input->http_only, output->IsHttpOnly()); |
1929 EXPECT_EQ(input->same_site, output->SameSite()); | 1933 EXPECT_EQ(input->same_site, output->SameSite()); |
1930 EXPECT_TRUE(output->IsPersistent()); | 1934 EXPECT_TRUE(output->IsPersistent()); |
1931 EXPECT_EQ(input->expiration_time.ToInternalValue(), | 1935 EXPECT_EQ(input->expiration_time.ToInternalValue(), |
1932 output->ExpiryDate().ToInternalValue()); | 1936 output->ExpiryDate().ToInternalValue()); |
1933 } | 1937 } |
1934 } | 1938 } |
1935 } | 1939 } |
1936 | 1940 |
1937 TEST_F(CookieMonsterTest, CookieListOrdering) { | 1941 TEST_F(CookieMonsterTest, CookieListOrdering) { |
1938 // Put a random set of cookies into a monster and make sure | 1942 // Put a random set of cookies into a monster and make sure |
1939 // they're returned in the right order. | 1943 // they're returned in the right order. |
1940 scoped_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); | 1944 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
1941 EXPECT_TRUE( | 1945 EXPECT_TRUE( |
1942 SetCookie(cm.get(), GURL("http://d.c.b.a.google.com/aa/x.html"), "c=1")); | 1946 SetCookie(cm.get(), GURL("http://d.c.b.a.google.com/aa/x.html"), "c=1")); |
1943 EXPECT_TRUE(SetCookie(cm.get(), GURL("http://b.a.google.com/aa/bb/cc/x.html"), | 1947 EXPECT_TRUE(SetCookie(cm.get(), GURL("http://b.a.google.com/aa/bb/cc/x.html"), |
1944 "d=1; domain=b.a.google.com")); | 1948 "d=1; domain=b.a.google.com")); |
1945 EXPECT_TRUE(SetCookie(cm.get(), GURL("http://b.a.google.com/aa/bb/cc/x.html"), | 1949 EXPECT_TRUE(SetCookie(cm.get(), GURL("http://b.a.google.com/aa/bb/cc/x.html"), |
1946 "a=4; domain=b.a.google.com")); | 1950 "a=4; domain=b.a.google.com")); |
1947 EXPECT_TRUE(SetCookie(cm.get(), | 1951 EXPECT_TRUE(SetCookie(cm.get(), |
1948 GURL("http://c.b.a.google.com/aa/bb/cc/x.html"), | 1952 GURL("http://c.b.a.google.com/aa/bb/cc/x.html"), |
1949 "e=1; domain=c.b.a.google.com")); | 1953 "e=1; domain=c.b.a.google.com")); |
1950 EXPECT_TRUE(SetCookie(cm.get(), | 1954 EXPECT_TRUE(SetCookie(cm.get(), |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1987 #if defined(OS_WIN) | 1991 #if defined(OS_WIN) |
1988 #define MAYBE_GarbageCollectionTriggers DISABLED_GarbageCollectionTriggers | 1992 #define MAYBE_GarbageCollectionTriggers DISABLED_GarbageCollectionTriggers |
1989 #else | 1993 #else |
1990 #define MAYBE_GarbageCollectionTriggers GarbageCollectionTriggers | 1994 #define MAYBE_GarbageCollectionTriggers GarbageCollectionTriggers |
1991 #endif | 1995 #endif |
1992 | 1996 |
1993 TEST_F(CookieMonsterTest, MAYBE_GarbageCollectionTriggers) { | 1997 TEST_F(CookieMonsterTest, MAYBE_GarbageCollectionTriggers) { |
1994 // First we check to make sure that a whole lot of recent cookies | 1998 // First we check to make sure that a whole lot of recent cookies |
1995 // doesn't get rid of anything after garbage collection is checked for. | 1999 // doesn't get rid of anything after garbage collection is checked for. |
1996 { | 2000 { |
1997 scoped_ptr<CookieMonster> cm( | 2001 std::unique_ptr<CookieMonster> cm( |
1998 CreateMonsterForGC(CookieMonster::kMaxCookies * 2)); | 2002 CreateMonsterForGC(CookieMonster::kMaxCookies * 2)); |
1999 EXPECT_EQ(CookieMonster::kMaxCookies * 2, GetAllCookies(cm.get()).size()); | 2003 EXPECT_EQ(CookieMonster::kMaxCookies * 2, GetAllCookies(cm.get()).size()); |
2000 SetCookie(cm.get(), GURL("http://newdomain.com"), "b=2"); | 2004 SetCookie(cm.get(), GURL("http://newdomain.com"), "b=2"); |
2001 EXPECT_EQ(CookieMonster::kMaxCookies * 2 + 1, | 2005 EXPECT_EQ(CookieMonster::kMaxCookies * 2 + 1, |
2002 GetAllCookies(cm.get()).size()); | 2006 GetAllCookies(cm.get()).size()); |
2003 } | 2007 } |
2004 | 2008 |
2005 // Now we explore a series of relationships between cookie last access | 2009 // Now we explore a series of relationships between cookie last access |
2006 // time and size of store to make sure we only get rid of cookies when | 2010 // time and size of store to make sure we only get rid of cookies when |
2007 // we really should. | 2011 // we really should. |
(...skipping 21 matching lines...) Expand all Loading... |
2029 CookieMonster::kMaxCookies - CookieMonster::kPurgeCookies}, | 2033 CookieMonster::kMaxCookies - CookieMonster::kPurgeCookies}, |
2030 {// Old cookies enough to bring below our purge line (which we | 2034 {// Old cookies enough to bring below our purge line (which we |
2031 // shouldn't do). | 2035 // shouldn't do). |
2032 CookieMonster::kMaxCookies * 2, | 2036 CookieMonster::kMaxCookies * 2, |
2033 CookieMonster::kMaxCookies * 3 / 2, | 2037 CookieMonster::kMaxCookies * 3 / 2, |
2034 CookieMonster::kMaxCookies * 2, | 2038 CookieMonster::kMaxCookies * 2, |
2035 CookieMonster::kMaxCookies - CookieMonster::kPurgeCookies}}; | 2039 CookieMonster::kMaxCookies - CookieMonster::kPurgeCookies}}; |
2036 | 2040 |
2037 for (int ci = 0; ci < static_cast<int>(arraysize(test_cases)); ++ci) { | 2041 for (int ci = 0; ci < static_cast<int>(arraysize(test_cases)); ++ci) { |
2038 const TestCase* test_case = &test_cases[ci]; | 2042 const TestCase* test_case = &test_cases[ci]; |
2039 scoped_ptr<CookieMonster> cm = CreateMonsterFromStoreForGC( | 2043 std::unique_ptr<CookieMonster> cm = CreateMonsterFromStoreForGC( |
2040 test_case->num_cookies, test_case->num_old_cookies, 0, 0, | 2044 test_case->num_cookies, test_case->num_old_cookies, 0, 0, |
2041 CookieMonster::kSafeFromGlobalPurgeDays * 2); | 2045 CookieMonster::kSafeFromGlobalPurgeDays * 2); |
2042 EXPECT_EQ(test_case->expected_initial_cookies, | 2046 EXPECT_EQ(test_case->expected_initial_cookies, |
2043 GetAllCookies(cm.get()).size()) | 2047 GetAllCookies(cm.get()).size()) |
2044 << "For test case " << ci; | 2048 << "For test case " << ci; |
2045 // Will trigger GC | 2049 // Will trigger GC |
2046 SetCookie(cm.get(), GURL("http://newdomain.com"), "b=2"); | 2050 SetCookie(cm.get(), GURL("http://newdomain.com"), "b=2"); |
2047 EXPECT_EQ(test_case->expected_cookies_after_set, | 2051 EXPECT_EQ(test_case->expected_cookies_after_set, |
2048 GetAllCookies(cm.get()).size()) | 2052 GetAllCookies(cm.get()).size()) |
2049 << "For test case " << ci; | 2053 << "For test case " << ci; |
2050 } | 2054 } |
2051 } | 2055 } |
2052 | 2056 |
2053 // Tests that if the main load event happens before the loaded event for a | 2057 // Tests that if the main load event happens before the loaded event for a |
2054 // particular key, the tasks for that key run first. | 2058 // particular key, the tasks for that key run first. |
2055 TEST_F(CookieMonsterTest, WhileLoadingLoadCompletesBeforeKeyLoadCompletes) { | 2059 TEST_F(CookieMonsterTest, WhileLoadingLoadCompletesBeforeKeyLoadCompletes) { |
2056 const GURL kUrl = GURL(kTopLevelDomainPlus1); | 2060 const GURL kUrl = GURL(kTopLevelDomainPlus1); |
2057 | 2061 |
2058 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); | 2062 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); |
2059 store->set_store_load_commands(true); | 2063 store->set_store_load_commands(true); |
2060 scoped_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); | 2064 std::unique_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); |
2061 | 2065 |
2062 // Get all cookies task that queues a task to set a cookie when executed. | 2066 // Get all cookies task that queues a task to set a cookie when executed. |
2063 ResultSavingCookieCallback<bool> set_cookie_callback; | 2067 ResultSavingCookieCallback<bool> set_cookie_callback; |
2064 cm->SetCookieWithOptionsAsync( | 2068 cm->SetCookieWithOptionsAsync( |
2065 kUrl, "a=b", CookieOptions(), | 2069 kUrl, "a=b", CookieOptions(), |
2066 base::Bind(&ResultSavingCookieCallback<bool>::Run, | 2070 base::Bind(&ResultSavingCookieCallback<bool>::Run, |
2067 base::Unretained(&set_cookie_callback))); | 2071 base::Unretained(&set_cookie_callback))); |
2068 | 2072 |
2069 GetCookieListCallback get_cookie_list_callback1; | 2073 GetCookieListCallback get_cookie_list_callback1; |
2070 cm->GetAllCookiesAsync( | 2074 cm->GetAllCookiesAsync( |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2102 } | 2106 } |
2103 | 2107 |
2104 // Tests that case that DeleteAll is waiting for load to complete, and then a | 2108 // Tests that case that DeleteAll is waiting for load to complete, and then a |
2105 // get is queued. The get should wait to run until after all the cookies are | 2109 // get is queued. The get should wait to run until after all the cookies are |
2106 // retrieved, and should return nothing, since all cookies were just deleted. | 2110 // retrieved, and should return nothing, since all cookies were just deleted. |
2107 TEST_F(CookieMonsterTest, WhileLoadingDeleteAllGetForURL) { | 2111 TEST_F(CookieMonsterTest, WhileLoadingDeleteAllGetForURL) { |
2108 const GURL kUrl = GURL(kTopLevelDomainPlus1); | 2112 const GURL kUrl = GURL(kTopLevelDomainPlus1); |
2109 | 2113 |
2110 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); | 2114 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); |
2111 store->set_store_load_commands(true); | 2115 store->set_store_load_commands(true); |
2112 scoped_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); | 2116 std::unique_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); |
2113 | 2117 |
2114 ResultSavingCookieCallback<int> delete_callback; | 2118 ResultSavingCookieCallback<int> delete_callback; |
2115 cm->DeleteAllAsync(base::Bind(&ResultSavingCookieCallback<int>::Run, | 2119 cm->DeleteAllAsync(base::Bind(&ResultSavingCookieCallback<int>::Run, |
2116 base::Unretained(&delete_callback))); | 2120 base::Unretained(&delete_callback))); |
2117 | 2121 |
2118 GetCookieListCallback get_cookie_list_callback; | 2122 GetCookieListCallback get_cookie_list_callback; |
2119 cm->GetCookieListWithOptionsAsync( | 2123 cm->GetCookieListWithOptionsAsync( |
2120 kUrl, CookieOptions(), | 2124 kUrl, CookieOptions(), |
2121 base::Bind(&GetCookieListCallback::Run, | 2125 base::Bind(&GetCookieListCallback::Run, |
2122 base::Unretained(&get_cookie_list_callback))); | 2126 base::Unretained(&get_cookie_list_callback))); |
(...skipping 20 matching lines...) Expand all Loading... |
2143 | 2147 |
2144 // Tests that a set cookie call sandwiched between two get all cookies, all | 2148 // Tests that a set cookie call sandwiched between two get all cookies, all |
2145 // before load completes, affects the first but not the second. The set should | 2149 // before load completes, affects the first but not the second. The set should |
2146 // also not trigger a LoadCookiesForKey (As that could complete only after the | 2150 // also not trigger a LoadCookiesForKey (As that could complete only after the |
2147 // main load for the store). | 2151 // main load for the store). |
2148 TEST_F(CookieMonsterTest, WhileLoadingGetAllSetGetAll) { | 2152 TEST_F(CookieMonsterTest, WhileLoadingGetAllSetGetAll) { |
2149 const GURL kUrl = GURL(kTopLevelDomainPlus1); | 2153 const GURL kUrl = GURL(kTopLevelDomainPlus1); |
2150 | 2154 |
2151 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); | 2155 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); |
2152 store->set_store_load_commands(true); | 2156 store->set_store_load_commands(true); |
2153 scoped_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); | 2157 std::unique_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); |
2154 | 2158 |
2155 GetCookieListCallback get_cookie_list_callback1; | 2159 GetCookieListCallback get_cookie_list_callback1; |
2156 cm->GetAllCookiesAsync( | 2160 cm->GetAllCookiesAsync( |
2157 base::Bind(&GetCookieListCallback::Run, | 2161 base::Bind(&GetCookieListCallback::Run, |
2158 base::Unretained(&get_cookie_list_callback1))); | 2162 base::Unretained(&get_cookie_list_callback1))); |
2159 | 2163 |
2160 ResultSavingCookieCallback<bool> set_cookie_callback; | 2164 ResultSavingCookieCallback<bool> set_cookie_callback; |
2161 cm->SetCookieWithOptionsAsync( | 2165 cm->SetCookieWithOptionsAsync( |
2162 kUrl, "a=b", CookieOptions(), | 2166 kUrl, "a=b", CookieOptions(), |
2163 base::Bind(&ResultSavingCookieCallback<bool>::Run, | 2167 base::Bind(&ResultSavingCookieCallback<bool>::Run, |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2195 } // namespace | 2199 } // namespace |
2196 | 2200 |
2197 // Tests that if a single cookie task is queued as a result of a task performed | 2201 // Tests that if a single cookie task is queued as a result of a task performed |
2198 // on all cookies when loading completes, it will be run after any already | 2202 // on all cookies when loading completes, it will be run after any already |
2199 // queued tasks. | 2203 // queued tasks. |
2200 TEST_F(CookieMonsterTest, CheckOrderOfCookieTaskQueueWhenLoadingCompletes) { | 2204 TEST_F(CookieMonsterTest, CheckOrderOfCookieTaskQueueWhenLoadingCompletes) { |
2201 const GURL kUrl = GURL(kTopLevelDomainPlus1); | 2205 const GURL kUrl = GURL(kTopLevelDomainPlus1); |
2202 | 2206 |
2203 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); | 2207 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); |
2204 store->set_store_load_commands(true); | 2208 store->set_store_load_commands(true); |
2205 scoped_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); | 2209 std::unique_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); |
2206 | 2210 |
2207 // Get all cookies task that queues a task to set a cookie when executed. | 2211 // Get all cookies task that queues a task to set a cookie when executed. |
2208 ResultSavingCookieCallback<bool> set_cookie_callback; | 2212 ResultSavingCookieCallback<bool> set_cookie_callback; |
2209 cm->GetAllCookiesAsync(base::Bind( | 2213 cm->GetAllCookiesAsync(base::Bind( |
2210 &RunClosureOnCookieListReceived, | 2214 &RunClosureOnCookieListReceived, |
2211 base::Bind(&CookieStore::SetCookieWithOptionsAsync, | 2215 base::Bind(&CookieStore::SetCookieWithOptionsAsync, |
2212 base::Unretained(cm.get()), kUrl, "a=b", CookieOptions(), | 2216 base::Unretained(cm.get()), kUrl, "a=b", CookieOptions(), |
2213 base::Bind(&ResultSavingCookieCallback<bool>::Run, | 2217 base::Bind(&ResultSavingCookieCallback<bool>::Run, |
2214 base::Unretained(&set_cookie_callback))))); | 2218 base::Unretained(&set_cookie_callback))))); |
2215 | 2219 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2297 | 2301 |
2298 volatile int callback_count_; | 2302 volatile int callback_count_; |
2299 }; | 2303 }; |
2300 | 2304 |
2301 } // namespace | 2305 } // namespace |
2302 | 2306 |
2303 // Test that FlushStore() is forwarded to the store and callbacks are posted. | 2307 // Test that FlushStore() is forwarded to the store and callbacks are posted. |
2304 TEST_F(CookieMonsterTest, FlushStore) { | 2308 TEST_F(CookieMonsterTest, FlushStore) { |
2305 scoped_refptr<CallbackCounter> counter(new CallbackCounter()); | 2309 scoped_refptr<CallbackCounter> counter(new CallbackCounter()); |
2306 scoped_refptr<FlushablePersistentStore> store(new FlushablePersistentStore()); | 2310 scoped_refptr<FlushablePersistentStore> store(new FlushablePersistentStore()); |
2307 scoped_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); | 2311 std::unique_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); |
2308 | 2312 |
2309 ASSERT_EQ(0, store->flush_count()); | 2313 ASSERT_EQ(0, store->flush_count()); |
2310 ASSERT_EQ(0, counter->callback_count()); | 2314 ASSERT_EQ(0, counter->callback_count()); |
2311 | 2315 |
2312 // Before initialization, FlushStore() should just run the callback. | 2316 // Before initialization, FlushStore() should just run the callback. |
2313 cm->FlushStore(base::Bind(&CallbackCounter::Callback, counter.get())); | 2317 cm->FlushStore(base::Bind(&CallbackCounter::Callback, counter.get())); |
2314 base::MessageLoop::current()->RunUntilIdle(); | 2318 base::MessageLoop::current()->RunUntilIdle(); |
2315 | 2319 |
2316 ASSERT_EQ(0, store->flush_count()); | 2320 ASSERT_EQ(0, store->flush_count()); |
2317 ASSERT_EQ(1, counter->callback_count()); | 2321 ASSERT_EQ(1, counter->callback_count()); |
(...skipping 29 matching lines...) Expand all Loading... |
2347 ASSERT_EQ(2, counter->callback_count()); | 2351 ASSERT_EQ(2, counter->callback_count()); |
2348 | 2352 |
2349 cm->FlushStore(base::Bind(&CallbackCounter::Callback, counter.get())); | 2353 cm->FlushStore(base::Bind(&CallbackCounter::Callback, counter.get())); |
2350 base::MessageLoop::current()->RunUntilIdle(); | 2354 base::MessageLoop::current()->RunUntilIdle(); |
2351 | 2355 |
2352 ASSERT_EQ(3, counter->callback_count()); | 2356 ASSERT_EQ(3, counter->callback_count()); |
2353 } | 2357 } |
2354 | 2358 |
2355 TEST_F(CookieMonsterTest, SetAllCookies) { | 2359 TEST_F(CookieMonsterTest, SetAllCookies) { |
2356 scoped_refptr<FlushablePersistentStore> store(new FlushablePersistentStore()); | 2360 scoped_refptr<FlushablePersistentStore> store(new FlushablePersistentStore()); |
2357 scoped_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); | 2361 std::unique_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); |
2358 cm->SetPersistSessionCookies(true); | 2362 cm->SetPersistSessionCookies(true); |
2359 | 2363 |
2360 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "U=V; path=/")); | 2364 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "U=V; path=/")); |
2361 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "W=X; path=/foo")); | 2365 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "W=X; path=/foo")); |
2362 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "Y=Z; path=/")); | 2366 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "Y=Z; path=/")); |
2363 | 2367 |
2364 CookieList list; | 2368 CookieList list; |
2365 list.push_back(*CanonicalCookie::Create( | 2369 list.push_back(*CanonicalCookie::Create( |
2366 http_www_google_.url(), "A", "B", http_www_google_.url().host(), "/", | 2370 http_www_google_.url(), "A", "B", http_www_google_.url().host(), "/", |
2367 base::Time::Now(), base::Time(), false, false, | 2371 base::Time::Now(), base::Time(), false, false, |
(...skipping 25 matching lines...) Expand all Loading... |
2393 ASSERT_TRUE(++it != cookies.end()); | 2397 ASSERT_TRUE(++it != cookies.end()); |
2394 EXPECT_EQ("A", it->Name()); | 2398 EXPECT_EQ("A", it->Name()); |
2395 EXPECT_EQ("B", it->Value()); | 2399 EXPECT_EQ("B", it->Value()); |
2396 | 2400 |
2397 ASSERT_TRUE(++it != cookies.end()); | 2401 ASSERT_TRUE(++it != cookies.end()); |
2398 EXPECT_EQ("Y", it->Name()); | 2402 EXPECT_EQ("Y", it->Name()); |
2399 EXPECT_EQ("Z", it->Value()); | 2403 EXPECT_EQ("Z", it->Value()); |
2400 } | 2404 } |
2401 | 2405 |
2402 TEST_F(CookieMonsterTest, ComputeCookieDiff) { | 2406 TEST_F(CookieMonsterTest, ComputeCookieDiff) { |
2403 scoped_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); | 2407 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
2404 | 2408 |
2405 base::Time now = base::Time::Now(); | 2409 base::Time now = base::Time::Now(); |
2406 base::Time creation_time = now - base::TimeDelta::FromSeconds(1); | 2410 base::Time creation_time = now - base::TimeDelta::FromSeconds(1); |
2407 | 2411 |
2408 scoped_ptr<CanonicalCookie> cookie1(CanonicalCookie::Create( | 2412 std::unique_ptr<CanonicalCookie> cookie1(CanonicalCookie::Create( |
2409 http_www_google_.url(), "A", "B", http_www_google_.url().host(), "/", | 2413 http_www_google_.url(), "A", "B", http_www_google_.url().host(), "/", |
2410 creation_time, base::Time(), false, false, CookieSameSite::DEFAULT_MODE, | 2414 creation_time, base::Time(), false, false, CookieSameSite::DEFAULT_MODE, |
2411 false, COOKIE_PRIORITY_DEFAULT)); | 2415 false, COOKIE_PRIORITY_DEFAULT)); |
2412 scoped_ptr<CanonicalCookie> cookie2(CanonicalCookie::Create( | 2416 std::unique_ptr<CanonicalCookie> cookie2(CanonicalCookie::Create( |
2413 http_www_google_.url(), "C", "D", http_www_google_.url().host(), "/", | 2417 http_www_google_.url(), "C", "D", http_www_google_.url().host(), "/", |
2414 creation_time, base::Time(), false, false, CookieSameSite::DEFAULT_MODE, | 2418 creation_time, base::Time(), false, false, CookieSameSite::DEFAULT_MODE, |
2415 false, COOKIE_PRIORITY_DEFAULT)); | 2419 false, COOKIE_PRIORITY_DEFAULT)); |
2416 scoped_ptr<CanonicalCookie> cookie3(CanonicalCookie::Create( | 2420 std::unique_ptr<CanonicalCookie> cookie3(CanonicalCookie::Create( |
2417 http_www_google_.url(), "E", "F", http_www_google_.url().host(), "/", | 2421 http_www_google_.url(), "E", "F", http_www_google_.url().host(), "/", |
2418 creation_time, base::Time(), false, false, CookieSameSite::DEFAULT_MODE, | 2422 creation_time, base::Time(), false, false, CookieSameSite::DEFAULT_MODE, |
2419 false, COOKIE_PRIORITY_DEFAULT)); | 2423 false, COOKIE_PRIORITY_DEFAULT)); |
2420 scoped_ptr<CanonicalCookie> cookie4(CanonicalCookie::Create( | 2424 std::unique_ptr<CanonicalCookie> cookie4(CanonicalCookie::Create( |
2421 http_www_google_.url(), "G", "H", http_www_google_.url().host(), "/", | 2425 http_www_google_.url(), "G", "H", http_www_google_.url().host(), "/", |
2422 creation_time, base::Time(), false, false, CookieSameSite::DEFAULT_MODE, | 2426 creation_time, base::Time(), false, false, CookieSameSite::DEFAULT_MODE, |
2423 false, COOKIE_PRIORITY_DEFAULT)); | 2427 false, COOKIE_PRIORITY_DEFAULT)); |
2424 scoped_ptr<CanonicalCookie> cookie4_with_new_value(CanonicalCookie::Create( | 2428 std::unique_ptr<CanonicalCookie> cookie4_with_new_value( |
2425 http_www_google_.url(), "G", "iamnew", http_www_google_.url().host(), "/", | 2429 CanonicalCookie::Create( |
2426 creation_time, base::Time(), false, false, CookieSameSite::DEFAULT_MODE, | 2430 http_www_google_.url(), "G", "iamnew", http_www_google_.url().host(), |
2427 false, COOKIE_PRIORITY_DEFAULT)); | 2431 "/", creation_time, base::Time(), false, false, |
2428 scoped_ptr<CanonicalCookie> cookie5(CanonicalCookie::Create( | 2432 CookieSameSite::DEFAULT_MODE, false, COOKIE_PRIORITY_DEFAULT)); |
| 2433 std::unique_ptr<CanonicalCookie> cookie5(CanonicalCookie::Create( |
2429 http_www_google_.url(), "I", "J", http_www_google_.url().host(), "/", | 2434 http_www_google_.url(), "I", "J", http_www_google_.url().host(), "/", |
2430 creation_time, base::Time(), false, false, CookieSameSite::DEFAULT_MODE, | 2435 creation_time, base::Time(), false, false, CookieSameSite::DEFAULT_MODE, |
2431 false, COOKIE_PRIORITY_DEFAULT)); | 2436 false, COOKIE_PRIORITY_DEFAULT)); |
2432 scoped_ptr<CanonicalCookie> cookie5_with_new_creation_time( | 2437 std::unique_ptr<CanonicalCookie> cookie5_with_new_creation_time( |
2433 CanonicalCookie::Create( | 2438 CanonicalCookie::Create( |
2434 http_www_google_.url(), "I", "J", http_www_google_.url().host(), "/", | 2439 http_www_google_.url(), "I", "J", http_www_google_.url().host(), "/", |
2435 now, base::Time(), false, false, CookieSameSite::DEFAULT_MODE, false, | 2440 now, base::Time(), false, false, CookieSameSite::DEFAULT_MODE, false, |
2436 COOKIE_PRIORITY_DEFAULT)); | 2441 COOKIE_PRIORITY_DEFAULT)); |
2437 scoped_ptr<CanonicalCookie> cookie6(CanonicalCookie::Create( | 2442 std::unique_ptr<CanonicalCookie> cookie6(CanonicalCookie::Create( |
2438 http_www_google_.url(), "K", "L", http_www_google_.url().host(), "/foo", | 2443 http_www_google_.url(), "K", "L", http_www_google_.url().host(), "/foo", |
2439 creation_time, base::Time(), false, false, CookieSameSite::DEFAULT_MODE, | 2444 creation_time, base::Time(), false, false, CookieSameSite::DEFAULT_MODE, |
2440 false, COOKIE_PRIORITY_DEFAULT)); | 2445 false, COOKIE_PRIORITY_DEFAULT)); |
2441 scoped_ptr<CanonicalCookie> cookie6_with_new_path(CanonicalCookie::Create( | 2446 std::unique_ptr<CanonicalCookie> cookie6_with_new_path( |
2442 http_www_google_.url(), "K", "L", http_www_google_.url().host(), "/bar", | 2447 CanonicalCookie::Create( |
2443 creation_time, base::Time(), false, false, CookieSameSite::DEFAULT_MODE, | 2448 http_www_google_.url(), "K", "L", http_www_google_.url().host(), |
2444 false, COOKIE_PRIORITY_DEFAULT)); | 2449 "/bar", creation_time, base::Time(), false, false, |
2445 scoped_ptr<CanonicalCookie> cookie7(CanonicalCookie::Create( | 2450 CookieSameSite::DEFAULT_MODE, false, COOKIE_PRIORITY_DEFAULT)); |
| 2451 std::unique_ptr<CanonicalCookie> cookie7(CanonicalCookie::Create( |
2446 http_www_google_.url(), "M", "N", http_www_google_.url().host(), "/foo", | 2452 http_www_google_.url(), "M", "N", http_www_google_.url().host(), "/foo", |
2447 creation_time, base::Time(), false, false, CookieSameSite::DEFAULT_MODE, | 2453 creation_time, base::Time(), false, false, CookieSameSite::DEFAULT_MODE, |
2448 false, COOKIE_PRIORITY_DEFAULT)); | 2454 false, COOKIE_PRIORITY_DEFAULT)); |
2449 scoped_ptr<CanonicalCookie> cookie7_with_new_path(CanonicalCookie::Create( | 2455 std::unique_ptr<CanonicalCookie> cookie7_with_new_path( |
2450 http_www_google_.url(), "M", "N", http_www_google_.url().host(), "/bar", | 2456 CanonicalCookie::Create( |
2451 creation_time, base::Time(), false, false, CookieSameSite::DEFAULT_MODE, | 2457 http_www_google_.url(), "M", "N", http_www_google_.url().host(), |
2452 false, COOKIE_PRIORITY_DEFAULT)); | 2458 "/bar", creation_time, base::Time(), false, false, |
| 2459 CookieSameSite::DEFAULT_MODE, false, COOKIE_PRIORITY_DEFAULT)); |
2453 | 2460 |
2454 CookieList old_cookies; | 2461 CookieList old_cookies; |
2455 old_cookies.push_back(*cookie1); | 2462 old_cookies.push_back(*cookie1); |
2456 old_cookies.push_back(*cookie2); | 2463 old_cookies.push_back(*cookie2); |
2457 old_cookies.push_back(*cookie4); | 2464 old_cookies.push_back(*cookie4); |
2458 old_cookies.push_back(*cookie5); | 2465 old_cookies.push_back(*cookie5); |
2459 old_cookies.push_back(*cookie6); | 2466 old_cookies.push_back(*cookie6); |
2460 old_cookies.push_back(*cookie7); | 2467 old_cookies.push_back(*cookie7); |
2461 | 2468 |
2462 CookieList new_cookies; | 2469 CookieList new_cookies; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2512 EXPECT_FALSE(IsCookieInList(*cookie7, cookies_to_add)); | 2519 EXPECT_FALSE(IsCookieInList(*cookie7, cookies_to_add)); |
2513 EXPECT_FALSE(IsCookieInList(*cookie7, cookies_to_delete)); | 2520 EXPECT_FALSE(IsCookieInList(*cookie7, cookies_to_delete)); |
2514 EXPECT_TRUE(IsCookieInList(*cookie7_with_new_path, cookies_to_add)); | 2521 EXPECT_TRUE(IsCookieInList(*cookie7_with_new_path, cookies_to_add)); |
2515 EXPECT_FALSE(IsCookieInList(*cookie7_with_new_path, cookies_to_delete)); | 2522 EXPECT_FALSE(IsCookieInList(*cookie7_with_new_path, cookies_to_delete)); |
2516 } | 2523 } |
2517 | 2524 |
2518 // Check that DeleteAll does flush (as a sanity check that flush_count() | 2525 // Check that DeleteAll does flush (as a sanity check that flush_count() |
2519 // works). | 2526 // works). |
2520 TEST_F(CookieMonsterTest, DeleteAll) { | 2527 TEST_F(CookieMonsterTest, DeleteAll) { |
2521 scoped_refptr<FlushablePersistentStore> store(new FlushablePersistentStore()); | 2528 scoped_refptr<FlushablePersistentStore> store(new FlushablePersistentStore()); |
2522 scoped_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); | 2529 std::unique_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); |
2523 cm->SetPersistSessionCookies(true); | 2530 cm->SetPersistSessionCookies(true); |
2524 | 2531 |
2525 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "X=Y; path=/")); | 2532 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "X=Y; path=/")); |
2526 | 2533 |
2527 ASSERT_EQ(0, store->flush_count()); | 2534 ASSERT_EQ(0, store->flush_count()); |
2528 EXPECT_EQ(1, DeleteAll(cm.get())); | 2535 EXPECT_EQ(1, DeleteAll(cm.get())); |
2529 EXPECT_EQ(1, store->flush_count()); | 2536 EXPECT_EQ(1, store->flush_count()); |
2530 } | 2537 } |
2531 | 2538 |
2532 TEST_F(CookieMonsterTest, HistogramCheck) { | 2539 TEST_F(CookieMonsterTest, HistogramCheck) { |
2533 scoped_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); | 2540 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
2534 // Should match call in InitializeHistograms, but doesn't really matter | 2541 // Should match call in InitializeHistograms, but doesn't really matter |
2535 // since the histogram should have been initialized by the CM construction | 2542 // since the histogram should have been initialized by the CM construction |
2536 // above. | 2543 // above. |
2537 base::HistogramBase* expired_histogram = base::Histogram::FactoryGet( | 2544 base::HistogramBase* expired_histogram = base::Histogram::FactoryGet( |
2538 "Cookie.ExpirationDurationMinutes", 1, 10 * 365 * 24 * 60, 50, | 2545 "Cookie.ExpirationDurationMinutes", 1, 10 * 365 * 24 * 60, 50, |
2539 base::Histogram::kUmaTargetedHistogramFlag); | 2546 base::Histogram::kUmaTargetedHistogramFlag); |
2540 | 2547 |
2541 scoped_ptr<base::HistogramSamples> samples1( | 2548 std::unique_ptr<base::HistogramSamples> samples1( |
2542 expired_histogram->SnapshotSamples()); | 2549 expired_histogram->SnapshotSamples()); |
2543 ASSERT_TRUE(SetCookieWithDetails( | 2550 ASSERT_TRUE(SetCookieWithDetails( |
2544 cm.get(), GURL("http://fake.a.url"), "a", "b", "a.url", "/", base::Time(), | 2551 cm.get(), GURL("http://fake.a.url"), "a", "b", "a.url", "/", base::Time(), |
2545 base::Time::Now() + base::TimeDelta::FromMinutes(59), base::Time(), false, | 2552 base::Time::Now() + base::TimeDelta::FromMinutes(59), base::Time(), false, |
2546 false, CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT)); | 2553 false, CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT)); |
2547 | 2554 |
2548 scoped_ptr<base::HistogramSamples> samples2( | 2555 std::unique_ptr<base::HistogramSamples> samples2( |
2549 expired_histogram->SnapshotSamples()); | 2556 expired_histogram->SnapshotSamples()); |
2550 EXPECT_EQ(samples1->TotalCount() + 1, samples2->TotalCount()); | 2557 EXPECT_EQ(samples1->TotalCount() + 1, samples2->TotalCount()); |
2551 | 2558 |
2552 // kValidCookieLine creates a session cookie. | 2559 // kValidCookieLine creates a session cookie. |
2553 ASSERT_TRUE(SetCookie(cm.get(), http_www_google_.url(), kValidCookieLine)); | 2560 ASSERT_TRUE(SetCookie(cm.get(), http_www_google_.url(), kValidCookieLine)); |
2554 | 2561 |
2555 scoped_ptr<base::HistogramSamples> samples3( | 2562 std::unique_ptr<base::HistogramSamples> samples3( |
2556 expired_histogram->SnapshotSamples()); | 2563 expired_histogram->SnapshotSamples()); |
2557 EXPECT_EQ(samples2->TotalCount(), samples3->TotalCount()); | 2564 EXPECT_EQ(samples2->TotalCount(), samples3->TotalCount()); |
2558 } | 2565 } |
2559 | 2566 |
2560 TEST_F(CookieMonsterTest, InvalidExpiryTime) { | 2567 TEST_F(CookieMonsterTest, InvalidExpiryTime) { |
2561 std::string cookie_line = | 2568 std::string cookie_line = |
2562 std::string(kValidCookieLine) + "; expires=Blarg arg arg"; | 2569 std::string(kValidCookieLine) + "; expires=Blarg arg arg"; |
2563 scoped_ptr<CanonicalCookie> cookie(CanonicalCookie::Create( | 2570 std::unique_ptr<CanonicalCookie> cookie(CanonicalCookie::Create( |
2564 http_www_google_.url(), cookie_line, Time::Now(), CookieOptions())); | 2571 http_www_google_.url(), cookie_line, Time::Now(), CookieOptions())); |
2565 ASSERT_FALSE(cookie->IsPersistent()); | 2572 ASSERT_FALSE(cookie->IsPersistent()); |
2566 } | 2573 } |
2567 | 2574 |
2568 // Test that CookieMonster writes session cookies into the underlying | 2575 // Test that CookieMonster writes session cookies into the underlying |
2569 // CookieStore if the "persist session cookies" option is on. | 2576 // CookieStore if the "persist session cookies" option is on. |
2570 TEST_F(CookieMonsterTest, PersistSessionCookies) { | 2577 TEST_F(CookieMonsterTest, PersistSessionCookies) { |
2571 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); | 2578 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); |
2572 scoped_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); | 2579 std::unique_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); |
2573 cm->SetPersistSessionCookies(true); | 2580 cm->SetPersistSessionCookies(true); |
2574 | 2581 |
2575 // All cookies set with SetCookie are session cookies. | 2582 // All cookies set with SetCookie are session cookies. |
2576 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=B")); | 2583 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=B")); |
2577 EXPECT_EQ("A=B", GetCookies(cm.get(), http_www_google_.url())); | 2584 EXPECT_EQ("A=B", GetCookies(cm.get(), http_www_google_.url())); |
2578 | 2585 |
2579 // The cookie was written to the backing store. | 2586 // The cookie was written to the backing store. |
2580 EXPECT_EQ(1u, store->commands().size()); | 2587 EXPECT_EQ(1u, store->commands().size()); |
2581 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[0].type); | 2588 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[0].type); |
2582 EXPECT_EQ("A", store->commands()[0].cookie.Name()); | 2589 EXPECT_EQ("A", store->commands()[0].cookie.Name()); |
(...skipping 15 matching lines...) Expand all Loading... |
2598 EXPECT_EQ("", GetCookies(cm.get(), http_www_google_.url())); | 2605 EXPECT_EQ("", GetCookies(cm.get(), http_www_google_.url())); |
2599 EXPECT_EQ(4u, store->commands().size()); | 2606 EXPECT_EQ(4u, store->commands().size()); |
2600 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[3].type); | 2607 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[3].type); |
2601 EXPECT_EQ("A", store->commands()[3].cookie.Name()); | 2608 EXPECT_EQ("A", store->commands()[3].cookie.Name()); |
2602 EXPECT_EQ("C", store->commands()[3].cookie.Value()); | 2609 EXPECT_EQ("C", store->commands()[3].cookie.Value()); |
2603 } | 2610 } |
2604 | 2611 |
2605 // Test the commands sent to the persistent cookie store. | 2612 // Test the commands sent to the persistent cookie store. |
2606 TEST_F(CookieMonsterTest, PersisentCookieStorageTest) { | 2613 TEST_F(CookieMonsterTest, PersisentCookieStorageTest) { |
2607 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); | 2614 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); |
2608 scoped_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); | 2615 std::unique_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); |
2609 | 2616 |
2610 // Add a cookie. | 2617 // Add a cookie. |
2611 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), | 2618 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), |
2612 "A=B; expires=Mon, 18-Apr-22 22:50:13 GMT")); | 2619 "A=B; expires=Mon, 18-Apr-22 22:50:13 GMT")); |
2613 this->MatchCookieLines("A=B", GetCookies(cm.get(), http_www_google_.url())); | 2620 this->MatchCookieLines("A=B", GetCookies(cm.get(), http_www_google_.url())); |
2614 ASSERT_EQ(1u, store->commands().size()); | 2621 ASSERT_EQ(1u, store->commands().size()); |
2615 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[0].type); | 2622 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[0].type); |
2616 // Remove it. | 2623 // Remove it. |
2617 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=B; max-age=0")); | 2624 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=B; max-age=0")); |
2618 this->MatchCookieLines(std::string(), | 2625 this->MatchCookieLines(std::string(), |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2654 const std::string path("/path"); | 2661 const std::string path("/path"); |
2655 | 2662 |
2656 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); | 2663 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); |
2657 | 2664 |
2658 std::vector<CanonicalCookie*> initial_cookies; | 2665 std::vector<CanonicalCookie*> initial_cookies; |
2659 | 2666 |
2660 AddCookieToList(url, "foo=bar; path=" + path, now1, &initial_cookies); | 2667 AddCookieToList(url, "foo=bar; path=" + path, now1, &initial_cookies); |
2661 | 2668 |
2662 // We have to manually build this cookie because it contains a control | 2669 // We have to manually build this cookie because it contains a control |
2663 // character, and our cookie line parser rejects control characters. | 2670 // character, and our cookie line parser rejects control characters. |
2664 scoped_ptr<CanonicalCookie> cc = CanonicalCookie::Create( | 2671 std::unique_ptr<CanonicalCookie> cc = CanonicalCookie::Create( |
2665 url, "baz", | 2672 url, "baz", |
2666 "\x05" | 2673 "\x05" |
2667 "boo", | 2674 "boo", |
2668 domain, path, now2, later, false, false, CookieSameSite::DEFAULT_MODE, | 2675 domain, path, now2, later, false, false, CookieSameSite::DEFAULT_MODE, |
2669 false, COOKIE_PRIORITY_DEFAULT); | 2676 false, COOKIE_PRIORITY_DEFAULT); |
2670 initial_cookies.push_back(cc.release()); | 2677 initial_cookies.push_back(cc.release()); |
2671 | 2678 |
2672 AddCookieToList(url, "hello=world; path=" + path, now3, &initial_cookies); | 2679 AddCookieToList(url, "hello=world; path=" + path, now3, &initial_cookies); |
2673 | 2680 |
2674 // Inject our initial cookies into the mock PersistentCookieStore. | 2681 // Inject our initial cookies into the mock PersistentCookieStore. |
2675 store->SetLoadExpectation(true, initial_cookies); | 2682 store->SetLoadExpectation(true, initial_cookies); |
2676 | 2683 |
2677 scoped_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); | 2684 std::unique_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); |
2678 | 2685 |
2679 EXPECT_EQ("foo=bar; hello=world", GetCookies(cm.get(), url)); | 2686 EXPECT_EQ("foo=bar; hello=world", GetCookies(cm.get(), url)); |
2680 } | 2687 } |
2681 | 2688 |
2682 // Test that cookie source schemes are histogrammed correctly. | 2689 // Test that cookie source schemes are histogrammed correctly. |
2683 TEST_F(CookieMonsterTest, CookieSourceHistogram) { | 2690 TEST_F(CookieMonsterTest, CookieSourceHistogram) { |
2684 base::HistogramTester histograms; | 2691 base::HistogramTester histograms; |
2685 const std::string cookie_source_histogram = "Cookie.CookieSourceScheme"; | 2692 const std::string cookie_source_histogram = "Cookie.CookieSourceScheme"; |
2686 | 2693 |
2687 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); | 2694 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); |
2688 scoped_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); | 2695 std::unique_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); |
2689 | 2696 |
2690 histograms.ExpectTotalCount(cookie_source_histogram, 0); | 2697 histograms.ExpectTotalCount(cookie_source_histogram, 0); |
2691 | 2698 |
2692 // Set a secure cookie on a cryptographic scheme. | 2699 // Set a secure cookie on a cryptographic scheme. |
2693 EXPECT_TRUE( | 2700 EXPECT_TRUE( |
2694 SetCookie(cm.get(), https_www_google_.url(), "A=B; path=/; Secure")); | 2701 SetCookie(cm.get(), https_www_google_.url(), "A=B; path=/; Secure")); |
2695 histograms.ExpectTotalCount(cookie_source_histogram, 1); | 2702 histograms.ExpectTotalCount(cookie_source_histogram, 1); |
2696 histograms.ExpectBucketCount( | 2703 histograms.ExpectBucketCount( |
2697 cookie_source_histogram, | 2704 cookie_source_histogram, |
2698 CookieMonster::COOKIE_SOURCE_SECURE_COOKIE_CRYPTOGRAPHIC_SCHEME, 1); | 2705 CookieMonster::COOKIE_SOURCE_SECURE_COOKIE_CRYPTOGRAPHIC_SCHEME, 1); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2745 CookieMonster::COOKIE_SOURCE_NONSECURE_COOKIE_NONCRYPTOGRAPHIC_SCHEME, 1); | 2752 CookieMonster::COOKIE_SOURCE_NONSECURE_COOKIE_NONCRYPTOGRAPHIC_SCHEME, 1); |
2746 } | 2753 } |
2747 | 2754 |
2748 // Test that cookie delete equivalent histograms are recorded correctly when | 2755 // Test that cookie delete equivalent histograms are recorded correctly when |
2749 // strict secure cookies are not enabled. | 2756 // strict secure cookies are not enabled. |
2750 TEST_F(CookieMonsterTest, CookieDeleteEquivalentHistogramTest) { | 2757 TEST_F(CookieMonsterTest, CookieDeleteEquivalentHistogramTest) { |
2751 base::HistogramTester histograms; | 2758 base::HistogramTester histograms; |
2752 const std::string cookie_source_histogram = "Cookie.CookieDeleteEquivalent"; | 2759 const std::string cookie_source_histogram = "Cookie.CookieDeleteEquivalent"; |
2753 | 2760 |
2754 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); | 2761 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); |
2755 scoped_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); | 2762 std::unique_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); |
2756 | 2763 |
2757 // Set a secure cookie from a secure origin | 2764 // Set a secure cookie from a secure origin |
2758 EXPECT_TRUE(SetCookie(cm.get(), https_www_google_.url(), "A=B; Secure")); | 2765 EXPECT_TRUE(SetCookie(cm.get(), https_www_google_.url(), "A=B; Secure")); |
2759 histograms.ExpectTotalCount(cookie_source_histogram, 1); | 2766 histograms.ExpectTotalCount(cookie_source_histogram, 1); |
2760 histograms.ExpectBucketCount(cookie_source_histogram, | 2767 histograms.ExpectBucketCount(cookie_source_histogram, |
2761 CookieMonster::COOKIE_DELETE_EQUIVALENT_ATTEMPT, | 2768 CookieMonster::COOKIE_DELETE_EQUIVALENT_ATTEMPT, |
2762 1); | 2769 1); |
2763 | 2770 |
2764 // Set a new cookie with a different name from a variety of origins (including | 2771 // Set a new cookie with a different name from a variety of origins (including |
2765 // the same one). | 2772 // the same one). |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2810 // already existing cookie and is not equivalent. | 2817 // already existing cookie and is not equivalent. |
2811 EXPECT_TRUE(SetCookie(cm.get(), https_www_google_.url(), | 2818 EXPECT_TRUE(SetCookie(cm.get(), https_www_google_.url(), |
2812 "A=E; secure; path=/some/other/path")); | 2819 "A=E; secure; path=/some/other/path")); |
2813 histograms.ExpectTotalCount(cookie_source_histogram, 9); | 2820 histograms.ExpectTotalCount(cookie_source_histogram, 9); |
2814 histograms.ExpectBucketCount(cookie_source_histogram, | 2821 histograms.ExpectBucketCount(cookie_source_histogram, |
2815 CookieMonster::COOKIE_DELETE_EQUIVALENT_ATTEMPT, | 2822 CookieMonster::COOKIE_DELETE_EQUIVALENT_ATTEMPT, |
2816 7); | 2823 7); |
2817 } | 2824 } |
2818 | 2825 |
2819 TEST_F(CookieMonsterStrictSecureTest, SetSecureCookies) { | 2826 TEST_F(CookieMonsterStrictSecureTest, SetSecureCookies) { |
2820 scoped_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); | 2827 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
2821 GURL http_url("http://www.google.com"); | 2828 GURL http_url("http://www.google.com"); |
2822 GURL http_superdomain_url("http://google.com"); | 2829 GURL http_superdomain_url("http://google.com"); |
2823 GURL https_url("https://www.google.com"); | 2830 GURL https_url("https://www.google.com"); |
2824 | 2831 |
2825 // A non-secure cookie can be created from either a URL with a secure or | 2832 // A non-secure cookie can be created from either a URL with a secure or |
2826 // insecure scheme. | 2833 // insecure scheme. |
2827 EXPECT_TRUE(SetCookie(cm.get(), http_url, "A=C;")); | 2834 EXPECT_TRUE(SetCookie(cm.get(), http_url, "A=C;")); |
2828 EXPECT_TRUE(SetCookie(cm.get(), https_url, "A=B;")); | 2835 EXPECT_TRUE(SetCookie(cm.get(), https_url, "A=B;")); |
2829 | 2836 |
2830 // A secure cookie cannot be created from a URL with an insecure scheme. | 2837 // A secure cookie cannot be created from a URL with an insecure scheme. |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3003 // global purge goal (3000), but the secure cookies are not evicted. | 3010 // global purge goal (3000), but the secure cookies are not evicted. |
3004 const CookiesEntry test14[] = {{1U, true}}; | 3011 const CookiesEntry test14[] = {{1U, true}}; |
3005 const AltHosts test14_alt_hosts(1500, 1800); | 3012 const AltHosts test14_alt_hosts(1500, 1800); |
3006 TestSecureCookieEviction(test14, arraysize(test14), 1501U, 1499, | 3013 TestSecureCookieEviction(test14, arraysize(test14), 1501U, 1499, |
3007 &test14_alt_hosts); | 3014 &test14_alt_hosts); |
3008 } | 3015 } |
3009 | 3016 |
3010 // Tests that strict secure cookies doesn't trip equivalent cookie checks | 3017 // Tests that strict secure cookies doesn't trip equivalent cookie checks |
3011 // accidentally. Regression test for https://crbug.com/569943. | 3018 // accidentally. Regression test for https://crbug.com/569943. |
3012 TEST_F(CookieMonsterStrictSecureTest, EquivalentCookies) { | 3019 TEST_F(CookieMonsterStrictSecureTest, EquivalentCookies) { |
3013 scoped_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); | 3020 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
3014 GURL http_url("http://www.google.com"); | 3021 GURL http_url("http://www.google.com"); |
3015 GURL http_superdomain_url("http://google.com"); | 3022 GURL http_superdomain_url("http://google.com"); |
3016 GURL https_url("https://www.google.com"); | 3023 GURL https_url("https://www.google.com"); |
3017 | 3024 |
3018 // Tests that non-equivalent cookies because of the path attribute can be set | 3025 // Tests that non-equivalent cookies because of the path attribute can be set |
3019 // successfully. | 3026 // successfully. |
3020 EXPECT_TRUE(SetCookie(cm.get(), https_url, "A=B; Secure")); | 3027 EXPECT_TRUE(SetCookie(cm.get(), https_url, "A=B; Secure")); |
3021 EXPECT_TRUE(SetCookie(cm.get(), https_url, "A=C; path=/some/other/path")); | 3028 EXPECT_TRUE(SetCookie(cm.get(), https_url, "A=C; path=/some/other/path")); |
3022 EXPECT_FALSE(SetCookie(cm.get(), http_url, "A=D; path=/some/other/path")); | 3029 EXPECT_FALSE(SetCookie(cm.get(), http_url, "A=D; path=/some/other/path")); |
3023 | 3030 |
3024 // Tests that non-equivalent cookies because of the domain attribute can be | 3031 // Tests that non-equivalent cookies because of the domain attribute can be |
3025 // set successfully. | 3032 // set successfully. |
3026 EXPECT_TRUE(SetCookie(cm.get(), https_url, "A=B; Secure")); | 3033 EXPECT_TRUE(SetCookie(cm.get(), https_url, "A=B; Secure")); |
3027 EXPECT_TRUE(SetCookie(cm.get(), https_url, "A=C; domain=google.com")); | 3034 EXPECT_TRUE(SetCookie(cm.get(), https_url, "A=C; domain=google.com")); |
3028 EXPECT_FALSE(SetCookie(cm.get(), http_url, "A=D; domain=google.com")); | 3035 EXPECT_FALSE(SetCookie(cm.get(), http_url, "A=D; domain=google.com")); |
3029 } | 3036 } |
3030 | 3037 |
3031 // Test that cookie delete equivalent histograms are recorded correctly for | 3038 // Test that cookie delete equivalent histograms are recorded correctly for |
3032 // strict secure cookies. | 3039 // strict secure cookies. |
3033 TEST_F(CookieMonsterStrictSecureTest, CookieDeleteEquivalentHistogramTest) { | 3040 TEST_F(CookieMonsterStrictSecureTest, CookieDeleteEquivalentHistogramTest) { |
3034 base::HistogramTester histograms; | 3041 base::HistogramTester histograms; |
3035 const std::string cookie_source_histogram = "Cookie.CookieDeleteEquivalent"; | 3042 const std::string cookie_source_histogram = "Cookie.CookieDeleteEquivalent"; |
3036 | 3043 |
3037 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); | 3044 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); |
3038 scoped_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); | 3045 std::unique_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); |
3039 | 3046 |
3040 // Set a secure cookie from a secure origin | 3047 // Set a secure cookie from a secure origin |
3041 EXPECT_TRUE(SetCookie(cm.get(), https_www_google_.url(), "A=B; Secure")); | 3048 EXPECT_TRUE(SetCookie(cm.get(), https_www_google_.url(), "A=B; Secure")); |
3042 histograms.ExpectTotalCount(cookie_source_histogram, 1); | 3049 histograms.ExpectTotalCount(cookie_source_histogram, 1); |
3043 histograms.ExpectBucketCount(cookie_source_histogram, | 3050 histograms.ExpectBucketCount(cookie_source_histogram, |
3044 CookieMonster::COOKIE_DELETE_EQUIVALENT_ATTEMPT, | 3051 CookieMonster::COOKIE_DELETE_EQUIVALENT_ATTEMPT, |
3045 1); | 3052 1); |
3046 | 3053 |
3047 // Set a new cookie with a different name from a variety of origins (including | 3054 // Set a new cookie with a different name from a variety of origins (including |
3048 // the same one). | 3055 // the same one). |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3114 | 3121 |
3115 ~CookieMonsterNotificationTest() override {} | 3122 ~CookieMonsterNotificationTest() override {} |
3116 | 3123 |
3117 CookieMonster* monster() { return monster_.get(); } | 3124 CookieMonster* monster() { return monster_.get(); } |
3118 | 3125 |
3119 protected: | 3126 protected: |
3120 const GURL test_url_; | 3127 const GURL test_url_; |
3121 | 3128 |
3122 private: | 3129 private: |
3123 scoped_refptr<MockPersistentCookieStore> store_; | 3130 scoped_refptr<MockPersistentCookieStore> store_; |
3124 scoped_ptr<CookieMonster> monster_; | 3131 std::unique_ptr<CookieMonster> monster_; |
3125 }; | 3132 }; |
3126 | 3133 |
3127 void RecordCookieChanges(std::vector<CanonicalCookie>* out_cookies, | 3134 void RecordCookieChanges(std::vector<CanonicalCookie>* out_cookies, |
3128 std::vector<bool>* out_removes, | 3135 std::vector<bool>* out_removes, |
3129 const CanonicalCookie& cookie, | 3136 const CanonicalCookie& cookie, |
3130 bool removed) { | 3137 bool removed) { |
3131 DCHECK(out_cookies); | 3138 DCHECK(out_cookies); |
3132 out_cookies->push_back(cookie); | 3139 out_cookies->push_back(cookie); |
3133 if (out_removes) | 3140 if (out_removes) |
3134 out_removes->push_back(removed); | 3141 out_removes->push_back(removed); |
3135 } | 3142 } |
3136 | 3143 |
3137 TEST_F(CookieMonsterNotificationTest, NoNotifyWithNoCookie) { | 3144 TEST_F(CookieMonsterNotificationTest, NoNotifyWithNoCookie) { |
3138 std::vector<CanonicalCookie> cookies; | 3145 std::vector<CanonicalCookie> cookies; |
3139 scoped_ptr<CookieStore::CookieChangedSubscription> sub( | 3146 std::unique_ptr<CookieStore::CookieChangedSubscription> sub( |
3140 monster()->AddCallbackForCookie( | 3147 monster()->AddCallbackForCookie( |
3141 test_url_, "abc", | 3148 test_url_, "abc", |
3142 base::Bind(&RecordCookieChanges, &cookies, nullptr))); | 3149 base::Bind(&RecordCookieChanges, &cookies, nullptr))); |
3143 base::MessageLoop::current()->RunUntilIdle(); | 3150 base::MessageLoop::current()->RunUntilIdle(); |
3144 EXPECT_EQ(0U, cookies.size()); | 3151 EXPECT_EQ(0U, cookies.size()); |
3145 } | 3152 } |
3146 | 3153 |
3147 TEST_F(CookieMonsterNotificationTest, NoNotifyWithInitialCookie) { | 3154 TEST_F(CookieMonsterNotificationTest, NoNotifyWithInitialCookie) { |
3148 std::vector<CanonicalCookie> cookies; | 3155 std::vector<CanonicalCookie> cookies; |
3149 SetCookie(monster(), test_url_, "abc=def"); | 3156 SetCookie(monster(), test_url_, "abc=def"); |
3150 base::MessageLoop::current()->RunUntilIdle(); | 3157 base::MessageLoop::current()->RunUntilIdle(); |
3151 scoped_ptr<CookieStore::CookieChangedSubscription> sub( | 3158 std::unique_ptr<CookieStore::CookieChangedSubscription> sub( |
3152 monster()->AddCallbackForCookie( | 3159 monster()->AddCallbackForCookie( |
3153 test_url_, "abc", | 3160 test_url_, "abc", |
3154 base::Bind(&RecordCookieChanges, &cookies, nullptr))); | 3161 base::Bind(&RecordCookieChanges, &cookies, nullptr))); |
3155 base::MessageLoop::current()->RunUntilIdle(); | 3162 base::MessageLoop::current()->RunUntilIdle(); |
3156 EXPECT_EQ(0U, cookies.size()); | 3163 EXPECT_EQ(0U, cookies.size()); |
3157 } | 3164 } |
3158 | 3165 |
3159 TEST_F(CookieMonsterNotificationTest, NotifyOnSet) { | 3166 TEST_F(CookieMonsterNotificationTest, NotifyOnSet) { |
3160 std::vector<CanonicalCookie> cookies; | 3167 std::vector<CanonicalCookie> cookies; |
3161 std::vector<bool> removes; | 3168 std::vector<bool> removes; |
3162 scoped_ptr<CookieStore::CookieChangedSubscription> sub( | 3169 std::unique_ptr<CookieStore::CookieChangedSubscription> sub( |
3163 monster()->AddCallbackForCookie( | 3170 monster()->AddCallbackForCookie( |
3164 test_url_, "abc", | 3171 test_url_, "abc", |
3165 base::Bind(&RecordCookieChanges, &cookies, &removes))); | 3172 base::Bind(&RecordCookieChanges, &cookies, &removes))); |
3166 SetCookie(monster(), test_url_, "abc=def"); | 3173 SetCookie(monster(), test_url_, "abc=def"); |
3167 base::MessageLoop::current()->RunUntilIdle(); | 3174 base::MessageLoop::current()->RunUntilIdle(); |
3168 EXPECT_EQ(1U, cookies.size()); | 3175 EXPECT_EQ(1U, cookies.size()); |
3169 EXPECT_EQ(1U, removes.size()); | 3176 EXPECT_EQ(1U, removes.size()); |
3170 | 3177 |
3171 EXPECT_EQ("abc", cookies[0].Name()); | 3178 EXPECT_EQ("abc", cookies[0].Name()); |
3172 EXPECT_EQ("def", cookies[0].Value()); | 3179 EXPECT_EQ("def", cookies[0].Value()); |
3173 EXPECT_FALSE(removes[0]); | 3180 EXPECT_FALSE(removes[0]); |
3174 } | 3181 } |
3175 | 3182 |
3176 TEST_F(CookieMonsterNotificationTest, NotifyOnDelete) { | 3183 TEST_F(CookieMonsterNotificationTest, NotifyOnDelete) { |
3177 std::vector<CanonicalCookie> cookies; | 3184 std::vector<CanonicalCookie> cookies; |
3178 std::vector<bool> removes; | 3185 std::vector<bool> removes; |
3179 scoped_ptr<CookieStore::CookieChangedSubscription> sub( | 3186 std::unique_ptr<CookieStore::CookieChangedSubscription> sub( |
3180 monster()->AddCallbackForCookie( | 3187 monster()->AddCallbackForCookie( |
3181 test_url_, "abc", | 3188 test_url_, "abc", |
3182 base::Bind(&RecordCookieChanges, &cookies, &removes))); | 3189 base::Bind(&RecordCookieChanges, &cookies, &removes))); |
3183 SetCookie(monster(), test_url_, "abc=def"); | 3190 SetCookie(monster(), test_url_, "abc=def"); |
3184 base::MessageLoop::current()->RunUntilIdle(); | 3191 base::MessageLoop::current()->RunUntilIdle(); |
3185 EXPECT_EQ(1U, cookies.size()); | 3192 EXPECT_EQ(1U, cookies.size()); |
3186 EXPECT_EQ(1U, removes.size()); | 3193 EXPECT_EQ(1U, removes.size()); |
3187 | 3194 |
3188 DeleteCookie(monster(), test_url_, "abc"); | 3195 DeleteCookie(monster(), test_url_, "abc"); |
3189 base::MessageLoop::current()->RunUntilIdle(); | 3196 base::MessageLoop::current()->RunUntilIdle(); |
3190 EXPECT_EQ(2U, cookies.size()); | 3197 EXPECT_EQ(2U, cookies.size()); |
3191 EXPECT_EQ(2U, removes.size()); | 3198 EXPECT_EQ(2U, removes.size()); |
3192 | 3199 |
3193 EXPECT_EQ("abc", cookies[1].Name()); | 3200 EXPECT_EQ("abc", cookies[1].Name()); |
3194 EXPECT_EQ("def", cookies[1].Value()); | 3201 EXPECT_EQ("def", cookies[1].Value()); |
3195 EXPECT_TRUE(removes[1]); | 3202 EXPECT_TRUE(removes[1]); |
3196 } | 3203 } |
3197 | 3204 |
3198 TEST_F(CookieMonsterNotificationTest, NotifyOnUpdate) { | 3205 TEST_F(CookieMonsterNotificationTest, NotifyOnUpdate) { |
3199 std::vector<CanonicalCookie> cookies; | 3206 std::vector<CanonicalCookie> cookies; |
3200 std::vector<bool> removes; | 3207 std::vector<bool> removes; |
3201 scoped_ptr<CookieStore::CookieChangedSubscription> sub( | 3208 std::unique_ptr<CookieStore::CookieChangedSubscription> sub( |
3202 monster()->AddCallbackForCookie( | 3209 monster()->AddCallbackForCookie( |
3203 test_url_, "abc", | 3210 test_url_, "abc", |
3204 base::Bind(&RecordCookieChanges, &cookies, &removes))); | 3211 base::Bind(&RecordCookieChanges, &cookies, &removes))); |
3205 SetCookie(monster(), test_url_, "abc=def"); | 3212 SetCookie(monster(), test_url_, "abc=def"); |
3206 base::MessageLoop::current()->RunUntilIdle(); | 3213 base::MessageLoop::current()->RunUntilIdle(); |
3207 EXPECT_EQ(1U, cookies.size()); | 3214 EXPECT_EQ(1U, cookies.size()); |
3208 | 3215 |
3209 // Replacing an existing cookie is actually a two-phase delete + set | 3216 // Replacing an existing cookie is actually a two-phase delete + set |
3210 // operation, so we get an extra notification. | 3217 // operation, so we get an extra notification. |
3211 SetCookie(monster(), test_url_, "abc=ghi"); | 3218 SetCookie(monster(), test_url_, "abc=ghi"); |
3212 base::MessageLoop::current()->RunUntilIdle(); | 3219 base::MessageLoop::current()->RunUntilIdle(); |
3213 | 3220 |
3214 EXPECT_EQ(3U, cookies.size()); | 3221 EXPECT_EQ(3U, cookies.size()); |
3215 EXPECT_EQ(3U, removes.size()); | 3222 EXPECT_EQ(3U, removes.size()); |
3216 | 3223 |
3217 EXPECT_EQ("abc", cookies[1].Name()); | 3224 EXPECT_EQ("abc", cookies[1].Name()); |
3218 EXPECT_EQ("def", cookies[1].Value()); | 3225 EXPECT_EQ("def", cookies[1].Value()); |
3219 EXPECT_TRUE(removes[1]); | 3226 EXPECT_TRUE(removes[1]); |
3220 | 3227 |
3221 EXPECT_EQ("abc", cookies[2].Name()); | 3228 EXPECT_EQ("abc", cookies[2].Name()); |
3222 EXPECT_EQ("ghi", cookies[2].Value()); | 3229 EXPECT_EQ("ghi", cookies[2].Value()); |
3223 EXPECT_FALSE(removes[2]); | 3230 EXPECT_FALSE(removes[2]); |
3224 } | 3231 } |
3225 | 3232 |
3226 TEST_F(CookieMonsterNotificationTest, MultipleNotifies) { | 3233 TEST_F(CookieMonsterNotificationTest, MultipleNotifies) { |
3227 std::vector<CanonicalCookie> cookies0; | 3234 std::vector<CanonicalCookie> cookies0; |
3228 std::vector<CanonicalCookie> cookies1; | 3235 std::vector<CanonicalCookie> cookies1; |
3229 scoped_ptr<CookieStore::CookieChangedSubscription> sub0( | 3236 std::unique_ptr<CookieStore::CookieChangedSubscription> sub0( |
3230 monster()->AddCallbackForCookie( | 3237 monster()->AddCallbackForCookie( |
3231 test_url_, "abc", | 3238 test_url_, "abc", |
3232 base::Bind(&RecordCookieChanges, &cookies0, nullptr))); | 3239 base::Bind(&RecordCookieChanges, &cookies0, nullptr))); |
3233 scoped_ptr<CookieStore::CookieChangedSubscription> sub1( | 3240 std::unique_ptr<CookieStore::CookieChangedSubscription> sub1( |
3234 monster()->AddCallbackForCookie( | 3241 monster()->AddCallbackForCookie( |
3235 test_url_, "def", | 3242 test_url_, "def", |
3236 base::Bind(&RecordCookieChanges, &cookies1, nullptr))); | 3243 base::Bind(&RecordCookieChanges, &cookies1, nullptr))); |
3237 SetCookie(monster(), test_url_, "abc=def"); | 3244 SetCookie(monster(), test_url_, "abc=def"); |
3238 base::MessageLoop::current()->RunUntilIdle(); | 3245 base::MessageLoop::current()->RunUntilIdle(); |
3239 EXPECT_EQ(1U, cookies0.size()); | 3246 EXPECT_EQ(1U, cookies0.size()); |
3240 EXPECT_EQ(0U, cookies1.size()); | 3247 EXPECT_EQ(0U, cookies1.size()); |
3241 SetCookie(monster(), test_url_, "def=abc"); | 3248 SetCookie(monster(), test_url_, "def=abc"); |
3242 base::MessageLoop::current()->RunUntilIdle(); | 3249 base::MessageLoop::current()->RunUntilIdle(); |
3243 EXPECT_EQ(1U, cookies0.size()); | 3250 EXPECT_EQ(1U, cookies0.size()); |
3244 EXPECT_EQ(1U, cookies1.size()); | 3251 EXPECT_EQ(1U, cookies1.size()); |
3245 } | 3252 } |
3246 | 3253 |
3247 TEST_F(CookieMonsterNotificationTest, MultipleSameNotifies) { | 3254 TEST_F(CookieMonsterNotificationTest, MultipleSameNotifies) { |
3248 std::vector<CanonicalCookie> cookies0; | 3255 std::vector<CanonicalCookie> cookies0; |
3249 std::vector<CanonicalCookie> cookies1; | 3256 std::vector<CanonicalCookie> cookies1; |
3250 scoped_ptr<CookieStore::CookieChangedSubscription> sub0( | 3257 std::unique_ptr<CookieStore::CookieChangedSubscription> sub0( |
3251 monster()->AddCallbackForCookie( | 3258 monster()->AddCallbackForCookie( |
3252 test_url_, "abc", | 3259 test_url_, "abc", |
3253 base::Bind(&RecordCookieChanges, &cookies0, nullptr))); | 3260 base::Bind(&RecordCookieChanges, &cookies0, nullptr))); |
3254 scoped_ptr<CookieStore::CookieChangedSubscription> sub1( | 3261 std::unique_ptr<CookieStore::CookieChangedSubscription> sub1( |
3255 monster()->AddCallbackForCookie( | 3262 monster()->AddCallbackForCookie( |
3256 test_url_, "abc", | 3263 test_url_, "abc", |
3257 base::Bind(&RecordCookieChanges, &cookies1, nullptr))); | 3264 base::Bind(&RecordCookieChanges, &cookies1, nullptr))); |
3258 SetCookie(monster(), test_url_, "abc=def"); | 3265 SetCookie(monster(), test_url_, "abc=def"); |
3259 base::MessageLoop::current()->RunUntilIdle(); | 3266 base::MessageLoop::current()->RunUntilIdle(); |
3260 EXPECT_EQ(1U, cookies0.size()); | 3267 EXPECT_EQ(1U, cookies0.size()); |
3261 EXPECT_EQ(1U, cookies0.size()); | 3268 EXPECT_EQ(1U, cookies0.size()); |
3262 } | 3269 } |
3263 | 3270 |
3264 } // namespace net | 3271 } // namespace net |
OLD | NEW |