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

Side by Side Diff: ios/net/cookies/system_cookie_util_unittest.mm

Issue 2874843002: Shifted creation of unvalidated CanonicalCookies over to a constructor. (Closed)
Patch Set: Merged to top of dependent CL. Created 3 years, 7 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 | « ios/net/cookies/system_cookie_util.mm ('k') | net/cookies/canonical_cookie.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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "ios/net/cookies/system_cookie_util.h" 5 #include "ios/net/cookies/system_cookie_util.h"
6 6
7 #import <Foundation/Foundation.h> 7 #import <Foundation/Foundation.h>
8 8
9 #include "base/mac/scoped_nsobject.h" 9 #include "base/mac/scoped_nsobject.h"
10 #include "base/strings/sys_string_conversions.h" 10 #include "base/strings/sys_string_conversions.h"
11 #include "base/time/time.h" 11 #include "base/time/time.h"
12 #include "net/cookies/cookie_constants.h" 12 #include "net/cookies/cookie_constants.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "testing/gtest_mac.h" 14 #include "testing/gtest_mac.h"
15 #include "url/gurl.h" 15 #include "url/gurl.h"
16 16
17 namespace net { 17 namespace net {
18 18
19 namespace { 19 namespace {
20 20
21 const char kCookieDomain[] = "domain"; 21 const char kCookieDomain[] = "domain";
22 const char kCookieName[] = "name"; 22 const char kCookieName[] = "name";
23 const char kCookiePath[] = "path/"; 23 const char kCookiePath[] = "path/";
24 const char kCookieValue[] = "value"; 24 const char kCookieValue[] = "value";
25 const char kCookieValueInvalidUtf8[] = "\x81r\xe4\xbd\xa0\xe5\xa5\xbd"; 25 const char kCookieValueInvalidUtf8[] = "\x81r\xe4\xbd\xa0\xe5\xa5\xbd";
26 26
27 void CheckSystemCookie(const base::Time& expires, bool secure, bool httponly) { 27 void CheckSystemCookie(const base::Time& expires, bool secure, bool httponly) {
28 // Generate a canonical cookie. 28 // Generate a canonical cookie.
29 net::CanonicalCookie canonical_cookie = *net::CanonicalCookie::Create( 29 net::CanonicalCookie canonical_cookie(
30 kCookieName, kCookieValue, kCookieDomain, kCookiePath, 30 kCookieName, kCookieValue, kCookieDomain, kCookiePath,
31 base::Time(), // creation 31 base::Time(), // creation
32 expires, 32 expires,
33 base::Time(), // last_access 33 base::Time(), // last_access
34 secure, httponly, net::CookieSameSite::DEFAULT_MODE, 34 secure, httponly, net::CookieSameSite::DEFAULT_MODE,
35 net::COOKIE_PRIORITY_DEFAULT); 35 net::COOKIE_PRIORITY_DEFAULT);
36 // Convert it to system cookie. 36 // Convert it to system cookie.
37 base::scoped_nsobject<NSHTTPCookie> system_cookie( 37 base::scoped_nsobject<NSHTTPCookie> system_cookie(
38 [SystemCookieFromCanonicalCookie(canonical_cookie) retain]); 38 [SystemCookieFromCanonicalCookie(canonical_cookie) retain]);
39 39
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 109
110 // Test various combinations of session, secure and httponly attributes. 110 // Test various combinations of session, secure and httponly attributes.
111 CheckSystemCookie(expire_date, false, false); 111 CheckSystemCookie(expire_date, false, false);
112 CheckSystemCookie(base::Time(), true, false); 112 CheckSystemCookie(base::Time(), true, false);
113 CheckSystemCookie(expire_date, false, true); 113 CheckSystemCookie(expire_date, false, true);
114 CheckSystemCookie(base::Time(), true, true); 114 CheckSystemCookie(base::Time(), true, true);
115 } 115 }
116 116
117 TEST(CookieUtil, SystemCookieFromBadCanonicalCookie) { 117 TEST(CookieUtil, SystemCookieFromBadCanonicalCookie) {
118 // Generate a bad canonical cookie (value is invalid utf8). 118 // Generate a bad canonical cookie (value is invalid utf8).
119 net::CanonicalCookie bad_canonical_cookie = *net::CanonicalCookie::Create( 119 net::CanonicalCookie bad_canonical_cookie(
120 kCookieName, kCookieValueInvalidUtf8, kCookieDomain, kCookiePath, 120 kCookieName, kCookieValueInvalidUtf8, kCookieDomain, kCookiePath,
121 base::Time(), // creation 121 base::Time(), // creation
122 base::Time(), // expires 122 base::Time(), // expires
123 base::Time(), // last_access 123 base::Time(), // last_access
124 false, // secure 124 false, // secure
125 false, // httponly 125 false, // httponly
126 net::CookieSameSite::DEFAULT_MODE, net::COOKIE_PRIORITY_DEFAULT); 126 net::CookieSameSite::DEFAULT_MODE, net::COOKIE_PRIORITY_DEFAULT);
127 // Convert it to system cookie. 127 // Convert it to system cookie.
128 base::scoped_nsobject<NSHTTPCookie> system_cookie( 128 base::scoped_nsobject<NSHTTPCookie> system_cookie(
129 [SystemCookieFromCanonicalCookie(bad_canonical_cookie) retain]); 129 [SystemCookieFromCanonicalCookie(bad_canonical_cookie) retain]);
130 EXPECT_TRUE(system_cookie == nil); 130 EXPECT_TRUE(system_cookie == nil);
131 } 131 }
132 132
133 } // namespace net 133 } // namespace net
OLDNEW
« no previous file with comments | « ios/net/cookies/system_cookie_util.mm ('k') | net/cookies/canonical_cookie.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698