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

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

Issue 10697035: Add a mutable version of CookieMonster::ParsedCookie (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merged with ToT Created 8 years, 5 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 | Annotate | Revision Log
« net/cookies/parsed_cookie.cc ('K') | « net/cookies/parsed_cookie.cc ('k') | no next file » | 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/parsed_cookie.h" 7 #include "net/cookies/parsed_cookie.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 namespace net { 10 namespace net {
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 EXPECT_EQ("hello", 268 EXPECT_EQ("hello",
269 ParsedCookie::ParseValueString("hello\nworld")); 269 ParsedCookie::ParseValueString("hello\nworld"));
270 EXPECT_EQ("fs!!@", 270 EXPECT_EQ("fs!!@",
271 ParsedCookie::ParseValueString("fs!!@;helloworld")); 271 ParsedCookie::ParseValueString("fs!!@;helloworld"));
272 EXPECT_EQ("hello world\tgood", 272 EXPECT_EQ("hello world\tgood",
273 ParsedCookie::ParseValueString("hello world\tgood\rbye")); 273 ParsedCookie::ParseValueString("hello world\tgood\rbye"));
274 EXPECT_EQ("A=B=C", 274 EXPECT_EQ("A=B=C",
275 ParsedCookie::ParseValueString("A=B=C;D=E")); 275 ParsedCookie::ParseValueString("A=B=C;D=E"));
276 } 276 }
277 277
278 TEST(ParsedCookieTest, SerializeCookieLine) {
279 const char input[] = "ANCUUID=zohNumRKgI0oxyhSsV3Z7D ; "
280 "expires=Sun, 18-Apr-2027 21:06:29 GMT ; "
281 "path=/ ; ";
282 const char output[] = "ANCUUID=zohNumRKgI0oxyhSsV3Z7D; "
283 "expires=Sun, 18-Apr-2027 21:06:29 GMT; "
284 "path=/";
285 ParsedCookie pc(input);
286 EXPECT_EQ(output, pc.ToCookieLine());
287 }
288
289 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.
290 ParsedCookie pc("name=value");
291 // Set a string containing an invalid character
292 EXPECT_FALSE(pc.SetDomain("foo;bar"));
293 EXPECT_FALSE(pc.HasDomain());
294 EXPECT_EQ("name=value", pc.ToCookieLine());
295
296 // Set all other attributes and check that they are appended in order.
297 EXPECT_TRUE(pc.SetDomain("domain.com"));
298 EXPECT_TRUE(pc.SetPath("/"));
299 EXPECT_TRUE(pc.SetMACKey("mackey"));
300 EXPECT_TRUE(pc.SetMACAlgorithm("\"macalgorithm\""));
301 EXPECT_TRUE(pc.SetExpires("Sun, 18-Apr-2027 21:06:29 GMT"));
302 EXPECT_TRUE(pc.SetMaxAge("12345"));
303 EXPECT_TRUE(pc.SetIsSecure(true));
304 EXPECT_TRUE(pc.SetIsHttpOnly(true));
305 EXPECT_EQ("name=value; domain=domain.com; path=/; mac-key=mackey; "
306 "mac-algorithm=\"macalgorithm\"; "
307 "expires=Sun, 18-Apr-2027 21:06:29 GMT; max-age=12345; secure; "
308 "httponly",
309 pc.ToCookieLine());
310 EXPECT_TRUE(pc.HasDomain());
311 EXPECT_TRUE(pc.HasPath());
312 EXPECT_TRUE(pc.HasMACKey());
313 EXPECT_TRUE(pc.HasMACAlgorithm());
314 EXPECT_TRUE(pc.HasExpires());
315 EXPECT_TRUE(pc.HasMaxAge());
316 EXPECT_TRUE(pc.IsSecure());
317 EXPECT_TRUE(pc.IsHttpOnly());
318
319 // Clear one attribute from the middle.
320 EXPECT_TRUE(pc.SetMACAlgorithm(""));
321 EXPECT_TRUE(pc.HasDomain());
322 EXPECT_TRUE(pc.HasPath());
323 EXPECT_TRUE(pc.HasMACKey());
324 EXPECT_FALSE(pc.HasMACAlgorithm());
325 EXPECT_TRUE(pc.HasExpires());
326 EXPECT_TRUE(pc.HasMaxAge());
327 EXPECT_TRUE(pc.IsSecure());
328 EXPECT_TRUE(pc.IsHttpOnly());
329 EXPECT_EQ("name=value; domain=domain.com; path=/; mac-key=mackey; "
330 "expires=Sun, 18-Apr-2027 21:06:29 GMT; max-age=12345; secure; "
331 "httponly",
332 pc.ToCookieLine());
333
334 // Clear the rest and change the name and value.
335 EXPECT_TRUE(pc.SetDomain(""));
336 EXPECT_TRUE(pc.SetPath(""));
337 EXPECT_TRUE(pc.SetMACKey(""));
338 EXPECT_TRUE(pc.SetMACAlgorithm(""));
339 EXPECT_TRUE(pc.SetExpires(""));
340 EXPECT_TRUE(pc.SetMaxAge(""));
341 EXPECT_TRUE(pc.SetIsSecure(false));
342 EXPECT_TRUE(pc.SetIsHttpOnly(false));
343 EXPECT_TRUE(pc.SetName("name2"));
344 EXPECT_TRUE(pc.SetValue("value2"));
345 EXPECT_FALSE(pc.HasDomain());
346 EXPECT_FALSE(pc.HasPath());
347 EXPECT_FALSE(pc.HasMACKey());
348 EXPECT_FALSE(pc.HasMACAlgorithm());
349 EXPECT_FALSE(pc.HasExpires());
350 EXPECT_FALSE(pc.HasMaxAge());
351 EXPECT_FALSE(pc.IsSecure());
352 EXPECT_FALSE(pc.IsHttpOnly());
353 EXPECT_EQ("name2=value2", pc.ToCookieLine());
354 }
355
278 } // namespace net 356 } // namespace net
OLDNEW
« net/cookies/parsed_cookie.cc ('K') | « net/cookies/parsed_cookie.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698