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

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

Issue 1634803004: Convert CookieMonster tests to use base::RunLoop (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comments 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 | « no previous file | net/cookies/cookie_store_test_callbacks.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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 MultiThreadedCookieStoreTest, 108 MultiThreadedCookieStoreTest,
109 CookieMonsterTestTraits); 109 CookieMonsterTestTraits);
110 110
111 INSTANTIATE_TYPED_TEST_CASE_P(CookieMonsterStrictSecure, 111 INSTANTIATE_TYPED_TEST_CASE_P(CookieMonsterStrictSecure,
112 CookieStoreTest, 112 CookieStoreTest,
113 CookieMonsterEnforcingStrictSecure); 113 CookieMonsterEnforcingStrictSecure);
114 114
115 template <typename T> 115 template <typename T>
116 class CookieMonsterTestBase : public CookieStoreTest<T> { 116 class CookieMonsterTestBase : public CookieStoreTest<T> {
117 public: 117 public:
118 using CookieStoreTest<T>::RunFor;
119 using CookieStoreTest<T>::SetCookie; 118 using CookieStoreTest<T>::SetCookie;
120 119
121 protected: 120 protected:
122 using CookieStoreTest<T>::http_www_google_; 121 using CookieStoreTest<T>::http_www_google_;
123 using CookieStoreTest<T>::https_www_google_; 122 using CookieStoreTest<T>::https_www_google_;
124 123
125 CookieList GetAllCookiesForURL(CookieMonster* cm, const GURL& url) { 124 CookieList GetAllCookiesForURL(CookieMonster* cm, const GURL& url) {
126 DCHECK(cm); 125 DCHECK(cm);
127 GetCookieListCallback callback; 126 GetCookieListCallback callback;
128 cm->GetAllCookiesForURLAsync(url, base::Bind(&GetCookieListCallback::Run, 127 cm->GetAllCookiesForURLAsync(url, base::Bind(&GetCookieListCallback::Run,
129 base::Unretained(&callback))); 128 base::Unretained(&callback)));
130 RunFor(kTimeout); 129 callback.WaitUntilDone();
131 EXPECT_TRUE(callback.did_run());
132 return callback.cookies(); 130 return callback.cookies();
133 } 131 }
134 132
135 CookieList GetAllCookiesForURLWithOptions(CookieMonster* cm, 133 CookieList GetAllCookiesForURLWithOptions(CookieMonster* cm,
136 const GURL& url, 134 const GURL& url,
137 const CookieOptions& options) { 135 const CookieOptions& options) {
138 DCHECK(cm); 136 DCHECK(cm);
139 GetCookieListCallback callback; 137 GetCookieListCallback callback;
140 cm->GetAllCookiesForURLWithOptionsAsync( 138 cm->GetAllCookiesForURLWithOptionsAsync(
141 url, options, 139 url, options,
142 base::Bind(&GetCookieListCallback::Run, base::Unretained(&callback))); 140 base::Bind(&GetCookieListCallback::Run, base::Unretained(&callback)));
143 RunFor(kTimeout); 141 callback.WaitUntilDone();
144 EXPECT_TRUE(callback.did_run());
145 return callback.cookies(); 142 return callback.cookies();
146 } 143 }
147 144
148 bool SetCookieWithDetails(CookieMonster* cm, 145 bool SetCookieWithDetails(CookieMonster* cm,
149 const GURL& url, 146 const GURL& url,
150 const std::string& name, 147 const std::string& name,
151 const std::string& value, 148 const std::string& value,
152 const std::string& domain, 149 const std::string& domain,
153 const std::string& path, 150 const std::string& path,
154 const base::Time& expiration_time, 151 const base::Time& expiration_time,
155 bool secure, 152 bool secure,
156 bool http_only, 153 bool http_only,
157 bool first_party_only, 154 bool first_party_only,
158 CookiePriority priority) { 155 CookiePriority priority) {
159 DCHECK(cm); 156 DCHECK(cm);
160 ResultSavingCookieCallback<bool> callback; 157 ResultSavingCookieCallback<bool> callback;
161 cm->SetCookieWithDetailsAsync( 158 cm->SetCookieWithDetailsAsync(
162 url, name, value, domain, path, expiration_time, secure, http_only, 159 url, name, value, domain, path, expiration_time, secure, http_only,
163 first_party_only, false /* enforce prefixes */, 160 first_party_only, false /* enforce prefixes */,
164 false /* enforces strict secure cookies */, priority, 161 false /* enforces strict secure cookies */, priority,
165 base::Bind(&ResultSavingCookieCallback<bool>::Run, 162 base::Bind(&ResultSavingCookieCallback<bool>::Run,
166 base::Unretained(&callback))); 163 base::Unretained(&callback)));
167 RunFor(kTimeout); 164 callback.WaitUntilDone();
168 EXPECT_TRUE(callback.did_run());
169 return callback.result(); 165 return callback.result();
170 } 166 }
171 167
172 bool SetAllCookies(CookieMonster* cm, const CookieList& list) { 168 bool SetAllCookies(CookieMonster* cm, const CookieList& list) {
173 DCHECK(cm); 169 DCHECK(cm);
174 ResultSavingCookieCallback<bool> callback; 170 ResultSavingCookieCallback<bool> callback;
175 cm->SetAllCookiesAsync(list, 171 cm->SetAllCookiesAsync(list,
176 base::Bind(&ResultSavingCookieCallback<bool>::Run, 172 base::Bind(&ResultSavingCookieCallback<bool>::Run,
177 base::Unretained(&callback))); 173 base::Unretained(&callback)));
178 RunFor(kTimeout); 174 callback.WaitUntilDone();
179 EXPECT_TRUE(callback.did_run());
180 return callback.result(); 175 return callback.result();
181 } 176 }
182 177
183 int DeleteAll(CookieMonster* cm) { 178 int DeleteAll(CookieMonster* cm) {
184 DCHECK(cm); 179 DCHECK(cm);
185 ResultSavingCookieCallback<int> callback; 180 ResultSavingCookieCallback<int> callback;
186 cm->DeleteAllAsync(base::Bind(&ResultSavingCookieCallback<int>::Run, 181 cm->DeleteAllAsync(base::Bind(&ResultSavingCookieCallback<int>::Run,
187 base::Unretained(&callback))); 182 base::Unretained(&callback)));
188 RunFor(kTimeout); 183 callback.WaitUntilDone();
189 EXPECT_TRUE(callback.did_run());
190 return callback.result(); 184 return callback.result();
191 } 185 }
192 186
193 int DeleteAllCreatedBetween(CookieMonster* cm, 187 int DeleteAllCreatedBetween(CookieMonster* cm,
194 const base::Time& delete_begin, 188 const base::Time& delete_begin,
195 const base::Time& delete_end) { 189 const base::Time& delete_end) {
196 DCHECK(cm); 190 DCHECK(cm);
197 ResultSavingCookieCallback<int> callback; 191 ResultSavingCookieCallback<int> callback;
198 cm->DeleteAllCreatedBetweenAsync( 192 cm->DeleteAllCreatedBetweenAsync(
199 delete_begin, delete_end, 193 delete_begin, delete_end,
200 base::Bind(&ResultSavingCookieCallback<int>::Run, 194 base::Bind(&ResultSavingCookieCallback<int>::Run,
201 base::Unretained(&callback))); 195 base::Unretained(&callback)));
202 RunFor(kTimeout); 196 callback.WaitUntilDone();
203 EXPECT_TRUE(callback.did_run());
204 return callback.result(); 197 return callback.result();
205 } 198 }
206 199
207 int DeleteAllCreatedBetweenForHost(CookieMonster* cm, 200 int DeleteAllCreatedBetweenForHost(CookieMonster* cm,
208 const base::Time delete_begin, 201 const base::Time delete_begin,
209 const base::Time delete_end, 202 const base::Time delete_end,
210 const GURL& url) { 203 const GURL& url) {
211 DCHECK(cm); 204 DCHECK(cm);
212 ResultSavingCookieCallback<int> callback; 205 ResultSavingCookieCallback<int> callback;
213 cm->DeleteAllCreatedBetweenForHostAsync( 206 cm->DeleteAllCreatedBetweenForHostAsync(
214 delete_begin, delete_end, url, 207 delete_begin, delete_end, url,
215 base::Bind(&ResultSavingCookieCallback<int>::Run, 208 base::Bind(&ResultSavingCookieCallback<int>::Run,
216 base::Unretained(&callback))); 209 base::Unretained(&callback)));
217 RunFor(kTimeout); 210 callback.WaitUntilDone();
218 EXPECT_TRUE(callback.did_run());
219 return callback.result(); 211 return callback.result();
220 } 212 }
221 213
222 int DeleteAllForHost(CookieMonster* cm, const GURL& url) { 214 int DeleteAllForHost(CookieMonster* cm, const GURL& url) {
223 DCHECK(cm); 215 DCHECK(cm);
224 ResultSavingCookieCallback<int> callback; 216 ResultSavingCookieCallback<int> callback;
225 cm->DeleteAllForHostAsync(url, 217 cm->DeleteAllForHostAsync(url,
226 base::Bind(&ResultSavingCookieCallback<int>::Run, 218 base::Bind(&ResultSavingCookieCallback<int>::Run,
227 base::Unretained(&callback))); 219 base::Unretained(&callback)));
228 RunFor(kTimeout); 220 callback.WaitUntilDone();
229 EXPECT_TRUE(callback.did_run());
230 return callback.result(); 221 return callback.result();
231 } 222 }
232 223
233 bool DeleteCanonicalCookie(CookieMonster* cm, const CanonicalCookie& cookie) { 224 bool DeleteCanonicalCookie(CookieMonster* cm, const CanonicalCookie& cookie) {
234 DCHECK(cm); 225 DCHECK(cm);
235 ResultSavingCookieCallback<bool> callback; 226 ResultSavingCookieCallback<bool> callback;
236 cm->DeleteCanonicalCookieAsync( 227 cm->DeleteCanonicalCookieAsync(
237 cookie, base::Bind(&ResultSavingCookieCallback<bool>::Run, 228 cookie, base::Bind(&ResultSavingCookieCallback<bool>::Run,
238 base::Unretained(&callback))); 229 base::Unretained(&callback)));
239 RunFor(kTimeout); 230 callback.WaitUntilDone();
240 EXPECT_TRUE(callback.did_run());
241 return callback.result(); 231 return callback.result();
242 } 232 }
243 233
244 // Helper for DeleteAllForHost test; repopulates CM with same layout 234 // Helper for DeleteAllForHost test; repopulates CM with same layout
245 // each time. 235 // each time.
246 void PopulateCmForDeleteAllForHost(scoped_refptr<CookieMonster> cm) { 236 void PopulateCmForDeleteAllForHost(scoped_refptr<CookieMonster> cm) {
247 GURL url_top_level_domain_plus_1(kTopLevelDomainPlus1); 237 GURL url_top_level_domain_plus_1(kTopLevelDomainPlus1);
248 GURL url_top_level_domain_plus_2(kTopLevelDomainPlus2); 238 GURL url_top_level_domain_plus_2(kTopLevelDomainPlus2);
249 GURL url_top_level_domain_plus_2_secure(kTopLevelDomainPlus2Secure); 239 GURL url_top_level_domain_plus_2_secure(kTopLevelDomainPlus2Secure);
250 GURL url_top_level_domain_plus_3(kTopLevelDomainPlus3); 240 GURL url_top_level_domain_plus_3(kTopLevelDomainPlus3);
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after
698 const std::string value; 688 const std::string value;
699 const std::string domain; 689 const std::string domain;
700 const std::string path; 690 const std::string path;
701 const base::Time expiration_time; 691 const base::Time expiration_time;
702 bool secure; 692 bool secure;
703 bool http_only; 693 bool http_only;
704 bool first_party_only; 694 bool first_party_only;
705 CookiePriority priority; 695 CookiePriority priority;
706 }; 696 };
707 697
708 ACTION(QuitCurrentMessageLoop) { 698 ACTION_P(QuitRunLoop, run_loop) {
709 base::ThreadTaskRunnerHandle::Get()->PostTask( 699 run_loop->Quit();
710 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure());
711 } 700 }
712 701
713 // TODO(erikwright): When the synchronous helpers 'GetCookies' etc. are removed, 702 // TODO(erikwright): When the synchronous helpers 'GetCookies' etc. are removed,
714 // rename these, removing the 'Action' suffix. 703 // rename these, removing the 'Action' suffix.
715 ACTION_P4(DeleteCookieAction, cookie_monster, url, name, callback) { 704 ACTION_P4(DeleteCookieAction, cookie_monster, url, name, callback) {
716 cookie_monster->DeleteCookieAsync(url, name, callback->AsCallback()); 705 cookie_monster->DeleteCookieAsync(url, name, callback->AsCallback());
717 } 706 }
718 ACTION_P3(GetCookiesAction, cookie_monster, url, callback) { 707 ACTION_P3(GetCookiesAction, cookie_monster, url, callback) {
719 cookie_monster->GetCookiesWithOptionsAsync(url, CookieOptions(), 708 cookie_monster->GetCookiesWithOptionsAsync(url, CookieOptions(),
720 callback->AsCallback()); 709 callback->AsCallback());
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
779 768
780 // This test suite verifies the task deferral behaviour of the CookieMonster. 769 // This test suite verifies the task deferral behaviour of the CookieMonster.
781 // Specifically, for each asynchronous method, verify that: 770 // Specifically, for each asynchronous method, verify that:
782 // 1. invoking it on an uninitialized cookie store causes the store to begin 771 // 1. invoking it on an uninitialized cookie store causes the store to begin
783 // chain-loading its backing data or loading data for a specific domain key 772 // chain-loading its backing data or loading data for a specific domain key
784 // (eTLD+1). 773 // (eTLD+1).
785 // 2. The initial invocation does not complete until the loading completes. 774 // 2. The initial invocation does not complete until the loading completes.
786 // 3. Invocations after the loading has completed complete immediately. 775 // 3. Invocations after the loading has completed complete immediately.
787 class DeferredCookieTaskTest : public CookieMonsterTest { 776 class DeferredCookieTaskTest : public CookieMonsterTest {
788 protected: 777 protected:
789 DeferredCookieTaskTest() { 778 DeferredCookieTaskTest() : expect_load_called_(false) {
790 persistent_store_ = new NewMockPersistentCookieStore(); 779 persistent_store_ = new NewMockPersistentCookieStore();
791 cookie_monster_ = new CookieMonster(persistent_store_.get(), NULL); 780 cookie_monster_ = new CookieMonster(persistent_store_.get(), NULL);
792 } 781 }
793 782
794 // Defines a cookie to be returned from PersistentCookieStore::Load 783 // Defines a cookie to be returned from PersistentCookieStore::Load
795 void DeclareLoadedCookie(const std::string& key, 784 void DeclareLoadedCookie(const std::string& key,
796 const std::string& cookie_line, 785 const std::string& cookie_line,
797 const base::Time& creation_time) { 786 const base::Time& creation_time) {
798 AddCookieToList(key, cookie_line, creation_time, &loaded_cookies_); 787 AddCookieToList(key, cookie_line, creation_time, &loaded_cookies_);
799 } 788 }
800 789
801 // Runs the message loop, waiting until PersistentCookieStore::Load is called. 790 // Runs the message loop, waiting until PersistentCookieStore::Load is called.
802 // Call CompleteLoadingAndWait to cause the load to complete. 791 // Call CompleteLoading to cause the load to complete.
803 void WaitForLoadCall() { 792 void WaitForLoadCall() {
804 RunFor(kTimeout); 793 load_run_loop_.Run();
805 794
806 // Verify that PeristentStore::Load was called. 795 // Verify that PeristentStore::Load was called.
807 testing::Mock::VerifyAndClear(persistent_store_.get()); 796 testing::Mock::VerifyAndClear(persistent_store_.get());
808 } 797 }
809 798
810 // Invokes the PersistentCookieStore::LoadCookiesForKey completion callbacks 799 // Invokes the PersistentCookieStore::LoadCookiesForKey completion callbacks
811 // and PersistentCookieStore::Load completion callback and waits 800 // and PersistentCookieStore::Load completion callback.
812 // until the message loop is quit. 801 void CompleteLoading() {
813 void CompleteLoadingAndWait() {
814 while (!loaded_for_key_callbacks_.empty()) { 802 while (!loaded_for_key_callbacks_.empty()) {
815 loaded_for_key_callbacks_.front().Run(loaded_cookies_); 803 loaded_for_key_callbacks_.front().Run(loaded_cookies_);
816 loaded_cookies_.clear(); 804 loaded_cookies_.clear();
817 loaded_for_key_callbacks_.pop(); 805 loaded_for_key_callbacks_.pop();
818 } 806 }
819
820 loaded_callback_.Run(loaded_cookies_); 807 loaded_callback_.Run(loaded_cookies_);
821 RunFor(kTimeout);
822 } 808 }
823 809
824 // Performs the provided action, expecting it to cause a call to 810 // Performs the provided action, expecting it to cause a call to
825 // PersistentCookieStore::Load. Call WaitForLoadCall to verify the load call 811 // PersistentCookieStore::Load. Call WaitForLoadCall to verify the load call
826 // is received. 812 // is received.
827 void BeginWith(testing::Action<void(void)> action) { 813 void BeginWith(testing::Action<void(void)> action) {
828 EXPECT_CALL(*this, Begin()).WillOnce(action); 814 EXPECT_CALL(*this, Begin()).WillOnce(action);
829 ExpectLoadCall(); 815 ExpectLoadCall();
830 Begin(); 816 Begin();
831 } 817 }
832 818
833 void BeginWithForDomainKey(std::string key, 819 void BeginWithForDomainKey(std::string key,
834 testing::Action<void(void)> action) { 820 testing::Action<void(void)> action) {
835 EXPECT_CALL(*this, Begin()).WillOnce(action); 821 EXPECT_CALL(*this, Begin()).WillOnce(action);
836 ExpectLoadCall(); 822 ExpectLoadCall();
837 ExpectLoadForKeyCall(key, false); 823 ExpectLoadForKeyCall(key);
838 Begin(); 824 Begin();
839 } 825 }
840 826
841 // Declares an expectation that PersistentCookieStore::Load will be called, 827 // Declares an expectation that PersistentCookieStore::Load will be called,
842 // saving the provided callback and sending a quit to the message loop. 828 // saving the provided callback and sending a quit to |load_run_loop_|.
843 void ExpectLoadCall() { 829 void ExpectLoadCall() {
830 // Make sure the |load_run_loop_| is not reused.
831 CHECK(!expect_load_called_);
832 expect_load_called_ = true;
844 EXPECT_CALL(*persistent_store_.get(), Load(testing::_)) 833 EXPECT_CALL(*persistent_store_.get(), Load(testing::_))
845 .WillOnce(testing::DoAll(testing::SaveArg<0>(&loaded_callback_), 834 .WillOnce(testing::DoAll(testing::SaveArg<0>(&loaded_callback_),
846 QuitCurrentMessageLoop())); 835 QuitRunLoop(&load_run_loop_)));
847 } 836 }
848 837
849 // Declares an expectation that PersistentCookieStore::LoadCookiesForKey 838 // Declares an expectation that PersistentCookieStore::LoadCookiesForKey
850 // will be called, saving the provided callback and sending a quit to the 839 // will be called, saving the provided callback.
851 // message loop. 840 void ExpectLoadForKeyCall(const std::string& key) {
852 void ExpectLoadForKeyCall(const std::string& key, bool quit_queue) { 841 EXPECT_CALL(*persistent_store_.get(), LoadCookiesForKey(key, testing::_))
853 if (quit_queue) 842 .WillOnce(PushCallbackAction(&loaded_for_key_callbacks_));
854 EXPECT_CALL(*persistent_store_.get(), LoadCookiesForKey(key, testing::_))
855 .WillOnce(
856 testing::DoAll(PushCallbackAction(&loaded_for_key_callbacks_),
857 QuitCurrentMessageLoop()));
858 else
859 EXPECT_CALL(*persistent_store_.get(), LoadCookiesForKey(key, testing::_))
860 .WillOnce(PushCallbackAction(&loaded_for_key_callbacks_));
861 } 843 }
862 844
863 // Invokes the initial action. 845 // Invokes the initial action.
864 MOCK_METHOD0(Begin, void(void)); 846 MOCK_METHOD0(Begin, void(void));
865 847
866 // Returns the CookieMonster instance under test. 848 // Returns the CookieMonster instance under test.
867 CookieMonster& cookie_monster() { return *cookie_monster_.get(); } 849 CookieMonster& cookie_monster() { return *cookie_monster_.get(); }
868 850
869 private: 851 private:
870 // Declares that mock expectations in this test suite are strictly ordered. 852 // Declares that mock expectations in this test suite are strictly ordered.
871 testing::InSequence in_sequence_; 853 testing::InSequence in_sequence_;
872 // Holds cookies to be returned from PersistentCookieStore::Load or 854 // Holds cookies to be returned from PersistentCookieStore::Load or
873 // PersistentCookieStore::LoadCookiesForKey. 855 // PersistentCookieStore::LoadCookiesForKey.
874 std::vector<CanonicalCookie*> loaded_cookies_; 856 std::vector<CanonicalCookie*> loaded_cookies_;
875 // Stores the callback passed from the CookieMonster to the 857 // Stores the callback passed from the CookieMonster to the
876 // PersistentCookieStore::Load 858 // PersistentCookieStore::Load
877 CookieMonster::PersistentCookieStore::LoadedCallback loaded_callback_; 859 CookieMonster::PersistentCookieStore::LoadedCallback loaded_callback_;
878 // Stores the callback passed from the CookieMonster to the 860 // Stores the callback passed from the CookieMonster to the
879 // PersistentCookieStore::LoadCookiesForKey 861 // PersistentCookieStore::LoadCookiesForKey
880 std::queue<CookieMonster::PersistentCookieStore::LoadedCallback> 862 std::queue<CookieMonster::PersistentCookieStore::LoadedCallback>
881 loaded_for_key_callbacks_; 863 loaded_for_key_callbacks_;
882 864 // base::RunLoop used to wait for PersistentCookieStore::Load to be called.
865 base::RunLoop load_run_loop_;
866 // Indicates whether ExpectLoadCall() has been called.
867 bool expect_load_called_;
883 // Stores the CookieMonster under test. 868 // Stores the CookieMonster under test.
884 scoped_refptr<CookieMonster> cookie_monster_; 869 scoped_refptr<CookieMonster> cookie_monster_;
885 // Stores the mock PersistentCookieStore. 870 // Stores the mock PersistentCookieStore.
886 scoped_refptr<NewMockPersistentCookieStore> persistent_store_; 871 scoped_refptr<NewMockPersistentCookieStore> persistent_store_;
887 }; 872 };
888 873
889 TEST_F(DeferredCookieTaskTest, DeferredGetCookies) { 874 TEST_F(DeferredCookieTaskTest, DeferredGetCookies) {
890 DeclareLoadedCookie(http_www_google_.host(), 875 DeclareLoadedCookie(http_www_google_.host(),
891 "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", 876 "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT",
892 Time::Now() + TimeDelta::FromDays(3)); 877 Time::Now() + TimeDelta::FromDays(3));
893 878
894 MockGetCookiesCallback get_cookies_callback; 879 MockGetCookiesCallback get_cookies_callback;
895 880
896 BeginWithForDomainKey( 881 BeginWithForDomainKey(
897 http_www_google_.domain(), 882 http_www_google_.domain(),
898 GetCookiesAction(&cookie_monster(), http_www_google_.url(), 883 GetCookiesAction(&cookie_monster(), http_www_google_.url(),
899 &get_cookies_callback)); 884 &get_cookies_callback));
900 885
901 WaitForLoadCall(); 886 WaitForLoadCall();
902 887
903 EXPECT_CALL(get_cookies_callback, Invoke("X=1")) 888 EXPECT_CALL(get_cookies_callback, Invoke("X=1"))
904 .WillOnce(GetCookiesAction(&cookie_monster(), http_www_google_.url(), 889 .WillOnce(GetCookiesAction(&cookie_monster(), http_www_google_.url(),
905 &get_cookies_callback)); 890 &get_cookies_callback));
906 EXPECT_CALL(get_cookies_callback, Invoke("X=1")) 891 base::RunLoop loop;
907 .WillOnce(QuitCurrentMessageLoop()); 892 EXPECT_CALL(get_cookies_callback, Invoke("X=1")).WillOnce(QuitRunLoop(&loop));
908 893
909 CompleteLoadingAndWait(); 894 CompleteLoading();
895 loop.Run();
910 } 896 }
911 897
912 TEST_F(DeferredCookieTaskTest, DeferredSetCookie) { 898 TEST_F(DeferredCookieTaskTest, DeferredSetCookie) {
913 MockSetCookiesCallback set_cookies_callback; 899 MockSetCookiesCallback set_cookies_callback;
914 900
915 BeginWithForDomainKey( 901 BeginWithForDomainKey(
916 http_www_google_.domain(), 902 http_www_google_.domain(),
917 SetCookieAction(&cookie_monster(), http_www_google_.url(), "A=B", 903 SetCookieAction(&cookie_monster(), http_www_google_.url(), "A=B",
918 &set_cookies_callback)); 904 &set_cookies_callback));
919 905
920 WaitForLoadCall(); 906 WaitForLoadCall();
921 907
922 EXPECT_CALL(set_cookies_callback, Invoke(true)) 908 EXPECT_CALL(set_cookies_callback, Invoke(true))
923 .WillOnce(SetCookieAction(&cookie_monster(), http_www_google_.url(), 909 .WillOnce(SetCookieAction(&cookie_monster(), http_www_google_.url(),
924 "X=Y", &set_cookies_callback)); 910 "X=Y", &set_cookies_callback));
925 EXPECT_CALL(set_cookies_callback, Invoke(true)) 911 base::RunLoop loop;
926 .WillOnce(QuitCurrentMessageLoop()); 912 EXPECT_CALL(set_cookies_callback, Invoke(true)).WillOnce(QuitRunLoop(&loop));
927 913
928 CompleteLoadingAndWait(); 914 CompleteLoading();
915 loop.Run();
929 } 916 }
930 917
931 TEST_F(DeferredCookieTaskTest, DeferredSetAllCookies) { 918 TEST_F(DeferredCookieTaskTest, DeferredSetAllCookies) {
932 MockSetCookiesCallback set_cookies_callback; 919 MockSetCookiesCallback set_cookies_callback;
933 CookieList list; 920 CookieList list;
934 list.push_back(CanonicalCookie(http_www_google_.url(), "A", "B", 921 list.push_back(CanonicalCookie(http_www_google_.url(), "A", "B",
935 http_www_google_.domain(), "/", 922 http_www_google_.domain(), "/",
936 base::Time::Now(), base::Time(), base::Time(), 923 base::Time::Now(), base::Time(), base::Time(),
937 false, true, false, COOKIE_PRIORITY_DEFAULT)); 924 false, true, false, COOKIE_PRIORITY_DEFAULT));
938 list.push_back(CanonicalCookie(http_www_google_.url(), "C", "D", 925 list.push_back(CanonicalCookie(http_www_google_.url(), "C", "D",
939 http_www_google_.domain(), "/", 926 http_www_google_.domain(), "/",
940 base::Time::Now(), base::Time(), base::Time(), 927 base::Time::Now(), base::Time(), base::Time(),
941 false, true, false, COOKIE_PRIORITY_DEFAULT)); 928 false, true, false, COOKIE_PRIORITY_DEFAULT));
942 929
943 BeginWith( 930 BeginWith(
944 SetAllCookiesAction(&cookie_monster(), list, &set_cookies_callback)); 931 SetAllCookiesAction(&cookie_monster(), list, &set_cookies_callback));
945 932
946 WaitForLoadCall(); 933 WaitForLoadCall();
947 934
948 EXPECT_CALL(set_cookies_callback, Invoke(true)) 935 EXPECT_CALL(set_cookies_callback, Invoke(true))
949 .WillOnce( 936 .WillOnce(
950 SetAllCookiesAction(&cookie_monster(), list, &set_cookies_callback)); 937 SetAllCookiesAction(&cookie_monster(), list, &set_cookies_callback));
951 EXPECT_CALL(set_cookies_callback, Invoke(true)) 938 base::RunLoop loop;
952 .WillOnce(QuitCurrentMessageLoop()); 939 EXPECT_CALL(set_cookies_callback, Invoke(true)).WillOnce(QuitRunLoop(&loop));
953 940
954 CompleteLoadingAndWait(); 941 CompleteLoading();
942 loop.Run();
955 } 943 }
956 944
957 TEST_F(DeferredCookieTaskTest, DeferredDeleteCookie) { 945 TEST_F(DeferredCookieTaskTest, DeferredDeleteCookie) {
958 MockClosure delete_cookie_callback; 946 MockClosure delete_cookie_callback;
959 947
960 BeginWithForDomainKey( 948 BeginWithForDomainKey(
961 http_www_google_.domain(), 949 http_www_google_.domain(),
962 DeleteCookieAction(&cookie_monster(), http_www_google_.url(), "A", 950 DeleteCookieAction(&cookie_monster(), http_www_google_.url(), "A",
963 &delete_cookie_callback)); 951 &delete_cookie_callback));
964 952
965 WaitForLoadCall(); 953 WaitForLoadCall();
966 954
967 EXPECT_CALL(delete_cookie_callback, Invoke()) 955 EXPECT_CALL(delete_cookie_callback, Invoke())
968 .WillOnce(DeleteCookieAction(&cookie_monster(), http_www_google_.url(), 956 .WillOnce(DeleteCookieAction(&cookie_monster(), http_www_google_.url(),
969 "X", &delete_cookie_callback)); 957 "X", &delete_cookie_callback));
970 EXPECT_CALL(delete_cookie_callback, Invoke()) 958 base::RunLoop loop;
971 .WillOnce(QuitCurrentMessageLoop()); 959 EXPECT_CALL(delete_cookie_callback, Invoke()).WillOnce(QuitRunLoop(&loop));
972 960
973 CompleteLoadingAndWait(); 961 CompleteLoading();
962 loop.Run();
974 } 963 }
975 964
976 TEST_F(DeferredCookieTaskTest, DeferredSetCookieWithDetails) { 965 TEST_F(DeferredCookieTaskTest, DeferredSetCookieWithDetails) {
977 MockSetCookiesCallback set_cookies_callback; 966 MockSetCookiesCallback set_cookies_callback;
978 967
979 CookiesInputInfo cookie_info = {www_google_foo_.url(), 968 CookiesInputInfo cookie_info = {www_google_foo_.url(),
980 "A", 969 "A",
981 "B", 970 "B",
982 std::string(), 971 std::string(),
983 "/foo", 972 "/foo",
(...skipping 15 matching lines...) Expand all
999 std::string(), 988 std::string(),
1000 "/foo", 989 "/foo",
1001 base::Time(), 990 base::Time(),
1002 false, 991 false,
1003 false, 992 false,
1004 false, 993 false,
1005 COOKIE_PRIORITY_DEFAULT}; 994 COOKIE_PRIORITY_DEFAULT};
1006 EXPECT_CALL(set_cookies_callback, Invoke(true)) 995 EXPECT_CALL(set_cookies_callback, Invoke(true))
1007 .WillOnce(SetCookieWithDetailsAction(&cookie_monster(), cookie_info_exp, 996 .WillOnce(SetCookieWithDetailsAction(&cookie_monster(), cookie_info_exp,
1008 &set_cookies_callback)); 997 &set_cookies_callback));
1009 EXPECT_CALL(set_cookies_callback, Invoke(true)) 998 base::RunLoop loop;
1010 .WillOnce(QuitCurrentMessageLoop()); 999 EXPECT_CALL(set_cookies_callback, Invoke(true)).WillOnce(QuitRunLoop(&loop));
1011 1000
1012 CompleteLoadingAndWait(); 1001 CompleteLoading();
1002 loop.Run();
1013 } 1003 }
1014 1004
1015 TEST_F(DeferredCookieTaskTest, DeferredGetAllCookies) { 1005 TEST_F(DeferredCookieTaskTest, DeferredGetAllCookies) {
1016 DeclareLoadedCookie(http_www_google_.host(), 1006 DeclareLoadedCookie(http_www_google_.host(),
1017 "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", 1007 "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT",
1018 Time::Now() + TimeDelta::FromDays(3)); 1008 Time::Now() + TimeDelta::FromDays(3));
1019 1009
1020 MockGetCookieListCallback get_cookie_list_callback; 1010 MockGetCookieListCallback get_cookie_list_callback;
1021 1011
1022 BeginWith(GetAllCookiesAction(&cookie_monster(), &get_cookie_list_callback)); 1012 BeginWith(GetAllCookiesAction(&cookie_monster(), &get_cookie_list_callback));
1023 1013
1024 WaitForLoadCall(); 1014 WaitForLoadCall();
1025 1015
1026 EXPECT_CALL(get_cookie_list_callback, Invoke(testing::_)) 1016 EXPECT_CALL(get_cookie_list_callback, Invoke(testing::_))
1027 .WillOnce( 1017 .WillOnce(
1028 GetAllCookiesAction(&cookie_monster(), &get_cookie_list_callback)); 1018 GetAllCookiesAction(&cookie_monster(), &get_cookie_list_callback));
1019 base::RunLoop loop;
1029 EXPECT_CALL(get_cookie_list_callback, Invoke(testing::_)) 1020 EXPECT_CALL(get_cookie_list_callback, Invoke(testing::_))
1030 .WillOnce(QuitCurrentMessageLoop()); 1021 .WillOnce(QuitRunLoop(&loop));
1031 1022
1032 CompleteLoadingAndWait(); 1023 CompleteLoading();
1024 loop.Run();
1033 } 1025 }
1034 1026
1035 TEST_F(DeferredCookieTaskTest, DeferredGetAllForUrlCookies) { 1027 TEST_F(DeferredCookieTaskTest, DeferredGetAllForUrlCookies) {
1036 DeclareLoadedCookie(http_www_google_.host(), 1028 DeclareLoadedCookie(http_www_google_.host(),
1037 "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", 1029 "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT",
1038 Time::Now() + TimeDelta::FromDays(3)); 1030 Time::Now() + TimeDelta::FromDays(3));
1039 1031
1040 MockGetCookieListCallback get_cookie_list_callback; 1032 MockGetCookieListCallback get_cookie_list_callback;
1041 1033
1042 BeginWithForDomainKey( 1034 BeginWithForDomainKey(
1043 http_www_google_.domain(), 1035 http_www_google_.domain(),
1044 GetAllCookiesForUrlAction(&cookie_monster(), http_www_google_.url(), 1036 GetAllCookiesForUrlAction(&cookie_monster(), http_www_google_.url(),
1045 &get_cookie_list_callback)); 1037 &get_cookie_list_callback));
1046 1038
1047 WaitForLoadCall(); 1039 WaitForLoadCall();
1048 1040
1049 EXPECT_CALL(get_cookie_list_callback, Invoke(testing::_)) 1041 EXPECT_CALL(get_cookie_list_callback, Invoke(testing::_))
1050 .WillOnce(GetAllCookiesForUrlAction(&cookie_monster(), 1042 .WillOnce(GetAllCookiesForUrlAction(&cookie_monster(),
1051 http_www_google_.url(), 1043 http_www_google_.url(),
1052 &get_cookie_list_callback)); 1044 &get_cookie_list_callback));
1045 base::RunLoop loop;
1053 EXPECT_CALL(get_cookie_list_callback, Invoke(testing::_)) 1046 EXPECT_CALL(get_cookie_list_callback, Invoke(testing::_))
1054 .WillOnce(QuitCurrentMessageLoop()); 1047 .WillOnce(QuitRunLoop(&loop));
1055 1048
1056 CompleteLoadingAndWait(); 1049 CompleteLoading();
1050 loop.Run();
1057 } 1051 }
1058 1052
1059 TEST_F(DeferredCookieTaskTest, DeferredGetAllForUrlWithOptionsCookies) { 1053 TEST_F(DeferredCookieTaskTest, DeferredGetAllForUrlWithOptionsCookies) {
1060 DeclareLoadedCookie(http_www_google_.host(), 1054 DeclareLoadedCookie(http_www_google_.host(),
1061 "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", 1055 "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT",
1062 Time::Now() + TimeDelta::FromDays(3)); 1056 Time::Now() + TimeDelta::FromDays(3));
1063 1057
1064 MockGetCookieListCallback get_cookie_list_callback; 1058 MockGetCookieListCallback get_cookie_list_callback;
1065 1059
1066 BeginWithForDomainKey(http_www_google_.domain(), 1060 BeginWithForDomainKey(http_www_google_.domain(),
1067 GetAllCookiesForUrlWithOptionsAction( 1061 GetAllCookiesForUrlWithOptionsAction(
1068 &cookie_monster(), http_www_google_.url(), 1062 &cookie_monster(), http_www_google_.url(),
1069 &get_cookie_list_callback)); 1063 &get_cookie_list_callback));
1070 1064
1071 WaitForLoadCall(); 1065 WaitForLoadCall();
1072 1066
1073 EXPECT_CALL(get_cookie_list_callback, Invoke(testing::_)) 1067 EXPECT_CALL(get_cookie_list_callback, Invoke(testing::_))
1074 .WillOnce(GetAllCookiesForUrlWithOptionsAction( 1068 .WillOnce(GetAllCookiesForUrlWithOptionsAction(
1075 &cookie_monster(), http_www_google_.url(), 1069 &cookie_monster(), http_www_google_.url(),
1076 &get_cookie_list_callback)); 1070 &get_cookie_list_callback));
1071 base::RunLoop loop;
1077 EXPECT_CALL(get_cookie_list_callback, Invoke(testing::_)) 1072 EXPECT_CALL(get_cookie_list_callback, Invoke(testing::_))
1078 .WillOnce(QuitCurrentMessageLoop()); 1073 .WillOnce(QuitRunLoop(&loop));
1079 1074
1080 CompleteLoadingAndWait(); 1075 CompleteLoading();
1076 loop.Run();
1081 } 1077 }
1082 1078
1083 TEST_F(DeferredCookieTaskTest, DeferredDeleteAllCookies) { 1079 TEST_F(DeferredCookieTaskTest, DeferredDeleteAllCookies) {
1084 MockDeleteCallback delete_callback; 1080 MockDeleteCallback delete_callback;
1085 1081
1086 BeginWith(DeleteAllAction(&cookie_monster(), &delete_callback)); 1082 BeginWith(DeleteAllAction(&cookie_monster(), &delete_callback));
1087 1083
1088 WaitForLoadCall(); 1084 WaitForLoadCall();
1089 1085
1090 EXPECT_CALL(delete_callback, Invoke(false)) 1086 EXPECT_CALL(delete_callback, Invoke(false))
1091 .WillOnce(DeleteAllAction(&cookie_monster(), &delete_callback)); 1087 .WillOnce(DeleteAllAction(&cookie_monster(), &delete_callback));
1092 EXPECT_CALL(delete_callback, Invoke(false))
1093 .WillOnce(QuitCurrentMessageLoop());
1094 1088
1095 CompleteLoadingAndWait(); 1089 base::RunLoop loop;
1090 EXPECT_CALL(delete_callback, Invoke(false)).WillOnce(QuitRunLoop(&loop));
1091
1092 CompleteLoading();
1093 loop.Run();
1096 } 1094 }
1097 1095
1098 TEST_F(DeferredCookieTaskTest, DeferredDeleteAllCreatedBetweenCookies) { 1096 TEST_F(DeferredCookieTaskTest, DeferredDeleteAllCreatedBetweenCookies) {
1099 MockDeleteCallback delete_callback; 1097 MockDeleteCallback delete_callback;
1100 1098
1101 BeginWith(DeleteAllCreatedBetweenAction(&cookie_monster(), base::Time(), 1099 BeginWith(DeleteAllCreatedBetweenAction(&cookie_monster(), base::Time(),
1102 base::Time::Now(), &delete_callback)); 1100 base::Time::Now(), &delete_callback));
1103 1101
1104 WaitForLoadCall(); 1102 WaitForLoadCall();
1105 1103
1106 EXPECT_CALL(delete_callback, Invoke(false)) 1104 EXPECT_CALL(delete_callback, Invoke(false))
1107 .WillOnce(DeleteAllCreatedBetweenAction(&cookie_monster(), base::Time(), 1105 .WillOnce(DeleteAllCreatedBetweenAction(&cookie_monster(), base::Time(),
1108 base::Time::Now(), 1106 base::Time::Now(),
1109 &delete_callback)); 1107 &delete_callback));
1110 EXPECT_CALL(delete_callback, Invoke(false)) 1108 base::RunLoop loop;
1111 .WillOnce(QuitCurrentMessageLoop()); 1109 EXPECT_CALL(delete_callback, Invoke(false)).WillOnce(QuitRunLoop(&loop));
1112 1110
1113 CompleteLoadingAndWait(); 1111 CompleteLoading();
1112 loop.Run();
1114 } 1113 }
1115 1114
1116 TEST_F(DeferredCookieTaskTest, DeferredDeleteAllForHostCookies) { 1115 TEST_F(DeferredCookieTaskTest, DeferredDeleteAllForHostCookies) {
1117 MockDeleteCallback delete_callback; 1116 MockDeleteCallback delete_callback;
1118 1117
1119 BeginWithForDomainKey( 1118 BeginWithForDomainKey(
1120 http_www_google_.domain(), 1119 http_www_google_.domain(),
1121 DeleteAllForHostAction(&cookie_monster(), http_www_google_.url(), 1120 DeleteAllForHostAction(&cookie_monster(), http_www_google_.url(),
1122 &delete_callback)); 1121 &delete_callback));
1123 1122
1124 WaitForLoadCall(); 1123 WaitForLoadCall();
1125 1124
1126 EXPECT_CALL(delete_callback, Invoke(false)) 1125 EXPECT_CALL(delete_callback, Invoke(false))
1127 .WillOnce(DeleteAllForHostAction( 1126 .WillOnce(DeleteAllForHostAction(
1128 &cookie_monster(), http_www_google_.url(), &delete_callback)); 1127 &cookie_monster(), http_www_google_.url(), &delete_callback));
1129 EXPECT_CALL(delete_callback, Invoke(false)) 1128 base::RunLoop loop;
1130 .WillOnce(QuitCurrentMessageLoop()); 1129 EXPECT_CALL(delete_callback, Invoke(false)).WillOnce(QuitRunLoop(&loop));
1131 1130
1132 CompleteLoadingAndWait(); 1131 CompleteLoading();
1132 loop.Run();
1133 } 1133 }
1134 1134
1135 TEST_F(DeferredCookieTaskTest, DeferredDeleteCanonicalCookie) { 1135 TEST_F(DeferredCookieTaskTest, DeferredDeleteCanonicalCookie) {
1136 std::vector<CanonicalCookie*> cookies; 1136 std::vector<CanonicalCookie*> cookies;
1137 CanonicalCookie cookie = BuildCanonicalCookie( 1137 CanonicalCookie cookie = BuildCanonicalCookie(
1138 http_www_google_.host(), "X=1; path=/", base::Time::Now()); 1138 http_www_google_.host(), "X=1; path=/", base::Time::Now());
1139 1139
1140 MockDeleteCookieCallback delete_cookie_callback; 1140 MockDeleteCookieCallback delete_cookie_callback;
1141 1141
1142 BeginWith(DeleteCanonicalCookieAction(&cookie_monster(), cookie, 1142 BeginWith(DeleteCanonicalCookieAction(&cookie_monster(), cookie,
1143 &delete_cookie_callback)); 1143 &delete_cookie_callback));
1144 1144
1145 WaitForLoadCall(); 1145 WaitForLoadCall();
1146 1146
1147 EXPECT_CALL(delete_cookie_callback, Invoke(false)) 1147 EXPECT_CALL(delete_cookie_callback, Invoke(false))
1148 .WillOnce(DeleteCanonicalCookieAction(&cookie_monster(), cookie, 1148 .WillOnce(DeleteCanonicalCookieAction(&cookie_monster(), cookie,
1149 &delete_cookie_callback)); 1149 &delete_cookie_callback));
1150 base::RunLoop loop;
1150 EXPECT_CALL(delete_cookie_callback, Invoke(false)) 1151 EXPECT_CALL(delete_cookie_callback, Invoke(false))
1151 .WillOnce(QuitCurrentMessageLoop()); 1152 .WillOnce(QuitRunLoop(&loop));
1152 1153
1153 CompleteLoadingAndWait(); 1154 CompleteLoading();
1155 loop.Run();
1154 } 1156 }
1155 1157
1156 TEST_F(DeferredCookieTaskTest, DeferredDeleteSessionCookies) { 1158 TEST_F(DeferredCookieTaskTest, DeferredDeleteSessionCookies) {
1157 MockDeleteCallback delete_callback; 1159 MockDeleteCallback delete_callback;
1158 1160
1159 BeginWith(DeleteSessionCookiesAction(&cookie_monster(), &delete_callback)); 1161 BeginWith(DeleteSessionCookiesAction(&cookie_monster(), &delete_callback));
1160 1162
1161 WaitForLoadCall(); 1163 WaitForLoadCall();
1162 1164
1163 EXPECT_CALL(delete_callback, Invoke(false)) 1165 EXPECT_CALL(delete_callback, Invoke(false))
1164 .WillOnce( 1166 .WillOnce(
1165 DeleteSessionCookiesAction(&cookie_monster(), &delete_callback)); 1167 DeleteSessionCookiesAction(&cookie_monster(), &delete_callback));
1166 EXPECT_CALL(delete_callback, Invoke(false)) 1168 base::RunLoop loop;
1167 .WillOnce(QuitCurrentMessageLoop()); 1169 EXPECT_CALL(delete_callback, Invoke(false)).WillOnce(QuitRunLoop(&loop));
1168 1170
1169 CompleteLoadingAndWait(); 1171 CompleteLoading();
1172 loop.Run();
1170 } 1173 }
1171 1174
1172 // Verify that a series of queued tasks are executed in order upon loading of 1175 // Verify that a series of queued tasks are executed in order upon loading of
1173 // the backing store and that new tasks received while the queued tasks are 1176 // the backing store and that new tasks received while the queued tasks are
1174 // being dispatched go to the end of the queue. 1177 // being dispatched go to the end of the queue.
1175 TEST_F(DeferredCookieTaskTest, DeferredTaskOrder) { 1178 TEST_F(DeferredCookieTaskTest, DeferredTaskOrder) {
1176 DeclareLoadedCookie(http_www_google_.host(), 1179 DeclareLoadedCookie(http_www_google_.host(),
1177 "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", 1180 "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT",
1178 Time::Now() + TimeDelta::FromDays(3)); 1181 Time::Now() + TimeDelta::FromDays(3));
1179 1182
1180 MockGetCookiesCallback get_cookies_callback; 1183 MockGetCookiesCallback get_cookies_callback;
1181 MockSetCookiesCallback set_cookies_callback; 1184 MockSetCookiesCallback set_cookies_callback;
1182 MockGetCookiesCallback get_cookies_callback_deferred; 1185 MockGetCookiesCallback get_cookies_callback_deferred;
1183 1186
1184 EXPECT_CALL(*this, Begin()) 1187 EXPECT_CALL(*this, Begin())
1185 .WillOnce(testing::DoAll( 1188 .WillOnce(testing::DoAll(
1186 GetCookiesAction(&cookie_monster(), http_www_google_.url(), 1189 GetCookiesAction(&cookie_monster(), http_www_google_.url(),
1187 &get_cookies_callback), 1190 &get_cookies_callback),
1188 SetCookieAction(&cookie_monster(), http_www_google_.url(), "A=B", 1191 SetCookieAction(&cookie_monster(), http_www_google_.url(), "A=B",
1189 &set_cookies_callback))); 1192 &set_cookies_callback)));
1190 ExpectLoadCall(); 1193 ExpectLoadCall();
1191 ExpectLoadForKeyCall(http_www_google_.domain(), false); 1194 ExpectLoadForKeyCall(http_www_google_.domain());
1192 Begin(); 1195 Begin();
1193 1196
1194 WaitForLoadCall(); 1197 WaitForLoadCall();
1195 EXPECT_CALL(get_cookies_callback, Invoke("X=1")) 1198 EXPECT_CALL(get_cookies_callback, Invoke("X=1"))
1196 .WillOnce(GetCookiesAction(&cookie_monster(), http_www_google_.url(), 1199 .WillOnce(GetCookiesAction(&cookie_monster(), http_www_google_.url(),
1197 &get_cookies_callback_deferred)); 1200 &get_cookies_callback_deferred));
1198 EXPECT_CALL(set_cookies_callback, Invoke(true)); 1201 EXPECT_CALL(set_cookies_callback, Invoke(true));
1202 base::RunLoop loop;
1199 EXPECT_CALL(get_cookies_callback_deferred, Invoke("A=B; X=1")) 1203 EXPECT_CALL(get_cookies_callback_deferred, Invoke("A=B; X=1"))
1200 .WillOnce(QuitCurrentMessageLoop()); 1204 .WillOnce(QuitRunLoop(&loop));
1201 1205
1202 CompleteLoadingAndWait(); 1206 CompleteLoading();
1207 loop.Run();
1203 } 1208 }
1204 1209
1205 TEST_F(CookieMonsterTest, TestCookieDeleteAll) { 1210 TEST_F(CookieMonsterTest, TestCookieDeleteAll) {
1206 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); 1211 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore);
1207 scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL)); 1212 scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL));
1208 CookieOptions options; 1213 CookieOptions options;
1209 options.set_include_httponly(); 1214 options.set_include_httponly();
1210 1215
1211 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), kValidCookieLine)); 1216 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), kValidCookieLine));
1212 EXPECT_EQ("A=B", GetCookies(cm.get(), http_www_google_.url())); 1217 EXPECT_EQ("A=B", GetCookies(cm.get(), http_www_google_.url()));
(...skipping 1371 matching lines...) Expand 10 before | Expand all | Expand 10 after
2584 ResultSavingCookieCallback<bool>* callback) { 2589 ResultSavingCookieCallback<bool>* callback) {
2585 cm->DeleteCanonicalCookieAsync( 2590 cm->DeleteCanonicalCookieAsync(
2586 cookie, base::Bind(&ResultSavingCookieCallback<bool>::Run, 2591 cookie, base::Bind(&ResultSavingCookieCallback<bool>::Run,
2587 base::Unretained(callback))); 2592 base::Unretained(callback)));
2588 } 2593 }
2589 2594
2590 protected: 2595 protected:
2591 void RunOnOtherThread(const base::Closure& task) { 2596 void RunOnOtherThread(const base::Closure& task) {
2592 other_thread_.Start(); 2597 other_thread_.Start();
2593 other_thread_.task_runner()->PostTask(FROM_HERE, task); 2598 other_thread_.task_runner()->PostTask(FROM_HERE, task);
2594 RunFor(kTimeout);
2595 other_thread_.Stop(); 2599 other_thread_.Stop();
2596 } 2600 }
2597 2601
2598 Thread other_thread_; 2602 Thread other_thread_;
2599 }; 2603 };
2600 2604
2601 } // namespace 2605 } // namespace
2602 2606
2603 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckGetAllCookies) { 2607 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckGetAllCookies) {
2604 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); 2608 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
2605 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=B")); 2609 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=B"));
2606 CookieList cookies = GetAllCookies(cm.get()); 2610 CookieList cookies = GetAllCookies(cm.get());
2607 CookieList::const_iterator it = cookies.begin(); 2611 CookieList::const_iterator it = cookies.begin();
2608 ASSERT_TRUE(it != cookies.end()); 2612 ASSERT_TRUE(it != cookies.end());
2609 EXPECT_EQ(http_www_google_.host(), it->Domain()); 2613 EXPECT_EQ(http_www_google_.host(), it->Domain());
2610 EXPECT_EQ("A", it->Name()); 2614 EXPECT_EQ("A", it->Name());
2611 ASSERT_TRUE(++it == cookies.end()); 2615 ASSERT_TRUE(++it == cookies.end());
2612 GetCookieListCallback callback(&other_thread_); 2616 GetCookieListCallback callback(&other_thread_);
2613 base::Closure task = 2617 base::Closure task =
2614 base::Bind(&MultiThreadedCookieMonsterTest::GetAllCookiesTask, 2618 base::Bind(&MultiThreadedCookieMonsterTest::GetAllCookiesTask,
2615 base::Unretained(this), cm, &callback); 2619 base::Unretained(this), cm, &callback);
2616 RunOnOtherThread(task); 2620 RunOnOtherThread(task);
2617 EXPECT_TRUE(callback.did_run()); 2621 callback.WaitUntilDone();
2618 it = callback.cookies().begin(); 2622 it = callback.cookies().begin();
2619 ASSERT_TRUE(it != callback.cookies().end()); 2623 ASSERT_TRUE(it != callback.cookies().end());
2620 EXPECT_EQ(http_www_google_.host(), it->Domain()); 2624 EXPECT_EQ(http_www_google_.host(), it->Domain());
2621 EXPECT_EQ("A", it->Name()); 2625 EXPECT_EQ("A", it->Name());
2622 ASSERT_TRUE(++it == callback.cookies().end()); 2626 ASSERT_TRUE(++it == callback.cookies().end());
2623 } 2627 }
2624 2628
2625 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckGetAllCookiesForURL) { 2629 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckGetAllCookiesForURL) {
2626 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); 2630 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
2627 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=B")); 2631 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=B"));
2628 CookieList cookies = GetAllCookiesForURL(cm.get(), http_www_google_.url()); 2632 CookieList cookies = GetAllCookiesForURL(cm.get(), http_www_google_.url());
2629 CookieList::const_iterator it = cookies.begin(); 2633 CookieList::const_iterator it = cookies.begin();
2630 ASSERT_TRUE(it != cookies.end()); 2634 ASSERT_TRUE(it != cookies.end());
2631 EXPECT_EQ(http_www_google_.host(), it->Domain()); 2635 EXPECT_EQ(http_www_google_.host(), it->Domain());
2632 EXPECT_EQ("A", it->Name()); 2636 EXPECT_EQ("A", it->Name());
2633 ASSERT_TRUE(++it == cookies.end()); 2637 ASSERT_TRUE(++it == cookies.end());
2634 GetCookieListCallback callback(&other_thread_); 2638 GetCookieListCallback callback(&other_thread_);
2635 base::Closure task = 2639 base::Closure task =
2636 base::Bind(&MultiThreadedCookieMonsterTest::GetAllCookiesForURLTask, 2640 base::Bind(&MultiThreadedCookieMonsterTest::GetAllCookiesForURLTask,
2637 base::Unretained(this), cm, http_www_google_.url(), &callback); 2641 base::Unretained(this), cm, http_www_google_.url(), &callback);
2638 RunOnOtherThread(task); 2642 RunOnOtherThread(task);
2639 EXPECT_TRUE(callback.did_run()); 2643 callback.WaitUntilDone();
2640 it = callback.cookies().begin(); 2644 it = callback.cookies().begin();
2641 ASSERT_TRUE(it != callback.cookies().end()); 2645 ASSERT_TRUE(it != callback.cookies().end());
2642 EXPECT_EQ(http_www_google_.host(), it->Domain()); 2646 EXPECT_EQ(http_www_google_.host(), it->Domain());
2643 EXPECT_EQ("A", it->Name()); 2647 EXPECT_EQ("A", it->Name());
2644 ASSERT_TRUE(++it == callback.cookies().end()); 2648 ASSERT_TRUE(++it == callback.cookies().end());
2645 } 2649 }
2646 2650
2647 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckGetAllCookiesForURLWithOpt) { 2651 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckGetAllCookiesForURLWithOpt) {
2648 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); 2652 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
2649 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=B")); 2653 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=B"));
2650 CookieOptions options; 2654 CookieOptions options;
2651 CookieList cookies = 2655 CookieList cookies =
2652 GetAllCookiesForURLWithOptions(cm.get(), http_www_google_.url(), options); 2656 GetAllCookiesForURLWithOptions(cm.get(), http_www_google_.url(), options);
2653 CookieList::const_iterator it = cookies.begin(); 2657 CookieList::const_iterator it = cookies.begin();
2654 ASSERT_TRUE(it != cookies.end()); 2658 ASSERT_TRUE(it != cookies.end());
2655 EXPECT_EQ(http_www_google_.host(), it->Domain()); 2659 EXPECT_EQ(http_www_google_.host(), it->Domain());
2656 EXPECT_EQ("A", it->Name()); 2660 EXPECT_EQ("A", it->Name());
2657 ASSERT_TRUE(++it == cookies.end()); 2661 ASSERT_TRUE(++it == cookies.end());
2658 GetCookieListCallback callback(&other_thread_); 2662 GetCookieListCallback callback(&other_thread_);
2659 base::Closure task = base::Bind( 2663 base::Closure task = base::Bind(
2660 &MultiThreadedCookieMonsterTest::GetAllCookiesForURLWithOptionsTask, 2664 &MultiThreadedCookieMonsterTest::GetAllCookiesForURLWithOptionsTask,
2661 base::Unretained(this), cm, http_www_google_.url(), options, &callback); 2665 base::Unretained(this), cm, http_www_google_.url(), options, &callback);
2662 RunOnOtherThread(task); 2666 RunOnOtherThread(task);
2663 EXPECT_TRUE(callback.did_run()); 2667 callback.WaitUntilDone();
2664 it = callback.cookies().begin(); 2668 it = callback.cookies().begin();
2665 ASSERT_TRUE(it != callback.cookies().end()); 2669 ASSERT_TRUE(it != callback.cookies().end());
2666 EXPECT_EQ(http_www_google_.host(), it->Domain()); 2670 EXPECT_EQ(http_www_google_.host(), it->Domain());
2667 EXPECT_EQ("A", it->Name()); 2671 EXPECT_EQ("A", it->Name());
2668 ASSERT_TRUE(++it == callback.cookies().end()); 2672 ASSERT_TRUE(++it == callback.cookies().end());
2669 } 2673 }
2670 2674
2671 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckSetCookieWithDetails) { 2675 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckSetCookieWithDetails) {
2672 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); 2676 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
2673 EXPECT_TRUE(SetCookieWithDetails(cm.get(), www_google_foo_.url(), "A", "B", 2677 EXPECT_TRUE(SetCookieWithDetails(cm.get(), www_google_foo_.url(), "A", "B",
2674 std::string(), "/foo", base::Time(), false, 2678 std::string(), "/foo", base::Time(), false,
2675 false, false, COOKIE_PRIORITY_DEFAULT)); 2679 false, false, COOKIE_PRIORITY_DEFAULT));
2676 ResultSavingCookieCallback<bool> callback(&other_thread_); 2680 ResultSavingCookieCallback<bool> callback(&other_thread_);
2677 base::Closure task = 2681 base::Closure task =
2678 base::Bind(&MultiThreadedCookieMonsterTest::SetCookieWithDetailsTask, 2682 base::Bind(&MultiThreadedCookieMonsterTest::SetCookieWithDetailsTask,
2679 base::Unretained(this), cm, www_google_foo_.url(), &callback); 2683 base::Unretained(this), cm, www_google_foo_.url(), &callback);
2680 RunOnOtherThread(task); 2684 RunOnOtherThread(task);
2681 EXPECT_TRUE(callback.did_run()); 2685 callback.WaitUntilDone();
2682 EXPECT_TRUE(callback.result()); 2686 EXPECT_TRUE(callback.result());
2683 } 2687 }
2684 2688
2685 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckDeleteAllCreatedBetween) { 2689 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckDeleteAllCreatedBetween) {
2686 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); 2690 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
2687 CookieOptions options; 2691 CookieOptions options;
2688 Time now = Time::Now(); 2692 Time now = Time::Now();
2689 EXPECT_TRUE( 2693 EXPECT_TRUE(
2690 SetCookieWithOptions(cm.get(), http_www_google_.url(), "A=B", options)); 2694 SetCookieWithOptions(cm.get(), http_www_google_.url(), "A=B", options));
2691 EXPECT_EQ(1, DeleteAllCreatedBetween(cm.get(), now - TimeDelta::FromDays(99), 2695 EXPECT_EQ(1, DeleteAllCreatedBetween(cm.get(), now - TimeDelta::FromDays(99),
2692 Time())); 2696 Time()));
2693 EXPECT_TRUE( 2697 EXPECT_TRUE(
2694 SetCookieWithOptions(cm.get(), http_www_google_.url(), "A=B", options)); 2698 SetCookieWithOptions(cm.get(), http_www_google_.url(), "A=B", options));
2695 ResultSavingCookieCallback<int> callback(&other_thread_); 2699 ResultSavingCookieCallback<int> callback(&other_thread_);
2696 base::Closure task = 2700 base::Closure task =
2697 base::Bind(&MultiThreadedCookieMonsterTest::DeleteAllCreatedBetweenTask, 2701 base::Bind(&MultiThreadedCookieMonsterTest::DeleteAllCreatedBetweenTask,
2698 base::Unretained(this), cm, now - TimeDelta::FromDays(99), 2702 base::Unretained(this), cm, now - TimeDelta::FromDays(99),
2699 Time(), &callback); 2703 Time(), &callback);
2700 RunOnOtherThread(task); 2704 RunOnOtherThread(task);
2701 EXPECT_TRUE(callback.did_run()); 2705 callback.WaitUntilDone();
2702 EXPECT_EQ(1, callback.result()); 2706 EXPECT_EQ(1, callback.result());
2703 } 2707 }
2704 2708
2705 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckDeleteAllForHost) { 2709 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckDeleteAllForHost) {
2706 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); 2710 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
2707 CookieOptions options; 2711 CookieOptions options;
2708 EXPECT_TRUE( 2712 EXPECT_TRUE(
2709 SetCookieWithOptions(cm.get(), http_www_google_.url(), "A=B", options)); 2713 SetCookieWithOptions(cm.get(), http_www_google_.url(), "A=B", options));
2710 EXPECT_EQ(1, DeleteAllForHost(cm.get(), http_www_google_.url())); 2714 EXPECT_EQ(1, DeleteAllForHost(cm.get(), http_www_google_.url()));
2711 EXPECT_TRUE( 2715 EXPECT_TRUE(
2712 SetCookieWithOptions(cm.get(), http_www_google_.url(), "A=B", options)); 2716 SetCookieWithOptions(cm.get(), http_www_google_.url(), "A=B", options));
2713 ResultSavingCookieCallback<int> callback(&other_thread_); 2717 ResultSavingCookieCallback<int> callback(&other_thread_);
2714 base::Closure task = 2718 base::Closure task =
2715 base::Bind(&MultiThreadedCookieMonsterTest::DeleteAllForHostTask, 2719 base::Bind(&MultiThreadedCookieMonsterTest::DeleteAllForHostTask,
2716 base::Unretained(this), cm, http_www_google_.url(), &callback); 2720 base::Unretained(this), cm, http_www_google_.url(), &callback);
2717 RunOnOtherThread(task); 2721 RunOnOtherThread(task);
2718 EXPECT_TRUE(callback.did_run()); 2722 callback.WaitUntilDone();
2719 EXPECT_EQ(1, callback.result()); 2723 EXPECT_EQ(1, callback.result());
2720 } 2724 }
2721 2725
2722 TEST_F(MultiThreadedCookieMonsterTest, 2726 TEST_F(MultiThreadedCookieMonsterTest,
2723 ThreadCheckDeleteAllCreatedBetweenForHost) { 2727 ThreadCheckDeleteAllCreatedBetweenForHost) {
2724 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); 2728 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
2725 GURL url_not_google("http://www.notgoogle.com"); 2729 GURL url_not_google("http://www.notgoogle.com");
2726 2730
2727 CookieOptions options; 2731 CookieOptions options;
2728 Time now = Time::Now(); 2732 Time now = Time::Now();
(...skipping 26 matching lines...) Expand all
2755 EXPECT_TRUE( 2759 EXPECT_TRUE(
2756 SetCookieWithOptions(cm.get(), http_www_google_.url(), "A=B", options)); 2760 SetCookieWithOptions(cm.get(), http_www_google_.url(), "A=B", options));
2757 ResultSavingCookieCallback<int> callback(&other_thread_); 2761 ResultSavingCookieCallback<int> callback(&other_thread_);
2758 2762
2759 // 2. Second set of deletions. 2763 // 2. Second set of deletions.
2760 base::Closure task = base::Bind( 2764 base::Closure task = base::Bind(
2761 &MultiThreadedCookieMonsterTest::DeleteAllCreatedBetweenForHostTask, 2765 &MultiThreadedCookieMonsterTest::DeleteAllCreatedBetweenForHostTask,
2762 base::Unretained(this), cm, ago1, Time(), http_www_google_.url(), 2766 base::Unretained(this), cm, ago1, Time(), http_www_google_.url(),
2763 &callback); 2767 &callback);
2764 RunOnOtherThread(task); 2768 RunOnOtherThread(task);
2765 EXPECT_TRUE(callback.did_run()); 2769 callback.WaitUntilDone();
2766 EXPECT_EQ(2, callback.result()); // Deletes A=B, G=H. 2770 EXPECT_EQ(2, callback.result()); // Deletes A=B, G=H.
2767 } 2771 }
2768 2772
2769 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckDeleteCanonicalCookie) { 2773 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckDeleteCanonicalCookie) {
2770 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); 2774 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
2771 CookieOptions options; 2775 CookieOptions options;
2772 EXPECT_TRUE( 2776 EXPECT_TRUE(
2773 SetCookieWithOptions(cm.get(), http_www_google_.url(), "A=B", options)); 2777 SetCookieWithOptions(cm.get(), http_www_google_.url(), "A=B", options));
2774 CookieList cookies = GetAllCookies(cm.get()); 2778 CookieList cookies = GetAllCookies(cm.get());
2775 CookieList::iterator it = cookies.begin(); 2779 CookieList::iterator it = cookies.begin();
2776 EXPECT_TRUE(DeleteCanonicalCookie(cm.get(), *it)); 2780 EXPECT_TRUE(DeleteCanonicalCookie(cm.get(), *it));
2777 2781
2778 EXPECT_TRUE( 2782 EXPECT_TRUE(
2779 SetCookieWithOptions(cm.get(), http_www_google_.url(), "A=B", options)); 2783 SetCookieWithOptions(cm.get(), http_www_google_.url(), "A=B", options));
2780 ResultSavingCookieCallback<bool> callback(&other_thread_); 2784 ResultSavingCookieCallback<bool> callback(&other_thread_);
2781 cookies = GetAllCookies(cm.get()); 2785 cookies = GetAllCookies(cm.get());
2782 it = cookies.begin(); 2786 it = cookies.begin();
2783 base::Closure task = 2787 base::Closure task =
2784 base::Bind(&MultiThreadedCookieMonsterTest::DeleteCanonicalCookieTask, 2788 base::Bind(&MultiThreadedCookieMonsterTest::DeleteCanonicalCookieTask,
2785 base::Unretained(this), cm, *it, &callback); 2789 base::Unretained(this), cm, *it, &callback);
2786 RunOnOtherThread(task); 2790 RunOnOtherThread(task);
2787 EXPECT_TRUE(callback.did_run()); 2791 callback.WaitUntilDone();
2788 EXPECT_TRUE(callback.result()); 2792 EXPECT_TRUE(callback.result());
2789 } 2793 }
2790 2794
2791 // Ensure that cookies for http, https, ws, and wss all share the same storage 2795 // Ensure that cookies for http, https, ws, and wss all share the same storage
2792 // and policies when GetAllCookiesForURLAsync is used. This test is part of 2796 // and policies when GetAllCookiesForURLAsync is used. This test is part of
2793 // MultiThreadedCookieMonsterTest in order to test and use 2797 // MultiThreadedCookieMonsterTest in order to test and use
2794 // GetAllCookiesForURLAsync, but it does not use any additional threads. 2798 // GetAllCookiesForURLAsync, but it does not use any additional threads.
2795 TEST_F(MultiThreadedCookieMonsterTest, GetAllCookiesForURLEffectiveDomain) { 2799 TEST_F(MultiThreadedCookieMonsterTest, GetAllCookiesForURLEffectiveDomain) {
2796 scoped_ptr<CanonicalCookie> cookie(CanonicalCookie::Create( 2800 scoped_ptr<CanonicalCookie> cookie(CanonicalCookie::Create(
2797 http_www_google_.url(), kValidCookieLine, Time::Now(), CookieOptions())); 2801 http_www_google_.url(), kValidCookieLine, Time::Now(), CookieOptions()));
(...skipping 17 matching lines...) Expand all
2815 EXPECT_CALL(checkpoint, Call(1)); 2819 EXPECT_CALL(checkpoint, Call(1));
2816 // LoadCookiesForKey will never be called after checkpoint.Call(1) although 2820 // LoadCookiesForKey will never be called after checkpoint.Call(1) although
2817 // we will call GetAllCookiesForURLAsync again, because all URLs below share 2821 // we will call GetAllCookiesForURLAsync again, because all URLs below share
2818 // the same key. 2822 // the same key.
2819 EXPECT_CALL(*store, LoadCookiesForKey(::testing::_, ::testing::_)).Times(0); 2823 EXPECT_CALL(*store, LoadCookiesForKey(::testing::_, ::testing::_)).Times(0);
2820 2824
2821 GetCookieListCallback callback; 2825 GetCookieListCallback callback;
2822 checkpoint.Call(0); 2826 checkpoint.Call(0);
2823 GetAllCookiesForURLTask(cm.get(), http_www_google_.url(), &callback); 2827 GetAllCookiesForURLTask(cm.get(), http_www_google_.url(), &callback);
2824 checkpoint.Call(1); 2828 checkpoint.Call(1);
2825 ASSERT_FALSE(callback.did_run());
2826 // Pass the cookies to the CookieMonster. 2829 // Pass the cookies to the CookieMonster.
2827 loaded_callback.Run(cookies); 2830 loaded_callback.Run(cookies);
2828 // Now GetAllCookiesForURLTask is done. 2831 // Now GetAllCookiesForURLTask is done.
2829 ASSERT_TRUE(callback.did_run()); 2832 callback.WaitUntilDone();
2830 // See that the callback was called with the cookies. 2833 // See that the callback was called with the cookies.
2831 ASSERT_EQ(1u, callback.cookies().size()); 2834 ASSERT_EQ(1u, callback.cookies().size());
2832 EXPECT_TRUE(cookie->IsEquivalent(callback.cookies()[0])); 2835 EXPECT_TRUE(cookie->IsEquivalent(callback.cookies()[0]));
2833 2836
2834 // All urls in |urls| should share the same cookie domain. 2837 // All urls in |urls| should share the same cookie domain.
2835 const GURL kUrls[] = { 2838 const GURL kUrls[] = {
2836 http_www_google_.url(), https_www_google_.url(), ws_www_google_.url(), 2839 http_www_google_.url(), https_www_google_.url(), ws_www_google_.url(),
2837 wss_www_google_.url(), 2840 wss_www_google_.url(),
2838 }; 2841 };
2839 for (const GURL& url : kUrls) { 2842 for (const GURL& url : kUrls) {
2840 // Call the function with |url| and verify it is done synchronously without 2843 // Call the function with |url| and verify it is done synchronously without
2841 // calling LoadCookiesForKey. 2844 // calling LoadCookiesForKey.
2842 GetCookieListCallback callback; 2845 GetCookieListCallback callback;
2843 GetAllCookiesForURLTask(cm.get(), url, &callback); 2846 GetAllCookiesForURLTask(cm.get(), url, &callback);
2844 ASSERT_TRUE(callback.did_run()); 2847 callback.WaitUntilDone();
2845 ASSERT_EQ(1u, callback.cookies().size()); 2848 ASSERT_EQ(1u, callback.cookies().size());
2846 EXPECT_TRUE(cookie->IsEquivalent(callback.cookies()[0])); 2849 EXPECT_TRUE(cookie->IsEquivalent(callback.cookies()[0]));
2847 } 2850 }
2848 } 2851 }
2849 2852
2850 TEST_F(CookieMonsterTest, InvalidExpiryTime) { 2853 TEST_F(CookieMonsterTest, InvalidExpiryTime) {
2851 std::string cookie_line = 2854 std::string cookie_line =
2852 std::string(kValidCookieLine) + "; expires=Blarg arg arg"; 2855 std::string(kValidCookieLine) + "; expires=Blarg arg arg";
2853 scoped_ptr<CanonicalCookie> cookie(CanonicalCookie::Create( 2856 scoped_ptr<CanonicalCookie> cookie(CanonicalCookie::Create(
2854 http_www_google_.url(), cookie_line, Time::Now(), CookieOptions())); 2857 http_www_google_.url(), cookie_line, Time::Now(), CookieOptions()));
(...skipping 690 matching lines...) Expand 10 before | Expand all | Expand 10 after
3545 monster()->AddCallbackForCookie( 3548 monster()->AddCallbackForCookie(
3546 test_url_, "abc", 3549 test_url_, "abc",
3547 base::Bind(&RecordCookieChanges, &cookies1, nullptr))); 3550 base::Bind(&RecordCookieChanges, &cookies1, nullptr)));
3548 SetCookie(monster(), test_url_, "abc=def"); 3551 SetCookie(monster(), test_url_, "abc=def");
3549 base::MessageLoop::current()->RunUntilIdle(); 3552 base::MessageLoop::current()->RunUntilIdle();
3550 EXPECT_EQ(1U, cookies0.size()); 3553 EXPECT_EQ(1U, cookies0.size());
3551 EXPECT_EQ(1U, cookies0.size()); 3554 EXPECT_EQ(1U, cookies0.size());
3552 } 3555 }
3553 3556
3554 } // namespace net 3557 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/cookies/cookie_store_test_callbacks.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698