OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/cookies/cookie_monster.h" | 5 #include "net/cookies/cookie_monster.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 2204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2215 GetAllCookies(cm.get()).size()) | 2215 GetAllCookies(cm.get()).size()) |
2216 << "For test case " << ci; | 2216 << "For test case " << ci; |
2217 // Will trigger GC | 2217 // Will trigger GC |
2218 SetCookie(cm.get(), GURL("http://newdomain.com"), "b=2"); | 2218 SetCookie(cm.get(), GURL("http://newdomain.com"), "b=2"); |
2219 EXPECT_EQ(test_case->expected_cookies_after_set, | 2219 EXPECT_EQ(test_case->expected_cookies_after_set, |
2220 GetAllCookies(cm.get()).size()) | 2220 GetAllCookies(cm.get()).size()) |
2221 << "For test case " << ci; | 2221 << "For test case " << ci; |
2222 } | 2222 } |
2223 } | 2223 } |
2224 | 2224 |
| 2225 // Tests garbage collection when there are only secure cookies. |
| 2226 // See https://crbug/730000 |
| 2227 TEST_F(CookieMonsterTest, GarbageCollectWithSecureCookiesOnly) { |
| 2228 // Create a CookieMonster at its cookie limit. A bit confusing, but the second |
| 2229 // number is a subset of the first number. |
| 2230 std::unique_ptr<CookieMonster> cm = CreateMonsterFromStoreForGC( |
| 2231 CookieMonster::kMaxCookies /* num_secure_cookies */, |
| 2232 CookieMonster::kMaxCookies /* num_old_secure_cookies */, |
| 2233 0 /* num_non_secure_cookies */, 0 /* num_old_non_secure_cookies */, |
| 2234 CookieMonster::kSafeFromGlobalPurgeDays * 2 /* days_old */); |
| 2235 EXPECT_EQ(CookieMonster::kMaxCookies, GetAllCookies(cm.get()).size()); |
| 2236 |
| 2237 // Trigger purge with a secure cookie (So there are still no insecure |
| 2238 // cookies). |
| 2239 SetCookie(cm.get(), GURL("https://newdomain.com"), "b=2; Secure"); |
| 2240 EXPECT_EQ(CookieMonster::kMaxCookies - CookieMonster::kPurgeCookies, |
| 2241 GetAllCookies(cm.get()).size()); |
| 2242 } |
| 2243 |
2225 // Tests that if the main load event happens before the loaded event for a | 2244 // Tests that if the main load event happens before the loaded event for a |
2226 // particular key, the tasks for that key run first. | 2245 // particular key, the tasks for that key run first. |
2227 TEST_F(CookieMonsterTest, WhileLoadingLoadCompletesBeforeKeyLoadCompletes) { | 2246 TEST_F(CookieMonsterTest, WhileLoadingLoadCompletesBeforeKeyLoadCompletes) { |
2228 const GURL kUrl = GURL(kTopLevelDomainPlus1); | 2247 const GURL kUrl = GURL(kTopLevelDomainPlus1); |
2229 | 2248 |
2230 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); | 2249 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); |
2231 store->set_store_load_commands(true); | 2250 store->set_store_load_commands(true); |
2232 std::unique_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); | 2251 std::unique_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); |
2233 | 2252 |
2234 // Get all cookies task that queues a task to set a cookie when executed. | 2253 // Get all cookies task that queues a task to set a cookie when executed. |
(...skipping 1186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3421 monster()->AddCallbackForCookie( | 3440 monster()->AddCallbackForCookie( |
3422 test_url_, "abc", | 3441 test_url_, "abc", |
3423 base::Bind(&RecordCookieChanges, &cookies1, nullptr))); | 3442 base::Bind(&RecordCookieChanges, &cookies1, nullptr))); |
3424 SetCookie(monster(), test_url_, "abc=def"); | 3443 SetCookie(monster(), test_url_, "abc=def"); |
3425 base::RunLoop().RunUntilIdle(); | 3444 base::RunLoop().RunUntilIdle(); |
3426 EXPECT_EQ(1U, cookies0.size()); | 3445 EXPECT_EQ(1U, cookies0.size()); |
3427 EXPECT_EQ(1U, cookies0.size()); | 3446 EXPECT_EQ(1U, cookies0.size()); |
3428 } | 3447 } |
3429 | 3448 |
3430 } // namespace net | 3449 } // namespace net |
OLD | NEW |