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 "net/cookies/cookie_constants.h" | 8 #include "net/cookies/cookie_constants.h" |
9 #include "net/cookies/cookie_options.h" | 9 #include "net/cookies/cookie_options.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 CanonicalCookie::Create(url, "A=2; HttpOnly", creation_time, options)); | 77 CanonicalCookie::Create(url, "A=2; HttpOnly", creation_time, options)); |
78 EXPECT_FALSE(cookie.get()); | 78 EXPECT_FALSE(cookie.get()); |
79 CookieOptions httponly_options; | 79 CookieOptions httponly_options; |
80 httponly_options.set_include_httponly(); | 80 httponly_options.set_include_httponly(); |
81 cookie.reset(CanonicalCookie::Create(url, "A=2; HttpOnly", creation_time, | 81 cookie.reset(CanonicalCookie::Create(url, "A=2; HttpOnly", creation_time, |
82 httponly_options)); | 82 httponly_options)); |
83 EXPECT_TRUE(cookie->IsHttpOnly()); | 83 EXPECT_TRUE(cookie->IsHttpOnly()); |
84 | 84 |
85 // Test creating http only cookies. | 85 // Test creating http only cookies. |
86 CookieOptions first_party_options; | 86 CookieOptions first_party_options; |
87 first_party_options.set_first_party_url(url); | 87 first_party_options.set_first_party(url::Origin(url)); |
88 cookie.reset(CanonicalCookie::Create(url, "A=2; First-Party-Only", | 88 cookie.reset(CanonicalCookie::Create(url, "A=2; First-Party-Only", |
89 creation_time, httponly_options)); | 89 creation_time, httponly_options)); |
90 EXPECT_TRUE(cookie.get()); | 90 EXPECT_TRUE(cookie.get()); |
91 EXPECT_TRUE(cookie->IsFirstPartyOnly()); | 91 EXPECT_TRUE(cookie->IsFirstPartyOnly()); |
92 | 92 |
93 // Test the creating cookies using specific parameter instead of a cookie | 93 // Test the creating cookies using specific parameter instead of a cookie |
94 // string. | 94 // string. |
95 cookie.reset(CanonicalCookie::Create( | 95 cookie.reset(CanonicalCookie::Create( |
96 url, "A", "2", "www.example.com", "/test", creation_time, base::Time(), | 96 url, "A", "2", "www.example.com", "/test", creation_time, base::Time(), |
97 false, false, false, COOKIE_PRIORITY_DEFAULT)); | 97 false, false, false, COOKIE_PRIORITY_DEFAULT)); |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 GURL secure_url_with_path("https://example.test/foo/bar/index.html"); | 344 GURL secure_url_with_path("https://example.test/foo/bar/index.html"); |
345 GURL third_party_url("https://not-example.test"); | 345 GURL third_party_url("https://not-example.test"); |
346 base::Time creation_time = base::Time::Now(); | 346 base::Time creation_time = base::Time::Now(); |
347 CookieOptions options; | 347 CookieOptions options; |
348 scoped_ptr<CanonicalCookie> cookie; | 348 scoped_ptr<CanonicalCookie> cookie; |
349 | 349 |
350 // First-party-only cookies are not inlcuded if a top-level URL is unset. | 350 // First-party-only cookies are not inlcuded if a top-level URL is unset. |
351 cookie.reset(CanonicalCookie::Create(secure_url, "A=2; First-Party-Only", | 351 cookie.reset(CanonicalCookie::Create(secure_url, "A=2; First-Party-Only", |
352 creation_time, options)); | 352 creation_time, options)); |
353 EXPECT_TRUE(cookie->IsFirstPartyOnly()); | 353 EXPECT_TRUE(cookie->IsFirstPartyOnly()); |
354 options.set_first_party_url(GURL()); | 354 options.set_first_party(url::Origin()); |
355 EXPECT_FALSE(cookie->IncludeForRequestURL(secure_url, options)); | 355 EXPECT_FALSE(cookie->IncludeForRequestURL(secure_url, options)); |
356 | 356 |
357 // First-party-only cookies are included only if the cookie's origin matches | 357 // First-party-only cookies are included only if the cookie's origin matches |
358 // the | 358 // the |
359 // first-party origin. | 359 // first-party origin. |
360 options.set_first_party_url(secure_url); | 360 options.set_first_party(url::Origin(secure_url)); |
361 EXPECT_TRUE(cookie->IncludeForRequestURL(secure_url, options)); | 361 EXPECT_TRUE(cookie->IncludeForRequestURL(secure_url, options)); |
362 options.set_first_party_url(insecure_url); | 362 options.set_first_party(url::Origin(insecure_url)); |
363 EXPECT_FALSE(cookie->IncludeForRequestURL(secure_url, options)); | 363 EXPECT_FALSE(cookie->IncludeForRequestURL(secure_url, options)); |
364 options.set_first_party_url(third_party_url); | 364 options.set_first_party(url::Origin(third_party_url)); |
365 EXPECT_FALSE(cookie->IncludeForRequestURL(secure_url, options)); | 365 EXPECT_FALSE(cookie->IncludeForRequestURL(secure_url, options)); |
366 | 366 |
367 // "First-Party-Only" doesn't override the 'secure' flag. | 367 // "First-Party-Only" doesn't override the 'secure' flag. |
368 cookie.reset(CanonicalCookie::Create( | 368 cookie.reset(CanonicalCookie::Create( |
369 secure_url, "A=2; Secure; First-Party-Only", creation_time, options)); | 369 secure_url, "A=2; Secure; First-Party-Only", creation_time, options)); |
370 options.set_first_party_url(secure_url); | 370 options.set_first_party(url::Origin(secure_url)); |
371 EXPECT_TRUE(cookie->IncludeForRequestURL(secure_url, options)); | 371 EXPECT_TRUE(cookie->IncludeForRequestURL(secure_url, options)); |
372 EXPECT_FALSE(cookie->IncludeForRequestURL(insecure_url, options)); | 372 EXPECT_FALSE(cookie->IncludeForRequestURL(insecure_url, options)); |
373 options.set_first_party_url(insecure_url); | 373 options.set_first_party(url::Origin(insecure_url)); |
374 EXPECT_FALSE(cookie->IncludeForRequestURL(secure_url, options)); | 374 EXPECT_FALSE(cookie->IncludeForRequestURL(secure_url, options)); |
375 EXPECT_FALSE(cookie->IncludeForRequestURL(insecure_url, options)); | 375 EXPECT_FALSE(cookie->IncludeForRequestURL(insecure_url, options)); |
376 | 376 |
377 // "First-Party-Only" doesn't override the 'path' flag. | 377 // "First-Party-Only" doesn't override the 'path' flag. |
378 cookie.reset(CanonicalCookie::Create(secure_url_with_path, | 378 cookie.reset(CanonicalCookie::Create(secure_url_with_path, |
379 "A=2; First-Party-Only; path=/foo/bar", | 379 "A=2; First-Party-Only; path=/foo/bar", |
380 creation_time, options)); | 380 creation_time, options)); |
381 options.set_first_party_url(secure_url_with_path); | 381 options.set_first_party(url::Origin(secure_url_with_path)); |
382 EXPECT_TRUE(cookie->IncludeForRequestURL(secure_url_with_path, options)); | 382 EXPECT_TRUE(cookie->IncludeForRequestURL(secure_url_with_path, options)); |
383 EXPECT_FALSE(cookie->IncludeForRequestURL(secure_url, options)); | 383 EXPECT_FALSE(cookie->IncludeForRequestURL(secure_url, options)); |
384 options.set_first_party_url(secure_url); | 384 options.set_first_party(url::Origin(secure_url)); |
385 EXPECT_TRUE(cookie->IncludeForRequestURL(secure_url_with_path, options)); | 385 EXPECT_TRUE(cookie->IncludeForRequestURL(secure_url_with_path, options)); |
386 EXPECT_FALSE(cookie->IncludeForRequestURL(secure_url, options)); | 386 EXPECT_FALSE(cookie->IncludeForRequestURL(secure_url, options)); |
387 } | 387 } |
388 | 388 |
389 TEST(CanonicalCookieTest, PartialCompare) { | 389 TEST(CanonicalCookieTest, PartialCompare) { |
390 GURL url("http://www.example.com"); | 390 GURL url("http://www.example.com"); |
391 base::Time creation_time = base::Time::Now(); | 391 base::Time creation_time = base::Time::Now(); |
392 CookieOptions options; | 392 CookieOptions options; |
393 scoped_ptr<CanonicalCookie> cookie( | 393 scoped_ptr<CanonicalCookie> cookie( |
394 CanonicalCookie::Create(url, "a=b", creation_time, options)); | 394 CanonicalCookie::Create(url, "a=b", creation_time, options)); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 else if (b.FullCompare(a)) | 443 else if (b.FullCompare(a)) |
444 EXPECT_FALSE(a.PartialCompare(b)); | 444 EXPECT_FALSE(a.PartialCompare(b)); |
445 }; | 445 }; |
446 | 446 |
447 check_consistency(*cookie, *cookie_different_path); | 447 check_consistency(*cookie, *cookie_different_path); |
448 check_consistency(*cookie, *cookie_different_value); | 448 check_consistency(*cookie, *cookie_different_value); |
449 check_consistency(*cookie_different_path, *cookie_different_value); | 449 check_consistency(*cookie_different_path, *cookie_different_value); |
450 } | 450 } |
451 | 451 |
452 } // namespace net | 452 } // namespace net |
OLD | NEW |