| 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 "base/memory/scoped_ptr.h" |
| 8 #include "base/test/histogram_tester.h" | 8 #include "base/test/histogram_tester.h" |
| 9 #include "net/cookies/cookie_constants.h" | 9 #include "net/cookies/cookie_constants.h" |
| 10 #include "net/cookies/cookie_options.h" | 10 #include "net/cookies/cookie_options.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 #include "url/gurl.h" | 12 #include "url/gurl.h" |
| 13 | 13 |
| 14 namespace net { | 14 namespace net { |
| 15 | 15 |
| 16 TEST(CanonicalCookieTest, Constructor) { | 16 TEST(CanonicalCookieTest, Constructor) { |
| 17 GURL url("http://www.example.com/test"); | 17 GURL url("http://www.example.com/test"); |
| 18 base::Time current_time = base::Time::Now(); | 18 base::Time current_time = base::Time::Now(); |
| 19 | 19 |
| 20 CanonicalCookie cookie(url, "A", "2", "www.example.com", "/test", | 20 CanonicalCookie cookie(url, "A", "2", "www.example.com", "/test", |
| 21 current_time, base::Time(), current_time, false, false, | 21 current_time, base::Time(), current_time, false, false, |
| 22 false, COOKIE_PRIORITY_DEFAULT); | 22 COOKIE_SAME_SITE_DEFAULT, COOKIE_PRIORITY_DEFAULT); |
| 23 EXPECT_EQ(url.GetOrigin(), cookie.Source()); | 23 EXPECT_EQ(url.GetOrigin(), cookie.Source()); |
| 24 EXPECT_EQ("A", cookie.Name()); | 24 EXPECT_EQ("A", cookie.Name()); |
| 25 EXPECT_EQ("2", cookie.Value()); | 25 EXPECT_EQ("2", cookie.Value()); |
| 26 EXPECT_EQ("www.example.com", cookie.Domain()); | 26 EXPECT_EQ("www.example.com", cookie.Domain()); |
| 27 EXPECT_EQ("/test", cookie.Path()); | 27 EXPECT_EQ("/test", cookie.Path()); |
| 28 EXPECT_FALSE(cookie.IsSecure()); | 28 EXPECT_FALSE(cookie.IsSecure()); |
| 29 EXPECT_FALSE(cookie.IsHttpOnly()); | 29 EXPECT_FALSE(cookie.IsHttpOnly()); |
| 30 EXPECT_FALSE(cookie.IsSameSite()); | 30 EXPECT_EQ(COOKIE_SAME_SITE_NONE, cookie.SameSite()); |
| 31 | 31 |
| 32 CanonicalCookie cookie2(url, "A", "2", std::string(), std::string(), | 32 CanonicalCookie cookie2(url, "A", "2", std::string(), std::string(), |
| 33 current_time, base::Time(), current_time, false, | 33 current_time, base::Time(), current_time, false, |
| 34 false, false, COOKIE_PRIORITY_DEFAULT); | 34 false, COOKIE_SAME_SITE_DEFAULT, |
| 35 COOKIE_PRIORITY_DEFAULT); |
| 35 EXPECT_EQ(url.GetOrigin(), cookie.Source()); | 36 EXPECT_EQ(url.GetOrigin(), cookie.Source()); |
| 36 EXPECT_EQ("A", cookie2.Name()); | 37 EXPECT_EQ("A", cookie2.Name()); |
| 37 EXPECT_EQ("2", cookie2.Value()); | 38 EXPECT_EQ("2", cookie2.Value()); |
| 38 EXPECT_EQ("", cookie2.Domain()); | 39 EXPECT_EQ("", cookie2.Domain()); |
| 39 EXPECT_EQ("", cookie2.Path()); | 40 EXPECT_EQ("", cookie2.Path()); |
| 40 EXPECT_FALSE(cookie2.IsSecure()); | 41 EXPECT_FALSE(cookie2.IsSecure()); |
| 41 EXPECT_FALSE(cookie2.IsHttpOnly()); | 42 EXPECT_FALSE(cookie2.IsHttpOnly()); |
| 42 EXPECT_FALSE(cookie2.IsSameSite()); | 43 EXPECT_EQ(COOKIE_SAME_SITE_NONE, cookie2.SameSite()); |
| 43 } | 44 } |
| 44 | 45 |
| 45 TEST(CanonicalCookieTest, Create) { | 46 TEST(CanonicalCookieTest, Create) { |
| 46 // Test creating cookies from a cookie string. | 47 // Test creating cookies from a cookie string. |
| 47 GURL url("http://www.example.com/test/foo.html"); | 48 GURL url("http://www.example.com/test/foo.html"); |
| 48 base::Time creation_time = base::Time::Now(); | 49 base::Time creation_time = base::Time::Now(); |
| 49 CookieOptions options; | 50 CookieOptions options; |
| 50 | 51 |
| 51 scoped_ptr<CanonicalCookie> cookie( | 52 scoped_ptr<CanonicalCookie> cookie( |
| 52 CanonicalCookie::Create(url, "A=2", creation_time, options)); | 53 CanonicalCookie::Create(url, "A=2", creation_time, options)); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 78 EXPECT_FALSE(cookie.get()); | 79 EXPECT_FALSE(cookie.get()); |
| 79 CookieOptions httponly_options; | 80 CookieOptions httponly_options; |
| 80 httponly_options.set_include_httponly(); | 81 httponly_options.set_include_httponly(); |
| 81 cookie = CanonicalCookie::Create(url, "A=2; HttpOnly", creation_time, | 82 cookie = CanonicalCookie::Create(url, "A=2; HttpOnly", creation_time, |
| 82 httponly_options); | 83 httponly_options); |
| 83 EXPECT_TRUE(cookie->IsHttpOnly()); | 84 EXPECT_TRUE(cookie->IsHttpOnly()); |
| 84 | 85 |
| 85 // Test creating http only cookies. | 86 // Test creating http only cookies. |
| 86 CookieOptions same_site_options; | 87 CookieOptions same_site_options; |
| 87 same_site_options.set_include_same_site(); | 88 same_site_options.set_include_same_site(); |
| 88 cookie = CanonicalCookie::Create(url, "A=2; SameSite", creation_time, | 89 cookie = CanonicalCookie::Create(url, "A=2; SameSite=Strict", creation_time, |
| 89 same_site_options); | 90 same_site_options); |
| 90 EXPECT_TRUE(cookie.get()); | 91 EXPECT_TRUE(cookie.get()); |
| 91 EXPECT_TRUE(cookie->IsSameSite()); | 92 EXPECT_EQ(COOKIE_SAME_SITE_STRICT, cookie->SameSite()); |
| 92 | 93 |
| 93 // Test the creating cookies using specific parameter instead of a cookie | 94 // Test the creating cookies using specific parameter instead of a cookie |
| 94 // string. | 95 // string. |
| 95 cookie = CanonicalCookie::Create(url, "A", "2", "www.example.com", "/test", | 96 cookie = CanonicalCookie::Create( |
| 96 creation_time, base::Time(), false, false, | 97 url, "A", "2", "www.example.com", "/test", creation_time, base::Time(), |
| 97 false, false, COOKIE_PRIORITY_DEFAULT); | 98 false, false, COOKIE_SAME_SITE_DEFAULT, false, COOKIE_PRIORITY_DEFAULT); |
| 98 EXPECT_EQ(url.GetOrigin(), cookie->Source()); | 99 EXPECT_EQ(url.GetOrigin(), cookie->Source()); |
| 99 EXPECT_EQ("A", cookie->Name()); | 100 EXPECT_EQ("A", cookie->Name()); |
| 100 EXPECT_EQ("2", cookie->Value()); | 101 EXPECT_EQ("2", cookie->Value()); |
| 101 EXPECT_EQ(".www.example.com", cookie->Domain()); | 102 EXPECT_EQ(".www.example.com", cookie->Domain()); |
| 102 EXPECT_EQ("/test", cookie->Path()); | 103 EXPECT_EQ("/test", cookie->Path()); |
| 103 EXPECT_FALSE(cookie->IsSecure()); | 104 EXPECT_FALSE(cookie->IsSecure()); |
| 104 EXPECT_FALSE(cookie->IsHttpOnly()); | 105 EXPECT_FALSE(cookie->IsHttpOnly()); |
| 105 EXPECT_FALSE(cookie->IsSameSite()); | 106 EXPECT_EQ(COOKIE_SAME_SITE_NONE, cookie->SameSite()); |
| 106 | 107 |
| 107 cookie = CanonicalCookie::Create(url, "A", "2", ".www.example.com", "/test", | 108 cookie = CanonicalCookie::Create( |
| 108 creation_time, base::Time(), false, false, | 109 url, "A", "2", ".www.example.com", "/test", creation_time, base::Time(), |
| 109 false, false, COOKIE_PRIORITY_DEFAULT); | 110 false, false, COOKIE_SAME_SITE_DEFAULT, false, COOKIE_PRIORITY_DEFAULT); |
| 110 EXPECT_EQ(url.GetOrigin(), cookie->Source()); | 111 EXPECT_EQ(url.GetOrigin(), cookie->Source()); |
| 111 EXPECT_EQ("A", cookie->Name()); | 112 EXPECT_EQ("A", cookie->Name()); |
| 112 EXPECT_EQ("2", cookie->Value()); | 113 EXPECT_EQ("2", cookie->Value()); |
| 113 EXPECT_EQ(".www.example.com", cookie->Domain()); | 114 EXPECT_EQ(".www.example.com", cookie->Domain()); |
| 114 EXPECT_EQ("/test", cookie->Path()); | 115 EXPECT_EQ("/test", cookie->Path()); |
| 115 EXPECT_FALSE(cookie->IsSecure()); | 116 EXPECT_FALSE(cookie->IsSecure()); |
| 116 EXPECT_FALSE(cookie->IsHttpOnly()); | 117 EXPECT_FALSE(cookie->IsHttpOnly()); |
| 117 EXPECT_FALSE(cookie->IsSameSite()); | 118 EXPECT_EQ(COOKIE_SAME_SITE_NONE, cookie->SameSite()); |
| 118 } | 119 } |
| 119 | 120 |
| 120 TEST(CanonicalCookieTest, EmptyExpiry) { | 121 TEST(CanonicalCookieTest, EmptyExpiry) { |
| 121 GURL url("http://www7.ipdl.inpit.go.jp/Tokujitu/tjkta.ipdl?N0000=108"); | 122 GURL url("http://www7.ipdl.inpit.go.jp/Tokujitu/tjkta.ipdl?N0000=108"); |
| 122 base::Time creation_time = base::Time::Now(); | 123 base::Time creation_time = base::Time::Now(); |
| 123 CookieOptions options; | 124 CookieOptions options; |
| 124 | 125 |
| 125 std::string cookie_line = | 126 std::string cookie_line = |
| 126 "ACSTM=20130308043820420042; path=/; domain=ipdl.inpit.go.jp; Expires="; | 127 "ACSTM=20130308043820420042; path=/; domain=ipdl.inpit.go.jp; Expires="; |
| 127 scoped_ptr<CanonicalCookie> cookie( | 128 scoped_ptr<CanonicalCookie> cookie( |
| (...skipping 24 matching lines...) Expand all Loading... |
| 152 GURL url("http://www.example.com/"); | 153 GURL url("http://www.example.com/"); |
| 153 std::string cookie_name = "A"; | 154 std::string cookie_name = "A"; |
| 154 std::string cookie_value = "2EDA-EF"; | 155 std::string cookie_value = "2EDA-EF"; |
| 155 std::string cookie_domain = ".www.example.com"; | 156 std::string cookie_domain = ".www.example.com"; |
| 156 std::string cookie_path = "/"; | 157 std::string cookie_path = "/"; |
| 157 base::Time creation_time = base::Time::Now(); | 158 base::Time creation_time = base::Time::Now(); |
| 158 base::Time last_access_time = creation_time; | 159 base::Time last_access_time = creation_time; |
| 159 base::Time expiration_time = creation_time + base::TimeDelta::FromDays(2); | 160 base::Time expiration_time = creation_time + base::TimeDelta::FromDays(2); |
| 160 bool secure(false); | 161 bool secure(false); |
| 161 bool httponly(false); | 162 bool httponly(false); |
| 162 bool same_site(false); | 163 CookieSameSite same_site(COOKIE_SAME_SITE_NONE); |
| 163 | 164 |
| 164 // Test that a cookie is equivalent to itself. | 165 // Test that a cookie is equivalent to itself. |
| 165 scoped_ptr<CanonicalCookie> cookie(new CanonicalCookie( | 166 scoped_ptr<CanonicalCookie> cookie(new CanonicalCookie( |
| 166 url, cookie_name, cookie_value, cookie_domain, cookie_path, creation_time, | 167 url, cookie_name, cookie_value, cookie_domain, cookie_path, creation_time, |
| 167 expiration_time, last_access_time, secure, httponly, same_site, | 168 expiration_time, last_access_time, secure, httponly, same_site, |
| 168 COOKIE_PRIORITY_MEDIUM)); | 169 COOKIE_PRIORITY_MEDIUM)); |
| 169 EXPECT_TRUE(cookie->IsEquivalent(*cookie)); | 170 EXPECT_TRUE(cookie->IsEquivalent(*cookie)); |
| 170 | 171 |
| 171 // Test that two identical cookies are equivalent. | 172 // Test that two identical cookies are equivalent. |
| 172 scoped_ptr<CanonicalCookie> other_cookie(new CanonicalCookie( | 173 scoped_ptr<CanonicalCookie> other_cookie(new CanonicalCookie( |
| (...skipping 25 matching lines...) Expand all Loading... |
| 198 EXPECT_TRUE(cookie->IsEquivalent(*other_cookie)); | 199 EXPECT_TRUE(cookie->IsEquivalent(*other_cookie)); |
| 199 | 200 |
| 200 other_cookie.reset(new CanonicalCookie( | 201 other_cookie.reset(new CanonicalCookie( |
| 201 url, cookie_name, cookie_name, cookie_domain, cookie_path, creation_time, | 202 url, cookie_name, cookie_name, cookie_domain, cookie_path, creation_time, |
| 202 expiration_time, last_access_time, secure, true, same_site, | 203 expiration_time, last_access_time, secure, true, same_site, |
| 203 COOKIE_PRIORITY_LOW)); | 204 COOKIE_PRIORITY_LOW)); |
| 204 EXPECT_TRUE(cookie->IsEquivalent(*other_cookie)); | 205 EXPECT_TRUE(cookie->IsEquivalent(*other_cookie)); |
| 205 | 206 |
| 206 other_cookie.reset(new CanonicalCookie( | 207 other_cookie.reset(new CanonicalCookie( |
| 207 url, cookie_name, cookie_name, cookie_domain, cookie_path, creation_time, | 208 url, cookie_name, cookie_name, cookie_domain, cookie_path, creation_time, |
| 208 expiration_time, last_access_time, secure, httponly, true, | 209 expiration_time, last_access_time, secure, httponly, |
| 209 COOKIE_PRIORITY_LOW)); | 210 COOKIE_SAME_SITE_STRICT, COOKIE_PRIORITY_LOW)); |
| 210 EXPECT_TRUE(cookie->IsEquivalent(*other_cookie)); | 211 EXPECT_TRUE(cookie->IsEquivalent(*other_cookie)); |
| 211 | 212 |
| 212 // Tests that use different variations of attribute values that | 213 // Tests that use different variations of attribute values that |
| 213 // DO affect cookie equivalence. | 214 // DO affect cookie equivalence. |
| 214 other_cookie.reset( | 215 other_cookie.reset( |
| 215 new CanonicalCookie(url, "B", cookie_value, cookie_domain, cookie_path, | 216 new CanonicalCookie(url, "B", cookie_value, cookie_domain, cookie_path, |
| 216 creation_time, expiration_time, last_access_time, | 217 creation_time, expiration_time, last_access_time, |
| 217 secure, httponly, same_site, COOKIE_PRIORITY_MEDIUM)); | 218 secure, httponly, same_site, COOKIE_PRIORITY_MEDIUM)); |
| 218 EXPECT_FALSE(cookie->IsEquivalent(*other_cookie)); | 219 EXPECT_FALSE(cookie->IsEquivalent(*other_cookie)); |
| 219 | 220 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 242 GURL url("http://www.example.com/"); | 243 GURL url("http://www.example.com/"); |
| 243 std::string cookie_name = "A"; | 244 std::string cookie_name = "A"; |
| 244 std::string cookie_value = "2EDA-EF"; | 245 std::string cookie_value = "2EDA-EF"; |
| 245 std::string cookie_domain = ".www.example.com"; | 246 std::string cookie_domain = ".www.example.com"; |
| 246 std::string cookie_path = "/"; | 247 std::string cookie_path = "/"; |
| 247 base::Time creation_time = base::Time::Now(); | 248 base::Time creation_time = base::Time::Now(); |
| 248 base::Time last_access_time = creation_time; | 249 base::Time last_access_time = creation_time; |
| 249 base::Time expiration_time = creation_time + base::TimeDelta::FromDays(2); | 250 base::Time expiration_time = creation_time + base::TimeDelta::FromDays(2); |
| 250 bool secure(false); | 251 bool secure(false); |
| 251 bool httponly(false); | 252 bool httponly(false); |
| 252 bool same_site(false); | 253 CookieSameSite same_site(COOKIE_SAME_SITE_NONE); |
| 253 | 254 |
| 254 // Test that a cookie is equivalent to itself. | 255 // Test that a cookie is equivalent to itself. |
| 255 scoped_ptr<CanonicalCookie> cookie(new CanonicalCookie( | 256 scoped_ptr<CanonicalCookie> cookie(new CanonicalCookie( |
| 256 url, cookie_name, cookie_value, cookie_domain, cookie_path, creation_time, | 257 url, cookie_name, cookie_value, cookie_domain, cookie_path, creation_time, |
| 257 expiration_time, last_access_time, secure, httponly, same_site, | 258 expiration_time, last_access_time, secure, httponly, same_site, |
| 258 COOKIE_PRIORITY_MEDIUM)); | 259 COOKIE_PRIORITY_MEDIUM)); |
| 259 EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*cookie)); | 260 EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*cookie)); |
| 260 | 261 |
| 261 // Test that two identical cookies are equivalent. | 262 // Test that two identical cookies are equivalent. |
| 262 scoped_ptr<CanonicalCookie> other_cookie(new CanonicalCookie( | 263 scoped_ptr<CanonicalCookie> other_cookie(new CanonicalCookie( |
| (...skipping 29 matching lines...) Expand all Loading... |
| 292 EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie)); | 293 EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie)); |
| 293 | 294 |
| 294 other_cookie.reset(new CanonicalCookie( | 295 other_cookie.reset(new CanonicalCookie( |
| 295 url, cookie_name, cookie_name, cookie_domain, cookie_path, creation_time, | 296 url, cookie_name, cookie_name, cookie_domain, cookie_path, creation_time, |
| 296 expiration_time, last_access_time, secure, true, same_site, | 297 expiration_time, last_access_time, secure, true, same_site, |
| 297 COOKIE_PRIORITY_LOW)); | 298 COOKIE_PRIORITY_LOW)); |
| 298 EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie)); | 299 EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie)); |
| 299 | 300 |
| 300 other_cookie.reset(new CanonicalCookie( | 301 other_cookie.reset(new CanonicalCookie( |
| 301 url, cookie_name, cookie_name, cookie_domain, cookie_path, creation_time, | 302 url, cookie_name, cookie_name, cookie_domain, cookie_path, creation_time, |
| 302 expiration_time, last_access_time, secure, httponly, true, | 303 expiration_time, last_access_time, secure, httponly, |
| 303 COOKIE_PRIORITY_LOW)); | 304 COOKIE_SAME_SITE_STRICT, COOKIE_PRIORITY_LOW)); |
| 304 EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie)); | 305 EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie)); |
| 305 | 306 |
| 306 // The following 3 tests' expected results differ from their IsEquivalent | 307 // The following 3 tests' expected results differ from their IsEquivalent |
| 307 // counterparts above. | 308 // counterparts above. |
| 308 other_cookie.reset(new CanonicalCookie( | 309 other_cookie.reset(new CanonicalCookie( |
| 309 url, cookie_name, cookie_value, cookie_domain, "/test/0", creation_time, | 310 url, cookie_name, cookie_value, cookie_domain, "/test/0", creation_time, |
| 310 expiration_time, last_access_time, secure, httponly, same_site, | 311 expiration_time, last_access_time, secure, httponly, same_site, |
| 311 COOKIE_PRIORITY_MEDIUM)); | 312 COOKIE_PRIORITY_MEDIUM)); |
| 312 EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie)); | 313 EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie)); |
| 313 | 314 |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 GURL insecure_url("http://example.test"); | 438 GURL insecure_url("http://example.test"); |
| 438 GURL secure_url("https://example.test"); | 439 GURL secure_url("https://example.test"); |
| 439 GURL secure_url_with_path("https://example.test/foo/bar/index.html"); | 440 GURL secure_url_with_path("https://example.test/foo/bar/index.html"); |
| 440 GURL third_party_url("https://not-example.test"); | 441 GURL third_party_url("https://not-example.test"); |
| 441 base::Time creation_time = base::Time::Now(); | 442 base::Time creation_time = base::Time::Now(); |
| 442 CookieOptions options; | 443 CookieOptions options; |
| 443 scoped_ptr<CanonicalCookie> cookie; | 444 scoped_ptr<CanonicalCookie> cookie; |
| 444 | 445 |
| 445 // Same-site cookies are not included for cross-site requests, | 446 // Same-site cookies are not included for cross-site requests, |
| 446 // even if other properties match: | 447 // even if other properties match: |
| 447 cookie = CanonicalCookie::Create(secure_url, "A=2; SameSite", creation_time, | 448 cookie = CanonicalCookie::Create(secure_url, "A=2; SameSite=Strict", |
| 448 options); | 449 creation_time, options); |
| 449 EXPECT_TRUE(cookie->IsSameSite()); | 450 EXPECT_EQ(COOKIE_SAME_SITE_STRICT, cookie->SameSite()); |
| 450 EXPECT_FALSE(cookie->IncludeForRequestURL(secure_url, options)); | 451 EXPECT_FALSE(cookie->IncludeForRequestURL(secure_url, options)); |
| 451 cookie = CanonicalCookie::Create(secure_url, "A=2; Secure; SameSite", | 452 cookie = CanonicalCookie::Create(secure_url, "A=2; Secure; SameSite=Strict", |
| 452 creation_time, options); | 453 creation_time, options); |
| 453 EXPECT_TRUE(cookie->IsSameSite()); | 454 EXPECT_EQ(COOKIE_SAME_SITE_STRICT, cookie->SameSite()); |
| 454 EXPECT_FALSE(cookie->IncludeForRequestURL(secure_url, options)); | 455 EXPECT_FALSE(cookie->IncludeForRequestURL(secure_url, options)); |
| 455 cookie = CanonicalCookie::Create(secure_url_with_path, | 456 cookie = CanonicalCookie::Create(secure_url_with_path, |
| 456 "A=2; SameSite; path=/foo/bar", | 457 "A=2; SameSite=Strict; path=/foo/bar", |
| 457 creation_time, options); | 458 creation_time, options); |
| 458 EXPECT_TRUE(cookie->IsSameSite()); | 459 EXPECT_EQ(COOKIE_SAME_SITE_STRICT, cookie->SameSite()); |
| 459 EXPECT_FALSE(cookie->IncludeForRequestURL(secure_url, options)); | 460 EXPECT_FALSE(cookie->IncludeForRequestURL(secure_url, options)); |
| 460 | 461 |
| 461 // Same-site cookies are included for same-site requests: | 462 // Same-site cookies are included for same-site requests: |
| 462 options.set_include_same_site(); | 463 options.set_include_same_site(); |
| 463 cookie = CanonicalCookie::Create(secure_url, "A=2; SameSite", creation_time, | 464 cookie = CanonicalCookie::Create(secure_url, "A=2; SameSite=Strict", |
| 464 options); | 465 creation_time, options); |
| 465 EXPECT_TRUE(cookie->IsSameSite()); | 466 EXPECT_EQ(COOKIE_SAME_SITE_STRICT, cookie->SameSite()); |
| 466 EXPECT_TRUE(cookie->IncludeForRequestURL(secure_url, options)); | 467 EXPECT_TRUE(cookie->IncludeForRequestURL(secure_url, options)); |
| 467 cookie = CanonicalCookie::Create(secure_url, "A=2; Secure; SameSite", | 468 cookie = CanonicalCookie::Create(secure_url, "A=2; Secure; SameSite=Strict", |
| 468 creation_time, options); | 469 creation_time, options); |
| 469 EXPECT_TRUE(cookie->IsSameSite()); | 470 EXPECT_EQ(COOKIE_SAME_SITE_STRICT, cookie->SameSite()); |
| 470 EXPECT_TRUE(cookie->IncludeForRequestURL(secure_url, options)); | 471 EXPECT_TRUE(cookie->IncludeForRequestURL(secure_url, options)); |
| 471 cookie = CanonicalCookie::Create(secure_url_with_path, | 472 cookie = CanonicalCookie::Create(secure_url_with_path, |
| 472 "A=2; SameSite; path=/foo/bar", | 473 "A=2; SameSite=Strict; path=/foo/bar", |
| 473 creation_time, options); | 474 creation_time, options); |
| 474 EXPECT_TRUE(cookie->IsSameSite()); | 475 EXPECT_EQ(COOKIE_SAME_SITE_STRICT, cookie->SameSite()); |
| 475 EXPECT_TRUE(cookie->IncludeForRequestURL(secure_url_with_path, options)); | 476 EXPECT_TRUE(cookie->IncludeForRequestURL(secure_url_with_path, options)); |
| 476 } | 477 } |
| 477 | 478 |
| 478 TEST(CanonicalCookieTest, PartialCompare) { | 479 TEST(CanonicalCookieTest, PartialCompare) { |
| 479 GURL url("http://www.example.com"); | 480 GURL url("http://www.example.com"); |
| 480 base::Time creation_time = base::Time::Now(); | 481 base::Time creation_time = base::Time::Now(); |
| 481 CookieOptions options; | 482 CookieOptions options; |
| 482 scoped_ptr<CanonicalCookie> cookie( | 483 scoped_ptr<CanonicalCookie> cookie( |
| 483 CanonicalCookie::Create(url, "a=b", creation_time, options)); | 484 CanonicalCookie::Create(url, "a=b", creation_time, options)); |
| 484 scoped_ptr<CanonicalCookie> cookie_different_path( | 485 scoped_ptr<CanonicalCookie> cookie_different_path( |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 628 CanonicalCookie::Create(https_url, "a=b", creation_time, options)); | 629 CanonicalCookie::Create(https_url, "a=b", creation_time, options)); |
| 629 scoped_ptr<CanonicalCookie> https_cookie_secure(CanonicalCookie::Create( | 630 scoped_ptr<CanonicalCookie> https_cookie_secure(CanonicalCookie::Create( |
| 630 https_url, "a=b; Secure", creation_time, options)); | 631 https_url, "a=b; Secure", creation_time, options)); |
| 631 | 632 |
| 632 EXPECT_TRUE(http_cookie_no_secure.get()); | 633 EXPECT_TRUE(http_cookie_no_secure.get()); |
| 633 EXPECT_FALSE(http_cookie_secure.get()); | 634 EXPECT_FALSE(http_cookie_secure.get()); |
| 634 EXPECT_TRUE(https_cookie_no_secure.get()); | 635 EXPECT_TRUE(https_cookie_no_secure.get()); |
| 635 EXPECT_TRUE(https_cookie_secure.get()); | 636 EXPECT_TRUE(https_cookie_secure.get()); |
| 636 | 637 |
| 637 scoped_ptr<CanonicalCookie> http_cookie_no_secure_extended( | 638 scoped_ptr<CanonicalCookie> http_cookie_no_secure_extended( |
| 638 CanonicalCookie::Create(http_url, "a", "b", "", "", creation_time, | 639 CanonicalCookie::Create( |
| 639 creation_time, false, false, false, true, | 640 http_url, "a", "b", "", "", creation_time, creation_time, false, |
| 640 COOKIE_PRIORITY_DEFAULT)); | 641 false, COOKIE_SAME_SITE_STRICT, true, COOKIE_PRIORITY_DEFAULT)); |
| 641 scoped_ptr<CanonicalCookie> http_cookie_secure_extended( | 642 scoped_ptr<CanonicalCookie> http_cookie_secure_extended( |
| 642 CanonicalCookie::Create(http_url, "a", "b", "", "", creation_time, | 643 CanonicalCookie::Create( |
| 643 creation_time, true, false, false, true, | 644 http_url, "a", "b", "", "", creation_time, creation_time, true, false, |
| 644 COOKIE_PRIORITY_DEFAULT)); | 645 COOKIE_SAME_SITE_STRICT, true, COOKIE_PRIORITY_DEFAULT)); |
| 645 scoped_ptr<CanonicalCookie> https_cookie_no_secure_extended( | 646 scoped_ptr<CanonicalCookie> https_cookie_no_secure_extended( |
| 646 CanonicalCookie::Create(https_url, "a", "b", "", "", creation_time, | 647 CanonicalCookie::Create( |
| 647 creation_time, false, false, false, true, | 648 https_url, "a", "b", "", "", creation_time, creation_time, false, |
| 648 COOKIE_PRIORITY_DEFAULT)); | 649 false, COOKIE_SAME_SITE_STRICT, true, COOKIE_PRIORITY_DEFAULT)); |
| 649 scoped_ptr<CanonicalCookie> https_cookie_secure_extended( | 650 scoped_ptr<CanonicalCookie> https_cookie_secure_extended( |
| 650 CanonicalCookie::Create(https_url, "a", "b", "", "", creation_time, | 651 CanonicalCookie::Create( |
| 651 creation_time, true, false, false, true, | 652 https_url, "a", "b", "", "", creation_time, creation_time, true, |
| 652 COOKIE_PRIORITY_DEFAULT)); | 653 false, COOKIE_SAME_SITE_STRICT, true, COOKIE_PRIORITY_DEFAULT)); |
| 653 | 654 |
| 654 EXPECT_TRUE(http_cookie_no_secure_extended.get()); | 655 EXPECT_TRUE(http_cookie_no_secure_extended.get()); |
| 655 EXPECT_FALSE(http_cookie_secure_extended.get()); | 656 EXPECT_FALSE(http_cookie_secure_extended.get()); |
| 656 EXPECT_TRUE(https_cookie_no_secure_extended.get()); | 657 EXPECT_TRUE(https_cookie_no_secure_extended.get()); |
| 657 EXPECT_TRUE(https_cookie_secure_extended.get()); | 658 EXPECT_TRUE(https_cookie_secure_extended.get()); |
| 658 } | 659 } |
| 659 | 660 |
| 660 TEST(CanonicalCookieTest, TestPrefixHistograms) { | 661 TEST(CanonicalCookieTest, TestPrefixHistograms) { |
| 661 base::HistogramTester histograms; | 662 base::HistogramTester histograms; |
| 662 const char kCookiePrefixHistogram[] = "Cookie.CookiePrefix"; | 663 const char kCookiePrefixHistogram[] = "Cookie.CookiePrefix"; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 701 CanonicalCookie::COOKIE_PREFIX_SECURE, 1); | 702 CanonicalCookie::COOKIE_PREFIX_SECURE, 1); |
| 702 EXPECT_TRUE(CanonicalCookie::Create(https_url, "__SecureA=B; Path=/; Secure", | 703 EXPECT_TRUE(CanonicalCookie::Create(https_url, "__SecureA=B; Path=/; Secure", |
| 703 creation_time, options)); | 704 creation_time, options)); |
| 704 histograms.ExpectBucketCount(kCookiePrefixHistogram, | 705 histograms.ExpectBucketCount(kCookiePrefixHistogram, |
| 705 CanonicalCookie::COOKIE_PREFIX_SECURE, 2); | 706 CanonicalCookie::COOKIE_PREFIX_SECURE, 2); |
| 706 histograms.ExpectBucketCount(kCookiePrefixBlockedHistogram, | 707 histograms.ExpectBucketCount(kCookiePrefixBlockedHistogram, |
| 707 CanonicalCookie::COOKIE_PREFIX_SECURE, 1); | 708 CanonicalCookie::COOKIE_PREFIX_SECURE, 1); |
| 708 } | 709 } |
| 709 | 710 |
| 710 } // namespace net | 711 } // namespace net |
| OLD | NEW |