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

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

Issue 876973003: Implement the "first-party-only" cookie flag. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: FirstPartyOnly. Created 5 years, 10 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/parsed_cookie.cc ('k') | net/url_request/url_request_http_job.cc » ('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 <string> 5 #include <string>
6 6
7 #include "net/cookies/cookie_constants.h" 7 #include "net/cookies/cookie_constants.h"
8 #include "net/cookies/parsed_cookie.h" 8 #include "net/cookies/parsed_cookie.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 EXPECT_TRUE(pc.IsValid()); 85 EXPECT_TRUE(pc.IsValid());
86 EXPECT_TRUE(pc.IsSecure()); 86 EXPECT_TRUE(pc.IsSecure());
87 EXPECT_TRUE(pc.HasPath()); 87 EXPECT_TRUE(pc.HasPath());
88 EXPECT_EQ("/", pc.Path()); 88 EXPECT_EQ("/", pc.Path());
89 EXPECT_EQ("", pc.Name()); 89 EXPECT_EQ("", pc.Name());
90 EXPECT_EQ("BLAHHH", pc.Value()); 90 EXPECT_EQ("BLAHHH", pc.Value());
91 EXPECT_EQ(COOKIE_PRIORITY_DEFAULT, pc.Priority()); 91 EXPECT_EQ(COOKIE_PRIORITY_DEFAULT, pc.Priority());
92 } 92 }
93 93
94 TEST(ParsedCookieTest, TestAttributeCase) { 94 TEST(ParsedCookieTest, TestAttributeCase) {
95 ParsedCookie pc("BLAHHH; Path=/; sECuRe; httpONLY; pRIoRitY=hIgH"); 95 ParsedCookie pc(
96 "BLAHHH; Path=/; sECuRe; httpONLY; first-PaRty-only; pRIoRitY=hIgH");
96 EXPECT_TRUE(pc.IsValid()); 97 EXPECT_TRUE(pc.IsValid());
97 EXPECT_TRUE(pc.IsSecure()); 98 EXPECT_TRUE(pc.IsSecure());
98 EXPECT_TRUE(pc.IsHttpOnly()); 99 EXPECT_TRUE(pc.IsHttpOnly());
100 EXPECT_TRUE(pc.IsFirstPartyOnly());
99 EXPECT_TRUE(pc.HasPath()); 101 EXPECT_TRUE(pc.HasPath());
100 EXPECT_EQ("/", pc.Path()); 102 EXPECT_EQ("/", pc.Path());
101 EXPECT_EQ("", pc.Name()); 103 EXPECT_EQ("", pc.Name());
102 EXPECT_EQ("BLAHHH", pc.Value()); 104 EXPECT_EQ("BLAHHH", pc.Value());
103 EXPECT_EQ(COOKIE_PRIORITY_HIGH, pc.Priority()); 105 EXPECT_EQ(COOKIE_PRIORITY_HIGH, pc.Priority());
104 EXPECT_EQ(4U, pc.NumberOfAttributes()); 106 EXPECT_EQ(5U, pc.NumberOfAttributes());
105 } 107 }
106 108
107 TEST(ParsedCookieTest, TestDoubleQuotedNameless) { 109 TEST(ParsedCookieTest, TestDoubleQuotedNameless) {
108 ParsedCookie pc("\"BLA\\\"HHH\"; path=/; secure;"); 110 ParsedCookie pc("\"BLA\\\"HHH\"; path=/; secure;");
109 EXPECT_TRUE(pc.IsValid()); 111 EXPECT_TRUE(pc.IsValid());
110 EXPECT_TRUE(pc.IsSecure()); 112 EXPECT_TRUE(pc.IsSecure());
111 EXPECT_TRUE(pc.HasPath()); 113 EXPECT_TRUE(pc.HasPath());
112 EXPECT_EQ("/", pc.Path()); 114 EXPECT_EQ("/", pc.Path());
113 EXPECT_EQ("", pc.Name()); 115 EXPECT_EQ("", pc.Name());
114 EXPECT_EQ("\"BLA\\\"HHH\"", pc.Value()); 116 EXPECT_EQ("\"BLA\\\"HHH\"", pc.Value());
(...skipping 24 matching lines...) Expand all
139 EXPECT_TRUE(pc.IsValid()); 141 EXPECT_TRUE(pc.IsValid());
140 EXPECT_EQ("ABC", pc.Name()); 142 EXPECT_EQ("ABC", pc.Name());
141 EXPECT_EQ("", pc.Value()); 143 EXPECT_EQ("", pc.Value());
142 EXPECT_TRUE(pc.HasPath()); 144 EXPECT_TRUE(pc.HasPath());
143 EXPECT_EQ("/wee", pc.Path()); 145 EXPECT_EQ("/wee", pc.Path());
144 EXPECT_EQ(COOKIE_PRIORITY_DEFAULT, pc.Priority()); 146 EXPECT_EQ(COOKIE_PRIORITY_DEFAULT, pc.Priority());
145 EXPECT_EQ(1U, pc.NumberOfAttributes()); 147 EXPECT_EQ(1U, pc.NumberOfAttributes());
146 } 148 }
147 149
148 TEST(ParsedCookieTest, Whitespace) { 150 TEST(ParsedCookieTest, Whitespace) {
149 ParsedCookie pc(" A = BC ;secure;;; httponly"); 151 ParsedCookie pc(" A = BC ;secure;;; first-party-only ");
150 EXPECT_TRUE(pc.IsValid()); 152 EXPECT_TRUE(pc.IsValid());
151 EXPECT_EQ("A", pc.Name()); 153 EXPECT_EQ("A", pc.Name());
152 EXPECT_EQ("BC", pc.Value()); 154 EXPECT_EQ("BC", pc.Value());
153 EXPECT_FALSE(pc.HasPath()); 155 EXPECT_FALSE(pc.HasPath());
154 EXPECT_FALSE(pc.HasDomain()); 156 EXPECT_FALSE(pc.HasDomain());
155 EXPECT_TRUE(pc.IsSecure()); 157 EXPECT_TRUE(pc.IsSecure());
156 EXPECT_TRUE(pc.IsHttpOnly()); 158 EXPECT_FALSE(pc.IsHttpOnly());
159 EXPECT_TRUE(pc.IsFirstPartyOnly());
157 EXPECT_EQ(COOKIE_PRIORITY_DEFAULT, pc.Priority()); 160 EXPECT_EQ(COOKIE_PRIORITY_DEFAULT, pc.Priority());
158 // We parse anything between ; as attributes, so we end up with two 161 // We parse anything between ; as attributes, so we end up with two
159 // attributes with an empty string name and value. 162 // attributes with an empty string name and value.
160 EXPECT_EQ(4U, pc.NumberOfAttributes()); 163 EXPECT_EQ(4U, pc.NumberOfAttributes());
161 } 164 }
162 TEST(ParsedCookieTest, MultipleEquals) { 165 TEST(ParsedCookieTest, MultipleEquals) {
163 ParsedCookie pc(" A=== BC ;secure;;; httponly"); 166 ParsedCookie pc(" A=== BC ;secure;;; httponly");
164 EXPECT_TRUE(pc.IsValid()); 167 EXPECT_TRUE(pc.IsValid());
165 EXPECT_EQ("A", pc.Name()); 168 EXPECT_EQ("A", pc.Name());
166 EXPECT_EQ("== BC", pc.Value()); 169 EXPECT_EQ("== BC", pc.Value());
167 EXPECT_FALSE(pc.HasPath()); 170 EXPECT_FALSE(pc.HasPath());
168 EXPECT_FALSE(pc.HasDomain()); 171 EXPECT_FALSE(pc.HasDomain());
169 EXPECT_TRUE(pc.IsSecure()); 172 EXPECT_TRUE(pc.IsSecure());
170 EXPECT_TRUE(pc.IsHttpOnly()); 173 EXPECT_TRUE(pc.IsHttpOnly());
174 EXPECT_FALSE(pc.IsFirstPartyOnly());
171 EXPECT_EQ(COOKIE_PRIORITY_DEFAULT, pc.Priority()); 175 EXPECT_EQ(COOKIE_PRIORITY_DEFAULT, pc.Priority());
172 EXPECT_EQ(4U, pc.NumberOfAttributes()); 176 EXPECT_EQ(4U, pc.NumberOfAttributes());
173 } 177 }
174 178
175 TEST(ParsedCookieTest, QuotedTrailingWhitespace) { 179 TEST(ParsedCookieTest, QuotedTrailingWhitespace) {
176 ParsedCookie pc( 180 ParsedCookie pc(
177 "ANCUUID=\"zohNumRKgI0oxyhSsV3Z7D\" ; " 181 "ANCUUID=\"zohNumRKgI0oxyhSsV3Z7D\" ; "
178 "expires=Sun, 18-Apr-2027 21:06:29 GMT ; " 182 "expires=Sun, 18-Apr-2027 21:06:29 GMT ; "
179 "path=/ ; "); 183 "path=/ ; ");
180 EXPECT_TRUE(pc.IsValid()); 184 EXPECT_TRUE(pc.IsValid());
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 EXPECT_TRUE(pc.IsValid()); 350 EXPECT_TRUE(pc.IsValid());
347 351
348 // Set all other attributes and check that they are appended in order. 352 // Set all other attributes and check that they are appended in order.
349 EXPECT_TRUE(pc.SetDomain("domain.com")); 353 EXPECT_TRUE(pc.SetDomain("domain.com"));
350 EXPECT_TRUE(pc.SetPath("/")); 354 EXPECT_TRUE(pc.SetPath("/"));
351 EXPECT_TRUE(pc.SetExpires("Sun, 18-Apr-2027 21:06:29 GMT")); 355 EXPECT_TRUE(pc.SetExpires("Sun, 18-Apr-2027 21:06:29 GMT"));
352 EXPECT_TRUE(pc.SetMaxAge("12345")); 356 EXPECT_TRUE(pc.SetMaxAge("12345"));
353 EXPECT_TRUE(pc.SetIsSecure(true)); 357 EXPECT_TRUE(pc.SetIsSecure(true));
354 EXPECT_TRUE(pc.SetIsHttpOnly(true)); 358 EXPECT_TRUE(pc.SetIsHttpOnly(true));
355 EXPECT_TRUE(pc.SetIsHttpOnly(true)); 359 EXPECT_TRUE(pc.SetIsHttpOnly(true));
360 EXPECT_TRUE(pc.SetIsFirstPartyOnly(true));
356 EXPECT_TRUE(pc.SetPriority("HIGH")); 361 EXPECT_TRUE(pc.SetPriority("HIGH"));
357 EXPECT_EQ( 362 EXPECT_EQ(
358 "name=value; domain=domain.com; path=/; " 363 "name=value; domain=domain.com; path=/; "
359 "expires=Sun, 18-Apr-2027 21:06:29 GMT; max-age=12345; secure; " 364 "expires=Sun, 18-Apr-2027 21:06:29 GMT; max-age=12345; secure; "
360 "httponly; priority=HIGH", 365 "httponly; first-party-only; priority=HIGH",
361 pc.ToCookieLine()); 366 pc.ToCookieLine());
362 EXPECT_TRUE(pc.HasDomain()); 367 EXPECT_TRUE(pc.HasDomain());
363 EXPECT_TRUE(pc.HasPath()); 368 EXPECT_TRUE(pc.HasPath());
364 EXPECT_TRUE(pc.HasExpires()); 369 EXPECT_TRUE(pc.HasExpires());
365 EXPECT_TRUE(pc.HasMaxAge()); 370 EXPECT_TRUE(pc.HasMaxAge());
366 EXPECT_TRUE(pc.IsSecure()); 371 EXPECT_TRUE(pc.IsSecure());
367 EXPECT_TRUE(pc.IsHttpOnly()); 372 EXPECT_TRUE(pc.IsHttpOnly());
373 EXPECT_TRUE(pc.IsFirstPartyOnly());
368 EXPECT_EQ(COOKIE_PRIORITY_HIGH, pc.Priority()); 374 EXPECT_EQ(COOKIE_PRIORITY_HIGH, pc.Priority());
369 375
370 // Clear one attribute from the middle. 376 // Clear one attribute from the middle.
371 EXPECT_TRUE(pc.SetPath("/foo")); 377 EXPECT_TRUE(pc.SetPath("/foo"));
372 EXPECT_TRUE(pc.HasDomain()); 378 EXPECT_TRUE(pc.HasDomain());
373 EXPECT_TRUE(pc.HasPath()); 379 EXPECT_TRUE(pc.HasPath());
374 EXPECT_TRUE(pc.HasExpires()); 380 EXPECT_TRUE(pc.HasExpires());
375 EXPECT_TRUE(pc.IsSecure()); 381 EXPECT_TRUE(pc.IsSecure());
376 EXPECT_TRUE(pc.IsHttpOnly()); 382 EXPECT_TRUE(pc.IsHttpOnly());
377 EXPECT_EQ( 383 EXPECT_EQ(
378 "name=value; domain=domain.com; path=/foo; " 384 "name=value; domain=domain.com; path=/foo; "
379 "expires=Sun, 18-Apr-2027 21:06:29 GMT; max-age=12345; secure; " 385 "expires=Sun, 18-Apr-2027 21:06:29 GMT; max-age=12345; secure; "
380 "httponly; priority=HIGH", 386 "httponly; first-party-only; priority=HIGH",
381 pc.ToCookieLine()); 387 pc.ToCookieLine());
382 388
383 // Set priority to medium. 389 // Set priority to medium.
384 EXPECT_TRUE(pc.SetPriority("medium")); 390 EXPECT_TRUE(pc.SetPriority("medium"));
385 EXPECT_EQ( 391 EXPECT_EQ(
386 "name=value; domain=domain.com; path=/foo; " 392 "name=value; domain=domain.com; path=/foo; "
387 "expires=Sun, 18-Apr-2027 21:06:29 GMT; max-age=12345; secure; " 393 "expires=Sun, 18-Apr-2027 21:06:29 GMT; max-age=12345; secure; "
388 "httponly; priority=medium", 394 "httponly; first-party-only; priority=medium",
389 pc.ToCookieLine()); 395 pc.ToCookieLine());
390 396
391 // Clear the rest and change the name and value. 397 // Clear the rest and change the name and value.
392 EXPECT_TRUE(pc.SetDomain(std::string())); 398 EXPECT_TRUE(pc.SetDomain(std::string()));
393 EXPECT_TRUE(pc.SetPath(std::string())); 399 EXPECT_TRUE(pc.SetPath(std::string()));
394 EXPECT_TRUE(pc.SetExpires(std::string())); 400 EXPECT_TRUE(pc.SetExpires(std::string()));
395 EXPECT_TRUE(pc.SetMaxAge(std::string())); 401 EXPECT_TRUE(pc.SetMaxAge(std::string()));
396 EXPECT_TRUE(pc.SetIsSecure(false)); 402 EXPECT_TRUE(pc.SetIsSecure(false));
397 EXPECT_TRUE(pc.SetIsHttpOnly(false)); 403 EXPECT_TRUE(pc.SetIsHttpOnly(false));
404 EXPECT_TRUE(pc.SetIsFirstPartyOnly(false));
398 EXPECT_TRUE(pc.SetName("name2")); 405 EXPECT_TRUE(pc.SetName("name2"));
399 EXPECT_TRUE(pc.SetValue("value2")); 406 EXPECT_TRUE(pc.SetValue("value2"));
400 EXPECT_TRUE(pc.SetPriority(std::string())); 407 EXPECT_TRUE(pc.SetPriority(std::string()));
401 EXPECT_FALSE(pc.HasDomain()); 408 EXPECT_FALSE(pc.HasDomain());
402 EXPECT_FALSE(pc.HasPath()); 409 EXPECT_FALSE(pc.HasPath());
403 EXPECT_FALSE(pc.HasExpires()); 410 EXPECT_FALSE(pc.HasExpires());
404 EXPECT_FALSE(pc.HasMaxAge()); 411 EXPECT_FALSE(pc.HasMaxAge());
405 EXPECT_FALSE(pc.IsSecure()); 412 EXPECT_FALSE(pc.IsSecure());
406 EXPECT_FALSE(pc.IsHttpOnly()); 413 EXPECT_FALSE(pc.IsHttpOnly());
414 EXPECT_FALSE(pc.IsFirstPartyOnly());
407 EXPECT_EQ("name2=value2", pc.ToCookieLine()); 415 EXPECT_EQ("name2=value2", pc.ToCookieLine());
408 } 416 }
409 417
410 TEST(ParsedCookieTest, SetPriority) { 418 TEST(ParsedCookieTest, SetPriority) {
411 ParsedCookie pc("name=value"); 419 ParsedCookie pc("name=value");
412 EXPECT_TRUE(pc.IsValid()); 420 EXPECT_TRUE(pc.IsValid());
413 421
414 EXPECT_EQ("name=value", pc.ToCookieLine()); 422 EXPECT_EQ("name=value", pc.ToCookieLine());
415 EXPECT_EQ(COOKIE_PRIORITY_DEFAULT, pc.Priority()); 423 EXPECT_EQ(COOKIE_PRIORITY_DEFAULT, pc.Priority());
416 424
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 EXPECT_TRUE(pc5.IsValid()); 544 EXPECT_TRUE(pc5.IsValid());
537 EXPECT_EQ(pc5_literal, pc5.ToCookieLine()); 545 EXPECT_EQ(pc5_literal, pc5.ToCookieLine());
538 EXPECT_TRUE(pc6.IsValid()); 546 EXPECT_TRUE(pc6.IsValid());
539 EXPECT_EQ(pc6_literal, pc6.ToCookieLine()); 547 EXPECT_EQ(pc6_literal, pc6.ToCookieLine());
540 EXPECT_TRUE(pc7.IsValid()); 548 EXPECT_TRUE(pc7.IsValid());
541 EXPECT_EQ(pc7_literal, pc7.ToCookieLine()); 549 EXPECT_EQ(pc7_literal, pc7.ToCookieLine());
542 EXPECT_TRUE(pc8.IsValid()); 550 EXPECT_TRUE(pc8.IsValid());
543 EXPECT_EQ(pc8_literal, pc8.ToCookieLine()); 551 EXPECT_EQ(pc8_literal, pc8.ToCookieLine());
544 } 552 }
545 } 553 }
OLDNEW
« no previous file with comments | « net/cookies/parsed_cookie.cc ('k') | net/url_request/url_request_http_job.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698