OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/cookies/canonical_cookie.h" | 5 #include "net/cookies/canonical_cookie.h" |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include <memory> |
| 8 |
8 #include "base/test/histogram_tester.h" | 9 #include "base/test/histogram_tester.h" |
9 #include "net/cookies/cookie_constants.h" | 10 #include "net/cookies/cookie_constants.h" |
10 #include "net/cookies/cookie_options.h" | 11 #include "net/cookies/cookie_options.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
12 #include "url/gurl.h" | 13 #include "url/gurl.h" |
13 | 14 |
14 namespace net { | 15 namespace net { |
15 | 16 |
16 TEST(CanonicalCookieTest, Constructor) { | 17 TEST(CanonicalCookieTest, Constructor) { |
17 GURL url("http://www.example.com/test"); | 18 GURL url("http://www.example.com/test"); |
(...skipping 24 matching lines...) Expand all Loading... |
42 EXPECT_FALSE(cookie2.IsHttpOnly()); | 43 EXPECT_FALSE(cookie2.IsHttpOnly()); |
43 EXPECT_EQ(CookieSameSite::NO_RESTRICTION, cookie2.SameSite()); | 44 EXPECT_EQ(CookieSameSite::NO_RESTRICTION, cookie2.SameSite()); |
44 } | 45 } |
45 | 46 |
46 TEST(CanonicalCookieTest, Create) { | 47 TEST(CanonicalCookieTest, Create) { |
47 // Test creating cookies from a cookie string. | 48 // Test creating cookies from a cookie string. |
48 GURL url("http://www.example.com/test/foo.html"); | 49 GURL url("http://www.example.com/test/foo.html"); |
49 base::Time creation_time = base::Time::Now(); | 50 base::Time creation_time = base::Time::Now(); |
50 CookieOptions options; | 51 CookieOptions options; |
51 | 52 |
52 scoped_ptr<CanonicalCookie> cookie( | 53 std::unique_ptr<CanonicalCookie> cookie( |
53 CanonicalCookie::Create(url, "A=2", creation_time, options)); | 54 CanonicalCookie::Create(url, "A=2", creation_time, options)); |
54 EXPECT_EQ(url.GetOrigin(), cookie->Source()); | 55 EXPECT_EQ(url.GetOrigin(), cookie->Source()); |
55 EXPECT_EQ("A", cookie->Name()); | 56 EXPECT_EQ("A", cookie->Name()); |
56 EXPECT_EQ("2", cookie->Value()); | 57 EXPECT_EQ("2", cookie->Value()); |
57 EXPECT_EQ("www.example.com", cookie->Domain()); | 58 EXPECT_EQ("www.example.com", cookie->Domain()); |
58 EXPECT_EQ("/test", cookie->Path()); | 59 EXPECT_EQ("/test", cookie->Path()); |
59 EXPECT_FALSE(cookie->IsSecure()); | 60 EXPECT_FALSE(cookie->IsSecure()); |
60 | 61 |
61 GURL url2("http://www.foo.com"); | 62 GURL url2("http://www.foo.com"); |
62 cookie = CanonicalCookie::Create(url2, "B=1", creation_time, options); | 63 cookie = CanonicalCookie::Create(url2, "B=1", creation_time, options); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 EXPECT_EQ(".www.example.com", cookie->Domain()); | 120 EXPECT_EQ(".www.example.com", cookie->Domain()); |
120 EXPECT_EQ("/test", cookie->Path()); | 121 EXPECT_EQ("/test", cookie->Path()); |
121 EXPECT_FALSE(cookie->IsSecure()); | 122 EXPECT_FALSE(cookie->IsSecure()); |
122 EXPECT_FALSE(cookie->IsHttpOnly()); | 123 EXPECT_FALSE(cookie->IsHttpOnly()); |
123 EXPECT_EQ(CookieSameSite::NO_RESTRICTION, cookie->SameSite()); | 124 EXPECT_EQ(CookieSameSite::NO_RESTRICTION, cookie->SameSite()); |
124 } | 125 } |
125 | 126 |
126 TEST(CanonicalCookieTest, CreateInvalidSameSite) { | 127 TEST(CanonicalCookieTest, CreateInvalidSameSite) { |
127 GURL url("http://www.example.com/test/foo.html"); | 128 GURL url("http://www.example.com/test/foo.html"); |
128 base::Time now = base::Time::Now(); | 129 base::Time now = base::Time::Now(); |
129 scoped_ptr<CanonicalCookie> cookie; | 130 std::unique_ptr<CanonicalCookie> cookie; |
130 CookieOptions options; | 131 CookieOptions options; |
131 | 132 |
132 // Invalid 'SameSite' attribute values. | 133 // Invalid 'SameSite' attribute values. |
133 options.set_same_site_cookie_mode( | 134 options.set_same_site_cookie_mode( |
134 CookieOptions::SameSiteCookieMode::INCLUDE_STRICT_AND_LAX); | 135 CookieOptions::SameSiteCookieMode::INCLUDE_STRICT_AND_LAX); |
135 | 136 |
136 cookie = CanonicalCookie::Create(url, "A=2; SameSite=Invalid", now, options); | 137 cookie = CanonicalCookie::Create(url, "A=2; SameSite=Invalid", now, options); |
137 EXPECT_EQ(nullptr, cookie.get()); | 138 EXPECT_EQ(nullptr, cookie.get()); |
138 | 139 |
139 cookie = CanonicalCookie::Create(url, "A=2; SameSite", now, options); | 140 cookie = CanonicalCookie::Create(url, "A=2; SameSite", now, options); |
140 EXPECT_EQ(nullptr, cookie.get()); | 141 EXPECT_EQ(nullptr, cookie.get()); |
141 } | 142 } |
142 | 143 |
143 TEST(CanonicalCookieTest, EmptyExpiry) { | 144 TEST(CanonicalCookieTest, EmptyExpiry) { |
144 GURL url("http://www7.ipdl.inpit.go.jp/Tokujitu/tjkta.ipdl?N0000=108"); | 145 GURL url("http://www7.ipdl.inpit.go.jp/Tokujitu/tjkta.ipdl?N0000=108"); |
145 base::Time creation_time = base::Time::Now(); | 146 base::Time creation_time = base::Time::Now(); |
146 CookieOptions options; | 147 CookieOptions options; |
147 | 148 |
148 std::string cookie_line = | 149 std::string cookie_line = |
149 "ACSTM=20130308043820420042; path=/; domain=ipdl.inpit.go.jp; Expires="; | 150 "ACSTM=20130308043820420042; path=/; domain=ipdl.inpit.go.jp; Expires="; |
150 scoped_ptr<CanonicalCookie> cookie( | 151 std::unique_ptr<CanonicalCookie> cookie( |
151 CanonicalCookie::Create(url, cookie_line, creation_time, options)); | 152 CanonicalCookie::Create(url, cookie_line, creation_time, options)); |
152 EXPECT_TRUE(cookie.get()); | 153 EXPECT_TRUE(cookie.get()); |
153 EXPECT_FALSE(cookie->IsPersistent()); | 154 EXPECT_FALSE(cookie->IsPersistent()); |
154 EXPECT_FALSE(cookie->IsExpired(creation_time)); | 155 EXPECT_FALSE(cookie->IsExpired(creation_time)); |
155 EXPECT_EQ(base::Time(), cookie->ExpiryDate()); | 156 EXPECT_EQ(base::Time(), cookie->ExpiryDate()); |
156 | 157 |
157 // With a stale server time | 158 // With a stale server time |
158 options.set_server_time(creation_time - base::TimeDelta::FromHours(1)); | 159 options.set_server_time(creation_time - base::TimeDelta::FromHours(1)); |
159 cookie = CanonicalCookie::Create(url, cookie_line, creation_time, options); | 160 cookie = CanonicalCookie::Create(url, cookie_line, creation_time, options); |
160 EXPECT_TRUE(cookie.get()); | 161 EXPECT_TRUE(cookie.get()); |
(...skipping 17 matching lines...) Expand all Loading... |
178 std::string cookie_domain = ".www.example.com"; | 179 std::string cookie_domain = ".www.example.com"; |
179 std::string cookie_path = "/"; | 180 std::string cookie_path = "/"; |
180 base::Time creation_time = base::Time::Now(); | 181 base::Time creation_time = base::Time::Now(); |
181 base::Time last_access_time = creation_time; | 182 base::Time last_access_time = creation_time; |
182 base::Time expiration_time = creation_time + base::TimeDelta::FromDays(2); | 183 base::Time expiration_time = creation_time + base::TimeDelta::FromDays(2); |
183 bool secure(false); | 184 bool secure(false); |
184 bool httponly(false); | 185 bool httponly(false); |
185 CookieSameSite same_site(CookieSameSite::NO_RESTRICTION); | 186 CookieSameSite same_site(CookieSameSite::NO_RESTRICTION); |
186 | 187 |
187 // Test that a cookie is equivalent to itself. | 188 // Test that a cookie is equivalent to itself. |
188 scoped_ptr<CanonicalCookie> cookie(new CanonicalCookie( | 189 std::unique_ptr<CanonicalCookie> cookie(new CanonicalCookie( |
189 url, cookie_name, cookie_value, cookie_domain, cookie_path, creation_time, | 190 url, cookie_name, cookie_value, cookie_domain, cookie_path, creation_time, |
190 expiration_time, last_access_time, secure, httponly, same_site, | 191 expiration_time, last_access_time, secure, httponly, same_site, |
191 COOKIE_PRIORITY_MEDIUM)); | 192 COOKIE_PRIORITY_MEDIUM)); |
192 EXPECT_TRUE(cookie->IsEquivalent(*cookie)); | 193 EXPECT_TRUE(cookie->IsEquivalent(*cookie)); |
193 | 194 |
194 // Test that two identical cookies are equivalent. | 195 // Test that two identical cookies are equivalent. |
195 scoped_ptr<CanonicalCookie> other_cookie(new CanonicalCookie( | 196 std::unique_ptr<CanonicalCookie> other_cookie(new CanonicalCookie( |
196 url, cookie_name, cookie_value, cookie_domain, cookie_path, creation_time, | 197 url, cookie_name, cookie_value, cookie_domain, cookie_path, creation_time, |
197 expiration_time, last_access_time, secure, httponly, same_site, | 198 expiration_time, last_access_time, secure, httponly, same_site, |
198 COOKIE_PRIORITY_MEDIUM)); | 199 COOKIE_PRIORITY_MEDIUM)); |
199 EXPECT_TRUE(cookie->IsEquivalent(*other_cookie)); | 200 EXPECT_TRUE(cookie->IsEquivalent(*other_cookie)); |
200 | 201 |
201 // Tests that use different variations of attribute values that | 202 // Tests that use different variations of attribute values that |
202 // DON'T affect cookie equivalence. | 203 // DON'T affect cookie equivalence. |
203 other_cookie.reset( | 204 other_cookie.reset( |
204 new CanonicalCookie(url, cookie_name, "2", cookie_domain, cookie_path, | 205 new CanonicalCookie(url, cookie_name, "2", cookie_domain, cookie_path, |
205 creation_time, expiration_time, last_access_time, | 206 creation_time, expiration_time, last_access_time, |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 std::string cookie_domain = ".www.example.com"; | 269 std::string cookie_domain = ".www.example.com"; |
269 std::string cookie_path = "/"; | 270 std::string cookie_path = "/"; |
270 base::Time creation_time = base::Time::Now(); | 271 base::Time creation_time = base::Time::Now(); |
271 base::Time last_access_time = creation_time; | 272 base::Time last_access_time = creation_time; |
272 base::Time expiration_time = creation_time + base::TimeDelta::FromDays(2); | 273 base::Time expiration_time = creation_time + base::TimeDelta::FromDays(2); |
273 bool secure(false); | 274 bool secure(false); |
274 bool httponly(false); | 275 bool httponly(false); |
275 CookieSameSite same_site(CookieSameSite::NO_RESTRICTION); | 276 CookieSameSite same_site(CookieSameSite::NO_RESTRICTION); |
276 | 277 |
277 // Test that a cookie is equivalent to itself. | 278 // Test that a cookie is equivalent to itself. |
278 scoped_ptr<CanonicalCookie> cookie(new CanonicalCookie( | 279 std::unique_ptr<CanonicalCookie> cookie(new CanonicalCookie( |
279 url, cookie_name, cookie_value, cookie_domain, cookie_path, creation_time, | 280 url, cookie_name, cookie_value, cookie_domain, cookie_path, creation_time, |
280 expiration_time, last_access_time, secure, httponly, same_site, | 281 expiration_time, last_access_time, secure, httponly, same_site, |
281 COOKIE_PRIORITY_MEDIUM)); | 282 COOKIE_PRIORITY_MEDIUM)); |
282 EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*cookie)); | 283 EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*cookie)); |
283 | 284 |
284 // Test that two identical cookies are equivalent. | 285 // Test that two identical cookies are equivalent. |
285 scoped_ptr<CanonicalCookie> other_cookie(new CanonicalCookie( | 286 std::unique_ptr<CanonicalCookie> other_cookie(new CanonicalCookie( |
286 url, cookie_name, cookie_value, cookie_domain, cookie_path, creation_time, | 287 url, cookie_name, cookie_value, cookie_domain, cookie_path, creation_time, |
287 expiration_time, last_access_time, secure, httponly, same_site, | 288 expiration_time, last_access_time, secure, httponly, same_site, |
288 COOKIE_PRIORITY_MEDIUM)); | 289 COOKIE_PRIORITY_MEDIUM)); |
289 EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie)); | 290 EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie)); |
290 | 291 |
291 // Tests that use different variations of attribute values that | 292 // Tests that use different variations of attribute values that |
292 // DON'T affect cookie equivalence. Differs from the IsEquivalent tests above | 293 // DON'T affect cookie equivalence. Differs from the IsEquivalent tests above |
293 // as follows: | 294 // as follows: |
294 // * Should return true even if paths differ. | 295 // * Should return true even if paths differ. |
295 // * Should return true if the domains "domain-match" (but are not | 296 // * Should return true if the domains "domain-match" (but are not |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 creation_time, expiration_time, last_access_time, | 358 creation_time, expiration_time, last_access_time, |
358 secure, httponly, same_site, COOKIE_PRIORITY_MEDIUM)); | 359 secure, httponly, same_site, COOKIE_PRIORITY_MEDIUM)); |
359 EXPECT_FALSE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie)); | 360 EXPECT_FALSE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie)); |
360 } | 361 } |
361 | 362 |
362 TEST(CanonicalCookieTest, IsDomainMatch) { | 363 TEST(CanonicalCookieTest, IsDomainMatch) { |
363 GURL url("http://www.example.com/test/foo.html"); | 364 GURL url("http://www.example.com/test/foo.html"); |
364 base::Time creation_time = base::Time::Now(); | 365 base::Time creation_time = base::Time::Now(); |
365 CookieOptions options; | 366 CookieOptions options; |
366 | 367 |
367 scoped_ptr<CanonicalCookie> cookie( | 368 std::unique_ptr<CanonicalCookie> cookie( |
368 CanonicalCookie::Create(url, "A=2", creation_time, options)); | 369 CanonicalCookie::Create(url, "A=2", creation_time, options)); |
369 EXPECT_TRUE(cookie->IsHostCookie()); | 370 EXPECT_TRUE(cookie->IsHostCookie()); |
370 EXPECT_TRUE(cookie->IsDomainMatch("www.example.com")); | 371 EXPECT_TRUE(cookie->IsDomainMatch("www.example.com")); |
371 EXPECT_TRUE(cookie->IsDomainMatch("www.example.com")); | 372 EXPECT_TRUE(cookie->IsDomainMatch("www.example.com")); |
372 EXPECT_FALSE(cookie->IsDomainMatch("foo.www.example.com")); | 373 EXPECT_FALSE(cookie->IsDomainMatch("foo.www.example.com")); |
373 EXPECT_FALSE(cookie->IsDomainMatch("www0.example.com")); | 374 EXPECT_FALSE(cookie->IsDomainMatch("www0.example.com")); |
374 EXPECT_FALSE(cookie->IsDomainMatch("example.com")); | 375 EXPECT_FALSE(cookie->IsDomainMatch("example.com")); |
375 | 376 |
376 cookie = CanonicalCookie::Create(url, "A=2; Domain=www.example.com", | 377 cookie = CanonicalCookie::Create(url, "A=2; Domain=www.example.com", |
377 creation_time, options); | 378 creation_time, options); |
(...skipping 10 matching lines...) Expand all Loading... |
388 EXPECT_TRUE(cookie->IsDomainMatch("www.example.com")); | 389 EXPECT_TRUE(cookie->IsDomainMatch("www.example.com")); |
389 EXPECT_TRUE(cookie->IsDomainMatch("foo.www.example.com")); | 390 EXPECT_TRUE(cookie->IsDomainMatch("foo.www.example.com")); |
390 EXPECT_FALSE(cookie->IsDomainMatch("www0.example.com")); | 391 EXPECT_FALSE(cookie->IsDomainMatch("www0.example.com")); |
391 EXPECT_FALSE(cookie->IsDomainMatch("example.com")); | 392 EXPECT_FALSE(cookie->IsDomainMatch("example.com")); |
392 } | 393 } |
393 | 394 |
394 TEST(CanonicalCookieTest, IsOnPath) { | 395 TEST(CanonicalCookieTest, IsOnPath) { |
395 base::Time creation_time = base::Time::Now(); | 396 base::Time creation_time = base::Time::Now(); |
396 CookieOptions options; | 397 CookieOptions options; |
397 | 398 |
398 scoped_ptr<CanonicalCookie> cookie(CanonicalCookie::Create( | 399 std::unique_ptr<CanonicalCookie> cookie(CanonicalCookie::Create( |
399 GURL("http://www.example.com"), "A=2", creation_time, options)); | 400 GURL("http://www.example.com"), "A=2", creation_time, options)); |
400 EXPECT_TRUE(cookie->IsOnPath("/")); | 401 EXPECT_TRUE(cookie->IsOnPath("/")); |
401 EXPECT_TRUE(cookie->IsOnPath("/test")); | 402 EXPECT_TRUE(cookie->IsOnPath("/test")); |
402 EXPECT_TRUE(cookie->IsOnPath("/test/bar.html")); | 403 EXPECT_TRUE(cookie->IsOnPath("/test/bar.html")); |
403 | 404 |
404 // Test the empty string edge case. | 405 // Test the empty string edge case. |
405 EXPECT_FALSE(cookie->IsOnPath(std::string())); | 406 EXPECT_FALSE(cookie->IsOnPath(std::string())); |
406 | 407 |
407 cookie = CanonicalCookie::Create(GURL("http://www.example.com/test/foo.html"), | 408 cookie = CanonicalCookie::Create(GURL("http://www.example.com/test/foo.html"), |
408 "A=2", creation_time, options); | 409 "A=2", creation_time, options); |
409 EXPECT_FALSE(cookie->IsOnPath("/")); | 410 EXPECT_FALSE(cookie->IsOnPath("/")); |
410 EXPECT_TRUE(cookie->IsOnPath("/test")); | 411 EXPECT_TRUE(cookie->IsOnPath("/test")); |
411 EXPECT_TRUE(cookie->IsOnPath("/test/bar.html")); | 412 EXPECT_TRUE(cookie->IsOnPath("/test/bar.html")); |
412 EXPECT_TRUE(cookie->IsOnPath("/test/sample/bar.html")); | 413 EXPECT_TRUE(cookie->IsOnPath("/test/sample/bar.html")); |
413 } | 414 } |
414 | 415 |
415 TEST(CanonicalCookieTest, IncludeForRequestURL) { | 416 TEST(CanonicalCookieTest, IncludeForRequestURL) { |
416 GURL url("http://www.example.com"); | 417 GURL url("http://www.example.com"); |
417 base::Time creation_time = base::Time::Now(); | 418 base::Time creation_time = base::Time::Now(); |
418 CookieOptions options; | 419 CookieOptions options; |
419 | 420 |
420 scoped_ptr<CanonicalCookie> cookie( | 421 std::unique_ptr<CanonicalCookie> cookie( |
421 CanonicalCookie::Create(url, "A=2", creation_time, options)); | 422 CanonicalCookie::Create(url, "A=2", creation_time, options)); |
422 EXPECT_TRUE(cookie->IncludeForRequestURL(url, options)); | 423 EXPECT_TRUE(cookie->IncludeForRequestURL(url, options)); |
423 EXPECT_TRUE(cookie->IncludeForRequestURL( | 424 EXPECT_TRUE(cookie->IncludeForRequestURL( |
424 GURL("http://www.example.com/foo/bar"), options)); | 425 GURL("http://www.example.com/foo/bar"), options)); |
425 EXPECT_TRUE(cookie->IncludeForRequestURL( | 426 EXPECT_TRUE(cookie->IncludeForRequestURL( |
426 GURL("https://www.example.com/foo/bar"), options)); | 427 GURL("https://www.example.com/foo/bar"), options)); |
427 EXPECT_FALSE( | 428 EXPECT_FALSE( |
428 cookie->IncludeForRequestURL(GURL("https://sub.example.com"), options)); | 429 cookie->IncludeForRequestURL(GURL("https://sub.example.com"), options)); |
429 EXPECT_FALSE(cookie->IncludeForRequestURL(GURL("https://sub.www.example.com"), | 430 EXPECT_FALSE(cookie->IncludeForRequestURL(GURL("https://sub.www.example.com"), |
430 options)); | 431 options)); |
(...skipping 22 matching lines...) Expand all Loading... |
453 EXPECT_TRUE(cookie->IsHttpOnly()); | 454 EXPECT_TRUE(cookie->IsHttpOnly()); |
454 EXPECT_TRUE(cookie->IncludeForRequestURL(url, options)); | 455 EXPECT_TRUE(cookie->IncludeForRequestURL(url, options)); |
455 options.set_exclude_httponly(); | 456 options.set_exclude_httponly(); |
456 EXPECT_FALSE(cookie->IncludeForRequestURL(url, options)); | 457 EXPECT_FALSE(cookie->IncludeForRequestURL(url, options)); |
457 } | 458 } |
458 | 459 |
459 TEST(CanonicalCookieTest, IncludeSameSiteForSameSiteURL) { | 460 TEST(CanonicalCookieTest, IncludeSameSiteForSameSiteURL) { |
460 GURL url("https://example.test"); | 461 GURL url("https://example.test"); |
461 base::Time creation_time = base::Time::Now(); | 462 base::Time creation_time = base::Time::Now(); |
462 CookieOptions options; | 463 CookieOptions options; |
463 scoped_ptr<CanonicalCookie> cookie; | 464 std::unique_ptr<CanonicalCookie> cookie; |
464 | 465 |
465 // `SameSite=Strict` cookies are included for a URL only if the options' | 466 // `SameSite=Strict` cookies are included for a URL only if the options' |
466 // SameSiteCookieMode is INCLUDE_STRICT_AND_LAX. | 467 // SameSiteCookieMode is INCLUDE_STRICT_AND_LAX. |
467 cookie = CanonicalCookie::Create(url, "A=2; SameSite=Strict", creation_time, | 468 cookie = CanonicalCookie::Create(url, "A=2; SameSite=Strict", creation_time, |
468 options); | 469 options); |
469 EXPECT_EQ(CookieSameSite::STRICT_MODE, cookie->SameSite()); | 470 EXPECT_EQ(CookieSameSite::STRICT_MODE, cookie->SameSite()); |
470 options.set_same_site_cookie_mode( | 471 options.set_same_site_cookie_mode( |
471 CookieOptions::SameSiteCookieMode::DO_NOT_INCLUDE); | 472 CookieOptions::SameSiteCookieMode::DO_NOT_INCLUDE); |
472 EXPECT_FALSE(cookie->IncludeForRequestURL(url, options)); | 473 EXPECT_FALSE(cookie->IncludeForRequestURL(url, options)); |
473 options.set_same_site_cookie_mode( | 474 options.set_same_site_cookie_mode( |
(...skipping 16 matching lines...) Expand all Loading... |
490 EXPECT_TRUE(cookie->IncludeForRequestURL(url, options)); | 491 EXPECT_TRUE(cookie->IncludeForRequestURL(url, options)); |
491 options.set_same_site_cookie_mode( | 492 options.set_same_site_cookie_mode( |
492 CookieOptions::SameSiteCookieMode::INCLUDE_STRICT_AND_LAX); | 493 CookieOptions::SameSiteCookieMode::INCLUDE_STRICT_AND_LAX); |
493 EXPECT_TRUE(cookie->IncludeForRequestURL(url, options)); | 494 EXPECT_TRUE(cookie->IncludeForRequestURL(url, options)); |
494 } | 495 } |
495 | 496 |
496 TEST(CanonicalCookieTest, PartialCompare) { | 497 TEST(CanonicalCookieTest, PartialCompare) { |
497 GURL url("http://www.example.com"); | 498 GURL url("http://www.example.com"); |
498 base::Time creation_time = base::Time::Now(); | 499 base::Time creation_time = base::Time::Now(); |
499 CookieOptions options; | 500 CookieOptions options; |
500 scoped_ptr<CanonicalCookie> cookie( | 501 std::unique_ptr<CanonicalCookie> cookie( |
501 CanonicalCookie::Create(url, "a=b", creation_time, options)); | 502 CanonicalCookie::Create(url, "a=b", creation_time, options)); |
502 scoped_ptr<CanonicalCookie> cookie_different_path( | 503 std::unique_ptr<CanonicalCookie> cookie_different_path( |
503 CanonicalCookie::Create(url, "a=b; path=/foo", creation_time, options)); | 504 CanonicalCookie::Create(url, "a=b; path=/foo", creation_time, options)); |
504 scoped_ptr<CanonicalCookie> cookie_different_value( | 505 std::unique_ptr<CanonicalCookie> cookie_different_value( |
505 CanonicalCookie::Create(url, "a=c", creation_time, options)); | 506 CanonicalCookie::Create(url, "a=c", creation_time, options)); |
506 | 507 |
507 // Cookie is equivalent to itself. | 508 // Cookie is equivalent to itself. |
508 EXPECT_FALSE(cookie->PartialCompare(*cookie)); | 509 EXPECT_FALSE(cookie->PartialCompare(*cookie)); |
509 | 510 |
510 // Changing the path affects the ordering. | 511 // Changing the path affects the ordering. |
511 EXPECT_TRUE(cookie->PartialCompare(*cookie_different_path)); | 512 EXPECT_TRUE(cookie->PartialCompare(*cookie_different_path)); |
512 EXPECT_FALSE(cookie_different_path->PartialCompare(*cookie)); | 513 EXPECT_FALSE(cookie_different_path->PartialCompare(*cookie)); |
513 | 514 |
514 // Changing the value does not affect the ordering. | 515 // Changing the value does not affect the ordering. |
515 EXPECT_FALSE(cookie->PartialCompare(*cookie_different_value)); | 516 EXPECT_FALSE(cookie->PartialCompare(*cookie_different_value)); |
516 EXPECT_FALSE(cookie_different_value->PartialCompare(*cookie)); | 517 EXPECT_FALSE(cookie_different_value->PartialCompare(*cookie)); |
517 | 518 |
518 // Cookies identical for PartialCompare() are equivalent. | 519 // Cookies identical for PartialCompare() are equivalent. |
519 EXPECT_TRUE(cookie->IsEquivalent(*cookie_different_value)); | 520 EXPECT_TRUE(cookie->IsEquivalent(*cookie_different_value)); |
520 EXPECT_TRUE(cookie->IsEquivalent(*cookie)); | 521 EXPECT_TRUE(cookie->IsEquivalent(*cookie)); |
521 } | 522 } |
522 | 523 |
523 TEST(CanonicalCookieTest, FullCompare) { | 524 TEST(CanonicalCookieTest, FullCompare) { |
524 GURL url("http://www.example.com"); | 525 GURL url("http://www.example.com"); |
525 base::Time creation_time = base::Time::Now(); | 526 base::Time creation_time = base::Time::Now(); |
526 CookieOptions options; | 527 CookieOptions options; |
527 scoped_ptr<CanonicalCookie> cookie( | 528 std::unique_ptr<CanonicalCookie> cookie( |
528 CanonicalCookie::Create(url, "a=b", creation_time, options)); | 529 CanonicalCookie::Create(url, "a=b", creation_time, options)); |
529 scoped_ptr<CanonicalCookie> cookie_different_path( | 530 std::unique_ptr<CanonicalCookie> cookie_different_path( |
530 CanonicalCookie::Create(url, "a=b; path=/foo", creation_time, options)); | 531 CanonicalCookie::Create(url, "a=b; path=/foo", creation_time, options)); |
531 scoped_ptr<CanonicalCookie> cookie_different_value( | 532 std::unique_ptr<CanonicalCookie> cookie_different_value( |
532 CanonicalCookie::Create(url, "a=c", creation_time, options)); | 533 CanonicalCookie::Create(url, "a=c", creation_time, options)); |
533 | 534 |
534 // Cookie is equivalent to itself. | 535 // Cookie is equivalent to itself. |
535 EXPECT_FALSE(cookie->FullCompare(*cookie)); | 536 EXPECT_FALSE(cookie->FullCompare(*cookie)); |
536 | 537 |
537 // Changing the path affects the ordering. | 538 // Changing the path affects the ordering. |
538 EXPECT_TRUE(cookie->FullCompare(*cookie_different_path)); | 539 EXPECT_TRUE(cookie->FullCompare(*cookie_different_path)); |
539 EXPECT_FALSE(cookie_different_path->FullCompare(*cookie)); | 540 EXPECT_FALSE(cookie_different_path->FullCompare(*cookie)); |
540 | 541 |
541 // Changing the value affects the ordering. | 542 // Changing the value affects the ordering. |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
631 options)); | 632 options)); |
632 } | 633 } |
633 | 634 |
634 TEST(CanonicalCookieTest, EnforceSecureCookiesRequireSecureScheme) { | 635 TEST(CanonicalCookieTest, EnforceSecureCookiesRequireSecureScheme) { |
635 GURL http_url("http://www.example.com"); | 636 GURL http_url("http://www.example.com"); |
636 GURL https_url("https://www.example.com"); | 637 GURL https_url("https://www.example.com"); |
637 base::Time creation_time = base::Time::Now(); | 638 base::Time creation_time = base::Time::Now(); |
638 CookieOptions options; | 639 CookieOptions options; |
639 options.set_enforce_strict_secure(); | 640 options.set_enforce_strict_secure(); |
640 | 641 |
641 scoped_ptr<CanonicalCookie> http_cookie_no_secure( | 642 std::unique_ptr<CanonicalCookie> http_cookie_no_secure( |
642 CanonicalCookie::Create(http_url, "a=b", creation_time, options)); | 643 CanonicalCookie::Create(http_url, "a=b", creation_time, options)); |
643 scoped_ptr<CanonicalCookie> http_cookie_secure( | 644 std::unique_ptr<CanonicalCookie> http_cookie_secure( |
644 CanonicalCookie::Create(http_url, "a=b; Secure", creation_time, options)); | 645 CanonicalCookie::Create(http_url, "a=b; Secure", creation_time, options)); |
645 scoped_ptr<CanonicalCookie> https_cookie_no_secure( | 646 std::unique_ptr<CanonicalCookie> https_cookie_no_secure( |
646 CanonicalCookie::Create(https_url, "a=b", creation_time, options)); | 647 CanonicalCookie::Create(https_url, "a=b", creation_time, options)); |
647 scoped_ptr<CanonicalCookie> https_cookie_secure(CanonicalCookie::Create( | 648 std::unique_ptr<CanonicalCookie> https_cookie_secure(CanonicalCookie::Create( |
648 https_url, "a=b; Secure", creation_time, options)); | 649 https_url, "a=b; Secure", creation_time, options)); |
649 | 650 |
650 EXPECT_TRUE(http_cookie_no_secure.get()); | 651 EXPECT_TRUE(http_cookie_no_secure.get()); |
651 EXPECT_FALSE(http_cookie_secure.get()); | 652 EXPECT_FALSE(http_cookie_secure.get()); |
652 EXPECT_TRUE(https_cookie_no_secure.get()); | 653 EXPECT_TRUE(https_cookie_no_secure.get()); |
653 EXPECT_TRUE(https_cookie_secure.get()); | 654 EXPECT_TRUE(https_cookie_secure.get()); |
654 | 655 |
655 scoped_ptr<CanonicalCookie> http_cookie_no_secure_extended( | 656 std::unique_ptr<CanonicalCookie> http_cookie_no_secure_extended( |
656 CanonicalCookie::Create( | 657 CanonicalCookie::Create( |
657 http_url, "a", "b", "", "", creation_time, creation_time, false, | 658 http_url, "a", "b", "", "", creation_time, creation_time, false, |
658 false, CookieSameSite::STRICT_MODE, true, COOKIE_PRIORITY_DEFAULT)); | 659 false, CookieSameSite::STRICT_MODE, true, COOKIE_PRIORITY_DEFAULT)); |
659 scoped_ptr<CanonicalCookie> http_cookie_secure_extended( | 660 std::unique_ptr<CanonicalCookie> http_cookie_secure_extended( |
660 CanonicalCookie::Create( | 661 CanonicalCookie::Create( |
661 http_url, "a", "b", "", "", creation_time, creation_time, true, false, | 662 http_url, "a", "b", "", "", creation_time, creation_time, true, false, |
662 CookieSameSite::STRICT_MODE, true, COOKIE_PRIORITY_DEFAULT)); | 663 CookieSameSite::STRICT_MODE, true, COOKIE_PRIORITY_DEFAULT)); |
663 scoped_ptr<CanonicalCookie> https_cookie_no_secure_extended( | 664 std::unique_ptr<CanonicalCookie> https_cookie_no_secure_extended( |
664 CanonicalCookie::Create( | 665 CanonicalCookie::Create( |
665 https_url, "a", "b", "", "", creation_time, creation_time, false, | 666 https_url, "a", "b", "", "", creation_time, creation_time, false, |
666 false, CookieSameSite::STRICT_MODE, true, COOKIE_PRIORITY_DEFAULT)); | 667 false, CookieSameSite::STRICT_MODE, true, COOKIE_PRIORITY_DEFAULT)); |
667 scoped_ptr<CanonicalCookie> https_cookie_secure_extended( | 668 std::unique_ptr<CanonicalCookie> https_cookie_secure_extended( |
668 CanonicalCookie::Create( | 669 CanonicalCookie::Create( |
669 https_url, "a", "b", "", "", creation_time, creation_time, true, | 670 https_url, "a", "b", "", "", creation_time, creation_time, true, |
670 false, CookieSameSite::STRICT_MODE, true, COOKIE_PRIORITY_DEFAULT)); | 671 false, CookieSameSite::STRICT_MODE, true, COOKIE_PRIORITY_DEFAULT)); |
671 | 672 |
672 EXPECT_TRUE(http_cookie_no_secure_extended.get()); | 673 EXPECT_TRUE(http_cookie_no_secure_extended.get()); |
673 EXPECT_FALSE(http_cookie_secure_extended.get()); | 674 EXPECT_FALSE(http_cookie_secure_extended.get()); |
674 EXPECT_TRUE(https_cookie_no_secure_extended.get()); | 675 EXPECT_TRUE(https_cookie_no_secure_extended.get()); |
675 EXPECT_TRUE(https_cookie_secure_extended.get()); | 676 EXPECT_TRUE(https_cookie_secure_extended.get()); |
676 } | 677 } |
677 | 678 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
719 CanonicalCookie::COOKIE_PREFIX_SECURE, 1); | 720 CanonicalCookie::COOKIE_PREFIX_SECURE, 1); |
720 EXPECT_TRUE(CanonicalCookie::Create(https_url, "__SecureA=B; Path=/; Secure", | 721 EXPECT_TRUE(CanonicalCookie::Create(https_url, "__SecureA=B; Path=/; Secure", |
721 creation_time, options)); | 722 creation_time, options)); |
722 histograms.ExpectBucketCount(kCookiePrefixHistogram, | 723 histograms.ExpectBucketCount(kCookiePrefixHistogram, |
723 CanonicalCookie::COOKIE_PREFIX_SECURE, 2); | 724 CanonicalCookie::COOKIE_PREFIX_SECURE, 2); |
724 histograms.ExpectBucketCount(kCookiePrefixBlockedHistogram, | 725 histograms.ExpectBucketCount(kCookiePrefixBlockedHistogram, |
725 CanonicalCookie::COOKIE_PREFIX_SECURE, 1); | 726 CanonicalCookie::COOKIE_PREFIX_SECURE, 1); |
726 } | 727 } |
727 | 728 |
728 } // namespace net | 729 } // namespace net |
OLD | NEW |