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

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

Issue 1666513002: Promote CookieMonster::DeleteCanonicalCookieAsync to CookieStore. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@cookie_monster13
Patch Set: Rebase Created 4 years, 10 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
« no previous file with comments | « net/cookies/cookie_monster.cc ('k') | net/cookies/cookie_store.h » ('j') | 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_store_unittest.h" 5 #include "net/cookies/cookie_store_unittest.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 DCHECK(cm); 163 DCHECK(cm);
164 ResultSavingCookieCallback<int> callback; 164 ResultSavingCookieCallback<int> callback;
165 cm->DeleteAllCreatedBetweenForHostAsync( 165 cm->DeleteAllCreatedBetweenForHostAsync(
166 delete_begin, delete_end, url, 166 delete_begin, delete_end, url,
167 base::Bind(&ResultSavingCookieCallback<int>::Run, 167 base::Bind(&ResultSavingCookieCallback<int>::Run,
168 base::Unretained(&callback))); 168 base::Unretained(&callback)));
169 callback.WaitUntilDone(); 169 callback.WaitUntilDone();
170 return callback.result(); 170 return callback.result();
171 } 171 }
172 172
173 bool DeleteCanonicalCookie(CookieMonster* cm, const CanonicalCookie& cookie) {
174 DCHECK(cm);
175 ResultSavingCookieCallback<bool> callback;
176 cm->DeleteCanonicalCookieAsync(
177 cookie, base::Bind(&ResultSavingCookieCallback<bool>::Run,
178 base::Unretained(&callback)));
179 callback.WaitUntilDone();
180 return callback.result();
181 }
182
183 // Helper for DeleteAllForHost test; repopulates CM with same layout 173 // Helper for DeleteAllForHost test; repopulates CM with same layout
184 // each time. 174 // each time.
185 void PopulateCmForDeleteAllForHost(scoped_refptr<CookieMonster> cm) { 175 void PopulateCmForDeleteAllForHost(scoped_refptr<CookieMonster> cm) {
186 GURL url_top_level_domain_plus_1(kTopLevelDomainPlus1); 176 GURL url_top_level_domain_plus_1(kTopLevelDomainPlus1);
187 GURL url_top_level_domain_plus_2(kTopLevelDomainPlus2); 177 GURL url_top_level_domain_plus_2(kTopLevelDomainPlus2);
188 GURL url_top_level_domain_plus_2_secure(kTopLevelDomainPlus2Secure); 178 GURL url_top_level_domain_plus_2_secure(kTopLevelDomainPlus2Secure);
189 GURL url_top_level_domain_plus_3(kTopLevelDomainPlus3); 179 GURL url_top_level_domain_plus_3(kTopLevelDomainPlus3);
190 GURL url_other(kOtherDomain); 180 GURL url_other(kOtherDomain);
191 181
192 this->DeleteAll(cm.get()); 182 this->DeleteAll(cm.get());
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after
621 MOCK_METHOD1(Invoke, void(const CookieList& cookies)); 611 MOCK_METHOD1(Invoke, void(const CookieList& cookies));
622 }; 612 };
623 613
624 class MockDeleteCallback 614 class MockDeleteCallback
625 : public MockCookieCallback<MockDeleteCallback, 615 : public MockCookieCallback<MockDeleteCallback,
626 CookieMonster::DeleteCallback> { 616 CookieMonster::DeleteCallback> {
627 public: 617 public:
628 MOCK_METHOD1(Invoke, void(int num_deleted)); 618 MOCK_METHOD1(Invoke, void(int num_deleted));
629 }; 619 };
630 620
631 class MockDeleteCookieCallback
632 : public MockCookieCallback<MockDeleteCookieCallback,
633 CookieMonster::DeleteCookieCallback> {
634 public:
635 MOCK_METHOD1(Invoke, void(bool success));
636 };
637
638 struct CookiesInputInfo { 621 struct CookiesInputInfo {
639 const GURL url; 622 const GURL url;
640 const std::string name; 623 const std::string name;
641 const std::string value; 624 const std::string value;
642 const std::string domain; 625 const std::string domain;
643 const std::string path; 626 const std::string path;
644 const base::Time expiration_time; 627 const base::Time expiration_time;
645 bool secure; 628 bool secure;
646 bool http_only; 629 bool http_only;
647 bool same_site; 630 bool same_site;
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after
1090 1073
1091 CompleteLoading(); 1074 CompleteLoading();
1092 loop.Run(); 1075 loop.Run();
1093 } 1076 }
1094 1077
1095 TEST_F(DeferredCookieTaskTest, DeferredDeleteCanonicalCookie) { 1078 TEST_F(DeferredCookieTaskTest, DeferredDeleteCanonicalCookie) {
1096 std::vector<CanonicalCookie*> cookies; 1079 std::vector<CanonicalCookie*> cookies;
1097 CanonicalCookie cookie = BuildCanonicalCookie( 1080 CanonicalCookie cookie = BuildCanonicalCookie(
1098 http_www_google_.host(), "X=1; path=/", base::Time::Now()); 1081 http_www_google_.host(), "X=1; path=/", base::Time::Now());
1099 1082
1100 MockDeleteCookieCallback delete_cookie_callback; 1083 MockDeleteCallback delete_cookie_callback;
1101 1084
1102 BeginWith(DeleteCanonicalCookieAction(&cookie_monster(), cookie, 1085 BeginWith(DeleteCanonicalCookieAction(&cookie_monster(), cookie,
1103 &delete_cookie_callback)); 1086 &delete_cookie_callback));
1104 1087
1105 WaitForLoadCall(); 1088 WaitForLoadCall();
1106 1089
1107 EXPECT_CALL(delete_cookie_callback, Invoke(false)) 1090 EXPECT_CALL(delete_cookie_callback, Invoke(0))
1108 .WillOnce(DeleteCanonicalCookieAction(&cookie_monster(), cookie, 1091 .WillOnce(DeleteCanonicalCookieAction(&cookie_monster(), cookie,
1109 &delete_cookie_callback)); 1092 &delete_cookie_callback));
1110 base::RunLoop loop; 1093 base::RunLoop loop;
1111 EXPECT_CALL(delete_cookie_callback, Invoke(false)) 1094 EXPECT_CALL(delete_cookie_callback, Invoke(0)).WillOnce(QuitRunLoop(&loop));
1112 .WillOnce(QuitRunLoop(&loop));
1113 1095
1114 CompleteLoading(); 1096 CompleteLoading();
1115 loop.Run(); 1097 loop.Run();
1116 } 1098 }
1117 1099
1118 TEST_F(DeferredCookieTaskTest, DeferredDeleteSessionCookies) { 1100 TEST_F(DeferredCookieTaskTest, DeferredDeleteSessionCookies) {
1119 MockDeleteCallback delete_callback; 1101 MockDeleteCallback delete_callback;
1120 1102
1121 BeginWith(DeleteSessionCookiesAction(&cookie_monster(), &delete_callback)); 1103 BeginWith(DeleteSessionCookiesAction(&cookie_monster(), &delete_callback));
1122 1104
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
1263 } 1245 }
1264 1246
1265 TEST_F(CookieMonsterTest, TestHostGarbageCollection) { 1247 TEST_F(CookieMonsterTest, TestHostGarbageCollection) {
1266 TestHostGarbageCollectHelper(); 1248 TestHostGarbageCollectHelper();
1267 } 1249 }
1268 1250
1269 TEST_F(CookieMonsterTest, TestPriorityAwareGarbageCollection) { 1251 TEST_F(CookieMonsterTest, TestPriorityAwareGarbageCollection) {
1270 TestPriorityAwareGarbageCollectHelper(); 1252 TestPriorityAwareGarbageCollectHelper();
1271 } 1253 }
1272 1254
1273 TEST_F(CookieMonsterTest, TestDeleteSingleCookie) {
1274 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
1275
1276 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=B"));
1277 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "C=D"));
1278 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "E=F"));
1279 EXPECT_EQ("A=B; C=D; E=F", GetCookies(cm.get(), http_www_google_.url()));
1280
1281 EXPECT_TRUE(
1282 FindAndDeleteCookie(cm.get(), http_www_google_.url().host(), "C"));
1283 EXPECT_EQ("A=B; E=F", GetCookies(cm.get(), http_www_google_.url()));
1284
1285 EXPECT_FALSE(FindAndDeleteCookie(cm.get(), "random.host", "E"));
1286 EXPECT_EQ("A=B; E=F", GetCookies(cm.get(), http_www_google_.url()));
1287 }
1288
1289 TEST_F(CookieMonsterTest, SetCookieableSchemes) { 1255 TEST_F(CookieMonsterTest, SetCookieableSchemes) {
1290 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); 1256 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
1291 scoped_refptr<CookieMonster> cm_foo(new CookieMonster(NULL, NULL)); 1257 scoped_refptr<CookieMonster> cm_foo(new CookieMonster(NULL, NULL));
1292 1258
1293 // Only cm_foo should allow foo:// cookies. 1259 // Only cm_foo should allow foo:// cookies.
1294 std::vector<std::string> schemes; 1260 std::vector<std::string> schemes;
1295 schemes.push_back("foo"); 1261 schemes.push_back("foo");
1296 cm_foo->SetCookieableSchemes(schemes); 1262 cm_foo->SetCookieableSchemes(schemes);
1297 1263
1298 GURL foo_url("foo://host/path"); 1264 GURL foo_url("foo://host/path");
(...skipping 1134 matching lines...) Expand 10 before | Expand all | Expand 10 after
2433 const GURL& url, 2399 const GURL& url,
2434 ResultSavingCookieCallback<int>* callback) { 2400 ResultSavingCookieCallback<int>* callback) {
2435 cm->DeleteAllCreatedBetweenForHostAsync( 2401 cm->DeleteAllCreatedBetweenForHostAsync(
2436 delete_begin, delete_end, url, 2402 delete_begin, delete_end, url,
2437 base::Bind(&ResultSavingCookieCallback<int>::Run, 2403 base::Bind(&ResultSavingCookieCallback<int>::Run,
2438 base::Unretained(callback))); 2404 base::Unretained(callback)));
2439 } 2405 }
2440 2406
2441 void DeleteCanonicalCookieTask(CookieMonster* cm, 2407 void DeleteCanonicalCookieTask(CookieMonster* cm,
2442 const CanonicalCookie& cookie, 2408 const CanonicalCookie& cookie,
2443 ResultSavingCookieCallback<bool>* callback) { 2409 ResultSavingCookieCallback<int>* callback) {
2444 cm->DeleteCanonicalCookieAsync( 2410 cm->DeleteCanonicalCookieAsync(
2445 cookie, base::Bind(&ResultSavingCookieCallback<bool>::Run, 2411 cookie, base::Bind(&ResultSavingCookieCallback<int>::Run,
2446 base::Unretained(callback))); 2412 base::Unretained(callback)));
2447 } 2413 }
2448 2414
2449 protected: 2415 protected:
2450 void RunOnOtherThread(const base::Closure& task) { 2416 void RunOnOtherThread(const base::Closure& task) {
2451 other_thread_.Start(); 2417 other_thread_.Start();
2452 other_thread_.task_runner()->PostTask(FROM_HERE, task); 2418 other_thread_.task_runner()->PostTask(FROM_HERE, task);
2453 other_thread_.Stop(); 2419 other_thread_.Stop();
2454 } 2420 }
2455 2421
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
2612 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); 2578 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
2613 CookieOptions options; 2579 CookieOptions options;
2614 EXPECT_TRUE( 2580 EXPECT_TRUE(
2615 SetCookieWithOptions(cm.get(), http_www_google_.url(), "A=B", options)); 2581 SetCookieWithOptions(cm.get(), http_www_google_.url(), "A=B", options));
2616 CookieList cookies = GetAllCookies(cm.get()); 2582 CookieList cookies = GetAllCookies(cm.get());
2617 CookieList::iterator it = cookies.begin(); 2583 CookieList::iterator it = cookies.begin();
2618 EXPECT_TRUE(DeleteCanonicalCookie(cm.get(), *it)); 2584 EXPECT_TRUE(DeleteCanonicalCookie(cm.get(), *it));
2619 2585
2620 EXPECT_TRUE( 2586 EXPECT_TRUE(
2621 SetCookieWithOptions(cm.get(), http_www_google_.url(), "A=B", options)); 2587 SetCookieWithOptions(cm.get(), http_www_google_.url(), "A=B", options));
2622 ResultSavingCookieCallback<bool> callback(&other_thread_); 2588 ResultSavingCookieCallback<int> callback(&other_thread_);
2623 cookies = GetAllCookies(cm.get()); 2589 cookies = GetAllCookies(cm.get());
2624 it = cookies.begin(); 2590 it = cookies.begin();
2625 base::Closure task = 2591 base::Closure task =
2626 base::Bind(&MultiThreadedCookieMonsterTest::DeleteCanonicalCookieTask, 2592 base::Bind(&MultiThreadedCookieMonsterTest::DeleteCanonicalCookieTask,
2627 base::Unretained(this), cm, *it, &callback); 2593 base::Unretained(this), cm, *it, &callback);
2628 RunOnOtherThread(task); 2594 RunOnOtherThread(task);
2629 callback.WaitUntilDone(); 2595 callback.WaitUntilDone();
2630 EXPECT_TRUE(callback.result()); 2596 EXPECT_EQ(1, callback.result());
2631 } 2597 }
2632 2598
2633 // Ensure that cookies for http, https, ws, and wss all share the same storage 2599 // Ensure that cookies for http, https, ws, and wss all share the same storage
2634 // and policies when GetAllCookiesForURLAsync is used. This test is part of 2600 // and policies when GetAllCookiesForURLAsync is used. This test is part of
2635 // MultiThreadedCookieMonsterTest in order to test and use 2601 // MultiThreadedCookieMonsterTest in order to test and use
2636 // GetAllCookiesForURLAsync, but it does not use any additional threads. 2602 // GetAllCookiesForURLAsync, but it does not use any additional threads.
2637 TEST_F(MultiThreadedCookieMonsterTest, GetAllCookiesForURLEffectiveDomain) { 2603 TEST_F(MultiThreadedCookieMonsterTest, GetAllCookiesForURLEffectiveDomain) {
2638 scoped_ptr<CanonicalCookie> cookie(CanonicalCookie::Create( 2604 scoped_ptr<CanonicalCookie> cookie(CanonicalCookie::Create(
2639 http_www_google_.url(), kValidCookieLine, Time::Now(), CookieOptions())); 2605 http_www_google_.url(), kValidCookieLine, Time::Now(), CookieOptions()));
2640 2606
(...skipping 745 matching lines...) Expand 10 before | Expand all | Expand 10 after
3386 monster()->AddCallbackForCookie( 3352 monster()->AddCallbackForCookie(
3387 test_url_, "abc", 3353 test_url_, "abc",
3388 base::Bind(&RecordCookieChanges, &cookies1, nullptr))); 3354 base::Bind(&RecordCookieChanges, &cookies1, nullptr)));
3389 SetCookie(monster(), test_url_, "abc=def"); 3355 SetCookie(monster(), test_url_, "abc=def");
3390 base::MessageLoop::current()->RunUntilIdle(); 3356 base::MessageLoop::current()->RunUntilIdle();
3391 EXPECT_EQ(1U, cookies0.size()); 3357 EXPECT_EQ(1U, cookies0.size());
3392 EXPECT_EQ(1U, cookies0.size()); 3358 EXPECT_EQ(1U, cookies0.size());
3393 } 3359 }
3394 3360
3395 } // namespace net 3361 } // namespace net
OLDNEW
« no previous file with comments | « net/cookies/cookie_monster.cc ('k') | net/cookies/cookie_store.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698