| OLD | NEW |
| 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 Loading... |
| 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( | 95 ParsedCookie pc("BLAHHH; Path=/; sECuRe; httpONLY; sAmESitE; pRIoRitY=hIgH"); |
| 96 "BLAHHH; Path=/; sECuRe; httpONLY; first-PaRty-only; pRIoRitY=hIgH"); | |
| 97 EXPECT_TRUE(pc.IsValid()); | 96 EXPECT_TRUE(pc.IsValid()); |
| 98 EXPECT_TRUE(pc.IsSecure()); | 97 EXPECT_TRUE(pc.IsSecure()); |
| 99 EXPECT_TRUE(pc.IsHttpOnly()); | 98 EXPECT_TRUE(pc.IsHttpOnly()); |
| 100 EXPECT_TRUE(pc.IsFirstPartyOnly()); | 99 EXPECT_TRUE(pc.IsSameSite()); |
| 101 EXPECT_TRUE(pc.HasPath()); | 100 EXPECT_TRUE(pc.HasPath()); |
| 102 EXPECT_EQ("/", pc.Path()); | 101 EXPECT_EQ("/", pc.Path()); |
| 103 EXPECT_EQ("", pc.Name()); | 102 EXPECT_EQ("", pc.Name()); |
| 104 EXPECT_EQ("BLAHHH", pc.Value()); | 103 EXPECT_EQ("BLAHHH", pc.Value()); |
| 105 EXPECT_EQ(COOKIE_PRIORITY_HIGH, pc.Priority()); | 104 EXPECT_EQ(COOKIE_PRIORITY_HIGH, pc.Priority()); |
| 106 EXPECT_EQ(5U, pc.NumberOfAttributes()); | 105 EXPECT_EQ(5U, pc.NumberOfAttributes()); |
| 107 } | 106 } |
| 108 | 107 |
| 109 TEST(ParsedCookieTest, TestDoubleQuotedNameless) { | 108 TEST(ParsedCookieTest, TestDoubleQuotedNameless) { |
| 110 ParsedCookie pc("\"BLA\\\"HHH\"; path=/; secure;"); | 109 ParsedCookie pc("\"BLA\\\"HHH\"; path=/; secure;"); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 141 EXPECT_TRUE(pc.IsValid()); | 140 EXPECT_TRUE(pc.IsValid()); |
| 142 EXPECT_EQ("ABC", pc.Name()); | 141 EXPECT_EQ("ABC", pc.Name()); |
| 143 EXPECT_EQ("", pc.Value()); | 142 EXPECT_EQ("", pc.Value()); |
| 144 EXPECT_TRUE(pc.HasPath()); | 143 EXPECT_TRUE(pc.HasPath()); |
| 145 EXPECT_EQ("/wee", pc.Path()); | 144 EXPECT_EQ("/wee", pc.Path()); |
| 146 EXPECT_EQ(COOKIE_PRIORITY_DEFAULT, pc.Priority()); | 145 EXPECT_EQ(COOKIE_PRIORITY_DEFAULT, pc.Priority()); |
| 147 EXPECT_EQ(1U, pc.NumberOfAttributes()); | 146 EXPECT_EQ(1U, pc.NumberOfAttributes()); |
| 148 } | 147 } |
| 149 | 148 |
| 150 TEST(ParsedCookieTest, Whitespace) { | 149 TEST(ParsedCookieTest, Whitespace) { |
| 151 ParsedCookie pc(" A = BC ;secure;;; first-party-only "); | 150 ParsedCookie pc(" A = BC ;secure;;; samesite "); |
| 152 EXPECT_TRUE(pc.IsValid()); | 151 EXPECT_TRUE(pc.IsValid()); |
| 153 EXPECT_EQ("A", pc.Name()); | 152 EXPECT_EQ("A", pc.Name()); |
| 154 EXPECT_EQ("BC", pc.Value()); | 153 EXPECT_EQ("BC", pc.Value()); |
| 155 EXPECT_FALSE(pc.HasPath()); | 154 EXPECT_FALSE(pc.HasPath()); |
| 156 EXPECT_FALSE(pc.HasDomain()); | 155 EXPECT_FALSE(pc.HasDomain()); |
| 157 EXPECT_TRUE(pc.IsSecure()); | 156 EXPECT_TRUE(pc.IsSecure()); |
| 158 EXPECT_FALSE(pc.IsHttpOnly()); | 157 EXPECT_FALSE(pc.IsHttpOnly()); |
| 159 EXPECT_TRUE(pc.IsFirstPartyOnly()); | 158 EXPECT_TRUE(pc.IsSameSite()); |
| 160 EXPECT_EQ(COOKIE_PRIORITY_DEFAULT, pc.Priority()); | 159 EXPECT_EQ(COOKIE_PRIORITY_DEFAULT, pc.Priority()); |
| 161 // We parse anything between ; as attributes, so we end up with two | 160 // We parse anything between ; as attributes, so we end up with two |
| 162 // attributes with an empty string name and value. | 161 // attributes with an empty string name and value. |
| 163 EXPECT_EQ(4U, pc.NumberOfAttributes()); | 162 EXPECT_EQ(4U, pc.NumberOfAttributes()); |
| 164 } | 163 } |
| 165 TEST(ParsedCookieTest, MultipleEquals) { | 164 TEST(ParsedCookieTest, MultipleEquals) { |
| 166 ParsedCookie pc(" A=== BC ;secure;;; httponly"); | 165 ParsedCookie pc(" A=== BC ;secure;;; httponly"); |
| 167 EXPECT_TRUE(pc.IsValid()); | 166 EXPECT_TRUE(pc.IsValid()); |
| 168 EXPECT_EQ("A", pc.Name()); | 167 EXPECT_EQ("A", pc.Name()); |
| 169 EXPECT_EQ("== BC", pc.Value()); | 168 EXPECT_EQ("== BC", pc.Value()); |
| 170 EXPECT_FALSE(pc.HasPath()); | 169 EXPECT_FALSE(pc.HasPath()); |
| 171 EXPECT_FALSE(pc.HasDomain()); | 170 EXPECT_FALSE(pc.HasDomain()); |
| 172 EXPECT_TRUE(pc.IsSecure()); | 171 EXPECT_TRUE(pc.IsSecure()); |
| 173 EXPECT_TRUE(pc.IsHttpOnly()); | 172 EXPECT_TRUE(pc.IsHttpOnly()); |
| 174 EXPECT_FALSE(pc.IsFirstPartyOnly()); | 173 EXPECT_FALSE(pc.IsSameSite()); |
| 175 EXPECT_EQ(COOKIE_PRIORITY_DEFAULT, pc.Priority()); | 174 EXPECT_EQ(COOKIE_PRIORITY_DEFAULT, pc.Priority()); |
| 176 EXPECT_EQ(4U, pc.NumberOfAttributes()); | 175 EXPECT_EQ(4U, pc.NumberOfAttributes()); |
| 177 } | 176 } |
| 178 | 177 |
| 179 TEST(ParsedCookieTest, QuotedTrailingWhitespace) { | 178 TEST(ParsedCookieTest, QuotedTrailingWhitespace) { |
| 180 ParsedCookie pc( | 179 ParsedCookie pc( |
| 181 "ANCUUID=\"zohNumRKgI0oxyhSsV3Z7D\" ; " | 180 "ANCUUID=\"zohNumRKgI0oxyhSsV3Z7D\" ; " |
| 182 "expires=Sun, 18-Apr-2027 21:06:29 GMT ; " | 181 "expires=Sun, 18-Apr-2027 21:06:29 GMT ; " |
| 183 "path=/ ; "); | 182 "path=/ ; "); |
| 184 EXPECT_TRUE(pc.IsValid()); | 183 EXPECT_TRUE(pc.IsValid()); |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 EXPECT_TRUE(pc.IsValid()); | 349 EXPECT_TRUE(pc.IsValid()); |
| 351 | 350 |
| 352 // Set all other attributes and check that they are appended in order. | 351 // Set all other attributes and check that they are appended in order. |
| 353 EXPECT_TRUE(pc.SetDomain("domain.com")); | 352 EXPECT_TRUE(pc.SetDomain("domain.com")); |
| 354 EXPECT_TRUE(pc.SetPath("/")); | 353 EXPECT_TRUE(pc.SetPath("/")); |
| 355 EXPECT_TRUE(pc.SetExpires("Sun, 18-Apr-2027 21:06:29 GMT")); | 354 EXPECT_TRUE(pc.SetExpires("Sun, 18-Apr-2027 21:06:29 GMT")); |
| 356 EXPECT_TRUE(pc.SetMaxAge("12345")); | 355 EXPECT_TRUE(pc.SetMaxAge("12345")); |
| 357 EXPECT_TRUE(pc.SetIsSecure(true)); | 356 EXPECT_TRUE(pc.SetIsSecure(true)); |
| 358 EXPECT_TRUE(pc.SetIsHttpOnly(true)); | 357 EXPECT_TRUE(pc.SetIsHttpOnly(true)); |
| 359 EXPECT_TRUE(pc.SetIsHttpOnly(true)); | 358 EXPECT_TRUE(pc.SetIsHttpOnly(true)); |
| 360 EXPECT_TRUE(pc.SetIsFirstPartyOnly(true)); | 359 EXPECT_TRUE(pc.SetIsSameSite(true)); |
| 361 EXPECT_TRUE(pc.SetPriority("HIGH")); | 360 EXPECT_TRUE(pc.SetPriority("HIGH")); |
| 362 EXPECT_EQ( | 361 EXPECT_EQ( |
| 363 "name=value; domain=domain.com; path=/; " | 362 "name=value; domain=domain.com; path=/; " |
| 364 "expires=Sun, 18-Apr-2027 21:06:29 GMT; max-age=12345; secure; " | 363 "expires=Sun, 18-Apr-2027 21:06:29 GMT; max-age=12345; secure; " |
| 365 "httponly; first-party-only; priority=HIGH", | 364 "httponly; samesite; priority=HIGH", |
| 366 pc.ToCookieLine()); | 365 pc.ToCookieLine()); |
| 367 EXPECT_TRUE(pc.HasDomain()); | 366 EXPECT_TRUE(pc.HasDomain()); |
| 368 EXPECT_TRUE(pc.HasPath()); | 367 EXPECT_TRUE(pc.HasPath()); |
| 369 EXPECT_TRUE(pc.HasExpires()); | 368 EXPECT_TRUE(pc.HasExpires()); |
| 370 EXPECT_TRUE(pc.HasMaxAge()); | 369 EXPECT_TRUE(pc.HasMaxAge()); |
| 371 EXPECT_TRUE(pc.IsSecure()); | 370 EXPECT_TRUE(pc.IsSecure()); |
| 372 EXPECT_TRUE(pc.IsHttpOnly()); | 371 EXPECT_TRUE(pc.IsHttpOnly()); |
| 373 EXPECT_TRUE(pc.IsFirstPartyOnly()); | 372 EXPECT_TRUE(pc.IsSameSite()); |
| 374 EXPECT_EQ(COOKIE_PRIORITY_HIGH, pc.Priority()); | 373 EXPECT_EQ(COOKIE_PRIORITY_HIGH, pc.Priority()); |
| 375 | 374 |
| 376 // Clear one attribute from the middle. | 375 // Clear one attribute from the middle. |
| 377 EXPECT_TRUE(pc.SetPath("/foo")); | 376 EXPECT_TRUE(pc.SetPath("/foo")); |
| 378 EXPECT_TRUE(pc.HasDomain()); | 377 EXPECT_TRUE(pc.HasDomain()); |
| 379 EXPECT_TRUE(pc.HasPath()); | 378 EXPECT_TRUE(pc.HasPath()); |
| 380 EXPECT_TRUE(pc.HasExpires()); | 379 EXPECT_TRUE(pc.HasExpires()); |
| 381 EXPECT_TRUE(pc.IsSecure()); | 380 EXPECT_TRUE(pc.IsSecure()); |
| 382 EXPECT_TRUE(pc.IsHttpOnly()); | 381 EXPECT_TRUE(pc.IsHttpOnly()); |
| 383 EXPECT_EQ( | 382 EXPECT_EQ( |
| 384 "name=value; domain=domain.com; path=/foo; " | 383 "name=value; domain=domain.com; path=/foo; " |
| 385 "expires=Sun, 18-Apr-2027 21:06:29 GMT; max-age=12345; secure; " | 384 "expires=Sun, 18-Apr-2027 21:06:29 GMT; max-age=12345; secure; " |
| 386 "httponly; first-party-only; priority=HIGH", | 385 "httponly; samesite; priority=HIGH", |
| 387 pc.ToCookieLine()); | 386 pc.ToCookieLine()); |
| 388 | 387 |
| 389 // Set priority to medium. | 388 // Set priority to medium. |
| 390 EXPECT_TRUE(pc.SetPriority("medium")); | 389 EXPECT_TRUE(pc.SetPriority("medium")); |
| 391 EXPECT_EQ( | 390 EXPECT_EQ( |
| 392 "name=value; domain=domain.com; path=/foo; " | 391 "name=value; domain=domain.com; path=/foo; " |
| 393 "expires=Sun, 18-Apr-2027 21:06:29 GMT; max-age=12345; secure; " | 392 "expires=Sun, 18-Apr-2027 21:06:29 GMT; max-age=12345; secure; " |
| 394 "httponly; first-party-only; priority=medium", | 393 "httponly; samesite; priority=medium", |
| 395 pc.ToCookieLine()); | 394 pc.ToCookieLine()); |
| 396 | 395 |
| 397 // Clear the rest and change the name and value. | 396 // Clear the rest and change the name and value. |
| 398 EXPECT_TRUE(pc.SetDomain(std::string())); | 397 EXPECT_TRUE(pc.SetDomain(std::string())); |
| 399 EXPECT_TRUE(pc.SetPath(std::string())); | 398 EXPECT_TRUE(pc.SetPath(std::string())); |
| 400 EXPECT_TRUE(pc.SetExpires(std::string())); | 399 EXPECT_TRUE(pc.SetExpires(std::string())); |
| 401 EXPECT_TRUE(pc.SetMaxAge(std::string())); | 400 EXPECT_TRUE(pc.SetMaxAge(std::string())); |
| 402 EXPECT_TRUE(pc.SetIsSecure(false)); | 401 EXPECT_TRUE(pc.SetIsSecure(false)); |
| 403 EXPECT_TRUE(pc.SetIsHttpOnly(false)); | 402 EXPECT_TRUE(pc.SetIsHttpOnly(false)); |
| 404 EXPECT_TRUE(pc.SetIsFirstPartyOnly(false)); | 403 EXPECT_TRUE(pc.SetIsSameSite(false)); |
| 405 EXPECT_TRUE(pc.SetName("name2")); | 404 EXPECT_TRUE(pc.SetName("name2")); |
| 406 EXPECT_TRUE(pc.SetValue("value2")); | 405 EXPECT_TRUE(pc.SetValue("value2")); |
| 407 EXPECT_TRUE(pc.SetPriority(std::string())); | 406 EXPECT_TRUE(pc.SetPriority(std::string())); |
| 408 EXPECT_FALSE(pc.HasDomain()); | 407 EXPECT_FALSE(pc.HasDomain()); |
| 409 EXPECT_FALSE(pc.HasPath()); | 408 EXPECT_FALSE(pc.HasPath()); |
| 410 EXPECT_FALSE(pc.HasExpires()); | 409 EXPECT_FALSE(pc.HasExpires()); |
| 411 EXPECT_FALSE(pc.HasMaxAge()); | 410 EXPECT_FALSE(pc.HasMaxAge()); |
| 412 EXPECT_FALSE(pc.IsSecure()); | 411 EXPECT_FALSE(pc.IsSecure()); |
| 413 EXPECT_FALSE(pc.IsHttpOnly()); | 412 EXPECT_FALSE(pc.IsHttpOnly()); |
| 414 EXPECT_FALSE(pc.IsFirstPartyOnly()); | 413 EXPECT_FALSE(pc.IsSameSite()); |
| 415 EXPECT_EQ("name2=value2", pc.ToCookieLine()); | 414 EXPECT_EQ("name2=value2", pc.ToCookieLine()); |
| 416 } | 415 } |
| 417 | 416 |
| 418 TEST(ParsedCookieTest, SetPriority) { | 417 TEST(ParsedCookieTest, SetPriority) { |
| 419 ParsedCookie pc("name=value"); | 418 ParsedCookie pc("name=value"); |
| 420 EXPECT_TRUE(pc.IsValid()); | 419 EXPECT_TRUE(pc.IsValid()); |
| 421 | 420 |
| 422 EXPECT_EQ("name=value", pc.ToCookieLine()); | 421 EXPECT_EQ("name=value", pc.ToCookieLine()); |
| 423 EXPECT_EQ(COOKIE_PRIORITY_DEFAULT, pc.Priority()); | 422 EXPECT_EQ(COOKIE_PRIORITY_DEFAULT, pc.Priority()); |
| 424 | 423 |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 544 EXPECT_TRUE(pc5.IsValid()); | 543 EXPECT_TRUE(pc5.IsValid()); |
| 545 EXPECT_EQ(pc5_literal, pc5.ToCookieLine()); | 544 EXPECT_EQ(pc5_literal, pc5.ToCookieLine()); |
| 546 EXPECT_TRUE(pc6.IsValid()); | 545 EXPECT_TRUE(pc6.IsValid()); |
| 547 EXPECT_EQ(pc6_literal, pc6.ToCookieLine()); | 546 EXPECT_EQ(pc6_literal, pc6.ToCookieLine()); |
| 548 EXPECT_TRUE(pc7.IsValid()); | 547 EXPECT_TRUE(pc7.IsValid()); |
| 549 EXPECT_EQ(pc7_literal, pc7.ToCookieLine()); | 548 EXPECT_EQ(pc7_literal, pc7.ToCookieLine()); |
| 550 EXPECT_TRUE(pc8.IsValid()); | 549 EXPECT_TRUE(pc8.IsValid()); |
| 551 EXPECT_EQ(pc8_literal, pc8.ToCookieLine()); | 550 EXPECT_EQ(pc8_literal, pc8.ToCookieLine()); |
| 552 } | 551 } |
| 553 } | 552 } |
| OLD | NEW |