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

Side by Side Diff: net/cookies/cookie_store_unittest.h

Issue 13145003: Rewrite std::string("") to std::string(), Linux edition. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Ugh 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 | Annotate | Revision Log
« no previous file with comments | « net/cookies/cookie_store_test_helpers.cc ('k') | net/cookies/parsed_cookie.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 #ifndef NET_COOKIES_COOKIE_STORE_UNITTEST_H_ 5 #ifndef NET_COOKIES_COOKIE_STORE_UNITTEST_H_
6 #define NET_COOKIES_COOKIE_STORE_UNITTEST_H_ 6 #define NET_COOKIES_COOKIE_STORE_UNITTEST_H_
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/strings/string_tokenizer.h" 10 #include "base/strings/string_tokenizer.h"
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 268
269 // Test setting a domain= that doesn't start w/ a dot, should 269 // Test setting a domain= that doesn't start w/ a dot, should
270 // treat it as a domain cookie, as if there was a pre-pended dot. 270 // treat it as a domain cookie, as if there was a pre-pended dot.
271 EXPECT_TRUE(this->SetCookie(cs, this->url_google_, 271 EXPECT_TRUE(this->SetCookie(cs, this->url_google_,
272 "G=H; domain=www.google.izzle")); 272 "G=H; domain=www.google.izzle"));
273 this->MatchCookieLines("A=B; C=D; E=F; G=H", 273 this->MatchCookieLines("A=B; C=D; E=F; G=H",
274 this->GetCookies(cs, this->url_google_)); 274 this->GetCookies(cs, this->url_google_));
275 275
276 // Test domain enforcement, should fail on a sub-domain or something too deep. 276 // Test domain enforcement, should fail on a sub-domain or something too deep.
277 EXPECT_FALSE(this->SetCookie(cs, this->url_google_, "I=J; domain=.izzle")); 277 EXPECT_FALSE(this->SetCookie(cs, this->url_google_, "I=J; domain=.izzle"));
278 this->MatchCookieLines("", this->GetCookies(cs, GURL("http://a.izzle"))); 278 this->MatchCookieLines(std::string(),
279 EXPECT_FALSE(this->SetCookie(cs, this->url_google_, 279 this->GetCookies(cs, GURL("http://a.izzle")));
280 "K=L; domain=.bla.www.google.izzle")); 280 EXPECT_FALSE(this->SetCookie(
281 cs, this->url_google_, "K=L; domain=.bla.www.google.izzle"));
281 this->MatchCookieLines("C=D; E=F; G=H", 282 this->MatchCookieLines("C=D; E=F; G=H",
282 this->GetCookies(cs, GURL("http://bla.www.google.izzle"))); 283 this->GetCookies(cs, GURL("http://bla.www.google.izzle")));
283 this->MatchCookieLines("A=B; C=D; E=F; G=H", 284 this->MatchCookieLines("A=B; C=D; E=F; G=H",
284 this->GetCookies(cs, this->url_google_)); 285 this->GetCookies(cs, this->url_google_));
285 } 286 }
286 287
287 // FireFox recognizes domains containing trailing periods as valid. 288 // FireFox recognizes domains containing trailing periods as valid.
288 // IE and Safari do not. Assert the expected policy here. 289 // IE and Safari do not. Assert the expected policy here.
289 TYPED_TEST_P(CookieStoreTest, DomainWithTrailingDotTest) { 290 TYPED_TEST_P(CookieStoreTest, DomainWithTrailingDotTest) {
290 scoped_refptr<CookieStore> cs(this->GetCookieStore()); 291 scoped_refptr<CookieStore> cs(this->GetCookieStore());
291 EXPECT_FALSE(this->SetCookie(cs, this->url_google_, 292 EXPECT_FALSE(this->SetCookie(cs, this->url_google_,
292 "a=1; domain=.www.google.com.")); 293 "a=1; domain=.www.google.com."));
293 EXPECT_FALSE(this->SetCookie(cs, this->url_google_, 294 EXPECT_FALSE(this->SetCookie(cs, this->url_google_,
294 "b=2; domain=.www.google.com..")); 295 "b=2; domain=.www.google.com.."));
295 this->MatchCookieLines("", this->GetCookies(cs, this->url_google_)); 296 this->MatchCookieLines(std::string(),
297 this->GetCookies(cs, this->url_google_));
296 } 298 }
297 299
298 // Test that cookies can bet set on higher level domains. 300 // Test that cookies can bet set on higher level domains.
299 // http://b/issue?id=896491 301 // http://b/issue?id=896491
300 TYPED_TEST_P(CookieStoreTest, ValidSubdomainTest) { 302 TYPED_TEST_P(CookieStoreTest, ValidSubdomainTest) {
301 scoped_refptr<CookieStore> cs(this->GetCookieStore()); 303 scoped_refptr<CookieStore> cs(this->GetCookieStore());
302 GURL url_abcd("http://a.b.c.d.com"); 304 GURL url_abcd("http://a.b.c.d.com");
303 GURL url_bcd("http://b.c.d.com"); 305 GURL url_bcd("http://b.c.d.com");
304 GURL url_cd("http://c.d.com"); 306 GURL url_cd("http://c.d.com");
305 GURL url_d("http://d.com"); 307 GURL url_d("http://d.com");
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 "k=11; domain=.foo.bar.com?blah")); 361 "k=11; domain=.foo.bar.com?blah"));
360 EXPECT_FALSE(this->SetCookie(cs, url_foobar, 362 EXPECT_FALSE(this->SetCookie(cs, url_foobar,
361 "l=12; domain=.foo.bar.com/blah")); 363 "l=12; domain=.foo.bar.com/blah"));
362 EXPECT_FALSE(this->SetCookie(cs, url_foobar, 364 EXPECT_FALSE(this->SetCookie(cs, url_foobar,
363 "m=13; domain=.foo.bar.com:80")); 365 "m=13; domain=.foo.bar.com:80"));
364 EXPECT_FALSE(this->SetCookie(cs, url_foobar, 366 EXPECT_FALSE(this->SetCookie(cs, url_foobar,
365 "n=14; domain=.foo.bar.com:")); 367 "n=14; domain=.foo.bar.com:"));
366 EXPECT_FALSE(this->SetCookie(cs, url_foobar, 368 EXPECT_FALSE(this->SetCookie(cs, url_foobar,
367 "o=15; domain=.foo.bar.com#sup")); 369 "o=15; domain=.foo.bar.com#sup"));
368 370
369 this->MatchCookieLines("", this->GetCookies(cs, url_foobar)); 371 this->MatchCookieLines(std::string(), this->GetCookies(cs, url_foobar));
370 } 372 }
371 373
372 { 374 {
373 // Make sure the cookie code hasn't gotten its subdomain string handling 375 // Make sure the cookie code hasn't gotten its subdomain string handling
374 // reversed, missed a suffix check, etc. It's important here that the two 376 // reversed, missed a suffix check, etc. It's important here that the two
375 // hosts below have the same domain + registry. 377 // hosts below have the same domain + registry.
376 scoped_refptr<CookieStore> cs(this->GetCookieStore()); 378 scoped_refptr<CookieStore> cs(this->GetCookieStore());
377 GURL url_foocom("http://foo.com.com"); 379 GURL url_foocom("http://foo.com.com");
378 EXPECT_FALSE(this->SetCookie(cs, url_foocom, 380 EXPECT_FALSE(this->SetCookie(cs, url_foocom,
379 "a=1; domain=.foo.com.com.com")); 381 "a=1; domain=.foo.com.com.com"));
380 this->MatchCookieLines("", this->GetCookies(cs, url_foocom)); 382 this->MatchCookieLines(std::string(), this->GetCookies(cs, url_foocom));
381 } 383 }
382 } 384 }
383 385
384 // Test the behavior of omitting dot prefix from domain, should 386 // Test the behavior of omitting dot prefix from domain, should
385 // function the same as FireFox. 387 // function the same as FireFox.
386 // http://b/issue?id=889898 388 // http://b/issue?id=889898
387 TYPED_TEST_P(CookieStoreTest, DomainWithoutLeadingDotTest) { 389 TYPED_TEST_P(CookieStoreTest, DomainWithoutLeadingDotTest) {
388 { // The omission of dot results in setting a domain cookie. 390 { // The omission of dot results in setting a domain cookie.
389 scoped_refptr<CookieStore> cs(this->GetCookieStore()); 391 scoped_refptr<CookieStore> cs(this->GetCookieStore());
390 GURL url_hosted("http://manage.hosted.filefront.com"); 392 GURL url_hosted("http://manage.hosted.filefront.com");
391 GURL url_filefront("http://www.filefront.com"); 393 GURL url_filefront("http://www.filefront.com");
392 EXPECT_TRUE(this->SetCookie(cs, url_hosted, 394 EXPECT_TRUE(this->SetCookie(cs, url_hosted,
393 "sawAd=1; domain=filefront.com")); 395 "sawAd=1; domain=filefront.com"));
394 this->MatchCookieLines("sawAd=1", this->GetCookies(cs, url_hosted)); 396 this->MatchCookieLines("sawAd=1", this->GetCookies(cs, url_hosted));
395 this->MatchCookieLines("sawAd=1", this->GetCookies(cs, url_filefront)); 397 this->MatchCookieLines("sawAd=1", this->GetCookies(cs, url_filefront));
396 } 398 }
397 399
398 { // Even when the domains match exactly, don't consider it host cookie. 400 { // Even when the domains match exactly, don't consider it host cookie.
399 scoped_refptr<CookieStore> cs(this->GetCookieStore()); 401 scoped_refptr<CookieStore> cs(this->GetCookieStore());
400 GURL url("http://www.google.com"); 402 GURL url("http://www.google.com");
401 EXPECT_TRUE(this->SetCookie(cs, url, "a=1; domain=www.google.com")); 403 EXPECT_TRUE(this->SetCookie(cs, url, "a=1; domain=www.google.com"));
402 this->MatchCookieLines("a=1", this->GetCookies(cs, url)); 404 this->MatchCookieLines("a=1", this->GetCookies(cs, url));
403 this->MatchCookieLines("a=1", 405 this->MatchCookieLines("a=1",
404 this->GetCookies(cs, GURL("http://sub.www.google.com"))); 406 this->GetCookies(cs, GURL("http://sub.www.google.com")));
405 this->MatchCookieLines("", 407 this->MatchCookieLines(
406 this->GetCookies(cs, GURL("http://something-else.com"))); 408 std::string(), this->GetCookies(cs, GURL("http://something-else.com")));
407 } 409 }
408 } 410 }
409 411
410 // Test that the domain specified in cookie string is treated case-insensitive 412 // Test that the domain specified in cookie string is treated case-insensitive
411 // http://b/issue?id=896475. 413 // http://b/issue?id=896475.
412 TYPED_TEST_P(CookieStoreTest, CaseInsensitiveDomainTest) { 414 TYPED_TEST_P(CookieStoreTest, CaseInsensitiveDomainTest) {
413 scoped_refptr<CookieStore> cs(this->GetCookieStore()); 415 scoped_refptr<CookieStore> cs(this->GetCookieStore());
414 GURL url("http://www.google.com"); 416 GURL url("http://www.google.com");
415 EXPECT_TRUE(this->SetCookie(cs, url, "a=1; domain=.GOOGLE.COM")); 417 EXPECT_TRUE(this->SetCookie(cs, url, "a=1; domain=.GOOGLE.COM"));
416 EXPECT_TRUE(this->SetCookie(cs, url, "b=2; domain=.wWw.gOOgLE.coM")); 418 EXPECT_TRUE(this->SetCookie(cs, url, "b=2; domain=.wWw.gOOgLE.coM"));
417 this->MatchCookieLines("a=1; b=2", this->GetCookies(cs, url)); 419 this->MatchCookieLines("a=1; b=2", this->GetCookies(cs, url));
418 } 420 }
419 421
420 TYPED_TEST_P(CookieStoreTest, TestIpAddress) { 422 TYPED_TEST_P(CookieStoreTest, TestIpAddress) {
421 GURL url_ip("http://1.2.3.4/weee"); 423 GURL url_ip("http://1.2.3.4/weee");
422 { 424 {
423 scoped_refptr<CookieStore> cs(this->GetCookieStore()); 425 scoped_refptr<CookieStore> cs(this->GetCookieStore());
424 EXPECT_TRUE(this->SetCookie(cs, url_ip, kValidCookieLine)); 426 EXPECT_TRUE(this->SetCookie(cs, url_ip, kValidCookieLine));
425 this->MatchCookieLines("A=B", this->GetCookies(cs, url_ip)); 427 this->MatchCookieLines("A=B", this->GetCookies(cs, url_ip));
426 } 428 }
427 429
428 { // IP addresses should not be able to set domain cookies. 430 { // IP addresses should not be able to set domain cookies.
429 scoped_refptr<CookieStore> cs(this->GetCookieStore()); 431 scoped_refptr<CookieStore> cs(this->GetCookieStore());
430 EXPECT_FALSE(this->SetCookie(cs, url_ip, "b=2; domain=.1.2.3.4")); 432 EXPECT_FALSE(this->SetCookie(cs, url_ip, "b=2; domain=.1.2.3.4"));
431 EXPECT_FALSE(this->SetCookie(cs, url_ip, "c=3; domain=.3.4")); 433 EXPECT_FALSE(this->SetCookie(cs, url_ip, "c=3; domain=.3.4"));
432 this->MatchCookieLines("", this->GetCookies(cs, url_ip)); 434 this->MatchCookieLines(std::string(), this->GetCookies(cs, url_ip));
433 // It should be allowed to set a cookie if domain= matches the IP address 435 // It should be allowed to set a cookie if domain= matches the IP address
434 // exactly. This matches IE/Firefox, even though it seems a bit wrong. 436 // exactly. This matches IE/Firefox, even though it seems a bit wrong.
435 EXPECT_FALSE(this->SetCookie(cs, url_ip, "b=2; domain=1.2.3.3")); 437 EXPECT_FALSE(this->SetCookie(cs, url_ip, "b=2; domain=1.2.3.3"));
436 this->MatchCookieLines("", this->GetCookies(cs, url_ip)); 438 this->MatchCookieLines(std::string(), this->GetCookies(cs, url_ip));
437 EXPECT_TRUE(this->SetCookie(cs, url_ip, "b=2; domain=1.2.3.4")); 439 EXPECT_TRUE(this->SetCookie(cs, url_ip, "b=2; domain=1.2.3.4"));
438 this->MatchCookieLines("b=2", this->GetCookies(cs, url_ip)); 440 this->MatchCookieLines("b=2", this->GetCookies(cs, url_ip));
439 } 441 }
440 } 442 }
441 443
442 // Test host cookies, and setting of cookies on TLD. 444 // Test host cookies, and setting of cookies on TLD.
443 TYPED_TEST_P(CookieStoreTest, TestNonDottedAndTLD) { 445 TYPED_TEST_P(CookieStoreTest, TestNonDottedAndTLD) {
444 { 446 {
445 scoped_refptr<CookieStore> cs(this->GetCookieStore()); 447 scoped_refptr<CookieStore> cs(this->GetCookieStore());
446 GURL url("http://com/"); 448 GURL url("http://com/");
447 // Allow setting on "com", (but only as a host cookie). 449 // Allow setting on "com", (but only as a host cookie).
448 EXPECT_TRUE(this->SetCookie(cs, url, "a=1")); 450 EXPECT_TRUE(this->SetCookie(cs, url, "a=1"));
449 EXPECT_FALSE(this->SetCookie(cs, url, "b=2; domain=.com")); 451 EXPECT_FALSE(this->SetCookie(cs, url, "b=2; domain=.com"));
450 EXPECT_FALSE(this->SetCookie(cs, url, "c=3; domain=com")); 452 EXPECT_FALSE(this->SetCookie(cs, url, "c=3; domain=com"));
451 this->MatchCookieLines("a=1", this->GetCookies(cs, url)); 453 this->MatchCookieLines("a=1", this->GetCookies(cs, url));
452 // Make sure it doesn't show up for a normal .com, it should be a host 454 // Make sure it doesn't show up for a normal .com, it should be a host
453 // not a domain cookie. 455 // not a domain cookie.
454 this->MatchCookieLines("", 456 this->MatchCookieLines(
457 std::string(),
455 this->GetCookies(cs, GURL("http://hopefully-no-cookies.com/"))); 458 this->GetCookies(cs, GURL("http://hopefully-no-cookies.com/")));
456 if (TypeParam::supports_non_dotted_domains) { 459 if (TypeParam::supports_non_dotted_domains) {
457 this->MatchCookieLines("", this->GetCookies(cs, GURL("http://.com/"))); 460 this->MatchCookieLines(std::string(),
461 this->GetCookies(cs, GURL("http://.com/")));
458 } 462 }
459 } 463 }
460 464
461 { 465 {
462 // http://com. should be treated the same as http://com. 466 // http://com. should be treated the same as http://com.
463 scoped_refptr<CookieStore> cs(this->GetCookieStore()); 467 scoped_refptr<CookieStore> cs(this->GetCookieStore());
464 GURL url("http://com./index.html"); 468 GURL url("http://com./index.html");
465 if (TypeParam::supports_trailing_dots) { 469 if (TypeParam::supports_trailing_dots) {
466 EXPECT_TRUE(this->SetCookie(cs, url, "a=1")); 470 EXPECT_TRUE(this->SetCookie(cs, url, "a=1"));
467 this->MatchCookieLines("a=1", this->GetCookies(cs, url)); 471 this->MatchCookieLines("a=1", this->GetCookies(cs, url));
468 this->MatchCookieLines("", 472 this->MatchCookieLines(
473 std::string(),
469 this->GetCookies(cs, GURL("http://hopefully-no-cookies.com./"))); 474 this->GetCookies(cs, GURL("http://hopefully-no-cookies.com./")));
470 } else { 475 } else {
471 EXPECT_FALSE(this->SetCookie(cs, url, "a=1")); 476 EXPECT_FALSE(this->SetCookie(cs, url, "a=1"));
472 } 477 }
473 } 478 }
474 479
475 { // Should not be able to set host cookie from a subdomain. 480 { // Should not be able to set host cookie from a subdomain.
476 scoped_refptr<CookieStore> cs(this->GetCookieStore()); 481 scoped_refptr<CookieStore> cs(this->GetCookieStore());
477 GURL url("http://a.b"); 482 GURL url("http://a.b");
478 EXPECT_FALSE(this->SetCookie(cs, url, "a=1; domain=.b")); 483 EXPECT_FALSE(this->SetCookie(cs, url, "a=1; domain=.b"));
479 EXPECT_FALSE(this->SetCookie(cs, url, "b=2; domain=b")); 484 EXPECT_FALSE(this->SetCookie(cs, url, "b=2; domain=b"));
480 this->MatchCookieLines("", this->GetCookies(cs, url)); 485 this->MatchCookieLines(std::string(), this->GetCookies(cs, url));
481 } 486 }
482 487
483 { // Same test as above, but explicitly on a known TLD (com). 488 { // Same test as above, but explicitly on a known TLD (com).
484 scoped_refptr<CookieStore> cs(this->GetCookieStore()); 489 scoped_refptr<CookieStore> cs(this->GetCookieStore());
485 GURL url("http://google.com"); 490 GURL url("http://google.com");
486 EXPECT_FALSE(this->SetCookie(cs, url, "a=1; domain=.com")); 491 EXPECT_FALSE(this->SetCookie(cs, url, "a=1; domain=.com"));
487 EXPECT_FALSE(this->SetCookie(cs, url, "b=2; domain=com")); 492 EXPECT_FALSE(this->SetCookie(cs, url, "b=2; domain=com"));
488 this->MatchCookieLines("", this->GetCookies(cs, url)); 493 this->MatchCookieLines(std::string(), this->GetCookies(cs, url));
489 } 494 }
490 495
491 { // Make sure can't set cookie on TLD which is dotted. 496 { // Make sure can't set cookie on TLD which is dotted.
492 scoped_refptr<CookieStore> cs(this->GetCookieStore()); 497 scoped_refptr<CookieStore> cs(this->GetCookieStore());
493 GURL url("http://google.co.uk"); 498 GURL url("http://google.co.uk");
494 EXPECT_FALSE(this->SetCookie(cs, url, "a=1; domain=.co.uk")); 499 EXPECT_FALSE(this->SetCookie(cs, url, "a=1; domain=.co.uk"));
495 EXPECT_FALSE(this->SetCookie(cs, url, "b=2; domain=.uk")); 500 EXPECT_FALSE(this->SetCookie(cs, url, "b=2; domain=.uk"));
496 this->MatchCookieLines("", this->GetCookies(cs, url)); 501 this->MatchCookieLines(std::string(), this->GetCookies(cs, url));
497 this->MatchCookieLines("", 502 this->MatchCookieLines(
503 std::string(),
498 this->GetCookies(cs, GURL("http://something-else.co.uk"))); 504 this->GetCookies(cs, GURL("http://something-else.co.uk")));
499 this->MatchCookieLines("", 505 this->MatchCookieLines(
500 this->GetCookies(cs, GURL("http://something-else.uk"))); 506 std::string(), this->GetCookies(cs, GURL("http://something-else.uk")));
501 } 507 }
502 508
503 { // Intranet URLs should only be able to set host cookies. 509 { // Intranet URLs should only be able to set host cookies.
504 scoped_refptr<CookieStore> cs(this->GetCookieStore()); 510 scoped_refptr<CookieStore> cs(this->GetCookieStore());
505 GURL url("http://b"); 511 GURL url("http://b");
506 EXPECT_TRUE(this->SetCookie(cs, url, "a=1")); 512 EXPECT_TRUE(this->SetCookie(cs, url, "a=1"));
507 EXPECT_FALSE(this->SetCookie(cs, url, "b=2; domain=.b")); 513 EXPECT_FALSE(this->SetCookie(cs, url, "b=2; domain=.b"));
508 EXPECT_FALSE(this->SetCookie(cs, url, "c=3; domain=b")); 514 EXPECT_FALSE(this->SetCookie(cs, url, "c=3; domain=b"));
509 this->MatchCookieLines("a=1", this->GetCookies(cs, url)); 515 this->MatchCookieLines("a=1", this->GetCookies(cs, url));
510 } 516 }
(...skipping 15 matching lines...) Expand all
526 this->MatchCookieLines("a=1", this->GetCookies(cs, url)); 532 this->MatchCookieLines("a=1", this->GetCookies(cs, url));
527 533
528 EXPECT_TRUE(this->SetCookie(cs, url_with_dot, "b=2; domain=.google.com.")); 534 EXPECT_TRUE(this->SetCookie(cs, url_with_dot, "b=2; domain=.google.com."));
529 this->MatchCookieLines("b=2", this->GetCookies(cs, url_with_dot)); 535 this->MatchCookieLines("b=2", this->GetCookies(cs, url_with_dot));
530 } else { 536 } else {
531 EXPECT_TRUE(this->SetCookie(cs, url, "b=2; domain=.www.google.com.")); 537 EXPECT_TRUE(this->SetCookie(cs, url, "b=2; domain=.www.google.com."));
532 EXPECT_FALSE(this->SetCookie(cs, url_with_dot, "b=2; domain=.google.com.")); 538 EXPECT_FALSE(this->SetCookie(cs, url_with_dot, "b=2; domain=.google.com."));
533 } 539 }
534 540
535 // Make sure there weren't any side effects. 541 // Make sure there weren't any side effects.
536 this->MatchCookieLines("", 542 this->MatchCookieLines(
543 std::string(),
537 this->GetCookies(cs, GURL("http://hopefully-no-cookies.com/"))); 544 this->GetCookies(cs, GURL("http://hopefully-no-cookies.com/")));
538 this->MatchCookieLines("", this->GetCookies(cs, GURL("http://.com/"))); 545 this->MatchCookieLines(std::string(),
546 this->GetCookies(cs, GURL("http://.com/")));
539 } 547 }
540 548
541 TYPED_TEST_P(CookieStoreTest, InvalidScheme) { 549 TYPED_TEST_P(CookieStoreTest, InvalidScheme) {
542 if (!TypeParam::filters_schemes) 550 if (!TypeParam::filters_schemes)
543 return; 551 return;
544 552
545 scoped_refptr<CookieStore> cs(this->GetCookieStore()); 553 scoped_refptr<CookieStore> cs(this->GetCookieStore());
546 EXPECT_FALSE(this->SetCookie(cs, GURL(kUrlFtp), kValidCookieLine)); 554 EXPECT_FALSE(this->SetCookie(cs, GURL(kUrlFtp), kValidCookieLine));
547 } 555 }
548 556
549 TYPED_TEST_P(CookieStoreTest, InvalidScheme_Read) { 557 TYPED_TEST_P(CookieStoreTest, InvalidScheme_Read) {
550 if (!TypeParam::filters_schemes) 558 if (!TypeParam::filters_schemes)
551 return; 559 return;
552 560
553 scoped_refptr<CookieStore> cs(this->GetCookieStore()); 561 scoped_refptr<CookieStore> cs(this->GetCookieStore());
554 EXPECT_TRUE(this->SetCookie(cs, GURL(kUrlGoogle), kValidDomainCookieLine)); 562 EXPECT_TRUE(this->SetCookie(cs, GURL(kUrlGoogle), kValidDomainCookieLine));
555 this->MatchCookieLines("", this->GetCookies(cs, GURL(kUrlFtp))); 563 this->MatchCookieLines(std::string(), this->GetCookies(cs, GURL(kUrlFtp)));
556 } 564 }
557 565
558 TYPED_TEST_P(CookieStoreTest, PathTest) { 566 TYPED_TEST_P(CookieStoreTest, PathTest) {
559 scoped_refptr<CookieStore> cs(this->GetCookieStore()); 567 scoped_refptr<CookieStore> cs(this->GetCookieStore());
560 std::string url("http://www.google.izzle"); 568 std::string url("http://www.google.izzle");
561 EXPECT_TRUE(this->SetCookie(cs, GURL(url), "A=B; path=/wee")); 569 EXPECT_TRUE(this->SetCookie(cs, GURL(url), "A=B; path=/wee"));
562 this->MatchCookieLines("A=B", this->GetCookies(cs, GURL(url + "/wee"))); 570 this->MatchCookieLines("A=B", this->GetCookies(cs, GURL(url + "/wee")));
563 this->MatchCookieLines("A=B", this->GetCookies(cs, GURL(url + "/wee/"))); 571 this->MatchCookieLines("A=B", this->GetCookies(cs, GURL(url + "/wee/")));
564 this->MatchCookieLines("A=B", this->GetCookies(cs, GURL(url + "/wee/war"))); 572 this->MatchCookieLines("A=B", this->GetCookies(cs, GURL(url + "/wee/war")));
565 this->MatchCookieLines("A=B", 573 this->MatchCookieLines("A=B",
566 this->GetCookies(cs, GURL(url + "/wee/war/more/more"))); 574 this->GetCookies(cs, GURL(url + "/wee/war/more/more")));
567 if (!TypeParam::has_path_prefix_bug) 575 if (!TypeParam::has_path_prefix_bug)
568 this->MatchCookieLines("", this->GetCookies(cs, GURL(url + "/weehee"))); 576 this->MatchCookieLines(std::string(),
569 this->MatchCookieLines("", this->GetCookies(cs, GURL(url + "/"))); 577 this->GetCookies(cs, GURL(url + "/weehee")));
578 this->MatchCookieLines(std::string(), this->GetCookies(cs, GURL(url + "/")));
570 579
571 // If we add a 0 length path, it should default to / 580 // If we add a 0 length path, it should default to /
572 EXPECT_TRUE(this->SetCookie(cs, GURL(url), "A=C; path=")); 581 EXPECT_TRUE(this->SetCookie(cs, GURL(url), "A=C; path="));
573 this->MatchCookieLines("A=B; A=C", this->GetCookies(cs, GURL(url + "/wee"))); 582 this->MatchCookieLines("A=B; A=C", this->GetCookies(cs, GURL(url + "/wee")));
574 this->MatchCookieLines("A=C", this->GetCookies(cs, GURL(url + "/"))); 583 this->MatchCookieLines("A=C", this->GetCookies(cs, GURL(url + "/")));
575 } 584 }
576 585
577 TYPED_TEST_P(CookieStoreTest, EmptyExpires) { 586 TYPED_TEST_P(CookieStoreTest, EmptyExpires) {
578 scoped_refptr<CookieStore> cs(this->GetCookieStore()); 587 scoped_refptr<CookieStore> cs(this->GetCookieStore());
579 CookieOptions options; 588 CookieOptions options;
(...skipping 25 matching lines...) Expand all
605 614
606 scoped_refptr<CookieStore> cs(this->GetCookieStore()); 615 scoped_refptr<CookieStore> cs(this->GetCookieStore());
607 CookieOptions options; 616 CookieOptions options;
608 options.set_include_httponly(); 617 options.set_include_httponly();
609 618
610 // Create a httponly cookie. 619 // Create a httponly cookie.
611 EXPECT_TRUE(this->SetCookieWithOptions(cs, this->url_google_, "A=B; httponly", 620 EXPECT_TRUE(this->SetCookieWithOptions(cs, this->url_google_, "A=B; httponly",
612 options)); 621 options));
613 622
614 // Check httponly read protection. 623 // Check httponly read protection.
615 this->MatchCookieLines("", this->GetCookies(cs, this->url_google_)); 624 this->MatchCookieLines(std::string(),
616 this->MatchCookieLines("A=B", 625 this->GetCookies(cs, this->url_google_));
617 this->GetCookiesWithOptions(cs, this->url_google_, options)); 626 this->MatchCookieLines(
627 "A=B", this->GetCookiesWithOptions(cs, this->url_google_, options));
618 628
619 // Check httponly overwrite protection. 629 // Check httponly overwrite protection.
620 EXPECT_FALSE(this->SetCookie(cs, this->url_google_, "A=C")); 630 EXPECT_FALSE(this->SetCookie(cs, this->url_google_, "A=C"));
621 this->MatchCookieLines("", this->GetCookies(cs, this->url_google_)); 631 this->MatchCookieLines(std::string(),
622 this->MatchCookieLines("A=B", 632 this->GetCookies(cs, this->url_google_));
623 this->GetCookiesWithOptions(cs, this->url_google_, options)); 633 this->MatchCookieLines(
634 "A=B", this->GetCookiesWithOptions(cs, this->url_google_, options));
624 EXPECT_TRUE(this->SetCookieWithOptions(cs, this->url_google_, "A=C", 635 EXPECT_TRUE(this->SetCookieWithOptions(cs, this->url_google_, "A=C",
625 options)); 636 options));
626 this->MatchCookieLines("A=C", this->GetCookies(cs, this->url_google_)); 637 this->MatchCookieLines("A=C", this->GetCookies(cs, this->url_google_));
627 638
628 // Check httponly create protection. 639 // Check httponly create protection.
629 EXPECT_FALSE(this->SetCookie(cs, this->url_google_, "B=A; httponly")); 640 EXPECT_FALSE(this->SetCookie(cs, this->url_google_, "B=A; httponly"));
630 this->MatchCookieLines("A=C", 641 this->MatchCookieLines("A=C",
631 this->GetCookiesWithOptions(cs, this->url_google_, options)); 642 this->GetCookiesWithOptions(cs, this->url_google_, options));
632 EXPECT_TRUE(this->SetCookieWithOptions(cs, this->url_google_, "B=A; httponly", 643 EXPECT_TRUE(this->SetCookieWithOptions(cs, this->url_google_, "B=A; httponly",
633 options)); 644 options));
634 this->MatchCookieLines("A=C; B=A", 645 this->MatchCookieLines("A=C; B=A",
635 this->GetCookiesWithOptions(cs, this->url_google_, options)); 646 this->GetCookiesWithOptions(cs, this->url_google_, options));
636 this->MatchCookieLines("A=C", this->GetCookies(cs, this->url_google_)); 647 this->MatchCookieLines("A=C", this->GetCookies(cs, this->url_google_));
637 } 648 }
638 649
639 TYPED_TEST_P(CookieStoreTest, TestCookieDeletion) { 650 TYPED_TEST_P(CookieStoreTest, TestCookieDeletion) {
640 scoped_refptr<CookieStore> cs(this->GetCookieStore()); 651 scoped_refptr<CookieStore> cs(this->GetCookieStore());
641 652
642 // Create a session cookie. 653 // Create a session cookie.
643 EXPECT_TRUE(this->SetCookie(cs, this->url_google_, kValidCookieLine)); 654 EXPECT_TRUE(this->SetCookie(cs, this->url_google_, kValidCookieLine));
644 this->MatchCookieLines("A=B", this->GetCookies(cs, this->url_google_)); 655 this->MatchCookieLines("A=B", this->GetCookies(cs, this->url_google_));
645 // Delete it via Max-Age. 656 // Delete it via Max-Age.
646 EXPECT_TRUE(this->SetCookie(cs, this->url_google_, 657 EXPECT_TRUE(this->SetCookie(cs, this->url_google_,
647 std::string(kValidCookieLine) + "; max-age=0")); 658 std::string(kValidCookieLine) + "; max-age=0"));
648 this->MatchCookieLineWithTimeout(cs, this->url_google_, ""); 659 this->MatchCookieLineWithTimeout(cs, this->url_google_, std::string());
649 660
650 // Create a session cookie. 661 // Create a session cookie.
651 EXPECT_TRUE(this->SetCookie(cs, this->url_google_, kValidCookieLine)); 662 EXPECT_TRUE(this->SetCookie(cs, this->url_google_, kValidCookieLine));
652 this->MatchCookieLines("A=B", this->GetCookies(cs, this->url_google_)); 663 this->MatchCookieLines("A=B", this->GetCookies(cs, this->url_google_));
653 // Delete it via Expires. 664 // Delete it via Expires.
654 EXPECT_TRUE(this->SetCookie(cs, this->url_google_, 665 EXPECT_TRUE(this->SetCookie(cs, this->url_google_,
655 std::string(kValidCookieLine) + 666 std::string(kValidCookieLine) +
656 "; expires=Mon, 18-Apr-1977 22:50:13 GMT")); 667 "; expires=Mon, 18-Apr-1977 22:50:13 GMT"));
657 this->MatchCookieLines("", this->GetCookies(cs, this->url_google_)); 668 this->MatchCookieLines(std::string(),
669 this->GetCookies(cs, this->url_google_));
658 670
659 // Create a persistent cookie. 671 // Create a persistent cookie.
660 EXPECT_TRUE(this->SetCookie(cs, this->url_google_, 672 EXPECT_TRUE(this->SetCookie(cs, this->url_google_,
661 std::string(kValidCookieLine) + 673 std::string(kValidCookieLine) +
662 "; expires=Mon, 18-Apr-22 22:50:13 GMT")); 674 "; expires=Mon, 18-Apr-22 22:50:13 GMT"));
663 675
664 this->MatchCookieLines("A=B", this->GetCookies(cs, this->url_google_)); 676 this->MatchCookieLines("A=B", this->GetCookies(cs, this->url_google_));
665 // Delete it via Max-Age. 677 // Delete it via Max-Age.
666 EXPECT_TRUE(this->SetCookie(cs, this->url_google_, 678 EXPECT_TRUE(this->SetCookie(cs, this->url_google_,
667 std::string(kValidCookieLine) + "; max-age=0")); 679 std::string(kValidCookieLine) + "; max-age=0"));
668 this->MatchCookieLineWithTimeout(cs, this->url_google_, ""); 680 this->MatchCookieLineWithTimeout(cs, this->url_google_, std::string());
669 681
670 // Create a persistent cookie. 682 // Create a persistent cookie.
671 EXPECT_TRUE(this->SetCookie(cs, this->url_google_, 683 EXPECT_TRUE(this->SetCookie(cs, this->url_google_,
672 std::string(kValidCookieLine) + 684 std::string(kValidCookieLine) +
673 "; expires=Mon, 18-Apr-22 22:50:13 GMT")); 685 "; expires=Mon, 18-Apr-22 22:50:13 GMT"));
674 this->MatchCookieLines("A=B", this->GetCookies(cs, this->url_google_)); 686 this->MatchCookieLines("A=B", this->GetCookies(cs, this->url_google_));
675 // Delete it via Expires. 687 // Delete it via Expires.
676 EXPECT_TRUE(this->SetCookie(cs, this->url_google_, 688 EXPECT_TRUE(this->SetCookie(cs, this->url_google_,
677 std::string(kValidCookieLine) + 689 std::string(kValidCookieLine) +
678 "; expires=Mon, 18-Apr-1977 22:50:13 GMT")); 690 "; expires=Mon, 18-Apr-1977 22:50:13 GMT"));
679 this->MatchCookieLines("", this->GetCookies(cs, this->url_google_)); 691 this->MatchCookieLines(std::string(),
692 this->GetCookies(cs, this->url_google_));
680 693
681 // Create a persistent cookie. 694 // Create a persistent cookie.
682 EXPECT_TRUE(this->SetCookie(cs, this->url_google_, 695 EXPECT_TRUE(this->SetCookie(cs, this->url_google_,
683 std::string(kValidCookieLine) + 696 std::string(kValidCookieLine) +
684 "; expires=Mon, 18-Apr-22 22:50:13 GMT")); 697 "; expires=Mon, 18-Apr-22 22:50:13 GMT"));
685 this->MatchCookieLines("A=B", this->GetCookies(cs, this->url_google_)); 698 this->MatchCookieLines("A=B", this->GetCookies(cs, this->url_google_));
686 // Check that it is not deleted with significant enough clock skew. 699 // Check that it is not deleted with significant enough clock skew.
687 base::Time server_time; 700 base::Time server_time;
688 EXPECT_TRUE(base::Time::FromString("Sun, 17-Apr-1977 22:50:13 GMT", 701 EXPECT_TRUE(base::Time::FromString("Sun, 17-Apr-1977 22:50:13 GMT",
689 &server_time)); 702 &server_time));
690 EXPECT_TRUE(this->SetCookieWithServerTime( 703 EXPECT_TRUE(this->SetCookieWithServerTime(
691 cs, this->url_google_, 704 cs, this->url_google_,
692 std::string(kValidCookieLine) + 705 std::string(kValidCookieLine) +
693 "; expires=Mon, 18-Apr-1977 22:50:13 GMT", 706 "; expires=Mon, 18-Apr-1977 22:50:13 GMT",
694 server_time)); 707 server_time));
695 this->MatchCookieLines("A=B", this->GetCookies(cs, this->url_google_)); 708 this->MatchCookieLines("A=B", this->GetCookies(cs, this->url_google_));
696 709
697 // Create a persistent cookie. 710 // Create a persistent cookie.
698 EXPECT_TRUE(this->SetCookie(cs, this->url_google_, 711 EXPECT_TRUE(this->SetCookie(cs, this->url_google_,
699 std::string(kValidCookieLine) + 712 std::string(kValidCookieLine) +
700 "; expires=Mon, 18-Apr-22 22:50:13 GMT")); 713 "; expires=Mon, 18-Apr-22 22:50:13 GMT"));
701 this->MatchCookieLines("A=B", this->GetCookies(cs, this->url_google_)); 714 this->MatchCookieLines("A=B", this->GetCookies(cs, this->url_google_));
702 // Delete it via Expires, with a unix epoch of 0. 715 // Delete it via Expires, with a unix epoch of 0.
703 EXPECT_TRUE(this->SetCookie(cs, this->url_google_, 716 EXPECT_TRUE(this->SetCookie(cs, this->url_google_,
704 std::string(kValidCookieLine) + 717 std::string(kValidCookieLine) +
705 "; expires=Thu, 1-Jan-1970 00:00:00 GMT")); 718 "; expires=Thu, 1-Jan-1970 00:00:00 GMT"));
706 this->MatchCookieLines("", this->GetCookies(cs, this->url_google_)); 719 this->MatchCookieLines(std::string(),
720 this->GetCookies(cs, this->url_google_));
707 } 721 }
708 722
709 TYPED_TEST_P(CookieStoreTest, TestDeleteAllCreatedBetween) { 723 TYPED_TEST_P(CookieStoreTest, TestDeleteAllCreatedBetween) {
710 scoped_refptr<CookieStore> cs(this->GetCookieStore()); 724 scoped_refptr<CookieStore> cs(this->GetCookieStore());
711 const base::Time last_month = base::Time::Now() - 725 const base::Time last_month = base::Time::Now() -
712 base::TimeDelta::FromDays(30); 726 base::TimeDelta::FromDays(30);
713 const base::Time last_minute = base::Time::Now() - 727 const base::Time last_minute = base::Time::Now() -
714 base::TimeDelta::FromMinutes(1); 728 base::TimeDelta::FromMinutes(1);
715 const base::Time next_minute = base::Time::Now() + 729 const base::Time next_minute = base::Time::Now() +
716 base::TimeDelta::FromMinutes(1); 730 base::TimeDelta::FromMinutes(1);
717 const base::Time next_month = base::Time::Now() + 731 const base::Time next_month = base::Time::Now() +
718 base::TimeDelta::FromDays(30); 732 base::TimeDelta::FromDays(30);
719 733
720 // Add a cookie. 734 // Add a cookie.
721 EXPECT_TRUE(this->SetCookie(cs, this->url_google_, "A=B")); 735 EXPECT_TRUE(this->SetCookie(cs, this->url_google_, "A=B"));
722 // Check that the cookie is in the store. 736 // Check that the cookie is in the store.
723 this->MatchCookieLines("A=B", this->GetCookies(cs, this->url_google_)); 737 this->MatchCookieLines("A=B", this->GetCookies(cs, this->url_google_));
724 738
725 // Remove cookies in empty intervals. 739 // Remove cookies in empty intervals.
726 EXPECT_EQ(0, this->DeleteCreatedBetween(cs, last_month, last_minute)); 740 EXPECT_EQ(0, this->DeleteCreatedBetween(cs, last_month, last_minute));
727 EXPECT_EQ(0, this->DeleteCreatedBetween(cs, next_minute, next_month)); 741 EXPECT_EQ(0, this->DeleteCreatedBetween(cs, next_minute, next_month));
728 // Check that the cookie is still there. 742 // Check that the cookie is still there.
729 this->MatchCookieLines("A=B", this->GetCookies(cs, this->url_google_)); 743 this->MatchCookieLines("A=B", this->GetCookies(cs, this->url_google_));
730 744
731 // Remove the cookie with an interval defined by two dates. 745 // Remove the cookie with an interval defined by two dates.
732 EXPECT_EQ(1, this->DeleteCreatedBetween(cs, last_minute, next_minute)); 746 EXPECT_EQ(1, this->DeleteCreatedBetween(cs, last_minute, next_minute));
733 // Check that the cookie disappeared. 747 // Check that the cookie disappeared.
734 this->MatchCookieLines("", this->GetCookies(cs, this->url_google_)); 748 this->MatchCookieLines(std::string(),
749 this->GetCookies(cs, this->url_google_));
735 750
736 // Add another cookie. 751 // Add another cookie.
737 EXPECT_TRUE(this->SetCookie(cs, this->url_google_, "C=D")); 752 EXPECT_TRUE(this->SetCookie(cs, this->url_google_, "C=D"));
738 // Check that the cookie is in the store. 753 // Check that the cookie is in the store.
739 this->MatchCookieLines("C=D", this->GetCookies(cs, this->url_google_)); 754 this->MatchCookieLines("C=D", this->GetCookies(cs, this->url_google_));
740 755
741 // Remove the cookie with a null ending time. 756 // Remove the cookie with a null ending time.
742 EXPECT_EQ(1, this->DeleteCreatedBetween(cs, last_minute, base::Time())); 757 EXPECT_EQ(1, this->DeleteCreatedBetween(cs, last_minute, base::Time()));
743 // Check that the cookie disappeared. 758 // Check that the cookie disappeared.
744 this->MatchCookieLines("", this->GetCookies(cs, this->url_google_)); 759 this->MatchCookieLines(std::string(),
760 this->GetCookies(cs, this->url_google_));
745 } 761 }
746 762
747 TYPED_TEST_P(CookieStoreTest, TestSecure) { 763 TYPED_TEST_P(CookieStoreTest, TestSecure) {
748 scoped_refptr<CookieStore> cs(this->GetCookieStore()); 764 scoped_refptr<CookieStore> cs(this->GetCookieStore());
749 765
750 EXPECT_TRUE(this->SetCookie(cs, this->url_google_, "A=B")); 766 EXPECT_TRUE(this->SetCookie(cs, this->url_google_, "A=B"));
751 this->MatchCookieLines("A=B", this->GetCookies(cs, this->url_google_)); 767 this->MatchCookieLines("A=B", this->GetCookies(cs, this->url_google_));
752 this->MatchCookieLines("A=B", this->GetCookies(cs, this->url_google_secure_)); 768 this->MatchCookieLines("A=B", this->GetCookies(cs, this->url_google_secure_));
753 769
754 EXPECT_TRUE(this->SetCookie(cs, this->url_google_secure_, "A=B; secure")); 770 EXPECT_TRUE(this->SetCookie(cs, this->url_google_secure_, "A=B; secure"));
755 // The secure should overwrite the non-secure. 771 // The secure should overwrite the non-secure.
756 this->MatchCookieLines("", this->GetCookies(cs, this->url_google_)); 772 this->MatchCookieLines(std::string(),
773 this->GetCookies(cs, this->url_google_));
757 this->MatchCookieLines("A=B", this->GetCookies(cs, this->url_google_secure_)); 774 this->MatchCookieLines("A=B", this->GetCookies(cs, this->url_google_secure_));
758 775
759 EXPECT_TRUE(this->SetCookie(cs, this->url_google_secure_, "D=E; secure")); 776 EXPECT_TRUE(this->SetCookie(cs, this->url_google_secure_, "D=E; secure"));
760 this->MatchCookieLines("", this->GetCookies(cs, this->url_google_)); 777 this->MatchCookieLines(std::string(),
778 this->GetCookies(cs, this->url_google_));
761 this->MatchCookieLines("A=B; D=E", 779 this->MatchCookieLines("A=B; D=E",
762 this->GetCookies(cs, this->url_google_secure_)); 780 this->GetCookies(cs, this->url_google_secure_));
763 781
764 EXPECT_TRUE(this->SetCookie(cs, this->url_google_secure_, "A=B")); 782 EXPECT_TRUE(this->SetCookie(cs, this->url_google_secure_, "A=B"));
765 // The non-secure should overwrite the secure. 783 // The non-secure should overwrite the secure.
766 this->MatchCookieLines("A=B", this->GetCookies(cs, this->url_google_)); 784 this->MatchCookieLines("A=B", this->GetCookies(cs, this->url_google_));
767 this->MatchCookieLines("D=E; A=B", 785 this->MatchCookieLines("D=E; A=B",
768 this->GetCookies(cs, this->url_google_secure_)); 786 this->GetCookies(cs, this->url_google_secure_));
769 } 787 }
770 788
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
1059 REGISTER_TYPED_TEST_CASE_P(MultiThreadedCookieStoreTest, 1077 REGISTER_TYPED_TEST_CASE_P(MultiThreadedCookieStoreTest,
1060 ThreadCheckGetCookies, 1078 ThreadCheckGetCookies,
1061 ThreadCheckGetCookiesWithOptions, 1079 ThreadCheckGetCookiesWithOptions,
1062 ThreadCheckSetCookieWithOptions, 1080 ThreadCheckSetCookieWithOptions,
1063 ThreadCheckDeleteCookie, 1081 ThreadCheckDeleteCookie,
1064 ThreadCheckDeleteSessionCookies); 1082 ThreadCheckDeleteSessionCookies);
1065 1083
1066 } // namespace net 1084 } // namespace net
1067 1085
1068 #endif // NET_COOKIES_COOKIE_STORE_UNITTEST_H_ 1086 #endif // NET_COOKIES_COOKIE_STORE_UNITTEST_H_
OLDNEW
« no previous file with comments | « net/cookies/cookie_store_test_helpers.cc ('k') | net/cookies/parsed_cookie.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698