Chromium Code Reviews| Index: net/cookies/parsed_cookie_unittest.cc |
| diff --git a/net/cookies/parsed_cookie_unittest.cc b/net/cookies/parsed_cookie_unittest.cc |
| index 7b6d562263d8e4a3cb097c99f90b9ba0536e5aa9..001b9692f1b8b93348bf638b8cab050ddfc46bb5 100644 |
| --- a/net/cookies/parsed_cookie_unittest.cc |
| +++ b/net/cookies/parsed_cookie_unittest.cc |
| @@ -275,4 +275,82 @@ TEST(ParsedCookieTest, ParseTokensAndValues) { |
| ParsedCookie::ParseValueString("A=B=C;D=E")); |
| } |
| +TEST(ParsedCookieTest, SerializeCookieLine) { |
| + const char input[] = "ANCUUID=zohNumRKgI0oxyhSsV3Z7D ; " |
| + "expires=Sun, 18-Apr-2027 21:06:29 GMT ; " |
| + "path=/ ; "; |
| + const char output[] = "ANCUUID=zohNumRKgI0oxyhSsV3Z7D; " |
| + "expires=Sun, 18-Apr-2027 21:06:29 GMT; " |
| + "path=/"; |
| + ParsedCookie pc(input); |
| + EXPECT_EQ(output, pc.ToCookieLine()); |
| +} |
| + |
| +TEST(ParsedCookieTest, SetValues) { |
|
erikwright (departed)
2012/07/12 15:50:57
Add checks for invalid name/value.
Add constructio
battre
2012/07/12 18:03:10
Done.
|
| + ParsedCookie pc("name=value"); |
| + // Set a string containing an invalid character |
| + EXPECT_FALSE(pc.SetDomain("foo;bar")); |
| + EXPECT_FALSE(pc.HasDomain()); |
| + EXPECT_EQ("name=value", pc.ToCookieLine()); |
| + |
| + // Set all other attributes and check that they are appended in order. |
| + EXPECT_TRUE(pc.SetDomain("domain.com")); |
| + EXPECT_TRUE(pc.SetPath("/")); |
| + EXPECT_TRUE(pc.SetMACKey("mackey")); |
| + EXPECT_TRUE(pc.SetMACAlgorithm("\"macalgorithm\"")); |
| + EXPECT_TRUE(pc.SetExpires("Sun, 18-Apr-2027 21:06:29 GMT")); |
| + EXPECT_TRUE(pc.SetMaxAge("12345")); |
| + EXPECT_TRUE(pc.SetIsSecure(true)); |
| + EXPECT_TRUE(pc.SetIsHttpOnly(true)); |
| + EXPECT_EQ("name=value; domain=domain.com; path=/; mac-key=mackey; " |
| + "mac-algorithm=\"macalgorithm\"; " |
| + "expires=Sun, 18-Apr-2027 21:06:29 GMT; max-age=12345; secure; " |
| + "httponly", |
| + pc.ToCookieLine()); |
| + EXPECT_TRUE(pc.HasDomain()); |
| + EXPECT_TRUE(pc.HasPath()); |
| + EXPECT_TRUE(pc.HasMACKey()); |
| + EXPECT_TRUE(pc.HasMACAlgorithm()); |
| + EXPECT_TRUE(pc.HasExpires()); |
| + EXPECT_TRUE(pc.HasMaxAge()); |
| + EXPECT_TRUE(pc.IsSecure()); |
| + EXPECT_TRUE(pc.IsHttpOnly()); |
| + |
| + // Clear one attribute from the middle. |
| + EXPECT_TRUE(pc.SetMACAlgorithm("")); |
| + EXPECT_TRUE(pc.HasDomain()); |
| + EXPECT_TRUE(pc.HasPath()); |
| + EXPECT_TRUE(pc.HasMACKey()); |
| + EXPECT_FALSE(pc.HasMACAlgorithm()); |
| + EXPECT_TRUE(pc.HasExpires()); |
| + EXPECT_TRUE(pc.HasMaxAge()); |
| + EXPECT_TRUE(pc.IsSecure()); |
| + EXPECT_TRUE(pc.IsHttpOnly()); |
| + EXPECT_EQ("name=value; domain=domain.com; path=/; mac-key=mackey; " |
| + "expires=Sun, 18-Apr-2027 21:06:29 GMT; max-age=12345; secure; " |
| + "httponly", |
| + pc.ToCookieLine()); |
| + |
| + // Clear the rest and change the name and value. |
| + EXPECT_TRUE(pc.SetDomain("")); |
| + EXPECT_TRUE(pc.SetPath("")); |
| + EXPECT_TRUE(pc.SetMACKey("")); |
| + EXPECT_TRUE(pc.SetMACAlgorithm("")); |
| + EXPECT_TRUE(pc.SetExpires("")); |
| + EXPECT_TRUE(pc.SetMaxAge("")); |
| + EXPECT_TRUE(pc.SetIsSecure(false)); |
| + EXPECT_TRUE(pc.SetIsHttpOnly(false)); |
| + EXPECT_TRUE(pc.SetName("name2")); |
| + EXPECT_TRUE(pc.SetValue("value2")); |
| + EXPECT_FALSE(pc.HasDomain()); |
| + EXPECT_FALSE(pc.HasPath()); |
| + EXPECT_FALSE(pc.HasMACKey()); |
| + EXPECT_FALSE(pc.HasMACAlgorithm()); |
| + EXPECT_FALSE(pc.HasExpires()); |
| + EXPECT_FALSE(pc.HasMaxAge()); |
| + EXPECT_FALSE(pc.IsSecure()); |
| + EXPECT_FALSE(pc.IsHttpOnly()); |
| + EXPECT_EQ("name2=value2", pc.ToCookieLine()); |
| +} |
| + |
| } // namespace net |