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