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

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

Issue 2159373002: net: make CanonicalCookie's constructor private (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: domain 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') | 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/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 std::unique_ptr<CanonicalCookie> cookie(CanonicalCookie::Create(
22 current_time, base::Time(), current_time, false, false, 22 url, "A", "2", std::string(), "/test", current_time, base::Time(), false,
23 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT); 23 false, CookieSameSite::DEFAULT_MODE, false, COOKIE_PRIORITY_DEFAULT));
24 EXPECT_EQ("A", cookie.Name()); 24 EXPECT_EQ("A", cookie->Name());
25 EXPECT_EQ("2", cookie.Value()); 25 EXPECT_EQ("2", cookie->Value());
26 EXPECT_EQ("www.example.com", cookie.Domain()); 26 EXPECT_EQ("www.example.com", cookie->Domain());
27 EXPECT_EQ("/test", cookie.Path()); 27 EXPECT_EQ("/test", cookie->Path());
28 EXPECT_FALSE(cookie.IsSecure()); 28 EXPECT_FALSE(cookie->IsSecure());
29 EXPECT_FALSE(cookie.IsHttpOnly()); 29 EXPECT_FALSE(cookie->IsHttpOnly());
30 EXPECT_EQ(CookieSameSite::NO_RESTRICTION, cookie.SameSite()); 30 EXPECT_EQ(CookieSameSite::NO_RESTRICTION, cookie->SameSite());
31 31
32 CanonicalCookie cookie2(url, "A", "2", std::string(), std::string(), 32 std::unique_ptr<CanonicalCookie> cookie2(CanonicalCookie::Create(
33 current_time, base::Time(), current_time, false, 33 url, "A", "2", ".www.example.com", std::string(), current_time,
34 false, CookieSameSite::DEFAULT_MODE, 34 base::Time(), false, false, CookieSameSite::DEFAULT_MODE, false,
35 COOKIE_PRIORITY_DEFAULT); 35 COOKIE_PRIORITY_DEFAULT));
36 EXPECT_EQ("A", cookie2.Name()); 36 EXPECT_EQ("A", cookie2->Name());
37 EXPECT_EQ("2", cookie2.Value()); 37 EXPECT_EQ("2", cookie2->Value());
38 EXPECT_EQ("", cookie2.Domain()); 38 EXPECT_EQ(".www.example.com", cookie2->Domain());
39 EXPECT_EQ("", cookie2.Path()); 39 EXPECT_EQ("/", cookie2->Path());
40 EXPECT_FALSE(cookie2.IsSecure()); 40 EXPECT_FALSE(cookie2->IsSecure());
41 EXPECT_FALSE(cookie2.IsHttpOnly()); 41 EXPECT_FALSE(cookie2->IsHttpOnly());
42 EXPECT_EQ(CookieSameSite::NO_RESTRICTION, cookie2.SameSite()); 42 EXPECT_EQ(CookieSameSite::NO_RESTRICTION, cookie2->SameSite());
43 } 43 }
44 44
45 TEST(CanonicalCookieTest, Create) { 45 TEST(CanonicalCookieTest, Create) {
46 // Test creating cookies from a cookie string. 46 // Test creating cookies from a cookie string.
47 GURL url("http://www.example.com/test/foo.html"); 47 GURL url("http://www.example.com/test/foo.html");
48 base::Time creation_time = base::Time::Now(); 48 base::Time creation_time = base::Time::Now();
49 CookieOptions options; 49 CookieOptions options;
50 50
51 std::unique_ptr<CanonicalCookie> cookie( 51 std::unique_ptr<CanonicalCookie> cookie(
52 CanonicalCookie::Create(url, "A=2", creation_time, options)); 52 CanonicalCookie::Create(url, "A=2", creation_time, options));
(...skipping 655 matching lines...) Expand 10 before | Expand all | Expand 10 after
708 CanonicalCookie::COOKIE_PREFIX_SECURE, 1); 708 CanonicalCookie::COOKIE_PREFIX_SECURE, 1);
709 EXPECT_TRUE(CanonicalCookie::Create(https_url, "__SecureA=B; Path=/; Secure", 709 EXPECT_TRUE(CanonicalCookie::Create(https_url, "__SecureA=B; Path=/; Secure",
710 creation_time, options)); 710 creation_time, options));
711 histograms.ExpectBucketCount(kCookiePrefixHistogram, 711 histograms.ExpectBucketCount(kCookiePrefixHistogram,
712 CanonicalCookie::COOKIE_PREFIX_SECURE, 2); 712 CanonicalCookie::COOKIE_PREFIX_SECURE, 2);
713 histograms.ExpectBucketCount(kCookiePrefixBlockedHistogram, 713 histograms.ExpectBucketCount(kCookiePrefixBlockedHistogram,
714 CanonicalCookie::COOKIE_PREFIX_SECURE, 1); 714 CanonicalCookie::COOKIE_PREFIX_SECURE, 1);
715 } 715 }
716 716
717 } // namespace net 717 } // 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