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

Side by Side Diff: net/cookies/cookie_store_unittest.h

Issue 266243004: Clang format slam. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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 | Annotate | Revision Log
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 #ifndef NET_COOKIES_COOKIE_STORE_UNITTEST_H_ 5 #ifndef NET_COOKIES_COOKIE_STORE_UNITTEST_H_
6 #define NET_COOKIES_COOKIE_STORE_UNITTEST_H_ 6 #define NET_COOKIES_COOKIE_STORE_UNITTEST_H_
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/strings/string_tokenizer.h" 10 #include "base/strings/string_tokenizer.h"
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 // Helper methods for the asynchronous Cookie Store API that call the 84 // Helper methods for the asynchronous Cookie Store API that call the
85 // asynchronous method and then pump the loop until the callback is invoked, 85 // asynchronous method and then pump the loop until the callback is invoked,
86 // finally returning the value. 86 // finally returning the value.
87 87
88 std::string GetCookies(CookieStore* cs, const GURL& url) { 88 std::string GetCookies(CookieStore* cs, const GURL& url) {
89 DCHECK(cs); 89 DCHECK(cs);
90 CookieOptions options; 90 CookieOptions options;
91 if (!CookieStoreTestTraits::supports_http_only) 91 if (!CookieStoreTestTraits::supports_http_only)
92 options.set_include_httponly(); 92 options.set_include_httponly();
93 StringResultCookieCallback callback; 93 StringResultCookieCallback callback;
94 cs->GetCookiesWithOptionsAsync( 94 cs->GetCookiesWithOptionsAsync(url,
95 url, options, 95 options,
96 base::Bind(&StringResultCookieCallback::Run, 96 base::Bind(&StringResultCookieCallback::Run,
97 base::Unretained(&callback))); 97 base::Unretained(&callback)));
98 RunFor(kTimeout); 98 RunFor(kTimeout);
99 EXPECT_TRUE(callback.did_run()); 99 EXPECT_TRUE(callback.did_run());
100 return callback.result(); 100 return callback.result();
101 } 101 }
102 102
103 std::string GetCookiesWithOptions(CookieStore* cs, 103 std::string GetCookiesWithOptions(CookieStore* cs,
104 const GURL& url, 104 const GURL& url,
105 const CookieOptions& options) { 105 const CookieOptions& options) {
106 DCHECK(cs); 106 DCHECK(cs);
107 StringResultCookieCallback callback; 107 StringResultCookieCallback callback;
108 cs->GetCookiesWithOptionsAsync( 108 cs->GetCookiesWithOptionsAsync(url,
109 url, options, base::Bind(&StringResultCookieCallback::Run, 109 options,
110 base::Unretained(&callback))); 110 base::Bind(&StringResultCookieCallback::Run,
111 base::Unretained(&callback)));
111 RunFor(kTimeout); 112 RunFor(kTimeout);
112 EXPECT_TRUE(callback.did_run()); 113 EXPECT_TRUE(callback.did_run());
113 return callback.result(); 114 return callback.result();
114 } 115 }
115 116
116 bool SetCookieWithOptions(CookieStore* cs, 117 bool SetCookieWithOptions(CookieStore* cs,
117 const GURL& url, 118 const GURL& url,
118 const std::string& cookie_line, 119 const std::string& cookie_line,
119 const CookieOptions& options) { 120 const CookieOptions& options) {
120 DCHECK(cs); 121 DCHECK(cs);
121 ResultSavingCookieCallback<bool> callback; 122 ResultSavingCookieCallback<bool> callback;
122 cs->SetCookieWithOptionsAsync( 123 cs->SetCookieWithOptionsAsync(
123 url, cookie_line, options, 124 url,
124 base::Bind( 125 cookie_line,
125 &ResultSavingCookieCallback<bool>::Run, 126 options,
126 base::Unretained(&callback))); 127 base::Bind(&ResultSavingCookieCallback<bool>::Run,
128 base::Unretained(&callback)));
127 RunFor(kTimeout); 129 RunFor(kTimeout);
128 EXPECT_TRUE(callback.did_run()); 130 EXPECT_TRUE(callback.did_run());
129 return callback.result(); 131 return callback.result();
130 } 132 }
131 133
132 bool SetCookieWithServerTime(CookieStore* cs, 134 bool SetCookieWithServerTime(CookieStore* cs,
133 const GURL& url, 135 const GURL& url,
134 const std::string& cookie_line, 136 const std::string& cookie_line,
135 const base::Time& server_time) { 137 const base::Time& server_time) {
136 CookieOptions options; 138 CookieOptions options;
(...skipping 11 matching lines...) Expand all
148 options.set_include_httponly(); 150 options.set_include_httponly();
149 return SetCookieWithOptions(cs, url, cookie_line, options); 151 return SetCookieWithOptions(cs, url, cookie_line, options);
150 } 152 }
151 153
152 void DeleteCookie(CookieStore* cs, 154 void DeleteCookie(CookieStore* cs,
153 const GURL& url, 155 const GURL& url,
154 const std::string& cookie_name) { 156 const std::string& cookie_name) {
155 DCHECK(cs); 157 DCHECK(cs);
156 NoResultCookieCallback callback; 158 NoResultCookieCallback callback;
157 cs->DeleteCookieAsync( 159 cs->DeleteCookieAsync(
158 url, cookie_name, 160 url,
161 cookie_name,
159 base::Bind(&NoResultCookieCallback::Run, base::Unretained(&callback))); 162 base::Bind(&NoResultCookieCallback::Run, base::Unretained(&callback)));
160 RunFor(kTimeout); 163 RunFor(kTimeout);
161 EXPECT_TRUE(callback.did_run()); 164 EXPECT_TRUE(callback.did_run());
162 } 165 }
163 166
164 int DeleteCreatedBetween(CookieStore* cs, 167 int DeleteCreatedBetween(CookieStore* cs,
165 const base::Time& delete_begin, 168 const base::Time& delete_begin,
166 const base::Time& delete_end) { 169 const base::Time& delete_end) {
167 DCHECK(cs); 170 DCHECK(cs);
168 ResultSavingCookieCallback<int> callback; 171 ResultSavingCookieCallback<int> callback;
169 cs->DeleteAllCreatedBetweenAsync( 172 cs->DeleteAllCreatedBetweenAsync(
170 delete_begin, delete_end, 173 delete_begin,
171 base::Bind( 174 delete_end,
172 &ResultSavingCookieCallback<int>::Run, 175 base::Bind(&ResultSavingCookieCallback<int>::Run,
173 base::Unretained(&callback))); 176 base::Unretained(&callback)));
174 RunFor(kTimeout); 177 RunFor(kTimeout);
175 EXPECT_TRUE(callback.did_run()); 178 EXPECT_TRUE(callback.did_run());
176 return callback.result(); 179 return callback.result();
177 } 180 }
178 181
179 int DeleteAllCreatedBetweenForHost(CookieStore* cs, 182 int DeleteAllCreatedBetweenForHost(CookieStore* cs,
180 const base::Time delete_begin, 183 const base::Time delete_begin,
181 const base::Time delete_end, 184 const base::Time delete_end,
182 const GURL& url) { 185 const GURL& url) {
183 DCHECK(cs); 186 DCHECK(cs);
184 ResultSavingCookieCallback<int> callback; 187 ResultSavingCookieCallback<int> callback;
185 cs->DeleteAllCreatedBetweenForHostAsync( 188 cs->DeleteAllCreatedBetweenForHostAsync(
186 delete_begin, delete_end, url, 189 delete_begin,
187 base::Bind( 190 delete_end,
188 &ResultSavingCookieCallback<int>::Run, 191 url,
189 base::Unretained(&callback))); 192 base::Bind(&ResultSavingCookieCallback<int>::Run,
193 base::Unretained(&callback)));
190 RunFor(kTimeout); 194 RunFor(kTimeout);
191 EXPECT_TRUE(callback.did_run()); 195 EXPECT_TRUE(callback.did_run());
192 return callback.result(); 196 return callback.result();
193 } 197 }
194 198
195 int DeleteSessionCookies(CookieStore* cs) { 199 int DeleteSessionCookies(CookieStore* cs) {
196 DCHECK(cs); 200 DCHECK(cs);
197 ResultSavingCookieCallback<int> callback; 201 ResultSavingCookieCallback<int> callback;
198 cs->DeleteSessionCookiesAsync( 202 cs->DeleteSessionCookiesAsync(base::Bind(
199 base::Bind( 203 &ResultSavingCookieCallback<int>::Run, base::Unretained(&callback)));
200 &ResultSavingCookieCallback<int>::Run,
201 base::Unretained(&callback)));
202 RunFor(kTimeout); 204 RunFor(kTimeout);
203 EXPECT_TRUE(callback.did_run()); 205 EXPECT_TRUE(callback.did_run());
204 return callback.result(); 206 return callback.result();
205 } 207 }
206 208
207 void RunFor(int ms) { 209 void RunFor(int ms) {
208 // Runs the test thread message loop for up to |ms| milliseconds. 210 // Runs the test thread message loop for up to |ms| milliseconds.
209 base::MessageLoop::current()->PostDelayedTask( 211 base::MessageLoop::current()->PostDelayedTask(
210 FROM_HERE, 212 FROM_HERE,
211 base::Bind(&base::MessageLoop::Quit, weak_factory_->GetWeakPtr()), 213 base::Bind(&base::MessageLoop::Quit, weak_factory_->GetWeakPtr()),
(...skipping 10 matching lines...) Expand all
222 void MatchCookieLines(const std::string& line1, const std::string& line2) { 224 void MatchCookieLines(const std::string& line1, const std::string& line2) {
223 EXPECT_EQ(TokenizeCookieLine(line1), TokenizeCookieLine(line2)); 225 EXPECT_EQ(TokenizeCookieLine(line1), TokenizeCookieLine(line2));
224 } 226 }
225 227
226 // Check the cookie line by polling until equality or a timeout is reached. 228 // Check the cookie line by polling until equality or a timeout is reached.
227 void MatchCookieLineWithTimeout(CookieStore* cs, 229 void MatchCookieLineWithTimeout(CookieStore* cs,
228 const GURL& url, 230 const GURL& url,
229 const std::string& line) { 231 const std::string& line) {
230 std::string cookies = GetCookies(cs, url); 232 std::string cookies = GetCookies(cs, url);
231 bool matched = (TokenizeCookieLine(line) == TokenizeCookieLine(cookies)); 233 bool matched = (TokenizeCookieLine(line) == TokenizeCookieLine(cookies));
232 base::Time polling_end_date = base::Time::Now() + 234 base::Time polling_end_date =
235 base::Time::Now() +
233 base::TimeDelta::FromMilliseconds( 236 base::TimeDelta::FromMilliseconds(
234 CookieStoreTestTraits::creation_time_granularity_in_ms); 237 CookieStoreTestTraits::creation_time_granularity_in_ms);
235 238
236 while (!matched && base::Time::Now() <= polling_end_date) { 239 while (!matched && base::Time::Now() <= polling_end_date) {
237 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(10)); 240 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(10));
238 cookies = GetCookies(cs, url); 241 cookies = GetCookies(cs, url);
239 matched = (TokenizeCookieLine(line) == TokenizeCookieLine(cookies)); 242 matched = (TokenizeCookieLine(line) == TokenizeCookieLine(cookies));
240 } 243 }
241 244
242 EXPECT_TRUE(matched) << "\"" << cookies 245 EXPECT_TRUE(matched) << "\"" << cookies << "\" does not match \"" << line
243 << "\" does not match \"" << line << "\""; 246 << "\"";
244 } 247 }
245 248
246 GURL url_google_; 249 GURL url_google_;
247 GURL url_google_secure_; 250 GURL url_google_secure_;
248 GURL url_google_foo_; 251 GURL url_google_foo_;
249 GURL url_google_bar_; 252 GURL url_google_bar_;
250 253
251 scoped_ptr<base::WeakPtrFactory<base::MessageLoop> > weak_factory_; 254 scoped_ptr<base::WeakPtrFactory<base::MessageLoop> > weak_factory_;
252 scoped_ptr<base::MessageLoop> message_loop_; 255 scoped_ptr<base::MessageLoop> message_loop_;
253 256
254 private: 257 private:
255 // Returns a set of strings of type "name=value". Fails in case of duplicate. 258 // Returns a set of strings of type "name=value". Fails in case of duplicate.
256 std::set<std::string> TokenizeCookieLine(const std::string& line) { 259 std::set<std::string> TokenizeCookieLine(const std::string& line) {
257 std::set<std::string> tokens; 260 std::set<std::string> tokens;
258 base::StringTokenizer tokenizer(line, " ;"); 261 base::StringTokenizer tokenizer(line, " ;");
259 while (tokenizer.GetNext()) 262 while (tokenizer.GetNext())
260 EXPECT_TRUE(tokens.insert(tokenizer.token()).second); 263 EXPECT_TRUE(tokens.insert(tokenizer.token()).second);
261 return tokens; 264 return tokens;
262 } 265 }
263 }; 266 };
264 267
265 TYPED_TEST_CASE_P(CookieStoreTest); 268 TYPED_TEST_CASE_P(CookieStoreTest);
266 269
267 TYPED_TEST_P(CookieStoreTest, TypeTest) { 270 TYPED_TEST_P(CookieStoreTest, TypeTest) {
268 scoped_refptr<CookieStore> cs(this->GetCookieStore()); 271 scoped_refptr<CookieStore> cs(this->GetCookieStore());
269 EXPECT_EQ(cs->GetCookieMonster(), 272 EXPECT_EQ(cs->GetCookieMonster(),
270 (TypeParam::is_cookie_monster) ? 273 (TypeParam::is_cookie_monster)
271 static_cast<CookieMonster*>(cs.get()) : NULL); 274 ? static_cast<CookieMonster*>(cs.get())
275 : NULL);
272 } 276 }
273 277
274 TYPED_TEST_P(CookieStoreTest, DomainTest) { 278 TYPED_TEST_P(CookieStoreTest, DomainTest) {
275 scoped_refptr<CookieStore> cs(this->GetCookieStore()); 279 scoped_refptr<CookieStore> cs(this->GetCookieStore());
276 EXPECT_TRUE(this->SetCookie(cs.get(), this->url_google_, "A=B")); 280 EXPECT_TRUE(this->SetCookie(cs.get(), this->url_google_, "A=B"));
277 this->MatchCookieLines("A=B", this->GetCookies(cs.get(), this->url_google_)); 281 this->MatchCookieLines("A=B", this->GetCookies(cs.get(), this->url_google_));
278 EXPECT_TRUE(this->SetCookie( 282 EXPECT_TRUE(this->SetCookie(
279 cs.get(), this->url_google_, "C=D; domain=.google.izzle")); 283 cs.get(), this->url_google_, "C=D; domain=.google.izzle"));
280 this->MatchCookieLines("A=B; C=D", 284 this->MatchCookieLines("A=B; C=D",
281 this->GetCookies(cs.get(), this->url_google_)); 285 this->GetCookies(cs.get(), this->url_google_));
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 "a=1", this->GetCookies(cs.get(), GURL("http://sub.www.google.com"))); 444 "a=1", this->GetCookies(cs.get(), GURL("http://sub.www.google.com")));
441 this->MatchCookieLines( 445 this->MatchCookieLines(
442 std::string(), 446 std::string(),
443 this->GetCookies(cs.get(), GURL("http://something-else.com"))); 447 this->GetCookies(cs.get(), GURL("http://something-else.com")));
444 } 448 }
445 } 449 }
446 450
447 // Test that the domain specified in cookie string is treated case-insensitive 451 // Test that the domain specified in cookie string is treated case-insensitive
448 // http://b/issue?id=896475. 452 // http://b/issue?id=896475.
449 TYPED_TEST_P(CookieStoreTest, CaseInsensitiveDomainTest) { 453 TYPED_TEST_P(CookieStoreTest, CaseInsensitiveDomainTest) {
450 scoped_refptr<CookieStore> cs(this->GetCookieStore()); 454 scoped_refptr<CookieStore> cs(this->GetCookieStore());
451 GURL url("http://www.google.com"); 455 GURL url("http://www.google.com");
452 EXPECT_TRUE(this->SetCookie(cs.get(), url, "a=1; domain=.GOOGLE.COM")); 456 EXPECT_TRUE(this->SetCookie(cs.get(), url, "a=1; domain=.GOOGLE.COM"));
453 EXPECT_TRUE(this->SetCookie(cs.get(), url, "b=2; domain=.wWw.gOOgLE.coM")); 457 EXPECT_TRUE(this->SetCookie(cs.get(), url, "b=2; domain=.wWw.gOOgLE.coM"));
454 this->MatchCookieLines("a=1; b=2", this->GetCookies(cs.get(), url)); 458 this->MatchCookieLines("a=1; b=2", this->GetCookies(cs.get(), url));
455 } 459 }
456 460
457 TYPED_TEST_P(CookieStoreTest, TestIpAddress) { 461 TYPED_TEST_P(CookieStoreTest, TestIpAddress) {
458 GURL url_ip("http://1.2.3.4/weee"); 462 GURL url_ip("http://1.2.3.4/weee");
459 { 463 {
460 scoped_refptr<CookieStore> cs(this->GetCookieStore()); 464 scoped_refptr<CookieStore> cs(this->GetCookieStore());
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
745 this->GetCookies(cs.get(), this->url_google_)); 749 this->GetCookies(cs.get(), this->url_google_));
746 750
747 // Create a persistent cookie. 751 // Create a persistent cookie.
748 EXPECT_TRUE(this->SetCookie( 752 EXPECT_TRUE(this->SetCookie(
749 cs.get(), 753 cs.get(),
750 this->url_google_, 754 this->url_google_,
751 std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-22 22:50:13 GMT")); 755 std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-22 22:50:13 GMT"));
752 this->MatchCookieLines("A=B", this->GetCookies(cs.get(), this->url_google_)); 756 this->MatchCookieLines("A=B", this->GetCookies(cs.get(), this->url_google_));
753 // Check that it is not deleted with significant enough clock skew. 757 // Check that it is not deleted with significant enough clock skew.
754 base::Time server_time; 758 base::Time server_time;
755 EXPECT_TRUE(base::Time::FromString("Sun, 17-Apr-1977 22:50:13 GMT", 759 EXPECT_TRUE(
756 &server_time)); 760 base::Time::FromString("Sun, 17-Apr-1977 22:50:13 GMT", &server_time));
757 EXPECT_TRUE(this->SetCookieWithServerTime( 761 EXPECT_TRUE(this->SetCookieWithServerTime(
758 cs.get(), 762 cs.get(),
759 this->url_google_, 763 this->url_google_,
760 std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-1977 22:50:13 GMT", 764 std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-1977 22:50:13 GMT",
761 server_time)); 765 server_time));
762 this->MatchCookieLines("A=B", this->GetCookies(cs.get(), this->url_google_)); 766 this->MatchCookieLines("A=B", this->GetCookies(cs.get(), this->url_google_));
763 767
764 // Create a persistent cookie. 768 // Create a persistent cookie.
765 EXPECT_TRUE(this->SetCookie( 769 EXPECT_TRUE(this->SetCookie(
766 cs.get(), 770 cs.get(),
767 this->url_google_, 771 this->url_google_,
768 std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-22 22:50:13 GMT")); 772 std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-22 22:50:13 GMT"));
769 this->MatchCookieLines("A=B", this->GetCookies(cs.get(), this->url_google_)); 773 this->MatchCookieLines("A=B", this->GetCookies(cs.get(), this->url_google_));
770 // Delete it via Expires, with a unix epoch of 0. 774 // Delete it via Expires, with a unix epoch of 0.
771 EXPECT_TRUE(this->SetCookie(cs.get(), 775 EXPECT_TRUE(this->SetCookie(cs.get(),
772 this->url_google_, 776 this->url_google_,
773 std::string(kValidCookieLine) + 777 std::string(kValidCookieLine) +
774 "; expires=Thu, 1-Jan-1970 00:00:00 GMT")); 778 "; expires=Thu, 1-Jan-1970 00:00:00 GMT"));
775 this->MatchCookieLines(std::string(), 779 this->MatchCookieLines(std::string(),
776 this->GetCookies(cs.get(), this->url_google_)); 780 this->GetCookies(cs.get(), this->url_google_));
777 } 781 }
778 782
779 TYPED_TEST_P(CookieStoreTest, TestDeleteAllCreatedBetween) { 783 TYPED_TEST_P(CookieStoreTest, TestDeleteAllCreatedBetween) {
780 scoped_refptr<CookieStore> cs(this->GetCookieStore()); 784 scoped_refptr<CookieStore> cs(this->GetCookieStore());
781 const base::Time last_month = base::Time::Now() - 785 const base::Time last_month =
782 base::TimeDelta::FromDays(30); 786 base::Time::Now() - base::TimeDelta::FromDays(30);
783 const base::Time last_minute = base::Time::Now() - 787 const base::Time last_minute =
784 base::TimeDelta::FromMinutes(1); 788 base::Time::Now() - base::TimeDelta::FromMinutes(1);
785 const base::Time next_minute = base::Time::Now() + 789 const base::Time next_minute =
786 base::TimeDelta::FromMinutes(1); 790 base::Time::Now() + base::TimeDelta::FromMinutes(1);
787 const base::Time next_month = base::Time::Now() + 791 const base::Time next_month =
788 base::TimeDelta::FromDays(30); 792 base::Time::Now() + base::TimeDelta::FromDays(30);
789 793
790 // Add a cookie. 794 // Add a cookie.
791 EXPECT_TRUE(this->SetCookie(cs.get(), this->url_google_, "A=B")); 795 EXPECT_TRUE(this->SetCookie(cs.get(), this->url_google_, "A=B"));
792 // Check that the cookie is in the store. 796 // Check that the cookie is in the store.
793 this->MatchCookieLines("A=B", this->GetCookies(cs.get(), this->url_google_)); 797 this->MatchCookieLines("A=B", this->GetCookies(cs.get(), this->url_google_));
794 798
795 // Remove cookies in empty intervals. 799 // Remove cookies in empty intervals.
796 EXPECT_EQ(0, this->DeleteCreatedBetween(cs.get(), last_month, last_minute)); 800 EXPECT_EQ(0, this->DeleteCreatedBetween(cs.get(), last_month, last_minute));
797 EXPECT_EQ(0, this->DeleteCreatedBetween(cs.get(), next_minute, next_month)); 801 EXPECT_EQ(0, this->DeleteCreatedBetween(cs.get(), next_minute, next_month));
798 // Check that the cookie is still there. 802 // Check that the cookie is still there.
(...skipping 24 matching lines...) Expand all
823 827
824 // These 3 cookies match the time range and host. 828 // These 3 cookies match the time range and host.
825 EXPECT_TRUE(this->SetCookie(cs.get(), this->url_google_, "A=B")); 829 EXPECT_TRUE(this->SetCookie(cs.get(), this->url_google_, "A=B"));
826 EXPECT_TRUE(this->SetCookie(cs.get(), this->url_google_, "C=D")); 830 EXPECT_TRUE(this->SetCookie(cs.get(), this->url_google_, "C=D"));
827 EXPECT_TRUE(this->SetCookie(cs.get(), this->url_google_, "Y=Z")); 831 EXPECT_TRUE(this->SetCookie(cs.get(), this->url_google_, "Y=Z"));
828 832
829 // This cookie does not match host. 833 // This cookie does not match host.
830 EXPECT_TRUE(this->SetCookie(cs.get(), url_not_google, "E=F")); 834 EXPECT_TRUE(this->SetCookie(cs.get(), url_not_google, "E=F"));
831 835
832 // Delete cookies. 836 // Delete cookies.
833 EXPECT_EQ( 837 EXPECT_EQ(3, // Deletes A=B, C=D, Y=Z
834 3, // Deletes A=B, C=D, Y=Z 838 this->DeleteAllCreatedBetweenForHost(
835 this->DeleteAllCreatedBetweenForHost( 839 cs.get(), now, base::Time::Max(), this->url_google_));
836 cs.get(), now, base::Time::Max(), this->url_google_));
837 } 840 }
838 841
839 TYPED_TEST_P(CookieStoreTest, TestSecure) { 842 TYPED_TEST_P(CookieStoreTest, TestSecure) {
840 scoped_refptr<CookieStore> cs(this->GetCookieStore()); 843 scoped_refptr<CookieStore> cs(this->GetCookieStore());
841 844
842 EXPECT_TRUE(this->SetCookie(cs.get(), this->url_google_, "A=B")); 845 EXPECT_TRUE(this->SetCookie(cs.get(), this->url_google_, "A=B"));
843 this->MatchCookieLines("A=B", 846 this->MatchCookieLines("A=B", this->GetCookies(cs.get(), this->url_google_));
844 this->GetCookies(cs.get(), this->url_google_)); 847 this->MatchCookieLines("A=B",
845 this->MatchCookieLines( 848 this->GetCookies(cs.get(), this->url_google_secure_));
846 "A=B", this->GetCookies(cs.get(), this->url_google_secure_));
847 849
848 EXPECT_TRUE( 850 EXPECT_TRUE(
849 this->SetCookie(cs.get(), this->url_google_secure_, "A=B; secure")); 851 this->SetCookie(cs.get(), this->url_google_secure_, "A=B; secure"));
850 // The secure should overwrite the non-secure. 852 // The secure should overwrite the non-secure.
851 this->MatchCookieLines(std::string(), 853 this->MatchCookieLines(std::string(),
852 this->GetCookies(cs.get(), this->url_google_)); 854 this->GetCookies(cs.get(), this->url_google_));
853 this->MatchCookieLines("A=B", 855 this->MatchCookieLines("A=B",
854 this->GetCookies(cs.get(), this->url_google_secure_)); 856 this->GetCookies(cs.get(), this->url_google_secure_));
855 857
856 EXPECT_TRUE( 858 EXPECT_TRUE(
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
1017 HttpOnlyTest, 1019 HttpOnlyTest,
1018 TestCookieDeletion, 1020 TestCookieDeletion,
1019 TestDeleteAllCreatedBetween, 1021 TestDeleteAllCreatedBetween,
1020 TestDeleteAllCreatedBetweenForHost, 1022 TestDeleteAllCreatedBetweenForHost,
1021 TestSecure, 1023 TestSecure,
1022 NetUtilCookieTest, 1024 NetUtilCookieTest,
1023 OverwritePersistentCookie, 1025 OverwritePersistentCookie,
1024 CookieOrdering, 1026 CookieOrdering,
1025 DeleteSessionCookie); 1027 DeleteSessionCookie);
1026 1028
1027 template<class CookieStoreTestTraits> 1029 template <class CookieStoreTestTraits>
1028 class MultiThreadedCookieStoreTest : 1030 class MultiThreadedCookieStoreTest
1029 public CookieStoreTest<CookieStoreTestTraits> { 1031 : public CookieStoreTest<CookieStoreTestTraits> {
1030 public: 1032 public:
1031 MultiThreadedCookieStoreTest() : other_thread_("CMTthread") {} 1033 MultiThreadedCookieStoreTest() : other_thread_("CMTthread") {}
1032 1034
1033 // Helper methods for calling the asynchronous CookieStore methods 1035 // Helper methods for calling the asynchronous CookieStore methods
1034 // from a different thread. 1036 // from a different thread.
1035 1037
1036 void GetCookiesTask(CookieStore* cs, 1038 void GetCookiesTask(CookieStore* cs,
1037 const GURL& url, 1039 const GURL& url,
1038 StringResultCookieCallback* callback) { 1040 StringResultCookieCallback* callback) {
1039 CookieOptions options; 1041 CookieOptions options;
1040 if (!CookieStoreTestTraits::supports_http_only) 1042 if (!CookieStoreTestTraits::supports_http_only)
1041 options.set_include_httponly(); 1043 options.set_include_httponly();
1042 cs->GetCookiesWithOptionsAsync( 1044 cs->GetCookiesWithOptionsAsync(url,
1043 url, options, 1045 options,
1044 base::Bind(&StringResultCookieCallback::Run, 1046 base::Bind(&StringResultCookieCallback::Run,
1045 base::Unretained(callback))); 1047 base::Unretained(callback)));
1046 } 1048 }
1047 1049
1048 void GetCookiesWithOptionsTask(CookieStore* cs, 1050 void GetCookiesWithOptionsTask(CookieStore* cs,
1049 const GURL& url, 1051 const GURL& url,
1050 const CookieOptions& options, 1052 const CookieOptions& options,
1051 StringResultCookieCallback* callback) { 1053 StringResultCookieCallback* callback) {
1052 cs->GetCookiesWithOptionsAsync( 1054 cs->GetCookiesWithOptionsAsync(url,
1053 url, options, 1055 options,
1054 base::Bind(&StringResultCookieCallback::Run, 1056 base::Bind(&StringResultCookieCallback::Run,
1055 base::Unretained(callback))); 1057 base::Unretained(callback)));
1056 } 1058 }
1057 1059
1058 void SetCookieWithOptionsTask(CookieStore* cs, 1060 void SetCookieWithOptionsTask(CookieStore* cs,
1059 const GURL& url, 1061 const GURL& url,
1060 const std::string& cookie_line, 1062 const std::string& cookie_line,
1061 const CookieOptions& options, 1063 const CookieOptions& options,
1062 ResultSavingCookieCallback<bool>* callback) { 1064 ResultSavingCookieCallback<bool>* callback) {
1063 cs->SetCookieWithOptionsAsync( 1065 cs->SetCookieWithOptionsAsync(
1064 url, cookie_line, options, 1066 url,
1065 base::Bind( 1067 cookie_line,
1066 &ResultSavingCookieCallback<bool>::Run, 1068 options,
1067 base::Unretained(callback))); 1069 base::Bind(&ResultSavingCookieCallback<bool>::Run,
1070 base::Unretained(callback)));
1068 } 1071 }
1069 1072
1070 void DeleteCookieTask(CookieStore* cs, 1073 void DeleteCookieTask(CookieStore* cs,
1071 const GURL& url, 1074 const GURL& url,
1072 const std::string& cookie_name, 1075 const std::string& cookie_name,
1073 NoResultCookieCallback* callback) { 1076 NoResultCookieCallback* callback) {
1074 cs->DeleteCookieAsync( 1077 cs->DeleteCookieAsync(
1075 url, cookie_name, 1078 url,
1079 cookie_name,
1076 base::Bind(&NoResultCookieCallback::Run, base::Unretained(callback))); 1080 base::Bind(&NoResultCookieCallback::Run, base::Unretained(callback)));
1077 } 1081 }
1078 1082
1079 void DeleteSessionCookiesTask(CookieStore* cs, 1083 void DeleteSessionCookiesTask(CookieStore* cs,
1080 ResultSavingCookieCallback<int>* callback) { 1084 ResultSavingCookieCallback<int>* callback) {
1081 cs->DeleteSessionCookiesAsync( 1085 cs->DeleteSessionCookiesAsync(base::Bind(
1082 base::Bind( 1086 &ResultSavingCookieCallback<int>::Run, base::Unretained(callback)));
1083 &ResultSavingCookieCallback<int>::Run,
1084 base::Unretained(callback)));
1085 } 1087 }
1086 1088
1087 protected: 1089 protected:
1088 void RunOnOtherThread(const base::Closure& task) { 1090 void RunOnOtherThread(const base::Closure& task) {
1089 other_thread_.Start(); 1091 other_thread_.Start();
1090 other_thread_.message_loop()->PostTask(FROM_HERE, task); 1092 other_thread_.message_loop()->PostTask(FROM_HERE, task);
1091 CookieStoreTest<CookieStoreTestTraits>::RunFor(kTimeout); 1093 CookieStoreTest<CookieStoreTestTraits>::RunFor(kTimeout);
1092 other_thread_.Stop(); 1094 other_thread_.Stop();
1093 } 1095 }
1094 1096
1095 Thread other_thread_; 1097 Thread other_thread_;
1096 }; 1098 };
1097 1099
1098 TYPED_TEST_CASE_P(MultiThreadedCookieStoreTest); 1100 TYPED_TEST_CASE_P(MultiThreadedCookieStoreTest);
1099 1101
1100 // TODO(ycxiao): Eventually, we will need to create a separate thread, create 1102 // TODO(ycxiao): Eventually, we will need to create a separate thread, create
1101 // the cookie store on that thread (or at least its store, i.e., the DB 1103 // the cookie store on that thread (or at least its store, i.e., the DB
1102 // thread). 1104 // thread).
1103 TYPED_TEST_P(MultiThreadedCookieStoreTest, ThreadCheckGetCookies) { 1105 TYPED_TEST_P(MultiThreadedCookieStoreTest, ThreadCheckGetCookies) {
1104 scoped_refptr<CookieStore> cs(this->GetCookieStore()); 1106 scoped_refptr<CookieStore> cs(this->GetCookieStore());
1105 EXPECT_TRUE(this->SetCookie(cs.get(), this->url_google_, "A=B")); 1107 EXPECT_TRUE(this->SetCookie(cs.get(), this->url_google_, "A=B"));
1106 this->MatchCookieLines("A=B", this->GetCookies(cs.get(), this->url_google_)); 1108 this->MatchCookieLines("A=B", this->GetCookies(cs.get(), this->url_google_));
1107 StringResultCookieCallback callback(&this->other_thread_); 1109 StringResultCookieCallback callback(&this->other_thread_);
1108 base::Closure task = base::Bind( 1110 base::Closure task =
1109 &net::MultiThreadedCookieStoreTest<TypeParam>::GetCookiesTask, 1111 base::Bind(&net::MultiThreadedCookieStoreTest<TypeParam>::GetCookiesTask,
1110 base::Unretained(this), 1112 base::Unretained(this),
1111 cs, this->url_google_, &callback); 1113 cs,
1114 this->url_google_,
1115 &callback);
1112 this->RunOnOtherThread(task); 1116 this->RunOnOtherThread(task);
1113 EXPECT_TRUE(callback.did_run()); 1117 EXPECT_TRUE(callback.did_run());
1114 EXPECT_EQ("A=B", callback.result()); 1118 EXPECT_EQ("A=B", callback.result());
1115 } 1119 }
1116 1120
1117 TYPED_TEST_P(MultiThreadedCookieStoreTest, ThreadCheckGetCookiesWithOptions) { 1121 TYPED_TEST_P(MultiThreadedCookieStoreTest, ThreadCheckGetCookiesWithOptions) {
1118 scoped_refptr<CookieStore> cs(this->GetCookieStore()); 1122 scoped_refptr<CookieStore> cs(this->GetCookieStore());
1119 CookieOptions options; 1123 CookieOptions options;
1120 if (!TypeParam::supports_http_only) 1124 if (!TypeParam::supports_http_only)
1121 options.set_include_httponly(); 1125 options.set_include_httponly();
1122 EXPECT_TRUE(this->SetCookie(cs.get(), this->url_google_, "A=B")); 1126 EXPECT_TRUE(this->SetCookie(cs.get(), this->url_google_, "A=B"));
1123 this->MatchCookieLines( 1127 this->MatchCookieLines(
1124 "A=B", this->GetCookiesWithOptions(cs.get(), this->url_google_, options)); 1128 "A=B", this->GetCookiesWithOptions(cs.get(), this->url_google_, options));
1125 StringResultCookieCallback callback(&this->other_thread_); 1129 StringResultCookieCallback callback(&this->other_thread_);
1126 base::Closure task = base::Bind( 1130 base::Closure task = base::Bind(
1127 &net::MultiThreadedCookieStoreTest<TypeParam>::GetCookiesWithOptionsTask, 1131 &net::MultiThreadedCookieStoreTest<TypeParam>::GetCookiesWithOptionsTask,
1128 base::Unretained(this), 1132 base::Unretained(this),
1129 cs, this->url_google_, options, &callback); 1133 cs,
1134 this->url_google_,
1135 options,
1136 &callback);
1130 this->RunOnOtherThread(task); 1137 this->RunOnOtherThread(task);
1131 EXPECT_TRUE(callback.did_run()); 1138 EXPECT_TRUE(callback.did_run());
1132 EXPECT_EQ("A=B", callback.result()); 1139 EXPECT_EQ("A=B", callback.result());
1133 } 1140 }
1134 1141
1135 TYPED_TEST_P(MultiThreadedCookieStoreTest, ThreadCheckSetCookieWithOptions) { 1142 TYPED_TEST_P(MultiThreadedCookieStoreTest, ThreadCheckSetCookieWithOptions) {
1136 scoped_refptr<CookieStore> cs(this->GetCookieStore()); 1143 scoped_refptr<CookieStore> cs(this->GetCookieStore());
1137 CookieOptions options; 1144 CookieOptions options;
1138 if (!TypeParam::supports_http_only) 1145 if (!TypeParam::supports_http_only)
1139 options.set_include_httponly(); 1146 options.set_include_httponly();
1140 EXPECT_TRUE( 1147 EXPECT_TRUE(
1141 this->SetCookieWithOptions(cs.get(), this->url_google_, "A=B", options)); 1148 this->SetCookieWithOptions(cs.get(), this->url_google_, "A=B", options));
1142 ResultSavingCookieCallback<bool> callback(&this->other_thread_); 1149 ResultSavingCookieCallback<bool> callback(&this->other_thread_);
1143 base::Closure task = base::Bind( 1150 base::Closure task = base::Bind(
1144 &net::MultiThreadedCookieStoreTest<TypeParam>::SetCookieWithOptionsTask, 1151 &net::MultiThreadedCookieStoreTest<TypeParam>::SetCookieWithOptionsTask,
1145 base::Unretained(this), 1152 base::Unretained(this),
1146 cs, this->url_google_, "A=B", options, &callback); 1153 cs,
1154 this->url_google_,
1155 "A=B",
1156 options,
1157 &callback);
1147 this->RunOnOtherThread(task); 1158 this->RunOnOtherThread(task);
1148 EXPECT_TRUE(callback.did_run()); 1159 EXPECT_TRUE(callback.did_run());
1149 EXPECT_TRUE(callback.result()); 1160 EXPECT_TRUE(callback.result());
1150 } 1161 }
1151 1162
1152 TYPED_TEST_P(MultiThreadedCookieStoreTest, ThreadCheckDeleteCookie) { 1163 TYPED_TEST_P(MultiThreadedCookieStoreTest, ThreadCheckDeleteCookie) {
1153 scoped_refptr<CookieStore> cs(this->GetCookieStore()); 1164 scoped_refptr<CookieStore> cs(this->GetCookieStore());
1154 CookieOptions options; 1165 CookieOptions options;
1155 if (!TypeParam::supports_http_only) 1166 if (!TypeParam::supports_http_only)
1156 options.set_include_httponly(); 1167 options.set_include_httponly();
1157 EXPECT_TRUE( 1168 EXPECT_TRUE(
1158 this->SetCookieWithOptions(cs.get(), this->url_google_, "A=B", options)); 1169 this->SetCookieWithOptions(cs.get(), this->url_google_, "A=B", options));
1159 this->DeleteCookie(cs.get(), this->url_google_, "A"); 1170 this->DeleteCookie(cs.get(), this->url_google_, "A");
1160 EXPECT_TRUE( 1171 EXPECT_TRUE(
1161 this->SetCookieWithOptions(cs.get(), this->url_google_, "A=B", options)); 1172 this->SetCookieWithOptions(cs.get(), this->url_google_, "A=B", options));
1162 NoResultCookieCallback callback(&this->other_thread_); 1173 NoResultCookieCallback callback(&this->other_thread_);
1163 base::Closure task = base::Bind( 1174 base::Closure task = base::Bind(
1164 &net::MultiThreadedCookieStoreTest<TypeParam>::DeleteCookieTask, 1175 &net::MultiThreadedCookieStoreTest<TypeParam>::DeleteCookieTask,
1165 base::Unretained(this), 1176 base::Unretained(this),
1166 cs, this->url_google_, "A", &callback); 1177 cs,
1178 this->url_google_,
1179 "A",
1180 &callback);
1167 this->RunOnOtherThread(task); 1181 this->RunOnOtherThread(task);
1168 EXPECT_TRUE(callback.did_run()); 1182 EXPECT_TRUE(callback.did_run());
1169 } 1183 }
1170 1184
1171 TYPED_TEST_P(MultiThreadedCookieStoreTest, ThreadCheckDeleteSessionCookies) { 1185 TYPED_TEST_P(MultiThreadedCookieStoreTest, ThreadCheckDeleteSessionCookies) {
1172 scoped_refptr<CookieStore> cs(this->GetCookieStore()); 1186 scoped_refptr<CookieStore> cs(this->GetCookieStore());
1173 CookieOptions options; 1187 CookieOptions options;
1174 if (!TypeParam::supports_http_only) 1188 if (!TypeParam::supports_http_only)
1175 options.set_include_httponly(); 1189 options.set_include_httponly();
1176 EXPECT_TRUE( 1190 EXPECT_TRUE(
1177 this->SetCookieWithOptions(cs.get(), this->url_google_, "A=B", options)); 1191 this->SetCookieWithOptions(cs.get(), this->url_google_, "A=B", options));
1178 EXPECT_TRUE( 1192 EXPECT_TRUE(
1179 this->SetCookieWithOptions(cs.get(), 1193 this->SetCookieWithOptions(cs.get(),
1180 this->url_google_, 1194 this->url_google_,
1181 "B=C; expires=Mon, 18-Apr-22 22:50:13 GMT", 1195 "B=C; expires=Mon, 18-Apr-22 22:50:13 GMT",
1182 options)); 1196 options));
1183 EXPECT_EQ(1, this->DeleteSessionCookies(cs.get())); 1197 EXPECT_EQ(1, this->DeleteSessionCookies(cs.get()));
1184 EXPECT_EQ(0, this->DeleteSessionCookies(cs.get())); 1198 EXPECT_EQ(0, this->DeleteSessionCookies(cs.get()));
1185 EXPECT_TRUE( 1199 EXPECT_TRUE(
1186 this->SetCookieWithOptions(cs.get(), this->url_google_, "A=B", options)); 1200 this->SetCookieWithOptions(cs.get(), this->url_google_, "A=B", options));
1187 ResultSavingCookieCallback<int> callback(&this->other_thread_); 1201 ResultSavingCookieCallback<int> callback(&this->other_thread_);
1188 base::Closure task = base::Bind( 1202 base::Closure task = base::Bind(
1189 &net::MultiThreadedCookieStoreTest<TypeParam>::DeleteSessionCookiesTask, 1203 &net::MultiThreadedCookieStoreTest<TypeParam>::DeleteSessionCookiesTask,
1190 base::Unretained(this), 1204 base::Unretained(this),
1191 cs, &callback); 1205 cs,
1206 &callback);
1192 this->RunOnOtherThread(task); 1207 this->RunOnOtherThread(task);
1193 EXPECT_TRUE(callback.did_run()); 1208 EXPECT_TRUE(callback.did_run());
1194 EXPECT_EQ(1, callback.result()); 1209 EXPECT_EQ(1, callback.result());
1195 } 1210 }
1196 1211
1197 REGISTER_TYPED_TEST_CASE_P(MultiThreadedCookieStoreTest, 1212 REGISTER_TYPED_TEST_CASE_P(MultiThreadedCookieStoreTest,
1198 ThreadCheckGetCookies, 1213 ThreadCheckGetCookies,
1199 ThreadCheckGetCookiesWithOptions, 1214 ThreadCheckGetCookiesWithOptions,
1200 ThreadCheckSetCookieWithOptions, 1215 ThreadCheckSetCookieWithOptions,
1201 ThreadCheckDeleteCookie, 1216 ThreadCheckDeleteCookie,
1202 ThreadCheckDeleteSessionCookies); 1217 ThreadCheckDeleteSessionCookies);
1203 1218
1204 } // namespace net 1219 } // namespace net
1205 1220
1206 #endif // NET_COOKIES_COOKIE_STORE_UNITTEST_H_ 1221 #endif // NET_COOKIES_COOKIE_STORE_UNITTEST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698