Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(77)

Side by Side Diff: net/cookies/cookie_monster_unittest.cc

Issue 2924933002: Fix CookieMonster garbage collection when no insecure cookies. (Closed)
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« net/cookies/cookie_monster.cc ('K') | « net/cookies/cookie_monster.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 2197 matching lines...) Expand 10 before | Expand all | Expand 10 after
2208 2208
2209 for (int ci = 0; ci < static_cast<int>(arraysize(test_cases)); ++ci) { 2209 for (int ci = 0; ci < static_cast<int>(arraysize(test_cases)); ++ci) {
2210 const TestCase* test_case = &test_cases[ci]; 2210 const TestCase* test_case = &test_cases[ci];
2211 std::unique_ptr<CookieMonster> cm = CreateMonsterFromStoreForGC( 2211 std::unique_ptr<CookieMonster> cm = CreateMonsterFromStoreForGC(
2212 test_case->num_cookies, test_case->num_old_cookies, 0, 0, 2212 test_case->num_cookies, test_case->num_old_cookies, 0, 0,
2213 CookieMonster::kSafeFromGlobalPurgeDays * 2); 2213 CookieMonster::kSafeFromGlobalPurgeDays * 2);
2214 EXPECT_EQ(test_case->expected_initial_cookies, 2214 EXPECT_EQ(test_case->expected_initial_cookies,
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");
mmenke 2017/06/06 23:19:48 If this were a secure cookie, this test would have
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
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
OLDNEW
« net/cookies/cookie_monster.cc ('K') | « net/cookies/cookie_monster.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698