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 "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/string_tokenizer.h" | 10 #include "base/string_tokenizer.h" |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 DCHECK(cs); | 140 DCHECK(cs); |
141 SetCookieCallback callback; | 141 SetCookieCallback callback; |
142 cs->SetCookieWithOptionsAsync( | 142 cs->SetCookieWithOptionsAsync( |
143 url, cookie_line, options, | 143 url, cookie_line, options, |
144 base::Bind(&SetCookieCallback::Run, base::Unretained(&callback))); | 144 base::Bind(&SetCookieCallback::Run, base::Unretained(&callback))); |
145 RunFor(kTimeout); | 145 RunFor(kTimeout); |
146 EXPECT_TRUE(callback.did_run()); | 146 EXPECT_TRUE(callback.did_run()); |
147 return callback.result(); | 147 return callback.result(); |
148 } | 148 } |
149 | 149 |
| 150 bool SetCookieWithServerTime(CookieStore* cs, |
| 151 const GURL& url, |
| 152 const std::string& cookie_line, |
| 153 const base::Time& server_time) { |
| 154 CookieOptions options; |
| 155 if (!CookieStoreTestTraits::supports_http_only) |
| 156 options.set_include_httponly(); |
| 157 options.set_server_time(server_time); |
| 158 return SetCookieWithOptions(cs, url, cookie_line, options); |
| 159 } |
| 160 |
150 bool SetCookie(CookieStore* cs, | 161 bool SetCookie(CookieStore* cs, |
151 const GURL& url, | 162 const GURL& url, |
152 const std::string& cookie_line) { | 163 const std::string& cookie_line) { |
153 CookieOptions options; | 164 CookieOptions options; |
154 if (!CookieStoreTestTraits::supports_http_only) | 165 if (!CookieStoreTestTraits::supports_http_only) |
155 options.set_include_httponly(); | 166 options.set_include_httponly(); |
156 return SetCookieWithOptions(cs, url, cookie_line, options); | 167 return SetCookieWithOptions(cs, url, cookie_line, options); |
157 } | 168 } |
158 | 169 |
159 void DeleteCookie(CookieStore* cs, | 170 void DeleteCookie(CookieStore* cs, |
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
695 EXPECT_TRUE(this->SetCookie(cs, this->url_google_, | 706 EXPECT_TRUE(this->SetCookie(cs, this->url_google_, |
696 std::string(kValidCookieLine) + | 707 std::string(kValidCookieLine) + |
697 "; expires=Mon, 18-Apr-1977 22:50:13 GMT")); | 708 "; expires=Mon, 18-Apr-1977 22:50:13 GMT")); |
698 this->MatchCookieLines("", this->GetCookies(cs, this->url_google_)); | 709 this->MatchCookieLines("", this->GetCookies(cs, this->url_google_)); |
699 | 710 |
700 // Create a persistent cookie. | 711 // Create a persistent cookie. |
701 EXPECT_TRUE(this->SetCookie(cs, this->url_google_, | 712 EXPECT_TRUE(this->SetCookie(cs, this->url_google_, |
702 std::string(kValidCookieLine) + | 713 std::string(kValidCookieLine) + |
703 "; expires=Mon, 18-Apr-22 22:50:13 GMT")); | 714 "; expires=Mon, 18-Apr-22 22:50:13 GMT")); |
704 this->MatchCookieLines("A=B", this->GetCookies(cs, this->url_google_)); | 715 this->MatchCookieLines("A=B", this->GetCookies(cs, this->url_google_)); |
| 716 // Check that it is not deleted with significant enough clock skew. |
| 717 base::Time server_time; |
| 718 EXPECT_TRUE(base::Time::FromString("Sun, 17-Apr-1977 22:50:13 GMT", |
| 719 &server_time)); |
| 720 EXPECT_TRUE(this->SetCookieWithServerTime( |
| 721 cs, this->url_google_, |
| 722 std::string(kValidCookieLine) + |
| 723 "; expires=Mon, 18-Apr-1977 22:50:13 GMT", |
| 724 server_time)); |
| 725 this->MatchCookieLines("A=B", this->GetCookies(cs, this->url_google_)); |
| 726 |
| 727 // Create a persistent cookie. |
| 728 EXPECT_TRUE(this->SetCookie(cs, this->url_google_, |
| 729 std::string(kValidCookieLine) + |
| 730 "; expires=Mon, 18-Apr-22 22:50:13 GMT")); |
| 731 this->MatchCookieLines("A=B", this->GetCookies(cs, this->url_google_)); |
705 // Delete it via Expires, with a unix epoch of 0. | 732 // Delete it via Expires, with a unix epoch of 0. |
706 EXPECT_TRUE(this->SetCookie(cs, this->url_google_, | 733 EXPECT_TRUE(this->SetCookie(cs, this->url_google_, |
707 std::string(kValidCookieLine) + | 734 std::string(kValidCookieLine) + |
708 "; expires=Thu, 1-Jan-1970 00:00:00 GMT")); | 735 "; expires=Thu, 1-Jan-1970 00:00:00 GMT")); |
709 this->MatchCookieLines("", this->GetCookies(cs, this->url_google_)); | 736 this->MatchCookieLines("", this->GetCookies(cs, this->url_google_)); |
710 } | 737 } |
711 | 738 |
712 TYPED_TEST_P(CookieStoreTest, TestDeleteAllCreatedBetween) { | 739 TYPED_TEST_P(CookieStoreTest, TestDeleteAllCreatedBetween) { |
713 scoped_refptr<CookieStore> cs(this->GetCookieStore()); | 740 scoped_refptr<CookieStore> cs(this->GetCookieStore()); |
714 const base::Time last_month = base::Time::Now() - | 741 const base::Time last_month = base::Time::Now() - |
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1083 } | 1110 } |
1084 | 1111 |
1085 REGISTER_TYPED_TEST_CASE_P(MultiThreadedCookieStoreTest, | 1112 REGISTER_TYPED_TEST_CASE_P(MultiThreadedCookieStoreTest, |
1086 ThreadCheckGetCookies, ThreadCheckGetCookiesWithOptions, | 1113 ThreadCheckGetCookies, ThreadCheckGetCookiesWithOptions, |
1087 ThreadCheckGetCookiesWithInfo, ThreadCheckSetCookieWithOptions, | 1114 ThreadCheckGetCookiesWithInfo, ThreadCheckSetCookieWithOptions, |
1088 ThreadCheckDeleteCookie, ThreadCheckDeleteSessionCookies); | 1115 ThreadCheckDeleteCookie, ThreadCheckDeleteSessionCookies); |
1089 | 1116 |
1090 } // namespace net | 1117 } // namespace net |
1091 | 1118 |
1092 #endif // NET_COOKIES_COOKIE_STORE_UNITTEST_H_ | 1119 #endif // NET_COOKIES_COOKIE_STORE_UNITTEST_H_ |
OLD | NEW |