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