| 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 CookieSameSite::DEFAULT_MODE, 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(CookieSameSite::NO_RESTRICTION, 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, CookieSameSite::DEFAULT_MODE, |
| 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(CookieSameSite::NO_RESTRICTION, 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 22 matching lines...) Expand all Loading... |
| 75 // Test creating http only cookies. | 76 // Test creating http only cookies. |
| 76 cookie = | 77 cookie = |
| 77 CanonicalCookie::Create(url, "A=2; HttpOnly", creation_time, options); | 78 CanonicalCookie::Create(url, "A=2; HttpOnly", creation_time, options); |
| 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 SameSite 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(); |
| 89 cookie = CanonicalCookie::Create(url, "A=2; SameSite=Strict", creation_time, |
| 90 same_site_options); |
| 91 EXPECT_TRUE(cookie.get()); |
| 92 EXPECT_EQ(CookieSameSite::STRICT_MODE, cookie->SameSite()); |
| 93 cookie = CanonicalCookie::Create(url, "A=2; SameSite=Lax", creation_time, |
| 94 same_site_options); |
| 95 EXPECT_TRUE(cookie.get()); |
| 96 EXPECT_EQ(CookieSameSite::LAX_MODE, cookie->SameSite()); |
| 88 cookie = CanonicalCookie::Create(url, "A=2; SameSite", creation_time, | 97 cookie = CanonicalCookie::Create(url, "A=2; SameSite", creation_time, |
| 89 same_site_options); | 98 same_site_options); |
| 90 EXPECT_TRUE(cookie.get()); | 99 EXPECT_TRUE(cookie.get()); |
| 91 EXPECT_TRUE(cookie->IsSameSite()); | 100 EXPECT_EQ(CookieSameSite::NO_RESTRICTION, cookie->SameSite()); |
| 92 | 101 |
| 93 // Test the creating cookies using specific parameter instead of a cookie | 102 // Test the creating cookies using specific parameter instead of a cookie |
| 94 // string. | 103 // string. |
| 95 cookie = CanonicalCookie::Create(url, "A", "2", "www.example.com", "/test", | 104 cookie = CanonicalCookie::Create(url, "A", "2", "www.example.com", "/test", |
| 96 creation_time, base::Time(), false, false, | 105 creation_time, base::Time(), false, false, |
| 97 false, false, COOKIE_PRIORITY_DEFAULT); | 106 CookieSameSite::DEFAULT_MODE, false, |
| 107 COOKIE_PRIORITY_DEFAULT); |
| 98 EXPECT_EQ(url.GetOrigin(), cookie->Source()); | 108 EXPECT_EQ(url.GetOrigin(), cookie->Source()); |
| 99 EXPECT_EQ("A", cookie->Name()); | 109 EXPECT_EQ("A", cookie->Name()); |
| 100 EXPECT_EQ("2", cookie->Value()); | 110 EXPECT_EQ("2", cookie->Value()); |
| 101 EXPECT_EQ(".www.example.com", cookie->Domain()); | 111 EXPECT_EQ(".www.example.com", cookie->Domain()); |
| 102 EXPECT_EQ("/test", cookie->Path()); | 112 EXPECT_EQ("/test", cookie->Path()); |
| 103 EXPECT_FALSE(cookie->IsSecure()); | 113 EXPECT_FALSE(cookie->IsSecure()); |
| 104 EXPECT_FALSE(cookie->IsHttpOnly()); | 114 EXPECT_FALSE(cookie->IsHttpOnly()); |
| 105 EXPECT_FALSE(cookie->IsSameSite()); | 115 EXPECT_EQ(CookieSameSite::NO_RESTRICTION, cookie->SameSite()); |
| 106 | 116 |
| 107 cookie = CanonicalCookie::Create(url, "A", "2", ".www.example.com", "/test", | 117 cookie = CanonicalCookie::Create(url, "A", "2", ".www.example.com", "/test", |
| 108 creation_time, base::Time(), false, false, | 118 creation_time, base::Time(), false, false, |
| 109 false, false, COOKIE_PRIORITY_DEFAULT); | 119 CookieSameSite::DEFAULT_MODE, false, |
| 120 COOKIE_PRIORITY_DEFAULT); |
| 110 EXPECT_EQ(url.GetOrigin(), cookie->Source()); | 121 EXPECT_EQ(url.GetOrigin(), cookie->Source()); |
| 111 EXPECT_EQ("A", cookie->Name()); | 122 EXPECT_EQ("A", cookie->Name()); |
| 112 EXPECT_EQ("2", cookie->Value()); | 123 EXPECT_EQ("2", cookie->Value()); |
| 113 EXPECT_EQ(".www.example.com", cookie->Domain()); | 124 EXPECT_EQ(".www.example.com", cookie->Domain()); |
| 114 EXPECT_EQ("/test", cookie->Path()); | 125 EXPECT_EQ("/test", cookie->Path()); |
| 115 EXPECT_FALSE(cookie->IsSecure()); | 126 EXPECT_FALSE(cookie->IsSecure()); |
| 116 EXPECT_FALSE(cookie->IsHttpOnly()); | 127 EXPECT_FALSE(cookie->IsHttpOnly()); |
| 117 EXPECT_FALSE(cookie->IsSameSite()); | 128 EXPECT_EQ(CookieSameSite::NO_RESTRICTION, cookie->SameSite()); |
| 118 } | 129 } |
| 119 | 130 |
| 120 TEST(CanonicalCookieTest, EmptyExpiry) { | 131 TEST(CanonicalCookieTest, EmptyExpiry) { |
| 121 GURL url("http://www7.ipdl.inpit.go.jp/Tokujitu/tjkta.ipdl?N0000=108"); | 132 GURL url("http://www7.ipdl.inpit.go.jp/Tokujitu/tjkta.ipdl?N0000=108"); |
| 122 base::Time creation_time = base::Time::Now(); | 133 base::Time creation_time = base::Time::Now(); |
| 123 CookieOptions options; | 134 CookieOptions options; |
| 124 | 135 |
| 125 std::string cookie_line = | 136 std::string cookie_line = |
| 126 "ACSTM=20130308043820420042; path=/; domain=ipdl.inpit.go.jp; Expires="; | 137 "ACSTM=20130308043820420042; path=/; domain=ipdl.inpit.go.jp; Expires="; |
| 127 scoped_ptr<CanonicalCookie> cookie( | 138 scoped_ptr<CanonicalCookie> cookie( |
| (...skipping 24 matching lines...) Expand all Loading... |
| 152 GURL url("http://www.example.com/"); | 163 GURL url("http://www.example.com/"); |
| 153 std::string cookie_name = "A"; | 164 std::string cookie_name = "A"; |
| 154 std::string cookie_value = "2EDA-EF"; | 165 std::string cookie_value = "2EDA-EF"; |
| 155 std::string cookie_domain = ".www.example.com"; | 166 std::string cookie_domain = ".www.example.com"; |
| 156 std::string cookie_path = "/"; | 167 std::string cookie_path = "/"; |
| 157 base::Time creation_time = base::Time::Now(); | 168 base::Time creation_time = base::Time::Now(); |
| 158 base::Time last_access_time = creation_time; | 169 base::Time last_access_time = creation_time; |
| 159 base::Time expiration_time = creation_time + base::TimeDelta::FromDays(2); | 170 base::Time expiration_time = creation_time + base::TimeDelta::FromDays(2); |
| 160 bool secure(false); | 171 bool secure(false); |
| 161 bool httponly(false); | 172 bool httponly(false); |
| 162 bool same_site(false); | 173 CookieSameSite same_site(CookieSameSite::NO_RESTRICTION); |
| 163 | 174 |
| 164 // Test that a cookie is equivalent to itself. | 175 // Test that a cookie is equivalent to itself. |
| 165 scoped_ptr<CanonicalCookie> cookie(new CanonicalCookie( | 176 scoped_ptr<CanonicalCookie> cookie(new CanonicalCookie( |
| 166 url, cookie_name, cookie_value, cookie_domain, cookie_path, creation_time, | 177 url, cookie_name, cookie_value, cookie_domain, cookie_path, creation_time, |
| 167 expiration_time, last_access_time, secure, httponly, same_site, | 178 expiration_time, last_access_time, secure, httponly, same_site, |
| 168 COOKIE_PRIORITY_MEDIUM)); | 179 COOKIE_PRIORITY_MEDIUM)); |
| 169 EXPECT_TRUE(cookie->IsEquivalent(*cookie)); | 180 EXPECT_TRUE(cookie->IsEquivalent(*cookie)); |
| 170 | 181 |
| 171 // Test that two identical cookies are equivalent. | 182 // Test that two identical cookies are equivalent. |
| 172 scoped_ptr<CanonicalCookie> other_cookie(new CanonicalCookie( | 183 scoped_ptr<CanonicalCookie> other_cookie(new CanonicalCookie( |
| (...skipping 25 matching lines...) Expand all Loading... |
| 198 EXPECT_TRUE(cookie->IsEquivalent(*other_cookie)); | 209 EXPECT_TRUE(cookie->IsEquivalent(*other_cookie)); |
| 199 | 210 |
| 200 other_cookie.reset(new CanonicalCookie( | 211 other_cookie.reset(new CanonicalCookie( |
| 201 url, cookie_name, cookie_name, cookie_domain, cookie_path, creation_time, | 212 url, cookie_name, cookie_name, cookie_domain, cookie_path, creation_time, |
| 202 expiration_time, last_access_time, secure, true, same_site, | 213 expiration_time, last_access_time, secure, true, same_site, |
| 203 COOKIE_PRIORITY_LOW)); | 214 COOKIE_PRIORITY_LOW)); |
| 204 EXPECT_TRUE(cookie->IsEquivalent(*other_cookie)); | 215 EXPECT_TRUE(cookie->IsEquivalent(*other_cookie)); |
| 205 | 216 |
| 206 other_cookie.reset(new CanonicalCookie( | 217 other_cookie.reset(new CanonicalCookie( |
| 207 url, cookie_name, cookie_name, cookie_domain, cookie_path, creation_time, | 218 url, cookie_name, cookie_name, cookie_domain, cookie_path, creation_time, |
| 208 expiration_time, last_access_time, secure, httponly, true, | 219 expiration_time, last_access_time, secure, httponly, |
| 209 COOKIE_PRIORITY_LOW)); | 220 CookieSameSite::STRICT_MODE, COOKIE_PRIORITY_LOW)); |
| 210 EXPECT_TRUE(cookie->IsEquivalent(*other_cookie)); | 221 EXPECT_TRUE(cookie->IsEquivalent(*other_cookie)); |
| 211 | 222 |
| 212 // Tests that use different variations of attribute values that | 223 // Tests that use different variations of attribute values that |
| 213 // DO affect cookie equivalence. | 224 // DO affect cookie equivalence. |
| 214 other_cookie.reset( | 225 other_cookie.reset( |
| 215 new CanonicalCookie(url, "B", cookie_value, cookie_domain, cookie_path, | 226 new CanonicalCookie(url, "B", cookie_value, cookie_domain, cookie_path, |
| 216 creation_time, expiration_time, last_access_time, | 227 creation_time, expiration_time, last_access_time, |
| 217 secure, httponly, same_site, COOKIE_PRIORITY_MEDIUM)); | 228 secure, httponly, same_site, COOKIE_PRIORITY_MEDIUM)); |
| 218 EXPECT_FALSE(cookie->IsEquivalent(*other_cookie)); | 229 EXPECT_FALSE(cookie->IsEquivalent(*other_cookie)); |
| 219 | 230 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 242 GURL url("http://www.example.com/"); | 253 GURL url("http://www.example.com/"); |
| 243 std::string cookie_name = "A"; | 254 std::string cookie_name = "A"; |
| 244 std::string cookie_value = "2EDA-EF"; | 255 std::string cookie_value = "2EDA-EF"; |
| 245 std::string cookie_domain = ".www.example.com"; | 256 std::string cookie_domain = ".www.example.com"; |
| 246 std::string cookie_path = "/"; | 257 std::string cookie_path = "/"; |
| 247 base::Time creation_time = base::Time::Now(); | 258 base::Time creation_time = base::Time::Now(); |
| 248 base::Time last_access_time = creation_time; | 259 base::Time last_access_time = creation_time; |
| 249 base::Time expiration_time = creation_time + base::TimeDelta::FromDays(2); | 260 base::Time expiration_time = creation_time + base::TimeDelta::FromDays(2); |
| 250 bool secure(false); | 261 bool secure(false); |
| 251 bool httponly(false); | 262 bool httponly(false); |
| 252 bool same_site(false); | 263 CookieSameSite same_site(CookieSameSite::NO_RESTRICTION); |
| 253 | 264 |
| 254 // Test that a cookie is equivalent to itself. | 265 // Test that a cookie is equivalent to itself. |
| 255 scoped_ptr<CanonicalCookie> cookie(new CanonicalCookie( | 266 scoped_ptr<CanonicalCookie> cookie(new CanonicalCookie( |
| 256 url, cookie_name, cookie_value, cookie_domain, cookie_path, creation_time, | 267 url, cookie_name, cookie_value, cookie_domain, cookie_path, creation_time, |
| 257 expiration_time, last_access_time, secure, httponly, same_site, | 268 expiration_time, last_access_time, secure, httponly, same_site, |
| 258 COOKIE_PRIORITY_MEDIUM)); | 269 COOKIE_PRIORITY_MEDIUM)); |
| 259 EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*cookie)); | 270 EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*cookie)); |
| 260 | 271 |
| 261 // Test that two identical cookies are equivalent. | 272 // Test that two identical cookies are equivalent. |
| 262 scoped_ptr<CanonicalCookie> other_cookie(new CanonicalCookie( | 273 scoped_ptr<CanonicalCookie> other_cookie(new CanonicalCookie( |
| (...skipping 29 matching lines...) Expand all Loading... |
| 292 EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie)); | 303 EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie)); |
| 293 | 304 |
| 294 other_cookie.reset(new CanonicalCookie( | 305 other_cookie.reset(new CanonicalCookie( |
| 295 url, cookie_name, cookie_name, cookie_domain, cookie_path, creation_time, | 306 url, cookie_name, cookie_name, cookie_domain, cookie_path, creation_time, |
| 296 expiration_time, last_access_time, secure, true, same_site, | 307 expiration_time, last_access_time, secure, true, same_site, |
| 297 COOKIE_PRIORITY_LOW)); | 308 COOKIE_PRIORITY_LOW)); |
| 298 EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie)); | 309 EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie)); |
| 299 | 310 |
| 300 other_cookie.reset(new CanonicalCookie( | 311 other_cookie.reset(new CanonicalCookie( |
| 301 url, cookie_name, cookie_name, cookie_domain, cookie_path, creation_time, | 312 url, cookie_name, cookie_name, cookie_domain, cookie_path, creation_time, |
| 302 expiration_time, last_access_time, secure, httponly, true, | 313 expiration_time, last_access_time, secure, httponly, |
| 303 COOKIE_PRIORITY_LOW)); | 314 CookieSameSite::STRICT_MODE, COOKIE_PRIORITY_LOW)); |
| 304 EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie)); | 315 EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie)); |
| 305 | 316 |
| 306 // The following 3 tests' expected results differ from their IsEquivalent | 317 // The following 3 tests' expected results differ from their IsEquivalent |
| 307 // counterparts above. | 318 // counterparts above. |
| 308 other_cookie.reset(new CanonicalCookie( | 319 other_cookie.reset(new CanonicalCookie( |
| 309 url, cookie_name, cookie_value, cookie_domain, "/test/0", creation_time, | 320 url, cookie_name, cookie_value, cookie_domain, "/test/0", creation_time, |
| 310 expiration_time, last_access_time, secure, httponly, same_site, | 321 expiration_time, last_access_time, secure, httponly, same_site, |
| 311 COOKIE_PRIORITY_MEDIUM)); | 322 COOKIE_PRIORITY_MEDIUM)); |
| 312 EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie)); | 323 EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie)); |
| 313 | 324 |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 GURL insecure_url("http://example.test"); | 448 GURL insecure_url("http://example.test"); |
| 438 GURL secure_url("https://example.test"); | 449 GURL secure_url("https://example.test"); |
| 439 GURL secure_url_with_path("https://example.test/foo/bar/index.html"); | 450 GURL secure_url_with_path("https://example.test/foo/bar/index.html"); |
| 440 GURL third_party_url("https://not-example.test"); | 451 GURL third_party_url("https://not-example.test"); |
| 441 base::Time creation_time = base::Time::Now(); | 452 base::Time creation_time = base::Time::Now(); |
| 442 CookieOptions options; | 453 CookieOptions options; |
| 443 scoped_ptr<CanonicalCookie> cookie; | 454 scoped_ptr<CanonicalCookie> cookie; |
| 444 | 455 |
| 445 // Same-site cookies are not included for cross-site requests, | 456 // Same-site cookies are not included for cross-site requests, |
| 446 // even if other properties match: | 457 // even if other properties match: |
| 447 cookie = CanonicalCookie::Create(secure_url, "A=2; SameSite", creation_time, | 458 cookie = CanonicalCookie::Create(secure_url, "A=2; SameSite=Strict", |
| 448 options); | 459 creation_time, options); |
| 449 EXPECT_TRUE(cookie->IsSameSite()); | 460 EXPECT_EQ(CookieSameSite::STRICT_MODE, cookie->SameSite()); |
| 450 EXPECT_FALSE(cookie->IncludeForRequestURL(secure_url, options)); | 461 EXPECT_FALSE(cookie->IncludeForRequestURL(secure_url, options)); |
| 451 cookie = CanonicalCookie::Create(secure_url, "A=2; Secure; SameSite", | 462 cookie = CanonicalCookie::Create(secure_url, "A=2; Secure; SameSite=Strict", |
| 452 creation_time, options); | 463 creation_time, options); |
| 453 EXPECT_TRUE(cookie->IsSameSite()); | 464 EXPECT_EQ(CookieSameSite::STRICT_MODE, cookie->SameSite()); |
| 454 EXPECT_FALSE(cookie->IncludeForRequestURL(secure_url, options)); | 465 EXPECT_FALSE(cookie->IncludeForRequestURL(secure_url, options)); |
| 455 cookie = CanonicalCookie::Create(secure_url_with_path, | 466 cookie = CanonicalCookie::Create(secure_url_with_path, |
| 456 "A=2; SameSite; path=/foo/bar", | 467 "A=2; SameSite=Strict; path=/foo/bar", |
| 457 creation_time, options); | 468 creation_time, options); |
| 458 EXPECT_TRUE(cookie->IsSameSite()); | 469 EXPECT_EQ(CookieSameSite::STRICT_MODE, cookie->SameSite()); |
| 459 EXPECT_FALSE(cookie->IncludeForRequestURL(secure_url, options)); | 470 EXPECT_FALSE(cookie->IncludeForRequestURL(secure_url, options)); |
| 460 | 471 |
| 461 // Same-site cookies are included for same-site requests: | 472 // Same-site cookies are included for same-site requests: |
| 462 options.set_include_same_site(); | 473 options.set_include_same_site(); |
| 463 cookie = CanonicalCookie::Create(secure_url, "A=2; SameSite", creation_time, | 474 cookie = CanonicalCookie::Create(secure_url, "A=2; SameSite=Strict", |
| 464 options); | 475 creation_time, options); |
| 465 EXPECT_TRUE(cookie->IsSameSite()); | 476 EXPECT_EQ(CookieSameSite::STRICT_MODE, cookie->SameSite()); |
| 466 EXPECT_TRUE(cookie->IncludeForRequestURL(secure_url, options)); | 477 EXPECT_TRUE(cookie->IncludeForRequestURL(secure_url, options)); |
| 467 cookie = CanonicalCookie::Create(secure_url, "A=2; Secure; SameSite", | 478 cookie = CanonicalCookie::Create(secure_url, "A=2; Secure; SameSite=Strict", |
| 468 creation_time, options); | 479 creation_time, options); |
| 469 EXPECT_TRUE(cookie->IsSameSite()); | 480 EXPECT_EQ(CookieSameSite::STRICT_MODE, cookie->SameSite()); |
| 470 EXPECT_TRUE(cookie->IncludeForRequestURL(secure_url, options)); | 481 EXPECT_TRUE(cookie->IncludeForRequestURL(secure_url, options)); |
| 471 cookie = CanonicalCookie::Create(secure_url_with_path, | 482 cookie = CanonicalCookie::Create(secure_url_with_path, |
| 472 "A=2; SameSite; path=/foo/bar", | 483 "A=2; SameSite=Strict; path=/foo/bar", |
| 473 creation_time, options); | 484 creation_time, options); |
| 474 EXPECT_TRUE(cookie->IsSameSite()); | 485 EXPECT_EQ(CookieSameSite::STRICT_MODE, cookie->SameSite()); |
| 475 EXPECT_TRUE(cookie->IncludeForRequestURL(secure_url_with_path, options)); | 486 EXPECT_TRUE(cookie->IncludeForRequestURL(secure_url_with_path, options)); |
| 476 } | 487 } |
| 477 | 488 |
| 478 TEST(CanonicalCookieTest, PartialCompare) { | 489 TEST(CanonicalCookieTest, PartialCompare) { |
| 479 GURL url("http://www.example.com"); | 490 GURL url("http://www.example.com"); |
| 480 base::Time creation_time = base::Time::Now(); | 491 base::Time creation_time = base::Time::Now(); |
| 481 CookieOptions options; | 492 CookieOptions options; |
| 482 scoped_ptr<CanonicalCookie> cookie( | 493 scoped_ptr<CanonicalCookie> cookie( |
| 483 CanonicalCookie::Create(url, "a=b", creation_time, options)); | 494 CanonicalCookie::Create(url, "a=b", creation_time, options)); |
| 484 scoped_ptr<CanonicalCookie> cookie_different_path( | 495 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)); | 639 CanonicalCookie::Create(https_url, "a=b", creation_time, options)); |
| 629 scoped_ptr<CanonicalCookie> https_cookie_secure(CanonicalCookie::Create( | 640 scoped_ptr<CanonicalCookie> https_cookie_secure(CanonicalCookie::Create( |
| 630 https_url, "a=b; Secure", creation_time, options)); | 641 https_url, "a=b; Secure", creation_time, options)); |
| 631 | 642 |
| 632 EXPECT_TRUE(http_cookie_no_secure.get()); | 643 EXPECT_TRUE(http_cookie_no_secure.get()); |
| 633 EXPECT_FALSE(http_cookie_secure.get()); | 644 EXPECT_FALSE(http_cookie_secure.get()); |
| 634 EXPECT_TRUE(https_cookie_no_secure.get()); | 645 EXPECT_TRUE(https_cookie_no_secure.get()); |
| 635 EXPECT_TRUE(https_cookie_secure.get()); | 646 EXPECT_TRUE(https_cookie_secure.get()); |
| 636 | 647 |
| 637 scoped_ptr<CanonicalCookie> http_cookie_no_secure_extended( | 648 scoped_ptr<CanonicalCookie> http_cookie_no_secure_extended( |
| 638 CanonicalCookie::Create(http_url, "a", "b", "", "", creation_time, | 649 CanonicalCookie::Create( |
| 639 creation_time, false, false, false, true, | 650 http_url, "a", "b", "", "", creation_time, creation_time, false, |
| 640 COOKIE_PRIORITY_DEFAULT)); | 651 false, CookieSameSite::STRICT_MODE, true, COOKIE_PRIORITY_DEFAULT)); |
| 641 scoped_ptr<CanonicalCookie> http_cookie_secure_extended( | 652 scoped_ptr<CanonicalCookie> http_cookie_secure_extended( |
| 642 CanonicalCookie::Create(http_url, "a", "b", "", "", creation_time, | 653 CanonicalCookie::Create( |
| 643 creation_time, true, false, false, true, | 654 http_url, "a", "b", "", "", creation_time, creation_time, true, false, |
| 644 COOKIE_PRIORITY_DEFAULT)); | 655 CookieSameSite::STRICT_MODE, true, COOKIE_PRIORITY_DEFAULT)); |
| 645 scoped_ptr<CanonicalCookie> https_cookie_no_secure_extended( | 656 scoped_ptr<CanonicalCookie> https_cookie_no_secure_extended( |
| 646 CanonicalCookie::Create(https_url, "a", "b", "", "", creation_time, | 657 CanonicalCookie::Create( |
| 647 creation_time, false, false, false, true, | 658 https_url, "a", "b", "", "", creation_time, creation_time, false, |
| 648 COOKIE_PRIORITY_DEFAULT)); | 659 false, CookieSameSite::STRICT_MODE, true, COOKIE_PRIORITY_DEFAULT)); |
| 649 scoped_ptr<CanonicalCookie> https_cookie_secure_extended( | 660 scoped_ptr<CanonicalCookie> https_cookie_secure_extended( |
| 650 CanonicalCookie::Create(https_url, "a", "b", "", "", creation_time, | 661 CanonicalCookie::Create( |
| 651 creation_time, true, false, false, true, | 662 https_url, "a", "b", "", "", creation_time, creation_time, true, |
| 652 COOKIE_PRIORITY_DEFAULT)); | 663 false, CookieSameSite::STRICT_MODE, true, COOKIE_PRIORITY_DEFAULT)); |
| 653 | 664 |
| 654 EXPECT_TRUE(http_cookie_no_secure_extended.get()); | 665 EXPECT_TRUE(http_cookie_no_secure_extended.get()); |
| 655 EXPECT_FALSE(http_cookie_secure_extended.get()); | 666 EXPECT_FALSE(http_cookie_secure_extended.get()); |
| 656 EXPECT_TRUE(https_cookie_no_secure_extended.get()); | 667 EXPECT_TRUE(https_cookie_no_secure_extended.get()); |
| 657 EXPECT_TRUE(https_cookie_secure_extended.get()); | 668 EXPECT_TRUE(https_cookie_secure_extended.get()); |
| 658 } | 669 } |
| 659 | 670 |
| 660 TEST(CanonicalCookieTest, TestPrefixHistograms) { | 671 TEST(CanonicalCookieTest, TestPrefixHistograms) { |
| 661 base::HistogramTester histograms; | 672 base::HistogramTester histograms; |
| 662 const char kCookiePrefixHistogram[] = "Cookie.CookiePrefix"; | 673 const char kCookiePrefixHistogram[] = "Cookie.CookiePrefix"; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 701 CanonicalCookie::COOKIE_PREFIX_SECURE, 1); | 712 CanonicalCookie::COOKIE_PREFIX_SECURE, 1); |
| 702 EXPECT_TRUE(CanonicalCookie::Create(https_url, "__SecureA=B; Path=/; Secure", | 713 EXPECT_TRUE(CanonicalCookie::Create(https_url, "__SecureA=B; Path=/; Secure", |
| 703 creation_time, options)); | 714 creation_time, options)); |
| 704 histograms.ExpectBucketCount(kCookiePrefixHistogram, | 715 histograms.ExpectBucketCount(kCookiePrefixHistogram, |
| 705 CanonicalCookie::COOKIE_PREFIX_SECURE, 2); | 716 CanonicalCookie::COOKIE_PREFIX_SECURE, 2); |
| 706 histograms.ExpectBucketCount(kCookiePrefixBlockedHistogram, | 717 histograms.ExpectBucketCount(kCookiePrefixBlockedHistogram, |
| 707 CanonicalCookie::COOKIE_PREFIX_SECURE, 1); | 718 CanonicalCookie::COOKIE_PREFIX_SECURE, 1); |
| 708 } | 719 } |
| 709 | 720 |
| 710 } // namespace net | 721 } // namespace net |
| OLD | NEW |