Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(140)

Side by Side Diff: net/cookies/canonical_cookie_unittest.cc

Issue 1773133002: SameSite: Implement 'Strict'/'Lax' attribute parsing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: bugs Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 25 matching lines...) Expand all
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,
mmenke 2016/03/14 20:14:50 Should we have a lax test somewhere in this file,
Mike West 2016/03/15 09:41:10 I plan to add more detailed tests for the distinct
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(CookieSameSite::STRICT_MODE, 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(url, "A", "2", "www.example.com", "/test",
96 creation_time, base::Time(), false, false, 97 creation_time, base::Time(), false, false,
97 false, false, COOKIE_PRIORITY_DEFAULT); 98 CookieSameSite::DEFAULT_MODE, false,
99 COOKIE_PRIORITY_DEFAULT);
98 EXPECT_EQ(url.GetOrigin(), cookie->Source()); 100 EXPECT_EQ(url.GetOrigin(), cookie->Source());
99 EXPECT_EQ("A", cookie->Name()); 101 EXPECT_EQ("A", cookie->Name());
100 EXPECT_EQ("2", cookie->Value()); 102 EXPECT_EQ("2", cookie->Value());
101 EXPECT_EQ(".www.example.com", cookie->Domain()); 103 EXPECT_EQ(".www.example.com", cookie->Domain());
102 EXPECT_EQ("/test", cookie->Path()); 104 EXPECT_EQ("/test", cookie->Path());
103 EXPECT_FALSE(cookie->IsSecure()); 105 EXPECT_FALSE(cookie->IsSecure());
104 EXPECT_FALSE(cookie->IsHttpOnly()); 106 EXPECT_FALSE(cookie->IsHttpOnly());
105 EXPECT_FALSE(cookie->IsSameSite()); 107 EXPECT_EQ(CookieSameSite::NO_RESTRICTION, cookie->SameSite());
106 108
107 cookie = CanonicalCookie::Create(url, "A", "2", ".www.example.com", "/test", 109 cookie = CanonicalCookie::Create(url, "A", "2", ".www.example.com", "/test",
108 creation_time, base::Time(), false, false, 110 creation_time, base::Time(), false, false,
109 false, false, COOKIE_PRIORITY_DEFAULT); 111 CookieSameSite::DEFAULT_MODE, false,
112 COOKIE_PRIORITY_DEFAULT);
110 EXPECT_EQ(url.GetOrigin(), cookie->Source()); 113 EXPECT_EQ(url.GetOrigin(), cookie->Source());
111 EXPECT_EQ("A", cookie->Name()); 114 EXPECT_EQ("A", cookie->Name());
112 EXPECT_EQ("2", cookie->Value()); 115 EXPECT_EQ("2", cookie->Value());
113 EXPECT_EQ(".www.example.com", cookie->Domain()); 116 EXPECT_EQ(".www.example.com", cookie->Domain());
114 EXPECT_EQ("/test", cookie->Path()); 117 EXPECT_EQ("/test", cookie->Path());
115 EXPECT_FALSE(cookie->IsSecure()); 118 EXPECT_FALSE(cookie->IsSecure());
116 EXPECT_FALSE(cookie->IsHttpOnly()); 119 EXPECT_FALSE(cookie->IsHttpOnly());
117 EXPECT_FALSE(cookie->IsSameSite()); 120 EXPECT_EQ(CookieSameSite::NO_RESTRICTION, cookie->SameSite());
118 } 121 }
119 122
120 TEST(CanonicalCookieTest, EmptyExpiry) { 123 TEST(CanonicalCookieTest, EmptyExpiry) {
121 GURL url("http://www7.ipdl.inpit.go.jp/Tokujitu/tjkta.ipdl?N0000=108"); 124 GURL url("http://www7.ipdl.inpit.go.jp/Tokujitu/tjkta.ipdl?N0000=108");
122 base::Time creation_time = base::Time::Now(); 125 base::Time creation_time = base::Time::Now();
123 CookieOptions options; 126 CookieOptions options;
124 127
125 std::string cookie_line = 128 std::string cookie_line =
126 "ACSTM=20130308043820420042; path=/; domain=ipdl.inpit.go.jp; Expires="; 129 "ACSTM=20130308043820420042; path=/; domain=ipdl.inpit.go.jp; Expires=";
127 scoped_ptr<CanonicalCookie> cookie( 130 scoped_ptr<CanonicalCookie> cookie(
(...skipping 24 matching lines...) Expand all
152 GURL url("http://www.example.com/"); 155 GURL url("http://www.example.com/");
153 std::string cookie_name = "A"; 156 std::string cookie_name = "A";
154 std::string cookie_value = "2EDA-EF"; 157 std::string cookie_value = "2EDA-EF";
155 std::string cookie_domain = ".www.example.com"; 158 std::string cookie_domain = ".www.example.com";
156 std::string cookie_path = "/"; 159 std::string cookie_path = "/";
157 base::Time creation_time = base::Time::Now(); 160 base::Time creation_time = base::Time::Now();
158 base::Time last_access_time = creation_time; 161 base::Time last_access_time = creation_time;
159 base::Time expiration_time = creation_time + base::TimeDelta::FromDays(2); 162 base::Time expiration_time = creation_time + base::TimeDelta::FromDays(2);
160 bool secure(false); 163 bool secure(false);
161 bool httponly(false); 164 bool httponly(false);
162 bool same_site(false); 165 CookieSameSite same_site(CookieSameSite::NO_RESTRICTION);
163 166
164 // Test that a cookie is equivalent to itself. 167 // Test that a cookie is equivalent to itself.
165 scoped_ptr<CanonicalCookie> cookie(new CanonicalCookie( 168 scoped_ptr<CanonicalCookie> cookie(new CanonicalCookie(
166 url, cookie_name, cookie_value, cookie_domain, cookie_path, creation_time, 169 url, cookie_name, cookie_value, cookie_domain, cookie_path, creation_time,
167 expiration_time, last_access_time, secure, httponly, same_site, 170 expiration_time, last_access_time, secure, httponly, same_site,
168 COOKIE_PRIORITY_MEDIUM)); 171 COOKIE_PRIORITY_MEDIUM));
169 EXPECT_TRUE(cookie->IsEquivalent(*cookie)); 172 EXPECT_TRUE(cookie->IsEquivalent(*cookie));
170 173
171 // Test that two identical cookies are equivalent. 174 // Test that two identical cookies are equivalent.
172 scoped_ptr<CanonicalCookie> other_cookie(new CanonicalCookie( 175 scoped_ptr<CanonicalCookie> other_cookie(new CanonicalCookie(
(...skipping 25 matching lines...) Expand all
198 EXPECT_TRUE(cookie->IsEquivalent(*other_cookie)); 201 EXPECT_TRUE(cookie->IsEquivalent(*other_cookie));
199 202
200 other_cookie.reset(new CanonicalCookie( 203 other_cookie.reset(new CanonicalCookie(
201 url, cookie_name, cookie_name, cookie_domain, cookie_path, creation_time, 204 url, cookie_name, cookie_name, cookie_domain, cookie_path, creation_time,
202 expiration_time, last_access_time, secure, true, same_site, 205 expiration_time, last_access_time, secure, true, same_site,
203 COOKIE_PRIORITY_LOW)); 206 COOKIE_PRIORITY_LOW));
204 EXPECT_TRUE(cookie->IsEquivalent(*other_cookie)); 207 EXPECT_TRUE(cookie->IsEquivalent(*other_cookie));
205 208
206 other_cookie.reset(new CanonicalCookie( 209 other_cookie.reset(new CanonicalCookie(
207 url, cookie_name, cookie_name, cookie_domain, cookie_path, creation_time, 210 url, cookie_name, cookie_name, cookie_domain, cookie_path, creation_time,
208 expiration_time, last_access_time, secure, httponly, true, 211 expiration_time, last_access_time, secure, httponly,
209 COOKIE_PRIORITY_LOW)); 212 CookieSameSite::STRICT_MODE, COOKIE_PRIORITY_LOW));
210 EXPECT_TRUE(cookie->IsEquivalent(*other_cookie)); 213 EXPECT_TRUE(cookie->IsEquivalent(*other_cookie));
211 214
212 // Tests that use different variations of attribute values that 215 // Tests that use different variations of attribute values that
213 // DO affect cookie equivalence. 216 // DO affect cookie equivalence.
214 other_cookie.reset( 217 other_cookie.reset(
215 new CanonicalCookie(url, "B", cookie_value, cookie_domain, cookie_path, 218 new CanonicalCookie(url, "B", cookie_value, cookie_domain, cookie_path,
216 creation_time, expiration_time, last_access_time, 219 creation_time, expiration_time, last_access_time,
217 secure, httponly, same_site, COOKIE_PRIORITY_MEDIUM)); 220 secure, httponly, same_site, COOKIE_PRIORITY_MEDIUM));
218 EXPECT_FALSE(cookie->IsEquivalent(*other_cookie)); 221 EXPECT_FALSE(cookie->IsEquivalent(*other_cookie));
219 222
(...skipping 22 matching lines...) Expand all
242 GURL url("http://www.example.com/"); 245 GURL url("http://www.example.com/");
243 std::string cookie_name = "A"; 246 std::string cookie_name = "A";
244 std::string cookie_value = "2EDA-EF"; 247 std::string cookie_value = "2EDA-EF";
245 std::string cookie_domain = ".www.example.com"; 248 std::string cookie_domain = ".www.example.com";
246 std::string cookie_path = "/"; 249 std::string cookie_path = "/";
247 base::Time creation_time = base::Time::Now(); 250 base::Time creation_time = base::Time::Now();
248 base::Time last_access_time = creation_time; 251 base::Time last_access_time = creation_time;
249 base::Time expiration_time = creation_time + base::TimeDelta::FromDays(2); 252 base::Time expiration_time = creation_time + base::TimeDelta::FromDays(2);
250 bool secure(false); 253 bool secure(false);
251 bool httponly(false); 254 bool httponly(false);
252 bool same_site(false); 255 CookieSameSite same_site(CookieSameSite::NO_RESTRICTION);
253 256
254 // Test that a cookie is equivalent to itself. 257 // Test that a cookie is equivalent to itself.
255 scoped_ptr<CanonicalCookie> cookie(new CanonicalCookie( 258 scoped_ptr<CanonicalCookie> cookie(new CanonicalCookie(
256 url, cookie_name, cookie_value, cookie_domain, cookie_path, creation_time, 259 url, cookie_name, cookie_value, cookie_domain, cookie_path, creation_time,
257 expiration_time, last_access_time, secure, httponly, same_site, 260 expiration_time, last_access_time, secure, httponly, same_site,
258 COOKIE_PRIORITY_MEDIUM)); 261 COOKIE_PRIORITY_MEDIUM));
259 EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*cookie)); 262 EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*cookie));
260 263
261 // Test that two identical cookies are equivalent. 264 // Test that two identical cookies are equivalent.
262 scoped_ptr<CanonicalCookie> other_cookie(new CanonicalCookie( 265 scoped_ptr<CanonicalCookie> other_cookie(new CanonicalCookie(
(...skipping 29 matching lines...) Expand all
292 EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie)); 295 EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie));
293 296
294 other_cookie.reset(new CanonicalCookie( 297 other_cookie.reset(new CanonicalCookie(
295 url, cookie_name, cookie_name, cookie_domain, cookie_path, creation_time, 298 url, cookie_name, cookie_name, cookie_domain, cookie_path, creation_time,
296 expiration_time, last_access_time, secure, true, same_site, 299 expiration_time, last_access_time, secure, true, same_site,
297 COOKIE_PRIORITY_LOW)); 300 COOKIE_PRIORITY_LOW));
298 EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie)); 301 EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie));
299 302
300 other_cookie.reset(new CanonicalCookie( 303 other_cookie.reset(new CanonicalCookie(
301 url, cookie_name, cookie_name, cookie_domain, cookie_path, creation_time, 304 url, cookie_name, cookie_name, cookie_domain, cookie_path, creation_time,
302 expiration_time, last_access_time, secure, httponly, true, 305 expiration_time, last_access_time, secure, httponly,
303 COOKIE_PRIORITY_LOW)); 306 CookieSameSite::STRICT_MODE, COOKIE_PRIORITY_LOW));
304 EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie)); 307 EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie));
305 308
306 // The following 3 tests' expected results differ from their IsEquivalent 309 // The following 3 tests' expected results differ from their IsEquivalent
307 // counterparts above. 310 // counterparts above.
308 other_cookie.reset(new CanonicalCookie( 311 other_cookie.reset(new CanonicalCookie(
309 url, cookie_name, cookie_value, cookie_domain, "/test/0", creation_time, 312 url, cookie_name, cookie_value, cookie_domain, "/test/0", creation_time,
310 expiration_time, last_access_time, secure, httponly, same_site, 313 expiration_time, last_access_time, secure, httponly, same_site,
311 COOKIE_PRIORITY_MEDIUM)); 314 COOKIE_PRIORITY_MEDIUM));
312 EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie)); 315 EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie));
313 316
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 GURL insecure_url("http://example.test"); 440 GURL insecure_url("http://example.test");
438 GURL secure_url("https://example.test"); 441 GURL secure_url("https://example.test");
439 GURL secure_url_with_path("https://example.test/foo/bar/index.html"); 442 GURL secure_url_with_path("https://example.test/foo/bar/index.html");
440 GURL third_party_url("https://not-example.test"); 443 GURL third_party_url("https://not-example.test");
441 base::Time creation_time = base::Time::Now(); 444 base::Time creation_time = base::Time::Now();
442 CookieOptions options; 445 CookieOptions options;
443 scoped_ptr<CanonicalCookie> cookie; 446 scoped_ptr<CanonicalCookie> cookie;
444 447
445 // Same-site cookies are not included for cross-site requests, 448 // Same-site cookies are not included for cross-site requests,
446 // even if other properties match: 449 // even if other properties match:
447 cookie = CanonicalCookie::Create(secure_url, "A=2; SameSite", creation_time, 450 cookie = CanonicalCookie::Create(secure_url, "A=2; SameSite=Strict",
448 options); 451 creation_time, options);
449 EXPECT_TRUE(cookie->IsSameSite()); 452 EXPECT_EQ(CookieSameSite::STRICT_MODE, cookie->SameSite());
450 EXPECT_FALSE(cookie->IncludeForRequestURL(secure_url, options)); 453 EXPECT_FALSE(cookie->IncludeForRequestURL(secure_url, options));
451 cookie = CanonicalCookie::Create(secure_url, "A=2; Secure; SameSite", 454 cookie = CanonicalCookie::Create(secure_url, "A=2; Secure; SameSite=Strict",
452 creation_time, options); 455 creation_time, options);
453 EXPECT_TRUE(cookie->IsSameSite()); 456 EXPECT_EQ(CookieSameSite::STRICT_MODE, cookie->SameSite());
454 EXPECT_FALSE(cookie->IncludeForRequestURL(secure_url, options)); 457 EXPECT_FALSE(cookie->IncludeForRequestURL(secure_url, options));
455 cookie = CanonicalCookie::Create(secure_url_with_path, 458 cookie = CanonicalCookie::Create(secure_url_with_path,
456 "A=2; SameSite; path=/foo/bar", 459 "A=2; SameSite=Strict; path=/foo/bar",
457 creation_time, options); 460 creation_time, options);
458 EXPECT_TRUE(cookie->IsSameSite()); 461 EXPECT_EQ(CookieSameSite::STRICT_MODE, cookie->SameSite());
459 EXPECT_FALSE(cookie->IncludeForRequestURL(secure_url, options)); 462 EXPECT_FALSE(cookie->IncludeForRequestURL(secure_url, options));
460 463
461 // Same-site cookies are included for same-site requests: 464 // Same-site cookies are included for same-site requests:
462 options.set_include_same_site(); 465 options.set_include_same_site();
463 cookie = CanonicalCookie::Create(secure_url, "A=2; SameSite", creation_time, 466 cookie = CanonicalCookie::Create(secure_url, "A=2; SameSite=Strict",
464 options); 467 creation_time, options);
465 EXPECT_TRUE(cookie->IsSameSite()); 468 EXPECT_EQ(CookieSameSite::STRICT_MODE, cookie->SameSite());
466 EXPECT_TRUE(cookie->IncludeForRequestURL(secure_url, options)); 469 EXPECT_TRUE(cookie->IncludeForRequestURL(secure_url, options));
467 cookie = CanonicalCookie::Create(secure_url, "A=2; Secure; SameSite", 470 cookie = CanonicalCookie::Create(secure_url, "A=2; Secure; SameSite=Strict",
468 creation_time, options); 471 creation_time, options);
469 EXPECT_TRUE(cookie->IsSameSite()); 472 EXPECT_EQ(CookieSameSite::STRICT_MODE, cookie->SameSite());
470 EXPECT_TRUE(cookie->IncludeForRequestURL(secure_url, options)); 473 EXPECT_TRUE(cookie->IncludeForRequestURL(secure_url, options));
471 cookie = CanonicalCookie::Create(secure_url_with_path, 474 cookie = CanonicalCookie::Create(secure_url_with_path,
472 "A=2; SameSite; path=/foo/bar", 475 "A=2; SameSite=Strict; path=/foo/bar",
473 creation_time, options); 476 creation_time, options);
474 EXPECT_TRUE(cookie->IsSameSite()); 477 EXPECT_EQ(CookieSameSite::STRICT_MODE, cookie->SameSite());
475 EXPECT_TRUE(cookie->IncludeForRequestURL(secure_url_with_path, options)); 478 EXPECT_TRUE(cookie->IncludeForRequestURL(secure_url_with_path, options));
476 } 479 }
477 480
478 TEST(CanonicalCookieTest, PartialCompare) { 481 TEST(CanonicalCookieTest, PartialCompare) {
479 GURL url("http://www.example.com"); 482 GURL url("http://www.example.com");
480 base::Time creation_time = base::Time::Now(); 483 base::Time creation_time = base::Time::Now();
481 CookieOptions options; 484 CookieOptions options;
482 scoped_ptr<CanonicalCookie> cookie( 485 scoped_ptr<CanonicalCookie> cookie(
483 CanonicalCookie::Create(url, "a=b", creation_time, options)); 486 CanonicalCookie::Create(url, "a=b", creation_time, options));
484 scoped_ptr<CanonicalCookie> cookie_different_path( 487 scoped_ptr<CanonicalCookie> cookie_different_path(
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
628 CanonicalCookie::Create(https_url, "a=b", creation_time, options)); 631 CanonicalCookie::Create(https_url, "a=b", creation_time, options));
629 scoped_ptr<CanonicalCookie> https_cookie_secure(CanonicalCookie::Create( 632 scoped_ptr<CanonicalCookie> https_cookie_secure(CanonicalCookie::Create(
630 https_url, "a=b; Secure", creation_time, options)); 633 https_url, "a=b; Secure", creation_time, options));
631 634
632 EXPECT_TRUE(http_cookie_no_secure.get()); 635 EXPECT_TRUE(http_cookie_no_secure.get());
633 EXPECT_FALSE(http_cookie_secure.get()); 636 EXPECT_FALSE(http_cookie_secure.get());
634 EXPECT_TRUE(https_cookie_no_secure.get()); 637 EXPECT_TRUE(https_cookie_no_secure.get());
635 EXPECT_TRUE(https_cookie_secure.get()); 638 EXPECT_TRUE(https_cookie_secure.get());
636 639
637 scoped_ptr<CanonicalCookie> http_cookie_no_secure_extended( 640 scoped_ptr<CanonicalCookie> http_cookie_no_secure_extended(
638 CanonicalCookie::Create(http_url, "a", "b", "", "", creation_time, 641 CanonicalCookie::Create(
639 creation_time, false, false, false, true, 642 http_url, "a", "b", "", "", creation_time, creation_time, false,
640 COOKIE_PRIORITY_DEFAULT)); 643 false, CookieSameSite::STRICT_MODE, true, COOKIE_PRIORITY_DEFAULT));
641 scoped_ptr<CanonicalCookie> http_cookie_secure_extended( 644 scoped_ptr<CanonicalCookie> http_cookie_secure_extended(
642 CanonicalCookie::Create(http_url, "a", "b", "", "", creation_time, 645 CanonicalCookie::Create(
643 creation_time, true, false, false, true, 646 http_url, "a", "b", "", "", creation_time, creation_time, true, false,
644 COOKIE_PRIORITY_DEFAULT)); 647 CookieSameSite::STRICT_MODE, true, COOKIE_PRIORITY_DEFAULT));
645 scoped_ptr<CanonicalCookie> https_cookie_no_secure_extended( 648 scoped_ptr<CanonicalCookie> https_cookie_no_secure_extended(
646 CanonicalCookie::Create(https_url, "a", "b", "", "", creation_time, 649 CanonicalCookie::Create(
647 creation_time, false, false, false, true, 650 https_url, "a", "b", "", "", creation_time, creation_time, false,
648 COOKIE_PRIORITY_DEFAULT)); 651 false, CookieSameSite::STRICT_MODE, true, COOKIE_PRIORITY_DEFAULT));
649 scoped_ptr<CanonicalCookie> https_cookie_secure_extended( 652 scoped_ptr<CanonicalCookie> https_cookie_secure_extended(
650 CanonicalCookie::Create(https_url, "a", "b", "", "", creation_time, 653 CanonicalCookie::Create(
651 creation_time, true, false, false, true, 654 https_url, "a", "b", "", "", creation_time, creation_time, true,
652 COOKIE_PRIORITY_DEFAULT)); 655 false, CookieSameSite::STRICT_MODE, true, COOKIE_PRIORITY_DEFAULT));
653 656
654 EXPECT_TRUE(http_cookie_no_secure_extended.get()); 657 EXPECT_TRUE(http_cookie_no_secure_extended.get());
655 EXPECT_FALSE(http_cookie_secure_extended.get()); 658 EXPECT_FALSE(http_cookie_secure_extended.get());
656 EXPECT_TRUE(https_cookie_no_secure_extended.get()); 659 EXPECT_TRUE(https_cookie_no_secure_extended.get());
657 EXPECT_TRUE(https_cookie_secure_extended.get()); 660 EXPECT_TRUE(https_cookie_secure_extended.get());
658 } 661 }
659 662
660 TEST(CanonicalCookieTest, TestPrefixHistograms) { 663 TEST(CanonicalCookieTest, TestPrefixHistograms) {
661 base::HistogramTester histograms; 664 base::HistogramTester histograms;
662 const char kCookiePrefixHistogram[] = "Cookie.CookiePrefix"; 665 const char kCookiePrefixHistogram[] = "Cookie.CookiePrefix";
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
701 CanonicalCookie::COOKIE_PREFIX_SECURE, 1); 704 CanonicalCookie::COOKIE_PREFIX_SECURE, 1);
702 EXPECT_TRUE(CanonicalCookie::Create(https_url, "__SecureA=B; Path=/; Secure", 705 EXPECT_TRUE(CanonicalCookie::Create(https_url, "__SecureA=B; Path=/; Secure",
703 creation_time, options)); 706 creation_time, options));
704 histograms.ExpectBucketCount(kCookiePrefixHistogram, 707 histograms.ExpectBucketCount(kCookiePrefixHistogram,
705 CanonicalCookie::COOKIE_PREFIX_SECURE, 2); 708 CanonicalCookie::COOKIE_PREFIX_SECURE, 2);
706 histograms.ExpectBucketCount(kCookiePrefixBlockedHistogram, 709 histograms.ExpectBucketCount(kCookiePrefixBlockedHistogram,
707 CanonicalCookie::COOKIE_PREFIX_SECURE, 1); 710 CanonicalCookie::COOKIE_PREFIX_SECURE, 1);
708 } 711 }
709 712
710 } // namespace net 713 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698