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> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 // // The cookie store rejects cookies for invalid schemes such as ftp. | 58 // // The cookie store rejects cookies for invalid schemes such as ftp. |
59 // static const bool filters_schemes; | 59 // static const bool filters_schemes; |
60 // | 60 // |
61 // // The cookie store has a bug happening when a path is a substring of | 61 // // The cookie store has a bug happening when a path is a substring of |
62 // // another. | 62 // // another. |
63 // static const bool has_path_prefix_bug; | 63 // static const bool has_path_prefix_bug; |
64 // | 64 // |
65 // // Time to wait between two cookie insertions to ensure that cookies have | 65 // // Time to wait between two cookie insertions to ensure that cookies have |
66 // // different creation times. | 66 // // different creation times. |
67 // static const int creation_time_granularity_in_ms; | 67 // static const int creation_time_granularity_in_ms; |
68 // | |
69 // // The cookie store enforces secure flag requires a secure scheme. | |
70 // static const bool enforce_strict_secure; | |
71 // }; | 68 // }; |
72 | 69 |
73 template <class CookieStoreTestTraits> | 70 template <class CookieStoreTestTraits> |
74 class CookieStoreTest : public testing::Test { | 71 class CookieStoreTest : public testing::Test { |
75 protected: | 72 protected: |
76 CookieStoreTest() | 73 CookieStoreTest() |
77 : http_www_google_("http://www.google.izzle"), | 74 : http_www_google_("http://www.google.izzle"), |
78 https_www_google_("https://www.google.izzle"), | 75 https_www_google_("https://www.google.izzle"), |
79 ftp_google_("ftp://ftp.google.izzle/"), | 76 ftp_google_("ftp://ftp.google.izzle/"), |
80 ws_www_google_("ws://www.google.izzle"), | 77 ws_www_google_("ws://www.google.izzle"), |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 const base::Time expiration_time, | 167 const base::Time expiration_time, |
171 const base::Time last_access_time, | 168 const base::Time last_access_time, |
172 bool secure, | 169 bool secure, |
173 bool http_only, | 170 bool http_only, |
174 CookieSameSite same_site, | 171 CookieSameSite same_site, |
175 CookiePriority priority) { | 172 CookiePriority priority) { |
176 DCHECK(cs); | 173 DCHECK(cs); |
177 ResultSavingCookieCallback<bool> callback; | 174 ResultSavingCookieCallback<bool> callback; |
178 cs->SetCookieWithDetailsAsync( | 175 cs->SetCookieWithDetailsAsync( |
179 url, name, value, domain, path, creation_time, expiration_time, | 176 url, name, value, domain, path, creation_time, expiration_time, |
180 last_access_time, secure, http_only, same_site, | 177 last_access_time, secure, http_only, same_site, priority, |
181 false /* enforces strict secure cookies */, priority, | |
182 base::Bind(&ResultSavingCookieCallback<bool>::Run, | 178 base::Bind(&ResultSavingCookieCallback<bool>::Run, |
183 base::Unretained(&callback))); | 179 base::Unretained(&callback))); |
184 callback.WaitUntilDone(); | 180 callback.WaitUntilDone(); |
185 return callback.result(); | 181 return callback.result(); |
186 } | 182 } |
187 | 183 |
188 bool SetCookieWithServerTime(CookieStore* cs, | 184 bool SetCookieWithServerTime(CookieStore* cs, |
189 const GURL& url, | 185 const GURL& url, |
190 const std::string& cookie_line, | 186 const std::string& cookie_line, |
191 const base::Time& server_time) { | 187 const base::Time& server_time) { |
192 CookieOptions options; | 188 CookieOptions options; |
193 if (!CookieStoreTestTraits::supports_http_only) | 189 if (!CookieStoreTestTraits::supports_http_only) |
194 options.set_include_httponly(); | 190 options.set_include_httponly(); |
195 options.set_server_time(server_time); | 191 options.set_server_time(server_time); |
196 return SetCookieWithOptions(cs, url, cookie_line, options); | 192 return SetCookieWithOptions(cs, url, cookie_line, options); |
197 } | 193 } |
198 | 194 |
199 bool SetCookie(CookieStore* cs, | 195 bool SetCookie(CookieStore* cs, |
200 const GURL& url, | 196 const GURL& url, |
201 const std::string& cookie_line) { | 197 const std::string& cookie_line) { |
202 CookieOptions options; | 198 CookieOptions options; |
203 if (!CookieStoreTestTraits::supports_http_only) | 199 if (!CookieStoreTestTraits::supports_http_only) |
204 options.set_include_httponly(); | 200 options.set_include_httponly(); |
205 if (CookieStoreTestTraits::enforce_strict_secure) | |
206 options.set_enforce_strict_secure(); | |
207 return SetCookieWithOptions(cs, url, cookie_line, options); | 201 return SetCookieWithOptions(cs, url, cookie_line, options); |
208 } | 202 } |
209 | 203 |
210 void DeleteCookie(CookieStore* cs, | 204 void DeleteCookie(CookieStore* cs, |
211 const GURL& url, | 205 const GURL& url, |
212 const std::string& cookie_name) { | 206 const std::string& cookie_name) { |
213 DCHECK(cs); | 207 DCHECK(cs); |
214 NoResultCookieCallback callback; | 208 NoResultCookieCallback callback; |
215 cs->DeleteCookieAsync( | 209 cs->DeleteCookieAsync( |
216 url, cookie_name, | 210 url, cookie_name, |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 EXPECT_TRUE(this->SetCookieWithDetails( | 342 EXPECT_TRUE(this->SetCookieWithDetails( |
349 cs, this->www_google_foo_.url(), "A", "B", std::string(), "/foo", | 343 cs, this->www_google_foo_.url(), "A", "B", std::string(), "/foo", |
350 one_hour_ago, one_hour_from_now, base::Time(), false, false, | 344 one_hour_ago, one_hour_from_now, base::Time(), false, false, |
351 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT)); | 345 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT)); |
352 // Note that for the creation time to be set exactly, without modification, | 346 // Note that for the creation time to be set exactly, without modification, |
353 // it must be different from the one set by the line above. | 347 // it must be different from the one set by the line above. |
354 EXPECT_TRUE(this->SetCookieWithDetails( | 348 EXPECT_TRUE(this->SetCookieWithDetails( |
355 cs, this->www_google_bar_.url(), "C", "D", this->www_google_bar_.domain(), | 349 cs, this->www_google_bar_.url(), "C", "D", this->www_google_bar_.domain(), |
356 "/bar", two_hours_ago, base::Time(), one_hour_ago, false, true, | 350 "/bar", two_hours_ago, base::Time(), one_hour_ago, false, true, |
357 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT)); | 351 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT)); |
| 352 // Because of strict secure cookies, a cookie made by an HTTP URL should fail |
| 353 // to create a cookie with a the secure attribute. |
| 354 EXPECT_FALSE(this->SetCookieWithDetails( |
| 355 cs, this->http_www_google_.url(), "E", "F", std::string(), std::string(), |
| 356 base::Time(), base::Time(), base::Time(), true, false, |
| 357 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT)); |
358 EXPECT_TRUE(this->SetCookieWithDetails( | 358 EXPECT_TRUE(this->SetCookieWithDetails( |
359 cs, this->http_www_google_.url(), "E", "F", std::string(), std::string(), | 359 cs, this->https_www_google_.url(), "E", "F", std::string(), std::string(), |
360 base::Time(), base::Time(), base::Time(), true, false, | 360 base::Time(), base::Time(), base::Time(), true, false, |
361 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT)); | 361 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT)); |
362 | 362 |
363 // Test that malformed attributes fail to set the cookie. | 363 // Test that malformed attributes fail to set the cookie. |
364 EXPECT_FALSE(this->SetCookieWithDetails( | 364 EXPECT_FALSE(this->SetCookieWithDetails( |
365 cs, this->www_google_foo_.url(), " A", "B", std::string(), "/foo", | 365 cs, this->www_google_foo_.url(), " A", "B", std::string(), "/foo", |
366 base::Time(), base::Time(), base::Time(), false, false, | 366 base::Time(), base::Time(), base::Time(), false, false, |
367 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT)); | 367 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT)); |
368 EXPECT_FALSE(this->SetCookieWithDetails( | 368 EXPECT_FALSE(this->SetCookieWithDetails( |
369 cs, this->www_google_foo_.url(), "A;", "B", std::string(), "/foo", | 369 cs, this->www_google_foo_.url(), "A;", "B", std::string(), "/foo", |
(...skipping 1086 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1456 OverwritePersistentCookie, | 1456 OverwritePersistentCookie, |
1457 CookieOrdering, | 1457 CookieOrdering, |
1458 GetAllCookiesAsync, | 1458 GetAllCookiesAsync, |
1459 DeleteCookieAsync, | 1459 DeleteCookieAsync, |
1460 DeleteCanonicalCookieAsync, | 1460 DeleteCanonicalCookieAsync, |
1461 DeleteSessionCookie); | 1461 DeleteSessionCookie); |
1462 | 1462 |
1463 } // namespace net | 1463 } // namespace net |
1464 | 1464 |
1465 #endif // NET_COOKIES_COOKIE_STORE_UNITTEST_H_ | 1465 #endif // NET_COOKIES_COOKIE_STORE_UNITTEST_H_ |
OLD | NEW |