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

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

Issue 2959123002: Allow paths constructed from URLs rather as well as cookie attributes. (Closed)
Patch Set: Remove failing path tests. Created 3 years, 5 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
« no previous file with comments | « net/cookies/canonical_cookie.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <memory> 7 #include <memory>
8 8
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/test/histogram_tester.h" 10 #include "base/test/histogram_tester.h"
(...skipping 26 matching lines...) Expand all
37 COOKIE_PRIORITY_DEFAULT)); 37 COOKIE_PRIORITY_DEFAULT));
38 EXPECT_EQ("A", cookie2->Name()); 38 EXPECT_EQ("A", cookie2->Name());
39 EXPECT_EQ("2", cookie2->Value()); 39 EXPECT_EQ("2", cookie2->Value());
40 EXPECT_EQ(".www.example.com", cookie2->Domain()); 40 EXPECT_EQ(".www.example.com", cookie2->Domain());
41 EXPECT_EQ("/", cookie2->Path()); 41 EXPECT_EQ("/", cookie2->Path());
42 EXPECT_FALSE(cookie2->IsSecure()); 42 EXPECT_FALSE(cookie2->IsSecure());
43 EXPECT_FALSE(cookie2->IsHttpOnly()); 43 EXPECT_FALSE(cookie2->IsHttpOnly());
44 EXPECT_EQ(CookieSameSite::NO_RESTRICTION, cookie2->SameSite()); 44 EXPECT_EQ(CookieSameSite::NO_RESTRICTION, cookie2->SameSite());
45 } 45 }
46 46
47 TEST(CanonicalCookie, SpaceInName) { 47 TEST(CanonicalCookie, CreationCornerCases) {
48 GURL url("http://www.example.com/test/foo.html");
49 base::Time creation_time = base::Time::Now(); 48 base::Time creation_time = base::Time::Now();
50 CookieOptions options; 49 CookieOptions options;
51 std::unique_ptr<CanonicalCookie> cookie( 50 std::unique_ptr<CanonicalCookie> cookie;
52 CanonicalCookie::Create(url, "A C=2", creation_time, options)); 51
52 // Space in name.
53 cookie = CanonicalCookie::Create(GURL("http://www.example.com/test/foo.html"),
54 "A C=2", creation_time, options);
53 EXPECT_TRUE(cookie.get()); 55 EXPECT_TRUE(cookie.get());
54 EXPECT_EQ("A C", cookie->Name()); 56 EXPECT_EQ("A C", cookie->Name());
57
58 // Semicolon in path.
59 cookie = CanonicalCookie::Create(GURL("http://fool/;/"), "*", creation_time,
60 options);
61 EXPECT_TRUE(cookie.get());
62
63 // Space in path.
64 cookie = CanonicalCookie::Create(GURL("http://fool/xyzzy wwwww/"), "A=B",
mmenke 2017/06/28 00:26:20 Doesn't GURL precent-escape spaces in paths?
Randy Smith (Not in Mondays) 2017/06/28 14:58:05 Yeah, it does :-J. Ok. What I think that means i
mmenke 2017/06/28 17:13:48 I'm wondering if it's worth the effort - I don't t
Randy Smith (Not in Mondays) 2017/06/28 17:41:21 Sure. My goal at the moment is just to get the fu
65 creation_time, options);
66 EXPECT_TRUE(cookie.get());
55 } 67 }
56 68
57 TEST(CanonicalCookieTest, Create) { 69 TEST(CanonicalCookieTest, Create) {
58 // Test creating cookies from a cookie string. 70 // Test creating cookies from a cookie string.
59 GURL url("http://www.example.com/test/foo.html"); 71 GURL url("http://www.example.com/test/foo.html");
60 base::Time creation_time = base::Time::Now(); 72 base::Time creation_time = base::Time::Now();
61 CookieOptions options; 73 CookieOptions options;
62 74
63 std::unique_ptr<CanonicalCookie> cookie( 75 std::unique_ptr<CanonicalCookie> cookie(
64 CanonicalCookie::Create(url, "A=2", creation_time, options)); 76 CanonicalCookie::Create(url, "A=2", creation_time, options));
(...skipping 670 matching lines...) Expand 10 before | Expand all | Expand 10 after
735 COOKIE_PRIORITY_LOW) 747 COOKIE_PRIORITY_LOW)
736 .IsCanonical()); 748 .IsCanonical());
737 749
738 // Empty path. 750 // Empty path.
739 EXPECT_FALSE(CanonicalCookie("A", "B", "x.y", "", base::Time(), base::Time(), 751 EXPECT_FALSE(CanonicalCookie("A", "B", "x.y", "", base::Time(), base::Time(),
740 base::Time(), false, false, 752 base::Time(), false, false,
741 CookieSameSite::NO_RESTRICTION, 753 CookieSameSite::NO_RESTRICTION,
742 COOKIE_PRIORITY_LOW) 754 COOKIE_PRIORITY_LOW)
743 .IsCanonical()); 755 .IsCanonical());
744 756
745 // Path suffixed with a space.
746 EXPECT_FALSE(CanonicalCookie("A", "B", "x.y", "/path ", base::Time(),
747 base::Time(), base::Time(), false, false,
748 CookieSameSite::NO_RESTRICTION,
749 COOKIE_PRIORITY_LOW)
750 .IsCanonical());
751
752 // Path suffixed with separator.
753 EXPECT_FALSE(CanonicalCookie("A", "B", "x.y", "/path;", base::Time(),
754 base::Time(), base::Time(), false, false,
755 CookieSameSite::NO_RESTRICTION,
756 COOKIE_PRIORITY_LOW)
757 .IsCanonical());
758
759 // Simple IPv4 address as domain. 757 // Simple IPv4 address as domain.
760 EXPECT_TRUE(CanonicalCookie("A", "B", "1.2.3.4", "/path", base::Time(), 758 EXPECT_TRUE(CanonicalCookie("A", "B", "1.2.3.4", "/path", base::Time(),
761 base::Time(), base::Time(), false, false, 759 base::Time(), base::Time(), false, false,
762 CookieSameSite::NO_RESTRICTION, 760 CookieSameSite::NO_RESTRICTION,
763 COOKIE_PRIORITY_LOW) 761 COOKIE_PRIORITY_LOW)
764 .IsCanonical()); 762 .IsCanonical());
765 763
766 // NOn-canonical IPv4 address as domain. 764 // NOn-canonical IPv4 address as domain.
767 EXPECT_FALSE(CanonicalCookie("A", "B", "01.2.03.4", "/path", base::Time(), 765 EXPECT_FALSE(CanonicalCookie("A", "B", "01.2.03.4", "/path", base::Time(),
768 base::Time(), base::Time(), false, false, 766 base::Time(), base::Time(), false, false,
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
919 CanonicalCookie::COOKIE_PREFIX_SECURE, 1); 917 CanonicalCookie::COOKIE_PREFIX_SECURE, 1);
920 EXPECT_TRUE(CanonicalCookie::Create(https_url, "__SecureA=B; Path=/; Secure", 918 EXPECT_TRUE(CanonicalCookie::Create(https_url, "__SecureA=B; Path=/; Secure",
921 creation_time, options)); 919 creation_time, options));
922 histograms.ExpectBucketCount(kCookiePrefixHistogram, 920 histograms.ExpectBucketCount(kCookiePrefixHistogram,
923 CanonicalCookie::COOKIE_PREFIX_SECURE, 2); 921 CanonicalCookie::COOKIE_PREFIX_SECURE, 2);
924 histograms.ExpectBucketCount(kCookiePrefixBlockedHistogram, 922 histograms.ExpectBucketCount(kCookiePrefixBlockedHistogram,
925 CanonicalCookie::COOKIE_PREFIX_SECURE, 1); 923 CanonicalCookie::COOKIE_PREFIX_SECURE, 1);
926 } 924 }
927 925
928 } // namespace net 926 } // namespace net
OLDNEW
« no previous file with comments | « net/cookies/canonical_cookie.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698