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 #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 <set> |
| 9 #include <string> |
| 10 #include <vector> |
| 11 |
8 #include "base/bind.h" | 12 #include "base/bind.h" |
9 #include "base/location.h" | 13 #include "base/location.h" |
10 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
11 #include "base/single_thread_task_runner.h" | 15 #include "base/single_thread_task_runner.h" |
12 #include "base/strings/string_tokenizer.h" | 16 #include "base/strings/string_tokenizer.h" |
13 #include "base/thread_task_runner_handle.h" | 17 #include "base/thread_task_runner_handle.h" |
14 #include "base/threading/thread.h" | 18 #include "base/threading/thread.h" |
15 #include "net/cookies/cookie_monster.h" | 19 #include "net/cookies/cookie_monster.h" |
16 #include "net/cookies/cookie_store.h" | 20 #include "net/cookies/cookie_store.h" |
17 #include "net/cookies/cookie_store_test_callbacks.h" | 21 #include "net/cookies/cookie_store_test_callbacks.h" |
| 22 #include "net/cookies/cookie_store_test_helpers.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
19 #include "url/gurl.h" | 24 #include "url/gurl.h" |
20 | 25 |
21 #if defined(OS_IOS) | 26 #if defined(OS_IOS) |
22 #include "base/ios/ios_util.h" | 27 #include "base/ios/ios_util.h" |
23 #endif | 28 #endif |
24 | 29 |
25 // This file declares unittest templates that can be used to test common | 30 // This file declares unittest templates that can be used to test common |
26 // behavior of any CookieStore implementation. | 31 // behavior of any CookieStore implementation. |
27 // See cookie_monster_unittest.cc for an example of an implementation. | 32 // See cookie_monster_unittest.cc for an example of an implementation. |
28 | 33 |
29 namespace net { | 34 namespace net { |
30 | 35 |
31 using base::Thread; | 36 using base::Thread; |
32 | 37 |
33 const int kTimeout = 1000; | 38 const int kTimeout = 1000; |
34 | 39 |
35 const char kUrlFtp[] = "ftp://ftp.google.izzle/"; | |
36 const char kUrlGoogle[] = "http://www.google.izzle"; | |
37 const char kUrlGoogleFoo[] = "http://www.google.izzle/foo"; | |
38 const char kUrlGoogleBar[] = "http://www.google.izzle/bar"; | |
39 const char kUrlGoogleSecure[] = "https://www.google.izzle"; | |
40 const char kUrlGoogleWebSocket[] = "ws://www.google.izzle"; | |
41 const char kUrlGoogleWebSocketSecure[] = "wss://www.google.izzle"; | |
42 const char kValidCookieLine[] = "A=B; path=/"; | 40 const char kValidCookieLine[] = "A=B; path=/"; |
43 const char kValidDomainCookieLine[] = "A=B; path=/; domain=google.izzle"; | |
44 | 41 |
45 // The CookieStoreTestTraits must have the following members: | 42 // The CookieStoreTestTraits must have the following members: |
46 // struct CookieStoreTestTraits { | 43 // struct CookieStoreTestTraits { |
47 // // Factory function. | 44 // // Factory function. |
48 // static scoped_refptr<CookieStore> Create(); | 45 // static scoped_refptr<CookieStore> Create(); |
49 // | 46 // |
50 // // The cookie store is a CookieMonster. Only used to test | 47 // // The cookie store is a CookieMonster. Only used to test |
51 // // GetCookieMonster(). | 48 // // GetCookieMonster(). |
52 // static const bool is_cookie_monster; | 49 // static const bool is_cookie_monster; |
53 // | 50 // |
(...skipping 17 matching lines...) Expand all Loading... |
71 // | 68 // |
72 // // Time to wait between two cookie insertions to ensure that cookies have | 69 // // Time to wait between two cookie insertions to ensure that cookies have |
73 // // different creation times. | 70 // // different creation times. |
74 // static const int creation_time_granularity_in_ms; | 71 // static const int creation_time_granularity_in_ms; |
75 // }; | 72 // }; |
76 | 73 |
77 template <class CookieStoreTestTraits> | 74 template <class CookieStoreTestTraits> |
78 class CookieStoreTest : public testing::Test { | 75 class CookieStoreTest : public testing::Test { |
79 protected: | 76 protected: |
80 CookieStoreTest() | 77 CookieStoreTest() |
81 : url_google_(kUrlGoogle), | 78 : http_www_google_("http://www.google.izzle"), |
82 url_google_secure_(kUrlGoogleSecure), | 79 https_www_google_("https://www.google.izzle"), |
83 url_google_foo_(kUrlGoogleFoo), | 80 ftp_google_("ftp://ftp.google.izzle/"), |
84 url_google_bar_(kUrlGoogleBar) { | 81 ws_www_google_("ws://www.google.izzle"), |
| 82 wss_www_google_("wss://www.google.izzle"), |
| 83 www_google_foo_("http://www.google.izzle/foo"), |
| 84 www_google_bar_("http://www.google.izzle/bar") { |
85 // This test may be used outside of the net test suite, and thus may not | 85 // This test may be used outside of the net test suite, and thus may not |
86 // have a message loop. | 86 // have a message loop. |
87 if (!base::MessageLoop::current()) | 87 if (!base::MessageLoop::current()) |
88 message_loop_.reset(new base::MessageLoop); | 88 message_loop_.reset(new base::MessageLoop); |
89 weak_factory_.reset(new base::WeakPtrFactory<base::MessageLoop>( | 89 weak_factory_.reset(new base::WeakPtrFactory<base::MessageLoop>( |
90 base::MessageLoop::current())); | 90 base::MessageLoop::current())); |
91 } | 91 } |
92 | 92 |
93 // Helper methods for the asynchronous Cookie Store API that call the | 93 // Helper methods for the asynchronous Cookie Store API that call the |
94 // asynchronous method and then pump the loop until the callback is invoked, | 94 // asynchronous method and then pump the loop until the callback is invoked, |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 while (!matched && base::Time::Now() <= polling_end_date) { | 245 while (!matched && base::Time::Now() <= polling_end_date) { |
246 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(10)); | 246 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(10)); |
247 cookies = GetCookies(cs, url); | 247 cookies = GetCookies(cs, url); |
248 matched = (TokenizeCookieLine(line) == TokenizeCookieLine(cookies)); | 248 matched = (TokenizeCookieLine(line) == TokenizeCookieLine(cookies)); |
249 } | 249 } |
250 | 250 |
251 EXPECT_TRUE(matched) << "\"" << cookies | 251 EXPECT_TRUE(matched) << "\"" << cookies |
252 << "\" does not match \"" << line << "\""; | 252 << "\" does not match \"" << line << "\""; |
253 } | 253 } |
254 | 254 |
255 GURL url_google_; | 255 const CookieURLHelper http_www_google_; |
256 GURL url_google_secure_; | 256 const CookieURLHelper https_www_google_; |
257 GURL url_google_foo_; | 257 const CookieURLHelper ftp_google_; |
258 GURL url_google_bar_; | 258 const CookieURLHelper ws_www_google_; |
| 259 const CookieURLHelper wss_www_google_; |
| 260 const CookieURLHelper www_google_foo_; |
| 261 const CookieURLHelper www_google_bar_; |
259 | 262 |
260 scoped_ptr<base::WeakPtrFactory<base::MessageLoop> > weak_factory_; | 263 scoped_ptr<base::WeakPtrFactory<base::MessageLoop> > weak_factory_; |
261 scoped_ptr<base::MessageLoop> message_loop_; | 264 scoped_ptr<base::MessageLoop> message_loop_; |
262 | 265 |
263 private: | 266 private: |
264 // Returns a set of strings of type "name=value". Fails in case of duplicate. | 267 // Returns a set of strings of type "name=value". Fails in case of duplicate. |
265 std::set<std::string> TokenizeCookieLine(const std::string& line) { | 268 std::set<std::string> TokenizeCookieLine(const std::string& line) { |
266 std::set<std::string> tokens; | 269 std::set<std::string> tokens; |
267 base::StringTokenizer tokenizer(line, " ;"); | 270 base::StringTokenizer tokenizer(line, " ;"); |
268 while (tokenizer.GetNext()) | 271 while (tokenizer.GetNext()) |
269 EXPECT_TRUE(tokens.insert(tokenizer.token()).second); | 272 EXPECT_TRUE(tokens.insert(tokenizer.token()).second); |
270 return tokens; | 273 return tokens; |
271 } | 274 } |
272 }; | 275 }; |
273 | 276 |
274 TYPED_TEST_CASE_P(CookieStoreTest); | 277 TYPED_TEST_CASE_P(CookieStoreTest); |
275 | 278 |
276 TYPED_TEST_P(CookieStoreTest, TypeTest) { | 279 TYPED_TEST_P(CookieStoreTest, TypeTest) { |
277 scoped_refptr<CookieStore> cs(this->GetCookieStore()); | 280 scoped_refptr<CookieStore> cs(this->GetCookieStore()); |
278 EXPECT_EQ(cs->GetCookieMonster(), | 281 EXPECT_EQ(cs->GetCookieMonster(), |
279 (TypeParam::is_cookie_monster) ? | 282 (TypeParam::is_cookie_monster) ? |
280 static_cast<CookieMonster*>(cs.get()) : NULL); | 283 static_cast<CookieMonster*>(cs.get()) : NULL); |
281 } | 284 } |
282 | 285 |
283 TYPED_TEST_P(CookieStoreTest, DomainTest) { | 286 TYPED_TEST_P(CookieStoreTest, DomainTest) { |
284 scoped_refptr<CookieStore> cs(this->GetCookieStore()); | 287 scoped_refptr<CookieStore> cs(this->GetCookieStore()); |
285 EXPECT_TRUE(this->SetCookie(cs.get(), this->url_google_, "A=B")); | 288 EXPECT_TRUE(this->SetCookie(cs.get(), this->http_www_google_.url(), "A=B")); |
286 this->MatchCookieLines("A=B", this->GetCookies(cs.get(), this->url_google_)); | 289 this->MatchCookieLines( |
287 EXPECT_TRUE(this->SetCookie( | 290 "A=B", this->GetCookies(cs.get(), this->http_www_google_.url())); |
288 cs.get(), this->url_google_, "C=D; domain=.google.izzle")); | 291 EXPECT_TRUE( |
289 this->MatchCookieLines("A=B; C=D", | 292 this->SetCookie(cs.get(), this->http_www_google_.url(), |
290 this->GetCookies(cs.get(), this->url_google_)); | 293 this->http_www_google_.Format("C=D; domain=.%D"))); |
| 294 this->MatchCookieLines( |
| 295 "A=B; C=D", this->GetCookies(cs.get(), this->http_www_google_.url())); |
291 | 296 |
292 // Verify that A=B was set as a host cookie rather than a domain | 297 // Verify that A=B was set as a host cookie rather than a domain |
293 // cookie -- should not be accessible from a sub sub-domain. | 298 // cookie -- should not be accessible from a sub sub-domain. |
294 this->MatchCookieLines( | 299 this->MatchCookieLines( |
295 "C=D", this->GetCookies(cs.get(), GURL("http://foo.www.google.izzle"))); | 300 "C=D", |
| 301 this->GetCookies( |
| 302 cs.get(), GURL(this->http_www_google_.Format("http://foo.www.%D")))); |
296 | 303 |
297 // Test and make sure we find domain cookies on the same domain. | 304 // Test and make sure we find domain cookies on the same domain. |
298 EXPECT_TRUE(this->SetCookie( | 305 EXPECT_TRUE( |
299 cs.get(), this->url_google_, "E=F; domain=.www.google.izzle")); | 306 this->SetCookie(cs.get(), this->http_www_google_.url(), |
300 this->MatchCookieLines("A=B; C=D; E=F", | 307 this->http_www_google_.Format("E=F; domain=.www.%D"))); |
301 this->GetCookies(cs.get(), this->url_google_)); | 308 this->MatchCookieLines( |
| 309 "A=B; C=D; E=F", |
| 310 this->GetCookies(cs.get(), this->http_www_google_.url())); |
302 | 311 |
303 // Test setting a domain= that doesn't start w/ a dot, should | 312 // Test setting a domain= that doesn't start w/ a dot, should |
304 // treat it as a domain cookie, as if there was a pre-pended dot. | 313 // treat it as a domain cookie, as if there was a pre-pended dot. |
305 EXPECT_TRUE(this->SetCookie( | 314 EXPECT_TRUE( |
306 cs.get(), this->url_google_, "G=H; domain=www.google.izzle")); | 315 this->SetCookie(cs.get(), this->http_www_google_.url(), |
307 this->MatchCookieLines("A=B; C=D; E=F; G=H", | 316 this->http_www_google_.Format("G=H; domain=www.%D"))); |
308 this->GetCookies(cs.get(), this->url_google_)); | 317 this->MatchCookieLines( |
| 318 "A=B; C=D; E=F; G=H", |
| 319 this->GetCookies(cs.get(), this->http_www_google_.url())); |
309 | 320 |
310 // Test domain enforcement, should fail on a sub-domain or something too deep. | 321 // Test domain enforcement, should fail on a sub-domain or something too deep. |
311 EXPECT_FALSE( | 322 EXPECT_FALSE( |
312 this->SetCookie(cs.get(), this->url_google_, "I=J; domain=.izzle")); | 323 this->SetCookie(cs.get(), this->http_www_google_.url(), |
313 this->MatchCookieLines(std::string(), | 324 this->http_www_google_.Format("I=J; domain=.%R"))); |
314 this->GetCookies(cs.get(), GURL("http://a.izzle"))); | 325 this->MatchCookieLines( |
| 326 std::string(), |
| 327 this->GetCookies(cs.get(), |
| 328 GURL(this->http_www_google_.Format("http://a.%R")))); |
315 EXPECT_FALSE(this->SetCookie( | 329 EXPECT_FALSE(this->SetCookie( |
316 cs.get(), this->url_google_, "K=L; domain=.bla.www.google.izzle")); | 330 cs.get(), this->http_www_google_.url(), |
| 331 this->http_www_google_.Format("K=L; domain=.bla.www.%D"))); |
317 this->MatchCookieLines( | 332 this->MatchCookieLines( |
318 "C=D; E=F; G=H", | 333 "C=D; E=F; G=H", |
319 this->GetCookies(cs.get(), GURL("http://bla.www.google.izzle"))); | 334 this->GetCookies( |
320 this->MatchCookieLines("A=B; C=D; E=F; G=H", | 335 cs.get(), GURL(this->http_www_google_.Format("http://bla.www.%D")))); |
321 this->GetCookies(cs.get(), this->url_google_)); | 336 this->MatchCookieLines( |
| 337 "A=B; C=D; E=F; G=H", |
| 338 this->GetCookies(cs.get(), this->http_www_google_.url())); |
322 } | 339 } |
323 | 340 |
324 // FireFox recognizes domains containing trailing periods as valid. | 341 // FireFox recognizes domains containing trailing periods as valid. |
325 // IE and Safari do not. Assert the expected policy here. | 342 // IE and Safari do not. Assert the expected policy here. |
326 TYPED_TEST_P(CookieStoreTest, DomainWithTrailingDotTest) { | 343 TYPED_TEST_P(CookieStoreTest, DomainWithTrailingDotTest) { |
327 scoped_refptr<CookieStore> cs(this->GetCookieStore()); | 344 scoped_refptr<CookieStore> cs(this->GetCookieStore()); |
328 EXPECT_FALSE(this->SetCookie( | 345 EXPECT_FALSE(this->SetCookie(cs.get(), this->http_www_google_.url(), |
329 cs.get(), this->url_google_, "a=1; domain=.www.google.com.")); | 346 "a=1; domain=.www.google.com.")); |
330 EXPECT_FALSE(this->SetCookie( | 347 EXPECT_FALSE(this->SetCookie(cs.get(), this->http_www_google_.url(), |
331 cs.get(), this->url_google_, "b=2; domain=.www.google.com..")); | 348 "b=2; domain=.www.google.com..")); |
332 this->MatchCookieLines(std::string(), | 349 this->MatchCookieLines( |
333 this->GetCookies(cs.get(), this->url_google_)); | 350 std::string(), this->GetCookies(cs.get(), this->http_www_google_.url())); |
334 } | 351 } |
335 | 352 |
336 // Test that cookies can bet set on higher level domains. | 353 // Test that cookies can bet set on higher level domains. |
337 // http://b/issue?id=896491 | 354 // http://b/issue?id=896491 |
338 TYPED_TEST_P(CookieStoreTest, ValidSubdomainTest) { | 355 TYPED_TEST_P(CookieStoreTest, ValidSubdomainTest) { |
339 scoped_refptr<CookieStore> cs(this->GetCookieStore()); | 356 scoped_refptr<CookieStore> cs(this->GetCookieStore()); |
340 GURL url_abcd("http://a.b.c.d.com"); | 357 GURL url_abcd("http://a.b.c.d.com"); |
341 GURL url_bcd("http://b.c.d.com"); | 358 GURL url_bcd("http://b.c.d.com"); |
342 GURL url_cd("http://c.d.com"); | 359 GURL url_cd("http://c.d.com"); |
343 GURL url_d("http://d.com"); | 360 GURL url_d("http://d.com"); |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
592 this->GetCookies(cs.get(), GURL("http://hopefully-no-cookies.com/"))); | 609 this->GetCookies(cs.get(), GURL("http://hopefully-no-cookies.com/"))); |
593 this->MatchCookieLines(std::string(), | 610 this->MatchCookieLines(std::string(), |
594 this->GetCookies(cs.get(), GURL("http://.com/"))); | 611 this->GetCookies(cs.get(), GURL("http://.com/"))); |
595 } | 612 } |
596 | 613 |
597 TYPED_TEST_P(CookieStoreTest, InvalidScheme) { | 614 TYPED_TEST_P(CookieStoreTest, InvalidScheme) { |
598 if (!TypeParam::filters_schemes) | 615 if (!TypeParam::filters_schemes) |
599 return; | 616 return; |
600 | 617 |
601 scoped_refptr<CookieStore> cs(this->GetCookieStore()); | 618 scoped_refptr<CookieStore> cs(this->GetCookieStore()); |
602 EXPECT_FALSE(this->SetCookie(cs.get(), GURL(kUrlFtp), kValidCookieLine)); | 619 EXPECT_FALSE( |
| 620 this->SetCookie(cs.get(), this->ftp_google_.url(), kValidCookieLine)); |
603 } | 621 } |
604 | 622 |
605 TYPED_TEST_P(CookieStoreTest, InvalidScheme_Read) { | 623 TYPED_TEST_P(CookieStoreTest, InvalidScheme_Read) { |
606 if (!TypeParam::filters_schemes) | 624 if (!TypeParam::filters_schemes) |
607 return; | 625 return; |
608 | 626 |
| 627 const std::string kValidDomainCookieLine = |
| 628 this->http_www_google_.Format("A=B; path=/; domain=%D"); |
| 629 |
609 scoped_refptr<CookieStore> cs(this->GetCookieStore()); | 630 scoped_refptr<CookieStore> cs(this->GetCookieStore()); |
610 EXPECT_TRUE( | 631 EXPECT_TRUE(this->SetCookie(cs.get(), this->http_www_google_.url(), |
611 this->SetCookie(cs.get(), GURL(kUrlGoogle), kValidDomainCookieLine)); | 632 kValidDomainCookieLine)); |
612 this->MatchCookieLines(std::string(), | 633 this->MatchCookieLines(std::string(), |
613 this->GetCookies(cs.get(), GURL(kUrlFtp))); | 634 this->GetCookies(cs.get(), this->ftp_google_.url())); |
614 } | 635 } |
615 | 636 |
616 TYPED_TEST_P(CookieStoreTest, PathTest) { | 637 TYPED_TEST_P(CookieStoreTest, PathTest) { |
617 scoped_refptr<CookieStore> cs(this->GetCookieStore()); | 638 scoped_refptr<CookieStore> cs(this->GetCookieStore()); |
618 std::string url("http://www.google.izzle"); | 639 std::string url("http://www.google.izzle"); |
619 EXPECT_TRUE(this->SetCookie(cs.get(), GURL(url), "A=B; path=/wee")); | 640 EXPECT_TRUE(this->SetCookie(cs.get(), GURL(url), "A=B; path=/wee")); |
620 this->MatchCookieLines("A=B", this->GetCookies(cs.get(), GURL(url + "/wee"))); | 641 this->MatchCookieLines("A=B", this->GetCookies(cs.get(), GURL(url + "/wee"))); |
621 this->MatchCookieLines("A=B", | 642 this->MatchCookieLines("A=B", |
622 this->GetCookies(cs.get(), GURL(url + "/wee/"))); | 643 this->GetCookies(cs.get(), GURL(url + "/wee/"))); |
623 this->MatchCookieLines("A=B", | 644 this->MatchCookieLines("A=B", |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
664 | 685 |
665 TYPED_TEST_P(CookieStoreTest, HttpOnlyTest) { | 686 TYPED_TEST_P(CookieStoreTest, HttpOnlyTest) { |
666 if (!TypeParam::supports_http_only) | 687 if (!TypeParam::supports_http_only) |
667 return; | 688 return; |
668 | 689 |
669 scoped_refptr<CookieStore> cs(this->GetCookieStore()); | 690 scoped_refptr<CookieStore> cs(this->GetCookieStore()); |
670 CookieOptions options; | 691 CookieOptions options; |
671 options.set_include_httponly(); | 692 options.set_include_httponly(); |
672 | 693 |
673 // Create a httponly cookie. | 694 // Create a httponly cookie. |
674 EXPECT_TRUE(this->SetCookieWithOptions( | 695 EXPECT_TRUE(this->SetCookieWithOptions(cs.get(), this->http_www_google_.url(), |
675 cs.get(), this->url_google_, "A=B; httponly", options)); | 696 "A=B; httponly", options)); |
676 | 697 |
677 // Check httponly read protection. | 698 // Check httponly read protection. |
678 this->MatchCookieLines(std::string(), | |
679 this->GetCookies(cs.get(), this->url_google_)); | |
680 this->MatchCookieLines( | 699 this->MatchCookieLines( |
681 "A=B", this->GetCookiesWithOptions(cs.get(), this->url_google_, options)); | 700 std::string(), this->GetCookies(cs.get(), this->http_www_google_.url())); |
| 701 this->MatchCookieLines( |
| 702 "A=B", this->GetCookiesWithOptions(cs.get(), this->http_www_google_.url(), |
| 703 options)); |
682 | 704 |
683 // Check httponly overwrite protection. | 705 // Check httponly overwrite protection. |
684 EXPECT_FALSE(this->SetCookie(cs.get(), this->url_google_, "A=C")); | 706 EXPECT_FALSE(this->SetCookie(cs.get(), this->http_www_google_.url(), "A=C")); |
685 this->MatchCookieLines(std::string(), | |
686 this->GetCookies(cs.get(), this->url_google_)); | |
687 this->MatchCookieLines( | 707 this->MatchCookieLines( |
688 "A=B", this->GetCookiesWithOptions(cs.get(), this->url_google_, options)); | 708 std::string(), this->GetCookies(cs.get(), this->http_www_google_.url())); |
689 EXPECT_TRUE( | 709 this->MatchCookieLines( |
690 this->SetCookieWithOptions(cs.get(), this->url_google_, "A=C", options)); | 710 "A=B", this->GetCookiesWithOptions(cs.get(), this->http_www_google_.url(), |
691 this->MatchCookieLines("A=C", this->GetCookies(cs.get(), this->url_google_)); | 711 options)); |
| 712 EXPECT_TRUE(this->SetCookieWithOptions(cs.get(), this->http_www_google_.url(), |
| 713 "A=C", options)); |
| 714 this->MatchCookieLines( |
| 715 "A=C", this->GetCookies(cs.get(), this->http_www_google_.url())); |
692 | 716 |
693 // Check httponly create protection. | 717 // Check httponly create protection. |
694 EXPECT_FALSE(this->SetCookie(cs.get(), this->url_google_, "B=A; httponly")); | 718 EXPECT_FALSE( |
| 719 this->SetCookie(cs.get(), this->http_www_google_.url(), "B=A; httponly")); |
695 this->MatchCookieLines( | 720 this->MatchCookieLines( |
696 "A=C", this->GetCookiesWithOptions(cs.get(), this->url_google_, options)); | 721 "A=C", this->GetCookiesWithOptions(cs.get(), this->http_www_google_.url(), |
697 EXPECT_TRUE(this->SetCookieWithOptions( | 722 options)); |
698 cs.get(), this->url_google_, "B=A; httponly", options)); | 723 EXPECT_TRUE(this->SetCookieWithOptions(cs.get(), this->http_www_google_.url(), |
| 724 "B=A; httponly", options)); |
| 725 this->MatchCookieLines("A=C; B=A", |
| 726 this->GetCookiesWithOptions( |
| 727 cs.get(), this->http_www_google_.url(), options)); |
699 this->MatchCookieLines( | 728 this->MatchCookieLines( |
700 "A=C; B=A", | 729 "A=C", this->GetCookies(cs.get(), this->http_www_google_.url())); |
701 this->GetCookiesWithOptions(cs.get(), this->url_google_, options)); | |
702 this->MatchCookieLines("A=C", this->GetCookies(cs.get(), this->url_google_)); | |
703 } | 730 } |
704 | 731 |
705 TYPED_TEST_P(CookieStoreTest, TestCookieDeletion) { | 732 TYPED_TEST_P(CookieStoreTest, TestCookieDeletion) { |
706 scoped_refptr<CookieStore> cs(this->GetCookieStore()); | 733 scoped_refptr<CookieStore> cs(this->GetCookieStore()); |
707 | 734 |
708 // Create a session cookie. | 735 // Create a session cookie. |
709 EXPECT_TRUE(this->SetCookie(cs.get(), this->url_google_, kValidCookieLine)); | 736 EXPECT_TRUE(this->SetCookie(cs.get(), this->http_www_google_.url(), |
710 this->MatchCookieLines("A=B", this->GetCookies(cs.get(), this->url_google_)); | 737 kValidCookieLine)); |
| 738 this->MatchCookieLines( |
| 739 "A=B", this->GetCookies(cs.get(), this->http_www_google_.url())); |
711 // Delete it via Max-Age. | 740 // Delete it via Max-Age. |
712 EXPECT_TRUE(this->SetCookie(cs.get(), | 741 EXPECT_TRUE(this->SetCookie(cs.get(), this->http_www_google_.url(), |
713 this->url_google_, | |
714 std::string(kValidCookieLine) + "; max-age=0")); | 742 std::string(kValidCookieLine) + "; max-age=0")); |
715 this->MatchCookieLineWithTimeout(cs.get(), this->url_google_, std::string()); | 743 this->MatchCookieLineWithTimeout(cs.get(), this->http_www_google_.url(), |
| 744 std::string()); |
716 | 745 |
717 // Create a session cookie. | 746 // Create a session cookie. |
718 EXPECT_TRUE(this->SetCookie(cs.get(), this->url_google_, kValidCookieLine)); | 747 EXPECT_TRUE(this->SetCookie(cs.get(), this->http_www_google_.url(), |
719 this->MatchCookieLines("A=B", this->GetCookies(cs.get(), this->url_google_)); | 748 kValidCookieLine)); |
| 749 this->MatchCookieLines( |
| 750 "A=B", this->GetCookies(cs.get(), this->http_www_google_.url())); |
720 // Delete it via Expires. | 751 // Delete it via Expires. |
721 EXPECT_TRUE(this->SetCookie(cs.get(), | 752 EXPECT_TRUE(this->SetCookie(cs.get(), this->http_www_google_.url(), |
722 this->url_google_, | |
723 std::string(kValidCookieLine) + | 753 std::string(kValidCookieLine) + |
724 "; expires=Mon, 18-Apr-1977 22:50:13 GMT")); | 754 "; expires=Mon, 18-Apr-1977 22:50:13 GMT")); |
725 this->MatchCookieLines(std::string(), | 755 this->MatchCookieLines( |
726 this->GetCookies(cs.get(), this->url_google_)); | 756 std::string(), this->GetCookies(cs.get(), this->http_www_google_.url())); |
727 | 757 |
728 // Create a persistent cookie. | 758 // Create a persistent cookie. |
729 EXPECT_TRUE(this->SetCookie( | 759 EXPECT_TRUE(this->SetCookie( |
730 cs.get(), | 760 cs.get(), this->http_www_google_.url(), |
731 this->url_google_, | |
732 std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-22 22:50:13 GMT")); | 761 std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-22 22:50:13 GMT")); |
733 | 762 |
734 this->MatchCookieLines("A=B", this->GetCookies(cs.get(), this->url_google_)); | 763 this->MatchCookieLines( |
| 764 "A=B", this->GetCookies(cs.get(), this->http_www_google_.url())); |
735 // Delete it via Max-Age. | 765 // Delete it via Max-Age. |
736 EXPECT_TRUE(this->SetCookie(cs.get(), | 766 EXPECT_TRUE(this->SetCookie(cs.get(), this->http_www_google_.url(), |
737 this->url_google_, | |
738 std::string(kValidCookieLine) + "; max-age=0")); | 767 std::string(kValidCookieLine) + "; max-age=0")); |
739 this->MatchCookieLineWithTimeout(cs.get(), this->url_google_, std::string()); | 768 this->MatchCookieLineWithTimeout(cs.get(), this->http_www_google_.url(), |
| 769 std::string()); |
740 | 770 |
741 // Create a persistent cookie. | 771 // Create a persistent cookie. |
742 EXPECT_TRUE(this->SetCookie( | 772 EXPECT_TRUE(this->SetCookie( |
743 cs.get(), | 773 cs.get(), this->http_www_google_.url(), |
744 this->url_google_, | |
745 std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-22 22:50:13 GMT")); | 774 std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-22 22:50:13 GMT")); |
746 this->MatchCookieLines("A=B", this->GetCookies(cs.get(), this->url_google_)); | 775 this->MatchCookieLines( |
| 776 "A=B", this->GetCookies(cs.get(), this->http_www_google_.url())); |
747 // Delete it via Expires. | 777 // Delete it via Expires. |
748 EXPECT_TRUE(this->SetCookie(cs.get(), | 778 EXPECT_TRUE(this->SetCookie(cs.get(), this->http_www_google_.url(), |
749 this->url_google_, | |
750 std::string(kValidCookieLine) + | 779 std::string(kValidCookieLine) + |
751 "; expires=Mon, 18-Apr-1977 22:50:13 GMT")); | 780 "; expires=Mon, 18-Apr-1977 22:50:13 GMT")); |
752 this->MatchCookieLines(std::string(), | 781 this->MatchCookieLines( |
753 this->GetCookies(cs.get(), this->url_google_)); | 782 std::string(), this->GetCookies(cs.get(), this->http_www_google_.url())); |
754 | 783 |
755 // Create a persistent cookie. | 784 // Create a persistent cookie. |
756 EXPECT_TRUE(this->SetCookie( | 785 EXPECT_TRUE(this->SetCookie( |
757 cs.get(), | 786 cs.get(), this->http_www_google_.url(), |
758 this->url_google_, | |
759 std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-22 22:50:13 GMT")); | 787 std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-22 22:50:13 GMT")); |
760 this->MatchCookieLines("A=B", this->GetCookies(cs.get(), this->url_google_)); | 788 this->MatchCookieLines( |
| 789 "A=B", this->GetCookies(cs.get(), this->http_www_google_.url())); |
761 // Check that it is not deleted with significant enough clock skew. | 790 // Check that it is not deleted with significant enough clock skew. |
762 base::Time server_time; | 791 base::Time server_time; |
763 EXPECT_TRUE(base::Time::FromString("Sun, 17-Apr-1977 22:50:13 GMT", | 792 EXPECT_TRUE(base::Time::FromString("Sun, 17-Apr-1977 22:50:13 GMT", |
764 &server_time)); | 793 &server_time)); |
765 EXPECT_TRUE(this->SetCookieWithServerTime( | 794 EXPECT_TRUE(this->SetCookieWithServerTime( |
766 cs.get(), | 795 cs.get(), this->http_www_google_.url(), |
767 this->url_google_, | |
768 std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-1977 22:50:13 GMT", | 796 std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-1977 22:50:13 GMT", |
769 server_time)); | 797 server_time)); |
770 this->MatchCookieLines("A=B", this->GetCookies(cs.get(), this->url_google_)); | 798 this->MatchCookieLines( |
| 799 "A=B", this->GetCookies(cs.get(), this->http_www_google_.url())); |
771 | 800 |
772 // Create a persistent cookie. | 801 // Create a persistent cookie. |
773 EXPECT_TRUE(this->SetCookie( | 802 EXPECT_TRUE(this->SetCookie( |
774 cs.get(), | 803 cs.get(), this->http_www_google_.url(), |
775 this->url_google_, | |
776 std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-22 22:50:13 GMT")); | 804 std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-22 22:50:13 GMT")); |
777 this->MatchCookieLines("A=B", this->GetCookies(cs.get(), this->url_google_)); | 805 this->MatchCookieLines( |
| 806 "A=B", this->GetCookies(cs.get(), this->http_www_google_.url())); |
778 // Delete it via Expires, with a unix epoch of 0. | 807 // Delete it via Expires, with a unix epoch of 0. |
779 EXPECT_TRUE(this->SetCookie(cs.get(), | 808 EXPECT_TRUE(this->SetCookie(cs.get(), this->http_www_google_.url(), |
780 this->url_google_, | |
781 std::string(kValidCookieLine) + | 809 std::string(kValidCookieLine) + |
782 "; expires=Thu, 1-Jan-1970 00:00:00 GMT")); | 810 "; expires=Thu, 1-Jan-1970 00:00:00 GMT")); |
783 this->MatchCookieLines(std::string(), | 811 this->MatchCookieLines( |
784 this->GetCookies(cs.get(), this->url_google_)); | 812 std::string(), this->GetCookies(cs.get(), this->http_www_google_.url())); |
785 } | 813 } |
786 | 814 |
787 TYPED_TEST_P(CookieStoreTest, TestDeleteAllCreatedBetween) { | 815 TYPED_TEST_P(CookieStoreTest, TestDeleteAllCreatedBetween) { |
788 scoped_refptr<CookieStore> cs(this->GetCookieStore()); | 816 scoped_refptr<CookieStore> cs(this->GetCookieStore()); |
789 const base::Time last_month = base::Time::Now() - | 817 const base::Time last_month = base::Time::Now() - |
790 base::TimeDelta::FromDays(30); | 818 base::TimeDelta::FromDays(30); |
791 const base::Time last_minute = base::Time::Now() - | 819 const base::Time last_minute = base::Time::Now() - |
792 base::TimeDelta::FromMinutes(1); | 820 base::TimeDelta::FromMinutes(1); |
793 const base::Time next_minute = base::Time::Now() + | 821 const base::Time next_minute = base::Time::Now() + |
794 base::TimeDelta::FromMinutes(1); | 822 base::TimeDelta::FromMinutes(1); |
795 const base::Time next_month = base::Time::Now() + | 823 const base::Time next_month = base::Time::Now() + |
796 base::TimeDelta::FromDays(30); | 824 base::TimeDelta::FromDays(30); |
797 | 825 |
798 // Add a cookie. | 826 // Add a cookie. |
799 EXPECT_TRUE(this->SetCookie(cs.get(), this->url_google_, "A=B")); | 827 EXPECT_TRUE(this->SetCookie(cs.get(), this->http_www_google_.url(), "A=B")); |
800 // Check that the cookie is in the store. | 828 // Check that the cookie is in the store. |
801 this->MatchCookieLines("A=B", this->GetCookies(cs.get(), this->url_google_)); | 829 this->MatchCookieLines( |
| 830 "A=B", this->GetCookies(cs.get(), this->http_www_google_.url())); |
802 | 831 |
803 // Remove cookies in empty intervals. | 832 // Remove cookies in empty intervals. |
804 EXPECT_EQ(0, this->DeleteCreatedBetween(cs.get(), last_month, last_minute)); | 833 EXPECT_EQ(0, this->DeleteCreatedBetween(cs.get(), last_month, last_minute)); |
805 EXPECT_EQ(0, this->DeleteCreatedBetween(cs.get(), next_minute, next_month)); | 834 EXPECT_EQ(0, this->DeleteCreatedBetween(cs.get(), next_minute, next_month)); |
806 // Check that the cookie is still there. | 835 // Check that the cookie is still there. |
807 this->MatchCookieLines("A=B", this->GetCookies(cs.get(), this->url_google_)); | 836 this->MatchCookieLines( |
| 837 "A=B", this->GetCookies(cs.get(), this->http_www_google_.url())); |
808 | 838 |
809 // Remove the cookie with an interval defined by two dates. | 839 // Remove the cookie with an interval defined by two dates. |
810 EXPECT_EQ(1, this->DeleteCreatedBetween(cs.get(), last_minute, next_minute)); | 840 EXPECT_EQ(1, this->DeleteCreatedBetween(cs.get(), last_minute, next_minute)); |
811 // Check that the cookie disappeared. | 841 // Check that the cookie disappeared. |
812 this->MatchCookieLines(std::string(), | 842 this->MatchCookieLines( |
813 this->GetCookies(cs.get(), this->url_google_)); | 843 std::string(), this->GetCookies(cs.get(), this->http_www_google_.url())); |
814 | 844 |
815 // Add another cookie. | 845 // Add another cookie. |
816 EXPECT_TRUE(this->SetCookie(cs.get(), this->url_google_, "C=D")); | 846 EXPECT_TRUE(this->SetCookie(cs.get(), this->http_www_google_.url(), "C=D")); |
817 // Check that the cookie is in the store. | 847 // Check that the cookie is in the store. |
818 this->MatchCookieLines("C=D", this->GetCookies(cs.get(), this->url_google_)); | 848 this->MatchCookieLines( |
| 849 "C=D", this->GetCookies(cs.get(), this->http_www_google_.url())); |
819 | 850 |
820 // Remove the cookie with a null ending time. | 851 // Remove the cookie with a null ending time. |
821 EXPECT_EQ(1, this->DeleteCreatedBetween(cs.get(), last_minute, base::Time())); | 852 EXPECT_EQ(1, this->DeleteCreatedBetween(cs.get(), last_minute, base::Time())); |
822 // Check that the cookie disappeared. | 853 // Check that the cookie disappeared. |
823 this->MatchCookieLines(std::string(), | 854 this->MatchCookieLines( |
824 this->GetCookies(cs.get(), this->url_google_)); | 855 std::string(), this->GetCookies(cs.get(), this->http_www_google_.url())); |
825 } | 856 } |
826 | 857 |
827 TYPED_TEST_P(CookieStoreTest, TestDeleteAllCreatedBetweenForHost) { | 858 TYPED_TEST_P(CookieStoreTest, TestDeleteAllCreatedBetweenForHost) { |
828 scoped_refptr<CookieStore> cs(this->GetCookieStore()); | 859 scoped_refptr<CookieStore> cs(this->GetCookieStore()); |
829 GURL url_not_google("http://www.notgoogle.com"); | 860 GURL url_not_google("http://www.notgoogle.com"); |
830 base::Time now = base::Time::Now(); | 861 base::Time now = base::Time::Now(); |
831 | 862 |
832 // These 3 cookies match the time range and host. | 863 // These 3 cookies match the time range and host. |
833 EXPECT_TRUE(this->SetCookie(cs.get(), this->url_google_, "A=B")); | 864 EXPECT_TRUE(this->SetCookie(cs.get(), this->http_www_google_.url(), "A=B")); |
834 EXPECT_TRUE(this->SetCookie(cs.get(), this->url_google_, "C=D")); | 865 EXPECT_TRUE(this->SetCookie(cs.get(), this->http_www_google_.url(), "C=D")); |
835 EXPECT_TRUE(this->SetCookie(cs.get(), this->url_google_, "Y=Z")); | 866 EXPECT_TRUE(this->SetCookie(cs.get(), this->http_www_google_.url(), "Y=Z")); |
836 | 867 |
837 // This cookie does not match host. | 868 // This cookie does not match host. |
838 EXPECT_TRUE(this->SetCookie(cs.get(), url_not_google, "E=F")); | 869 EXPECT_TRUE(this->SetCookie(cs.get(), url_not_google, "E=F")); |
839 | 870 |
840 // Delete cookies. | 871 // Delete cookies. |
841 EXPECT_EQ( | 872 EXPECT_EQ( |
842 3, // Deletes A=B, C=D, Y=Z | 873 3, // Deletes A=B, C=D, Y=Z |
843 this->DeleteAllCreatedBetweenForHost( | 874 this->DeleteAllCreatedBetweenForHost(cs.get(), now, base::Time::Max(), |
844 cs.get(), now, base::Time::Max(), this->url_google_)); | 875 this->http_www_google_.url())); |
845 } | 876 } |
846 | 877 |
847 TYPED_TEST_P(CookieStoreTest, TestSecure) { | 878 TYPED_TEST_P(CookieStoreTest, TestSecure) { |
848 scoped_refptr<CookieStore> cs(this->GetCookieStore()); | 879 scoped_refptr<CookieStore> cs(this->GetCookieStore()); |
849 | 880 |
850 EXPECT_TRUE(this->SetCookie(cs.get(), this->url_google_, "A=B")); | 881 EXPECT_TRUE(this->SetCookie(cs.get(), this->http_www_google_.url(), "A=B")); |
851 this->MatchCookieLines("A=B", | |
852 this->GetCookies(cs.get(), this->url_google_)); | |
853 this->MatchCookieLines( | 882 this->MatchCookieLines( |
854 "A=B", this->GetCookies(cs.get(), this->url_google_secure_)); | 883 "A=B", this->GetCookies(cs.get(), this->http_www_google_.url())); |
| 884 this->MatchCookieLines( |
| 885 "A=B", this->GetCookies(cs.get(), this->https_www_google_.url())); |
855 | 886 |
856 EXPECT_TRUE( | 887 EXPECT_TRUE(this->SetCookie(cs.get(), this->https_www_google_.url(), |
857 this->SetCookie(cs.get(), this->url_google_secure_, "A=B; secure")); | 888 "A=B; secure")); |
858 // The secure should overwrite the non-secure. | 889 // The secure should overwrite the non-secure. |
859 this->MatchCookieLines(std::string(), | 890 this->MatchCookieLines( |
860 this->GetCookies(cs.get(), this->url_google_)); | 891 std::string(), |
861 this->MatchCookieLines("A=B", | 892 this->GetCookies(cs.get(), this->http_www_google_.url())); |
862 this->GetCookies(cs.get(), this->url_google_secure_)); | 893 this->MatchCookieLines( |
| 894 "A=B", this->GetCookies(cs.get(), this->https_www_google_.url())); |
863 | 895 |
864 EXPECT_TRUE( | 896 EXPECT_TRUE(this->SetCookie(cs.get(), this->https_www_google_.url(), |
865 this->SetCookie(cs.get(), this->url_google_secure_, "D=E; secure")); | 897 "D=E; secure")); |
866 this->MatchCookieLines(std::string(), | 898 this->MatchCookieLines( |
867 this->GetCookies(cs.get(), this->url_google_)); | 899 std::string(), |
868 this->MatchCookieLines("A=B; D=E", | 900 this->GetCookies(cs.get(), this->http_www_google_.url())); |
869 this->GetCookies(cs.get(), this->url_google_secure_)); | 901 this->MatchCookieLines( |
| 902 "A=B; D=E", this->GetCookies(cs.get(), this->https_www_google_.url())); |
870 | 903 |
871 EXPECT_TRUE(this->SetCookie(cs.get(), this->url_google_secure_, "A=B")); | 904 EXPECT_TRUE( |
| 905 this->SetCookie(cs.get(), this->https_www_google_.url(), "A=B")); |
872 // The non-secure should overwrite the secure. | 906 // The non-secure should overwrite the secure. |
873 this->MatchCookieLines("A=B", this->GetCookies(cs.get(), this->url_google_)); | 907 this->MatchCookieLines( |
874 this->MatchCookieLines("D=E; A=B", | 908 "A=B", this->GetCookies(cs.get(), this->http_www_google_.url())); |
875 this->GetCookies(cs.get(), this->url_google_secure_)); | 909 this->MatchCookieLines( |
| 910 "D=E; A=B", this->GetCookies(cs.get(), this->https_www_google_.url())); |
876 } | 911 } |
877 | 912 |
878 static const int kLastAccessThresholdMilliseconds = 200; | 913 static const int kLastAccessThresholdMilliseconds = 200; |
879 | 914 |
880 // Formerly NetUtilTest.CookieTest back when we used wininet's cookie handling. | 915 // Formerly NetUtilTest.CookieTest back when we used wininet's cookie handling. |
881 TYPED_TEST_P(CookieStoreTest, NetUtilCookieTest) { | 916 TYPED_TEST_P(CookieStoreTest, NetUtilCookieTest) { |
882 const GURL test_url("http://mojo.jojo.google.izzle/"); | 917 const GURL test_url("http://mojo.jojo.google.izzle/"); |
883 | 918 |
884 scoped_refptr<CookieStore> cs(this->GetCookieStore()); | 919 scoped_refptr<CookieStore> cs(this->GetCookieStore()); |
885 | 920 |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
986 EXPECT_TRUE(this->SetCookie( | 1021 EXPECT_TRUE(this->SetCookie( |
987 cs.get(), GURL("http://news.bbc.co.uk/midpath/x.html"), "g=10")); | 1022 cs.get(), GURL("http://news.bbc.co.uk/midpath/x.html"), "g=10")); |
988 EXPECT_EQ("d=1; a=4; e=1; b=1; c=1", | 1023 EXPECT_EQ("d=1; a=4; e=1; b=1; c=1", |
989 this->GetCookies(cs.get(), | 1024 this->GetCookies(cs.get(), |
990 GURL("http://d.c.b.a.google.com/aa/bb/cc/dd"))); | 1025 GURL("http://d.c.b.a.google.com/aa/bb/cc/dd"))); |
991 } | 1026 } |
992 | 1027 |
993 TYPED_TEST_P(CookieStoreTest, DeleteSessionCookie) { | 1028 TYPED_TEST_P(CookieStoreTest, DeleteSessionCookie) { |
994 scoped_refptr<CookieStore> cs(this->GetCookieStore()); | 1029 scoped_refptr<CookieStore> cs(this->GetCookieStore()); |
995 // Create a session cookie and a persistent cookie. | 1030 // Create a session cookie and a persistent cookie. |
| 1031 EXPECT_TRUE(this->SetCookie(cs.get(), this->http_www_google_.url(), |
| 1032 std::string(kValidCookieLine))); |
996 EXPECT_TRUE(this->SetCookie( | 1033 EXPECT_TRUE(this->SetCookie( |
997 cs.get(), this->url_google_, std::string(kValidCookieLine))); | 1034 cs.get(), this->http_www_google_.url(), |
998 EXPECT_TRUE(this->SetCookie(cs.get(), | 1035 this->http_www_google_.Format("C=D; path=/; domain=%D;" |
999 this->url_google_, | 1036 "expires=Mon, 18-Apr-22 22:50:13 GMT"))); |
1000 "C=D; path=/; domain=google.izzle;" | 1037 this->MatchCookieLines( |
1001 "expires=Mon, 18-Apr-22 22:50:13 GMT")); | 1038 "A=B; C=D", this->GetCookies(cs.get(), this->http_www_google_.url())); |
1002 this->MatchCookieLines("A=B; C=D", | |
1003 this->GetCookies(cs.get(), this->url_google_)); | |
1004 // Delete the session cookie. | 1039 // Delete the session cookie. |
1005 this->DeleteSessionCookies(cs.get()); | 1040 this->DeleteSessionCookies(cs.get()); |
1006 // Check that the session cookie has been deleted but not the persistent one. | 1041 // Check that the session cookie has been deleted but not the persistent one. |
1007 EXPECT_EQ("C=D", this->GetCookies(cs.get(), this->url_google_)); | 1042 EXPECT_EQ("C=D", this->GetCookies(cs.get(), this->http_www_google_.url())); |
1008 } | 1043 } |
1009 | 1044 |
1010 REGISTER_TYPED_TEST_CASE_P(CookieStoreTest, | 1045 REGISTER_TYPED_TEST_CASE_P(CookieStoreTest, |
1011 TypeTest, | 1046 TypeTest, |
1012 DomainTest, | 1047 DomainTest, |
1013 DomainWithTrailingDotTest, | 1048 DomainWithTrailingDotTest, |
1014 ValidSubdomainTest, | 1049 ValidSubdomainTest, |
1015 InvalidDomainTest, | 1050 InvalidDomainTest, |
1016 DomainWithoutLeadingDotTest, | 1051 DomainWithoutLeadingDotTest, |
1017 CaseInsensitiveDomainTest, | 1052 CaseInsensitiveDomainTest, |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1103 Thread other_thread_; | 1138 Thread other_thread_; |
1104 }; | 1139 }; |
1105 | 1140 |
1106 TYPED_TEST_CASE_P(MultiThreadedCookieStoreTest); | 1141 TYPED_TEST_CASE_P(MultiThreadedCookieStoreTest); |
1107 | 1142 |
1108 // TODO(ycxiao): Eventually, we will need to create a separate thread, create | 1143 // TODO(ycxiao): Eventually, we will need to create a separate thread, create |
1109 // the cookie store on that thread (or at least its store, i.e., the DB | 1144 // the cookie store on that thread (or at least its store, i.e., the DB |
1110 // thread). | 1145 // thread). |
1111 TYPED_TEST_P(MultiThreadedCookieStoreTest, ThreadCheckGetCookies) { | 1146 TYPED_TEST_P(MultiThreadedCookieStoreTest, ThreadCheckGetCookies) { |
1112 scoped_refptr<CookieStore> cs(this->GetCookieStore()); | 1147 scoped_refptr<CookieStore> cs(this->GetCookieStore()); |
1113 EXPECT_TRUE(this->SetCookie(cs.get(), this->url_google_, "A=B")); | 1148 EXPECT_TRUE(this->SetCookie(cs.get(), this->http_www_google_.url(), "A=B")); |
1114 this->MatchCookieLines("A=B", this->GetCookies(cs.get(), this->url_google_)); | 1149 this->MatchCookieLines( |
| 1150 "A=B", this->GetCookies(cs.get(), this->http_www_google_.url())); |
1115 StringResultCookieCallback callback(&this->other_thread_); | 1151 StringResultCookieCallback callback(&this->other_thread_); |
1116 base::Closure task = | 1152 base::Closure task = base::Bind( |
1117 base::Bind(&MultiThreadedCookieStoreTest<TypeParam>::GetCookiesTask, | 1153 &MultiThreadedCookieStoreTest<TypeParam>::GetCookiesTask, |
1118 base::Unretained(this), cs, this->url_google_, &callback); | 1154 base::Unretained(this), cs, this->http_www_google_.url(), &callback); |
1119 this->RunOnOtherThread(task); | 1155 this->RunOnOtherThread(task); |
1120 EXPECT_TRUE(callback.did_run()); | 1156 EXPECT_TRUE(callback.did_run()); |
1121 EXPECT_EQ("A=B", callback.result()); | 1157 EXPECT_EQ("A=B", callback.result()); |
1122 } | 1158 } |
1123 | 1159 |
1124 TYPED_TEST_P(MultiThreadedCookieStoreTest, ThreadCheckGetCookiesWithOptions) { | 1160 TYPED_TEST_P(MultiThreadedCookieStoreTest, ThreadCheckGetCookiesWithOptions) { |
1125 scoped_refptr<CookieStore> cs(this->GetCookieStore()); | 1161 scoped_refptr<CookieStore> cs(this->GetCookieStore()); |
1126 CookieOptions options; | 1162 CookieOptions options; |
1127 if (!TypeParam::supports_http_only) | 1163 if (!TypeParam::supports_http_only) |
1128 options.set_include_httponly(); | 1164 options.set_include_httponly(); |
1129 EXPECT_TRUE(this->SetCookie(cs.get(), this->url_google_, "A=B")); | 1165 EXPECT_TRUE(this->SetCookie(cs.get(), this->http_www_google_.url(), "A=B")); |
1130 this->MatchCookieLines( | 1166 this->MatchCookieLines( |
1131 "A=B", this->GetCookiesWithOptions(cs.get(), this->url_google_, options)); | 1167 "A=B", this->GetCookiesWithOptions(cs.get(), this->http_www_google_.url(), |
| 1168 options)); |
1132 StringResultCookieCallback callback(&this->other_thread_); | 1169 StringResultCookieCallback callback(&this->other_thread_); |
1133 base::Closure task = base::Bind( | 1170 base::Closure task = base::Bind( |
1134 &MultiThreadedCookieStoreTest<TypeParam>::GetCookiesWithOptionsTask, | 1171 &MultiThreadedCookieStoreTest<TypeParam>::GetCookiesWithOptionsTask, |
1135 base::Unretained(this), cs, this->url_google_, options, &callback); | 1172 base::Unretained(this), cs, this->http_www_google_.url(), options, |
| 1173 &callback); |
1136 this->RunOnOtherThread(task); | 1174 this->RunOnOtherThread(task); |
1137 EXPECT_TRUE(callback.did_run()); | 1175 EXPECT_TRUE(callback.did_run()); |
1138 EXPECT_EQ("A=B", callback.result()); | 1176 EXPECT_EQ("A=B", callback.result()); |
1139 } | 1177 } |
1140 | 1178 |
1141 TYPED_TEST_P(MultiThreadedCookieStoreTest, ThreadCheckSetCookieWithOptions) { | 1179 TYPED_TEST_P(MultiThreadedCookieStoreTest, ThreadCheckSetCookieWithOptions) { |
1142 scoped_refptr<CookieStore> cs(this->GetCookieStore()); | 1180 scoped_refptr<CookieStore> cs(this->GetCookieStore()); |
1143 CookieOptions options; | 1181 CookieOptions options; |
1144 if (!TypeParam::supports_http_only) | 1182 if (!TypeParam::supports_http_only) |
1145 options.set_include_httponly(); | 1183 options.set_include_httponly(); |
1146 EXPECT_TRUE( | 1184 EXPECT_TRUE(this->SetCookieWithOptions(cs.get(), this->http_www_google_.url(), |
1147 this->SetCookieWithOptions(cs.get(), this->url_google_, "A=B", options)); | 1185 "A=B", options)); |
1148 ResultSavingCookieCallback<bool> callback(&this->other_thread_); | 1186 ResultSavingCookieCallback<bool> callback(&this->other_thread_); |
1149 base::Closure task = base::Bind( | 1187 base::Closure task = base::Bind( |
1150 &MultiThreadedCookieStoreTest<TypeParam>::SetCookieWithOptionsTask, | 1188 &MultiThreadedCookieStoreTest<TypeParam>::SetCookieWithOptionsTask, |
1151 base::Unretained(this), cs, this->url_google_, "A=B", options, &callback); | 1189 base::Unretained(this), cs, this->http_www_google_.url(), "A=B", options, |
| 1190 &callback); |
1152 this->RunOnOtherThread(task); | 1191 this->RunOnOtherThread(task); |
1153 EXPECT_TRUE(callback.did_run()); | 1192 EXPECT_TRUE(callback.did_run()); |
1154 EXPECT_TRUE(callback.result()); | 1193 EXPECT_TRUE(callback.result()); |
1155 } | 1194 } |
1156 | 1195 |
1157 TYPED_TEST_P(MultiThreadedCookieStoreTest, ThreadCheckDeleteCookie) { | 1196 TYPED_TEST_P(MultiThreadedCookieStoreTest, ThreadCheckDeleteCookie) { |
1158 scoped_refptr<CookieStore> cs(this->GetCookieStore()); | 1197 scoped_refptr<CookieStore> cs(this->GetCookieStore()); |
1159 CookieOptions options; | 1198 CookieOptions options; |
1160 if (!TypeParam::supports_http_only) | 1199 if (!TypeParam::supports_http_only) |
1161 options.set_include_httponly(); | 1200 options.set_include_httponly(); |
1162 EXPECT_TRUE( | 1201 EXPECT_TRUE(this->SetCookieWithOptions(cs.get(), this->http_www_google_.url(), |
1163 this->SetCookieWithOptions(cs.get(), this->url_google_, "A=B", options)); | 1202 "A=B", options)); |
1164 this->DeleteCookie(cs.get(), this->url_google_, "A"); | 1203 this->DeleteCookie(cs.get(), this->http_www_google_.url(), "A"); |
1165 EXPECT_TRUE( | 1204 EXPECT_TRUE(this->SetCookieWithOptions(cs.get(), this->http_www_google_.url(), |
1166 this->SetCookieWithOptions(cs.get(), this->url_google_, "A=B", options)); | 1205 "A=B", options)); |
1167 NoResultCookieCallback callback(&this->other_thread_); | 1206 NoResultCookieCallback callback(&this->other_thread_); |
1168 base::Closure task = | 1207 base::Closure task = base::Bind( |
1169 base::Bind(&MultiThreadedCookieStoreTest<TypeParam>::DeleteCookieTask, | 1208 &MultiThreadedCookieStoreTest<TypeParam>::DeleteCookieTask, |
1170 base::Unretained(this), cs, this->url_google_, "A", &callback); | 1209 base::Unretained(this), cs, this->http_www_google_.url(), "A", &callback); |
1171 this->RunOnOtherThread(task); | 1210 this->RunOnOtherThread(task); |
1172 EXPECT_TRUE(callback.did_run()); | 1211 EXPECT_TRUE(callback.did_run()); |
1173 } | 1212 } |
1174 | 1213 |
1175 TYPED_TEST_P(MultiThreadedCookieStoreTest, ThreadCheckDeleteSessionCookies) { | 1214 TYPED_TEST_P(MultiThreadedCookieStoreTest, ThreadCheckDeleteSessionCookies) { |
1176 scoped_refptr<CookieStore> cs(this->GetCookieStore()); | 1215 scoped_refptr<CookieStore> cs(this->GetCookieStore()); |
1177 CookieOptions options; | 1216 CookieOptions options; |
1178 if (!TypeParam::supports_http_only) | 1217 if (!TypeParam::supports_http_only) |
1179 options.set_include_httponly(); | 1218 options.set_include_httponly(); |
1180 EXPECT_TRUE( | 1219 EXPECT_TRUE(this->SetCookieWithOptions(cs.get(), this->http_www_google_.url(), |
1181 this->SetCookieWithOptions(cs.get(), this->url_google_, "A=B", options)); | 1220 "A=B", options)); |
1182 EXPECT_TRUE( | 1221 EXPECT_TRUE(this->SetCookieWithOptions( |
1183 this->SetCookieWithOptions(cs.get(), | 1222 cs.get(), this->http_www_google_.url(), |
1184 this->url_google_, | 1223 "B=C; expires=Mon, 18-Apr-22 22:50:13 GMT", options)); |
1185 "B=C; expires=Mon, 18-Apr-22 22:50:13 GMT", | |
1186 options)); | |
1187 EXPECT_EQ(1, this->DeleteSessionCookies(cs.get())); | 1224 EXPECT_EQ(1, this->DeleteSessionCookies(cs.get())); |
1188 EXPECT_EQ(0, this->DeleteSessionCookies(cs.get())); | 1225 EXPECT_EQ(0, this->DeleteSessionCookies(cs.get())); |
1189 EXPECT_TRUE( | 1226 EXPECT_TRUE(this->SetCookieWithOptions(cs.get(), this->http_www_google_.url(), |
1190 this->SetCookieWithOptions(cs.get(), this->url_google_, "A=B", options)); | 1227 "A=B", options)); |
1191 ResultSavingCookieCallback<int> callback(&this->other_thread_); | 1228 ResultSavingCookieCallback<int> callback(&this->other_thread_); |
1192 base::Closure task = base::Bind( | 1229 base::Closure task = base::Bind( |
1193 &MultiThreadedCookieStoreTest<TypeParam>::DeleteSessionCookiesTask, | 1230 &MultiThreadedCookieStoreTest<TypeParam>::DeleteSessionCookiesTask, |
1194 base::Unretained(this), cs, &callback); | 1231 base::Unretained(this), cs, &callback); |
1195 this->RunOnOtherThread(task); | 1232 this->RunOnOtherThread(task); |
1196 EXPECT_TRUE(callback.did_run()); | 1233 EXPECT_TRUE(callback.did_run()); |
1197 EXPECT_EQ(1, callback.result()); | 1234 EXPECT_EQ(1, callback.result()); |
1198 } | 1235 } |
1199 | 1236 |
1200 REGISTER_TYPED_TEST_CASE_P(MultiThreadedCookieStoreTest, | 1237 REGISTER_TYPED_TEST_CASE_P(MultiThreadedCookieStoreTest, |
1201 ThreadCheckGetCookies, | 1238 ThreadCheckGetCookies, |
1202 ThreadCheckGetCookiesWithOptions, | 1239 ThreadCheckGetCookiesWithOptions, |
1203 ThreadCheckSetCookieWithOptions, | 1240 ThreadCheckSetCookieWithOptions, |
1204 ThreadCheckDeleteCookie, | 1241 ThreadCheckDeleteCookie, |
1205 ThreadCheckDeleteSessionCookies); | 1242 ThreadCheckDeleteSessionCookies); |
1206 | 1243 |
1207 } // namespace net | 1244 } // namespace net |
1208 | 1245 |
1209 #endif // NET_COOKIES_COOKIE_STORE_UNITTEST_H_ | 1246 #endif // NET_COOKIES_COOKIE_STORE_UNITTEST_H_ |
OLD | NEW |