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

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

Issue 9959011: Add CookieStore::DeleteSessionCookiesAsync method. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rebased again Created 8 years, 8 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 <time.h> 7 #include <time.h>
8 #include <string> 8 #include <string>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 DCHECK(cm); 466 DCHECK(cm);
467 SetCookieCallback callback; 467 SetCookieCallback callback;
468 cm->DeleteCanonicalCookieAsync( 468 cm->DeleteCanonicalCookieAsync(
469 cookie, 469 cookie,
470 base::Bind(&SetCookieCallback::Run, base::Unretained(&callback))); 470 base::Bind(&SetCookieCallback::Run, base::Unretained(&callback)));
471 RunFor(kTimeout); 471 RunFor(kTimeout);
472 EXPECT_TRUE(callback.did_run()); 472 EXPECT_TRUE(callback.did_run());
473 return callback.result(); 473 return callback.result();
474 } 474 }
475 475
476 int DeleteSessionCookies(CookieMonster*cm) {
477 DCHECK(cm);
478 DeleteCallback callback;
479 cm->DeleteSessionCookiesAsync(
480 base::Bind(&DeleteCallback::Run, base::Unretained(&callback)));
481 RunFor(kTimeout);
482 EXPECT_TRUE(callback.did_run());
483 return callback.num_deleted();
484 }
485
476 // Helper for DeleteAllForHost test; repopulates CM with same layout 486 // Helper for DeleteAllForHost test; repopulates CM with same layout
477 // each time. 487 // each time.
478 void PopulateCmForDeleteAllForHost(scoped_refptr<CookieMonster> cm) { 488 void PopulateCmForDeleteAllForHost(scoped_refptr<CookieMonster> cm) {
479 GURL url_top_level_domain_plus_1(kTopLevelDomainPlus1); 489 GURL url_top_level_domain_plus_1(kTopLevelDomainPlus1);
480 GURL url_top_level_domain_plus_2(kTopLevelDomainPlus2); 490 GURL url_top_level_domain_plus_2(kTopLevelDomainPlus2);
481 GURL url_top_level_domain_plus_2_secure(kTopLevelDomainPlus2Secure); 491 GURL url_top_level_domain_plus_2_secure(kTopLevelDomainPlus2Secure);
482 GURL url_top_level_domain_plus_3(kTopLevelDomainPlus3); 492 GURL url_top_level_domain_plus_3(kTopLevelDomainPlus3);
483 GURL url_other(kOtherDomain); 493 GURL url_other(kOtherDomain);
484 494
485 DeleteAll(cm); 495 DeleteAll(cm);
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
750 } 760 }
751 761
752 ACTION_P3(GetAllCookiesForUrlAction, cookie_monster, url, callback) { 762 ACTION_P3(GetAllCookiesForUrlAction, cookie_monster, url, callback) {
753 cookie_monster->GetAllCookiesForURLAsync(url, callback->AsCallback()); 763 cookie_monster->GetAllCookiesForURLAsync(url, callback->AsCallback());
754 } 764 }
755 765
756 ACTION_P(PushCallbackAction, callback_vector) { 766 ACTION_P(PushCallbackAction, callback_vector) {
757 callback_vector->push(arg1); 767 callback_vector->push(arg1);
758 } 768 }
759 769
770 ACTION_P2(DeleteSessionCookiesAction, cookie_monster, callback) {
771 cookie_monster->DeleteSessionCookiesAsync(callback->AsCallback());
772 }
773
760 } // namespace 774 } // namespace
761 775
762 // This test suite verifies the task deferral behaviour of the CookieMonster. 776 // This test suite verifies the task deferral behaviour of the CookieMonster.
763 // Specifically, for each asynchronous method, verify that: 777 // Specifically, for each asynchronous method, verify that:
764 // 1. invoking it on an uninitialized cookie store causes the store to begin 778 // 1. invoking it on an uninitialized cookie store causes the store to begin
765 // chain-loading its backing data or loading data for a specific domain key 779 // chain-loading its backing data or loading data for a specific domain key
766 // (eTLD+1). 780 // (eTLD+1).
767 // 2. The initial invocation does not complete until the loading completes. 781 // 2. The initial invocation does not complete until the loading completes.
768 // 3. Invocations after the loading has completed complete immediately. 782 // 3. Invocations after the loading has completed complete immediately.
769 class DeferredCookieTaskTest : public CookieMonsterTest { 783 class DeferredCookieTaskTest : public CookieMonsterTest {
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
1089 1103
1090 EXPECT_CALL(delete_cookie_callback, Invoke(false)).WillOnce( 1104 EXPECT_CALL(delete_cookie_callback, Invoke(false)).WillOnce(
1091 DeleteCanonicalCookieAction( 1105 DeleteCanonicalCookieAction(
1092 &cookie_monster(), cookie, &delete_cookie_callback)); 1106 &cookie_monster(), cookie, &delete_cookie_callback));
1093 EXPECT_CALL(delete_cookie_callback, Invoke(false)).WillOnce( 1107 EXPECT_CALL(delete_cookie_callback, Invoke(false)).WillOnce(
1094 QuitCurrentMessageLoop()); 1108 QuitCurrentMessageLoop());
1095 1109
1096 CompleteLoadingAndWait(); 1110 CompleteLoadingAndWait();
1097 } 1111 }
1098 1112
1113 TEST_F(DeferredCookieTaskTest, DeferredDeleteSessionCookies) {
1114 MockDeleteCallback delete_callback;
1115
1116 BeginWith(DeleteSessionCookiesAction(
1117 &cookie_monster(), &delete_callback));
1118
1119 WaitForLoadCall();
1120
1121 EXPECT_CALL(delete_callback, Invoke(false)).WillOnce(
1122 DeleteSessionCookiesAction(&cookie_monster(), &delete_callback));
1123 EXPECT_CALL(delete_callback, Invoke(false)).WillOnce(
1124 QuitCurrentMessageLoop());
1125
1126 CompleteLoadingAndWait();
1127 }
1128
1099 // Verify that a series of queued tasks are executed in order upon loading of 1129 // Verify that a series of queued tasks are executed in order upon loading of
1100 // the backing store and that new tasks received while the queued tasks are 1130 // the backing store and that new tasks received while the queued tasks are
1101 // being dispatched go to the end of the queue. 1131 // being dispatched go to the end of the queue.
1102 TEST_F(DeferredCookieTaskTest, DeferredTaskOrder) { 1132 TEST_F(DeferredCookieTaskTest, DeferredTaskOrder) {
1103 DeclareLoadedCookie("www.google.izzle", 1133 DeclareLoadedCookie("www.google.izzle",
1104 "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", 1134 "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT",
1105 Time::Now() + TimeDelta::FromDays(3)); 1135 Time::Now() + TimeDelta::FromDays(3));
1106 1136
1107 MockGetCookiesCallback get_cookies_callback; 1137 MockGetCookiesCallback get_cookies_callback;
1108 MockSetCookiesCallback set_cookies_callback; 1138 MockSetCookiesCallback set_cookies_callback;
(...skipping 1294 matching lines...) Expand 10 before | Expand all | Expand 10 after
2403 } 2433 }
2404 2434
2405 void DeleteCanonicalCookieTask(CookieMonster* cm, 2435 void DeleteCanonicalCookieTask(CookieMonster* cm,
2406 const CookieMonster::CanonicalCookie& cookie, 2436 const CookieMonster::CanonicalCookie& cookie,
2407 SetCookieCallback* callback) { 2437 SetCookieCallback* callback) {
2408 cm->DeleteCanonicalCookieAsync( 2438 cm->DeleteCanonicalCookieAsync(
2409 cookie, 2439 cookie,
2410 base::Bind(&SetCookieCallback::Run, base::Unretained(callback))); 2440 base::Bind(&SetCookieCallback::Run, base::Unretained(callback)));
2411 } 2441 }
2412 2442
2443 void DeleteSessionCookiesTask(CookieMonster* cm, DeleteCallback* callback) {
2444 cm->DeleteSessionCookiesAsync(
2445 base::Bind(&DeleteCallback::Run, base::Unretained(callback)));
2446 }
2447
2413 protected: 2448 protected:
2414 void RunOnOtherThread(const base::Closure& task) { 2449 void RunOnOtherThread(const base::Closure& task) {
2415 other_thread_.Start(); 2450 other_thread_.Start();
2416 other_thread_.message_loop()->PostTask(FROM_HERE, task); 2451 other_thread_.message_loop()->PostTask(FROM_HERE, task);
2417 RunFor(kTimeout); 2452 RunFor(kTimeout);
2418 other_thread_.Stop(); 2453 other_thread_.Stop();
2419 } 2454 }
2420 2455
2421 Thread other_thread_; 2456 Thread other_thread_;
2422 }; 2457 };
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
2560 it = cookies.begin(); 2595 it = cookies.begin();
2561 base::Closure task = base::Bind( 2596 base::Closure task = base::Bind(
2562 &net::MultiThreadedCookieMonsterTest::DeleteCanonicalCookieTask, 2597 &net::MultiThreadedCookieMonsterTest::DeleteCanonicalCookieTask,
2563 base::Unretained(this), 2598 base::Unretained(this),
2564 cm, *it, &callback); 2599 cm, *it, &callback);
2565 RunOnOtherThread(task); 2600 RunOnOtherThread(task);
2566 EXPECT_TRUE(callback.did_run()); 2601 EXPECT_TRUE(callback.did_run());
2567 EXPECT_TRUE(callback.result()); 2602 EXPECT_TRUE(callback.result());
2568 } 2603 }
2569 2604
2605 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckDeleteSessionCookies) {
2606 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
2607 CookieOptions options;
2608 EXPECT_TRUE(SetCookieWithOptions(cm, url_google_, "A=B", options));
2609 EXPECT_TRUE(SetCookieWithOptions(cm, url_google_,
2610 "B=C; expires=Mon, 18-Apr-22 22:50:13 GMT",
2611 options));
2612 EXPECT_EQ(1, DeleteSessionCookies(cm));
2613 EXPECT_EQ(0, DeleteSessionCookies(cm));
2614
2615 EXPECT_TRUE(SetCookieWithOptions(cm, url_google_, "A=B", options));
2616 DeleteCallback callback(&other_thread_);
2617 base::Closure task = base::Bind(
2618 &net::MultiThreadedCookieMonsterTest::DeleteSessionCookiesTask,
2619 base::Unretained(this),
2620 cm, &callback);
2621 RunOnOtherThread(task);
2622 EXPECT_TRUE(callback.did_run());
2623 EXPECT_EQ(1, callback.num_deleted());
2624 }
2625
2570 TEST_F(CookieMonsterTest, ShortLivedSessionCookies) { 2626 TEST_F(CookieMonsterTest, ShortLivedSessionCookies) {
2571 scoped_refptr<MockPersistentCookieStore> store( 2627 scoped_refptr<MockPersistentCookieStore> store(
2572 new MockPersistentCookieStore); 2628 new MockPersistentCookieStore);
2573 scoped_refptr<CookieMonster> cm(new CookieMonster(store, NULL)); 2629 scoped_refptr<CookieMonster> cm(new CookieMonster(store, NULL));
2574 2630
2575 // Create a short-lived session cookie. 2631 // Create a short-lived session cookie.
2576 CookieOptions options; 2632 CookieOptions options;
2577 options.set_force_session(); 2633 options.set_force_session();
2578 Time current = Time::Now(); 2634 Time current = Time::Now();
2579 EXPECT_TRUE(SetCookieWithOptions(cm, url_google_, 2635 EXPECT_TRUE(SetCookieWithOptions(cm, url_google_,
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
2678 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[4].type); 2734 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[4].type);
2679 2735
2680 // Create some non-persistent cookies and check that they don't go to the 2736 // Create some non-persistent cookies and check that they don't go to the
2681 // persistent storage. 2737 // persistent storage.
2682 EXPECT_TRUE(SetCookie(cm, url_google_, "B=Bar")); 2738 EXPECT_TRUE(SetCookie(cm, url_google_, "B=Bar"));
2683 this->MatchCookieLines("A=Foo; B=Bar", GetCookies(cm, url_google_)); 2739 this->MatchCookieLines("A=Foo; B=Bar", GetCookies(cm, url_google_));
2684 EXPECT_EQ(5u, store->commands().size()); 2740 EXPECT_EQ(5u, store->commands().size());
2685 } 2741 }
2686 2742
2687 } // namespace net 2743 } // 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