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

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

Issue 2930893002: Change all "google.com" references in net/cookies to "foo.com" to avoid repeatedly tripping ov… (Closed)
Patch Set: Final pass through to pick up some missed google references. Created 3 years, 6 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/cookie_monster_unittest.cc ('k') | net/cookies/cookie_util_unittest.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 <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 // 64 //
65 // // Time to wait between two cookie insertions to ensure that cookies have 65 // // Time to wait between two cookie insertions to ensure that cookies have
66 // // different creation times. 66 // // different creation times.
67 // static const int creation_time_granularity_in_ms; 67 // static const int creation_time_granularity_in_ms;
68 // }; 68 // };
69 69
70 template <class CookieStoreTestTraits> 70 template <class CookieStoreTestTraits>
71 class CookieStoreTest : public testing::Test { 71 class CookieStoreTest : public testing::Test {
72 protected: 72 protected:
73 CookieStoreTest() 73 CookieStoreTest()
74 : http_www_google_("http://www.google.izzle"), 74 : http_www_foo_("http://www.foo.com"),
75 https_www_google_("https://www.google.izzle"), 75 https_www_foo_("https://www.foo.com"),
76 ftp_google_("ftp://ftp.google.izzle/"), 76 ftp_foo_("ftp://ftp.foo.com/"),
77 ws_www_google_("ws://www.google.izzle"), 77 ws_www_foo_("ws://www.foo.com"),
78 wss_www_google_("wss://www.google.izzle"), 78 wss_www_foo_("wss://www.foo.com"),
79 www_google_foo_("http://www.google.izzle/foo"), 79 www_foo_foo_("http://www.foo.com/foo"),
80 www_google_bar_("http://www.google.izzle/bar"), 80 www_foo_bar_("http://www.foo.com/bar"),
81 http_foo_com_("http://foo.com"), 81 http_baz_com_("http://baz.com"),
82 http_bar_com_("http://bar.com") { 82 http_bar_com_("http://bar.com") {
83 // This test may be used outside of the net test suite, and thus may not 83 // This test may be used outside of the net test suite, and thus may not
84 // have a message loop. 84 // have a message loop.
85 if (!base::MessageLoop::current()) 85 if (!base::MessageLoop::current())
86 message_loop_.reset(new base::MessageLoop); 86 message_loop_.reset(new base::MessageLoop);
87 weak_factory_.reset(new base::WeakPtrFactory<base::MessageLoop>( 87 weak_factory_.reset(new base::WeakPtrFactory<base::MessageLoop>(
88 base::MessageLoop::current())); 88 base::MessageLoop::current()));
89 } 89 }
90 90
91 // Helper methods for the asynchronous Cookie Store API that call the 91 // Helper methods for the asynchronous Cookie Store API that call the
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 while (!matched && base::Time::Now() <= polling_end_date) { 296 while (!matched && base::Time::Now() <= polling_end_date) {
297 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(10)); 297 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(10));
298 cookies = GetCookies(cs, url); 298 cookies = GetCookies(cs, url);
299 matched = (TokenizeCookieLine(line) == TokenizeCookieLine(cookies)); 299 matched = (TokenizeCookieLine(line) == TokenizeCookieLine(cookies));
300 } 300 }
301 301
302 EXPECT_TRUE(matched) << "\"" << cookies 302 EXPECT_TRUE(matched) << "\"" << cookies
303 << "\" does not match \"" << line << "\""; 303 << "\" does not match \"" << line << "\"";
304 } 304 }
305 305
306 const CookieURLHelper http_www_google_; 306 const CookieURLHelper http_www_foo_;
307 const CookieURLHelper https_www_google_; 307 const CookieURLHelper https_www_foo_;
308 const CookieURLHelper ftp_google_; 308 const CookieURLHelper ftp_foo_;
309 const CookieURLHelper ws_www_google_; 309 const CookieURLHelper ws_www_foo_;
310 const CookieURLHelper wss_www_google_; 310 const CookieURLHelper wss_www_foo_;
311 const CookieURLHelper www_google_foo_; 311 const CookieURLHelper www_foo_foo_;
312 const CookieURLHelper www_google_bar_; 312 const CookieURLHelper www_foo_bar_;
313 const CookieURLHelper http_foo_com_; 313 const CookieURLHelper http_baz_com_;
314 const CookieURLHelper http_bar_com_; 314 const CookieURLHelper http_bar_com_;
315 315
316 std::unique_ptr<base::WeakPtrFactory<base::MessageLoop>> weak_factory_; 316 std::unique_ptr<base::WeakPtrFactory<base::MessageLoop>> weak_factory_;
317 std::unique_ptr<base::MessageLoop> message_loop_; 317 std::unique_ptr<base::MessageLoop> message_loop_;
318 318
319 private: 319 private:
320 // Returns a set of strings of type "name=value". Fails in case of duplicate. 320 // Returns a set of strings of type "name=value". Fails in case of duplicate.
321 std::set<std::string> TokenizeCookieLine(const std::string& line) { 321 std::set<std::string> TokenizeCookieLine(const std::string& line) {
322 std::set<std::string> tokens; 322 std::set<std::string> tokens;
323 base::StringTokenizer tokenizer(line, " ;"); 323 base::StringTokenizer tokenizer(line, " ;");
324 while (tokenizer.GetNext()) 324 while (tokenizer.GetNext())
325 EXPECT_TRUE(tokens.insert(tokenizer.token()).second); 325 EXPECT_TRUE(tokens.insert(tokenizer.token()).second);
326 return tokens; 326 return tokens;
327 } 327 }
328 328
329 std::unique_ptr<CookieStore> cookie_store_; 329 std::unique_ptr<CookieStore> cookie_store_;
330 }; 330 };
331 331
332 TYPED_TEST_CASE_P(CookieStoreTest); 332 TYPED_TEST_CASE_P(CookieStoreTest);
333 333
334 TYPED_TEST_P(CookieStoreTest, SetCookieWithDetailsAsync) { 334 TYPED_TEST_P(CookieStoreTest, SetCookieWithDetailsAsync) {
335 CookieStore* cs = this->GetCookieStore(); 335 CookieStore* cs = this->GetCookieStore();
336 336
337 base::Time two_hours_ago = base::Time::Now() - base::TimeDelta::FromHours(2); 337 base::Time two_hours_ago = base::Time::Now() - base::TimeDelta::FromHours(2);
338 base::Time one_hour_ago = base::Time::Now() - base::TimeDelta::FromHours(1); 338 base::Time one_hour_ago = base::Time::Now() - base::TimeDelta::FromHours(1);
339 base::Time one_hour_from_now = 339 base::Time one_hour_from_now =
340 base::Time::Now() + base::TimeDelta::FromHours(1); 340 base::Time::Now() + base::TimeDelta::FromHours(1);
341 341
342 EXPECT_TRUE(this->SetCookieWithDetails( 342 EXPECT_TRUE(this->SetCookieWithDetails(
343 cs, this->www_google_foo_.url(), "A", "B", std::string(), "/foo", 343 cs, this->www_foo_foo_.url(), "A", "B", std::string(), "/foo",
344 one_hour_ago, one_hour_from_now, base::Time(), false, false, 344 one_hour_ago, one_hour_from_now, base::Time(), false, false,
345 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT)); 345 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT));
346 // Note that for the creation time to be set exactly, without modification, 346 // Note that for the creation time to be set exactly, without modification,
347 // it must be different from the one set by the line above. 347 // it must be different from the one set by the line above.
348 EXPECT_TRUE(this->SetCookieWithDetails( 348 EXPECT_TRUE(this->SetCookieWithDetails(
349 cs, this->www_google_bar_.url(), "C", "D", this->www_google_bar_.domain(), 349 cs, this->www_foo_bar_.url(), "C", "D", this->www_foo_bar_.domain(),
350 "/bar", two_hours_ago, base::Time(), one_hour_ago, false, true, 350 "/bar", two_hours_ago, base::Time(), one_hour_ago, false, true,
351 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT)); 351 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT));
352 // Because of strict secure cookies, a cookie made by an HTTP URL should fail 352 // Because of strict secure cookies, a cookie made by an HTTP URL should fail
353 // to create a cookie with a the secure attribute. 353 // to create a cookie with a the secure attribute.
354 EXPECT_FALSE(this->SetCookieWithDetails( 354 EXPECT_FALSE(this->SetCookieWithDetails(
355 cs, this->http_www_google_.url(), "E", "F", std::string(), std::string(), 355 cs, this->http_www_foo_.url(), "E", "F", std::string(), std::string(),
356 base::Time(), base::Time(), base::Time(), true, false, 356 base::Time(), base::Time(), base::Time(), true, false,
357 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT)); 357 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT));
358 EXPECT_TRUE(this->SetCookieWithDetails( 358 EXPECT_TRUE(this->SetCookieWithDetails(
359 cs, this->https_www_google_.url(), "E", "F", std::string(), std::string(), 359 cs, this->https_www_foo_.url(), "E", "F", std::string(), std::string(),
360 base::Time(), base::Time(), base::Time(), true, false, 360 base::Time(), base::Time(), base::Time(), true, false,
361 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT)); 361 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT));
362 362
363 // Test that malformed attributes fail to set the cookie. 363 // Test that malformed attributes fail to set the cookie.
364 EXPECT_FALSE(this->SetCookieWithDetails( 364 EXPECT_FALSE(this->SetCookieWithDetails(
365 cs, this->www_google_foo_.url(), " A", "B", std::string(), "/foo", 365 cs, this->www_foo_foo_.url(), " A", "B", std::string(), "/foo",
366 base::Time(), base::Time(), base::Time(), false, false, 366 base::Time(), base::Time(), base::Time(), false, false,
367 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT)); 367 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT));
368 EXPECT_FALSE(this->SetCookieWithDetails( 368 EXPECT_FALSE(this->SetCookieWithDetails(
369 cs, this->www_google_foo_.url(), "A;", "B", std::string(), "/foo", 369 cs, this->www_foo_foo_.url(), "A;", "B", std::string(), "/foo",
370 base::Time(), base::Time(), base::Time(), false, false, 370 base::Time(), base::Time(), base::Time(), false, false,
371 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT)); 371 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT));
372 EXPECT_FALSE(this->SetCookieWithDetails( 372 EXPECT_FALSE(this->SetCookieWithDetails(
373 cs, this->www_google_foo_.url(), "A=", "B", std::string(), "/foo", 373 cs, this->www_foo_foo_.url(), "A=", "B", std::string(), "/foo",
374 base::Time(), base::Time(), base::Time(), false, false, 374 base::Time(), base::Time(), base::Time(), false, false,
375 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT)); 375 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT));
376 EXPECT_FALSE(this->SetCookieWithDetails( 376 EXPECT_FALSE(this->SetCookieWithDetails(
377 cs, this->www_google_foo_.url(), "A", "B", "google.ozzzzzzle", "foo", 377 cs, this->www_foo_foo_.url(), "A", "B", "foo.ozzzzzzle", "foo",
378 base::Time(), base::Time(), base::Time(), false, false, 378 base::Time(), base::Time(), base::Time(), false, false,
379 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT)); 379 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT));
380 EXPECT_FALSE(this->SetCookieWithDetails( 380 EXPECT_FALSE(this->SetCookieWithDetails(
381 cs, this->www_google_foo_.url(), "A=", "B", std::string(), "foo", 381 cs, this->www_foo_foo_.url(), "A=", "B", std::string(), "foo",
382 base::Time(), base::Time(), base::Time(), false, false, 382 base::Time(), base::Time(), base::Time(), false, false,
383 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT)); 383 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT));
384 384
385 // Get all the cookies for a given URL, regardless of properties. This 'get()' 385 // Get all the cookies for a given URL, regardless of properties. This 'get()'
386 // operation shouldn't update the access time, as the test checks that the 386 // operation shouldn't update the access time, as the test checks that the
387 // access time is set properly upon creation. Updating the access time would 387 // access time is set properly upon creation. Updating the access time would
388 // make that difficult. 388 // make that difficult.
389 CookieOptions options; 389 CookieOptions options;
390 options.set_include_httponly(); 390 options.set_include_httponly();
391 options.set_same_site_cookie_mode( 391 options.set_same_site_cookie_mode(
392 CookieOptions::SameSiteCookieMode::INCLUDE_STRICT_AND_LAX); 392 CookieOptions::SameSiteCookieMode::INCLUDE_STRICT_AND_LAX);
393 options.set_do_not_update_access_time(); 393 options.set_do_not_update_access_time();
394 394
395 CookieList cookies = 395 CookieList cookies =
396 this->GetCookieListWithOptions(cs, this->www_google_foo_.url(), options); 396 this->GetCookieListWithOptions(cs, this->www_foo_foo_.url(), options);
397 CookieList::iterator it = cookies.begin(); 397 CookieList::iterator it = cookies.begin();
398 398
399 ASSERT_TRUE(it != cookies.end()); 399 ASSERT_TRUE(it != cookies.end());
400 EXPECT_EQ("A", it->Name()); 400 EXPECT_EQ("A", it->Name());
401 EXPECT_EQ("B", it->Value()); 401 EXPECT_EQ("B", it->Value());
402 EXPECT_EQ(this->www_google_foo_.host(), it->Domain()); 402 EXPECT_EQ(this->www_foo_foo_.host(), it->Domain());
403 EXPECT_EQ("/foo", it->Path()); 403 EXPECT_EQ("/foo", it->Path());
404 EXPECT_EQ(one_hour_ago, it->CreationDate()); 404 EXPECT_EQ(one_hour_ago, it->CreationDate());
405 EXPECT_TRUE(it->IsPersistent()); 405 EXPECT_TRUE(it->IsPersistent());
406 // Expect expiration date is in the right range. Some cookie implementations 406 // Expect expiration date is in the right range. Some cookie implementations
407 // may not record it with millisecond accuracy. 407 // may not record it with millisecond accuracy.
408 EXPECT_LE((one_hour_from_now - it->ExpiryDate()).magnitude().InSeconds(), 5); 408 EXPECT_LE((one_hour_from_now - it->ExpiryDate()).magnitude().InSeconds(), 5);
409 // Some CookieStores don't store last access date. 409 // Some CookieStores don't store last access date.
410 if (!it->LastAccessDate().is_null()) 410 if (!it->LastAccessDate().is_null())
411 EXPECT_EQ(one_hour_ago, it->LastAccessDate()); 411 EXPECT_EQ(one_hour_ago, it->LastAccessDate());
412 EXPECT_FALSE(it->IsSecure()); 412 EXPECT_FALSE(it->IsSecure());
413 EXPECT_FALSE(it->IsHttpOnly()); 413 EXPECT_FALSE(it->IsHttpOnly());
414 414
415 ASSERT_TRUE(++it == cookies.end()); 415 ASSERT_TRUE(++it == cookies.end());
416 416
417 // Verify that the cookie was set as 'httponly' by passing in a CookieOptions 417 // Verify that the cookie was set as 'httponly' by passing in a CookieOptions
418 // that excludes them and getting an empty result. 418 // that excludes them and getting an empty result.
419 if (TypeParam::supports_http_only) { 419 if (TypeParam::supports_http_only) {
420 cookies = this->GetCookieListWithOptions(cs, this->www_google_bar_.url(), 420 cookies = this->GetCookieListWithOptions(cs, this->www_foo_bar_.url(),
421 CookieOptions()); 421 CookieOptions());
422 it = cookies.begin(); 422 it = cookies.begin();
423 ASSERT_TRUE(it == cookies.end()); 423 ASSERT_TRUE(it == cookies.end());
424 } 424 }
425 425
426 // Get the cookie using the wide open |options|: 426 // Get the cookie using the wide open |options|:
427 cookies = 427 cookies =
428 this->GetCookieListWithOptions(cs, this->www_google_bar_.url(), options); 428 this->GetCookieListWithOptions(cs, this->www_foo_bar_.url(), options);
429 it = cookies.begin(); 429 it = cookies.begin();
430 430
431 ASSERT_TRUE(it != cookies.end()); 431 ASSERT_TRUE(it != cookies.end());
432 EXPECT_EQ("C", it->Name()); 432 EXPECT_EQ("C", it->Name());
433 EXPECT_EQ("D", it->Value()); 433 EXPECT_EQ("D", it->Value());
434 EXPECT_EQ(this->www_google_bar_.Format(".%D"), it->Domain()); 434 EXPECT_EQ(this->www_foo_bar_.Format(".%D"), it->Domain());
435 EXPECT_EQ("/bar", it->Path()); 435 EXPECT_EQ("/bar", it->Path());
436 EXPECT_EQ(two_hours_ago, it->CreationDate()); 436 EXPECT_EQ(two_hours_ago, it->CreationDate());
437 EXPECT_FALSE(it->IsPersistent()); 437 EXPECT_FALSE(it->IsPersistent());
438 // Some CookieStores don't store last access date. 438 // Some CookieStores don't store last access date.
439 if (!it->LastAccessDate().is_null()) 439 if (!it->LastAccessDate().is_null())
440 EXPECT_EQ(one_hour_ago, it->LastAccessDate()); 440 EXPECT_EQ(one_hour_ago, it->LastAccessDate());
441 EXPECT_FALSE(it->IsSecure()); 441 EXPECT_FALSE(it->IsSecure());
442 EXPECT_TRUE(it->IsHttpOnly()); 442 EXPECT_TRUE(it->IsHttpOnly());
443 443
444 EXPECT_TRUE(++it == cookies.end()); 444 EXPECT_TRUE(++it == cookies.end());
445 445
446 cookies = this->GetCookieListWithOptions(cs, this->https_www_google_.url(), 446 cookies =
447 options); 447 this->GetCookieListWithOptions(cs, this->https_www_foo_.url(), options);
448 it = cookies.begin(); 448 it = cookies.begin();
449 449
450 ASSERT_TRUE(it != cookies.end()); 450 ASSERT_TRUE(it != cookies.end());
451 EXPECT_EQ("E", it->Name()); 451 EXPECT_EQ("E", it->Name());
452 EXPECT_EQ("F", it->Value()); 452 EXPECT_EQ("F", it->Value());
453 EXPECT_EQ("/", it->Path()); 453 EXPECT_EQ("/", it->Path());
454 EXPECT_EQ(this->https_www_google_.host(), it->Domain()); 454 EXPECT_EQ(this->https_www_foo_.host(), it->Domain());
455 // Cookie should have its creation time set, and be in a reasonable range. 455 // Cookie should have its creation time set, and be in a reasonable range.
456 EXPECT_LE((base::Time::Now() - it->CreationDate()).magnitude().InMinutes(), 456 EXPECT_LE((base::Time::Now() - it->CreationDate()).magnitude().InMinutes(),
457 2); 457 2);
458 EXPECT_FALSE(it->IsPersistent()); 458 EXPECT_FALSE(it->IsPersistent());
459 // Some CookieStores don't store last access date. 459 // Some CookieStores don't store last access date.
460 if (!it->LastAccessDate().is_null()) 460 if (!it->LastAccessDate().is_null())
461 EXPECT_EQ(it->CreationDate(), it->LastAccessDate()); 461 EXPECT_EQ(it->CreationDate(), it->LastAccessDate());
462 EXPECT_TRUE(it->IsSecure()); 462 EXPECT_TRUE(it->IsSecure());
463 EXPECT_FALSE(it->IsHttpOnly()); 463 EXPECT_FALSE(it->IsHttpOnly());
464 464
465 EXPECT_TRUE(++it == cookies.end()); 465 EXPECT_TRUE(++it == cookies.end());
466 } 466 }
467 467
468 // Test enforcement around setting secure cookies. 468 // Test enforcement around setting secure cookies.
469 TYPED_TEST_P(CookieStoreTest, SetCookieWithDetailsSecureEnforcement) { 469 TYPED_TEST_P(CookieStoreTest, SetCookieWithDetailsSecureEnforcement) {
470 CookieStore* cs = this->GetCookieStore(); 470 CookieStore* cs = this->GetCookieStore();
471 GURL http_url(this->http_www_google_.url()); 471 GURL http_url(this->http_www_foo_.url());
472 std::string http_domain(http_url.host()); 472 std::string http_domain(http_url.host());
473 GURL https_url(this->https_www_google_.url()); 473 GURL https_url(this->https_www_foo_.url());
474 std::string https_domain(https_url.host()); 474 std::string https_domain(https_url.host());
475 475
476 // Confirm that setting the secure attribute on an HTTP URL fails, but 476 // Confirm that setting the secure attribute on an HTTP URL fails, but
477 // the other combinations work. 477 // the other combinations work.
478 EXPECT_TRUE(this->SetCookieWithDetails( 478 EXPECT_TRUE(this->SetCookieWithDetails(
479 cs, http_url, "A", "B", http_domain, "/", base::Time::Now(), base::Time(), 479 cs, http_url, "A", "B", http_domain, "/", base::Time::Now(), base::Time(),
480 base::Time(), false, false, CookieSameSite::NO_RESTRICTION, 480 base::Time(), false, false, CookieSameSite::NO_RESTRICTION,
481 COOKIE_PRIORITY_DEFAULT)); 481 COOKIE_PRIORITY_DEFAULT));
482 EXPECT_FALSE(this->SetCookieWithDetails( 482 EXPECT_FALSE(this->SetCookieWithDetails(
483 cs, http_url, "A", "B", http_domain, "/", base::Time::Now(), base::Time(), 483 cs, http_url, "A", "B", http_domain, "/", base::Time::Now(), base::Time(),
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 528
529 GURL url6("http://foo6.bar.com"); 529 GURL url6("http://foo6.bar.com");
530 EXPECT_TRUE(this->SetCookie(cs, url6, "foo")); 530 EXPECT_TRUE(this->SetCookie(cs, url6, "foo"));
531 EXPECT_TRUE(this->SetCookie(cs, url6, " ")); 531 EXPECT_TRUE(this->SetCookie(cs, url6, " "));
532 EXPECT_EQ("", this->GetCookies(cs, url6)); 532 EXPECT_EQ("", this->GetCookies(cs, url6));
533 #endif 533 #endif
534 } 534 }
535 535
536 TYPED_TEST_P(CookieStoreTest, DomainTest) { 536 TYPED_TEST_P(CookieStoreTest, DomainTest) {
537 CookieStore* cs = this->GetCookieStore(); 537 CookieStore* cs = this->GetCookieStore();
538 EXPECT_TRUE(this->SetCookie(cs, this->http_www_google_.url(), "A=B")); 538 EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=B"));
539 this->MatchCookieLines("A=B", 539 this->MatchCookieLines("A=B",
540 this->GetCookies(cs, this->http_www_google_.url())); 540 this->GetCookies(cs, this->http_www_foo_.url()));
541 EXPECT_TRUE( 541 EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(),
542 this->SetCookie(cs, this->http_www_google_.url(), 542 this->http_www_foo_.Format("C=D; domain=.%D")));
543 this->http_www_google_.Format("C=D; domain=.%D")));
544 this->MatchCookieLines("A=B; C=D", 543 this->MatchCookieLines("A=B; C=D",
545 this->GetCookies(cs, this->http_www_google_.url())); 544 this->GetCookies(cs, this->http_www_foo_.url()));
546 545
547 // Verify that A=B was set as a host cookie rather than a domain 546 // Verify that A=B was set as a host cookie rather than a domain
548 // cookie -- should not be accessible from a sub sub-domain. 547 // cookie -- should not be accessible from a sub sub-domain.
549 this->MatchCookieLines( 548 this->MatchCookieLines(
550 "C=D", this->GetCookies( 549 "C=D", this->GetCookies(
551 cs, GURL(this->http_www_google_.Format("http://foo.www.%D")))); 550 cs, GURL(this->http_www_foo_.Format("http://foo.www.%D"))));
552 551
553 // Test and make sure we find domain cookies on the same domain. 552 // Test and make sure we find domain cookies on the same domain.
554 EXPECT_TRUE( 553 EXPECT_TRUE(
555 this->SetCookie(cs, this->http_www_google_.url(), 554 this->SetCookie(cs, this->http_www_foo_.url(),
556 this->http_www_google_.Format("E=F; domain=.www.%D"))); 555 this->http_www_foo_.Format("E=F; domain=.www.%D")));
557 this->MatchCookieLines("A=B; C=D; E=F", 556 this->MatchCookieLines("A=B; C=D; E=F",
558 this->GetCookies(cs, this->http_www_google_.url())); 557 this->GetCookies(cs, this->http_www_foo_.url()));
559 558
560 // Test setting a domain= that doesn't start w/ a dot, should 559 // Test setting a domain= that doesn't start w/ a dot, should
561 // treat it as a domain cookie, as if there was a pre-pended dot. 560 // treat it as a domain cookie, as if there was a pre-pended dot.
562 EXPECT_TRUE( 561 EXPECT_TRUE(
563 this->SetCookie(cs, this->http_www_google_.url(), 562 this->SetCookie(cs, this->http_www_foo_.url(),
564 this->http_www_google_.Format("G=H; domain=www.%D"))); 563 this->http_www_foo_.Format("G=H; domain=www.%D")));
565 this->MatchCookieLines("A=B; C=D; E=F; G=H", 564 this->MatchCookieLines("A=B; C=D; E=F; G=H",
566 this->GetCookies(cs, this->http_www_google_.url())); 565 this->GetCookies(cs, this->http_www_foo_.url()));
567 566
568 // Test domain enforcement, should fail on a sub-domain or something too deep. 567 // Test domain enforcement, should fail on a sub-domain or something too deep.
569 EXPECT_FALSE( 568 EXPECT_FALSE(this->SetCookie(cs, this->http_www_foo_.url(),
570 this->SetCookie(cs, this->http_www_google_.url(), 569 this->http_www_foo_.Format("I=J; domain=.%R")));
571 this->http_www_google_.Format("I=J; domain=.%R")));
572 this->MatchCookieLines( 570 this->MatchCookieLines(
573 std::string(), 571 std::string(),
574 this->GetCookies(cs, GURL(this->http_www_google_.Format("http://a.%R")))); 572 this->GetCookies(cs, GURL(this->http_www_foo_.Format("http://a.%R"))));
575 EXPECT_FALSE(this->SetCookie( 573 EXPECT_FALSE(
576 cs, this->http_www_google_.url(), 574 this->SetCookie(cs, this->http_www_foo_.url(),
577 this->http_www_google_.Format("K=L; domain=.bla.www.%D"))); 575 this->http_www_foo_.Format("K=L; domain=.bla.www.%D")));
578 this->MatchCookieLines( 576 this->MatchCookieLines(
579 "C=D; E=F; G=H", 577 "C=D; E=F; G=H",
580 this->GetCookies( 578 this->GetCookies(cs,
581 cs, GURL(this->http_www_google_.Format("http://bla.www.%D")))); 579 GURL(this->http_www_foo_.Format("http://bla.www.%D"))));
582 this->MatchCookieLines("A=B; C=D; E=F; G=H", 580 this->MatchCookieLines("A=B; C=D; E=F; G=H",
583 this->GetCookies(cs, this->http_www_google_.url())); 581 this->GetCookies(cs, this->http_www_foo_.url()));
584 } 582 }
585 583
586 // FireFox recognizes domains containing trailing periods as valid. 584 // FireFox recognizes domains containing trailing periods as valid.
587 // IE and Safari do not. Assert the expected policy here. 585 // IE and Safari do not. Assert the expected policy here.
588 TYPED_TEST_P(CookieStoreTest, DomainWithTrailingDotTest) { 586 TYPED_TEST_P(CookieStoreTest, DomainWithTrailingDotTest) {
589 CookieStore* cs = this->GetCookieStore(); 587 CookieStore* cs = this->GetCookieStore();
590 if (TypeParam::preserves_trailing_dots) { 588 if (TypeParam::preserves_trailing_dots) {
591 EXPECT_FALSE(this->SetCookie(cs, this->http_www_google_.url(), 589 EXPECT_FALSE(this->SetCookie(cs, this->http_www_foo_.url(),
592 "a=1; domain=.www.google.izzle.")); 590 "a=1; domain=.www.foo.com."));
593 EXPECT_FALSE(this->SetCookie(cs, this->http_www_google_.url(), 591 EXPECT_FALSE(this->SetCookie(cs, this->http_www_foo_.url(),
594 "b=2; domain=.www.google.izzle..")); 592 "b=2; domain=.www.foo.com.."));
595 this->MatchCookieLines(std::string(), 593 this->MatchCookieLines(std::string(),
596 this->GetCookies(cs, this->http_www_google_.url())); 594 this->GetCookies(cs, this->http_www_foo_.url()));
597 } else { 595 } else {
598 EXPECT_TRUE(this->SetCookie(cs, this->http_www_google_.url(), 596 EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(),
599 "a=1; domain=.www.google.izzle.")); 597 "a=1; domain=.www.foo.com."));
600 EXPECT_FALSE(this->SetCookie(cs, this->http_www_google_.url(), 598 EXPECT_FALSE(this->SetCookie(cs, this->http_www_foo_.url(),
601 "b=2; domain=.www.google.izzle..")); 599 "b=2; domain=.www.foo.com.."));
602 this->MatchCookieLines("a=1", 600 this->MatchCookieLines("a=1",
603 this->GetCookies(cs, this->http_www_google_.url())); 601 this->GetCookies(cs, this->http_www_foo_.url()));
604 } 602 }
605 } 603 }
606 604
607 // Test that cookies can bet set on higher level domains. 605 // Test that cookies can bet set on higher level domains.
608 TYPED_TEST_P(CookieStoreTest, ValidSubdomainTest) { 606 TYPED_TEST_P(CookieStoreTest, ValidSubdomainTest) {
609 CookieStore* cs = this->GetCookieStore(); 607 CookieStore* cs = this->GetCookieStore();
610 GURL url_abcd("http://a.b.c.d.com"); 608 GURL url_abcd("http://a.b.c.d.com");
611 GURL url_bcd("http://b.c.d.com"); 609 GURL url_bcd("http://b.c.d.com");
612 GURL url_cd("http://c.d.com"); 610 GURL url_cd("http://c.d.com");
613 GURL url_d("http://d.com"); 611 GURL url_d("http://d.com");
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
698 GURL url_filefront("http://www.filefront.com"); 696 GURL url_filefront("http://www.filefront.com");
699 EXPECT_TRUE(this->SetCookie(cs, url_hosted, "sawAd=1; domain=filefront.com")); 697 EXPECT_TRUE(this->SetCookie(cs, url_hosted, "sawAd=1; domain=filefront.com"));
700 this->MatchCookieLines("sawAd=1", this->GetCookies(cs, url_hosted)); 698 this->MatchCookieLines("sawAd=1", this->GetCookies(cs, url_hosted));
701 this->MatchCookieLines("sawAd=1", this->GetCookies(cs, url_filefront)); 699 this->MatchCookieLines("sawAd=1", this->GetCookies(cs, url_filefront));
702 } 700 }
703 701
704 // Even when the specified domain matches the domain of the URL exactly, treat 702 // Even when the specified domain matches the domain of the URL exactly, treat
705 // it as setting a domain cookie. 703 // it as setting a domain cookie.
706 TYPED_TEST_P(CookieStoreTest, DomainWithoutLeadingDotSameDomain) { 704 TYPED_TEST_P(CookieStoreTest, DomainWithoutLeadingDotSameDomain) {
707 CookieStore* cs = this->GetCookieStore(); 705 CookieStore* cs = this->GetCookieStore();
708 GURL url("http://www.google.com"); 706 GURL url("http://www.foo.com");
709 EXPECT_TRUE(this->SetCookie(cs, url, "a=1; domain=www.google.com")); 707 EXPECT_TRUE(this->SetCookie(cs, url, "a=1; domain=www.foo.com"));
710 this->MatchCookieLines("a=1", this->GetCookies(cs, url)); 708 this->MatchCookieLines("a=1", this->GetCookies(cs, url));
711 this->MatchCookieLines( 709 this->MatchCookieLines("a=1",
712 "a=1", this->GetCookies(cs, GURL("http://sub.www.google.com"))); 710 this->GetCookies(cs, GURL("http://sub.www.foo.com")));
713 this->MatchCookieLines( 711 this->MatchCookieLines(
714 std::string(), this->GetCookies(cs, GURL("http://something-else.com"))); 712 std::string(), this->GetCookies(cs, GURL("http://something-else.com")));
715 } 713 }
716 714
717 // Test that the domain specified in cookie string is treated case-insensitive 715 // Test that the domain specified in cookie string is treated case-insensitive
718 TYPED_TEST_P(CookieStoreTest, CaseInsensitiveDomainTest) { 716 TYPED_TEST_P(CookieStoreTest, CaseInsensitiveDomainTest) {
719 CookieStore* cs = this->GetCookieStore(); 717 CookieStore* cs = this->GetCookieStore();
720 GURL url("http://www.google.com"); 718 GURL url("http://www.foo.com");
721 EXPECT_TRUE(this->SetCookie(cs, url, "a=1; domain=.GOOGLE.COM")); 719 EXPECT_TRUE(this->SetCookie(cs, url, "a=1; domain=.FOO.COM"));
722 EXPECT_TRUE(this->SetCookie(cs, url, "b=2; domain=.wWw.gOOgLE.coM")); 720 EXPECT_TRUE(this->SetCookie(cs, url, "b=2; domain=.wWw.fOO.cOM"));
723 this->MatchCookieLines("a=1; b=2", this->GetCookies(cs, url)); 721 this->MatchCookieLines("a=1; b=2", this->GetCookies(cs, url));
724 } 722 }
725 723
726 TYPED_TEST_P(CookieStoreTest, TestIpAddress) { 724 TYPED_TEST_P(CookieStoreTest, TestIpAddress) {
727 GURL url_ip("http://1.2.3.4/weee"); 725 GURL url_ip("http://1.2.3.4/weee");
728 CookieStore* cs = this->GetCookieStore(); 726 CookieStore* cs = this->GetCookieStore();
729 EXPECT_TRUE(this->SetCookie(cs, url_ip, kValidCookieLine)); 727 EXPECT_TRUE(this->SetCookie(cs, url_ip, kValidCookieLine));
730 this->MatchCookieLines("A=B", this->GetCookies(cs, url_ip)); 728 this->MatchCookieLines("A=B", this->GetCookies(cs, url_ip));
731 } 729 }
732 730
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
786 TYPED_TEST_P(CookieStoreTest, TestSubdomainSettingCookiesOnUnknownTLD) { 784 TYPED_TEST_P(CookieStoreTest, TestSubdomainSettingCookiesOnUnknownTLD) {
787 CookieStore* cs = this->GetCookieStore(); 785 CookieStore* cs = this->GetCookieStore();
788 GURL url("http://a.b"); 786 GURL url("http://a.b");
789 EXPECT_FALSE(this->SetCookie(cs, url, "a=1; domain=.b")); 787 EXPECT_FALSE(this->SetCookie(cs, url, "a=1; domain=.b"));
790 EXPECT_FALSE(this->SetCookie(cs, url, "b=2; domain=b")); 788 EXPECT_FALSE(this->SetCookie(cs, url, "b=2; domain=b"));
791 this->MatchCookieLines(std::string(), this->GetCookies(cs, url)); 789 this->MatchCookieLines(std::string(), this->GetCookies(cs, url));
792 } 790 }
793 791
794 TYPED_TEST_P(CookieStoreTest, TestSubdomainSettingCookiesOnKnownTLD) { 792 TYPED_TEST_P(CookieStoreTest, TestSubdomainSettingCookiesOnKnownTLD) {
795 CookieStore* cs = this->GetCookieStore(); 793 CookieStore* cs = this->GetCookieStore();
796 GURL url("http://google.com"); 794 GURL url("http://foo.com");
797 EXPECT_FALSE(this->SetCookie(cs, url, "a=1; domain=.com")); 795 EXPECT_FALSE(this->SetCookie(cs, url, "a=1; domain=.com"));
798 EXPECT_FALSE(this->SetCookie(cs, url, "b=2; domain=com")); 796 EXPECT_FALSE(this->SetCookie(cs, url, "b=2; domain=com"));
799 this->MatchCookieLines(std::string(), this->GetCookies(cs, url)); 797 this->MatchCookieLines(std::string(), this->GetCookies(cs, url));
800 } 798 }
801 799
802 TYPED_TEST_P(CookieStoreTest, TestSubdomainSettingCookiesOnKnownDottedTLD) { 800 TYPED_TEST_P(CookieStoreTest, TestSubdomainSettingCookiesOnKnownDottedTLD) {
803 CookieStore* cs = this->GetCookieStore(); 801 CookieStore* cs = this->GetCookieStore();
804 GURL url("http://google.co.uk"); 802 GURL url("http://foo.co.uk");
805 EXPECT_FALSE(this->SetCookie(cs, url, "a=1; domain=.co.uk")); 803 EXPECT_FALSE(this->SetCookie(cs, url, "a=1; domain=.co.uk"));
806 EXPECT_FALSE(this->SetCookie(cs, url, "b=2; domain=.uk")); 804 EXPECT_FALSE(this->SetCookie(cs, url, "b=2; domain=.uk"));
807 this->MatchCookieLines(std::string(), this->GetCookies(cs, url)); 805 this->MatchCookieLines(std::string(), this->GetCookies(cs, url));
808 this->MatchCookieLines( 806 this->MatchCookieLines(
809 std::string(), this->GetCookies(cs, GURL("http://something-else.co.uk"))); 807 std::string(), this->GetCookies(cs, GURL("http://something-else.co.uk")));
810 this->MatchCookieLines( 808 this->MatchCookieLines(
811 std::string(), this->GetCookies(cs, GURL("http://something-else.uk"))); 809 std::string(), this->GetCookies(cs, GURL("http://something-else.uk")));
812 } 810 }
813 811
814 // Intranet URLs should only be able to set host cookies. 812 // Intranet URLs should only be able to set host cookies.
(...skipping 19 matching lines...) Expand all
834 // Make sure it doesn't show up for an intranet subdomain, it should be 832 // Make sure it doesn't show up for an intranet subdomain, it should be
835 // a host, not domain, cookie. 833 // a host, not domain, cookie.
836 this->MatchCookieLines( 834 this->MatchCookieLines(
837 std::string(), 835 std::string(),
838 this->GetCookies(cs, GURL("http://hopefully-no-cookies.b/"))); 836 this->GetCookies(cs, GURL("http://hopefully-no-cookies.b/")));
839 this->MatchCookieLines(std::string(), 837 this->MatchCookieLines(std::string(),
840 this->GetCookies(cs, GURL("http://.b/"))); 838 this->GetCookies(cs, GURL("http://.b/")));
841 } 839 }
842 840
843 // Test reading/writing cookies when the domain ends with a period, 841 // Test reading/writing cookies when the domain ends with a period,
844 // as in "www.google.com." 842 // as in "www.foo.com."
845 TYPED_TEST_P(CookieStoreTest, TestHostEndsWithDot) { 843 TYPED_TEST_P(CookieStoreTest, TestHostEndsWithDot) {
846 CookieStore* cs = this->GetCookieStore(); 844 CookieStore* cs = this->GetCookieStore();
847 GURL url("http://www.google.com"); 845 GURL url("http://www.foo.com");
848 GURL url_with_dot("http://www.google.com."); 846 GURL url_with_dot("http://www.foo.com.");
849 EXPECT_TRUE(this->SetCookie(cs, url, "a=1")); 847 EXPECT_TRUE(this->SetCookie(cs, url, "a=1"));
850 this->MatchCookieLines("a=1", this->GetCookies(cs, url)); 848 this->MatchCookieLines("a=1", this->GetCookies(cs, url));
851 849
852 // Do not share cookie space with the dot version of domain. 850 // Do not share cookie space with the dot version of domain.
853 // Note: this is not what FireFox does, but it _is_ what IE+Safari do. 851 // Note: this is not what FireFox does, but it _is_ what IE+Safari do.
854 if (TypeParam::preserves_trailing_dots) { 852 if (TypeParam::preserves_trailing_dots) {
855 EXPECT_FALSE(this->SetCookie(cs, url, "b=2; domain=.www.google.com.")); 853 EXPECT_FALSE(this->SetCookie(cs, url, "b=2; domain=.www.foo.com."));
856 this->MatchCookieLines("a=1", this->GetCookies(cs, url)); 854 this->MatchCookieLines("a=1", this->GetCookies(cs, url));
857 EXPECT_TRUE(this->SetCookie(cs, url_with_dot, "b=2; domain=.google.com.")); 855 EXPECT_TRUE(this->SetCookie(cs, url_with_dot, "b=2; domain=.foo.com."));
858 this->MatchCookieLines("b=2", this->GetCookies(cs, url_with_dot)); 856 this->MatchCookieLines("b=2", this->GetCookies(cs, url_with_dot));
859 } else { 857 } else {
860 EXPECT_TRUE(this->SetCookie(cs, url, "b=2; domain=.www.google.com.")); 858 EXPECT_TRUE(this->SetCookie(cs, url, "b=2; domain=.www.foo.com."));
861 this->MatchCookieLines("a=1 b=2", this->GetCookies(cs, url)); 859 this->MatchCookieLines("a=1 b=2", this->GetCookies(cs, url));
862 // Setting this cookie should fail, since the trailing dot on the domain 860 // Setting this cookie should fail, since the trailing dot on the domain
863 // isn't preserved, and then the domain mismatches the URL. 861 // isn't preserved, and then the domain mismatches the URL.
864 EXPECT_FALSE(this->SetCookie(cs, url_with_dot, "b=2; domain=.google.com.")); 862 EXPECT_FALSE(this->SetCookie(cs, url_with_dot, "b=2; domain=.foo.com."));
865 } 863 }
866 864
867 // Make sure there weren't any side effects. 865 // Make sure there weren't any side effects.
868 this->MatchCookieLines( 866 this->MatchCookieLines(
869 std::string(), 867 std::string(),
870 this->GetCookies(cs, GURL("http://hopefully-no-cookies.com/"))); 868 this->GetCookies(cs, GURL("http://hopefully-no-cookies.com/")));
871 this->MatchCookieLines(std::string(), 869 this->MatchCookieLines(std::string(),
872 this->GetCookies(cs, GURL("http://.com/"))); 870 this->GetCookies(cs, GURL("http://.com/")));
873 } 871 }
874 872
875 TYPED_TEST_P(CookieStoreTest, InvalidScheme) { 873 TYPED_TEST_P(CookieStoreTest, InvalidScheme) {
876 if (!TypeParam::filters_schemes) 874 if (!TypeParam::filters_schemes)
877 return; 875 return;
878 876
879 CookieStore* cs = this->GetCookieStore(); 877 CookieStore* cs = this->GetCookieStore();
880 EXPECT_FALSE(this->SetCookie(cs, this->ftp_google_.url(), kValidCookieLine)); 878 EXPECT_FALSE(this->SetCookie(cs, this->ftp_foo_.url(), kValidCookieLine));
881 } 879 }
882 880
883 TYPED_TEST_P(CookieStoreTest, InvalidScheme_Read) { 881 TYPED_TEST_P(CookieStoreTest, InvalidScheme_Read) {
884 if (!TypeParam::filters_schemes) 882 if (!TypeParam::filters_schemes)
885 return; 883 return;
886 884
887 const std::string kValidDomainCookieLine = 885 const std::string kValidDomainCookieLine =
888 this->http_www_google_.Format("A=B; path=/; domain=%D"); 886 this->http_www_foo_.Format("A=B; path=/; domain=%D");
889 887
890 CookieStore* cs = this->GetCookieStore(); 888 CookieStore* cs = this->GetCookieStore();
891 EXPECT_TRUE(this->SetCookie(cs, this->http_www_google_.url(), 889 EXPECT_TRUE(
892 kValidDomainCookieLine)); 890 this->SetCookie(cs, this->http_www_foo_.url(), kValidDomainCookieLine));
893 this->MatchCookieLines(std::string(), 891 this->MatchCookieLines(std::string(),
894 this->GetCookies(cs, this->ftp_google_.url())); 892 this->GetCookies(cs, this->ftp_foo_.url()));
895 EXPECT_EQ(0U, this->GetCookieListWithOptions(cs, this->ftp_google_.url(), 893 EXPECT_EQ(0U, this->GetCookieListWithOptions(cs, this->ftp_foo_.url(),
896 CookieOptions()) 894 CookieOptions())
897 .size()); 895 .size());
898 } 896 }
899 897
900 TYPED_TEST_P(CookieStoreTest, PathTest) { 898 TYPED_TEST_P(CookieStoreTest, PathTest) {
901 CookieStore* cs = this->GetCookieStore(); 899 CookieStore* cs = this->GetCookieStore();
902 std::string url("http://www.google.izzle"); 900 std::string url("http://www.foo.com");
903 EXPECT_TRUE(this->SetCookie(cs, GURL(url), "A=B; path=/wee")); 901 EXPECT_TRUE(this->SetCookie(cs, GURL(url), "A=B; path=/wee"));
904 this->MatchCookieLines("A=B", this->GetCookies(cs, GURL(url + "/wee"))); 902 this->MatchCookieLines("A=B", this->GetCookies(cs, GURL(url + "/wee")));
905 this->MatchCookieLines("A=B", this->GetCookies(cs, GURL(url + "/wee/"))); 903 this->MatchCookieLines("A=B", this->GetCookies(cs, GURL(url + "/wee/")));
906 this->MatchCookieLines("A=B", this->GetCookies(cs, GURL(url + "/wee/war"))); 904 this->MatchCookieLines("A=B", this->GetCookies(cs, GURL(url + "/wee/war")));
907 this->MatchCookieLines( 905 this->MatchCookieLines(
908 "A=B", this->GetCookies(cs, GURL(url + "/wee/war/more/more"))); 906 "A=B", this->GetCookies(cs, GURL(url + "/wee/war/more/more")));
909 if (!TypeParam::has_path_prefix_bug) 907 if (!TypeParam::has_path_prefix_bug)
910 this->MatchCookieLines(std::string(), 908 this->MatchCookieLines(std::string(),
911 this->GetCookies(cs, GURL(url + "/weehee"))); 909 this->GetCookies(cs, GURL(url + "/weehee")));
912 this->MatchCookieLines(std::string(), this->GetCookies(cs, GURL(url + "/"))); 910 this->MatchCookieLines(std::string(), this->GetCookies(cs, GURL(url + "/")));
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
944 942
945 TYPED_TEST_P(CookieStoreTest, HttpOnlyTest) { 943 TYPED_TEST_P(CookieStoreTest, HttpOnlyTest) {
946 if (!TypeParam::supports_http_only) 944 if (!TypeParam::supports_http_only)
947 return; 945 return;
948 946
949 CookieStore* cs = this->GetCookieStore(); 947 CookieStore* cs = this->GetCookieStore();
950 CookieOptions options; 948 CookieOptions options;
951 options.set_include_httponly(); 949 options.set_include_httponly();
952 950
953 // Create a httponly cookie. 951 // Create a httponly cookie.
954 EXPECT_TRUE(this->SetCookieWithOptions(cs, this->http_www_google_.url(), 952 EXPECT_TRUE(this->SetCookieWithOptions(cs, this->http_www_foo_.url(),
955 "A=B; httponly", options)); 953 "A=B; httponly", options));
956 954
957 // Check httponly read protection. 955 // Check httponly read protection.
958 this->MatchCookieLines(std::string(), 956 this->MatchCookieLines(std::string(),
959 this->GetCookies(cs, this->http_www_google_.url())); 957 this->GetCookies(cs, this->http_www_foo_.url()));
960 this->MatchCookieLines("A=B", this->GetCookiesWithOptions( 958 this->MatchCookieLines("A=B", this->GetCookiesWithOptions(
961 cs, this->http_www_google_.url(), options)); 959 cs, this->http_www_foo_.url(), options));
962 960
963 // Check httponly overwrite protection. 961 // Check httponly overwrite protection.
964 EXPECT_FALSE(this->SetCookie(cs, this->http_www_google_.url(), "A=C")); 962 EXPECT_FALSE(this->SetCookie(cs, this->http_www_foo_.url(), "A=C"));
965 this->MatchCookieLines(std::string(), 963 this->MatchCookieLines(std::string(),
966 this->GetCookies(cs, this->http_www_google_.url())); 964 this->GetCookies(cs, this->http_www_foo_.url()));
967 this->MatchCookieLines("A=B", this->GetCookiesWithOptions( 965 this->MatchCookieLines("A=B", this->GetCookiesWithOptions(
968 cs, this->http_www_google_.url(), options)); 966 cs, this->http_www_foo_.url(), options));
969 EXPECT_TRUE(this->SetCookieWithOptions(cs, this->http_www_google_.url(), 967 EXPECT_TRUE(this->SetCookieWithOptions(cs, this->http_www_foo_.url(), "A=C",
970 "A=C", options)); 968 options));
971 this->MatchCookieLines("A=C", 969 this->MatchCookieLines("A=C",
972 this->GetCookies(cs, this->http_www_google_.url())); 970 this->GetCookies(cs, this->http_www_foo_.url()));
973 971
974 // Check httponly create protection. 972 // Check httponly create protection.
975 EXPECT_FALSE( 973 EXPECT_FALSE(this->SetCookie(cs, this->http_www_foo_.url(), "B=A; httponly"));
976 this->SetCookie(cs, this->http_www_google_.url(), "B=A; httponly"));
977 this->MatchCookieLines("A=C", this->GetCookiesWithOptions( 974 this->MatchCookieLines("A=C", this->GetCookiesWithOptions(
978 cs, this->http_www_google_.url(), options)); 975 cs, this->http_www_foo_.url(), options));
979 EXPECT_TRUE(this->SetCookieWithOptions(cs, this->http_www_google_.url(), 976 EXPECT_TRUE(this->SetCookieWithOptions(cs, this->http_www_foo_.url(),
980 "B=A; httponly", options)); 977 "B=A; httponly", options));
981 this->MatchCookieLines( 978 this->MatchCookieLines(
982 "A=C; B=A", 979 "A=C; B=A",
983 this->GetCookiesWithOptions(cs, this->http_www_google_.url(), options)); 980 this->GetCookiesWithOptions(cs, this->http_www_foo_.url(), options));
984 this->MatchCookieLines("A=C", 981 this->MatchCookieLines("A=C",
985 this->GetCookies(cs, this->http_www_google_.url())); 982 this->GetCookies(cs, this->http_www_foo_.url()));
986 } 983 }
987 984
988 TYPED_TEST_P(CookieStoreTest, TestCookieDeletion) { 985 TYPED_TEST_P(CookieStoreTest, TestCookieDeletion) {
989 CookieStore* cs = this->GetCookieStore(); 986 CookieStore* cs = this->GetCookieStore();
990 987
991 // Create a session cookie. 988 // Create a session cookie.
992 EXPECT_TRUE( 989 EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), kValidCookieLine));
993 this->SetCookie(cs, this->http_www_google_.url(), kValidCookieLine));
994 this->MatchCookieLines("A=B", 990 this->MatchCookieLines("A=B",
995 this->GetCookies(cs, this->http_www_google_.url())); 991 this->GetCookies(cs, this->http_www_foo_.url()));
996 // Delete it via Max-Age. 992 // Delete it via Max-Age.
997 EXPECT_TRUE(this->SetCookie(cs, this->http_www_google_.url(), 993 EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(),
998 std::string(kValidCookieLine) + "; max-age=0")); 994 std::string(kValidCookieLine) + "; max-age=0"));
999 this->MatchCookieLineWithTimeout(cs, this->http_www_google_.url(), 995 this->MatchCookieLineWithTimeout(cs, this->http_www_foo_.url(),
1000 std::string()); 996 std::string());
1001 997
1002 // Create a session cookie. 998 // Create a session cookie.
1003 EXPECT_TRUE( 999 EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), kValidCookieLine));
1004 this->SetCookie(cs, this->http_www_google_.url(), kValidCookieLine));
1005 this->MatchCookieLines("A=B", 1000 this->MatchCookieLines("A=B",
1006 this->GetCookies(cs, this->http_www_google_.url())); 1001 this->GetCookies(cs, this->http_www_foo_.url()));
1007 // Delete it via Expires. 1002 // Delete it via Expires.
1008 EXPECT_TRUE(this->SetCookie(cs, this->http_www_google_.url(), 1003 EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(),
1009 std::string(kValidCookieLine) + 1004 std::string(kValidCookieLine) +
1010 "; expires=Mon, 18-Apr-1977 22:50:13 GMT")); 1005 "; expires=Mon, 18-Apr-1977 22:50:13 GMT"));
1011 this->MatchCookieLines(std::string(), 1006 this->MatchCookieLines(std::string(),
1012 this->GetCookies(cs, this->http_www_google_.url())); 1007 this->GetCookies(cs, this->http_www_foo_.url()));
1013 1008
1014 // Create a persistent cookie. 1009 // Create a persistent cookie.
1015 EXPECT_TRUE(this->SetCookie( 1010 EXPECT_TRUE(this->SetCookie(
1016 cs, this->http_www_google_.url(), 1011 cs, this->http_www_foo_.url(),
1017 std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-22 22:50:13 GMT")); 1012 std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-22 22:50:13 GMT"));
1018 1013
1019 this->MatchCookieLines("A=B", 1014 this->MatchCookieLines("A=B",
1020 this->GetCookies(cs, this->http_www_google_.url())); 1015 this->GetCookies(cs, this->http_www_foo_.url()));
1021 // Delete it via Max-Age. 1016 // Delete it via Max-Age.
1022 EXPECT_TRUE(this->SetCookie(cs, this->http_www_google_.url(), 1017 EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(),
1023 std::string(kValidCookieLine) + "; max-age=0")); 1018 std::string(kValidCookieLine) + "; max-age=0"));
1024 this->MatchCookieLineWithTimeout(cs, this->http_www_google_.url(), 1019 this->MatchCookieLineWithTimeout(cs, this->http_www_foo_.url(),
1025 std::string()); 1020 std::string());
1026 1021
1027 // Create a persistent cookie. 1022 // Create a persistent cookie.
1028 EXPECT_TRUE(this->SetCookie( 1023 EXPECT_TRUE(this->SetCookie(
1029 cs, this->http_www_google_.url(), 1024 cs, this->http_www_foo_.url(),
1030 std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-22 22:50:13 GMT")); 1025 std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-22 22:50:13 GMT"));
1031 this->MatchCookieLines("A=B", 1026 this->MatchCookieLines("A=B",
1032 this->GetCookies(cs, this->http_www_google_.url())); 1027 this->GetCookies(cs, this->http_www_foo_.url()));
1033 // Delete it via Expires. 1028 // Delete it via Expires.
1034 EXPECT_TRUE(this->SetCookie(cs, this->http_www_google_.url(), 1029 EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(),
1035 std::string(kValidCookieLine) + 1030 std::string(kValidCookieLine) +
1036 "; expires=Mon, 18-Apr-1977 22:50:13 GMT")); 1031 "; expires=Mon, 18-Apr-1977 22:50:13 GMT"));
1037 this->MatchCookieLines(std::string(), 1032 this->MatchCookieLines(std::string(),
1038 this->GetCookies(cs, this->http_www_google_.url())); 1033 this->GetCookies(cs, this->http_www_foo_.url()));
1039 1034
1040 // Create a persistent cookie. 1035 // Create a persistent cookie.
1041 EXPECT_TRUE(this->SetCookie( 1036 EXPECT_TRUE(this->SetCookie(
1042 cs, this->http_www_google_.url(), 1037 cs, this->http_www_foo_.url(),
1043 std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-22 22:50:13 GMT")); 1038 std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-22 22:50:13 GMT"));
1044 this->MatchCookieLines("A=B", 1039 this->MatchCookieLines("A=B",
1045 this->GetCookies(cs, this->http_www_google_.url())); 1040 this->GetCookies(cs, this->http_www_foo_.url()));
1046 // Check that it is not deleted with significant enough clock skew. 1041 // Check that it is not deleted with significant enough clock skew.
1047 base::Time server_time; 1042 base::Time server_time;
1048 EXPECT_TRUE(base::Time::FromString("Sun, 17-Apr-1977 22:50:13 GMT", 1043 EXPECT_TRUE(base::Time::FromString("Sun, 17-Apr-1977 22:50:13 GMT",
1049 &server_time)); 1044 &server_time));
1050 EXPECT_TRUE(this->SetCookieWithServerTime( 1045 EXPECT_TRUE(this->SetCookieWithServerTime(
1051 cs, this->http_www_google_.url(), 1046 cs, this->http_www_foo_.url(),
1052 std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-1977 22:50:13 GMT", 1047 std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-1977 22:50:13 GMT",
1053 server_time)); 1048 server_time));
1054 this->MatchCookieLines("A=B", 1049 this->MatchCookieLines("A=B",
1055 this->GetCookies(cs, this->http_www_google_.url())); 1050 this->GetCookies(cs, this->http_www_foo_.url()));
1056 1051
1057 // Create a persistent cookie. 1052 // Create a persistent cookie.
1058 EXPECT_TRUE(this->SetCookie( 1053 EXPECT_TRUE(this->SetCookie(
1059 cs, this->http_www_google_.url(), 1054 cs, this->http_www_foo_.url(),
1060 std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-22 22:50:13 GMT")); 1055 std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-22 22:50:13 GMT"));
1061 this->MatchCookieLines("A=B", 1056 this->MatchCookieLines("A=B",
1062 this->GetCookies(cs, this->http_www_google_.url())); 1057 this->GetCookies(cs, this->http_www_foo_.url()));
1063 // Delete it via Expires, with a unix epoch of 0. 1058 // Delete it via Expires, with a unix epoch of 0.
1064 EXPECT_TRUE(this->SetCookie(cs, this->http_www_google_.url(), 1059 EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(),
1065 std::string(kValidCookieLine) + 1060 std::string(kValidCookieLine) +
1066 "; expires=Thu, 1-Jan-1970 00:00:00 GMT")); 1061 "; expires=Thu, 1-Jan-1970 00:00:00 GMT"));
1067 this->MatchCookieLines(std::string(), 1062 this->MatchCookieLines(std::string(),
1068 this->GetCookies(cs, this->http_www_google_.url())); 1063 this->GetCookies(cs, this->http_www_foo_.url()));
1069 } 1064 }
1070 1065
1071 TYPED_TEST_P(CookieStoreTest, TestDeleteAll) { 1066 TYPED_TEST_P(CookieStoreTest, TestDeleteAll) {
1072 CookieStore* cs = this->GetCookieStore(); 1067 CookieStore* cs = this->GetCookieStore();
1073 1068
1074 // Set a session cookie. 1069 // Set a session cookie.
1075 EXPECT_TRUE( 1070 EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), kValidCookieLine));
1076 this->SetCookie(cs, this->http_www_google_.url(), kValidCookieLine)); 1071 EXPECT_EQ("A=B", this->GetCookies(cs, this->http_www_foo_.url()));
1077 EXPECT_EQ("A=B", this->GetCookies(cs, this->http_www_google_.url()));
1078 1072
1079 // Set a persistent cookie. 1073 // Set a persistent cookie.
1080 EXPECT_TRUE(this->SetCookie(cs, this->http_www_google_.url(), 1074 EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(),
1081 "C=D; expires=Mon, 18-Apr-22 22:50:13 GMT")); 1075 "C=D; expires=Mon, 18-Apr-22 22:50:13 GMT"));
1082 1076
1083 EXPECT_EQ(2u, this->GetAllCookies(cs).size()); 1077 EXPECT_EQ(2u, this->GetAllCookies(cs).size());
1084 1078
1085 // Delete both, and make sure it works 1079 // Delete both, and make sure it works
1086 EXPECT_EQ(2, this->DeleteAll(cs)); 1080 EXPECT_EQ(2, this->DeleteAll(cs));
1087 EXPECT_EQ(0u, this->GetAllCookies(cs).size()); 1081 EXPECT_EQ(0u, this->GetAllCookies(cs).size());
1088 } 1082 }
1089 1083
1090 TYPED_TEST_P(CookieStoreTest, TestDeleteAllCreatedBetween) { 1084 TYPED_TEST_P(CookieStoreTest, TestDeleteAllCreatedBetween) {
1091 CookieStore* cs = this->GetCookieStore(); 1085 CookieStore* cs = this->GetCookieStore();
1092 const base::Time last_month = base::Time::Now() - 1086 const base::Time last_month = base::Time::Now() -
1093 base::TimeDelta::FromDays(30); 1087 base::TimeDelta::FromDays(30);
1094 const base::Time last_minute = base::Time::Now() - 1088 const base::Time last_minute = base::Time::Now() -
1095 base::TimeDelta::FromMinutes(1); 1089 base::TimeDelta::FromMinutes(1);
1096 const base::Time next_minute = base::Time::Now() + 1090 const base::Time next_minute = base::Time::Now() +
1097 base::TimeDelta::FromMinutes(1); 1091 base::TimeDelta::FromMinutes(1);
1098 const base::Time next_month = base::Time::Now() + 1092 const base::Time next_month = base::Time::Now() +
1099 base::TimeDelta::FromDays(30); 1093 base::TimeDelta::FromDays(30);
1100 1094
1101 // Add a cookie. 1095 // Add a cookie.
1102 EXPECT_TRUE(this->SetCookie(cs, this->http_www_google_.url(), "A=B")); 1096 EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=B"));
1103 // Check that the cookie is in the store. 1097 // Check that the cookie is in the store.
1104 this->MatchCookieLines("A=B", 1098 this->MatchCookieLines("A=B",
1105 this->GetCookies(cs, this->http_www_google_.url())); 1099 this->GetCookies(cs, this->http_www_foo_.url()));
1106 1100
1107 // Remove cookies in empty intervals. 1101 // Remove cookies in empty intervals.
1108 EXPECT_EQ(0, this->DeleteCreatedBetween(cs, last_month, last_minute)); 1102 EXPECT_EQ(0, this->DeleteCreatedBetween(cs, last_month, last_minute));
1109 EXPECT_EQ(0, this->DeleteCreatedBetween(cs, next_minute, next_month)); 1103 EXPECT_EQ(0, this->DeleteCreatedBetween(cs, next_minute, next_month));
1110 // Check that the cookie is still there. 1104 // Check that the cookie is still there.
1111 this->MatchCookieLines("A=B", 1105 this->MatchCookieLines("A=B",
1112 this->GetCookies(cs, this->http_www_google_.url())); 1106 this->GetCookies(cs, this->http_www_foo_.url()));
1113 1107
1114 // Remove the cookie with an interval defined by two dates. 1108 // Remove the cookie with an interval defined by two dates.
1115 EXPECT_EQ(1, this->DeleteCreatedBetween(cs, last_minute, next_minute)); 1109 EXPECT_EQ(1, this->DeleteCreatedBetween(cs, last_minute, next_minute));
1116 // Check that the cookie disappeared. 1110 // Check that the cookie disappeared.
1117 this->MatchCookieLines(std::string(), 1111 this->MatchCookieLines(std::string(),
1118 this->GetCookies(cs, this->http_www_google_.url())); 1112 this->GetCookies(cs, this->http_www_foo_.url()));
1119 1113
1120 // Add another cookie. 1114 // Add another cookie.
1121 EXPECT_TRUE(this->SetCookie(cs, this->http_www_google_.url(), "C=D")); 1115 EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "C=D"));
1122 // Check that the cookie is in the store. 1116 // Check that the cookie is in the store.
1123 this->MatchCookieLines("C=D", 1117 this->MatchCookieLines("C=D",
1124 this->GetCookies(cs, this->http_www_google_.url())); 1118 this->GetCookies(cs, this->http_www_foo_.url()));
1125 1119
1126 // Remove the cookie with a null ending time. 1120 // Remove the cookie with a null ending time.
1127 EXPECT_EQ(1, this->DeleteCreatedBetween(cs, last_minute, base::Time())); 1121 EXPECT_EQ(1, this->DeleteCreatedBetween(cs, last_minute, base::Time()));
1128 // Check that the cookie disappeared. 1122 // Check that the cookie disappeared.
1129 this->MatchCookieLines(std::string(), 1123 this->MatchCookieLines(std::string(),
1130 this->GetCookies(cs, this->http_www_google_.url())); 1124 this->GetCookies(cs, this->http_www_foo_.url()));
1131 } 1125 }
1132 1126
1133 namespace { 1127 namespace {
1134 static bool CookieHasValue(const std::string& value, 1128 static bool CookieHasValue(const std::string& value,
1135 const CanonicalCookie& cookie) { 1129 const CanonicalCookie& cookie) {
1136 return cookie.Value() == value; 1130 return cookie.Value() == value;
1137 } 1131 }
1138 } 1132 }
1139 1133
1140 TYPED_TEST_P(CookieStoreTest, TestDeleteAllCreatedBetweenWithPredicate) { 1134 TYPED_TEST_P(CookieStoreTest, TestDeleteAllCreatedBetweenWithPredicate) {
1141 CookieStore* cs = this->GetCookieStore(); 1135 CookieStore* cs = this->GetCookieStore();
1142 base::Time now = base::Time::Now(); 1136 base::Time now = base::Time::Now();
1143 base::Time last_month = base::Time::Now() - base::TimeDelta::FromDays(30); 1137 base::Time last_month = base::Time::Now() - base::TimeDelta::FromDays(30);
1144 base::Time last_minute = base::Time::Now() - base::TimeDelta::FromMinutes(1); 1138 base::Time last_minute = base::Time::Now() - base::TimeDelta::FromMinutes(1);
1145 std::string desired_value("B"); 1139 std::string desired_value("B");
1146 1140
1147 // These 3 cookies match the time range and host. 1141 // These 3 cookies match the time range and host.
1148 EXPECT_TRUE(this->SetCookie(cs, this->http_www_google_.url(), "A=B")); 1142 EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=B"));
1149 EXPECT_TRUE(this->SetCookie(cs, this->http_www_google_.url(), "C=D")); 1143 EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "C=D"));
1150 EXPECT_TRUE(this->SetCookie(cs, this->http_www_google_.url(), "Y=Z")); 1144 EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "Y=Z"));
1151 EXPECT_TRUE(this->SetCookie(cs, this->https_www_google_.url(), "E=B")); 1145 EXPECT_TRUE(this->SetCookie(cs, this->https_www_foo_.url(), "E=B"));
1152 1146
1153 // Delete cookies. 1147 // Delete cookies.
1154 EXPECT_EQ(2, // Deletes A=B, E=B 1148 EXPECT_EQ(2, // Deletes A=B, E=B
1155 this->DeleteAllCreatedBetweenWithPredicate( 1149 this->DeleteAllCreatedBetweenWithPredicate(
1156 cs, now, base::Time::Max(), 1150 cs, now, base::Time::Max(),
1157 base::Bind(&CookieHasValue, desired_value))); 1151 base::Bind(&CookieHasValue, desired_value)));
1158 1152
1159 // Check that we deleted the right ones. 1153 // Check that we deleted the right ones.
1160 this->MatchCookieLines("C=D;Y=Z", 1154 this->MatchCookieLines("C=D;Y=Z",
1161 this->GetCookies(cs, this->https_www_google_.url())); 1155 this->GetCookies(cs, this->https_www_foo_.url()));
1162 1156
1163 // Now check that using a null predicate will do nothing. 1157 // Now check that using a null predicate will do nothing.
1164 EXPECT_EQ(0, this->DeleteAllCreatedBetweenWithPredicate( 1158 EXPECT_EQ(0, this->DeleteAllCreatedBetweenWithPredicate(
1165 cs, now, base::Time::Max(), CookieStore::CookiePredicate())); 1159 cs, now, base::Time::Max(), CookieStore::CookiePredicate()));
1166 1160
1167 // Finally, check that we don't delete cookies when our time range is off. 1161 // Finally, check that we don't delete cookies when our time range is off.
1168 desired_value = "D"; 1162 desired_value = "D";
1169 EXPECT_EQ(0, this->DeleteAllCreatedBetweenWithPredicate( 1163 EXPECT_EQ(0, this->DeleteAllCreatedBetweenWithPredicate(
1170 cs, last_month, last_minute, 1164 cs, last_month, last_minute,
1171 base::Bind(&CookieHasValue, desired_value))); 1165 base::Bind(&CookieHasValue, desired_value)));
1172 this->MatchCookieLines("C=D;Y=Z", 1166 this->MatchCookieLines("C=D;Y=Z",
1173 this->GetCookies(cs, this->https_www_google_.url())); 1167 this->GetCookies(cs, this->https_www_foo_.url()));
1174 // Same thing, but with a good time range. 1168 // Same thing, but with a good time range.
1175 EXPECT_EQ(1, this->DeleteAllCreatedBetweenWithPredicate( 1169 EXPECT_EQ(1, this->DeleteAllCreatedBetweenWithPredicate(
1176 cs, now, base::Time::Max(), 1170 cs, now, base::Time::Max(),
1177 base::Bind(&CookieHasValue, desired_value))); 1171 base::Bind(&CookieHasValue, desired_value)));
1178 this->MatchCookieLines("Y=Z", 1172 this->MatchCookieLines("Y=Z",
1179 this->GetCookies(cs, this->https_www_google_.url())); 1173 this->GetCookies(cs, this->https_www_foo_.url()));
1180 } 1174 }
1181 1175
1182 TYPED_TEST_P(CookieStoreTest, TestSecure) { 1176 TYPED_TEST_P(CookieStoreTest, TestSecure) {
1183 CookieStore* cs = this->GetCookieStore(); 1177 CookieStore* cs = this->GetCookieStore();
1184 1178
1185 EXPECT_TRUE(this->SetCookie(cs, this->http_www_google_.url(), "A=B")); 1179 EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=B"));
1186 this->MatchCookieLines("A=B", 1180 this->MatchCookieLines("A=B",
1187 this->GetCookies(cs, this->http_www_google_.url())); 1181 this->GetCookies(cs, this->http_www_foo_.url()));
1188 this->MatchCookieLines("A=B", 1182 this->MatchCookieLines("A=B",
1189 this->GetCookies(cs, this->https_www_google_.url())); 1183 this->GetCookies(cs, this->https_www_foo_.url()));
1190 1184
1191 EXPECT_TRUE( 1185 EXPECT_TRUE(this->SetCookie(cs, this->https_www_foo_.url(), "A=B; secure"));
1192 this->SetCookie(cs, this->https_www_google_.url(), "A=B; secure"));
1193 // The secure should overwrite the non-secure. 1186 // The secure should overwrite the non-secure.
1194 this->MatchCookieLines(std::string(), 1187 this->MatchCookieLines(std::string(),
1195 this->GetCookies(cs, this->http_www_google_.url())); 1188 this->GetCookies(cs, this->http_www_foo_.url()));
1196 this->MatchCookieLines("A=B", 1189 this->MatchCookieLines("A=B",
1197 this->GetCookies(cs, this->https_www_google_.url())); 1190 this->GetCookies(cs, this->https_www_foo_.url()));
1198 1191
1199 EXPECT_TRUE( 1192 EXPECT_TRUE(this->SetCookie(cs, this->https_www_foo_.url(), "D=E; secure"));
1200 this->SetCookie(cs, this->https_www_google_.url(), "D=E; secure"));
1201 this->MatchCookieLines(std::string(), 1193 this->MatchCookieLines(std::string(),
1202 this->GetCookies(cs, this->http_www_google_.url())); 1194 this->GetCookies(cs, this->http_www_foo_.url()));
1203 this->MatchCookieLines("A=B; D=E", 1195 this->MatchCookieLines("A=B; D=E",
1204 this->GetCookies(cs, this->https_www_google_.url())); 1196 this->GetCookies(cs, this->https_www_foo_.url()));
1205 1197
1206 EXPECT_TRUE(this->SetCookie(cs, this->https_www_google_.url(), "A=B")); 1198 EXPECT_TRUE(this->SetCookie(cs, this->https_www_foo_.url(), "A=B"));
1207 // The non-secure should overwrite the secure. 1199 // The non-secure should overwrite the secure.
1208 this->MatchCookieLines("A=B", 1200 this->MatchCookieLines("A=B",
1209 this->GetCookies(cs, this->http_www_google_.url())); 1201 this->GetCookies(cs, this->http_www_foo_.url()));
1210 this->MatchCookieLines("D=E; A=B", 1202 this->MatchCookieLines("D=E; A=B",
1211 this->GetCookies(cs, this->https_www_google_.url())); 1203 this->GetCookies(cs, this->https_www_foo_.url()));
1212 } 1204 }
1213 1205
1214 // Formerly NetUtilTest.CookieTest back when we used wininet's cookie handling. 1206 // Formerly NetUtilTest.CookieTest back when we used wininet's cookie handling.
1215 TYPED_TEST_P(CookieStoreTest, NetUtilCookieTest) { 1207 TYPED_TEST_P(CookieStoreTest, NetUtilCookieTest) {
1216 const GURL test_url("http://mojo.jojo.google.izzle/"); 1208 const GURL test_url("http://mojo.jojo.foo.com/");
1217 1209
1218 CookieStore* cs = this->GetCookieStore(); 1210 CookieStore* cs = this->GetCookieStore();
1219 1211
1220 EXPECT_TRUE(this->SetCookie(cs, test_url, "foo=bar")); 1212 EXPECT_TRUE(this->SetCookie(cs, test_url, "foo=bar"));
1221 std::string value = this->GetCookies(cs, test_url); 1213 std::string value = this->GetCookies(cs, test_url);
1222 this->MatchCookieLines("foo=bar", value); 1214 this->MatchCookieLines("foo=bar", value);
1223 1215
1224 // test that we can retrieve all cookies: 1216 // test that we can retrieve all cookies:
1225 EXPECT_TRUE(this->SetCookie(cs, test_url, "x=1")); 1217 EXPECT_TRUE(this->SetCookie(cs, test_url, "x=1"));
1226 EXPECT_TRUE(this->SetCookie(cs, test_url, "y=2")); 1218 EXPECT_TRUE(this->SetCookie(cs, test_url, "y=2"));
1227 1219
1228 std::string result = this->GetCookies(cs, test_url); 1220 std::string result = this->GetCookies(cs, test_url);
1229 EXPECT_FALSE(result.empty()); 1221 EXPECT_FALSE(result.empty());
1230 EXPECT_NE(result.find("x=1"), std::string::npos) << result; 1222 EXPECT_NE(result.find("x=1"), std::string::npos) << result;
1231 EXPECT_NE(result.find("y=2"), std::string::npos) << result; 1223 EXPECT_NE(result.find("y=2"), std::string::npos) << result;
1232 } 1224 }
1233 1225
1234 TYPED_TEST_P(CookieStoreTest, OverwritePersistentCookie) { 1226 TYPED_TEST_P(CookieStoreTest, OverwritePersistentCookie) {
1235 GURL url_google("http://www.google.com/"); 1227 GURL url_foo("http://www.foo.com/");
1236 GURL url_chromium("http://chromium.org"); 1228 GURL url_chromium("http://chromium.org");
1237 CookieStore* cs = this->GetCookieStore(); 1229 CookieStore* cs = this->GetCookieStore();
1238 1230
1239 // Insert a cookie "a" for path "/path1" 1231 // Insert a cookie "a" for path "/path1"
1240 EXPECT_TRUE(this->SetCookie(cs, url_google, 1232 EXPECT_TRUE(this->SetCookie(cs, url_foo,
1241 "a=val1; path=/path1; " 1233 "a=val1; path=/path1; "
1242 "expires=Mon, 18-Apr-22 22:50:13 GMT")); 1234 "expires=Mon, 18-Apr-22 22:50:13 GMT"));
1243 1235
1244 // Insert a cookie "b" for path "/path1" 1236 // Insert a cookie "b" for path "/path1"
1245 EXPECT_TRUE(this->SetCookie(cs, url_google, 1237 EXPECT_TRUE(this->SetCookie(cs, url_foo,
1246 "b=val1; path=/path1; " 1238 "b=val1; path=/path1; "
1247 "expires=Mon, 18-Apr-22 22:50:14 GMT")); 1239 "expires=Mon, 18-Apr-22 22:50:14 GMT"));
1248 1240
1249 // Insert a cookie "b" for path "/path1", that is httponly. This should 1241 // Insert a cookie "b" for path "/path1", that is httponly. This should
1250 // overwrite the non-http-only version. 1242 // overwrite the non-http-only version.
1251 CookieOptions allow_httponly; 1243 CookieOptions allow_httponly;
1252 allow_httponly.set_include_httponly(); 1244 allow_httponly.set_include_httponly();
1253 EXPECT_TRUE(this->SetCookieWithOptions(cs, url_google, 1245 EXPECT_TRUE(this->SetCookieWithOptions(cs, url_foo,
1254 "b=val2; path=/path1; httponly; " 1246 "b=val2; path=/path1; httponly; "
1255 "expires=Mon, 18-Apr-22 22:50:14 GMT", 1247 "expires=Mon, 18-Apr-22 22:50:14 GMT",
1256 allow_httponly)); 1248 allow_httponly));
1257 1249
1258 // Insert a cookie "a" for path "/path1". This should overwrite. 1250 // Insert a cookie "a" for path "/path1". This should overwrite.
1259 EXPECT_TRUE(this->SetCookie(cs, url_google, 1251 EXPECT_TRUE(this->SetCookie(cs, url_foo,
1260 "a=val33; path=/path1; " 1252 "a=val33; path=/path1; "
1261 "expires=Mon, 18-Apr-22 22:50:14 GMT")); 1253 "expires=Mon, 18-Apr-22 22:50:14 GMT"));
1262 1254
1263 // Insert a cookie "a" for path "/path2". This should NOT overwrite 1255 // Insert a cookie "a" for path "/path2". This should NOT overwrite
1264 // cookie "a", since the path is different. 1256 // cookie "a", since the path is different.
1265 EXPECT_TRUE(this->SetCookie(cs, url_google, 1257 EXPECT_TRUE(this->SetCookie(cs, url_foo,
1266 "a=val9; path=/path2; " 1258 "a=val9; path=/path2; "
1267 "expires=Mon, 18-Apr-22 22:50:14 GMT")); 1259 "expires=Mon, 18-Apr-22 22:50:14 GMT"));
1268 1260
1269 // Insert a cookie "a" for path "/path1", but this time for "chromium.org". 1261 // Insert a cookie "a" for path "/path1", but this time for "chromium.org".
1270 // Although the name and path match, the hostnames do not, so shouldn't 1262 // Although the name and path match, the hostnames do not, so shouldn't
1271 // overwrite. 1263 // overwrite.
1272 EXPECT_TRUE(this->SetCookie(cs, url_chromium, 1264 EXPECT_TRUE(this->SetCookie(cs, url_chromium,
1273 "a=val99; path=/path1; " 1265 "a=val99; path=/path1; "
1274 "expires=Mon, 18-Apr-22 22:50:14 GMT")); 1266 "expires=Mon, 18-Apr-22 22:50:14 GMT"));
1275 1267
1276 if (TypeParam::supports_http_only) { 1268 if (TypeParam::supports_http_only) {
1277 this->MatchCookieLines( 1269 this->MatchCookieLines(
1278 "a=val33", this->GetCookies(cs, GURL("http://www.google.com/path1"))); 1270 "a=val33", this->GetCookies(cs, GURL("http://www.foo.com/path1")));
1279 } else { 1271 } else {
1280 this->MatchCookieLines( 1272 this->MatchCookieLines(
1281 "a=val33; b=val2", 1273 "a=val33; b=val2",
1282 this->GetCookies(cs, GURL("http://www.google.com/path1"))); 1274 this->GetCookies(cs, GURL("http://www.foo.com/path1")));
1283 } 1275 }
1284 this->MatchCookieLines( 1276 this->MatchCookieLines(
1285 "a=val9", this->GetCookies(cs, GURL("http://www.google.com/path2"))); 1277 "a=val9", this->GetCookies(cs, GURL("http://www.foo.com/path2")));
1286 this->MatchCookieLines( 1278 this->MatchCookieLines(
1287 "a=val99", this->GetCookies(cs, GURL("http://chromium.org/path1"))); 1279 "a=val99", this->GetCookies(cs, GURL("http://chromium.org/path1")));
1288 } 1280 }
1289 1281
1290 TYPED_TEST_P(CookieStoreTest, CookieOrdering) { 1282 TYPED_TEST_P(CookieStoreTest, CookieOrdering) {
1291 // Put a random set of cookies into a store and make sure they're returned in 1283 // Put a random set of cookies into a store and make sure they're returned in
1292 // the right order. 1284 // the right order.
1293 // Cookies should be sorted by path length and creation time, as per RFC6265. 1285 // Cookies should be sorted by path length and creation time, as per RFC6265.
1294 CookieStore* cs = this->GetCookieStore(); 1286 CookieStore* cs = this->GetCookieStore();
1295 EXPECT_TRUE( 1287 EXPECT_TRUE(
1296 this->SetCookie(cs, GURL("http://d.c.b.a.google.com/aa/x.html"), "c=1")); 1288 this->SetCookie(cs, GURL("http://d.c.b.a.foo.com/aa/x.html"), "c=1"));
1297 EXPECT_TRUE(this->SetCookie(cs, GURL("http://b.a.google.com/aa/bb/cc/x.html"), 1289 EXPECT_TRUE(this->SetCookie(cs, GURL("http://b.a.foo.com/aa/bb/cc/x.html"),
1298 "d=1; domain=b.a.google.com")); 1290 "d=1; domain=b.a.foo.com"));
1299 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds( 1291 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(
1300 TypeParam::creation_time_granularity_in_ms)); 1292 TypeParam::creation_time_granularity_in_ms));
1301 EXPECT_TRUE(this->SetCookie(cs, GURL("http://b.a.google.com/aa/bb/cc/x.html"), 1293 EXPECT_TRUE(this->SetCookie(cs, GURL("http://b.a.foo.com/aa/bb/cc/x.html"),
1302 "a=4; domain=b.a.google.com")); 1294 "a=4; domain=b.a.foo.com"));
1303 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds( 1295 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(
1304 TypeParam::creation_time_granularity_in_ms)); 1296 TypeParam::creation_time_granularity_in_ms));
1305 EXPECT_TRUE(this->SetCookie(cs, 1297 EXPECT_TRUE(this->SetCookie(cs, GURL("http://c.b.a.foo.com/aa/bb/cc/x.html"),
1306 GURL("http://c.b.a.google.com/aa/bb/cc/x.html"), 1298 "e=1; domain=c.b.a.foo.com"));
1307 "e=1; domain=c.b.a.google.com")); 1299 EXPECT_TRUE(
1308 EXPECT_TRUE(this->SetCookie( 1300 this->SetCookie(cs, GURL("http://d.c.b.a.foo.com/aa/bb/x.html"), "b=1"));
1309 cs, GURL("http://d.c.b.a.google.com/aa/bb/x.html"), "b=1"));
1310 EXPECT_TRUE(this->SetCookie(cs, GURL("http://news.bbc.co.uk/midpath/x.html"), 1301 EXPECT_TRUE(this->SetCookie(cs, GURL("http://news.bbc.co.uk/midpath/x.html"),
1311 "g=10")); 1302 "g=10"));
1312 EXPECT_EQ( 1303 EXPECT_EQ("d=1; a=4; e=1; b=1; c=1",
1313 "d=1; a=4; e=1; b=1; c=1", 1304 this->GetCookies(cs, GURL("http://d.c.b.a.foo.com/aa/bb/cc/dd")));
1314 this->GetCookies(cs, GURL("http://d.c.b.a.google.com/aa/bb/cc/dd")));
1315 1305
1316 CookieOptions options; 1306 CookieOptions options;
1317 CookieList cookies = this->GetCookieListWithOptions( 1307 CookieList cookies = this->GetCookieListWithOptions(
1318 cs, GURL("http://d.c.b.a.google.com/aa/bb/cc/dd"), options); 1308 cs, GURL("http://d.c.b.a.foo.com/aa/bb/cc/dd"), options);
1319 CookieList::const_iterator it = cookies.begin(); 1309 CookieList::const_iterator it = cookies.begin();
1320 1310
1321 ASSERT_TRUE(it != cookies.end()); 1311 ASSERT_TRUE(it != cookies.end());
1322 EXPECT_EQ("d", it->Name()); 1312 EXPECT_EQ("d", it->Name());
1323 1313
1324 ASSERT_TRUE(++it != cookies.end()); 1314 ASSERT_TRUE(++it != cookies.end());
1325 EXPECT_EQ("a", it->Name()); 1315 EXPECT_EQ("a", it->Name());
1326 1316
1327 ASSERT_TRUE(++it != cookies.end()); 1317 ASSERT_TRUE(++it != cookies.end());
1328 EXPECT_EQ("e", it->Name()); 1318 EXPECT_EQ("e", it->Name());
1329 1319
1330 ASSERT_TRUE(++it != cookies.end()); 1320 ASSERT_TRUE(++it != cookies.end());
1331 EXPECT_EQ("b", it->Name()); 1321 EXPECT_EQ("b", it->Name());
1332 1322
1333 ASSERT_TRUE(++it != cookies.end()); 1323 ASSERT_TRUE(++it != cookies.end());
1334 EXPECT_EQ("c", it->Name()); 1324 EXPECT_EQ("c", it->Name());
1335 1325
1336 EXPECT_TRUE(++it == cookies.end()); 1326 EXPECT_TRUE(++it == cookies.end());
1337 } 1327 }
1338 1328
1339 // Check that GetAllCookiesAsync returns cookies from multiple domains, in the 1329 // Check that GetAllCookiesAsync returns cookies from multiple domains, in the
1340 // correct order. 1330 // correct order.
1341 TYPED_TEST_P(CookieStoreTest, GetAllCookiesAsync) { 1331 TYPED_TEST_P(CookieStoreTest, GetAllCookiesAsync) {
1342 CookieStore* cs = this->GetCookieStore(); 1332 CookieStore* cs = this->GetCookieStore();
1343 1333
1344 EXPECT_TRUE( 1334 EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=B; path=/a"));
1345 this->SetCookie(cs, this->http_www_google_.url(), "A=B; path=/a")); 1335 EXPECT_TRUE(this->SetCookie(cs, this->http_baz_com_.url(), "C=D;/"));
1346 EXPECT_TRUE(this->SetCookie(cs, this->http_foo_com_.url(), "C=D;/"));
1347 EXPECT_TRUE(this->SetCookie(cs, this->http_bar_com_.url(), "E=F; path=/bar")); 1336 EXPECT_TRUE(this->SetCookie(cs, this->http_bar_com_.url(), "E=F; path=/bar"));
1348 1337
1349 // Check cookies for url. 1338 // Check cookies for url.
1350 CookieList cookies = this->GetAllCookies(cs); 1339 CookieList cookies = this->GetAllCookies(cs);
1351 CookieList::const_iterator it = cookies.begin(); 1340 CookieList::const_iterator it = cookies.begin();
1352 1341
1353 ASSERT_TRUE(it != cookies.end()); 1342 ASSERT_TRUE(it != cookies.end());
1354 EXPECT_EQ(this->http_bar_com_.host(), it->Domain()); 1343 EXPECT_EQ(this->http_bar_com_.host(), it->Domain());
1355 EXPECT_EQ("/bar", it->Path()); 1344 EXPECT_EQ("/bar", it->Path());
1356 EXPECT_EQ("E", it->Name()); 1345 EXPECT_EQ("E", it->Name());
1357 EXPECT_EQ("F", it->Value()); 1346 EXPECT_EQ("F", it->Value());
1358 1347
1359 ASSERT_TRUE(++it != cookies.end()); 1348 ASSERT_TRUE(++it != cookies.end());
1360 EXPECT_EQ(this->http_www_google_.host(), it->Domain()); 1349 EXPECT_EQ(this->http_www_foo_.host(), it->Domain());
1361 EXPECT_EQ("/a", it->Path()); 1350 EXPECT_EQ("/a", it->Path());
1362 EXPECT_EQ("A", it->Name()); 1351 EXPECT_EQ("A", it->Name());
1363 EXPECT_EQ("B", it->Value()); 1352 EXPECT_EQ("B", it->Value());
1364 1353
1365 ASSERT_TRUE(++it != cookies.end()); 1354 ASSERT_TRUE(++it != cookies.end());
1366 EXPECT_EQ(this->http_foo_com_.host(), it->Domain()); 1355 EXPECT_EQ(this->http_baz_com_.host(), it->Domain());
1367 EXPECT_EQ("/", it->Path()); 1356 EXPECT_EQ("/", it->Path());
1368 EXPECT_EQ("C", it->Name()); 1357 EXPECT_EQ("C", it->Name());
1369 EXPECT_EQ("D", it->Value()); 1358 EXPECT_EQ("D", it->Value());
1370 1359
1371 ASSERT_TRUE(++it == cookies.end()); 1360 ASSERT_TRUE(++it == cookies.end());
1372 } 1361 }
1373 1362
1374 TYPED_TEST_P(CookieStoreTest, DeleteCookieAsync) { 1363 TYPED_TEST_P(CookieStoreTest, DeleteCookieAsync) {
1375 CookieStore* cs = this->GetCookieStore(); 1364 CookieStore* cs = this->GetCookieStore();
1376 1365
1366 EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=A1; path=/"));
1377 EXPECT_TRUE( 1367 EXPECT_TRUE(
1378 this->SetCookie(cs, this->http_www_google_.url(), "A=A1; path=/")); 1368 this->SetCookie(cs, this->http_www_foo_.url(), "A=A2; path=/foo"));
1379 EXPECT_TRUE( 1369 EXPECT_TRUE(
1380 this->SetCookie(cs, this->http_www_google_.url(), "A=A2; path=/foo")); 1370 this->SetCookie(cs, this->http_www_foo_.url(), "A=A3; path=/bar"));
1371 EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "B=B1; path=/"));
1381 EXPECT_TRUE( 1372 EXPECT_TRUE(
1382 this->SetCookie(cs, this->http_www_google_.url(), "A=A3; path=/bar")); 1373 this->SetCookie(cs, this->http_www_foo_.url(), "B=B2; path=/foo"));
1383 EXPECT_TRUE( 1374 EXPECT_TRUE(
1384 this->SetCookie(cs, this->http_www_google_.url(), "B=B1; path=/")); 1375 this->SetCookie(cs, this->http_www_foo_.url(), "B=B3; path=/bar"));
1385 EXPECT_TRUE(
1386 this->SetCookie(cs, this->http_www_google_.url(), "B=B2; path=/foo"));
1387 EXPECT_TRUE(
1388 this->SetCookie(cs, this->http_www_google_.url(), "B=B3; path=/bar"));
1389 1376
1390 this->DeleteCookie(cs, this->http_www_google_.AppendPath("foo/bar"), "A"); 1377 this->DeleteCookie(cs, this->http_www_foo_.AppendPath("foo/bar"), "A");
1391 1378
1392 CookieList cookies = this->GetAllCookies(cs); 1379 CookieList cookies = this->GetAllCookies(cs);
1393 size_t expected_size = 4; 1380 size_t expected_size = 4;
1394 EXPECT_EQ(expected_size, cookies.size()); 1381 EXPECT_EQ(expected_size, cookies.size());
1395 for (const auto& cookie : cookies) { 1382 for (const auto& cookie : cookies) {
1396 EXPECT_NE("A1", cookie.Value()); 1383 EXPECT_NE("A1", cookie.Value());
1397 EXPECT_NE("A2", cookie.Value()); 1384 EXPECT_NE("A2", cookie.Value());
1398 } 1385 }
1399 } 1386 }
1400 1387
1401 TYPED_TEST_P(CookieStoreTest, DeleteCanonicalCookieAsync) { 1388 TYPED_TEST_P(CookieStoreTest, DeleteCanonicalCookieAsync) {
1402 CookieStore* cs = this->GetCookieStore(); 1389 CookieStore* cs = this->GetCookieStore();
1403 1390
1404 // Set two cookies with the same name, and make sure both are set. 1391 // Set two cookies with the same name, and make sure both are set.
1405 EXPECT_TRUE( 1392 EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=B;Path=/foo"));
1406 this->SetCookie(cs, this->http_www_google_.url(), "A=B;Path=/foo")); 1393 EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=C;Path=/bar"));
1407 EXPECT_TRUE(
1408 this->SetCookie(cs, this->http_www_google_.url(), "A=C;Path=/bar"));
1409 EXPECT_EQ(2u, this->GetAllCookies(cs).size()); 1394 EXPECT_EQ(2u, this->GetAllCookies(cs).size());
1410 EXPECT_EQ("A=B", this->GetCookies(cs, this->www_google_foo_.url())); 1395 EXPECT_EQ("A=B", this->GetCookies(cs, this->www_foo_foo_.url()));
1411 EXPECT_EQ("A=C", this->GetCookies(cs, this->www_google_bar_.url())); 1396 EXPECT_EQ("A=C", this->GetCookies(cs, this->www_foo_bar_.url()));
1412 1397
1413 // Delete the "/foo" cookie, and make sure only it was deleted. 1398 // Delete the "/foo" cookie, and make sure only it was deleted.
1414 CookieList cookies = this->GetCookieListWithOptions( 1399 CookieList cookies = this->GetCookieListWithOptions(
1415 cs, this->www_google_foo_.url(), CookieOptions()); 1400 cs, this->www_foo_foo_.url(), CookieOptions());
1416 ASSERT_EQ(1u, cookies.size()); 1401 ASSERT_EQ(1u, cookies.size());
1417 EXPECT_EQ(1, this->DeleteCanonicalCookie(cs, cookies[0])); 1402 EXPECT_EQ(1, this->DeleteCanonicalCookie(cs, cookies[0]));
1418 EXPECT_EQ(1u, this->GetAllCookies(cs).size()); 1403 EXPECT_EQ(1u, this->GetAllCookies(cs).size());
1419 EXPECT_EQ("", this->GetCookies(cs, this->www_google_foo_.url())); 1404 EXPECT_EQ("", this->GetCookies(cs, this->www_foo_foo_.url()));
1420 EXPECT_EQ("A=C", this->GetCookies(cs, this->www_google_bar_.url())); 1405 EXPECT_EQ("A=C", this->GetCookies(cs, this->www_foo_bar_.url()));
1421 1406
1422 // Deleting the "/foo" cookie again should fail. 1407 // Deleting the "/foo" cookie again should fail.
1423 EXPECT_EQ(0, this->DeleteCanonicalCookie(cs, cookies[0])); 1408 EXPECT_EQ(0, this->DeleteCanonicalCookie(cs, cookies[0]));
1424 1409
1425 // Try to delete the "/bar" cookie after overwriting it with a new cookie. 1410 // Try to delete the "/bar" cookie after overwriting it with a new cookie.
1426 cookies = this->GetCookieListWithOptions(cs, this->www_google_bar_.url(), 1411 cookies = this->GetCookieListWithOptions(cs, this->www_foo_bar_.url(),
1427 CookieOptions()); 1412 CookieOptions());
1428 ASSERT_EQ(1u, cookies.size()); 1413 ASSERT_EQ(1u, cookies.size());
1429 EXPECT_TRUE( 1414 EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=D;Path=/bar"));
1430 this->SetCookie(cs, this->http_www_google_.url(), "A=D;Path=/bar"));
1431 EXPECT_EQ(0, this->DeleteCanonicalCookie(cs, cookies[0])); 1415 EXPECT_EQ(0, this->DeleteCanonicalCookie(cs, cookies[0]));
1432 EXPECT_EQ(1u, this->GetAllCookies(cs).size()); 1416 EXPECT_EQ(1u, this->GetAllCookies(cs).size());
1433 EXPECT_EQ("A=D", this->GetCookies(cs, this->www_google_bar_.url())); 1417 EXPECT_EQ("A=D", this->GetCookies(cs, this->www_foo_bar_.url()));
1434 1418
1435 // Delete the new "/bar" cookie. 1419 // Delete the new "/bar" cookie.
1436 cookies = this->GetCookieListWithOptions(cs, this->www_google_bar_.url(), 1420 cookies = this->GetCookieListWithOptions(cs, this->www_foo_bar_.url(),
1437 CookieOptions()); 1421 CookieOptions());
1438 ASSERT_EQ(1u, cookies.size()); 1422 ASSERT_EQ(1u, cookies.size());
1439 EXPECT_EQ(1, this->DeleteCanonicalCookie(cs, cookies[0])); 1423 EXPECT_EQ(1, this->DeleteCanonicalCookie(cs, cookies[0]));
1440 EXPECT_EQ(0u, this->GetAllCookies(cs).size()); 1424 EXPECT_EQ(0u, this->GetAllCookies(cs).size());
1441 EXPECT_EQ("", this->GetCookies(cs, this->www_google_bar_.url())); 1425 EXPECT_EQ("", this->GetCookies(cs, this->www_foo_bar_.url()));
1442 } 1426 }
1443 1427
1444 TYPED_TEST_P(CookieStoreTest, DeleteSessionCookie) { 1428 TYPED_TEST_P(CookieStoreTest, DeleteSessionCookie) {
1445 CookieStore* cs = this->GetCookieStore(); 1429 CookieStore* cs = this->GetCookieStore();
1446 // Create a session cookie and a persistent cookie. 1430 // Create a session cookie and a persistent cookie.
1447 EXPECT_TRUE(this->SetCookie(cs, this->http_www_google_.url(), 1431 EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(),
1448 std::string(kValidCookieLine))); 1432 std::string(kValidCookieLine)));
1449 EXPECT_TRUE(this->SetCookie( 1433 EXPECT_TRUE(this->SetCookie(
1450 cs, this->http_www_google_.url(), 1434 cs, this->http_www_foo_.url(),
1451 this->http_www_google_.Format("C=D; path=/; domain=%D;" 1435 this->http_www_foo_.Format("C=D; path=/; domain=%D;"
1452 "expires=Mon, 18-Apr-22 22:50:13 GMT"))); 1436 "expires=Mon, 18-Apr-22 22:50:13 GMT")));
1453 this->MatchCookieLines("A=B; C=D", 1437 this->MatchCookieLines("A=B; C=D",
1454 this->GetCookies(cs, this->http_www_google_.url())); 1438 this->GetCookies(cs, this->http_www_foo_.url()));
1455 // Delete the session cookie. 1439 // Delete the session cookie.
1456 this->DeleteSessionCookies(cs); 1440 this->DeleteSessionCookies(cs);
1457 // Check that the session cookie has been deleted but not the persistent one. 1441 // Check that the session cookie has been deleted but not the persistent one.
1458 EXPECT_EQ("C=D", this->GetCookies(cs, this->http_www_google_.url())); 1442 EXPECT_EQ("C=D", this->GetCookies(cs, this->http_www_foo_.url()));
1459 } 1443 }
1460 1444
1461 REGISTER_TYPED_TEST_CASE_P(CookieStoreTest, 1445 REGISTER_TYPED_TEST_CASE_P(CookieStoreTest,
1462 SetCookieWithDetailsAsync, 1446 SetCookieWithDetailsAsync,
1463 SetCookieWithDetailsSecureEnforcement, 1447 SetCookieWithDetailsSecureEnforcement,
1464 EmptyKeyTest, 1448 EmptyKeyTest,
1465 DomainTest, 1449 DomainTest,
1466 DomainWithTrailingDotTest, 1450 DomainWithTrailingDotTest,
1467 ValidSubdomainTest, 1451 ValidSubdomainTest,
1468 InvalidDomainTest, 1452 InvalidDomainTest,
(...skipping 25 matching lines...) Expand all
1494 OverwritePersistentCookie, 1478 OverwritePersistentCookie,
1495 CookieOrdering, 1479 CookieOrdering,
1496 GetAllCookiesAsync, 1480 GetAllCookiesAsync,
1497 DeleteCookieAsync, 1481 DeleteCookieAsync,
1498 DeleteCanonicalCookieAsync, 1482 DeleteCanonicalCookieAsync,
1499 DeleteSessionCookie); 1483 DeleteSessionCookie);
1500 1484
1501 } // namespace net 1485 } // namespace net
1502 1486
1503 #endif // NET_COOKIES_COOKIE_STORE_UNITTEST_H_ 1487 #endif // NET_COOKIES_COOKIE_STORE_UNITTEST_H_
OLDNEW
« no previous file with comments | « net/cookies/cookie_monster_unittest.cc ('k') | net/cookies/cookie_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698