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

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

Issue 2103863003: Make CanonicalCookie::Source() private. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@source
Patch Set: Merge Created 4 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') | net/cookies/cookie_monster.h » ('j') | 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/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 CanonicalCookie cookie(url, "A", "2", "www.example.com", "/test", 21 CanonicalCookie cookie(url, "A", "2", "www.example.com", "/test",
22 current_time, base::Time(), current_time, false, false, 22 current_time, base::Time(), current_time, false, false,
23 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT); 23 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT);
24 EXPECT_EQ(url.GetOrigin(), cookie.Source());
25 EXPECT_EQ("A", cookie.Name()); 24 EXPECT_EQ("A", cookie.Name());
26 EXPECT_EQ("2", cookie.Value()); 25 EXPECT_EQ("2", cookie.Value());
27 EXPECT_EQ("www.example.com", cookie.Domain()); 26 EXPECT_EQ("www.example.com", cookie.Domain());
28 EXPECT_EQ("/test", cookie.Path()); 27 EXPECT_EQ("/test", cookie.Path());
29 EXPECT_FALSE(cookie.IsSecure()); 28 EXPECT_FALSE(cookie.IsSecure());
30 EXPECT_FALSE(cookie.IsHttpOnly()); 29 EXPECT_FALSE(cookie.IsHttpOnly());
31 EXPECT_EQ(CookieSameSite::NO_RESTRICTION, cookie.SameSite()); 30 EXPECT_EQ(CookieSameSite::NO_RESTRICTION, cookie.SameSite());
32 31
33 CanonicalCookie cookie2(url, "A", "2", std::string(), std::string(), 32 CanonicalCookie cookie2(url, "A", "2", std::string(), std::string(),
34 current_time, base::Time(), current_time, false, 33 current_time, base::Time(), current_time, false,
35 false, CookieSameSite::DEFAULT_MODE, 34 false, CookieSameSite::DEFAULT_MODE,
36 COOKIE_PRIORITY_DEFAULT); 35 COOKIE_PRIORITY_DEFAULT);
37 EXPECT_EQ(url.GetOrigin(), cookie.Source());
38 EXPECT_EQ("A", cookie2.Name()); 36 EXPECT_EQ("A", cookie2.Name());
39 EXPECT_EQ("2", cookie2.Value()); 37 EXPECT_EQ("2", cookie2.Value());
40 EXPECT_EQ("", cookie2.Domain()); 38 EXPECT_EQ("", cookie2.Domain());
41 EXPECT_EQ("", cookie2.Path()); 39 EXPECT_EQ("", cookie2.Path());
42 EXPECT_FALSE(cookie2.IsSecure()); 40 EXPECT_FALSE(cookie2.IsSecure());
43 EXPECT_FALSE(cookie2.IsHttpOnly()); 41 EXPECT_FALSE(cookie2.IsHttpOnly());
44 EXPECT_EQ(CookieSameSite::NO_RESTRICTION, cookie2.SameSite()); 42 EXPECT_EQ(CookieSameSite::NO_RESTRICTION, cookie2.SameSite());
45 } 43 }
46 44
47 TEST(CanonicalCookieTest, Create) { 45 TEST(CanonicalCookieTest, Create) {
48 // Test creating cookies from a cookie string. 46 // Test creating cookies from a cookie string.
49 GURL url("http://www.example.com/test/foo.html"); 47 GURL url("http://www.example.com/test/foo.html");
50 base::Time creation_time = base::Time::Now(); 48 base::Time creation_time = base::Time::Now();
51 CookieOptions options; 49 CookieOptions options;
52 50
53 std::unique_ptr<CanonicalCookie> cookie( 51 std::unique_ptr<CanonicalCookie> cookie(
54 CanonicalCookie::Create(url, "A=2", creation_time, options)); 52 CanonicalCookie::Create(url, "A=2", creation_time, options));
55 EXPECT_EQ(url.GetOrigin(), cookie->Source());
56 EXPECT_EQ("A", cookie->Name()); 53 EXPECT_EQ("A", cookie->Name());
57 EXPECT_EQ("2", cookie->Value()); 54 EXPECT_EQ("2", cookie->Value());
58 EXPECT_EQ("www.example.com", cookie->Domain()); 55 EXPECT_EQ("www.example.com", cookie->Domain());
59 EXPECT_EQ("/test", cookie->Path()); 56 EXPECT_EQ("/test", cookie->Path());
60 EXPECT_FALSE(cookie->IsSecure()); 57 EXPECT_FALSE(cookie->IsSecure());
61 58
62 GURL url2("http://www.foo.com"); 59 GURL url2("http://www.foo.com");
63 cookie = CanonicalCookie::Create(url2, "B=1", creation_time, options); 60 cookie = CanonicalCookie::Create(url2, "B=1", creation_time, options);
64 EXPECT_EQ(url2.GetOrigin(), cookie->Source());
65 EXPECT_EQ("B", cookie->Name()); 61 EXPECT_EQ("B", cookie->Name());
66 EXPECT_EQ("1", cookie->Value()); 62 EXPECT_EQ("1", cookie->Value());
67 EXPECT_EQ("www.foo.com", cookie->Domain()); 63 EXPECT_EQ("www.foo.com", cookie->Domain());
68 EXPECT_EQ("/", cookie->Path()); 64 EXPECT_EQ("/", cookie->Path());
69 EXPECT_FALSE(cookie->IsSecure()); 65 EXPECT_FALSE(cookie->IsSecure());
70 66
71 // Test creating secure cookies. RFC 6265 allows insecure urls to set secure 67 // Test creating secure cookies. RFC 6265 allows insecure urls to set secure
72 // cookies. 68 // cookies.
73 cookie = CanonicalCookie::Create(url, "A=2; Secure", creation_time, options); 69 cookie = CanonicalCookie::Create(url, "A=2; Secure", creation_time, options);
74 EXPECT_TRUE(cookie.get()); 70 EXPECT_TRUE(cookie.get());
(...skipping 19 matching lines...) Expand all
94 EXPECT_EQ(CookieSameSite::STRICT_MODE, cookie->SameSite()); 90 EXPECT_EQ(CookieSameSite::STRICT_MODE, cookie->SameSite());
95 cookie = CanonicalCookie::Create(url, "A=2; SameSite=Lax", creation_time, 91 cookie = CanonicalCookie::Create(url, "A=2; SameSite=Lax", creation_time,
96 same_site_options); 92 same_site_options);
97 93
98 // Test the creating cookies using specific parameter instead of a cookie 94 // Test the creating cookies using specific parameter instead of a cookie
99 // string. 95 // string.
100 cookie = CanonicalCookie::Create(url, "A", "2", "www.example.com", "/test", 96 cookie = CanonicalCookie::Create(url, "A", "2", "www.example.com", "/test",
101 creation_time, base::Time(), false, false, 97 creation_time, base::Time(), false, false,
102 CookieSameSite::DEFAULT_MODE, false, 98 CookieSameSite::DEFAULT_MODE, false,
103 COOKIE_PRIORITY_DEFAULT); 99 COOKIE_PRIORITY_DEFAULT);
104 EXPECT_EQ(url.GetOrigin(), cookie->Source());
105 EXPECT_EQ("A", cookie->Name()); 100 EXPECT_EQ("A", cookie->Name());
106 EXPECT_EQ("2", cookie->Value()); 101 EXPECT_EQ("2", cookie->Value());
107 EXPECT_EQ(".www.example.com", cookie->Domain()); 102 EXPECT_EQ(".www.example.com", cookie->Domain());
108 EXPECT_EQ("/test", cookie->Path()); 103 EXPECT_EQ("/test", cookie->Path());
109 EXPECT_FALSE(cookie->IsSecure()); 104 EXPECT_FALSE(cookie->IsSecure());
110 EXPECT_FALSE(cookie->IsHttpOnly()); 105 EXPECT_FALSE(cookie->IsHttpOnly());
111 EXPECT_EQ(CookieSameSite::NO_RESTRICTION, cookie->SameSite()); 106 EXPECT_EQ(CookieSameSite::NO_RESTRICTION, cookie->SameSite());
112 107
113 cookie = CanonicalCookie::Create(url, "A", "2", ".www.example.com", "/test", 108 cookie = CanonicalCookie::Create(url, "A", "2", ".www.example.com", "/test",
114 creation_time, base::Time(), false, false, 109 creation_time, base::Time(), false, false,
115 CookieSameSite::DEFAULT_MODE, false, 110 CookieSameSite::DEFAULT_MODE, false,
116 COOKIE_PRIORITY_DEFAULT); 111 COOKIE_PRIORITY_DEFAULT);
117 EXPECT_EQ(url.GetOrigin(), cookie->Source());
118 EXPECT_EQ("A", cookie->Name()); 112 EXPECT_EQ("A", cookie->Name());
119 EXPECT_EQ("2", cookie->Value()); 113 EXPECT_EQ("2", cookie->Value());
120 EXPECT_EQ(".www.example.com", cookie->Domain()); 114 EXPECT_EQ(".www.example.com", cookie->Domain());
121 EXPECT_EQ("/test", cookie->Path()); 115 EXPECT_EQ("/test", cookie->Path());
122 EXPECT_FALSE(cookie->IsSecure()); 116 EXPECT_FALSE(cookie->IsSecure());
123 EXPECT_FALSE(cookie->IsHttpOnly()); 117 EXPECT_FALSE(cookie->IsHttpOnly());
124 EXPECT_EQ(CookieSameSite::NO_RESTRICTION, cookie->SameSite()); 118 EXPECT_EQ(CookieSameSite::NO_RESTRICTION, cookie->SameSite());
125 } 119 }
126 120
127 TEST(CanonicalCookieTest, CreateInvalidSameSite) { 121 TEST(CanonicalCookieTest, CreateInvalidSameSite) {
(...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after
714 CanonicalCookie::COOKIE_PREFIX_SECURE, 1); 708 CanonicalCookie::COOKIE_PREFIX_SECURE, 1);
715 EXPECT_TRUE(CanonicalCookie::Create(https_url, "__SecureA=B; Path=/; Secure", 709 EXPECT_TRUE(CanonicalCookie::Create(https_url, "__SecureA=B; Path=/; Secure",
716 creation_time, options)); 710 creation_time, options));
717 histograms.ExpectBucketCount(kCookiePrefixHistogram, 711 histograms.ExpectBucketCount(kCookiePrefixHistogram,
718 CanonicalCookie::COOKIE_PREFIX_SECURE, 2); 712 CanonicalCookie::COOKIE_PREFIX_SECURE, 2);
719 histograms.ExpectBucketCount(kCookiePrefixBlockedHistogram, 713 histograms.ExpectBucketCount(kCookiePrefixBlockedHistogram,
720 CanonicalCookie::COOKIE_PREFIX_SECURE, 1); 714 CanonicalCookie::COOKIE_PREFIX_SECURE, 1);
721 } 715 }
722 716
723 } // namespace net 717 } // namespace net
OLDNEW
« no previous file with comments | « net/cookies/canonical_cookie.cc ('k') | net/cookies/cookie_monster.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698