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 <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/test/histogram_tester.h" | 9 #include "base/test/histogram_tester.h" |
10 #include "net/cookies/cookie_constants.h" | 10 #include "net/cookies/cookie_constants.h" |
11 #include "net/cookies/cookie_options.h" | 11 #include "net/cookies/cookie_options.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 #include "url/gurl.h" | 13 #include "url/gurl.h" |
14 | 14 |
15 namespace net { | 15 namespace net { |
16 | 16 |
17 TEST(CanonicalCookieTest, Constructor) { | 17 TEST(CanonicalCookieTest, Constructor) { |
18 GURL url("http://www.example.com/test"); | 18 GURL url("http://www.example.com/test"); |
19 base::Time current_time = base::Time::Now(); | 19 base::Time current_time = base::Time::Now(); |
20 | 20 |
21 std::unique_ptr<CanonicalCookie> cookie(CanonicalCookie::Create( | 21 std::unique_ptr<CanonicalCookie> cookie(CanonicalCookie::Create( |
22 url, "A", "2", std::string(), "/test", current_time, base::Time(), false, | 22 "A", "2", "www.example.com", "/test", current_time, base::Time(), |
23 false, CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT)); | 23 base::Time(), false, false, CookieSameSite::DEFAULT_MODE, |
| 24 COOKIE_PRIORITY_DEFAULT)); |
24 EXPECT_EQ("A", cookie->Name()); | 25 EXPECT_EQ("A", cookie->Name()); |
25 EXPECT_EQ("2", cookie->Value()); | 26 EXPECT_EQ("2", cookie->Value()); |
26 EXPECT_EQ("www.example.com", cookie->Domain()); | 27 EXPECT_EQ("www.example.com", cookie->Domain()); |
27 EXPECT_EQ("/test", cookie->Path()); | 28 EXPECT_EQ("/test", cookie->Path()); |
28 EXPECT_FALSE(cookie->IsSecure()); | 29 EXPECT_FALSE(cookie->IsSecure()); |
29 EXPECT_FALSE(cookie->IsHttpOnly()); | 30 EXPECT_FALSE(cookie->IsHttpOnly()); |
30 EXPECT_EQ(CookieSameSite::NO_RESTRICTION, cookie->SameSite()); | 31 EXPECT_EQ(CookieSameSite::NO_RESTRICTION, cookie->SameSite()); |
31 | 32 |
32 std::unique_ptr<CanonicalCookie> cookie2(CanonicalCookie::Create( | 33 std::unique_ptr<CanonicalCookie> cookie2(CanonicalCookie::Create( |
33 url, "A", "2", ".www.example.com", std::string(), current_time, | 34 "A", "2", ".www.example.com", "/", current_time, base::Time(), |
34 base::Time(), false, false, CookieSameSite::DEFAULT_MODE, | 35 base::Time(), false, false, CookieSameSite::DEFAULT_MODE, |
35 COOKIE_PRIORITY_DEFAULT)); | 36 COOKIE_PRIORITY_DEFAULT)); |
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(".www.example.com", cookie2->Domain()); | 39 EXPECT_EQ(".www.example.com", 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_EQ(CookieSameSite::NO_RESTRICTION, cookie2->SameSite()); | 43 EXPECT_EQ(CookieSameSite::NO_RESTRICTION, cookie2->SameSite()); |
43 } | 44 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 CookieOptions::SameSiteCookieMode::INCLUDE_STRICT_AND_LAX); | 87 CookieOptions::SameSiteCookieMode::INCLUDE_STRICT_AND_LAX); |
87 cookie = CanonicalCookie::Create(url, "A=2; SameSite=Strict", creation_time, | 88 cookie = CanonicalCookie::Create(url, "A=2; SameSite=Strict", creation_time, |
88 same_site_options); | 89 same_site_options); |
89 EXPECT_TRUE(cookie.get()); | 90 EXPECT_TRUE(cookie.get()); |
90 EXPECT_EQ(CookieSameSite::STRICT_MODE, cookie->SameSite()); | 91 EXPECT_EQ(CookieSameSite::STRICT_MODE, cookie->SameSite()); |
91 cookie = CanonicalCookie::Create(url, "A=2; SameSite=Lax", creation_time, | 92 cookie = CanonicalCookie::Create(url, "A=2; SameSite=Lax", creation_time, |
92 same_site_options); | 93 same_site_options); |
93 | 94 |
94 // Test the creating cookies using specific parameter instead of a cookie | 95 // Test the creating cookies using specific parameter instead of a cookie |
95 // string. | 96 // string. |
96 cookie = CanonicalCookie::Create( | 97 cookie = CanonicalCookie::Create("A", "2", ".www.example.com", "/test", |
97 url, "A", "2", "www.example.com", "/test", creation_time, base::Time(), | 98 creation_time, base::Time(), base::Time(), |
98 false, false, CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT); | 99 false, false, CookieSameSite::DEFAULT_MODE, |
| 100 COOKIE_PRIORITY_DEFAULT); |
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_EQ(CookieSameSite::NO_RESTRICTION, cookie->SameSite()); | 107 EXPECT_EQ(CookieSameSite::NO_RESTRICTION, cookie->SameSite()); |
106 | 108 |
107 cookie = CanonicalCookie::Create( | 109 cookie = CanonicalCookie::Create("A", "2", ".www.example.com", "/test", |
108 url, "A", "2", ".www.example.com", "/test", creation_time, base::Time(), | 110 creation_time, base::Time(), base::Time(), |
109 false, false, CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT); | 111 false, false, CookieSameSite::DEFAULT_MODE, |
| 112 COOKIE_PRIORITY_DEFAULT); |
110 EXPECT_EQ("A", cookie->Name()); | 113 EXPECT_EQ("A", cookie->Name()); |
111 EXPECT_EQ("2", cookie->Value()); | 114 EXPECT_EQ("2", cookie->Value()); |
112 EXPECT_EQ(".www.example.com", cookie->Domain()); | 115 EXPECT_EQ(".www.example.com", cookie->Domain()); |
113 EXPECT_EQ("/test", cookie->Path()); | 116 EXPECT_EQ("/test", cookie->Path()); |
114 EXPECT_FALSE(cookie->IsSecure()); | 117 EXPECT_FALSE(cookie->IsSecure()); |
115 EXPECT_FALSE(cookie->IsHttpOnly()); | 118 EXPECT_FALSE(cookie->IsHttpOnly()); |
116 EXPECT_EQ(CookieSameSite::NO_RESTRICTION, cookie->SameSite()); | 119 EXPECT_EQ(CookieSameSite::NO_RESTRICTION, cookie->SameSite()); |
117 } | 120 } |
118 | 121 |
119 TEST(CanonicalCookieTest, CreateInvalidSameSite) { | 122 TEST(CanonicalCookieTest, CreateInvalidSameSite) { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 std::string cookie_domain = ".www.example.com"; | 174 std::string cookie_domain = ".www.example.com"; |
172 std::string cookie_path = "/path"; | 175 std::string cookie_path = "/path"; |
173 base::Time creation_time = base::Time::Now(); | 176 base::Time creation_time = base::Time::Now(); |
174 base::Time expiration_time = creation_time + base::TimeDelta::FromDays(2); | 177 base::Time expiration_time = creation_time + base::TimeDelta::FromDays(2); |
175 bool secure(false); | 178 bool secure(false); |
176 bool httponly(false); | 179 bool httponly(false); |
177 CookieSameSite same_site(CookieSameSite::NO_RESTRICTION); | 180 CookieSameSite same_site(CookieSameSite::NO_RESTRICTION); |
178 | 181 |
179 // Test that a cookie is equivalent to itself. | 182 // Test that a cookie is equivalent to itself. |
180 std::unique_ptr<CanonicalCookie> cookie(CanonicalCookie::Create( | 183 std::unique_ptr<CanonicalCookie> cookie(CanonicalCookie::Create( |
181 url, cookie_name, cookie_value, cookie_domain, cookie_path, creation_time, | 184 cookie_name, cookie_value, cookie_domain, cookie_path, creation_time, |
182 expiration_time, secure, httponly, same_site, COOKIE_PRIORITY_MEDIUM)); | 185 expiration_time, base::Time(), secure, httponly, same_site, |
| 186 COOKIE_PRIORITY_MEDIUM)); |
183 EXPECT_TRUE(cookie->IsEquivalent(*cookie)); | 187 EXPECT_TRUE(cookie->IsEquivalent(*cookie)); |
184 EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*cookie)); | 188 EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*cookie)); |
185 | 189 |
186 // Test that two identical cookies are equivalent. | 190 // Test that two identical cookies are equivalent. |
187 std::unique_ptr<CanonicalCookie> other_cookie(CanonicalCookie::Create( | 191 std::unique_ptr<CanonicalCookie> other_cookie(CanonicalCookie::Create( |
188 url, cookie_name, cookie_value, cookie_domain, cookie_path, creation_time, | 192 cookie_name, cookie_value, cookie_domain, cookie_path, creation_time, |
189 expiration_time, secure, httponly, same_site, COOKIE_PRIORITY_MEDIUM)); | 193 expiration_time, base::Time(), secure, httponly, same_site, |
| 194 COOKIE_PRIORITY_MEDIUM)); |
190 EXPECT_TRUE(cookie->IsEquivalent(*other_cookie)); | 195 EXPECT_TRUE(cookie->IsEquivalent(*other_cookie)); |
191 EXPECT_TRUE(other_cookie->IsEquivalentForSecureCookieMatching(*cookie)); | 196 EXPECT_TRUE(other_cookie->IsEquivalentForSecureCookieMatching(*cookie)); |
192 | 197 |
193 // Tests that use different variations of attribute values that | 198 // Tests that use different variations of attribute values that |
194 // DON'T affect cookie equivalence. | 199 // DON'T affect cookie equivalence. |
195 other_cookie = CanonicalCookie::Create( | 200 other_cookie = CanonicalCookie::Create( |
196 url, cookie_name, "2", cookie_domain, cookie_path, creation_time, | 201 cookie_name, "2", cookie_domain, cookie_path, creation_time, |
197 expiration_time, secure, httponly, same_site, COOKIE_PRIORITY_HIGH); | 202 expiration_time, base::Time(), secure, httponly, same_site, |
| 203 COOKIE_PRIORITY_HIGH); |
198 EXPECT_TRUE(cookie->IsEquivalent(*other_cookie)); | 204 EXPECT_TRUE(cookie->IsEquivalent(*other_cookie)); |
199 EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie)); | 205 EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie)); |
200 EXPECT_TRUE(other_cookie->IsEquivalentForSecureCookieMatching(*cookie)); | 206 EXPECT_TRUE(other_cookie->IsEquivalentForSecureCookieMatching(*cookie)); |
201 | 207 |
202 base::Time other_creation_time = | 208 base::Time other_creation_time = |
203 creation_time + base::TimeDelta::FromMinutes(2); | 209 creation_time + base::TimeDelta::FromMinutes(2); |
204 other_cookie = CanonicalCookie::Create( | 210 other_cookie = CanonicalCookie::Create( |
205 url, cookie_name, "2", cookie_domain, cookie_path, other_creation_time, | 211 cookie_name, "2", cookie_domain, cookie_path, other_creation_time, |
206 expiration_time, secure, httponly, same_site, COOKIE_PRIORITY_MEDIUM); | 212 expiration_time, base::Time(), secure, httponly, same_site, |
| 213 COOKIE_PRIORITY_MEDIUM); |
207 EXPECT_TRUE(cookie->IsEquivalent(*other_cookie)); | 214 EXPECT_TRUE(cookie->IsEquivalent(*other_cookie)); |
208 EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie)); | 215 EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie)); |
209 EXPECT_TRUE(other_cookie->IsEquivalentForSecureCookieMatching(*cookie)); | 216 EXPECT_TRUE(other_cookie->IsEquivalentForSecureCookieMatching(*cookie)); |
210 | 217 |
211 other_cookie = CanonicalCookie::Create( | 218 other_cookie = CanonicalCookie::Create( |
212 url, cookie_name, cookie_name, cookie_domain, cookie_path, creation_time, | 219 cookie_name, cookie_name, cookie_domain, cookie_path, creation_time, |
213 expiration_time, true, httponly, same_site, COOKIE_PRIORITY_LOW); | 220 expiration_time, base::Time(), true, httponly, same_site, |
| 221 COOKIE_PRIORITY_LOW); |
214 EXPECT_TRUE(cookie->IsEquivalent(*other_cookie)); | 222 EXPECT_TRUE(cookie->IsEquivalent(*other_cookie)); |
215 EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie)); | 223 EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie)); |
216 EXPECT_TRUE(other_cookie->IsEquivalentForSecureCookieMatching(*cookie)); | 224 EXPECT_TRUE(other_cookie->IsEquivalentForSecureCookieMatching(*cookie)); |
217 | 225 |
218 other_cookie = CanonicalCookie::Create( | 226 other_cookie = CanonicalCookie::Create( |
219 url, cookie_name, cookie_name, cookie_domain, cookie_path, creation_time, | 227 cookie_name, cookie_name, cookie_domain, cookie_path, creation_time, |
220 expiration_time, secure, true, same_site, COOKIE_PRIORITY_LOW); | 228 expiration_time, base::Time(), secure, true, same_site, |
| 229 COOKIE_PRIORITY_LOW); |
221 EXPECT_TRUE(cookie->IsEquivalent(*other_cookie)); | 230 EXPECT_TRUE(cookie->IsEquivalent(*other_cookie)); |
222 EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie)); | 231 EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie)); |
223 EXPECT_TRUE(other_cookie->IsEquivalentForSecureCookieMatching(*cookie)); | 232 EXPECT_TRUE(other_cookie->IsEquivalentForSecureCookieMatching(*cookie)); |
224 | 233 |
225 other_cookie = CanonicalCookie::Create( | 234 other_cookie = CanonicalCookie::Create( |
226 url, cookie_name, cookie_name, cookie_domain, cookie_path, creation_time, | 235 cookie_name, cookie_name, cookie_domain, cookie_path, creation_time, |
227 expiration_time, secure, httponly, CookieSameSite::STRICT_MODE, | 236 expiration_time, base::Time(), secure, httponly, |
228 COOKIE_PRIORITY_LOW); | 237 CookieSameSite::STRICT_MODE, COOKIE_PRIORITY_LOW); |
229 EXPECT_TRUE(cookie->IsEquivalent(*other_cookie)); | 238 EXPECT_TRUE(cookie->IsEquivalent(*other_cookie)); |
230 EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie)); | 239 EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie)); |
231 EXPECT_TRUE(other_cookie->IsEquivalentForSecureCookieMatching(*cookie)); | 240 EXPECT_TRUE(other_cookie->IsEquivalentForSecureCookieMatching(*cookie)); |
232 | 241 |
233 // Cookies whose names mismatch are not equivalent. | 242 // Cookies whose names mismatch are not equivalent. |
234 other_cookie = CanonicalCookie::Create( | 243 other_cookie = CanonicalCookie::Create( |
235 url, "B", cookie_value, cookie_domain, cookie_path, creation_time, | 244 "B", cookie_value, cookie_domain, cookie_path, creation_time, |
236 expiration_time, secure, httponly, same_site, COOKIE_PRIORITY_MEDIUM); | 245 expiration_time, base::Time(), secure, httponly, same_site, |
| 246 COOKIE_PRIORITY_MEDIUM); |
237 EXPECT_FALSE(cookie->IsEquivalent(*other_cookie)); | 247 EXPECT_FALSE(cookie->IsEquivalent(*other_cookie)); |
238 EXPECT_FALSE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie)); | 248 EXPECT_FALSE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie)); |
239 EXPECT_FALSE(other_cookie->IsEquivalentForSecureCookieMatching(*cookie)); | 249 EXPECT_FALSE(other_cookie->IsEquivalentForSecureCookieMatching(*cookie)); |
240 | 250 |
241 // A domain cookie at 'www.example.com' is not equivalent to a host cookie | 251 // A domain cookie at 'www.example.com' is not equivalent to a host cookie |
242 // at the same domain. These are, however, equivalent according to the laxer | 252 // at the same domain. These are, however, equivalent according to the laxer |
243 // rules of 'IsEquivalentForSecureCookieMatching'. | 253 // rules of 'IsEquivalentForSecureCookieMatching'. |
244 other_cookie = CanonicalCookie::Create( | 254 other_cookie = CanonicalCookie::Create( |
245 url, cookie_name, cookie_value, std::string(), cookie_path, creation_time, | 255 cookie_name, cookie_value, "www.example.com", cookie_path, creation_time, |
246 expiration_time, secure, httponly, same_site, COOKIE_PRIORITY_MEDIUM); | 256 expiration_time, base::Time(), secure, httponly, same_site, |
| 257 COOKIE_PRIORITY_MEDIUM); |
247 EXPECT_TRUE(cookie->IsDomainCookie()); | 258 EXPECT_TRUE(cookie->IsDomainCookie()); |
248 EXPECT_FALSE(other_cookie->IsDomainCookie()); | 259 EXPECT_FALSE(other_cookie->IsDomainCookie()); |
249 EXPECT_FALSE(cookie->IsEquivalent(*other_cookie)); | 260 EXPECT_FALSE(cookie->IsEquivalent(*other_cookie)); |
250 EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie)); | 261 EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie)); |
251 EXPECT_TRUE(other_cookie->IsEquivalentForSecureCookieMatching(*cookie)); | 262 EXPECT_TRUE(other_cookie->IsEquivalentForSecureCookieMatching(*cookie)); |
252 | 263 |
253 // Likewise, a cookie on 'example.com' is not equivalent to a cookie on | 264 // Likewise, a cookie on 'example.com' is not equivalent to a cookie on |
254 // 'www.example.com', but they are equivalent for secure cookie matching. | 265 // 'www.example.com', but they are equivalent for secure cookie matching. |
255 other_cookie = CanonicalCookie::Create( | 266 other_cookie = CanonicalCookie::Create( |
256 url, cookie_name, cookie_value, ".example.com", cookie_path, | 267 cookie_name, cookie_value, ".example.com", cookie_path, creation_time, |
257 creation_time, expiration_time, secure, httponly, same_site, | 268 expiration_time, base::Time(), secure, httponly, same_site, |
258 COOKIE_PRIORITY_MEDIUM); | 269 COOKIE_PRIORITY_MEDIUM); |
259 EXPECT_FALSE(cookie->IsEquivalent(*other_cookie)); | 270 EXPECT_FALSE(cookie->IsEquivalent(*other_cookie)); |
260 EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie)); | 271 EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie)); |
261 EXPECT_TRUE(other_cookie->IsEquivalentForSecureCookieMatching(*cookie)); | 272 EXPECT_TRUE(other_cookie->IsEquivalentForSecureCookieMatching(*cookie)); |
262 | 273 |
263 // Paths are a bit more complicated. 'IsEquivalent' requires an exact path | 274 // Paths are a bit more complicated. 'IsEquivalent' requires an exact path |
264 // match, while secure cookie matching uses a more relaxed 'IsOnPath' check. | 275 // match, while secure cookie matching uses a more relaxed 'IsOnPath' check. |
265 // That is, |cookie| set on '/path' is not equivalent in either way to | 276 // That is, |cookie| set on '/path' is not equivalent in either way to |
266 // |other_cookie| set on '/test' or '/path/subpath'. It is, however, | 277 // |other_cookie| set on '/test' or '/path/subpath'. It is, however, |
267 // equivalent for secure cookie matching to |other_cookie| set on '/'. | 278 // equivalent for secure cookie matching to |other_cookie| set on '/'. |
268 other_cookie = CanonicalCookie::Create( | 279 other_cookie = CanonicalCookie::Create( |
269 url, cookie_name, cookie_value, cookie_domain, "/test", creation_time, | 280 cookie_name, cookie_value, cookie_domain, "/test", creation_time, |
270 expiration_time, secure, httponly, same_site, COOKIE_PRIORITY_MEDIUM); | 281 expiration_time, base::Time(), secure, httponly, same_site, |
| 282 COOKIE_PRIORITY_MEDIUM); |
271 EXPECT_FALSE(cookie->IsEquivalent(*other_cookie)); | 283 EXPECT_FALSE(cookie->IsEquivalent(*other_cookie)); |
272 EXPECT_FALSE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie)); | 284 EXPECT_FALSE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie)); |
273 EXPECT_FALSE(other_cookie->IsEquivalentForSecureCookieMatching(*cookie)); | 285 EXPECT_FALSE(other_cookie->IsEquivalentForSecureCookieMatching(*cookie)); |
274 | 286 |
275 other_cookie = CanonicalCookie::Create( | 287 other_cookie = CanonicalCookie::Create( |
276 url, cookie_name, cookie_value, cookie_domain, cookie_path + "/subpath", | 288 cookie_name, cookie_value, cookie_domain, cookie_path + "/subpath", |
277 creation_time, expiration_time, secure, httponly, same_site, | 289 creation_time, expiration_time, base::Time(), secure, httponly, same_site, |
278 COOKIE_PRIORITY_MEDIUM); | 290 COOKIE_PRIORITY_MEDIUM); |
279 EXPECT_FALSE(cookie->IsEquivalent(*other_cookie)); | 291 EXPECT_FALSE(cookie->IsEquivalent(*other_cookie)); |
280 EXPECT_FALSE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie)); | 292 EXPECT_FALSE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie)); |
281 EXPECT_TRUE(other_cookie->IsEquivalentForSecureCookieMatching(*cookie)); | 293 EXPECT_TRUE(other_cookie->IsEquivalentForSecureCookieMatching(*cookie)); |
282 | 294 |
283 other_cookie = CanonicalCookie::Create( | 295 other_cookie = CanonicalCookie::Create( |
284 url, cookie_name, cookie_value, cookie_domain, "/", creation_time, | 296 cookie_name, cookie_value, cookie_domain, "/", creation_time, |
285 expiration_time, secure, httponly, same_site, COOKIE_PRIORITY_MEDIUM); | 297 expiration_time, base::Time(), secure, httponly, same_site, |
| 298 COOKIE_PRIORITY_MEDIUM); |
286 EXPECT_FALSE(cookie->IsEquivalent(*other_cookie)); | 299 EXPECT_FALSE(cookie->IsEquivalent(*other_cookie)); |
287 EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie)); | 300 EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie)); |
288 EXPECT_FALSE(other_cookie->IsEquivalentForSecureCookieMatching(*cookie)); | 301 EXPECT_FALSE(other_cookie->IsEquivalentForSecureCookieMatching(*cookie)); |
289 } | 302 } |
290 | 303 |
291 TEST(CanonicalCookieTest, IsDomainMatch) { | 304 TEST(CanonicalCookieTest, IsDomainMatch) { |
292 GURL url("http://www.example.com/test/foo.html"); | 305 GURL url("http://www.example.com/test/foo.html"); |
293 base::Time creation_time = base::Time::Now(); | 306 base::Time creation_time = base::Time::Now(); |
294 CookieOptions options; | 307 CookieOptions options; |
295 | 308 |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
572 CanonicalCookie::Create(http_url, "a=b; Secure", creation_time, options)); | 585 CanonicalCookie::Create(http_url, "a=b; Secure", creation_time, options)); |
573 std::unique_ptr<CanonicalCookie> https_cookie_no_secure( | 586 std::unique_ptr<CanonicalCookie> https_cookie_no_secure( |
574 CanonicalCookie::Create(https_url, "a=b", creation_time, options)); | 587 CanonicalCookie::Create(https_url, "a=b", creation_time, options)); |
575 std::unique_ptr<CanonicalCookie> https_cookie_secure(CanonicalCookie::Create( | 588 std::unique_ptr<CanonicalCookie> https_cookie_secure(CanonicalCookie::Create( |
576 https_url, "a=b; Secure", creation_time, options)); | 589 https_url, "a=b; Secure", creation_time, options)); |
577 | 590 |
578 EXPECT_TRUE(http_cookie_no_secure.get()); | 591 EXPECT_TRUE(http_cookie_no_secure.get()); |
579 EXPECT_FALSE(http_cookie_secure.get()); | 592 EXPECT_FALSE(http_cookie_secure.get()); |
580 EXPECT_TRUE(https_cookie_no_secure.get()); | 593 EXPECT_TRUE(https_cookie_no_secure.get()); |
581 EXPECT_TRUE(https_cookie_secure.get()); | 594 EXPECT_TRUE(https_cookie_secure.get()); |
582 | |
583 std::unique_ptr<CanonicalCookie> http_cookie_no_secure_extended( | |
584 CanonicalCookie::Create( | |
585 http_url, "a", "b", "", "", creation_time, creation_time, false, | |
586 false, CookieSameSite::STRICT_MODE, COOKIE_PRIORITY_DEFAULT)); | |
587 std::unique_ptr<CanonicalCookie> http_cookie_secure_extended( | |
588 CanonicalCookie::Create( | |
589 http_url, "a", "b", "", "", creation_time, creation_time, true, false, | |
590 CookieSameSite::STRICT_MODE, COOKIE_PRIORITY_DEFAULT)); | |
591 std::unique_ptr<CanonicalCookie> https_cookie_no_secure_extended( | |
592 CanonicalCookie::Create( | |
593 https_url, "a", "b", "", "", creation_time, creation_time, false, | |
594 false, CookieSameSite::STRICT_MODE, COOKIE_PRIORITY_DEFAULT)); | |
595 std::unique_ptr<CanonicalCookie> https_cookie_secure_extended( | |
596 CanonicalCookie::Create( | |
597 https_url, "a", "b", "", "", creation_time, creation_time, true, | |
598 false, CookieSameSite::STRICT_MODE, COOKIE_PRIORITY_DEFAULT)); | |
599 | |
600 EXPECT_TRUE(http_cookie_no_secure_extended.get()); | |
601 EXPECT_FALSE(http_cookie_secure_extended.get()); | |
602 EXPECT_TRUE(https_cookie_no_secure_extended.get()); | |
603 EXPECT_TRUE(https_cookie_secure_extended.get()); | |
604 } | 595 } |
605 | 596 |
606 TEST(CanonicalCookieTest, TestPrefixHistograms) { | 597 TEST(CanonicalCookieTest, TestPrefixHistograms) { |
607 base::HistogramTester histograms; | 598 base::HistogramTester histograms; |
608 const char kCookiePrefixHistogram[] = "Cookie.CookiePrefix"; | 599 const char kCookiePrefixHistogram[] = "Cookie.CookiePrefix"; |
609 const char kCookiePrefixBlockedHistogram[] = "Cookie.CookiePrefixBlocked"; | 600 const char kCookiePrefixBlockedHistogram[] = "Cookie.CookiePrefixBlocked"; |
610 GURL https_url("https://www.example.test"); | 601 GURL https_url("https://www.example.test"); |
611 base::Time creation_time = base::Time::Now(); | 602 base::Time creation_time = base::Time::Now(); |
612 CookieOptions options; | 603 CookieOptions options; |
613 | 604 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
647 CanonicalCookie::COOKIE_PREFIX_SECURE, 1); | 638 CanonicalCookie::COOKIE_PREFIX_SECURE, 1); |
648 EXPECT_TRUE(CanonicalCookie::Create(https_url, "__SecureA=B; Path=/; Secure", | 639 EXPECT_TRUE(CanonicalCookie::Create(https_url, "__SecureA=B; Path=/; Secure", |
649 creation_time, options)); | 640 creation_time, options)); |
650 histograms.ExpectBucketCount(kCookiePrefixHistogram, | 641 histograms.ExpectBucketCount(kCookiePrefixHistogram, |
651 CanonicalCookie::COOKIE_PREFIX_SECURE, 2); | 642 CanonicalCookie::COOKIE_PREFIX_SECURE, 2); |
652 histograms.ExpectBucketCount(kCookiePrefixBlockedHistogram, | 643 histograms.ExpectBucketCount(kCookiePrefixBlockedHistogram, |
653 CanonicalCookie::COOKIE_PREFIX_SECURE, 1); | 644 CanonicalCookie::COOKIE_PREFIX_SECURE, 1); |
654 } | 645 } |
655 | 646 |
656 } // namespace net | 647 } // namespace net |
OLD | NEW |