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

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

Issue 14113014: Adding Priority field to cookies. (Closed) Base URL: http://chromium.googlesource.com/chromium/src.git@master
Patch Set: Renamed enums PRIORITY_* to COOKIE_PRIORITY_*. Created 7 years, 8 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_constants.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 "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "googleurl/src/gurl.h" 8 #include "googleurl/src/gurl.h"
9 #include "net/cookies/cookie_constants.h"
9 #include "net/cookies/cookie_options.h" 10 #include "net/cookies/cookie_options.h"
10 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
11 12
12 namespace net { 13 namespace net {
13 14
14 TEST(CanonicalCookieTest, GetCookieSourceFromURL) { 15 TEST(CanonicalCookieTest, GetCookieSourceFromURL) {
15 EXPECT_EQ("http://example.com/", 16 EXPECT_EQ("http://example.com/",
16 CanonicalCookie::GetCookieSourceFromURL( 17 CanonicalCookie::GetCookieSourceFromURL(
17 GURL("http://example.com"))); 18 GURL("http://example.com")));
18 EXPECT_EQ("http://example.com/", 19 EXPECT_EQ("http://example.com/",
(...skipping 20 matching lines...) Expand all
39 EXPECT_EQ("http://example.com/", 40 EXPECT_EQ("http://example.com/",
40 CanonicalCookie::GetCookieSourceFromURL( 41 CanonicalCookie::GetCookieSourceFromURL(
41 GURL("http://example.com/test#foo"))); 42 GURL("http://example.com/test#foo")));
42 } 43 }
43 44
44 TEST(CanonicalCookieTest, Constructor) { 45 TEST(CanonicalCookieTest, Constructor) {
45 GURL url("http://www.example.com/test"); 46 GURL url("http://www.example.com/test");
46 base::Time current_time = base::Time::Now(); 47 base::Time current_time = base::Time::Now();
47 48
48 CanonicalCookie cookie(url, "A", "2", "www.example.com", "/test", 49 CanonicalCookie cookie(url, "A", "2", "www.example.com", "/test",
49 current_time, base::Time(), current_time, false, 50 current_time, base::Time(), current_time, false, false,
50 false); 51 COOKIE_PRIORITY_DEFAULT);
51 EXPECT_EQ(url.GetOrigin().spec(), cookie.Source()); 52 EXPECT_EQ(url.GetOrigin().spec(), cookie.Source());
52 EXPECT_EQ("A", cookie.Name()); 53 EXPECT_EQ("A", cookie.Name());
53 EXPECT_EQ("2", cookie.Value()); 54 EXPECT_EQ("2", cookie.Value());
54 EXPECT_EQ("www.example.com", cookie.Domain()); 55 EXPECT_EQ("www.example.com", cookie.Domain());
55 EXPECT_EQ("/test", cookie.Path()); 56 EXPECT_EQ("/test", cookie.Path());
56 EXPECT_FALSE(cookie.IsSecure()); 57 EXPECT_FALSE(cookie.IsSecure());
57 58
58 CanonicalCookie cookie2(url, 59 CanonicalCookie cookie2(url,
59 "A", 60 "A",
60 "2", 61 "2",
61 std::string(), 62 std::string(),
62 std::string(), 63 std::string(),
63 current_time, 64 current_time,
64 base::Time(), 65 base::Time(),
65 current_time, 66 current_time,
66 false, 67 false,
67 false); 68 false,
69 COOKIE_PRIORITY_DEFAULT);
68 EXPECT_EQ(url.GetOrigin().spec(), cookie.Source()); 70 EXPECT_EQ(url.GetOrigin().spec(), cookie.Source());
69 EXPECT_EQ("A", cookie2.Name()); 71 EXPECT_EQ("A", cookie2.Name());
70 EXPECT_EQ("2", cookie2.Value()); 72 EXPECT_EQ("2", cookie2.Value());
71 EXPECT_EQ("", cookie2.Domain()); 73 EXPECT_EQ("", cookie2.Domain());
72 EXPECT_EQ("", cookie2.Path()); 74 EXPECT_EQ("", cookie2.Path());
73 EXPECT_FALSE(cookie2.IsSecure()); 75 EXPECT_FALSE(cookie2.IsSecure());
74 76
75 } 77 }
76 78
77 TEST(CanonicalCookieTest, Create) { 79 TEST(CanonicalCookieTest, Create) {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 httponly_options.set_include_httponly(); 115 httponly_options.set_include_httponly();
114 cookie.reset( 116 cookie.reset(
115 CanonicalCookie::Create(url, "A=2; HttpOnly", creation_time, 117 CanonicalCookie::Create(url, "A=2; HttpOnly", creation_time,
116 httponly_options)); 118 httponly_options));
117 EXPECT_TRUE(cookie->IsHttpOnly()); 119 EXPECT_TRUE(cookie->IsHttpOnly());
118 120
119 // Test the creating cookies using specific parameter instead of a cookie 121 // Test the creating cookies using specific parameter instead of a cookie
120 // string. 122 // string.
121 cookie.reset(CanonicalCookie::Create( 123 cookie.reset(CanonicalCookie::Create(
122 url, "A", "2", "www.example.com", "/test", creation_time, base::Time(), 124 url, "A", "2", "www.example.com", "/test", creation_time, base::Time(),
123 false, false)); 125 false, false, COOKIE_PRIORITY_DEFAULT));
124 EXPECT_EQ(url.GetOrigin().spec(), cookie->Source()); 126 EXPECT_EQ(url.GetOrigin().spec(), cookie->Source());
125 EXPECT_EQ("A", cookie->Name()); 127 EXPECT_EQ("A", cookie->Name());
126 EXPECT_EQ("2", cookie->Value()); 128 EXPECT_EQ("2", cookie->Value());
127 EXPECT_EQ(".www.example.com", cookie->Domain()); 129 EXPECT_EQ(".www.example.com", cookie->Domain());
128 EXPECT_EQ("/test", cookie->Path()); 130 EXPECT_EQ("/test", cookie->Path());
129 EXPECT_FALSE(cookie->IsSecure()); 131 EXPECT_FALSE(cookie->IsSecure());
130 132
131 cookie.reset(CanonicalCookie::Create( 133 cookie.reset(CanonicalCookie::Create(
132 url, "A", "2", ".www.example.com", "/test", creation_time, base::Time(), 134 url, "A", "2", ".www.example.com", "/test", creation_time, base::Time(),
133 false, false)); 135 false, false, COOKIE_PRIORITY_DEFAULT));
134 EXPECT_EQ(url.GetOrigin().spec(), cookie->Source()); 136 EXPECT_EQ(url.GetOrigin().spec(), cookie->Source());
135 EXPECT_EQ("A", cookie->Name()); 137 EXPECT_EQ("A", cookie->Name());
136 EXPECT_EQ("2", cookie->Value()); 138 EXPECT_EQ("2", cookie->Value());
137 EXPECT_EQ(".www.example.com", cookie->Domain()); 139 EXPECT_EQ(".www.example.com", cookie->Domain());
138 EXPECT_EQ("/test", cookie->Path()); 140 EXPECT_EQ("/test", cookie->Path());
139 EXPECT_FALSE(cookie->IsSecure()); 141 EXPECT_FALSE(cookie->IsSecure());
140 } 142 }
141 143
142 TEST(CanonicalCookieTest, EmptyExpiry) { 144 TEST(CanonicalCookieTest, EmptyExpiry) {
143 GURL url("http://www7.ipdl.inpit.go.jp/Tokujitu/tjkta.ipdl?N0000=108"); 145 GURL url("http://www7.ipdl.inpit.go.jp/Tokujitu/tjkta.ipdl?N0000=108");
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 base::Time creation_time = base::Time::Now(); 183 base::Time creation_time = base::Time::Now();
182 base::Time last_access_time = creation_time; 184 base::Time last_access_time = creation_time;
183 base::Time expiration_time = creation_time + base::TimeDelta::FromDays(2); 185 base::Time expiration_time = creation_time + base::TimeDelta::FromDays(2);
184 bool secure(false); 186 bool secure(false);
185 bool httponly(false); 187 bool httponly(false);
186 188
187 // Test that a cookie is equivalent to itself. 189 // Test that a cookie is equivalent to itself.
188 scoped_ptr<CanonicalCookie> cookie( 190 scoped_ptr<CanonicalCookie> cookie(
189 new CanonicalCookie(url, cookie_name, cookie_value, cookie_domain, 191 new CanonicalCookie(url, cookie_name, cookie_value, cookie_domain,
190 cookie_path, creation_time, expiration_time, 192 cookie_path, creation_time, expiration_time,
191 last_access_time, secure, httponly)); 193 last_access_time, secure, httponly,
194 COOKIE_PRIORITY_MEDIUM));
192 EXPECT_TRUE(cookie->IsEquivalent(*cookie)); 195 EXPECT_TRUE(cookie->IsEquivalent(*cookie));
193 196
194 // Test that two identical cookies are equivalent. 197 // Test that two identical cookies are equivalent.
195 scoped_ptr<CanonicalCookie> other_cookie( 198 scoped_ptr<CanonicalCookie> other_cookie(
196 new CanonicalCookie(url, cookie_name, cookie_value, cookie_domain, 199 new CanonicalCookie(url, cookie_name, cookie_value, cookie_domain,
197 cookie_path, creation_time, expiration_time, 200 cookie_path, creation_time, expiration_time,
198 last_access_time, secure, httponly)); 201 last_access_time, secure, httponly,
202 COOKIE_PRIORITY_MEDIUM));
199 EXPECT_TRUE(cookie->IsEquivalent(*other_cookie)); 203 EXPECT_TRUE(cookie->IsEquivalent(*other_cookie));
200 204
201 // Tests that use different variations of attribute values that 205 // Tests that use different variations of attribute values that
202 // DON'T affect cookie equivalence. 206 // DON'T affect cookie equivalence.
203 other_cookie.reset(new CanonicalCookie(url, cookie_name, "2", cookie_domain, 207 other_cookie.reset(new CanonicalCookie(url, cookie_name, "2", cookie_domain,
204 cookie_path, creation_time, 208 cookie_path, creation_time,
205 expiration_time, last_access_time, 209 expiration_time, last_access_time,
206 secure, httponly)); 210 secure, httponly,
211 COOKIE_PRIORITY_HIGH));
207 EXPECT_TRUE(cookie->IsEquivalent(*other_cookie)); 212 EXPECT_TRUE(cookie->IsEquivalent(*other_cookie));
208 213
209 base::Time other_creation_time = 214 base::Time other_creation_time =
210 creation_time + base::TimeDelta::FromMinutes(2); 215 creation_time + base::TimeDelta::FromMinutes(2);
211 other_cookie.reset(new CanonicalCookie(url, cookie_name, "2", cookie_domain, 216 other_cookie.reset(new CanonicalCookie(url, cookie_name, "2", cookie_domain,
212 cookie_path, other_creation_time, 217 cookie_path, other_creation_time,
213 expiration_time, last_access_time, 218 expiration_time, last_access_time,
214 secure, httponly)); 219 secure, httponly,
220 COOKIE_PRIORITY_MEDIUM));
215 EXPECT_TRUE(cookie->IsEquivalent(*other_cookie)); 221 EXPECT_TRUE(cookie->IsEquivalent(*other_cookie));
216 222
217 other_cookie.reset(new CanonicalCookie(url, cookie_name, cookie_name, 223 other_cookie.reset(new CanonicalCookie(url, cookie_name, cookie_name,
218 cookie_domain, cookie_path, 224 cookie_domain, cookie_path,
219 creation_time, expiration_time, 225 creation_time, expiration_time,
220 last_access_time, true, httponly)); 226 last_access_time, true, httponly,
227 COOKIE_PRIORITY_LOW));
221 EXPECT_TRUE(cookie->IsEquivalent(*other_cookie)); 228 EXPECT_TRUE(cookie->IsEquivalent(*other_cookie));
222 229
223 // Tests that use different variations of attribute values that 230 // Tests that use different variations of attribute values that
224 // DO affect cookie equivalence. 231 // DO affect cookie equivalence.
225 other_cookie.reset(new CanonicalCookie(url, "B", cookie_value, cookie_domain, 232 other_cookie.reset(new CanonicalCookie(url, "B", cookie_value, cookie_domain,
226 cookie_path, creation_time, 233 cookie_path, creation_time,
227 expiration_time, last_access_time, 234 expiration_time, last_access_time,
228 secure, httponly)); 235 secure, httponly,
236 COOKIE_PRIORITY_MEDIUM));
229 EXPECT_FALSE(cookie->IsEquivalent(*other_cookie)); 237 EXPECT_FALSE(cookie->IsEquivalent(*other_cookie));
230 238
231 other_cookie.reset(new CanonicalCookie(url, cookie_name, cookie_value, 239 other_cookie.reset(new CanonicalCookie(url, cookie_name, cookie_value,
232 "www.example.com", cookie_path, 240 "www.example.com", cookie_path,
233 creation_time, expiration_time, 241 creation_time, expiration_time,
234 last_access_time, secure, httponly)); 242 last_access_time, secure, httponly,
243 COOKIE_PRIORITY_MEDIUM));
235 EXPECT_TRUE(cookie->IsDomainCookie()); 244 EXPECT_TRUE(cookie->IsDomainCookie());
236 EXPECT_FALSE(other_cookie->IsDomainCookie()); 245 EXPECT_FALSE(other_cookie->IsDomainCookie());
237 EXPECT_FALSE(cookie->IsEquivalent(*other_cookie)); 246 EXPECT_FALSE(cookie->IsEquivalent(*other_cookie));
238 247
239 other_cookie.reset(new CanonicalCookie(url, cookie_name, cookie_value, 248 other_cookie.reset(new CanonicalCookie(url, cookie_name, cookie_value,
240 ".example.com", cookie_path, 249 ".example.com", cookie_path,
241 creation_time, expiration_time, 250 creation_time, expiration_time,
242 last_access_time, secure, httponly)); 251 last_access_time, secure, httponly,
252 COOKIE_PRIORITY_MEDIUM));
243 EXPECT_FALSE(cookie->IsEquivalent(*other_cookie)); 253 EXPECT_FALSE(cookie->IsEquivalent(*other_cookie));
244 254
245 other_cookie.reset(new CanonicalCookie(url, cookie_name, cookie_value, 255 other_cookie.reset(new CanonicalCookie(url, cookie_name, cookie_value,
246 cookie_domain, "/test/0", 256 cookie_domain, "/test/0",
247 creation_time, expiration_time, 257 creation_time, expiration_time,
248 last_access_time, secure, httponly)); 258 last_access_time, secure, httponly,
259 COOKIE_PRIORITY_MEDIUM));
249 EXPECT_FALSE(cookie->IsEquivalent(*other_cookie)); 260 EXPECT_FALSE(cookie->IsEquivalent(*other_cookie));
250 } 261 }
251 262
252 TEST(CanonicalCookieTest, IsDomainMatch) { 263 TEST(CanonicalCookieTest, IsDomainMatch) {
253 GURL url("http://www.example.com/test/foo.html"); 264 GURL url("http://www.example.com/test/foo.html");
254 base::Time creation_time = base::Time::Now(); 265 base::Time creation_time = base::Time::Now();
255 CookieOptions options; 266 CookieOptions options;
256 267
257 scoped_ptr<CanonicalCookie> cookie( 268 scoped_ptr<CanonicalCookie> cookie(
258 CanonicalCookie::Create(url, "A=2", creation_time, options)); 269 CanonicalCookie::Create(url, "A=2", creation_time, options));
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 options.set_include_httponly(); 355 options.set_include_httponly();
345 cookie.reset( 356 cookie.reset(
346 CanonicalCookie::Create(url, "A=2; HttpOnly", creation_time, options)); 357 CanonicalCookie::Create(url, "A=2; HttpOnly", creation_time, options));
347 EXPECT_TRUE(cookie->IsHttpOnly()); 358 EXPECT_TRUE(cookie->IsHttpOnly());
348 EXPECT_TRUE(cookie->IncludeForRequestURL(url, options)); 359 EXPECT_TRUE(cookie->IncludeForRequestURL(url, options));
349 options.set_exclude_httponly(); 360 options.set_exclude_httponly();
350 EXPECT_FALSE(cookie->IncludeForRequestURL(url, options)); 361 EXPECT_FALSE(cookie->IncludeForRequestURL(url, options));
351 } 362 }
352 363
353 } // namespace net 364 } // namespace net
OLDNEW
« no previous file with comments | « net/cookies/canonical_cookie.cc ('k') | net/cookies/cookie_constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698